Aegis/app/src/main/java/me/impy/aegis/AegisApplication.java
Alexander Bakker 4cd87b0452 Update dependencies
And make the isRunning function in AegisApplication a little easier to read
2018-05-08 20:13:27 +02:00

68 lines
2 KiB
Java

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;
import me.impy.aegis.ui.MainActivity;
public class AegisApplication extends Application {
private boolean _running = false;
private DatabaseManager _manager = new DatabaseManager(this);
@Override
public void onCreate() {
super.onCreate();
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
initAppShortcuts();
}
}
public DatabaseManager getDatabaseManager() {
return _manager;
}
public SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(this);
}
public boolean isRunning() {
// return false the first time this is called
if (!_running) {
_running = true;
return false;
}
return true;
}
@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));
}
}