Replace some deprecated code (SDK 26)

This commit is contained in:
Jakob Nixdorf 2017-08-23 10:49:13 +02:00
parent 878dab427e
commit f0518a265c
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
9 changed files with 74 additions and 80 deletions

View file

@ -70,16 +70,16 @@ public class AboutActivity extends BaseActivity {
setTitle(R.string.about_activity_title);
setContentView(R.layout.activity_container);
Toolbar toolbar = (Toolbar) findViewById(R.id.container_toolbar);
Toolbar toolbar = findViewById(R.id.container_toolbar);
setSupportActionBar(toolbar);
ViewStub stub = (ViewStub) findViewById(R.id.container_stub);
ViewStub stub = findViewById(R.id.container_stub);
stub.setLayoutResource(R.layout.content_about);
View v = stub.inflate();
ColorFilter filter = ThemeHelper.getThemeColorFilter(this, android.R.attr.textColorSecondary);
for (int i : imageResources) {
ImageView imgView = (ImageView) v.findViewById(i);
ImageView imgView = v.findViewById(i);
imgView.getDrawable().setColorFilter(filter);
}
@ -91,13 +91,13 @@ public class AboutActivity extends BaseActivity {
e.printStackTrace();
}
TextView version = (TextView) v.findViewById(R.id.about_text_version);
TextView version = v.findViewById(R.id.about_text_version);
version.setText(versionName);
LinearLayout license = (LinearLayout) v.findViewById(R.id.about_layout_license);
LinearLayout changelog = (LinearLayout) v.findViewById(R.id.about_layout_changelog);
LinearLayout source = (LinearLayout) v.findViewById(R.id.about_layout_source);
LinearLayout licenses = (LinearLayout) v.findViewById(R.id.about_layout_licenses);
LinearLayout license = v.findViewById(R.id.about_layout_license);
LinearLayout changelog = v.findViewById(R.id.about_layout_changelog);
LinearLayout source = v.findViewById(R.id.about_layout_source);
LinearLayout licenses = v.findViewById(R.id.about_layout_licenses);
license.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -123,8 +123,8 @@ public class AboutActivity extends BaseActivity {
}
});
TextView author1GitHub = (TextView) v.findViewById(R.id.about_author1_github);
TextView author1Paypal = (TextView) v.findViewById(R.id.about_author1_paypal);
TextView author1GitHub = v.findViewById(R.id.about_author1_github);
TextView author1Paypal = v.findViewById(R.id.about_author1_paypal);
author1GitHub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -138,8 +138,8 @@ public class AboutActivity extends BaseActivity {
}
});
TextView author2GitHub = (TextView) v.findViewById(R.id.about_author2_github);
TextView author2App = (TextView) v.findViewById(R.id.about_author2_app);
TextView author2GitHub = v.findViewById(R.id.about_author2_github);
TextView author2App = v.findViewById(R.id.about_author2_app);
author2GitHub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -153,8 +153,8 @@ public class AboutActivity extends BaseActivity {
}
});
LinearLayout contributors = (LinearLayout) v.findViewById(R.id.about_layout_contributors);
LinearLayout translators = (LinearLayout) v.findViewById(R.id.about_layout_translators);
LinearLayout contributors = v.findViewById(R.id.about_layout_contributors);
LinearLayout translators = v.findViewById(R.id.about_layout_translators);
contributors.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -168,8 +168,8 @@ public class AboutActivity extends BaseActivity {
}
});
LinearLayout bugReport = (LinearLayout) v.findViewById(R.id.about_layout_bugs);
LinearLayout translate = (LinearLayout) v.findViewById(R.id.about_layout_translate);
LinearLayout bugReport = v.findViewById(R.id.about_layout_bugs);
LinearLayout translate = v.findViewById(R.id.about_layout_translate);
bugReport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

View file

