mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Move app shortcut initialization to AegisApplication
This commit is contained in:
parent
89c61eab3e
commit
1ac3cf9b58
2 changed files with 33 additions and 37 deletions
|
@ -1,8 +1,16 @@
|
|||
package me.impy.aegis;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.RequiresApi;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import me.impy.aegis.db.DatabaseManager;
|
||||
|
||||
|
@ -13,6 +21,10 @@ public class AegisApplication extends Application {
|
|||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
initAppShortcuts();
|
||||
}
|
||||
}
|
||||
|
||||
public DatabaseManager getDatabaseManager() {
|
||||
|
@ -31,4 +43,25 @@ public class AegisApplication extends Application {
|
|||
_running = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
||||
private void initAppShortcuts() {
|
||||
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
|
||||
if (shortcutManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.putExtra("action", "scan");
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
|
||||
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcut_new")
|
||||
.setShortLabel("New profile")
|
||||
.setLongLabel("Add new profile")
|
||||
.setIcon(Icon.createWithResource(this, R.drawable.intro_scanner))
|
||||
.setIntent(intent)
|
||||
.build();
|
||||
|
||||
shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,7 @@ import android.content.ClipboardManager;
|
|||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.os.Build;
|
||||
import android.support.design.widget.BottomSheetDialog;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
@ -25,7 +21,6 @@ import android.widget.Toast;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import me.impy.aegis.crypto.MasterKey;
|
||||
|
@ -67,9 +62,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
// init the app shortcuts
|
||||
initializeAppShortcuts();
|
||||
|
||||
// set up the key profile view
|
||||
_keyProfileView = (KeyProfileView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
|
||||
_keyProfileView.setListener(this);
|
||||
|
@ -513,35 +505,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
|||
startActivityForResult(intent, CODE_DECRYPT);
|
||||
}
|
||||
|
||||
private void initializeAppShortcuts() {
|
||||
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
|
||||
if (shortcutManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Remove this line
|
||||
shortcutManager.removeAllDynamicShortcuts();
|
||||
if (shortcutManager.getDynamicShortcuts().size() == 0) {
|
||||
// Application restored. Need to re-publish dynamic shortcuts.
|
||||
Intent intent = new Intent(this.getBaseContext(), MainActivity.class);
|
||||
intent.putExtra("action", "scan");
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
|
||||
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1")
|
||||
.setShortLabel("New profile")
|
||||
.setLongLabel("Add new profile")
|
||||
.setIcon(Icon.createWithResource(this.getApplicationContext(), R.drawable.intro_scanner))
|
||||
.setIntent(intent)
|
||||
.build();
|
||||
|
||||
shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
|
||||
}
|
||||
}
|
||||
|
||||
private void saveDatabase() {
|
||||
try {
|
||||
_db.save();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue