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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -59,18 +59,18 @@ public class EntryViewHolder extends RecyclerView.ViewHolder
this.context = context; this.context = context;
card = (CardView) v.findViewById(R.id.card_view); card = v.findViewById(R.id.card_view);
value = (TextView) v.findViewById(R.id.valueText); value = v.findViewById(R.id.valueText);
valueLayout = (LinearLayout) v.findViewById(R.id.valueLayout); valueLayout = v.findViewById(R.id.valueLayout);
visibleImg = (ImageView) v.findViewById(R.id.valueImg); visibleImg = v.findViewById(R.id.valueImg);
coverLayout = (LinearLayout) v.findViewById(R.id.coverLayout); coverLayout = v.findViewById(R.id.coverLayout);
label = (TextView) v.findViewById(R.id.textViewLabel); label = v.findViewById(R.id.textViewLabel);
customPeriodLayout = (LinearLayout) v.findViewById(R.id.customPeriodLayout); customPeriodLayout = v.findViewById(R.id.customPeriodLayout);
customPeriod = (TextView) v.findViewById(R.id.customPeriod); customPeriod = v.findViewById(R.id.customPeriod);
ImageButton menuButton = (ImageButton) v.findViewById(R.id.menuButton); ImageButton menuButton = v.findViewById(R.id.menuButton);
ImageButton copyButton = (ImageButton) v.findViewById(R.id.copyButton); ImageButton copyButton = v.findViewById(R.id.copyButton);
ImageView invisibleImg = (ImageView) v.findViewById(R.id.coverImg); ImageView invisibleImg = v.findViewById(R.id.coverImg);
// Style the buttons in the current theme colors // Style the buttons in the current theme colors
ColorFilter colorFilter = ThemeHelper.getThemeColorFilter(context, android.R.attr.textColorSecondary); 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); fabOpenAnimation = AnimationUtils.loadAnimation(context, R.anim.fab_open);
fabCloseAnimation = AnimationUtils.loadAnimation(context, R.anim.fab_close); 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); qrFAB = mainLayout.findViewById(R.id.qrFAB);
manualFAB = (FloatingActionButton) mainLayout.findViewById(R.id.manualFAB); manualFAB = mainLayout.findViewById(R.id.manualFAB);
qrLayout = (LinearLayout) mainLayout.findViewById(R.id.qrLayout); qrLayout = mainLayout.findViewById(R.id.qrLayout);
manualLayout = (LinearLayout) mainLayout.findViewById(R.id.manualLayout); manualLayout = mainLayout.findViewById(R.id.manualLayout);
baseFloatingActionButton.setOnClickListener(new View.OnClickListener() { baseFloatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override @Override