diff options
Diffstat (limited to 'app/src/main/java/com/wireguard/android')
7 files changed, 42 insertions, 44 deletions
diff --git a/app/src/main/java/com/wireguard/android/activity/BaseActivity.java b/app/src/main/java/com/wireguard/android/activity/BaseActivity.java index f6f56601..eb2de5ed 100644 --- a/app/src/main/java/com/wireguard/android/activity/BaseActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/BaseActivity.java @@ -1,10 +1,10 @@ package com.wireguard.android.activity; -import android.app.Activity; import android.content.Intent; import android.databinding.CallbackRegistry; import android.databinding.CallbackRegistry.NotifierCallback; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import com.wireguard.android.Application; import com.wireguard.android.backend.GoBackend; @@ -17,7 +17,7 @@ import java.util.Objects; * Base class for activities that need to remember the currently-selected tunnel. */ -public abstract class BaseActivity extends Activity { +public abstract class BaseActivity extends AppCompatActivity { private static final String KEY_SELECTED_TUNNEL = "selected_tunnel"; private final SelectionChangeRegistry selectionChangeRegistry = new SelectionChangeRegistry(); diff --git a/app/src/main/java/com/wireguard/android/activity/MainActivity.java b/app/src/main/java/com/wireguard/android/activity/MainActivity.java index e347af75..c43c0023 100644 --- a/app/src/main/java/com/wireguard/android/activity/MainActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/MainActivity.java @@ -1,9 +1,10 @@ package com.wireguard.android.activity; -import android.app.Fragment; -import android.app.FragmentTransaction; import android.content.Intent; import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -28,6 +29,7 @@ public class MainActivity extends BaseActivity { private State state = State.EMPTY; private boolean moveToState(final State nextState) { + final FragmentManager fragmentManager = getSupportFragmentManager(); Log.i(TAG, "Moving from " + state.name() + " to " + nextState.name()); if (nextState == state) { return false; @@ -37,16 +39,16 @@ public class MainActivity extends BaseActivity { return true; } else if (nextState.layer == state.layer + 1) { final Fragment fragment = Fragment.instantiate(this, nextState.fragment); - final FragmentTransaction transaction = getFragmentManager().beginTransaction() + final FragmentTransaction transaction = fragmentManager.beginTransaction() .replace(R.id.master_fragment, fragment) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); if (state.layer > 0) transaction.addToBackStack(null); transaction.commit(); } else if (nextState.layer == state.layer - 1) { - if (getFragmentManager().getBackStackEntryCount() == 0) + if (fragmentManager.getBackStackEntryCount() == 0) return false; - getFragmentManager().popBackStack(); + fragmentManager.popBackStack(); } else if (nextState.layer < state.layer - 1) { moveToState(State.ofLayer(state.layer - 1)); moveToState(nextState); @@ -121,8 +123,8 @@ public class MainActivity extends BaseActivity { } private void updateActionBar() { - if (getActionBar() != null) - getActionBar().setDisplayHomeAsUpEnabled(state.layer > State.LIST.layer); + if (getSupportActionBar() != null) + getSupportActionBar().setDisplayHomeAsUpEnabled(state.layer > State.LIST.layer); } private enum State { diff --git a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java index 41761b32..273c7da8 100644 --- a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java @@ -1,10 +1,11 @@ package com.wireguard.android.activity; -import android.app.Activity; import android.content.pm.PackageManager; import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceFragment; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceFragmentCompat; import com.wireguard.android.Application; import com.wireguard.android.R; @@ -19,7 +20,7 @@ import java.util.List; * Interface for changing application-global persistent settings. */ -public class SettingsActivity extends Activity { +public class SettingsActivity extends AppCompatActivity { @FunctionalInterface public interface PermissionRequestCallback { void done(String[] permissions, int[] grantResults); @@ -56,7 +57,7 @@ public class SettingsActivity extends Activity { } @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { final PermissionRequestCallback f = permissionRequestCallbacks.get(requestCode); if (f != null) { permissionRequestCallbacks.remove(requestCode); @@ -67,17 +68,16 @@ public class SettingsActivity extends Activity { @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getFragmentManager().findFragmentById(android.R.id.content) == null) { - getFragmentManager().beginTransaction() + if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) { + getSupportFragmentManager().beginTransaction() .add(android.R.id.content, new SettingsFragment()) .commit(); } } - public static class SettingsFragment extends PreferenceFragment { + public static class SettingsFragment extends PreferenceFragmentCompat { @Override - public void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onCreatePreferences(final Bundle savedInstanceState, final String key) { addPreferencesFromResource(R.xml.preferences); if (Application.getComponent().getBackendType() != WgQuickBackend.class) { final Preference toolsInstaller = diff --git a/app/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.java b/app/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.java index c5e024b1..dc25d463 100644 --- a/app/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/TunnelCreatorActivity.java @@ -14,8 +14,8 @@ public class TunnelCreatorActivity extends BaseActivity { @SuppressWarnings("UnnecessaryFullyQualifiedName") protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getFragmentManager().findFragmentById(android.R.id.content) == null) { - getFragmentManager().beginTransaction() + if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) { + getSupportFragmentManager().beginTransaction() .add(android.R.id.content, new TunnelEditorFragment()) .commit(); } diff --git a/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java b/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java index 9e188bc0..9bfeeb5c 100644 --- a/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java @@ -1,7 +1,7 @@ package com.wireguard.android.fragment; -import android.app.Fragment; import android.content.Context; +import android.support.v4.app.Fragment; import com.wireguard.android.activity.BaseActivity; import com.wireguard.android.activity.BaseActivity.OnSelectedTunnelChangedListener; diff --git a/app/src/main/java/com/wireguard/android/preference/ToolsInstallerPreference.java b/app/src/main/java/com/wireguard/android/preference/ToolsInstallerPreference.java index 6e54fa56..5c919aae 100644 --- a/app/src/main/java/com/wireguard/android/preference/ToolsInstallerPreference.java +++ b/app/src/main/java/com/wireguard/android/preference/ToolsInstallerPreference.java @@ -1,8 +1,8 @@ package com.wireguard.android.preference; import android.content.Context; -import android.preference.Preference; import android.support.annotation.NonNull; +import android.support.v7.preference.Preference; import android.system.OsConstants; import android.util.AttributeSet; @@ -37,17 +37,12 @@ public class ToolsInstallerPreference extends Preference { @Override public CharSequence getTitle() { - return getContext().getString(getTitleRes()); + return getContext().getString(R.string.tools_installer_title); } @Override - public int getTitleRes() { - return R.string.tools_installer_title; - } - - @Override - protected void onAttachedToActivity() { - super.onAttachedToActivity(); + public void onAttached() { + super.onAttached(); asyncWorker.supplyAsync(toolsInstaller::areInstalled).whenComplete(this::onCheckResult); } diff --git a/app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java b/app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java index 2101420f..c6d7187a 100644 --- a/app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java +++ b/app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java @@ -1,9 +1,10 @@ package com.wireguard.android.preference; +import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.os.Environment; -import android.preference.Preference; +import android.support.v7.preference.Preference; import android.util.AttributeSet; import android.util.Log; @@ -57,12 +58,7 @@ public class ZipExporterPreference extends Preference { @Override public CharSequence getTitle() { - return getContext().getString(getTitleRes()); - } - - @Override - public int getTitleRes() { - return R.string.zip_exporter_title; + return getContext().getString(R.string.zip_exporter_title); } private void exportZip() { @@ -86,7 +82,8 @@ public class ZipExporterPreference extends Preference { final ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(file)); for (int i = 0; i < futureConfigs.size(); ++i) { zip.putNextEntry(new ZipEntry(tunnels.get(i).getName() + ".conf")); - zip.write(futureConfigs.get(i).getNow(null).toString().getBytes(StandardCharsets.UTF_8)); + zip.write(futureConfigs.get(i).getNow(null). + toString().getBytes(StandardCharsets.UTF_8)); } zip.closeEntry(); zip.close(); @@ -104,7 +101,9 @@ public class ZipExporterPreference extends Preference { final String error = ExceptionLoggers.unwrap(throwable).getMessage(); final String message = getContext().getString(R.string.export_error, error); Log.e(TAG, message, throwable); - Snackbar.make(((SettingsActivity)getContext()).findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG).show(); + Snackbar.make( + ((SettingsActivity)getContext()).findViewById(android.R.id.content), + message, Snackbar.LENGTH_LONG).show(); } else { exportedFilePath = filePath; setEnabled(false); @@ -114,10 +113,12 @@ public class ZipExporterPreference extends Preference { @Override protected void onClick() { - ((SettingsActivity)getContext()).ensurePermissions(new String[] { "android.permission.WRITE_EXTERNAL_STORAGE" }, (permissions, granted) -> { - if (granted.length > 0 && granted[0] == PackageManager.PERMISSION_GRANTED) - exportZip(); - }); + ((SettingsActivity)getContext()).ensurePermissions( + new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, + (permissions, granted) -> { + if (granted.length > 0 && granted[0] == PackageManager.PERMISSION_GRANTED) + exportZip(); + }); } } |