[Android] Open the sliding menu only during the first run

Ludovic Fauvet git at videolan.org
Tue Sep 25 21:46:08 CEST 2012


vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Tue Sep 25 21:44:42 2012 +0200| [7fd4ad78b4f7bc0d18871e20c49c0bc5c87e9ed9] | committer: Ludovic Fauvet

Open the sliding menu only during the first run

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=7fd4ad78b4f7bc0d18871e20c49c0bc5c87e9ed9
---

 .../src/org/videolan/vlc/gui/MainActivity.java     |   66 ++++++++++++--------
 1 file changed, 39 insertions(+), 27 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index c45f8e8..fe63123 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -84,6 +84,7 @@ public class MainActivity extends SherlockFragmentActivity {
     protected static final String ACTION_SHOW_TEXTINFO = "org.videolan.vlc.gui.ShowTextInfo";
 
     private static final String PREF_SHOW_INFO = "show_info";
+    private static final String PREF_FIRST_RUN = "first_run";
 
     private ActionBar mActionBar;
     private SlidingMenu mMenu;
@@ -98,6 +99,7 @@ public class MainActivity extends SherlockFragmentActivity {
     private SharedPreferences mSettings;
 
     private int mVersionNumber = -1;
+    private boolean mFirstRun = false;
 
     public MainActivity() {
     }
@@ -130,8 +132,27 @@ public class MainActivity extends SherlockFragmentActivity {
         listView.setAdapter(mSidebarAdapter);
         mMenu.setViewBehind(sidebar);
 
+        /* Get the current version from package */
+        PackageInfo pinfo = null;
+        try {
+            pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
+        } catch (NameNotFoundException e) {
+            Log.e(TAG, "package info not found.");
+        }
+        if (pinfo != null)
+            mVersionNumber = pinfo.versionCode;
+
         /* Get settings */
         mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+
+        /* Check if it's the first run */
+        mFirstRun = mSettings.getInt(PREF_FIRST_RUN, -1) != mVersionNumber;
+        if (mFirstRun) {
+            Editor editor = mSettings.edit();
+            editor.putInt(PREF_FIRST_RUN, mVersionNumber);
+            editor.commit();
+        }
+
         LibVLC.useIOMX(this);
         try {
             // Start LibVLC
@@ -207,31 +228,21 @@ public class MainActivity extends SherlockFragmentActivity {
             .commit();
 
         /* Show info/alpha/beta Warning */
-        PackageInfo pinfo = null;
-        try {
-            pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
-        } catch (NameNotFoundException e) {
-            Log.e(TAG, "package info not found.");
-        }
-        if (pinfo != null) {
-            mVersionNumber = pinfo.versionCode;
-
-            if (mSettings.getInt(PREF_SHOW_INFO, -1) != mVersionNumber)
-                showInfoDialog();
-            else {
-                /*
-                 * The sliding menu is automatically opened when the user closes
-                 * the info dialog. If (for any reason) the dialog is not shown,
-                 * open the menu after a short delay.
-                 */
-                final Handler handler = new Handler();
-                handler.postDelayed(new Runnable() {
-                    @Override
-                    public void run() {
-                        mMenu.showBehind();
-                    }
-                }, 500);
-            }
+        if (mSettings.getInt(PREF_SHOW_INFO, -1) != mVersionNumber)
+            showInfoDialog();
+        else if (mFirstRun) {
+            /*
+             * The sliding menu is automatically opened when the user closes
+             * the info dialog. If (for any reason) the dialog is not shown,
+             * open the menu after a short delay.
+             */
+            final Handler handler = new Handler();
+            handler.postDelayed(new Runnable() {
+                @Override
+                public void run() {
+                    mMenu.showBehind();
+                }
+            }, 500);
         }
 
         /* Prepare the progressBar */
@@ -436,8 +447,9 @@ public class MainActivity extends SherlockFragmentActivity {
                 }
                 /* Close the dialog */
                 infoDialog.dismiss();
-                /* and finally open the sliding menu */
-                mMenu.showBehind();
+                /* and finally open the sliding menu if first run */
+                if (mFirstRun)
+                    mMenu.showBehind();
             }
         });
         infoDialog.show();



More information about the Android mailing list