|
| 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 | +} |
0 commit comments