Permalink
Browse files

SubstratumUI: API25 Circular Icon, Dynamic & Static AppShortcuts

  • Loading branch information...
1 parent 1f69251 commit 53faf6f348b002786c307c55be62196eb672f34b @nicholaschum committed Nov 4, 2016
@@ -129,6 +129,14 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
+ <meta-data android:name="android.app.shortcuts"
+ android:resource="@xml/shortcuts" />
+ </activity>
+ <activity android:name=".LaunchTheme"
+ android:theme="@style/Theme.AppCompat.Translucent">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ </intent-filter>
</activity>
<activity
android:name=".SplashScreenActivity"
@@ -4,19 +4,23 @@
import android.app.WallpaperManager;
import android.app.admin.DevicePolicyManager;
import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutManager;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
@@ -51,8 +55,10 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Enumeration;
import java.util.List;
+import dalvik.system.DexFile;
import projekt.substratum.adapters.InformationTabsAdapter;
import projekt.substratum.config.References;
import projekt.substratum.util.ReadOverlays;
@@ -125,6 +131,21 @@ public void onGlobalLayout() {
});
}
+ private static String[] getClassesOfPackage(Context context) {
+ ArrayList<String> classes = new ArrayList<>();
+ try {
+ String packageCodePath = context.getPackageCodePath();
+ DexFile df = new DexFile(packageCodePath);
+ for (Enumeration<String> iter = df.entries(); iter.hasMoreElements(); ) {
+ String className = iter.nextElement();
+ classes.add(className);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return classes.toArray(new String[classes.size()]);
+ }
+
private boolean checkColorDarkness(int color) {
double darkness =
1 - (0.299 * Color.red(color) +
@@ -471,14 +492,24 @@ public void onTabReselected(TabLayout.Tab tab) {
"permissions for system runtime code execution.");
}
}
+
+ new AppShortcutCreator().execute("last_opened");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (References.checkOMS(getApplicationContext())) {
- getMenuInflater().inflate(R.menu.theme_information_menu, menu);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
+ getMenuInflater().inflate(R.menu.theme_information_menu_n_mr1, menu);
+ } else {
+ getMenuInflater().inflate(R.menu.theme_information_menu, menu);
+ }
} else {
- getMenuInflater().inflate(R.menu.theme_information_menu_legacy, menu);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
+ getMenuInflater().inflate(R.menu.theme_information_menu_legacy_n_mr1, menu);
+ } else {
+ getMenuInflater().inflate(R.menu.theme_information_menu_legacy, menu);
+ }
}
return true;
}
@@ -487,6 +518,11 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
+ if (id == R.id.favorite) {
+ new AppShortcutCreator().execute("favorite");
+ return true;
+ }
+
if (id == R.id.clean) {
AlertDialog.Builder builder = new AlertDialog.Builder(InformationActivity.this);
builder.setTitle(theme_name);
@@ -969,4 +1005,38 @@ protected String doInBackground(String... sUrl) {
return null;
}
}
+
+ private class AppShortcutCreator extends AsyncTask<String, Integer, String> {
+
+ @Override
+ protected String doInBackground(String... sUrl) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
+ ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
+ Bitmap app_icon = ((BitmapDrawable)
+ References.grabAppIcon(getApplicationContext(), theme_pid)).getBitmap();
+ try {
+ Intent myIntent = new Intent(Intent.ACTION_MAIN);
+ myIntent.putExtra("theme_name", theme_name);
+ myIntent.putExtra("theme_pid", theme_pid);
+ myIntent.setComponent(
+ ComponentName.unflattenFromString(
+ "projekt.substratum/projekt.substratum.LaunchTheme"));
+ myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
+ Intent.FLAG_ACTIVITY_SINGLE_TOP);
+
+ ShortcutInfo shortcut = new ShortcutInfo.Builder(getApplicationContext(),
+ sUrl[0])
+ .setShortLabel(((sUrl[0].equals("favorite")) ? "" : "") + theme_name)
+ .setLongLabel(((sUrl[0].equals("favorite")) ? "" : "") + theme_name)
+ .setIcon(Icon.createWithBitmap(app_icon))
+ .setIntent(myIntent)
+ .build();
+ shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut));
+ } catch (Exception e) {
+ // Suppress warning
+ }
+ }
+ return null;
+ }
+ }
}
@@ -0,0 +1,57 @@
+package projekt.substratum;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.widget.Toast;
+
+import java.io.File;
+
+import projekt.substratum.config.References;
+
+/**
+ * @author Nicholas Chum (nicholaschum)
+ */
+
+public class LaunchTheme extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Intent currentIntent = getIntent();
+ String theme_name = currentIntent.getStringExtra("theme_name");
+ String theme_pid = currentIntent.getStringExtra("theme_pid");
+
+ SharedPreferences prefs = this.getSharedPreferences(
+ "substratum_state", Context.MODE_PRIVATE);
+ if (!prefs.contains("is_updating")) prefs.edit()
+ .putBoolean("is_updating", false).apply();
+ if (!prefs.getBoolean("is_updating", true)) {
+ // Process fail case if user uninstalls an app and goes back an activity
+ if (References.isPackageInstalled(this, theme_pid)) {
+ File checkSubstratumVerity = new File(this.getCacheDir()
+ .getAbsoluteFile() + "/SubstratumBuilder/" + theme_pid + "/substratum.xml");
+ if (checkSubstratumVerity.exists()) {
+ References.launchTheme(this, theme_name, theme_pid, null);
+ } else {
+ Toast toast = Toast.makeText(this, this.getString(R.string.toast_needs_caching),
+ Toast.LENGTH_LONG);
+ toast.show();
+ Intent intent = new Intent(this, MainActivity.class);
+ startActivity(intent);
+ }
+ } else {
+ Toast toast = Toast.makeText(this, this.getString(R.string.toast_uninstalled),
+ Toast.LENGTH_SHORT);
+ toast.show();
+ }
+ } else {
+ Toast toast = Toast.makeText(this, this.getString(R.string.background_updating_toast),
+ Toast.LENGTH_SHORT);
+ toast.show();
+ }
+ finish();
+ }
+}
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M20,4L4,4v2h16L20,4zM21,14v-2l-1,-5L4,7l-1,5v2h1v6h10v-6h4v6h2v-6h1zM12,18L6,18v-4h6v4z"/>
+</vector>
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:id="@+id/favorite"
+ android:title="@string/menu_favorite"/>
+ <item
+ android:id="@+id/rate"
+ android:title="@string/menu_rate"/>
+ <item
+ android:id="@+id/reboot_device"
+ android:title="@string/menu_reboot_device"/>
+ <item
+ android:id="@+id/soft_reboot"
+ android:title="@string/menu_soft_reboot"/>
+ <item
+ android:id="@+id/uninstall"
+ android:title="@string/menu_uninstall"/>
+</menu>
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:id="@+id/clean"
+ android:title="@string/menu_clean"/>
+ <item
+ android:id="@+id/disable"
+ android:title="@string/menu_disable"/>
+ <item
+ android:id="@+id/enable"
+ android:title="@string/menu_enable"/>
+ <item
+ android:id="@+id/favorite"
+ android:title="@string/menu_favorite"/>
+ <item
+ android:id="@+id/rate"
+ android:title="@string/menu_rate"/>
+ <item
+ android:id="@+id/restart_systemui"
+ android:title="@string/menu_restart_systemui"/>
+ <item
+ android:id="@+id/uninstall"
+ android:title="@string/menu_uninstall"/>
+</menu>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -182,6 +182,7 @@
<string name="menu_clean">Clean overlays</string>
<string name="menu_disable">Disable installed overlays</string>
<string name="menu_enable">Enable installed overlays</string>
+ <string name="menu_favorite">Favorite</string>
<string name="menu_rate">Rate theme</string>
<string name="menu_refresh">Refresh</string>
<string name="menu_refresh_windows">Refresh Windows</string>
@@ -305,6 +306,7 @@
<string name="no_themes_description">please install a compatible theme!</string>
<string name="toast_on_back_press_compiling">You can use other apps during compile by clicking Home/Recents buttons.</string>
+ <string name="toast_needs_caching">Substratum\'s cache was wiped, please rebuild this theme before continuing!</string>
<string name="notification_theme_installed">installed</string>
<string name="notification_theme_updated">updated</string>
@@ -333,6 +335,9 @@
<string name="char_success">Char stole all your cookies!</string>
<string name="char_error">Char couldn\'t steal your cookies!</string>
+ <string name="shortcut_store">Theme Showcase</string>
+ <string name="shortcut_store_disabled">Theme Showcase</string>
+
<string name="settings_title">About</string>
<string name="settings_title_1">App Options</string>
<string name="settings_title_2">Manager Options</string>
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
+ <shortcut
+ android:enabled="true"
+ android:icon="@drawable/shortcut_store"
+ android:shortcutDisabledMessage="@string/shortcut_store_disabled"
+ android:shortcutId="static"
+ android:shortcutLongLabel="@string/shortcut_store"
+ android:shortcutShortLabel="@string/shortcut_store">
+ <intent
+ android:action="android.intent.action.VIEW"
+ android:targetClass="projekt.substratum.ShowcaseActivity"
+ android:targetPackage="projekt.substratum"/>
+ </shortcut>
+</shortcuts>
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 53faf6f

Please sign in to comment.