Search in sources :

Example 1 with ShortcutsPojo

use of fr.neamar.kiss.pojo.ShortcutsPojo in project KISS by Neamar.

the class LoadShortcutsPojos method createPojo.

public ShortcutsPojo createPojo(String name) {
    ShortcutsPojo pojo = new ShortcutsPojo();
    pojo.id = ShortcutsPojo.SCHEME + name.toLowerCase();
    pojo.setName(name);
    return pojo;
}
Also used : ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo)

Example 2 with ShortcutsPojo

use of fr.neamar.kiss.pojo.ShortcutsPojo in project KISS by Neamar.

the class LoadShortcutsPojos method doInBackground.

@Override
protected ArrayList<ShortcutsPojo> doInBackground(Void... arg0) {
    List<ShortcutRecord> records = DBHelper.getShortcuts(context);
    ArrayList<ShortcutsPojo> pojos = new ArrayList<>();
    for (ShortcutRecord shortcutRecord : records) {
        ShortcutsPojo pojo = createPojo(shortcutRecord.name);
        pojo.packageName = shortcutRecord.packageName;
        pojo.resourceName = shortcutRecord.iconResource;
        pojo.intentUri = shortcutRecord.intentUri;
        if (shortcutRecord.icon_blob != null) {
            pojo.icon = BitmapFactory.decodeByteArray(shortcutRecord.icon_blob, 0, shortcutRecord.icon_blob.length);
        }
        pojos.add(pojo);
    }
    return pojos;
}
Also used : ShortcutRecord(fr.neamar.kiss.db.ShortcutRecord) ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo) ArrayList(java.util.ArrayList)

Example 3 with ShortcutsPojo

use of fr.neamar.kiss.pojo.ShortcutsPojo 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 4 with ShortcutsPojo

use of fr.neamar.kiss.pojo.ShortcutsPojo in project KISS by Neamar.

the class InstallShortcutHandler method createPojo.

public ShortcutsPojo createPojo(String name) {
    ShortcutsPojo pojo = new ShortcutsPojo();
    pojo.id = ShortcutsPojo.SCHEME + name.toLowerCase();
    pojo.setName(name);
    return pojo;
}
Also used : ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo)

Example 5 with ShortcutsPojo

use of fr.neamar.kiss.pojo.ShortcutsPojo 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

ShortcutsPojo (fr.neamar.kiss.pojo.ShortcutsPojo)6 DataHandler (fr.neamar.kiss.DataHandler)2 ShortcutsProvider (fr.neamar.kiss.dataprovider.ShortcutsProvider)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 ShortcutIconResource (android.content.Intent.ShortcutIconResource)1 Bitmap (android.graphics.Bitmap)1 ShortcutRecord (fr.neamar.kiss.db.ShortcutRecord)1 Pojo (fr.neamar.kiss.pojo.Pojo)1 URISyntaxException (java.net.URISyntaxException)1