Refactor BaseActivity

This commit is contained in:
Dominik Schürmann 2015-01-13 23:43:18 +01:00
parent d8ff737fc5
commit 7da3ddae7b
26 changed files with 85 additions and 62 deletions

View File

@ -27,6 +27,7 @@ import android.view.View;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.BaseActivity;
import org.sufficientlysecure.keychain.ui.util.ActionBarHelper; import org.sufficientlysecure.keychain.ui.util.ActionBarHelper;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.remote.AccountSettings; import org.sufficientlysecure.keychain.remote.AccountSettings;
@ -35,7 +36,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp
import org.sufficientlysecure.keychain.operations.results.SingletonResult; import org.sufficientlysecure.keychain.operations.results.SingletonResult;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
public class AccountSettingsActivity extends ActionBarActivity { public class AccountSettingsActivity extends BaseActivity {
private Uri mAccountUri; private Uri mAccountUri;
private AccountSettingsFragment mAccountSettingsFragment; private AccountSettingsFragment mAccountSettingsFragment;
@ -55,7 +56,6 @@ public class AccountSettingsActivity extends ActionBarActivity {
} }
}); });
setContentView(R.layout.api_account_settings_activity);
mAccountSettingsFragment = (AccountSettingsFragment) getSupportFragmentManager().findFragmentById( mAccountSettingsFragment = (AccountSettingsFragment) getSupportFragmentManager().findFragmentById(
R.id.api_account_settings_fragment); R.id.api_account_settings_fragment);
@ -72,6 +72,11 @@ public class AccountSettingsActivity extends ActionBarActivity {
} }
} }
@Override
protected void initLayout() {
setContentView(R.layout.api_account_settings_activity);
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);

View File

@ -33,9 +33,10 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.remote.AppSettings; import org.sufficientlysecure.keychain.remote.AppSettings;
import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.ui.BaseActivity;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
public class AppSettingsActivity extends ActionBarActivity { public class AppSettingsActivity extends BaseActivity {
private Uri mAppUri; private Uri mAppUri;
private AppSettingsFragment mSettingsFragment; private AppSettingsFragment mSettingsFragment;
@ -49,12 +50,11 @@ public class AppSettingsActivity extends ActionBarActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// let the actionbar look like Android's contact app // let the actionbar look like Android's contact app
ActionBar actionBar = getSupportActionBar(); // ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true); // actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(android.R.color.transparent); // actionBar.setIcon(android.R.color.transparent);
actionBar.setHomeButtonEnabled(true); // actionBar.setHomeButtonEnabled(true);
setContentView(R.layout.api_app_settings_activity);
mSettingsFragment = (AppSettingsFragment) getSupportFragmentManager().findFragmentById( mSettingsFragment = (AppSettingsFragment) getSupportFragmentManager().findFragmentById(
R.id.api_app_settings_fragment); R.id.api_app_settings_fragment);
@ -71,6 +71,11 @@ public class AppSettingsActivity extends ActionBarActivity {
} }
} }
@Override
protected void initLayout() {
setContentView(R.layout.api_app_settings_activity);
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);

View File

@ -32,8 +32,8 @@ public class AppsListActivity extends DrawerActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.api_apps_list_activity; setContentView(R.layout.api_apps_list_activity);
} }
} }

View File

