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();
}
}
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;
}
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);
}
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);
}
}
}
}
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);
}
Aggregations