mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 22:12:55 +00:00
Started working on app shortcuts
This commit is contained in:
parent
b129832358
commit
165146385d
2 changed files with 37 additions and 2 deletions
|
@ -7,6 +7,11 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
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.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.BottomSheetDialog;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
|
@ -25,6 +30,7 @@ import android.widget.LinearLayout;
|
|||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
|
@ -70,7 +76,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_main);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
initializeAppShortcuts();
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setOnClickListener(view -> {
|
||||
Intent scannerActivity = new Intent(getApplicationContext(), ScannerActivity.class);
|
||||
|
@ -266,6 +272,29 @@ public class MainActivity extends AppCompatActivity {
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void initializeAppShortcuts()
|
||||
{
|
||||
ShortcutManager shortcutManager = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
shortcutManager = getSystemService(ShortcutManager.class);
|
||||
if(shortcutManager != null) {
|
||||
if (shortcutManager.getDynamicShortcuts().size() == 0) {
|
||||
// Application restored. Need to re-publish dynamic shortcuts.
|
||||
|
||||
|
||||
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1")
|
||||
.setShortLabel("Web site")
|
||||
.setLongLabel("Add new profile")
|
||||
.setIcon(Icon.createWithResource(this.getApplicationContext(), R.drawable.intro_scanner))
|
||||
.setIntent(new Intent(Intent.ACTION_VIEW, Uri.EMPTY, this, ScannerActivity.class))
|
||||
.build();
|
||||
|
||||
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setPreferredTheme()
|
||||
{
|
||||
boolean restart = false;
|
||||
|
|
|
@ -7,6 +7,7 @@ import net.sqlcipher.database.SQLiteDatabase;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import me.impy.aegis.KeyProfile;
|
||||
|
@ -67,7 +68,12 @@ public class Database {
|
|||
|
||||
list.add(profile);
|
||||
}
|
||||
Collections.sort(list, (a, b) -> b.compareTo(a));
|
||||
Collections.sort(list, new Comparator<KeyProfile>() {
|
||||
@Override
|
||||
public int compare(KeyProfile a, KeyProfile b) {
|
||||
return b.compareTo(a);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
} finally {
|
||||
cursor.close();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue