Search in sources :

Example 51 with Bitmap

use of android.graphics.Bitmap 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 52 with Bitmap

use of android.graphics.Bitmap in project ADWLauncher2 by boombuler.

the class DragController method getViewBitmap.

/**
     * Draw the view into a bitmap.
     */
private Bitmap getViewBitmap(View v) {
    v.clearFocus();
    v.setPressed(false);
    boolean willNotCache = v.willNotCacheDrawing();
    v.setWillNotCacheDrawing(false);
    // Reset the drawing cache background color to fully transparent
    // for the duration of this operation
    int color = v.getDrawingCacheBackgroundColor();
    v.setDrawingCacheBackgroundColor(0);
    if (color != 0) {
        v.destroyDrawingCache();
    }
    v.buildDrawingCache();
    Bitmap cacheBitmap = v.getDrawingCache();
    if (cacheBitmap == null) {
        Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
    // Restore the view
    v.destroyDrawingCache();
    v.setWillNotCacheDrawing(willNotCache);
    v.setDrawingCacheBackgroundColor(color);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap)

Example 53 with Bitmap

use of android.graphics.Bitmap in project ADWLauncher2 by boombuler.

the class Launcher method showPreviews.

private void showPreviews(final View anchor, int start, int end) {
    final Resources resources = getResources();
    final Workspace workspace = mWorkspace;
    CellLayout cell = ((CellLayout) workspace.getChildAt(start));
    float max = workspace.getChildCount();
    final Rect r = new Rect();
    resources.getDrawable(R.drawable.preview_background).getPadding(r);
    int extraW = (int) ((r.left + r.right) * max);
    int extraH = r.top + r.bottom;
    int aW = cell.getWidth() - extraW;
    float w = aW / max;
    int width = cell.getWidth();
    int height = cell.getHeight();
    int x = cell.getLeftPadding();
    int y = cell.getTopPadding();
    width -= (x + cell.getRightPadding());
    height -= (y + cell.getBottomPadding());
    float scale = w / width;
    int count = end - start;
    final float sWidth = width * scale;
    float sHeight = height * scale;
    LinearLayout preview = new LinearLayout(this);
    PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
    ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
    for (int i = start; i < end; i++) {
        ImageView image = new ImageView(this);
        cell = (CellLayout) workspace.getChildAt(i);
        final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, Bitmap.Config.ARGB_8888);
        final Canvas c = new Canvas(bitmap);
        c.scale(scale, scale);
        c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
        cell.dispatchDraw(c);
        image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
        image.setImageBitmap(bitmap);
        image.setTag(i);
        image.setOnClickListener(handler);
        image.setOnFocusChangeListener(handler);
        image.setFocusable(true);
        if (i == mWorkspace.getCurrentScreen())
            image.requestFocus();
        preview.addView(image, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        bitmaps.add(bitmap);
    }
    final PopupWindow p = new PopupWindow(this);
    p.setContentView(preview);
    p.setWidth((int) (sWidth * count + extraW));
    p.setHeight((int) (sHeight + extraH));
    p.setAnimationStyle(R.style.AnimationPreview);
    p.setOutsideTouchable(true);
    p.setFocusable(true);
    p.setBackgroundDrawable(new ColorDrawable(0));
    p.showAsDropDown(anchor, 0, 0);
    p.setOnDismissListener(new PopupWindow.OnDismissListener() {

        public void onDismiss() {
            dismissPreview(anchor);
        }
    });
    anchor.setTag(p);
    anchor.setTag(R.id.workspace, preview);
    anchor.setTag(R.id.icon, bitmaps);
}
Also used : Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) ArrayList(java.util.ArrayList) PopupWindow(android.widget.PopupWindow) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 54 with Bitmap

use of android.graphics.Bitmap in project ADWLauncher2 by boombuler.

the class Launcher method completeEditShirtcut.

