Resolve crashes on Android 2.3 due to ActionBarCompat conversion

This commit is contained in:
Dominik Schürmann 2014-02-02 14:30:40 +01:00
parent 6eaf45940e
commit ef1401fc0d
11 changed files with 209 additions and 217 deletions

View File

@ -55,6 +55,8 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.support.v4.view.MenuCompat;
import android.support.v4.view.MenuItemCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -127,12 +129,12 @@ public class DecryptActivity extends DrawerActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (mDecryptEnabled) {
menu.add(1, Id.menu.option.decrypt, 0, mDecryptString).setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
MenuItem item = menu.add(1, Id.menu.option.decrypt, 0, mDecryptString);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
}
if (mReplyEnabled) {
menu.add(1, Id.menu.option.reply, 1, mReplyString).setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
MenuItem item = menu.add(1, Id.menu.option.reply, 1, mReplyString);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
}
return true;
@ -281,7 +283,7 @@ public class DecryptActivity extends DrawerActivity {
mReplyEnabled = false;
// build new actionbar
invalidateOptionsMenu();
supportInvalidateOptionsMenu();
if (mReturnResult) {
mSourcePrevious.setClickable(false);
@ -372,7 +374,7 @@ public class DecryptActivity extends DrawerActivity {
mDecryptString = getString(R.string.btn_verify);
// build new action bar
invalidateOptionsMenu();
supportInvalidateOptionsMenu();
} else {
Log.d(Constants.TAG, "Nothing matched!");
}
@ -421,7 +423,7 @@ public class DecryptActivity extends DrawerActivity {
mDecryptString = getString(R.string.btn_decrypt);
// build new action bar
invalidateOptionsMenu();
supportInvalidateOptionsMenu();
break;
}
@ -430,7 +432,7 @@ public class DecryptActivity extends DrawerActivity {
mDecryptString = getString(R.string.btn_decrypt);
// build new action bar
invalidateOptionsMenu();
supportInvalidateOptionsMenu();
break;
}
@ -723,7 +725,7 @@ public class DecryptActivity extends DrawerActivity {
mReplyEnabled = false;
// build new action bar
invalidateOptionsMenu();
supportInvalidateOptionsMenu();
Toast.makeText(DecryptActivity.this, R.string.decryption_successful,
Toast.LENGTH_SHORT).show();
@ -744,7 +746,7 @@ public class DecryptActivity extends DrawerActivity {
mReplyEnabled = false;
// build new action bar
invalidateOptionsMenu();
supportInvalidateOptionsMenu();
break;
case Id.target.file:

View File

@ -51,6 +51,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.support.v4.view.MenuItemCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -131,18 +132,16 @@ public class EncryptActivity extends DrawerActivity {
/**
* ActionBar menu is created based on class variables to change it at runtime
*
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (mEncryptToClipboardEnabled) {
menu.add(1, Id.menu.option.encrypt_to_clipboard, 0, mEncryptToClipboardString)
.setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
MenuItem item = menu.add(1, Id.menu.option.encrypt_to_clipboard, 0, mEncryptToClipboardString);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
}
if (mEncryptEnabled) {
menu.add(1, Id.menu.option.encrypt, 1, mEncryptString).setShowAsAction(
MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
MenuItem item = menu.add(1, Id.menu.option.encrypt, 1, mEncryptString);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
}
return true;
@ -152,18 +151,18 @@ public class EncryptActivity extends DrawerActivity {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case Id.menu.option.encrypt_to_clipboard:
encryptToClipboardClicked();
case Id.menu.option.encrypt_to_clipboard:
encryptToClipboardClicked();
return true;
return true;
case Id.menu.option.encrypt:
encryptClicked();
case Id.menu.option.encrypt:
encryptClicked();
return true;
return true;
default:
return super.onOptionsItemSelected(item);
default:
return super.onOptionsItemSelected(item);
}
}
@ -350,19 +349,19 @@ public class EncryptActivity extends DrawerActivity {
private void updateSource() {
switch (mSource.getCurrentView().getId()) {
case R.id.sourceFile: {
mSourceLabel.setText(R.string.label_file);
break;
}
case R.id.sourceFile: {
mSourceLabel.setText(R.string.label_file);
break;
}
case R.id.sourceMessage: {
mSourceLabel.setText(R.string.label_message);
break;
}
case R.id.sourceMessage: {
mSourceLabel.setText(R.string.label_message);
break;
}
default: {
break;
}
default: {
break;
}
}
updateActionBarButtons();
}
@ -377,7 +376,7 @@ public class EncryptActivity extends DrawerActivity {
*/
@SuppressLint("NewApi")
private void setActionbarButtons(boolean encryptEnabled, int encryptStringRes,
boolean encryptToClipboardEnabled, int encryptToClipboardStringRes) {
boolean encryptToClipboardEnabled, int encryptToClipboardStringRes) {
mEncryptEnabled = encryptEnabled;
if (encryptEnabled) {
mEncryptString = getString(encryptStringRes);
@ -388,7 +387,7 @@ public class EncryptActivity extends DrawerActivity {
}
// build new action bar based on these class variables
invalidateOptionsMenu();
supportInvalidateOptionsMenu();
}
/**
@ -396,56 +395,56 @@ public class EncryptActivity extends DrawerActivity {
*/
private void updateActionBarButtons() {
switch (mSource.getCurrentView().getId()) {
case R.id.sourceFile: {
setActionbarButtons(true, R.string.btn_encrypt_file, false, 0);
case R.id.sourceFile: {
setActionbarButtons(true, R.string.btn_encrypt_file, false, 0);
break;
}
break;
}
case R.id.sourceMessage: {
mSourceLabel.setText(R.string.label_message);
case R.id.sourceMessage: {
mSourceLabel.setText(R.string.label_message);
if (mMode.getCurrentView().getId() == R.id.modeSymmetric) {
setActionbarButtons(true, R.string.btn_encrypt_and_send, true,
R.string.btn_encrypt_to_clipboard);
} else {
if (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0) {
if (mSecretKeyId == 0) {
setActionbarButtons(false, 0, false, 0);
} else {
setActionbarButtons(true, R.string.btn_sign_and_send, true,
R.string.btn_sign_to_clipboard);
}
} else {
if (mMode.getCurrentView().getId() == R.id.modeSymmetric) {
setActionbarButtons(true, R.string.btn_encrypt_and_send, true,
R.string.btn_encrypt_to_clipboard);
} else {
if (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0) {
if (mSecretKeyId == 0) {
setActionbarButtons(false, 0, false, 0);
} else {
setActionbarButtons(true, R.string.btn_sign_and_send, true,
R.string.btn_sign_to_clipboard);
}
} else {
setActionbarButtons(true, R.string.btn_encrypt_and_send, true,
R.string.btn_encrypt_to_clipboard);
}
}
break;
}
break;
}
default: {
break;
}
default: {
break;
}
}
}
private void updateMode() {
switch (mMode.getCurrentView().getId()) {
case R.id.modeAsymmetric: {
mModeLabel.setText(R.string.label_asymmetric);
break;
}
case R.id.modeAsymmetric: {
mModeLabel.setText(R.string.label_asymmetric);
break;
}
case R.id.modeSymmetric: {
mModeLabel.setText(R.string.label_symmetric);
break;
}
case R.id.modeSymmetric: {
mModeLabel.setText(R.string.label_symmetric);
break;
}
default: {
break;
}
default: {
break;
}
}
updateActionBarButtons();
}
@ -675,50 +674,52 @@ public class EncryptActivity extends DrawerActivity {
String output;
switch (mEncryptTarget) {
case Id.target.clipboard:
output = data.getString(KeychainIntentService.RESULT_ENCRYPTED_STRING);
Log.d(Constants.TAG, "output: " + output);
ClipboardReflection.copyToClipboard(EncryptActivity.this, output);
Toast.makeText(EncryptActivity.this,
R.string.encryption_to_clipboard_successful, Toast.LENGTH_SHORT)
.show();
break;
case Id.target.clipboard:
output = data.getString(KeychainIntentService.RESULT_ENCRYPTED_STRING);
Log.d(Constants.TAG, "output: " + output);
ClipboardReflection.copyToClipboard(EncryptActivity.this, output);
Toast.makeText(EncryptActivity.this,
R.string.encryption_to_clipboard_successful, Toast.LENGTH_SHORT)
.show();
break;
case Id.target.email:
case Id.target.email:
output = data.getString(KeychainIntentService.RESULT_ENCRYPTED_STRING);
Log.d(Constants.TAG, "output: " + output);
output = data.getString(KeychainIntentService.RESULT_ENCRYPTED_STRING);
Log.d(Constants.TAG, "output: " + output);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
// Type is set to text/plain so that encrypted messages can
// be sent with Whatsapp, Hangouts, SMS etc...
sendIntent.setType("text/plain");
// Type is set to text/plain so that encrypted messages can
// be sent with Whatsapp, Hangouts, SMS etc...
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, output);
startActivity(Intent.createChooser(sendIntent,
getString(R.string.title_send_email)));
break;
sendIntent.putExtra(Intent.EXTRA_TEXT, output);
startActivity(Intent.createChooser(sendIntent,
getString(R.string.title_send_email)));
break;
case Id.target.file:
Toast.makeText(EncryptActivity.this, R.string.encryption_successful,
Toast.LENGTH_SHORT).show();
case Id.target.file:
Toast.makeText(EncryptActivity.this, R.string.encryption_successful,
Toast.LENGTH_SHORT).show();
if (mDeleteAfter.isChecked()) {
// Create and show dialog to delete original file
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
.newInstance(mInputFilename);
deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
}
break;
if (mDeleteAfter.isChecked()) {
// Create and show dialog to delete original file
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
.newInstance(mInputFilename);
deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
}
break;
default:
// shouldn't happen
break;
default:
// shouldn't happen
break;
}
}
};
}
;
};
// Create a new Messenger for the communication back
@ -844,7 +845,7 @@ public class EncryptActivity extends DrawerActivity {
});
mFileCompression = (Spinner) findViewById(R.id.fileCompression);
Choice[] choices = new Choice[] {
Choice[] choices = new Choice[]{
new Choice(Id.choice.compression.none, getString(R.string.choice_none) + " ("
+ getString(R.string.compression_fast) + ")"),
new Choice(Id.choice.compression.zip, "ZIP ("
@ -852,7 +853,7 @@ public class EncryptActivity extends DrawerActivity {
new Choice(Id.choice.compression.zlib, "ZLIB ("
+ getString(R.string.compression_fast) + ")"),
new Choice(Id.choice.compression.bzip2, "BZIP2 ("
+ getString(R.string.compression_very_slow) + ")"), };
+ getString(R.string.compression_very_slow) + ")"),};
ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(this,
android.R.layout.simple_spinner_item, choices);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
@ -957,44 +958,44 @@ public class EncryptActivity extends DrawerActivity {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case Id.request.filename: {
if (resultCode == RESULT_OK && data != null) {
try {
String path = FileHelper.getPath(this, data.getData());
Log.d(Constants.TAG, "path=" + path);
case Id.request.filename: {
if (resultCode == RESULT_OK && data != null) {
try {
String path = FileHelper.getPath(this, data.getData());
Log.d(Constants.TAG, "path=" + path);
mFilename.setText(path);
} catch (NullPointerException e) {
Log.e(Constants.TAG, "Nullpointer while retrieving path!");
mFilename.setText(path);
} catch (NullPointerException e) {
Log.e(Constants.TAG, "Nullpointer while retrieving path!");
}
}
return;
}
return;
}
case Id.request.public_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
mEncryptionKeyIds = bundle
.getLongArray(SelectPublicKeyActivity.RESULT_EXTRA_MASTER_KEY_IDS);
case Id.request.public_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
mEncryptionKeyIds = bundle
.getLongArray(SelectPublicKeyActivity.RESULT_EXTRA_MASTER_KEY_IDS);
}
updateView();
break;
}
updateView();
break;
}
case Id.request.secret_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
mSecretKeyId = bundle.getLong(SelectSecretKeyActivity.RESULT_EXTRA_MASTER_KEY_ID);
} else {
mSecretKeyId = Id.key.none;
case Id.request.secret_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
mSecretKeyId = bundle.getLong(SelectSecretKeyActivity.RESULT_EXTRA_MASTER_KEY_ID);
} else {
mSecretKeyId = Id.key.none;
}
updateView();
break;
}
updateView();
break;
}
default: {
break;
}
default: {
break;
}
}
super.onActivityResult(requestCode, resultCode, data);