@ -39,6 +39,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.remote.AccountSettings; import org.sufficientlysecure.keychain.remote.AccountSettings;
import org.sufficientlysecure.keychain.remote.AppSettings; import org.sufficientlysecure.keychain.remote.AppSettings;
import org.sufficientlysecure.keychain.ui.BaseActivity;
import org.sufficientlysecure.keychain.ui.SelectPublicKeyFragment; import org.sufficientlysecure.keychain.ui.SelectPublicKeyFragment;
import org.sufficientlysecure.keychain.ui.util.ActionBarHelper; import org.sufficientlysecure.keychain.ui.util.ActionBarHelper;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
@ -46,7 +47,7 @@ import org.sufficientlysecure.keychain.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
public class RemoteServiceActivity extends ActionBarActivity { public class RemoteServiceActivity extends BaseActivity {
public static final String ACTION_REGISTER = Constants.INTENT_PREFIX + "API_ACTIVITY_REGISTER"; public static final String ACTION_REGISTER = Constants.INTENT_PREFIX + "API_ACTIVITY_REGISTER";
public static final String ACTION_CREATE_ACCOUNT = Constants.INTENT_PREFIX public static final String ACTION_CREATE_ACCOUNT = Constants.INTENT_PREFIX
@ -96,6 +97,11 @@ public class RemoteServiceActivity extends ActionBarActivity {
handleActions(getIntent(), savedInstanceState); handleActions(getIntent(), savedInstanceState);
} }
@Override
protected void initLayout() {
// done in handleActions()
}
protected void handleActions(Intent intent, Bundle savedInstanceState) { protected void handleActions(Intent intent, Bundle savedInstanceState) {
String action = intent.getAction(); String action = intent.getAction();
@ -108,6 +114,7 @@ public class RemoteServiceActivity extends ActionBarActivity {
Log.d(Constants.TAG, "ACTION_REGISTER packageName: " + packageName); Log.d(Constants.TAG, "ACTION_REGISTER packageName: " + packageName);
setContentView(R.layout.api_remote_register_app); setContentView(R.layout.api_remote_register_app);
initToolbar();
mAppSettingsFragment = (AppSettingsFragment) getSupportFragmentManager().findFragmentById( mAppSettingsFragment = (AppSettingsFragment) getSupportFragmentManager().findFragmentById(
R.id.api_app_settings_fragment); R.id.api_app_settings_fragment);
@ -145,6 +152,7 @@ public class RemoteServiceActivity extends ActionBarActivity {
final String accName = extras.getString(EXTRA_ACC_NAME); final String accName = extras.getString(EXTRA_ACC_NAME);
setContentView(R.layout.api_remote_create_account); setContentView(R.layout.api_remote_create_account);
initToolbar();
mAccSettingsFragment = (AccountSettingsFragment) getSupportFragmentManager().findFragmentById( mAccSettingsFragment = (AccountSettingsFragment) getSupportFragmentManager().findFragmentById(
R.id.api_account_settings_fragment); R.id.api_account_settings_fragment);
@ -248,6 +256,9 @@ public class RemoteServiceActivity extends ActionBarActivity {
} }
} }
setContentView(R.layout.api_remote_select_pub_keys);
initToolbar();
// Inflate a "Done"/"Cancel" custom action bar view // Inflate a "Done"/"Cancel" custom action bar view
ActionBarHelper.setTwoButtonView(getSupportActionBar(), ActionBarHelper.setTwoButtonView(getSupportActionBar(),
R.string.btn_okay, R.drawable.ic_action_done, R.string.btn_okay, R.drawable.ic_action_done,
@ -272,7 +283,6 @@ public class RemoteServiceActivity extends ActionBarActivity {
} }
); );
setContentView(R.layout.api_remote_select_pub_keys);
// set text on view // set text on view
TextView textView = (TextView) findViewById(R.id.api_select_pub_keys_text); TextView textView = (TextView) findViewById(R.id.api_select_pub_keys_text);
@ -303,6 +313,9 @@ public class RemoteServiceActivity extends ActionBarActivity {
Spannable redErrorMessage = new SpannableString(errorMessage); Spannable redErrorMessage = new SpannableString(errorMessage);
redErrorMessage.setSpan(new ForegroundColorSpan(Color.RED), 0, errorMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); redErrorMessage.setSpan(new ForegroundColorSpan(Color.RED), 0, errorMessage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
setContentView(R.layout.api_remote_error_message);
initToolbar();
// Inflate a "Done" custom action bar view // Inflate a "Done" custom action bar view
ActionBarHelper.setOneButtonView(getSupportActionBar(), ActionBarHelper.setOneButtonView(getSupportActionBar(),
R.string.btn_okay, R.drawable.ic_action_done, R.string.btn_okay, R.drawable.ic_action_done,
@ -316,8 +329,6 @@ public class RemoteServiceActivity extends ActionBarActivity {
} }
); );
setContentView(R.layout.api_remote_error_message);
// set text on view // set text on view
TextView textView = (TextView) findViewById(R.id.api_app_error_message_text); TextView textView = (TextView) findViewById(R.id.api_app_error_message_text);
textView.setText(redErrorMessage); textView.setText(redErrorMessage);

View File

@ -32,7 +32,13 @@ public abstract class BaseActivity extends ActionBarActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(getLayoutResource()); initLayout();
initToolbar();
}
protected abstract void initLayout();
protected void initToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) { if (toolbar != null) {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
@ -40,8 +46,6 @@ public abstract class BaseActivity extends ActionBarActivity {
} }
} }
protected abstract int getLayoutResource();
protected void setActionBarIcon(int iconRes) { protected void setActionBarIcon(int iconRes) {
toolbar.setNavigationIcon(iconRes); toolbar.setNavigationIcon(iconRes);
} }

View File

@ -33,8 +33,8 @@ public class CertifyKeyActivity extends BaseActivity {
public static final String EXTRA_CERTIFY_KEY_ID = "certify_key_id"; public static final String EXTRA_CERTIFY_KEY_ID = "certify_key_id";
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.certify_key_activity; setContentView(R.layout.certify_key_activity);
} }
} }

View File

@ -47,8 +47,8 @@ public class CreateKeyActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.create_key_activity; setContentView(R.layout.create_key_activity);
} }
public void loadFragment(Bundle savedInstanceState, Fragment fragment, int action) { public void loadFragment(Bundle savedInstanceState, Fragment fragment, int action) {

View File

@ -65,8 +65,8 @@ public class DecryptActivity extends DrawerActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.decrypt_activity; setContentView(R.layout.decrypt_activity);
} }
@TargetApi(VERSION_CODES.HONEYCOMB) @TargetApi(VERSION_CODES.HONEYCOMB)

