Example usage for android.graphics.drawable BitmapDrawable BitmapDrawable

List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable BitmapDrawable BitmapDrawable.

Prototype

private BitmapDrawable(BitmapState state, Resources res) 

Source Link

Usage

From source file:com.android.launcher3.Utilities.java

public static void showEditMode(final Activity activity, final ShortcutInfo shortcutInfo) {
    ContextThemeWrapper theme;/*from www  .java2s.  co  m*/
    final Set<String> setString = new HashSet<String>();
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
        theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustomAPI23);
    } else {
        theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustom);
    }

    AlertDialog.Builder alert = new AlertDialog.Builder(theme);
    LinearLayout layout = new LinearLayout(activity.getApplicationContext());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setPadding(100, 0, 100, 100);

    final ImageView img = new ImageView(activity.getApplicationContext());
    Drawable icon = null;
    if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()) != null) {
        if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()).equals("NULL")) {
            if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                    shortcutInfo.getTargetComponent().getPackageName()) != null) {
                icon = new BitmapDrawable(activity.getResources(),
                        Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName()));
            } else {
                icon = new BitmapDrawable(activity.getResources(),
                        shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(),
                                Launcher.getLauncher(activity).getDeviceProfile().inv)));
            }
        } else {

            if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                    shortcutInfo.getTargetComponent().getPackageName()) != null) {
                icon = new BitmapDrawable(activity.getResources(),
                        Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName()));
            } else {
                icon = new BitmapDrawable(activity.getResources(),
                        Launcher.getIcons().get(shortcutInfo.getTargetComponent().getPackageName()));
            }
        }
    } else {

        if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                shortcutInfo.getTargetComponent().getPackageName()) != null) {
            icon = new BitmapDrawable(activity.getResources(),
                    Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName()));
        } else {
            icon = new BitmapDrawable(activity.getResources(),
                    shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(),
                            Launcher.getLauncher(Launcher.getLauncherActivity()).getDeviceProfile().inv)));
        }
    }
    img.setImageDrawable(icon);
    img.setPadding(0, 100, 0, 0);

    img.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showIconPack(activity, shortcutInfo);
        }
    });

    final EditText titleBox = new EditText(activity.getApplicationContext());

    try {
        Set<String> title = new HashSet<>(
                Utilities.getTitle(activity, shortcutInfo.getTargetComponent().getPackageName()));
        for (Iterator<String> it = title.iterator(); it.hasNext();) {
            String titleApp = it.next();
            titleBox.setText(titleApp);
        }
    } catch (Exception e) {
        titleBox.setText(shortcutInfo.title);
    }

    titleBox.getBackground().mutate().setColorFilter(
            ContextCompat.getColor(activity.getApplicationContext(), R.color.colorPrimary),
            PorterDuff.Mode.SRC_ATOP);

    layout.addView(img);
    layout.addView(titleBox);

    alert.setTitle(activity.getApplicationContext().getResources().getString(R.string.edit_label));
    alert.setView(layout);

    alert.setPositiveButton(activity.getApplicationContext().getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    for (ItemInfo itemInfo : AllAppsList.data) {
                        if (shortcutInfo.getTargetComponent().getPackageName()
                                .equals(itemInfo.getTargetComponent().getPackageName())) {
                            setString.add(titleBox.getText().toString());
                            getPrefs(activity.getApplicationContext()).edit()
                                    .putStringSet(itemInfo.getTargetComponent().getPackageName(), setString)
                                    .apply();
                            Launcher.getShortcutsCreation().clearAllLayout();
                            applyChange(activity);
                        }
                    }
                }
            });

    alert.setNegativeButton(activity.getApplicationContext().getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    Launcher.getShortcutsCreation().clearAllLayout();
                }
            });
    alert.show();
}

From source file:com.amaze.filemanager.activities.MainActivity.java

