From d93731701255e082b02bf80c5c029db8838b15b0 Mon Sep 17 00:00:00 2001 From: uberspot Date: Tue, 11 Mar 2014 01:50:17 +0200 Subject: [PATCH] Remove duplicate code from ActionBarHelper. You can now set the drawables via the method calls --- .../keychain/helper/ActionBarHelper.java | 107 +++++------------- .../service/remote/AppSettingsActivity.java | 2 +- .../service/remote/RemoteServiceActivity.java | 10 +- .../keychain/ui/EditKeyActivity.java | 10 +- .../ui/PreferencesKeyServerActivity.java | 4 +- .../keychain/ui/SelectPublicKeyActivity.java | 4 +- .../res/layout/actionbar_custom_view_save.xml | 27 ----- .../actionbar_custom_view_save_cancel.xml | 29 ----- .../layout/actionbar_include_save_button.xml | 36 ------ 9 files changed, 42 insertions(+), 187 deletions(-) delete mode 100644 OpenPGP-Keychain/src/main/res/layout/actionbar_custom_view_save.xml delete mode 100644 OpenPGP-Keychain/src/main/res/layout/actionbar_custom_view_save_cancel.xml delete mode 100644 OpenPGP-Keychain/src/main/res/layout/actionbar_include_save_button.xml diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ActionBarHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ActionBarHelper.java index 6aa8e7d74..2276e0f8a 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ActionBarHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ActionBarHelper.java @@ -22,6 +22,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.util.Log; import android.app.Activity; +import android.graphics.drawable.Drawable; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.view.LayoutInflater; @@ -56,28 +57,33 @@ public class ActionBarHelper { * Sets custom view on ActionBar for Done/Cancel activities * * @param actionBar - * @param doneText - * @param doneOnClickListener - * @param cancelText - * @param cancelOnClickListener + * @param firstText + * @param firstDrawableId + * @param firstOnClickListener + * @param secondText + * @param secondDrawableId + * @param secondOnClickListener */ - public static void setDoneCancelView(ActionBar actionBar, int doneText, - OnClickListener doneOnClickListener, int cancelText, - OnClickListener cancelOnClickListener) { + public static void setTwoButtonView(ActionBar actionBar, int firstText, int firstDrawableId, + OnClickListener firstOnClickListener, int secondText, int secondDrawableId, + OnClickListener secondOnClickListener) { - // Inflate a "Done"/"Cancel" custom action bar view + // Inflate the custom action bar view final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext() .getSystemService(Activity.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(doneText); + TextView firstTextView = ((TextView) customActionBarView.findViewById(R.id.actionbar_done_text)); + firstTextView.setText(firstText); + firstTextView.setCompoundDrawablesWithIntrinsicBounds(firstDrawableId, 0, 0, 0); customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener( - doneOnClickListener); - ((TextView) customActionBarView.findViewById(R.id.actionbar_cancel_text)) - .setText(cancelText); + firstOnClickListener); + TextView secondTextView = ((TextView) customActionBarView.findViewById(R.id.actionbar_cancel_text)); + secondTextView.setText(secondText); + secondTextView.setCompoundDrawablesWithIntrinsicBounds(secondDrawableId, 0, 0, 0); customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener( - cancelOnClickListener); + secondOnClickListener); // Show the custom action bar view and hide the normal Home icon and title. actionBar.setDisplayShowTitleEnabled(false); @@ -91,20 +97,22 @@ public class ActionBarHelper { * Sets custom view on ActionBar for Done activities * * @param actionBar - * @param doneText - * @param doneOnClickListener + * @param firstText + * @param firstOnClickListener */ - public static void setDoneView(ActionBar actionBar, int doneText, - OnClickListener doneOnClickListener) { + public static void setOneButtonView(ActionBar actionBar, int firstText, int firstDrawableId, + OnClickListener firstOnClickListener) { // Inflate a "Done" custom action bar view to serve as the "Up" affordance. final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext() .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); final View customActionBarView = inflater .inflate(R.layout.actionbar_custom_view_done, null); - ((TextView) customActionBarView.findViewById(R.id.actionbar_done_text)).setText(doneText); + TextView firstTextView = ((TextView) customActionBarView.findViewById(R.id.actionbar_done_text)); + firstTextView.setText(firstText); + firstTextView.setCompoundDrawablesWithIntrinsicBounds(firstDrawableId, 0, 0, 0); customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener( - doneOnClickListener); + firstOnClickListener); // Show the custom action bar view and hide the normal Home icon and title. actionBar.setDisplayShowTitleEnabled(false); @@ -112,65 +120,4 @@ public class ActionBarHelper { actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(customActionBarView); } - - /** - * Sets custom view on ActionBar for Save activities - * - * @param actionBar - * @param saveText - * @param saveOnClickListener - */ - public static void setSaveView(ActionBar actionBar, int saveText, - OnClickListener saveOnClickListener) { - // Inflate a "Save" custom action bar view to serve as the "Up" affordance. - final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext() - .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); - final View customActionBarView = inflater - .inflate(R.layout.actionbar_custom_view_save, null); - - ((TextView) customActionBarView.findViewById(R.id.actionbar_save_text)).setText(saveText); - customActionBarView.findViewById(R.id.actionbar_save).setOnClickListener( - saveOnClickListener); - - // Show the custom action bar view and hide the normal Home icon and title. - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayShowCustomEnabled(true); - actionBar.setCustomView(customActionBarView); - } - - /** - * Sets custom view on ActionBar for Save/Cancel activities - * - * @param actionBar - * @param saveText - * @param saveOnClickListener - * @param cancelText - * @param cancelOnClickListener - */ - public static void setSaveCancelView(ActionBar actionBar, int saveText, - OnClickListener saveOnClickListener, int cancelText, - OnClickListener cancelOnClickListener) { - - // Inflate a "Done"/"Cancel" custom action bar view - final LayoutInflater inflater = (LayoutInflater) actionBar.getThemedContext() - .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); - final View customActionBarView = inflater.inflate( - R.layout.actionbar_custom_view_save_cancel, null); - - ((TextView) customActionBarView.findViewById(R.id.actionbar_save_text)).setText(saveText); - customActionBarView.findViewById(R.id.actionbar_save).setOnClickListener( - saveOnClickListener); - ((TextView) customActionBarView.findViewById(R.id.actionbar_cancel_text)) - .setText(cancelText); - customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener( - cancelOnClickListener); - - // Show the custom action bar view and hide the normal Home icon and title. - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setDisplayShowHomeEnabled(false); - actionBar.setDisplayShowCustomEnabled(true); - actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - } } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java index a7afc9698..178b2fc67 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java @@ -41,7 +41,7 @@ public class AppSettingsActivity extends ActionBarActivity { super.onCreate(savedInstanceState); // Inflate a "Done" custom action bar - ActionBarHelper.setDoneView(getSupportActionBar(), R.string.api_settings_save, + ActionBarHelper.setOneButtonView(getSupportActionBar(), R.string.api_settings_save, R.drawable.ic_action_done, new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java index 11b3ee217..8fb562884 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java @@ -88,7 +88,7 @@ public class RemoteServiceActivity extends ActionBarActivity { final byte[] packageSignature = extras.getByteArray(EXTRA_PACKAGE_SIGNATURE); // Inflate a "Done"/"Cancel" custom action bar view - ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.api_register_allow, + ActionBarHelper.setTwoButtonView(getSupportActionBar(), R.string.api_register_allow, R.drawable.ic_action_done, new View.OnClickListener() { @Override public void onClick(View v) { @@ -108,7 +108,7 @@ public class RemoteServiceActivity extends ActionBarActivity { RemoteServiceActivity.this.finish(); } } - }, R.string.api_register_disallow, new View.OnClickListener() { + }, R.string.api_register_disallow, R.drawable.ic_action_cancel, new View.OnClickListener() { @Override public void onClick(View v) { // Disallow @@ -161,7 +161,7 @@ public class RemoteServiceActivity extends ActionBarActivity { } // Inflate a "Done"/"Cancel" custom action bar view - ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_okay, + ActionBarHelper.setTwoButtonView(getSupportActionBar(), R.string.btn_okay, R.drawable.ic_action_done, new View.OnClickListener() { @Override public void onClick(View v) { @@ -173,7 +173,7 @@ public class RemoteServiceActivity extends ActionBarActivity { RemoteServiceActivity.this.setResult(RESULT_OK, resultData); RemoteServiceActivity.this.finish(); } - }, R.string.btn_do_not_save, new View.OnClickListener() { + }, R.string.btn_do_not_save, R.drawable.ic_action_cancel, new View.OnClickListener() { @Override public void onClick(View v) { // cancel @@ -214,7 +214,7 @@ public class RemoteServiceActivity extends ActionBarActivity { String text = "" + errorMessage + ""; // Inflate a "Done" custom action bar view - ActionBarHelper.setDoneView(getSupportActionBar(), R.string.btn_okay, + ActionBarHelper.setOneButtonView(getSupportActionBar(), R.string.btn_okay, R.drawable.ic_action_done, new View.OnClickListener() { @Override diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java index 628f642d8..19f991640 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java @@ -134,14 +134,14 @@ public class EditKeyActivity extends ActionBarActivity { * @param intent */ private void handleActionCreateKey(Intent intent) { - // Inflate a "Done"/"Cancel" custom action bar - ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_save, + // Inflate a "Save"/"Cancel" custom action bar + ActionBarHelper.setTwoButtonView(getSupportActionBar(), R.string.btn_save, R.drawable.ic_action_save, new View.OnClickListener() { @Override public void onClick(View v) { saveClicked(); } - }, R.string.btn_do_not_save, new View.OnClickListener() { + }, R.string.btn_do_not_save, R.drawable.ic_action_cancel, new View.OnClickListener() { @Override public void onClick(View v) { cancelClicked(); @@ -249,8 +249,8 @@ public class EditKeyActivity extends ActionBarActivity { * @param intent */ private void handleActionEditKey(Intent intent) { - // Inflate a "Done"/"Cancel" custom action bar - ActionBarHelper.setSaveView(getSupportActionBar(), R.string.btn_save, + // Inflate a "Save"/"Cancel" custom action bar + ActionBarHelper.setOneButtonView(getSupportActionBar(), R.string.btn_save, R.drawable.ic_action_save, new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java index b5ac739ae..492e9f200 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java @@ -50,14 +50,14 @@ public class PreferencesKeyServerActivity extends ActionBarActivity implements O super.onCreate(savedInstanceState); // Inflate a "Done"/"Cancel" custom action bar view - ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_okay, + ActionBarHelper.setTwoButtonView(getSupportActionBar(), R.string.btn_okay, R.drawable.ic_action_done, new View.OnClickListener() { @Override public void onClick(View v) { // ok okClicked(); } - }, R.string.btn_do_not_save, new View.OnClickListener() { + }, R.string.btn_do_not_save, R.drawable.ic_action_cancel, new View.OnClickListener() { @Override public void onClick(View v) { // cancel diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyActivity.java index 86ae0073f..3c63628f7 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyActivity.java @@ -46,14 +46,14 @@ public class SelectPublicKeyActivity extends ActionBarActivity { super.onCreate(savedInstanceState); // Inflate a "Done"/"Cancel" custom action bar view - ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_okay, + ActionBarHelper.setTwoButtonView(getSupportActionBar(), R.string.btn_okay, R.drawable.ic_action_done, new View.OnClickListener() { @Override public void onClick(View v) { // ok okClicked(); } - }, R.string.btn_do_not_save, new View.OnClickListener() { + }, R.string.btn_do_not_save, R.drawable.ic_action_cancel, new View.OnClickListener() { @Override public void onClick(View v) { // cancel diff --git a/OpenPGP-Keychain/src/main/res/layout/actionbar_custom_view_save.xml b/OpenPGP-Keychain/src/main/res/layout/actionbar_custom_view_save.xml deleted file mode 100644 index f0dcf177c..000000000 --- a/OpenPGP-Keychain/src/main/res/layout/actionbar_custom_view_save.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/OpenPGP-Keychain/src/main/res/layout/actionbar_custom_view_save_cancel.xml b/OpenPGP-Keychain/src/main/res/layout/actionbar_custom_view_save_cancel.xml deleted file mode 100644 index ba08a7714..000000000 --- a/OpenPGP-Keychain/src/main/res/layout/actionbar_custom_view_save_cancel.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/OpenPGP-Keychain/src/main/res/layout/actionbar_include_save_button.xml b/OpenPGP-Keychain/src/main/res/layout/actionbar_include_save_button.xml deleted file mode 100644 index 86c59dcc5..000000000 --- a/OpenPGP-Keychain/src/main/res/layout/actionbar_include_save_button.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - \ No newline at end of file