From 1be368092ef0b05244108a1071bf8adad5db91ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 30 Dec 2013 21:46:42 +0100 Subject: [PATCH] Fix custom action bars for Android 4.4 --- .../keychain/helper/ActionBarHelper.java | 10 +++-- .../service/remote/AppSettingsActivity.java | 2 +- .../keychain/ui/EditKeyActivity.java | 38 ++----------------- 3 files changed, 10 insertions(+), 40 deletions(-) diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/ActionBarHelper.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/ActionBarHelper.java index dcac2df08..fee120273 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/ActionBarHelper.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/ActionBarHelper.java @@ -81,8 +81,9 @@ public class ActionBarHelper { cancelOnClickListener); // Show the custom action bar view and hide the normal Home icon and title. - actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM - | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); + actionBar.setDisplayShowTitleEnabled(false); + actionBar.setDisplayShowHomeEnabled(false); + actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } @@ -107,8 +108,9 @@ public class ActionBarHelper { doneOnClickListener); // Show the custom action bar view and hide the normal Home icon and title. - actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM - | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); + actionBar.setDisplayShowTitleEnabled(false); + actionBar.setDisplayShowHomeEnabled(false); + actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(customActionBarView); } diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java index 7b04d3da6..4f1bedb6f 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java @@ -41,7 +41,7 @@ public class AppSettingsActivity extends SherlockFragmentActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // Inflate a "Done" custom action bar view to serve as the "Up" affordance. + // Inflate a "Done" custom action bar ActionBarHelper.setDoneView(getSupportActionBar(), R.string.api_settings_save, new View.OnClickListener() { @Override diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 1e62d06e3..7abee78f3 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -58,10 +58,8 @@ import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.LinearLayout; -import android.widget.TextView; import android.widget.Toast; -import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockFragmentActivity; public class EditKeyActivity extends SherlockFragmentActivity { @@ -81,8 +79,6 @@ public class EditKeyActivity extends SherlockFragmentActivity { public static final String RESULT_EXTRA_MASTER_KEY_ID = "master_key_id"; public static final String RESULT_EXTRA_USER_ID = "user_id"; - private ActionBar mActionBar; - private PGPSecretKeyRing mKeyRing = null; private SectionView mUserIdsView; @@ -107,26 +103,15 @@ public class EditKeyActivity extends SherlockFragmentActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // Inflate a "Done"/"Cancel" custom action bar view - final LayoutInflater inflater = (LayoutInflater) getSupportActionBar().getThemedContext() - .getSystemService(LAYOUT_INFLATER_SERVICE); - final View customActionBarView = inflater.inflate( - R.layout.actionbar_custom_view_done_cancel, null); - - ((TextView) customActionBarView.findViewById(R.id.actionbar_done_text)) - .setText(R.string.btn_save); - customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener( + // Inflate a "Done"/"Cancel" custom action bar + ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_save, new View.OnClickListener() { @Override public void onClick(View v) { // save saveClicked(); } - }); - ((TextView) customActionBarView.findViewById(R.id.actionbar_cancel_text)) - .setText(R.string.btn_do_not_save); - customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener( - new View.OnClickListener() { + }, R.string.btn_do_not_save, new View.OnClickListener() { @Override public void onClick(View v) { // cancel @@ -134,21 +119,8 @@ public class EditKeyActivity extends SherlockFragmentActivity { } }); - // Show the custom action bar view and hide the normal Home icon and title. - final ActionBar actionBar = getSupportActionBar(); - actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM - | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); - actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - setContentView(R.layout.edit_key); - mActionBar = getSupportActionBar(); - mActionBar.setDisplayShowTitleEnabled(true); - - // set actionbar without home button if called from another app - ActionBarHelper.setBackButton(this); - // find views mChangePassPhrase = (Button) findViewById(R.id.edit_key_btn_change_pass_phrase); mNoPassphrase = (CheckBox) findViewById(R.id.edit_key_no_passphrase); @@ -201,8 +173,6 @@ public class EditKeyActivity extends SherlockFragmentActivity { private void handleActionCreateKey(Intent intent) { Bundle extras = intent.getExtras(); - mActionBar.setTitle(R.string.title_create_key); - mCurrentPassPhrase = ""; if (extras != null) { @@ -330,8 +300,6 @@ public class EditKeyActivity extends SherlockFragmentActivity { private void handleActionEditKey(Intent intent) { Bundle extras = intent.getExtras(); - mActionBar.setTitle(R.string.title_edit_key); - if (extras != null) { if (extras.containsKey(EXTRA_MASTER_CAN_SIGN)) { masterCanSign = extras.getBoolean(EXTRA_MASTER_CAN_SIGN);