From e25dc08fe527d478d83a6ee84ddcf4bc2b2a2812 Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Thu, 3 Apr 2014 23:23:20 -0400 Subject: [PATCH] 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 4b98c270..4f6e8779 100755 --- a/res/menu/main.xml +++ b/res/menu/main.xml @@ -17,26 +17,27 @@ * limitations under the License. */ --> - - + + diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index f63ecd8f..f48e0a9b 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