Search in sources :

Example 1 with ShortcutsProvider

use of fr.neamar.kiss.dataprovider.ShortcutsProvider in project KISS by Neamar.

the class UninstallShortcutHandler method onReceive.

@Override
public void onReceive(Context context, Intent data) {
    DataHandler dh = KissApplication.getDataHandler(context);
    ShortcutsProvider sp = dh.getShortcutsProvider();
    if (sp == null)
        return;
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Log.d("onReceive", "Uninstall shortcut " + name);
    ShortcutsPojo pojo = (ShortcutsPojo) sp.findByName(name);
    if (pojo == null) {
        Log.d("onReceive", "Shortcut " + name + " not found");
        return;
    }
    dh.removeShortcut(pojo);
}
Also used : ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo) ShortcutsProvider(fr.neamar.kiss.dataprovider.ShortcutsProvider) DataHandler(fr.neamar.kiss.DataHandler)

Example 2 with ShortcutsProvider

use of fr.neamar.kiss.dataprovider.ShortcutsProvider in project KISS by Neamar.

the class InstallShortcutHandler method onReceive.

@Override
public void onReceive(Context context, Intent data) {
    DataHandler dh = KissApplication.getDataHandler(context);
    ShortcutsProvider sp = dh.getShortcutsProvider();
    if (sp == null)
        return;
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Log.d("onReceive", "Received shortcut " + name);
    Intent target = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (target.getAction() == null) {
        target.setAction(Intent.ACTION_VIEW);
    }
    ShortcutsPojo pojo = createPojo(name);
    // convert target intent to parsable uri
    pojo.intentUri = target.toUri(0);
    //get embedded icon
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    if (icon != null) {
        Log.d("onReceive", "Shortcut " + name + " has embedded icon");
        pojo.icon = icon;
    } else {
        ShortcutIconResource sir = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        if (sir != null) {
            Log.d("onReceive", "Received icon package name " + sir.packageName);
            Log.d("onReceive", "Received icon resource name " + sir.resourceName);
            pojo.packageName = sir.packageName;
            pojo.resourceName = sir.resourceName;
        } else {
            //invalid shortcut
            Log.d("onReceive", "Invalid shortcut " + name + ", ignoring");
            return;
        }
    }
    try {
        Intent intent = Intent.parseUri(pojo.intentUri, 0);
        if (intent.getCategories() != null && intent.getCategories().contains(Intent.CATEGORY_LAUNCHER) && intent.getAction().equals(Intent.ACTION_MAIN)) {
            // The Play Store has an option to create shortcut for new apps,
            // However, KISS already displays all apps, so we discard the shortcut to avoid duplicates.
            Log.d("onReceive", "Shortcut for launcher app, discarded.");
            return;
        }
    } catch (URISyntaxException e) {
        // Invalid intentUri: skip
        // (should logically not happen)
        e.printStackTrace();
        return;
    }
    dh.addShortcut(pojo);
}
Also used : ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo) Bitmap(android.graphics.Bitmap) ShortcutsProvider(fr.neamar.kiss.dataprovider.ShortcutsProvider) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent) DataHandler(fr.neamar.kiss.DataHandler) URISyntaxException(java.net.URISyntaxException)

Aggregations

DataHandler (fr.neamar.kiss.DataHandler)2 ShortcutsProvider (fr.neamar.kiss.dataprovider.ShortcutsProvider)2 ShortcutsPojo (fr.neamar.kiss.pojo.ShortcutsPojo)2 Intent (android.content.Intent)1 ShortcutIconResource (android.content.Intent.ShortcutIconResource)1 Bitmap (android.graphics.Bitmap)1 URISyntaxException (java.net.URISyntaxException)1