View File

@ -3,8 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical" >
<fragment

View File

@ -1,20 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"

View File

@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_api_settings_revoke"
android:showAsAction="never"
android:title="@string/api_settings_revoke"/>
android:title="@string/api_settings_revoke"
app:showAsAction="never" />
<item
android:id="@+id/menu_api_settings_cancel"
android:showAsAction="never"
android:title="@string/api_settings_cancel"/>
android:title="@string/api_settings_cancel"
app:showAsAction="never" />
</menu>

View File

@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_key_edit_export_file"
android:showAsAction="never"
android:title="@string/menu_export_key"/>
app:showAsAction="never"
android:title="@string/menu_export_key" />
<item
android:id="@+id/menu_key_edit_delete"
android:showAsAction="never"
android:title="@string/menu_delete_key"/>
app:showAsAction="never"
android:title="@string/menu_delete_key" />
<item
android:id="@+id/menu_key_edit_cancel"
android:showAsAction="never"
android:title="@string/menu_key_edit_cancel"/>
app:showAsAction="never"
android:title="@string/menu_key_edit_cancel" />
</menu>

View File

@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_key_list_public_import"
android:showAsAction="always|withText"
app:showAsAction="always|withText"
android:icon="@drawable/ic_action_add_person"
android:title="@string/menu_import"/>
android:title="@string/menu_import" />
<item
android:id="@+id/menu_key_list_public_export"
android:showAsAction="never"
android:title="@string/menu_export_keys"/>
app:showAsAction="never"
android:title="@string/menu_export_keys" />
</menu>

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_key_list_public_multi_encrypt"
android:title="@string/menu_encrypt_to"/>
android:title="@string/menu_encrypt_to" />
<item
android:id="@+id/menu_key_list_public_multi_delete"
android:icon="@drawable/ic_action_discard"
android:title="@string/menu_delete_key"/>
android:title="@string/menu_delete_key" />
</menu>