void setDrawerHeaderBackground() {
    new Thread(new Runnable() {
        public void run() {
            if (Sp.getBoolean("plus_pic", false))
                return;
            String path = Sp.getString("drawer_header_path", null);
            if (path == null)
                return;
            try {
                ImageLoader.getInstance().loadImage(path, displayImageOptions, new ImageLoadingListener() {
                    @Override//from w  w w .j  a v a  2s. c  o  m
                    public void onLoadingStarted(String s, View view) {

                    }

                    @Override
                    public void onLoadingFailed(String s, View view, FailReason failReason) {

                    }

                    @Override
                    public void onLoadingComplete(String s, View view, Bitmap b) {
                        if (b == null)
                            return;
                        Drawable d = new BitmapDrawable(getResources(), b);
                        if (d == null)
                            return;
                        drawerHeaderParent.setBackgroundDrawable(d);
                        drawerHeaderView.setBackgroundResource(R.drawable.amaze_header_2);

                    }

                    @Override
                    public void onLoadingCancelled(String s, View view) {

                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).run();
}

From source file:com.android.launcher3.Launcher.java

@Override
public boolean onLongClick(View v) {
    if (!isDraggingEnabled())
        return false;
    if (isWorkspaceLocked())
        return false;
    if (mState != State.WORKSPACE)
        return false;

    if (creation != null)
        creation.clearAllLayout();// w  ww  .j  av  a2  s.c o  m

    if ((FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && v instanceof PageIndicator)
            || (v == mAllAppsButton && mAllAppsButton != null)) {
        onLongClickAllAppsButton(v);
        return true;
    }

    if (v instanceof Workspace) {
        if (!mWorkspace.isInOverviewMode()) {
            if (!mWorkspace.isTouchActive()) {
                showOverviewMode(true);
                mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                        HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    CellLayout.CellInfo longClickCellInfo = null;
    View itemUnderLongClick = null;
    if (v.getTag() instanceof ItemInfo) {
        ItemInfo info = (ItemInfo) v.getTag();
        longClickCellInfo = new CellLayout.CellInfo(v, info);
        itemUnderLongClick = longClickCellInfo.cell;
        mPendingRequestArgs = null;
    }

    // The hotseat touch handling does not go through Workspace, and we always allow long press
    // on hotseat items.
    if (!mDragController.isDragging()) {
        if (itemUnderLongClick == null) {
            // User long pressed on empty space
            mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                    HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
            if (mWorkspace.isInOverviewMode()) {
                mWorkspace.startReordering(v);
            } else {
                showOverviewMode(true);
            }
        } else {
            final boolean isAllAppsButton = !FeatureFlags.NO_ALL_APPS_ICON && isHotseatLayout(v)
                    && mDeviceProfile.inv.isAllAppsButtonRank(
                            mHotseat.getOrderInHotseat(longClickCellInfo.cellX, longClickCellInfo.cellY));
            if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
                // User long pressed on an item
                DragOptions dragOptions = new DragOptions();
                if (itemUnderLongClick instanceof BubbleTextView) {
                    BubbleTextView icon = (BubbleTextView) itemUnderLongClick;
                    if (icon.hasDeepShortcuts()) {
                        DeepShortcutsContainer dsc = DeepShortcutsContainer.showForIcon(icon);
                        if (dsc != null) {
                            dragOptions.deferDragCondition = dsc.createDeferDragCondition(null);
                        }
                    }
                }

                int positionInGrid = mHotseat.getOrderInHotseat(longClickCellInfo.cellX,
                        longClickCellInfo.cellY);

                List<Shortcuts> shortcutses = new ArrayList<Shortcuts>();

                if (creation != null)
                    creation.clearAllLayout();

                mWorkspace.startDrag(longClickCellInfo, dragOptions);

                //Get selected app info
                final Object tag = v.getTag();
                final ShortcutInfo shortcut;
                try {
                    shortcut = (ShortcutInfo) tag;
                    Drawable icon;
                    if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                            shortcut.getTargetComponent().getPackageName()) != null) {
                        icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity,
                                shortcut.getTargetComponent().getPackageName()));
                    } else {
                        icon = new BitmapDrawable(activity.getResources(),
                                shortcut.getIcon(new IconCache(Launcher.this, getDeviceProfile().inv)));
                    }

                    shortcutses = ShortcutsManager.getShortcutsBasedOnTag(Launcher.this.getApplicationContext(),
                            Launcher.this, shortcut, icon);
                    ShortcutsBuilder builder = new ShortcutsBuilder.Builder(this, masterLayout)
                            .launcher3Shortcuts(gridSize, positionInGrid, (int) v.getY(), v.getBottom(),
                                    Hotseat.isHotseatTouched,
                                    Utilities.getDockSizeDefaultValue(getApplicationContext()))
                            .setOptionLayoutStyle(StyleOption.NONE).setPackageImage(icon)
                            .setShortcutsList(shortcutses).build();

                    creation = new ShortcutsCreation(builder);

                    creation.init();

                    Hotseat.isHotseatTouched = false;

                } catch (ClassCastException e) {
                    Log.e(TAG, "Clicked on Folder/Widget!");
                    positionInGrid = mHotseat.getOrderInHotseat(longClickCellInfo.cellX,
                            longClickCellInfo.cellY);
                    try {
                        //Get selected folder info
                        final View f = v;
                        final Object tagF = v.getTag();
                        final FolderInfo folder;
                        folder = (FolderInfo) tagF;

                        shortcutses = new ArrayList<Shortcuts>();
                        shortcutses.add(new Shortcuts(R.drawable.ic_folder_open_black_24dp,
                                getString(R.string.folder_open), new OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (f instanceof FolderIcon) {
                                            onClickFolderIcon(f);
                                            creation.clearAllLayout();
                                        }
                                    }
                                }));
                        shortcutses.add(new Shortcuts(R.drawable.ic_title_black_24dp,
                                getString(R.string.folder_rename), new OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (f instanceof FolderIcon) {
                                            AlertDialog.Builder alert = new AlertDialog.Builder(
                                                    new ContextThemeWrapper(Launcher.this,
                                                            R.style.AlertDialogCustom));
                                            LinearLayout layout = new LinearLayout(getApplicationContext());
                                            layout.setOrientation(LinearLayout.VERTICAL);
                                            layout.setPadding(100, 50, 100, 100);

                                            final EditText titleBox = new EditText(Launcher.this);

                                            titleBox.getBackground().mutate()
                                                    .setColorFilter(
                                                            ContextCompat.getColor(getApplicationContext(),
                                                                    R.color.colorPrimary),
                                                            PorterDuff.Mode.SRC_ATOP);
                                            alert.setMessage(getString(R.string.folder_title));
                                            alert.setTitle(getString(R.string.folder_enter_title));

                                            layout.addView(titleBox);
                                            alert.setView(layout);

                                            alert.setPositiveButton(getString(R.string.ok),
                                                    new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog,
                                                                int whichButton) {
                                                            folder.setTitle(titleBox.getText().toString());
                                                            LauncherModel.updateItemInDatabase(
                                                                    Launcher.getLauncherActivity(), folder);
                                                        }
                                                    });

                                            alert.setNegativeButton(getString(R.string.cancel),
                                                    new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog,
                                                                int whichButton) {
                                                            creation.clearAllLayout();
                                                        }
                                                    });
                                            alert.show();
                                            creation.clearAllLayout();
                                        }
                                    }
                                }));

                        ShortcutsBuilder builder = new ShortcutsBuilder.Builder(this, masterLayout)
                                .launcher3Shortcuts(gridSize, positionInGrid, (int) v.getY(), v.getBottom(),
                                        Hotseat.isHotseatTouched,
                                        Utilities.getDockSizeDefaultValue(getApplicationContext()))
                                .setOptionLayoutStyle(0)
                                .setPackageImage(
                                        ContextCompat.getDrawable(Launcher.this, R.mipmap.ic_launcher_home))
                                .setShortcutsList(shortcutses).build();

                        creation = new ShortcutsCreation(builder);

                        creation.init();
                    } catch (ClassCastException ee) {
                    }
                }
            }
        }
    }
    return true;
}