View File

@ -96,9 +96,8 @@ public abstract class DrawerActivity extends BaseActivity {
// enable ActionBar app icon to behave as action to toggle nav drawer // enable ActionBar app icon to behave as action to toggle nav drawer
// if the drawer is not locked // if the drawer is not locked
if (!mIsDrawerLocked) { if (!mIsDrawerLocked) {
// TODO getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true);
// getSupportActionBar().setHomeButtonEnabled(true);
} }
// ActionBarDrawerToggle ties together the the proper interactions // ActionBarDrawerToggle ties together the the proper interactions

View File

@ -48,8 +48,8 @@ public class EditKeyActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.edit_key_activity; setContentView(R.layout.edit_key_activity);
} }
private void loadFragment(Bundle savedInstanceState, Uri dataUri, SaveKeyringParcel saveKeyringParcel) { private void loadFragment(Bundle savedInstanceState, Uri dataUri, SaveKeyringParcel saveKeyringParcel) {

View File

@ -326,8 +326,8 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.encrypt_files_activity; setContentView(R.layout.encrypt_files_activity);
} }
@Override @Override

View File

@ -303,8 +303,8 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.encrypt_text_activity; setContentView(R.layout.encrypt_text_activity);
} }
@Override @Override

View File

@ -73,8 +73,8 @@ public class FirstTimeActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.first_time_activity; setContentView(R.layout.first_time_activity);
} }
@Override @Override

View File

@ -98,7 +98,7 @@ public class HelpActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.help_activity; setContentView(R.layout.help_activity);
} }
} }

View File

@ -102,8 +102,8 @@ public class ImportKeysActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.import_keys_activity; setContentView(R.layout.import_keys_activity);
} }
protected void handleActions(Bundle savedInstanceState, Intent intent) { protected void handleActions(Bundle savedInstanceState, Intent intent) {

View File

@ -65,12 +65,12 @@ public class KeyListActivity extends DrawerActivity {
mExportHelper = new ExportHelper(this); mExportHelper = new ExportHelper(this);
// now setup navigation drawer in DrawerActivity... // now setup navigation drawer in DrawerActivity...
// activateDrawerNavigation(savedInstanceState); activateDrawerNavigation(savedInstanceState);
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.key_list_activity; setContentView(R.layout.key_list_activity);
} }
@Override @Override

View File

@ -45,8 +45,8 @@ public class LogDisplayActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.log_display_activity; setContentView(R.layout.log_display_activity);
} }
} }

View File

@ -122,8 +122,8 @@ public class NfcActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.nfc_activity; setContentView(R.layout.nfc_activity);
} }
/** /**

View File

@ -88,8 +88,8 @@ public class NfcIntentActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.nfc_activity; setContentView(R.layout.nfc_activity);
} }
/** /**

View File

@ -107,8 +107,8 @@ public class QrCodeViewActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.qr_code_activity; setContentView(R.layout.qr_code_activity);
} }
@Override @Override

View File

@ -95,8 +95,8 @@ public class SafeSlingerActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.safe_slinger_activity; setContentView(R.layout.safe_slinger_activity);
} }
private void startExchange(long masterKeyId, int number) { private void startExchange(long masterKeyId, int number) {

View File

@ -100,8 +100,8 @@ public class SelectPublicKeyActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.select_public_key_activity; setContentView(R.layout.select_public_key_activity);
} }
@Override @Override

View File

@ -85,8 +85,8 @@ public class UploadKeyActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.upload_key_activity; setContentView(R.layout.upload_key_activity);
} }
private void uploadKey() { private void uploadKey() {

View File

@ -111,8 +111,8 @@ public class ViewCertActivity extends BaseActivity
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.view_cert_activity; setContentView(R.layout.view_cert_activity);
} }
@Override @Override

View File

@ -168,8 +168,8 @@ public class ViewKeyActivity extends BaseActivity implements
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.view_key_activity; setContentView(R.layout.view_key_activity);
} }
private void initTabs(Uri dataUri) { private void initTabs(Uri dataUri) {

View File

@ -68,11 +68,10 @@ public class ViewKeyAdvancedActivity extends BaseActivity {
} }
@Override @Override
protected int getLayoutResource() { protected void initLayout() {
return R.layout.view_key_advanced_activity; setContentView(R.layout.view_key_advanced_activity);
} }
private void startFragment(Bundle savedInstanceState, Uri dataUri) { private void startFragment(Bundle savedInstanceState, Uri dataUri) {
// However, if we're being restored from a previous state, // However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else // then we don't need to do anything and should return or else