@ -53,17 +53,17 @@ public class AuthenticateActivity extends BaseActivity
setTitle(R.string.auth_activity_title);
setContentView(R.layout.activity_container);
Toolbar toolbar = (Toolbar) findViewById(R.id.container_toolbar);
Toolbar toolbar = findViewById(R.id.container_toolbar);
toolbar.setNavigationIcon(null);
setSupportActionBar(toolbar);
ViewStub stub = (ViewStub) findViewById(R.id.container_stub);
ViewStub stub = findViewById(R.id.container_stub);
stub.setLayoutResource(R.layout.content_authenticate);
View v = stub.inflate();
TextView passwordLabel = (TextView) v.findViewById(R.id.passwordLabel);
TextInputLayout passwordLayout = (TextInputLayout) v.findViewById(R.id.passwordLayout);
TextInputEditText passwordInput = (TextInputEditText) v.findViewById(R.id.passwordEdit);
TextView passwordLabel = v.findViewById(R.id.passwordLabel);
TextInputLayout passwordLayout = v.findViewById(R.id.passwordLayout);
TextInputEditText passwordInput = v.findViewById(R.id.passwordEdit);
AuthMethod authMethod = settings.getAuthMethod();

View file

@ -101,17 +101,17 @@ public class BackupActivity extends BaseActivity {
setTitle(R.string.backup_activity_title);
setContentView(R.layout.activity_container);
Toolbar toolbar = (Toolbar) findViewById(R.id.container_toolbar);
Toolbar toolbar = findViewById(R.id.container_toolbar);
setSupportActionBar(toolbar);
ViewStub stub = (ViewStub) findViewById(R.id.container_stub);
ViewStub stub = findViewById(R.id.container_stub);
stub.setLayoutResource(R.layout.content_backup);
View v = stub.inflate();
// Plain-text
LinearLayout backupPlain = (LinearLayout) v.findViewById(R.id.button_backup_plain);
LinearLayout restorePlain = (LinearLayout) v.findViewById(R.id.button_restore_plain);
LinearLayout backupPlain = v.findViewById(R.id.button_backup_plain);
LinearLayout restorePlain = v.findViewById(R.id.button_restore_plain);
backupPlain.setOnClickListener(new View.OnClickListener() {
@Override
@ -129,9 +129,9 @@ public class BackupActivity extends BaseActivity {
// Password
TextView cryptSetup = (TextView) v.findViewById(R.id.msg_crypt_setup);
LinearLayout backupCrypt = (LinearLayout) v.findViewById(R.id.button_backup_crypt);
LinearLayout restoreCrypt = (LinearLayout) v.findViewById(R.id.button_restore_crypt);
TextView cryptSetup = v.findViewById(R.id.msg_crypt_setup);
LinearLayout backupCrypt = v.findViewById(R.id.button_backup_crypt);
LinearLayout restoreCrypt = v.findViewById(R.id.button_restore_crypt);
if (settings.getBackupPassword().isEmpty()) {
cryptSetup.setVisibility(View.VISIBLE);
@ -162,9 +162,9 @@ public class BackupActivity extends BaseActivity {
String PGPProvider = settings.getOpenPGPProvider();
pgpKeyId = settings.getOpenPGPKey();
TextView setupPGP = (TextView) v.findViewById(R.id.msg_openpgp_setup);
LinearLayout backupPGP = (LinearLayout) v.findViewById(R.id.button_backup_openpgp);
LinearLayout restorePGP = (LinearLayout) v.findViewById(R.id.button_restore_openpgp);
TextView setupPGP = v.findViewById(R.id.msg_openpgp_setup);
LinearLayout backupPGP = v.findViewById(R.id.button_backup_openpgp);
LinearLayout restorePGP = v.findViewById(R.id.button_restore_openpgp);
if (TextUtils.isEmpty(PGPProvider)) {
setupPGP.setVisibility(View.VISIBLE);

View file

@ -32,7 +32,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.constraint.ConstraintLayout;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
@ -60,6 +59,8 @@ import org.shadowice.flocke.andotp.View.ItemTouchHelper.SimpleItemTouchHelperCal
import org.shadowice.flocke.andotp.R;
import org.shadowice.flocke.andotp.Utilities.TokenCalculator;
import java.util.Locale;
import static org.shadowice.flocke.andotp.Utilities.Settings.SortMode;
public class MainActivity extends BaseActivity
@ -86,20 +87,20 @@ public class MainActivity extends BaseActivity
// Manual data entry
private void enterDetails() {
ViewGroup container = (ViewGroup) findViewById(R.id.main_content);
ViewGroup container = findViewById(R.id.main_content);
View inputView = getLayoutInflater().inflate(R.layout.dialog_manual_entry, container, false);
final Spinner typeInput = (Spinner) inputView.findViewById(R.id.manual_type);
final EditText labelInput = (EditText) inputView.findViewById(R.id.manual_label);
final EditText secretInput = (EditText) inputView.findViewById(R.id.manual_secret);
final EditText periodInput = (EditText) inputView.findViewById(R.id.manual_period);
final EditText digitsInput = (EditText) inputView.findViewById(R.id.manual_digits);
final Spinner algorithmInput = (Spinner) inputView.findViewById(R.id.manual_algorithm);
final Spinner typeInput = inputView.findViewById(R.id.manual_type);
final EditText labelInput = inputView.findViewById(R.id.manual_label);
final EditText secretInput = inputView.findViewById(R.id.manual_secret);
final EditText periodInput = inputView.findViewById(R.id.manual_period);
final EditText digitsInput = inputView.findViewById(R.id.manual_digits);
final Spinner algorithmInput = inputView.findViewById(R.id.manual_algorithm);
typeInput.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_expandable_list_item_1, Entry.OTPType.values()));
algorithmInput.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_expandable_list_item_1, TokenCalculator.HashAlgorithm.values()));
periodInput.setText(Integer.toString(TokenCalculator.TOTP_DEFAULT_PERIOD));
digitsInput.setText(Integer.toString(TokenCalculator.TOTP_DEFAULT_DIGITS));
periodInput.setText(String.format(Locale.US, "%d", TokenCalculator.TOTP_DEFAULT_PERIOD));
digitsInput.setText(String.format(Locale.US, "%d", TokenCalculator.TOTP_DEFAULT_DIGITS));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.dialog_title_manual_entry)
@ -132,7 +133,7 @@ public class MainActivity extends BaseActivity
}
private void showFirstTimeWarning() {
ViewGroup container = (ViewGroup) findViewById(R.id.main_content);
ViewGroup container = findViewById(R.id.main_content);
View msgView = getLayoutInflater().inflate(R.layout.dialog_security_backup, container, false);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@ -167,7 +168,7 @@ public class MainActivity extends BaseActivity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
@ -193,9 +194,9 @@ public class MainActivity extends BaseActivity
}
});
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
final ProgressBar progressBar = findViewById(R.id.progressBar);
RecyclerView recList = (RecyclerView) findViewById(R.id.cardList);
RecyclerView recList = findViewById(R.id.cardList);
recList.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(this);
llm.setOrientation(LinearLayoutManager.VERTICAL);
@ -353,9 +354,9 @@ public class MainActivity extends BaseActivity
}
});
MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
public boolean onMenuItemActionExpand(MenuItem menuItem) {
floatingActionMenu.hide();
touchHelperCallback.setDragEnabled(false);
if (sortMenu != null)
@ -364,7 +365,7 @@ public class MainActivity extends BaseActivity
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
floatingActionMenu.show();
if (adapter == null || adapter.getSortMode() == SortMode.UNSORTED)
touchHelperCallback.setDragEnabled(true);

View file

@ -51,10 +51,10 @@ public class SettingsActivity extends BaseActivity
setTitle(R.string.settings_activity_title);
setContentView(R.layout.activity_container);
Toolbar toolbar = (Toolbar) findViewById(R.id.container_toolbar);
Toolbar toolbar = findViewById(R.id.container_toolbar);
setSupportActionBar(toolbar);
ViewStub stub = (ViewStub) findViewById(R.id.container_stub);
ViewStub stub = findViewById(R.id.container_stub);
stub.inflate();
fragment = new SettingsFragment();

View file

@ -77,12 +77,12 @@ public class PasswordPreference extends DialogPreference
@Override
protected void onBindDialogView(View view) {
TextInputLayout passwordLayout = (TextInputLayout) view.findViewById(R.id.passwordLayout);
passwordInput = (TextInputEditText) view.findViewById(R.id.passwordEdit);
passwordConfirm = (EditText) view.findViewById(R.id.passwordConfirm);
TextInputLayout passwordLayout = view.findViewById(R.id.passwordLayout);
passwordInput = view.findViewById(R.id.passwordEdit);
passwordConfirm = view.findViewById(R.id.passwordConfirm);
Button btnCancel = (Button) view.findViewById(R.id.btnCancel);
btnSave = (Button) view.findViewById(R.id.btnSave);
Button btnCancel = view.findViewById(R.id.btnCancel);
btnSave = view.findViewById(R.id.btnSave);
btnSave.setEnabled(false);
btnCancel.setOnClickListener(this);

View file

@ -28,19 +28,12 @@ public class StorageHelper {
/* Checks if external storage is available for read and write */
public static boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
return Environment.MEDIA_MOUNTED.equals(state);
}
/* Checks if external storage is available to at least read */
public static boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
}
}

