[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] fixes the menus for appcompat library



commit e25dc08fe527d478d83a6ee84ddcf4bc2b2a2812
Author: Nathan Freitas <nathan@xxxxxxxxxxx>
Date:   Thu Apr 3 23:23:20 2014 -0400

    fixes the menus for appcompat library
---
 res/menu/main.xml                     |   19 +++----
 src/org/torproject/android/Orbot.java |   89 +++++++++++++++++++++++++++++++--
 2 files changed, 95 insertions(+), 13 deletions(-)

diff --git a/res/menu/main.xml b/res/menu/main.xml
index 4b98c27..4f6e877 100755
--- a/res/menu/main.xml
+++ b/res/menu/main.xml
@@ -17,26 +17,27 @@
  * limitations under the License.
  */
 -->
-<menu xmlns:android="http://schemas.android.com/apk/res/android";>
-
+<menu xmlns:yourapp="http://schemas.android.com/apk/res-auto";
+    xmlns:android="http://schemas.android.com/apk/res/android";>
+    
  <item android:id="@+id/menu_start"
         android:title="@string/menu_start"
          android:icon="@drawable/ic_action_start"
-          android:showAsAction="ifRoom"
-         
+          yourapp:showAsAction="ifRoom"
+          yourapp:actionProviderClass="android.support.v7.widget.ShareActionProvider"
          />
 
  <item android:id="@+id/menu_settings"
         android:title="@string/menu_settings"
          android:icon="@drawable/ic_action_settings"
-         android:showAsAction="always"
+         yourapp:showAsAction="always"
          />
 
  <item 
      android:id="@+id/menu_verify_list"
         android:title="@string/menu_verify"
          android:icon="@drawable/ic_action_browse"
-                  android:showAsAction="always"         
+                  yourapp:showAsAction="always"         
         >
         <menu>
         <item android:id="@+id/menu_verify"
@@ -54,21 +55,21 @@
  <item android:id="@+id/menu_about"
         android:title="@string/menu_about"
          android:icon="@drawable/ic_menu_about"
-                  android:showAsAction="ifRoom"
+                  yourapp:showAsAction="ifRoom"
          
          />
  
   <item android:id="@+id/menu_wizard"
         android:title="@string/menu_wizard"
          android:icon="@drawable/ic_menu_goto"
-                  android:showAsAction="ifRoom"
+                  yourapp:showAsAction="ifRoom"
          
          />
  
   <item android:id="@+id/menu_exit"
         android:title="@string/menu_exit"
          android:icon="@drawable/ic_menu_exit"
-                  android:showAsAction="ifRoom"
+                  yourapp:showAsAction="ifRoom"
          
          />
  
diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java
index f63ecd8..f48e0a9 100644
--- a/src/org/torproject/android/Orbot.java
+++ b/src/org/torproject/android/Orbot.java
@@ -3,6 +3,8 @@
 
 package org.torproject.android;
 
+import static org.torproject.android.TorConstants.TAG;
+
 import java.util.Locale;
 
 import org.torproject.android.service.ITorService;
@@ -34,6 +36,7 @@ import android.os.IBinder;
 import android.os.Message;
 import android.os.RemoteException;
 import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.ActionMode;
 import android.text.ClipboardManager;
 import android.text.Layout;
 import android.text.method.ScrollingMovementMethod;
@@ -188,9 +191,87 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
        
         mItemOnOff = menu.getItem(0);
         
+        /*
+        startSupportActionMode(new ActionMode.Callback() {
+            @Override
+            public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
+                // Inflate our menu from a resource file
+             //   actionMode.getMenuInflater().inflate(R.menu.action_mode_main, menu);
+
+                // Return true so that the action mode is shown
+                return true;
+            }
+
+            @Override
+            public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
+                // As we do not need to modify the menu before displayed, we return false.
+                return false;
+            }
+
+            @Override
+            public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
+                // Similar to menu handling in Activity.onOptionsItemSelected()
+                switch (menuItem.getItemId()) {
+                    case R.id.menu_start:
+                    	 try
+                         {
+                                 
+                                 if (mService == null)
+                                 {
+                                 
+                                 }
+                                 else if (mService.getStatus() == TorServiceConstants.STATUS_OFF)
+                                 {
+                                     if (mItemOnOff != null)
+                                             mItemOnOff.setTitle(R.string.menu_stop);
+                                         startTor();
+                                         
+                                 }
+                                 else
+                                 {
+                                     if (mItemOnOff != null)
+                                             mItemOnOff.setTitle(R.string.menu_start);
+                                         stopTor();
+                                         
+                                 }
+                                 
+                         }
+                         catch (RemoteException re)
+                         {
+                                 Log.w(TAG, "Unable to start/top Tor from menu UI", re);
+                         }
+                        return true;
+                    case R.id.menu_settings:
+                    	 showSettings();
+                    	 return true;
+                    case R.id.menu_wizard:
+                          startWizard();
+                          return true;
+                    case R.id.menu_verify:
+                          doTorCheck();
+                          return true;
+                    case R.id.menu_exit:
+                          doExit();
+                          return true;        
+                    case R.id.menu_about:
+                          showAbout();
+                          return true;
+                }
+
+                return false;
+            }
+
+            @Override
+            public void onDestroyActionMode(ActionMode actionMode) {
+                // Allows you to be notified when the action mode is dismissed
+            }
+        });*/
+        
         return true;
     }
     
+    
+    
 
     private void showAbout ()
         {
@@ -214,10 +295,11 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
 	        .setView(view)
 	        .show();
         }
-    /**
-        public boolean onMenuItemSelected(int featureId, MenuItem item) {
+    
+    	@Override
+        public boolean onOptionsItemSelected(MenuItem item) {
                 
-                super.onMenuItemSelected(featureId, item);
+                super.onOptionsItemSelected(item);
                 
                 if (item.getItemId() == R.id.menu_start)
                 {
@@ -278,7 +360,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
                 
         return true;
         }
-      */
       
         /**
         * This is our attempt to REALLY exit Orbot, and stop the background service

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits