Search in sources :

Example 6 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project ADWLauncher2 by boombuler.

the class CustomShirtcutActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        switch(requestCode) {
            case PICK_CUSTOM_PICTURE:
                mBitmap = (Bitmap) data.getParcelableExtra("data");
                if (mBitmap != null) {
                    if (mBitmap.getWidth() > mIconSize)
                        mBitmap = Bitmap.createScaledBitmap(mBitmap, mIconSize, mIconSize, true);
                    btPickIcon.setImageBitmap(mBitmap);
                }
                break;
            case PICK_CUSTOM_ICON:
                Uri photoUri = data.getData();
                try {
                    InputStream is = getContentResolver().openInputStream(photoUri);
                    BitmapFactory.Options opts = new BitmapFactory.Options();
                    opts.inJustDecodeBounds = true;
                    BitmapFactory.decodeStream(is, null, opts);
                    BitmapFactory.Options ops2 = new BitmapFactory.Options();
                    int width = mIconSize;
                    float w = opts.outWidth;
                    //int scale = Math.round(w / width);
                    int scale = (int) (w / width);
                    ops2.inSampleSize = scale;
                    is = getContentResolver().openInputStream(photoUri);
                    mBitmap = BitmapFactory.decodeStream(is, null, ops2);
                    if (mBitmap != null) {
                        if (mBitmap.getWidth() > mIconSize)
                            mBitmap = Bitmap.createScaledBitmap(mBitmap, mIconSize, mIconSize, true);
                        btPickIcon.setImageBitmap(mBitmap);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case PICK_FROM_ICON_PACK:
                mBitmap = (Bitmap) data.getParcelableExtra("icon");
                if (mBitmap != null) {
                    if (mBitmap.getWidth() > mIconSize)
                        mBitmap = Bitmap.createScaledBitmap(mBitmap, mIconSize, mIconSize, true);
                    btPickIcon.setImageBitmap(mBitmap);
                }
                break;
            case PICK_STANDARD_MENU:
                String applicationName = getResources().getString(R.string.group_applications);
                String activitiesName = getResources().getString(R.string.shirtcuts_activity);
                String launcheractionsName = getResources().getString(R.string.launcher_actions);
                String shortcutName = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
                if (applicationName != null && applicationName.equals(shortcutName)) {
                    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
                    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                    Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
                    pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
                    startActivityForResult(pickIntent, PICK_STANDARD_APPLICATION);
                } else if (activitiesName != null && activitiesName.equals(shortcutName)) {
                    Intent picker = new Intent();
                    picker.setClass(this, ActivityPickerActivity.class);
                    startActivityForResult(picker, PICK_STANDARD_SHORTCUT);
                } else if (launcheractionsName != null && launcheractionsName.equals(shortcutName)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle(getString(R.string.launcher_actions));
                    final ListAdapter adapter = LauncherActions.getInstance().getSelectActionAdapter();
                    builder.setAdapter(adapter, new Dialog.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            LauncherActions.Action action = (LauncherActions.Action) adapter.getItem(which);
                            Intent result = new Intent();
                            result.putExtra(Intent.EXTRA_SHORTCUT_NAME, action.getName());
                            result.putExtra(Intent.EXTRA_SHORTCUT_INTENT, LauncherActions.getInstance().getIntentForAction(action));
                            ShortcutIconResource iconResource = new ShortcutIconResource();
                            iconResource.packageName = CustomShirtcutActivity.this.getPackageName();
                            iconResource.resourceName = getResources().getResourceName(action.getIconResourceId());
                            result.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
                            onActivityResult(PICK_STANDARD_SHORTCUT, RESULT_OK, result);
                        }
                    });
                    builder.create().show();
                } else {
                    startActivityForResult(data, PICK_STANDARD_SHORTCUT);
                }
                break;
            case PICK_STANDARD_APPLICATION:
                if (mBitmap != null) {
                    mBitmap.recycle();
                    mBitmap = null;
                }
                ComponentName component = data.getComponent();
                ActivityInfo activityInfo = null;
                try {
                    activityInfo = mPackageManager.getActivityInfo(component, 0);
                } catch (NameNotFoundException e) {
                }
                String title = null;
                if (activityInfo != null) {
                    title = activityInfo.loadLabel(mPackageManager).toString();
                    if (title == null) {
                        title = activityInfo.name;
                    }
                    mIntent = data;
                    btPickActivity.setText(title);
                    mBitmap = null;
                    btPickIcon.setImageDrawable(activityInfo.loadIcon(mPackageManager));
                    btPickIcon.setEnabled(true);
                    btOk.setEnabled(true);
                    edLabel.setText(title);
                }
                break;
            case PICK_STANDARD_SHORTCUT:
                if (mBitmap != null) {
                    mBitmap.recycle();
                    mBitmap = null;
                }
                Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
                String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
                Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
                Drawable icon = null;
                if (bitmap != null) {
                    icon = new FastBitmapDrawable(Bitmap.createScaledBitmap(bitmap, mIconSize, mIconSize, true));
                    mBitmap = bitmap;
                } else {
                    Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
                    if (extra != null && extra instanceof ShortcutIconResource) {
                        try {
                            ShortcutIconResource iconResource = (ShortcutIconResource) extra;
                            Resources resources = mPackageManager.getResourcesForApplication(iconResource.packageName);
                            final int id = resources.getIdentifier(iconResource.resourceName, null, null);
                            icon = resources.getDrawable(id);
                            mBitmap = Utilities.createIconBitmap(icon, this);
                        } catch (Exception e) {
                        }
                    }
                }
                if (icon == null) {
                    icon = getPackageManager().getDefaultActivityIcon();
                }
                mIntent = intent;
                btPickActivity.setText(name);
                btPickIcon.setImageDrawable(icon);
                btPickIcon.setEnabled(true);
                btOk.setEnabled(true);
                edLabel.setText(name);
                break;
            default:
                break;
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) ComponentName(android.content.ComponentName) BitmapFactory(android.graphics.BitmapFactory) ListAdapter(android.widget.ListAdapter) ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) InputStream(java.io.InputStream) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) Parcelable(android.os.Parcelable) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) LauncherActions(org.adw.launcher2.actions.LauncherActions) Resources(android.content.res.Resources)