View file

@ -59,18 +59,18 @@ public class EntryViewHolder extends RecyclerView.ViewHolder
this.context = context;
card = (CardView) v.findViewById(R.id.card_view);
value = (TextView) v.findViewById(R.id.valueText);
valueLayout = (LinearLayout) v.findViewById(R.id.valueLayout);
visibleImg = (ImageView) v.findViewById(R.id.valueImg);
coverLayout = (LinearLayout) v.findViewById(R.id.coverLayout);
label = (TextView) v.findViewById(R.id.textViewLabel);
customPeriodLayout = (LinearLayout) v.findViewById(R.id.customPeriodLayout);
customPeriod = (TextView) v.findViewById(R.id.customPeriod);
card = v.findViewById(R.id.card_view);
value = v.findViewById(R.id.valueText);
valueLayout = v.findViewById(R.id.valueLayout);
visibleImg = v.findViewById(R.id.valueImg);
coverLayout = v.findViewById(R.id.coverLayout);
label = v.findViewById(R.id.textViewLabel);
customPeriodLayout = v.findViewById(R.id.customPeriodLayout);
customPeriod = v.findViewById(R.id.customPeriod);
ImageButton menuButton = (ImageButton) v.findViewById(R.id.menuButton);
ImageButton copyButton = (ImageButton) v.findViewById(R.id.copyButton);
ImageView invisibleImg = (ImageView) v.findViewById(R.id.coverImg);
ImageButton menuButton = v.findViewById(R.id.menuButton);
ImageButton copyButton = v.findViewById(R.id.copyButton);
ImageView invisibleImg = v.findViewById(R.id.coverImg);
// Style the buttons in the current theme colors
ColorFilter colorFilter = ThemeHelper.getThemeColorFilter(context, android.R.attr.textColorSecondary);

View file

@ -57,13 +57,13 @@ public class FloatingActionMenu {
fabOpenAnimation = AnimationUtils.loadAnimation(context, R.anim.fab_open);
fabCloseAnimation = AnimationUtils.loadAnimation(context, R.anim.fab_close);
baseFloatingActionButton = (FloatingActionButton) mainLayout.findViewById(R.id.baseFloatingActionButton);
baseFloatingActionButton = mainLayout.findViewById(R.id.baseFloatingActionButton);
qrFAB = (FloatingActionButton) mainLayout.findViewById(R.id.qrFAB);
manualFAB = (FloatingActionButton) mainLayout.findViewById(R.id.manualFAB);
qrFAB = mainLayout.findViewById(R.id.qrFAB);
manualFAB = mainLayout.findViewById(R.id.manualFAB);
qrLayout = (LinearLayout) mainLayout.findViewById(R.id.qrLayout);
manualLayout = (LinearLayout) mainLayout.findViewById(R.id.manualLayout);
qrLayout = mainLayout.findViewById(R.id.qrLayout);
manualLayout = mainLayout.findViewById(R.id.manualLayout);
baseFloatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override