From 0ebecd9b64ad2f35ea1e5892ec140ad97fde3b03 Mon Sep 17 00:00:00 2001 From: str4d <str4d@mail.i2p> Date: Sun, 26 Jan 2014 06:38:34 +0000 Subject: [PATCH] Changed navbar first-use mechanics to match Android design pattern --- TODO | 1 - .../i2p/android/router/I2PActivityBase.java | 18 ++++++++++++ src/net/i2p/android/router/MainActivity.java | 13 ++++----- src/net/i2p/android/router/VersionDialog.java | 29 ++----------------- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/TODO b/TODO index 9047fb832..bb3a89202 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,6 @@ - Move help content from release notes to help page - Rewrite release notes to be release-specific - Fill out help page -- Change navbar first-open mechanics to match Android design docs # Short-term diff --git a/src/net/i2p/android/router/I2PActivityBase.java b/src/net/i2p/android/router/I2PActivityBase.java index 6f3f1d5ac..66923e7b4 100644 --- a/src/net/i2p/android/router/I2PActivityBase.java +++ b/src/net/i2p/android/router/I2PActivityBase.java @@ -63,6 +63,7 @@ public abstract class I2PActivityBase extends ActionBarActivity implements protected static final String PREF_AUTO_START = "autoStart"; /** true leads to a poor install experience, very slow to paint the screen */ protected static final boolean DEFAULT_AUTO_START = false; + protected static final String PREF_NAV_DRAWER_OPENED = "navDrawerOpened"; /** * Override this in subclasses that need a ViewPager, such as a @@ -122,18 +123,30 @@ public abstract class I2PActivityBase extends ActionBarActivity implements mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { + private boolean wasDragged = false; /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { + // Don't mark as opened if the user closed by dragging + // but uses the action bar icon to open + wasDragged = false; getSupportActionBar().setTitle(mTitle); supportInvalidateOptionsMenu(); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View view) { + if (wasDragged && !getPref(PREF_NAV_DRAWER_OPENED, false)) + setPref(PREF_NAV_DRAWER_OPENED, true); getSupportActionBar().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); } + + /** Called when the drawer motion state changes. */ + public void onDrawerStateChanged(int newState) { + if (newState == DrawerLayout.STATE_DRAGGING) + wasDragged = true; + } }; // Set the drawer toggle as the DrawerListener @@ -220,6 +233,11 @@ public abstract class I2PActivityBase extends ActionBarActivity implements bindRouter(false); } + /** @param def default */ + public boolean getPref(String pref, boolean def) { + return _sharedPrefs.getBoolean(pref, def); + } + /** @param def default */ public String getPref(String pref, String def) { return _sharedPrefs.getString(pref, def); diff --git a/src/net/i2p/android/router/MainActivity.java b/src/net/i2p/android/router/MainActivity.java index 932d66a11..89711b6be 100644 --- a/src/net/i2p/android/router/MainActivity.java +++ b/src/net/i2p/android/router/MainActivity.java @@ -20,8 +20,7 @@ import net.i2p.android.router.service.RouterService; import net.i2p.android.router.util.Util; public class MainActivity extends I2PActivityBase implements - MainFragment.RouterControlListener, - VersionDialog.VersionDialogListener { + MainFragment.RouterControlListener { IRouterState mStateService = null; MainFragment mMainFragment = null; @@ -36,6 +35,10 @@ public class MainActivity extends I2PActivityBase implements getSupportFragmentManager().beginTransaction() .add(R.id.main_fragment, mMainFragment).commit(); } + + // Open nav drawer if the user has never opened it themselves + if (!getPref(PREF_NAV_DRAWER_OPENED, false)) + mDrawerLayout.openDrawer(mDrawerList); } @Override @@ -234,10 +237,4 @@ public class MainActivity extends I2PActivityBase implements } return false; } - - // VersionDialog.VersionDialogListener - - public void onFirstRun() { - mDrawerLayout.openDrawer(mDrawerList); - } } diff --git a/src/net/i2p/android/router/VersionDialog.java b/src/net/i2p/android/router/VersionDialog.java index d5ecdb3be..23eb54525 100644 --- a/src/net/i2p/android/router/VersionDialog.java +++ b/src/net/i2p/android/router/VersionDialog.java @@ -2,7 +2,6 @@ package net.i2p.android.router; import net.i2p.android.router.R; import net.i2p.android.router.util.Util; -import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; @@ -15,27 +14,6 @@ public class VersionDialog extends DialogFragment { protected static final int DIALOG_NEW_INSTALL = 0; protected static final int DIALOG_NEW_VERSION = 1; - public interface VersionDialogListener { - public void onFirstRun(); - } - - VersionDialogListener mListener; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - // Verify that the host activity implements the callback interface - try { - // Instantiate the VersionDialogListener so we can tell the host - // if this is a new install. - mListener = (VersionDialogListener) activity; - } catch (ClassCastException e) { - // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() - + " must implement VersionDialogListener"); - } - } - @Override public Dialog onCreateDialog(Bundle SavedInstanceState) { final String currentVersion = Util.getOurVersion(getActivity()); @@ -51,15 +29,14 @@ public class VersionDialog extends DialogFragment { public void onClick(DialogInterface dialog, int id) { I2PActivityBase ab = (I2PActivityBase) getActivity(); ab.setPref(MainFragment.PREF_INSTALLED_VERSION, currentVersion); - dialog.cancel(); - mListener.onFirstRun(); + dialog.dismiss(); } }).setNeutralButton(R.string.label_release_notes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { I2PActivityBase ab = (I2PActivityBase) getActivity(); ab.setPref(MainFragment.PREF_INSTALLED_VERSION, currentVersion); - dialog.cancel(); + dialog.dismiss(); TextResourceDialog f = new TextResourceDialog(); Bundle args = new Bundle(); args.putInt(TextResourceDialog.TEXT_RESOURCE_ID, R.raw.releasenotes_txt); @@ -75,7 +52,7 @@ public class VersionDialog extends DialogFragment { public void onClick(DialogInterface dialog, int id) { I2PActivityBase ab = (I2PActivityBase) getActivity(); ab.setPref(MainFragment.PREF_INSTALLED_VERSION, currentVersion); - dialog.cancel(); + dialog.dismiss(); Intent intent = new Intent(getActivity(), LicenseActivity.class); startActivity(intent); } -- GitLab