From dd59f5871cfa5214746583111f84bda698f72131 Mon Sep 17 00:00:00 2001 From: masensio Date: Mon, 28 Oct 2013 12:58:56 +0100 Subject: [PATCH] OC-1833: Add CustomButton class to can change the background of buttons --- res/layout-land/account_setup.xml | 2 +- res/layout-v14/generic_explanation.xml | 4 +- res/layout/account_setup.xml | 2 +- res/layout/extensions_available_dialog.xml | 4 +- res/layout/failed_upload_files.xml | 4 +- res/layout/failed_upload_message_view.xml | 2 +- res/layout/generic_explanation.xml | 4 +- res/layout/log_send_file.xml | 3 +- res/layout/no_account_available.xml | 2 +- res/layout/pincodelock.xml | 2 +- res/layout/ssl_validator_layout.xml | 6 +-- res/layout/upload_files_layout.xml | 4 +- res/layout/uploader_layout.xml | 4 +- .../debitel/cloud/android/Uploader.java | 4 +- .../authentication/AuthenticatorActivity.java | 11 ++--- .../extensions/ExtensionsAvailableDialog.java | 13 ++---- .../cloud/android/ui/CustomButton.java | 45 +++++++++++++++++++ .../ErrorsWhileCopyingHandlerActivity.java | 12 ++--- .../ui/activity/FailedUploadActivity.java | 8 +--- .../ui/activity/InstantUploadActivity.java | 12 ++--- .../ui/activity/LogHistoryActivity.java | 9 +--- .../android/ui/activity/PinCodeActivity.java | 11 ++--- .../ui/activity/UploadFilesActivity.java | 16 +++---- .../android/ui/dialog/SslValidatorDialog.java | 6 +-- 24 files changed, 99 insertions(+), 91 deletions(-) create mode 100644 src/de/mobilcom/debitel/cloud/android/ui/CustomButton.java diff --git a/res/layout-land/account_setup.xml b/res/layout-land/account_setup.xml index 7bd362d178..b0a42ae6ae 100644 --- a/res/layout-land/account_setup.xml +++ b/res/layout-land/account_setup.xml @@ -185,7 +185,7 @@ - + android:text="@string/uploader_btn_upload_text"/> diff --git a/src/de/mobilcom/debitel/cloud/android/Uploader.java b/src/de/mobilcom/debitel/cloud/android/Uploader.java index 0cb3d76126..d788136555 100644 --- a/src/de/mobilcom/debitel/cloud/android/Uploader.java +++ b/src/de/mobilcom/debitel/cloud/android/Uploader.java @@ -49,7 +49,6 @@ import android.view.View; import android.view.Window; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; -import android.widget.Button; import android.widget.EditText; import android.widget.SimpleAdapter; import android.widget.Toast; @@ -61,6 +60,7 @@ import de.mobilcom.debitel.cloud.android.datamodel.DataStorageManager; import de.mobilcom.debitel.cloud.android.datamodel.FileDataStorageManager; import de.mobilcom.debitel.cloud.android.datamodel.OCFile; import de.mobilcom.debitel.cloud.android.files.services.FileUploader; +import de.mobilcom.debitel.cloud.android.ui.CustomButton; /** * This can be used to upload things to an ownCloud instance. @@ -310,7 +310,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro new String[] {"dirname"}, new int[] {R.id.textView1}); setListAdapter(sa); - Button btn = (Button) findViewById(R.id.uploader_choose_folder); + CustomButton btn = (CustomButton) findViewById(R.id.uploader_choose_folder); btn.setOnClickListener(this); getListView().setOnItemClickListener(this); } diff --git a/src/de/mobilcom/debitel/cloud/android/authentication/AuthenticatorActivity.java b/src/de/mobilcom/debitel/cloud/android/authentication/AuthenticatorActivity.java index 049b478730..3709779792 100644 --- a/src/de/mobilcom/debitel/cloud/android/authentication/AuthenticatorActivity.java +++ b/src/de/mobilcom/debitel/cloud/android/authentication/AuthenticatorActivity.java @@ -64,6 +64,7 @@ import de.mobilcom.debitel.cloud.android.operations.OwnCloudServerCheckOperation import de.mobilcom.debitel.cloud.android.operations.RemoteOperation; import de.mobilcom.debitel.cloud.android.operations.RemoteOperationResult; import de.mobilcom.debitel.cloud.android.operations.RemoteOperationResult.ResultCode; +import de.mobilcom.debitel.cloud.android.ui.CustomButton; import de.mobilcom.debitel.cloud.android.ui.dialog.SamlWebViewDialog; import de.mobilcom.debitel.cloud.android.ui.dialog.SslValidatorDialog; import de.mobilcom.debitel.cloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; @@ -187,7 +188,7 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList mOAuthAuthEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_1); mOAuthTokenEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_2); mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check); - mOkButton = findViewById(R.id.buttonOK); + mOkButton = (CustomButton) findViewById(R.id.buttonOK); mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text); /// set Host Url Input Enabled @@ -200,10 +201,10 @@ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList b.setText(String.format(getString(R.string.auth_register), getString(R.string.app_name))); } - /// complete background of 'OK' button - boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); - if (customButtons) - mOkButton.setBackgroundResource(R.drawable.btn_default); +// /// complete background of 'OK' button +// boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); +// if (customButtons) +// mOkButton.setBackgroundResource(R.drawable.btn_default); /// initialization mAccountMgr = AccountManager.get(this); diff --git a/src/de/mobilcom/debitel/cloud/android/extensions/ExtensionsAvailableDialog.java b/src/de/mobilcom/debitel/cloud/android/extensions/ExtensionsAvailableDialog.java index b5294954f7..e7e899f0a5 100644 --- a/src/de/mobilcom/debitel/cloud/android/extensions/ExtensionsAvailableDialog.java +++ b/src/de/mobilcom/debitel/cloud/android/extensions/ExtensionsAvailableDialog.java @@ -20,6 +20,7 @@ package de.mobilcom.debitel.cloud.android.extensions; import de.mobilcom.debitel.cloud.android.Log_OC; import de.mobilcom.debitel.cloud.android.R; +import de.mobilcom.debitel.cloud.android.ui.CustomButton; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.DialogFragment; @@ -27,7 +28,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; -import android.widget.Button; public class ExtensionsAvailableDialog extends DialogFragment implements OnClickListener { @@ -40,15 +40,8 @@ public class ExtensionsAvailableDialog extends DialogFragment implements Bundle savedInstanceState) { View view = inflater.inflate(R.layout.extensions_available_dialog, container); - Button btnYes = (Button) view.findViewById(R.id.buttonYes); - Button btnNo = (Button) view.findViewById(R.id.buttonNo); - - // Set background of buttons - boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); - if (customButtons) { - btnYes.setBackgroundResource(R.drawable.btn_default); - btnNo.setBackgroundResource(R.drawable.btn_default); - } + CustomButton btnYes = (CustomButton) view.findViewById(R.id.buttonYes); + CustomButton btnNo = (CustomButton) view.findViewById(R.id.buttonNo); btnYes.setOnClickListener(this); btnNo.setOnClickListener(this); diff --git a/src/de/mobilcom/debitel/cloud/android/ui/CustomButton.java b/src/de/mobilcom/debitel/cloud/android/ui/CustomButton.java new file mode 100644 index 0000000000..09b821577a --- /dev/null +++ b/src/de/mobilcom/debitel/cloud/android/ui/CustomButton.java @@ -0,0 +1,45 @@ +package de.mobilcom.debitel.cloud.android.ui; + +import de.mobilcom.debitel.cloud.android.R; +import android.content.Context; +import android.util.AttributeSet; +import android.widget.Button; +/** + * @author masensio + * + * Button for customizing the button background + */ + +public class CustomButton extends Button { + + public CustomButton(Context context) { + super(context); + + boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); + if (customButtons) + { + this.setBackgroundResource(R.drawable.btn_default); + } + } + + public CustomButton(Context context, AttributeSet attrs) { + super(context, attrs); + + boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); + if (customButtons) + { + this.setBackgroundResource(R.drawable.btn_default); + } + } + + public CustomButton(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + + boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); + if (customButtons) + { + this.setBackgroundResource(R.drawable.btn_default); + } + } + +} diff --git a/src/de/mobilcom/debitel/cloud/android/ui/activity/ErrorsWhileCopyingHandlerActivity.java b/src/de/mobilcom/debitel/cloud/android/ui/activity/ErrorsWhileCopyingHandlerActivity.java index f9367271ff..33ffc32f27 100644 --- a/src/de/mobilcom/debitel/cloud/android/ui/activity/ErrorsWhileCopyingHandlerActivity.java +++ b/src/de/mobilcom/debitel/cloud/android/ui/activity/ErrorsWhileCopyingHandlerActivity.java @@ -33,7 +33,6 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; @@ -44,6 +43,7 @@ import de.mobilcom.debitel.cloud.android.Log_OC; import de.mobilcom.debitel.cloud.android.R; import de.mobilcom.debitel.cloud.android.datamodel.FileDataStorageManager; import de.mobilcom.debitel.cloud.android.datamodel.OCFile; +import de.mobilcom.debitel.cloud.android.ui.CustomButton; import de.mobilcom.debitel.cloud.android.ui.dialog.IndeterminateProgressDialog; import de.mobilcom.debitel.cloud.android.utils.FileStorageUtils; @@ -117,14 +117,8 @@ public class ErrorsWhileCopyingHandlerActivity extends SherlockFragmentActivity } /// customize buttons - Button cancelBtn = (Button) findViewById(R.id.cancel); - Button okBtn = (Button) findViewById(R.id.ok); - // Set background of buttons - boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); - if (customButtons) { - cancelBtn.setBackgroundResource(R.drawable.btn_default); - okBtn.setBackgroundResource(R.drawable.btn_default); - } + CustomButton cancelBtn = (CustomButton) findViewById(R.id.cancel); + CustomButton okBtn = (CustomButton) findViewById(R.id.ok); okBtn.setText(R.string.foreign_files_move); cancelBtn.setOnClickListener(this); diff --git a/src/de/mobilcom/debitel/cloud/android/ui/activity/FailedUploadActivity.java b/src/de/mobilcom/debitel/cloud/android/ui/activity/FailedUploadActivity.java index c1bb9e2a38..eeb8b275ee 100644 --- a/src/de/mobilcom/debitel/cloud/android/ui/activity/FailedUploadActivity.java +++ b/src/de/mobilcom/debitel/cloud/android/ui/activity/FailedUploadActivity.java @@ -21,10 +21,10 @@ import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; -import android.widget.Button; import android.widget.TextView; import de.mobilcom.debitel.cloud.android.R; +import de.mobilcom.debitel.cloud.android.ui.CustomButton; /** * This Activity is used to display a detail message for failed uploads @@ -44,11 +44,7 @@ public class FailedUploadActivity extends Activity { String message = getIntent().getStringExtra(MESSAGE); TextView textView = (TextView) findViewById(R.id.faild_upload_message); textView.setText(message); - Button closeBtn = (Button) findViewById(R.id.failed_uploadactivity_close_button); - // Set background of 'close' button - boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); - if (customButtons) - closeBtn.setBackgroundResource(R.drawable.btn_default); + CustomButton closeBtn = (CustomButton) findViewById(R.id.failed_uploadactivity_close_button); closeBtn.setOnClickListener(new OnClickListener() { @Override diff --git a/src/de/mobilcom/debitel/cloud/android/ui/activity/InstantUploadActivity.java b/src/de/mobilcom/debitel/cloud/android/ui/activity/InstantUploadActivity.java index 6be111d96a..23cb6f02af 100644 --- a/src/de/mobilcom/debitel/cloud/android/ui/activity/InstantUploadActivity.java +++ b/src/de/mobilcom/debitel/cloud/android/ui/activity/InstantUploadActivity.java @@ -47,6 +47,7 @@ import de.mobilcom.debitel.cloud.android.authentication.AccountUtils; import de.mobilcom.debitel.cloud.android.db.DbHandler; import de.mobilcom.debitel.cloud.android.files.InstantUploadBroadcastReceiver; import de.mobilcom.debitel.cloud.android.files.services.FileUploader; +import de.mobilcom.debitel.cloud.android.ui.CustomButton; import de.mobilcom.debitel.cloud.android.utils.FileStorageUtils; /** @@ -76,21 +77,14 @@ public class InstantUploadActivity extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.failed_upload_files); - Button deleteAllBtn = (Button) findViewById(R.id.failed_upload_delete_all_btn); + CustomButton deleteAllBtn = (CustomButton) findViewById(R.id.failed_upload_delete_all_btn); deleteAllBtn.setOnClickListener(getDeleteListner()); - Button retryAllBtn = (Button) findViewById(R.id.failed_upload_retry_all_btn); + CustomButton retryAllBtn = (CustomButton) findViewById(R.id.failed_upload_retry_all_btn); retryAllBtn.setOnClickListener(getRetryListner()); this.failed_upload_all_cb = (CheckBox) findViewById(R.id.failed_upload_headline_cb); failed_upload_all_cb.setOnCheckedChangeListener(getCheckAllListener()); listView = (LinearLayout) findViewById(R.id.failed_upload_scrollviewlayout); - // Set background of buttons - boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); - if (customButtons) { - deleteAllBtn.setBackgroundResource(R.drawable.btn_default); - retryAllBtn.setBackgroundResource(R.drawable.btn_default); - } - loadListView(true); } diff --git a/src/de/mobilcom/debitel/cloud/android/ui/activity/LogHistoryActivity.java b/src/de/mobilcom/debitel/cloud/android/ui/activity/LogHistoryActivity.java index 0066bc13a3..20317bc810 100644 --- a/src/de/mobilcom/debitel/cloud/android/ui/activity/LogHistoryActivity.java +++ b/src/de/mobilcom/debitel/cloud/android/ui/activity/LogHistoryActivity.java @@ -26,7 +26,6 @@ import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.view.View; import android.view.View.OnClickListener; -import android.widget.Button; import android.widget.ListView; import com.actionbarsherlock.app.ActionBar; @@ -34,6 +33,7 @@ import com.actionbarsherlock.app.SherlockPreferenceActivity; import com.actionbarsherlock.view.MenuItem; import de.mobilcom.debitel.cloud.android.R; +import de.mobilcom.debitel.cloud.android.ui.CustomButton; import de.mobilcom.debitel.cloud.android.ui.adapter.LogListAdapter; import de.mobilcom.debitel.cloud.android.utils.FileStorageUtils; @@ -52,13 +52,8 @@ public class LogHistoryActivity extends SherlockPreferenceActivity implements On ActionBar actionBar = getSherlock().getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); ListView listView = (ListView) findViewById(android.R.id.list); - Button deleteHistoryButton = (Button) findViewById(R.id.deleteLogHistoryButton); + CustomButton deleteHistoryButton = (CustomButton) findViewById(R.id.deleteLogHistoryButton); - // Set background of 'deleteHistory' button - boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); - if (customButtons) - deleteHistoryButton.setBackgroundResource(R.drawable.btn_default); - deleteHistoryButton.setOnClickListener(new OnClickListener() { @Override diff --git a/src/de/mobilcom/debitel/cloud/android/ui/activity/PinCodeActivity.java b/src/de/mobilcom/debitel/cloud/android/ui/activity/PinCodeActivity.java index 5cd1a795d2..37e763d170 100644 --- a/src/de/mobilcom/debitel/cloud/android/ui/activity/PinCodeActivity.java +++ b/src/de/mobilcom/debitel/cloud/android/ui/activity/PinCodeActivity.java @@ -21,6 +21,7 @@ import java.util.Arrays; import com.actionbarsherlock.app.SherlockFragmentActivity; import de.mobilcom.debitel.cloud.android.R; +import de.mobilcom.debitel.cloud.android.ui.CustomButton; import android.app.AlertDialog; import android.content.DialogInterface; @@ -35,7 +36,6 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; import android.view.View.OnKeyListener; -import android.widget.Button; import android.widget.EditText; import android.widget.TextView; @@ -45,7 +45,7 @@ public class PinCodeActivity extends SherlockFragmentActivity { public final static String EXTRA_ACTIVITY = "de.mobilcom.debitel.cloud.android.ui.activity.PinCodeActivity.ACTIVITY"; public final static String EXTRA_NEW_STATE = "de.mobilcom.debitel.cloud.android.ui.activity.PinCodeActivity.NEW_STATE"; - Button bCancel; + CustomButton bCancel; TextView mPinHdr; TextView mPinHdrExplanation; EditText mText1; @@ -71,7 +71,7 @@ public class PinCodeActivity extends SherlockFragmentActivity { Intent intent = getIntent(); activity = intent.getStringExtra(EXTRA_ACTIVITY); - bCancel = (Button) findViewById(R.id.cancel); + bCancel = (CustomButton) findViewById(R.id.cancel); mPinHdr = (TextView) findViewById(R.id.pinHdr); mPinHdrExplanation = (TextView) findViewById(R.id.pinHdrExpl); mText1 = (EditText) findViewById(R.id.txt1); @@ -81,11 +81,6 @@ public class PinCodeActivity extends SherlockFragmentActivity { mText3 = (EditText) findViewById(R.id.txt3); mText4 = (EditText) findViewById(R.id.txt4); - // Set background of 'Cancel' button - boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); - if (customButtons) - bCancel.setBackgroundResource(R.drawable.btn_default); - SharedPreferences appPrefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); diff --git a/src/de/mobilcom/debitel/cloud/android/ui/activity/UploadFilesActivity.java b/src/de/mobilcom/debitel/cloud/android/ui/activity/UploadFilesActivity.java index 49d9b84743..6d0c88d657 100644 --- a/src/de/mobilcom/debitel/cloud/android/ui/activity/UploadFilesActivity.java +++ b/src/de/mobilcom/debitel/cloud/android/ui/activity/UploadFilesActivity.java @@ -29,7 +29,6 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.TextView; import com.actionbarsherlock.app.ActionBar; @@ -38,6 +37,7 @@ import com.actionbarsherlock.view.MenuItem; import de.mobilcom.debitel.cloud.android.Log_OC; import de.mobilcom.debitel.cloud.android.R; +import de.mobilcom.debitel.cloud.android.ui.CustomButton; import de.mobilcom.debitel.cloud.android.ui.dialog.IndeterminateProgressDialog; import de.mobilcom.debitel.cloud.android.ui.fragment.ConfirmationDialogFragment; import de.mobilcom.debitel.cloud.android.ui.fragment.LocalFileListFragment; @@ -58,8 +58,8 @@ public class UploadFilesActivity extends FileActivity implements private ArrayAdapter mDirectories; private File mCurrentDir = null; private LocalFileListFragment mFileListFragment; - private Button mCancelBtn; - private Button mUploadBtn; + private CustomButton mCancelBtn; + private CustomButton mUploadBtn; private Account mAccountOnCreation; private DialogFragment mCurrentDialog; @@ -103,17 +103,11 @@ public class UploadFilesActivity extends FileActivity implements // Set input controllers - mCancelBtn = (Button) findViewById(R.id.upload_files_btn_cancel); + mCancelBtn = (CustomButton) findViewById(R.id.upload_files_btn_cancel); mCancelBtn.setOnClickListener(this); - mUploadBtn = (Button) findViewById(R.id.upload_files_btn_upload); + mUploadBtn = (CustomButton) findViewById(R.id.upload_files_btn_upload); mUploadBtn.setOnClickListener(this); - // Set background of buttons - boolean customButtons = getResources().getBoolean(R.bool.custom_buttons); - if (customButtons) { - mCancelBtn.setBackgroundResource(R.drawable.btn_default); - mUploadBtn.setBackgroundResource(R.drawable.btn_default); - } // Action bar setup ActionBar actionBar = getSupportActionBar(); diff --git a/src/de/mobilcom/debitel/cloud/android/ui/dialog/SslValidatorDialog.java b/src/de/mobilcom/debitel/cloud/android/ui/dialog/SslValidatorDialog.java index 2b6f1684d2..f75b9842f0 100644 --- a/src/de/mobilcom/debitel/cloud/android/ui/dialog/SslValidatorDialog.java +++ b/src/de/mobilcom/debitel/cloud/android/ui/dialog/SslValidatorDialog.java @@ -34,7 +34,6 @@ import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.Window; -import android.widget.Button; import android.widget.TextView; import de.mobilcom.debitel.cloud.android.Log_OC; @@ -42,6 +41,7 @@ import de.mobilcom.debitel.cloud.android.R; import de.mobilcom.debitel.cloud.android.network.CertificateCombinedException; import de.mobilcom.debitel.cloud.android.network.OwnCloudClientUtils; import de.mobilcom.debitel.cloud.android.operations.RemoteOperationResult; +import de.mobilcom.debitel.cloud.android.ui.CustomButton; /** * Dialog to request the user about a certificate that could not be validated with the certificates store in the system. @@ -142,11 +142,11 @@ public class SslValidatorDialog extends Dialog { View detailsScroll = findViewById(R.id.details_scroll); if (detailsScroll.getVisibility() == View.VISIBLE) { detailsScroll.setVisibility(View.GONE); - ((Button)v).setText(R.string.ssl_validator_btn_details_see); + ((CustomButton)v).setText(R.string.ssl_validator_btn_details_see); } else { detailsScroll.setVisibility(View.VISIBLE); - ((Button)v).setText(R.string.ssl_validator_btn_details_hide); + ((CustomButton)v).setText(R.string.ssl_validator_btn_details_hide); } } });