Example 7 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project ADWLauncher2 by boombuler.

the class CustomShirtcutActivity method onClick.

@Override
public void onClick(View v) {
    if (v.equals(btPickActivity)) {
        Bundle bundle = new Bundle();
        ArrayList<String> shortcutNames = new ArrayList<String>();
        shortcutNames.add(getString(R.string.group_applications));
        shortcutNames.add(getString(R.string.shirtcuts_activity));
        shortcutNames.add(getString(R.string.launcher_actions));
        bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
        ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
        shortcutIcons.add(ShortcutIconResource.fromContext(CustomShirtcutActivity.this, R.drawable.ic_launcher_application));
        shortcutIcons.add(ShortcutIconResource.fromContext(CustomShirtcutActivity.this, R.drawable.ic_launcher_home));
        shortcutIcons.add(ShortcutIconResource.fromContext(CustomShirtcutActivity.this, R.drawable.ic_launcher_home));
        bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
        Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
        pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
        pickIntent.putExtras(bundle);
        startActivityForResult(pickIntent, PICK_STANDARD_MENU);
    } else if (v.equals(btPickIcon)) {
        showDialog(DIALOG_ICON_TYPE);
    } else if (v.equals(btOk)) {
        Intent mReturnData = new Intent();
        if (mIntent != null)
            mReturnData.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mIntent);
        mReturnData.putExtra(Intent.EXTRA_SHORTCUT_NAME, edLabel.getText().toString());
        Intent intent = getIntent();
        if (intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_EDIT) && intent.hasExtra(EXTRA_APPLICATIONINFO)) {
            long id = intent.getLongExtra(EXTRA_APPLICATIONINFO, 0);
            mReturnData.putExtra(EXTRA_APPLICATIONINFO, id);
        }
        if (mBitmap != null)
            mReturnData.putExtra(Intent.EXTRA_SHORTCUT_ICON, mBitmap);
        if (isDrawerInfo)
            mReturnData.putExtra(EXTRA_DRAWERINFO, true);
        setResult(RESULT_OK, mReturnData);
        finish();
    } else if (v.equals(btRevert)) {
        Intent mReturnData = new Intent();
        if (mIntent != null)
            mReturnData.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mIntent);
        mReturnData.putExtra(Intent.EXTRA_SHORTCUT_NAME, (String) null);
        Intent intent = getIntent();
        if (intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_EDIT) && intent.hasExtra(EXTRA_APPLICATIONINFO)) {
            long id = intent.getLongExtra(EXTRA_APPLICATIONINFO, 0);
            mReturnData.putExtra(EXTRA_APPLICATIONINFO, id);
        }
        mReturnData.putExtra(Intent.EXTRA_SHORTCUT_ICON, (Bitmap) null);
        if (isDrawerInfo)
            mReturnData.putExtra(EXTRA_DRAWERINFO, true);
        setResult(RESULT_OK, mReturnData);
        finish();
    }
}
Also used : Bitmap(android.graphics.Bitmap) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent)

Example 8 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project android_frameworks_base by ResurrectionRemix.

the class ShortcutPickHelper method pickShortcut.

