Skip to content

Commit be13715

Browse files
committed
Adds demo for fragments
1 parent dc64d10 commit be13715

File tree

5 files changed

+116
-2
lines changed

5 files changed

+116
-2
lines changed

sample/src/main/AndroidManifest.xml

+2
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@
4848

4949
<activity android:name=".EventsActivity" />
5050

51+
<activity android:name=".FragmentDemoActivity" />
52+
5153
</application>
5254
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.github.amlcurran.showcaseview.sample;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v4.app.Fragment;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
import android.widget.Button;
11+
12+
import com.github.amlcurran.showcaseview.ShowcaseView;
13+
import com.github.amlcurran.showcaseview.SimpleShowcaseEventListener;
14+
import com.github.amlcurran.showcaseview.targets.ViewTarget;
15+
16+
public class FragmentDemoActivity extends AppCompatActivity {
17+
18+
@Override
19+
protected void onCreate(@Nullable Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
setContentView(R.layout.activity_fragment_demo);
22+
}
23+
24+
public void onHiddenFirstShowcase() {
25+
getSupportFragmentManager()
26+
.beginTransaction()
27+
.replace(R.id.fragment_host_two, new SecondDemoFragment())
28+
.commit();
29+
}
30+
31+
public static class FirstDemoFragment extends Fragment {
32+
33+
private Button button;
34+
35+
@Override
36+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
37+
View view = inflater.inflate(R.layout.fragment_layout, container, false);
38+
button = (Button) view.findViewById(R.id.fragment_demo_button);
39+
return view;
40+
}
41+
42+
@Override
43+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
44+
super.onActivityCreated(savedInstanceState);
45+
new ShowcaseView.Builder(getActivity())
46+
.withMaterialShowcase()
47+
.setStyle(R.style.CustomShowcaseTheme)
48+
.setTarget(new ViewTarget(button))
49+
.hideOnTouchOutside()
50+
.setContentTitle(R.string.showcase_fragment_title)
51+
.setContentText(R.string.showcase_fragment_message)
52+
.setShowcaseEventListener(new SimpleShowcaseEventListener() {
53+
54+
@Override
55+
public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
56+
((FragmentDemoActivity) getActivity()).onHiddenFirstShowcase();
57+
}
58+
59+
})
60+
.build();
61+
}
62+
63+
}
64+
65+
public static class SecondDemoFragment extends Fragment {
66+
67+
private Button button;
68+
69+
@Override
70+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
71+
View view = inflater.inflate(R.layout.fragment_layout, container, false);
72+
button = (Button) view.findViewById(R.id.fragment_demo_button);
73+
return view;
74+
}
75+
76+
@Override
77+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
78+
super.onActivityCreated(savedInstanceState);
79+
new ShowcaseView.Builder(getActivity())
80+
.withMaterialShowcase()
81+
.setStyle(R.style.CustomShowcaseTheme2)
82+
.setTarget(new ViewTarget(button))
83+
.hideOnTouchOutside()
84+
.setContentTitle(R.string.showcase_fragment_title_2)
85+
.setContentText(R.string.showcase_fragment_message_2)
86+
.build();
87+
}
88+
89+
}
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
6+
7+
<fragment
8+
android:id="@+id/fragment_one"
9+
class="com.github.amlcurran.showcaseview.sample.FragmentDemoActivity$FirstDemoFragment"
10+
android:layout_width="match_parent"
11+
android:layout_height="0dp"
12+
android:layout_weight="1" />
13+
14+
<FrameLayout
15+
android:id="@+id/fragment_host_two"
16+
android:layout_width="match_parent"
17+
android:layout_height="0dp"
18+
android:layout_weight="1" />
19+
20+
</LinearLayout>

sample/src/main/res/layout/fragment_layout.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
android:layout_width="wrap_content"
2525
android:layout_height="wrap_content"
2626
android:text="@string/does_really_work_with_fragments"
27-
android:id="@+id/buttonFragments"
27+
android:id="@+id/fragment_demo_button"
2828
android:layout_centerInParent="true" />
2929

30-
</RelativeLayout>
30+
</RelativeLayout>

sample/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
<string name="showcase_like_title">Like button</string>
4141
<string name="showcase_like_message">Click the button if you like kittens.</string>
4242
<string name="showcase_fragment_title">ShowcaseView and Fragments?</string>
43+
<string name="showcase_fragment_title_2">Even works with transactions</string>
4344
<string name="showcase_fragment_message">Click the button to find out whether this works with Fragments, too.</string>
45+
<string name="showcase_fragment_message_2">Just remember to create the ShowcaseView during or after onActivityCreated()</string>
4446
<string name="showcase_menu_item_one_shot_title">Shown only once</string>
4547
<string name="showcase_menu_item_one_shot_message">This will be shown only once since it uses ShowcaseView.TYPE_ONE_SHOT as the shotType.\nDelete the app data to see it again.</string>
4648
<string name="does_really_work_with_fragments">Show toast</string>

0 commit comments

Comments
 (0)