Permalink
Browse files

Add screen analytics for fragment based navigation

  • Loading branch information...
ianhanniballake committed Nov 10, 2017
1 parent eb70fb2 commit 573c78c4d3d9cf9268c7d22a7f99900c7faf1391
@@ -35,9 +35,10 @@
import android.view.View;
import android.view.ViewGroup;
import com.google.android.apps.muzei.settings.SettingsAdvancedFragment;
import com.google.android.apps.muzei.settings.SettingsChooseSourceFragment;
import com.google.android.apps.muzei.settings.EffectsFragment;
import com.google.android.apps.muzei.settings.ChooseSourceFragment;
import com.google.android.apps.muzei.util.ScrimUtil;
import com.google.firebase.analytics.FirebaseAnalytics;
import net.nurik.roman.muzei.R;
@@ -46,7 +47,7 @@
* between various screens.
*/
public class MainFragment extends Fragment implements FragmentManager.OnBackStackChangedListener,
SettingsChooseSourceFragment.Callbacks {
ChooseSourceFragment.Callbacks {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -85,6 +86,9 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved
// Set up the container for the child fragments
final View container = view.findViewById(R.id.container);
if (savedInstanceState == null) {
FirebaseAnalytics.getInstance(getActivity())
.setCurrentScreen(getActivity(), "ArtDetail",
ArtDetailFragment.class.getSimpleName());
getChildFragmentManager().beginTransaction()
.replace(R.id.container, new ArtDetailFragment())
.commit();
@@ -98,25 +102,34 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
switch (item.getItemId()) {
case R.id.main_art_details:
FirebaseAnalytics.getInstance(getContext())
.setCurrentScreen(getActivity(), "ArtDetail",
ArtDetailFragment.class.getSimpleName());
getChildFragmentManager().beginTransaction()
.replace(R.id.container, new ArtDetailFragment())
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
return true;
case R.id.main_choose_source:
FirebaseAnalytics.getInstance(getContext())
.setCurrentScreen(getActivity(), "ChooseSource",
ChooseSourceFragment.class.getSimpleName());
getChildFragmentManager().popBackStack("main",
FragmentManager.POP_BACK_STACK_INCLUSIVE);
getChildFragmentManager().beginTransaction()
.replace(R.id.container, new SettingsChooseSourceFragment())
.replace(R.id.container, new ChooseSourceFragment())
.addToBackStack("main")
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
return true;
case R.id.main_effects:
FirebaseAnalytics.getInstance(getContext())
.setCurrentScreen(getActivity(), "Effects",
EffectsFragment.class.getSimpleName());
getChildFragmentManager().popBackStack("main",
FragmentManager.POP_BACK_STACK_INCLUSIVE);
getChildFragmentManager().beginTransaction()
.replace(R.id.container, new SettingsAdvancedFragment())
.replace(R.id.container, new EffectsFragment())
.addToBackStack("main")
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
@@ -70,13 +70,19 @@ private Fragment getCurrentFragment() {
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (sp.getBoolean(TutorialFragment.PREF_SEEN_TUTORIAL, false)) {
// The wallpaper is active and they've seen the tutorial
FirebaseAnalytics.getInstance(this).setCurrentScreen(this, "Main",
MainFragment.class.getSimpleName());
return new MainFragment();
} else {
// They need to see the tutorial after activating Muzei for the first time
FirebaseAnalytics.getInstance(this).setCurrentScreen(this, "Tutorial",
TutorialFragment.class.getSimpleName());
return new TutorialFragment();
}
} else {
// Show the intro fragment to have them activate Muzei
FirebaseAnalytics.getInstance(this).setCurrentScreen(this, "Intro",
IntroFragment.class.getSimpleName());
return new IntroFragment();
}
}
@@ -83,7 +83,7 @@
/**
* Fragment for allowing the user to choose the active source.
*/
public class SettingsChooseSourceFragment extends Fragment {
public class ChooseSourceFragment extends Fragment {
private static final String TAG = "SettingsChooseSourceFrg";
private static final String PLAY_STORE_PACKAGE_NAME = "com.android.vending";
@@ -119,7 +119,7 @@
private ComponentName mCurrentInitialSetupSource;
public SettingsChooseSourceFragment() {
public ChooseSourceFragment() {
}
@Override
@@ -38,7 +38,7 @@
/**
* Fragment for allowing the user to configure advanced settings.
*/
public class SettingsAdvancedFragment extends Fragment {
public class EffectsFragment extends Fragment {
private Handler mHandler = new Handler();
private SeekBar mBlurSeekBar;
@@ -33,6 +33,7 @@
import com.google.android.apps.muzei.event.WallpaperActiveStateChangedEvent;
import com.google.android.apps.muzei.render.MuzeiRendererFragment;
import com.google.firebase.analytics.FirebaseAnalytics;
import net.nurik.roman.muzei.R;
@@ -44,7 +45,7 @@
* shows when pressing the settings button in the widget.
*/
public class SettingsActivity extends AppCompatActivity
implements SettingsChooseSourceFragment.Callbacks {
implements ChooseSourceFragment.Callbacks {
public static final String EXTRA_START_SECTION =
"com.google.android.apps.muzei.settings.extra.START_SECTION";
@@ -58,8 +59,13 @@
@SuppressWarnings("unchecked")
private static final Class<? extends Fragment>[] SECTION_FRAGMENTS = new Class[]{
SettingsChooseSourceFragment.class,
SettingsAdvancedFragment.class,
ChooseSourceFragment.class,
EffectsFragment.class,
};
private static final String[] SECTION_SCREEN_NAME = new String[]{
"ChooseSource",
"Effects",
};
private int mStartSection = START_SECTION_SOURCE;
@@ -158,6 +164,9 @@ public void onItemSelected(AdapterView<?> spinner, View view, int position, long
try {
Fragment newFragment = fragmentClass.newInstance();
FirebaseAnalytics.getInstance(SettingsActivity.this)
.setCurrentScreen(SettingsActivity.this, SECTION_SCREEN_NAME[position],
fragmentClass.getSimpleName());
getSupportFragmentManager().beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.setTransitionStyle(R.style.Muzei_SimpleFadeFragmentAnimation)

0 comments on commit 573c78c

Please sign in to comment.