private void completeEditShirtcut(Intent data) {
    if (!data.hasExtra(CustomShirtcutActivity.EXTRA_APPLICATIONINFO))
        return;
    long appInfoId = data.getLongExtra(CustomShirtcutActivity.EXTRA_APPLICATIONINFO, 0);
    if (data.hasExtra(CustomShirtcutActivity.EXTRA_DRAWERINFO)) {
        List<ShortcutInfo> apps = mAppDB.getApps(new long[] { appInfoId });
        if (apps.size() == 1) {
            IconItemInfo info = apps.get(0);
            Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
            if (bitmap != null) {
                info.setIcon(bitmap);
            } else {
                bitmap = info.mIcon;
            }
            String title = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
            info.setTitle(title);
            mAppDB.updateAppDisplay(appInfoId, title, bitmap);
            // Notify Model:
            Intent modelIntent = new Intent(AppDB.INTENT_DB_CHANGED);
            modelIntent.putExtra(AppDB.EXTRA_UPDATED, new long[] { info.id });
            sendBroadcast(modelIntent);
        }
    } else {
        ItemInfo ii = mModel.getItemInfoById(appInfoId);
        if (ii != null && ii instanceof IconItemInfo) {
            IconItemInfo info = (IconItemInfo) ii;
            Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
            if (bitmap != null) {
                info.setIcon(bitmap);
            }
            info.setTitle(data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));
            if (data.hasExtra(Intent.EXTRA_SHORTCUT_INTENT) && info instanceof ShortcutInfo)
                ((ShortcutInfo) info).intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
            LauncherModel.updateItemInDatabase(this, info);
            // Need to update the icon here!
            if (ii.container == Favorites.CONTAINER_DRAWER) {
                ArrayList<IconItemInfo> lst = new ArrayList<IconItemInfo>();
                lst.add(info);
                mAllAppsGrid.updateApps(lst);
            } else {
                View v = mWorkspace.findViewWithTag(info);
                if (v instanceof BubbleTextView)
                    ((BubbleTextView) v).updateFromItemInfo(mIconCache, info);
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) ArrayList(java.util.ArrayList) Intent(android.content.Intent) LauncherIntent(mobi.intuitit.android.content.LauncherIntent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView)

Example 55 with Bitmap

use of android.graphics.Bitmap in project ADWLauncher2 by boombuler.

the class LiveFolderIcon method update.

public void update(LiveFolderInfo folderInfo) {
    final Resources resources = mLauncher.getResources();
    Bitmap b = folderInfo.getIcon(mLauncher.getIconCache());
    if (b == null || folderInfo.usesDefaultIcon()) {
        b = Utilities.createIconBitmap(resources.getDrawable(R.drawable.ic_launcher_folder), mLauncher);
    }
    setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(b), null, null);
    setText(folderInfo.getTitle(mLauncher.getIconCache()));
    setTag(folderInfo);
    setOnClickListener(mLauncher);
}
Also used : Bitmap(android.graphics.Bitmap) Resources(android.content.res.Resources)

Aggregations

Bitmap (android.graphics.Bitmap)3746 Canvas (android.graphics.Canvas)889 Paint (android.graphics.Paint)709 BitmapDrawable (android.graphics.drawable.BitmapDrawable)461 IOException (java.io.IOException)394 Rect (android.graphics.Rect)341 File (java.io.File)262 Test (org.junit.Test)255 Matrix (android.graphics.Matrix)254 Drawable (android.graphics.drawable.Drawable)243 BitmapFactory (android.graphics.BitmapFactory)240 View (android.view.View)225 ImageView (android.widget.ImageView)210 Intent (android.content.Intent)187 FileOutputStream (java.io.FileOutputStream)186 InputStream (java.io.InputStream)171 RectF (android.graphics.RectF)150 FileNotFoundException (java.io.FileNotFoundException)150 Point (android.graphics.Point)148 Uri (android.net.Uri)128