View File

@ -1,21 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_key_list_secret_create"
android:showAsAction="always|withText"
android:title="@string/menu_create_key"/>
app:showAsAction="always|withText"
android:title="@string/menu_create_key" />
<item
android:id="@+id/menu_key_list_secret_create_expert"
android:showAsAction="never"
android:title="@string/menu_create_key_expert"/>
app:showAsAction="never"
android:title="@string/menu_create_key_expert" />
<item
android:id="@+id/menu_key_list_secret_import"
android:showAsAction="never"
android:title="@string/menu_import"/>
app:showAsAction="never"
android:title="@string/menu_import" />
<item
android:id="@+id/menu_key_list_secret_export"
android:showAsAction="never"
android:title="@string/menu_export_keys"/>
app:showAsAction="never"
android:title="@string/menu_export_keys" />
</menu>

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_key_list_public_multi_delete"
android:icon="@drawable/ic_action_discard"
android:title="@string/menu_delete_key"/>
android:title="@string/menu_delete_key" />
</menu>

View File

@ -1,48 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_key_view_share"
android:icon="@drawable/ic_action_share"
android:showAsAction="always"
app:showAsAction="always"
android:title="@string/menu_share">
<menu>
<item
android:id="@+id/menu_key_view_share_fingerprint_title"
android:showAsAction="never"
app:showAsAction="never"
android:title="@string/menu_share_title_fingerprint">
<menu>
<item
android:id="@+id/menu_key_view_share_default_fingerprint"
android:showAsAction="never"
android:title="@string/menu_share_default_fingerprint"/>
app:showAsAction="never"
android:title="@string/menu_share_default_fingerprint" />
<item
android:id="@+id/menu_key_view_share_qr_code_fingerprint"
android:showAsAction="never"
android:title="@string/menu_share_qr_code_fingerprint"/>
app:showAsAction="never"
android:title="@string/menu_share_qr_code_fingerprint" />
</menu>
</item>
<item
android:id="@+id/menu_key_view_share_title"
android:showAsAction="never"
app:showAsAction="never"
android:title="@string/menu_share_title">
<menu>
<item
android:id="@+id/menu_key_view_share_default"
android:showAsAction="never"
android:title="@string/menu_share_default"/>
app:showAsAction="never"
android:title="@string/menu_share_default" />
<item
android:id="@+id/menu_key_view_share_qr_code"
android:showAsAction="never"
android:title="@string/menu_share_qr_code"/>
app:showAsAction="never"
android:title="@string/menu_share_qr_code" />
<item
android:id="@+id/menu_key_view_share_nfc"
android:showAsAction="never"
android:title="@string/menu_share_nfc"/>
app:showAsAction="never"
android:title="@string/menu_share_nfc" />
<item
android:id="@+id/menu_key_view_share_clipboard"
android:showAsAction="never"
android:title="@string/menu_copy_to_clipboard"/>
app:showAsAction="never"
android:title="@string/menu_copy_to_clipboard" />
</menu>
</item>
</menu>
@ -50,30 +51,30 @@
<item
android:id="@+id/menu_key_keyserver"
android:icon="@drawable/ic_action_import_export"
android:showAsAction="always"
app:showAsAction="always"
android:title="@string/menu_share">
<menu>
<item
android:id="@+id/menu_key_view_update"
android:showAsAction="never"
android:title="@string/menu_update_key"/>
app:showAsAction="never"
android:title="@string/menu_update_key" />
<item
android:id="@+id/menu_key_view_export_keyserver"
android:showAsAction="never"
android:title="@string/menu_export_key_to_server"/>
app:showAsAction="never"
android:title="@string/menu_export_key_to_server" />
</menu>
</item>
<item
android:id="@+id/menu_key_view_sign"
android:showAsAction="ifRoom"
android:title="@string/menu_sign_key"/>
app:showAsAction="ifRoom"
android:title="@string/menu_sign_key" />
<item
android:id="@+id/menu_key_view_export_file"
android:showAsAction="never"
android:title="@string/menu_export_key"/>
app:showAsAction="never"
android:title="@string/menu_export_key" />
<item
android:id="@+id/menu_key_view_delete"
android:showAsAction="never"
android:title="@string/menu_delete_key"/>
app:showAsAction="never"
android:title="@string/menu_delete_key" />
</menu>