public void pickShortcut(String[] names, ShortcutIconResource[] icons, int fragmentId) {
    Bundle bundle = new Bundle();
    ArrayList<String> shortcutNames = new ArrayList<String>();
    if (names != null) {
        for (String s : names) {
            shortcutNames.add(s);
        }
    }
    shortcutNames.add(mParent.getString(R.string.profile_applist_title));
    shortcutNames.add(mParent.getString(R.string.picker_activities));
    bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
    ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
    if (icons != null) {
        for (ShortcutIconResource s : icons) {
            shortcutIcons.add(s);
        }
    }
    shortcutIcons.add(ShortcutIconResource.fromContext(mParent, android.R.drawable.sym_def_app_icon));
    shortcutIcons.add(ShortcutIconResource.fromContext(mParent, R.drawable.activities_icon));
    bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
    Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
    pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
    pickIntent.putExtra(Intent.EXTRA_TITLE, mParent.getText(R.string.select_custom_app_title));
    pickIntent.putExtras(bundle);
    lastFragmentId = fragmentId;
    startFragmentOrActivity(pickIntent, REQUEST_PICK_SHORTCUT);
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent)

Example 9 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SlimShortcutPickerHelper method completeSetCustomShortcut.

private void completeSetCustomShortcut(Intent data) {
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    /* preserve shortcut name, we want to restore it later */
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));
    String appUri = intent.toUri(0);
    appUri = appUri.replaceAll("com.android.contacts.action.QUICK_CONTACT", "android.intent.action.VIEW");
    // Check if icon is present
    Bitmap bmp = null;
    Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    if (extra != null && extra instanceof Bitmap) {
        bmp = (Bitmap) extra;
    }
    // No icon till now check if icon resource is present
    if (bmp == null) {
        extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        if (extra != null && extra instanceof Intent.ShortcutIconResource) {
            try {
                Intent.ShortcutIconResource iconResource = (ShortcutIconResource) extra;
                Resources resources = mPackageManager.getResourcesForApplication(iconResource.packageName);
                final int id = resources.getIdentifier(iconResource.resourceName, null, null);
                bmp = BitmapFactory.decodeResource(resources, id);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    mListener.shortcutPicked(appUri, AppHelper.getFriendlyShortcutName(mParent, mPackageManager, intent), bmp, false);
}
Also used : Bitmap(android.graphics.Bitmap) ShortcutIconResource(android.content.Intent.ShortcutIconResource) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent) Parcelable(android.os.Parcelable) Resources(android.content.res.Resources)

Example 10 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ActivityPicker method getItems.

/**
     * Build and return list of items to be shown in dialog. Default
     * implementation mixes activities matching {@link #mBaseIntent} from
     * {@link #putIntentItems(Intent, List)} with any injected items from
     * {@link Intent#EXTRA_SHORTCUT_NAME}. Override this method in subclasses to
     * change the items shown.
     */
protected List<PickAdapter.Item> getItems() {
    PackageManager packageManager = getPackageManager();
    List<PickAdapter.Item> items = new ArrayList<PickAdapter.Item>();
    // Add any injected pick items
    final Intent intent = getIntent();
    ArrayList<String> labels = intent.getStringArrayListExtra(Intent.EXTRA_SHORTCUT_NAME);
    ArrayList<ShortcutIconResource> icons = intent.getParcelableArrayListExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
    if (labels != null && icons != null && labels.size() == icons.size()) {
        for (int i = 0; i < labels.size(); i++) {
            String label = labels.get(i);
            Drawable icon = null;
            try {
                // Try loading icon from requested package
                ShortcutIconResource iconResource = icons.get(i);
                Resources res = packageManager.getResourcesForApplication(iconResource.packageName);
                icon = res.getDrawable(res.getIdentifier(iconResource.resourceName, null, null), null);
            } catch (NameNotFoundException e) {
            // Ignore
            }
            items.add(new PickAdapter.Item(this, label, icon));
        }
    }
    // Add any intent items if base was given
    if (mBaseIntent != null) {
        putIntentItems(mBaseIntent, items);
    }
    return items;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PaintDrawable(android.graphics.drawable.PaintDrawable) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent) Paint(android.graphics.Paint) PackageManager(android.content.pm.PackageManager) Resources(android.content.res.Resources)

Aggregations

ShortcutIconResource (android.content.Intent.ShortcutIconResource)23 Intent (android.content.Intent)22 ArrayList (java.util.ArrayList)11 Resources (android.content.res.Resources)10 Bitmap (android.graphics.Bitmap)10 Bundle (android.os.Bundle)9 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)8 PackageManager (android.content.pm.PackageManager)7 Parcelable (android.os.Parcelable)7 RemoteException (android.os.RemoteException)5 URISyntaxException (java.net.URISyntaxException)5 Drawable (android.graphics.drawable.Drawable)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 ComponentName (android.content.ComponentName)2 ActivityInfo (android.content.pm.ActivityInfo)2 Paint (android.graphics.Paint)2 PaintDrawable (android.graphics.drawable.PaintDrawable)2 LauncherIntent (mobi.intuitit.android.content.LauncherIntent)2 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1