mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-15 05:15:03 -05:00
Refactor BaseActivity
This commit is contained in:
parent
d8ff737fc5
commit
7da3ddae7b
@ -27,6 +27,7 @@ import android.view.View;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.BaseActivity;
|
||||
import org.sufficientlysecure.keychain.ui.util.ActionBarHelper;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
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.util.Log;
|
||||
|
||||
public class AccountSettingsActivity extends ActionBarActivity {
|
||||
public class AccountSettingsActivity extends BaseActivity {
|
||||
private Uri mAccountUri;
|
||||
|
||||
private AccountSettingsFragment mAccountSettingsFragment;
|
||||
@ -55,7 +56,6 @@ public class AccountSettingsActivity extends ActionBarActivity {
|
||||
}
|
||||
});
|
||||
|
||||
setContentView(R.layout.api_account_settings_activity);
|
||||
|
||||
mAccountSettingsFragment = (AccountSettingsFragment) getSupportFragmentManager().findFragmentById(
|
||||
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
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
|
@ -33,9 +33,10 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.remote.AppSettings;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.ui.BaseActivity;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
public class AppSettingsActivity extends ActionBarActivity {
|
||||
public class AppSettingsActivity extends BaseActivity {
|
||||
private Uri mAppUri;
|
||||
|
||||
private AppSettingsFragment mSettingsFragment;
|
||||
@ -49,12 +50,11 @@ public class AppSettingsActivity extends ActionBarActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// let the actionbar look like Android's contact app
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setIcon(android.R.color.transparent);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
// ActionBar actionBar = getSupportActionBar();
|
||||
// actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
// actionBar.setIcon(android.R.color.transparent);
|
||||
// actionBar.setHomeButtonEnabled(true);
|
||||
|
||||
setContentView(R.layout.api_app_settings_activity);
|
||||
|
||||
mSettingsFragment = (AppSettingsFragment) getSupportFragmentManager().findFragmentById(
|
||||
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
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
|
@ -32,8 +32,8 @@ public class AppsListActivity extends DrawerActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.api_apps_list_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.api_apps_list_activity);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.remote.AccountSettings;
|
||||
import org.sufficientlysecure.keychain.remote.AppSettings;
|
||||
import org.sufficientlysecure.keychain.ui.BaseActivity;
|
||||
import org.sufficientlysecure.keychain.ui.SelectPublicKeyFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.ActionBarHelper;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
@ -46,7 +47,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
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_CREATE_ACCOUNT = Constants.INTENT_PREFIX
|
||||
@ -96,6 +97,11 @@ public class RemoteServiceActivity extends ActionBarActivity {
|
||||
handleActions(getIntent(), savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initLayout() {
|
||||
// done in handleActions()
|
||||
}
|
||||
|
||||
protected void handleActions(Intent intent, Bundle savedInstanceState) {
|
||||
|
||||
String action = intent.getAction();
|
||||
@ -108,6 +114,7 @@ public class RemoteServiceActivity extends ActionBarActivity {
|
||||
Log.d(Constants.TAG, "ACTION_REGISTER packageName: " + packageName);
|
||||
|
||||
setContentView(R.layout.api_remote_register_app);
|
||||
initToolbar();
|
||||
|
||||
mAppSettingsFragment = (AppSettingsFragment) getSupportFragmentManager().findFragmentById(
|
||||
R.id.api_app_settings_fragment);
|
||||
@ -145,6 +152,7 @@ public class RemoteServiceActivity extends ActionBarActivity {
|
||||
final String accName = extras.getString(EXTRA_ACC_NAME);
|
||||
|
||||
setContentView(R.layout.api_remote_create_account);
|
||||
initToolbar();
|
||||
|
||||
mAccSettingsFragment = (AccountSettingsFragment) getSupportFragmentManager().findFragmentById(
|
||||
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
|
||||
ActionBarHelper.setTwoButtonView(getSupportActionBar(),
|
||||
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
|
||||
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);
|
||||
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
|
||||
ActionBarHelper.setOneButtonView(getSupportActionBar(),
|
||||
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
|
||||
TextView textView = (TextView) findViewById(R.id.api_app_error_message_text);
|
||||
textView.setText(redErrorMessage);
|
||||
|
@ -32,7 +32,13 @@ public abstract class BaseActivity extends ActionBarActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getLayoutResource());
|
||||
initLayout();
|
||||
initToolbar();
|
||||
}
|
||||
|
||||
protected abstract void initLayout();
|
||||
|
||||
protected void initToolbar() {
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
@ -40,8 +46,6 @@ public abstract class BaseActivity extends ActionBarActivity {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract int getLayoutResource();
|
||||
|
||||
protected void setActionBarIcon(int iconRes) {
|
||||
toolbar.setNavigationIcon(iconRes);
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ public class CertifyKeyActivity extends BaseActivity {
|
||||
public static final String EXTRA_CERTIFY_KEY_ID = "certify_key_id";
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.certify_key_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.certify_key_activity);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ public class CreateKeyActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.create_key_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.create_key_activity);
|
||||
}
|
||||
|
||||
public void loadFragment(Bundle savedInstanceState, Fragment fragment, int action) {
|
||||
|
@ -65,8 +65,8 @@ public class DecryptActivity extends DrawerActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.decrypt_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.decrypt_activity);
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB)
|
||||
|
@ -96,9 +96,8 @@ public abstract class DrawerActivity extends BaseActivity {
|
||||
// enable ActionBar app icon to behave as action to toggle nav drawer
|
||||
// if the drawer is not locked
|
||||
if (!mIsDrawerLocked) {
|
||||
// TODO
|
||||
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
// getSupportActionBar().setHomeButtonEnabled(true);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
}
|
||||
|
||||
// ActionBarDrawerToggle ties together the the proper interactions
|
||||
|
@ -48,8 +48,8 @@ public class EditKeyActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.edit_key_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.edit_key_activity);
|
||||
}
|
||||
|
||||
private void loadFragment(Bundle savedInstanceState, Uri dataUri, SaveKeyringParcel saveKeyringParcel) {
|
||||
|
@ -326,8 +326,8 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.encrypt_files_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.encrypt_files_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -303,8 +303,8 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.encrypt_text_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.encrypt_text_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,8 +73,8 @@ public class FirstTimeActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.first_time_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.first_time_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,7 +98,7 @@ public class HelpActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.help_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.help_activity);
|
||||
}
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ public class ImportKeysActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.import_keys_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.import_keys_activity);
|
||||
}
|
||||
|
||||
protected void handleActions(Bundle savedInstanceState, Intent intent) {
|
||||
|
@ -65,12 +65,12 @@ public class KeyListActivity extends DrawerActivity {
|
||||
mExportHelper = new ExportHelper(this);
|
||||
|
||||
// now setup navigation drawer in DrawerActivity...
|
||||
// activateDrawerNavigation(savedInstanceState);
|
||||
activateDrawerNavigation(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.key_list_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.key_list_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,8 +45,8 @@ public class LogDisplayActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.log_display_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.log_display_activity);
|
||||
}
|
||||
|
||||
}
|
@ -122,8 +122,8 @@ public class NfcActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.nfc_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.nfc_activity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,8 +88,8 @@ public class NfcIntentActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.nfc_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.nfc_activity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,8 +107,8 @@ public class QrCodeViewActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.qr_code_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.qr_code_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,8 +95,8 @@ public class SafeSlingerActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.safe_slinger_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.safe_slinger_activity);
|
||||
}
|
||||
|
||||
private void startExchange(long masterKeyId, int number) {
|
||||
|
@ -100,8 +100,8 @@ public class SelectPublicKeyActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.select_public_key_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.select_public_key_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,8 +85,8 @@ public class UploadKeyActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.upload_key_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.upload_key_activity);
|
||||
}
|
||||
|
||||
private void uploadKey() {
|
||||
|
@ -111,8 +111,8 @@ public class ViewCertActivity extends BaseActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.view_cert_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.view_cert_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -168,8 +168,8 @@ public class ViewKeyActivity extends BaseActivity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.view_key_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.view_key_activity);
|
||||
}
|
||||
|
||||
private void initTabs(Uri dataUri) {
|
||||
|
@ -68,11 +68,10 @@ public class ViewKeyAdvancedActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResource() {
|
||||
return R.layout.view_key_advanced_activity;
|
||||
protected void initLayout() {
|
||||
setContentView(R.layout.view_key_advanced_activity);
|
||||
}
|
||||
|
||||
|
||||
private void startFragment(Bundle savedInstanceState, Uri dataUri) {
|
||||
// However, if we're being restored from a previous state,
|
||||
// then we don't need to do anything and should return or else
|
||||
|
Loading…
Reference in New Issue
Block a user