2019-02-07 22:39:33 +01:00
|
|
|
package com.beemdevelopment.aegis;
|
2017-12-23 22:33:32 +01:00
|
|
|
|
|
|
|
import android.app.Application;
|
2017-12-26 13:04:26 +01:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.ShortcutInfo;
|
|
|
|
import android.content.pm.ShortcutManager;
|
|
|
|
import android.graphics.drawable.Icon;
|
|
|
|
import android.os.Build;
|
2019-02-07 22:39:33 +01:00
|
|
|
|
|
|
|
import com.beemdevelopment.aegis.db.DatabaseManager;
|
|
|
|
import com.beemdevelopment.aegis.ui.MainActivity;
|
|
|
|
|
2017-12-26 13:04:26 +01:00
|
|
|
import java.util.Collections;
|
2017-12-23 22:33:32 +01:00
|
|
|
|
2019-04-04 14:07:36 +02:00
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
|
2017-12-23 22:33:32 +01:00
|
|
|
public class AegisApplication extends Application {
|
2018-05-11 21:29:10 +02:00
|
|
|
private DatabaseManager _manager;
|
|
|
|
private Preferences _prefs;
|
2017-12-23 22:33:32 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
2018-05-11 21:29:10 +02:00
|
|
|
_manager = new DatabaseManager(this);
|
|
|
|
_prefs = new Preferences(this);
|
2017-12-26 13:04:26 +01:00
|
|
|
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
|
|
|
initAppShortcuts();
|
|
|
|
}
|
2017-12-23 22:33:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public DatabaseManager getDatabaseManager() {
|
|
|
|
return _manager;
|
|
|
|
}
|
|
|
|
|
2018-05-11 20:08:51 +02:00
|
|
|
public Preferences getPreferences() {
|
|
|
|
return _prefs;
|
2017-12-23 22:33:32 +01:00
|
|
|
}
|
|
|
|
|
2017-12-26 13:04:26 +01:00
|
|
|
@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")
|
2018-10-09 23:13:51 +02:00
|
|
|
.setShortLabel(getString(R.string.new_profile))
|
|
|
|
.setLongLabel(getString(R.string.add_new_profile))
|
2018-09-22 14:55:37 +02:00
|
|
|
.setIcon(Icon.createWithResource(this, R.drawable.qr_scanner))
|
2017-12-26 13:04:26 +01:00
|
|
|
.setIntent(intent)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
|
|
|
|
}
|
2017-12-23 22:33:32 +01:00
|
|
|
}
|