Example usage for android.view ContextThemeWrapper ContextThemeWrapper

List of usage examples for android.view ContextThemeWrapper ContextThemeWrapper

Introduction

In this page you can find the example usage for android.view ContextThemeWrapper ContextThemeWrapper.

Prototype

public ContextThemeWrapper(Context base, Resources.Theme theme) 

Source Link

Document

Creates a new context wrapper with the specified theme.

Usage

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

public static void answerToRestartLauncher(final Context contextRestart, Context context, final int delay) {
    AlertDialog.Builder alert = new AlertDialog.Builder(
            new ContextThemeWrapper(context, R.style.AlertDialogCustom));

    alert.setTitle(context.getResources().getString(R.string.app_name));
    alert.setMessage(context.getResources().getString(R.string.ask_restart));

    alert.setPositiveButton(context.getResources().getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    restart(contextRestart, delay);
                }//  ww w.ja va  2s.c om
            });

    alert.setNegativeButton(context.getResources().getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                }
            });
    alert.setIcon(R.mipmap.ic_launcher_home);
    alert.show();
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    final Dialog dialog;
    ProgressDialog pdialog;//from   www .ja  v  a2  s. c o  m
    AlertDialog.Builder builder;
    LayoutInflater inflater;

    switch (id) {
    case Constants.DIALOG_LOGIN:
        dialog = new LoginDialog(this, mSettings, false) {
            @Override
            public void onLoginChosen(String user, String password) {
                removeDialog(Constants.DIALOG_LOGIN);
                new MyLoginTask(user, password).execute();
            }
        };
        break;

    case Constants.DIALOG_COMMENT_CLICK:
        dialog = new CommentClickDialog(this, mSettings);
        break;

    case Constants.DIALOG_REPLY: {
        dialog = new Dialog(this, mSettings.getDialogTheme());
        dialog.setContentView(R.layout.compose_reply_dialog);
        final EditText replyBody = (EditText) dialog.findViewById(R.id.body);
        final Button replySaveButton = (Button) dialog.findViewById(R.id.reply_save_button);
        final Button replyCancelButton = (Button) dialog.findViewById(R.id.reply_cancel_button);

        replySaveButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mReplyTargetName != null) {
                    new CommentReplyTask(mReplyTargetName).execute(replyBody.getText().toString());
                    dialog.dismiss();
                } else {
                    Common.showErrorToast("Error replying. Please try again.", Toast.LENGTH_SHORT,
                            CommentsListActivity.this);
                }
            }
        });
        replyCancelButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mVoteTargetThing.setReplyDraft(replyBody.getText().toString());
                dialog.cancel();
            }
        });
        dialog.setCancelable(false); // disallow the BACK key
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                replyBody.setText("");
            }
        });
        break;
    }

    case Constants.DIALOG_EDIT: {
        dialog = new Dialog(this, mSettings.getDialogTheme());
        dialog.setContentView(R.layout.compose_reply_dialog);
        final EditText replyBody = (EditText) dialog.findViewById(R.id.body);
        final Button replySaveButton = (Button) dialog.findViewById(R.id.reply_save_button);
        final Button replyCancelButton = (Button) dialog.findViewById(R.id.reply_cancel_button);

        replyBody.setText(mEditTargetBody);

        replySaveButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (mReplyTargetName != null) {
                    new EditTask(mReplyTargetName).execute(replyBody.getText().toString());
                    dialog.dismiss();
                } else {
                    Common.showErrorToast("Error editing. Please try again.", Toast.LENGTH_SHORT,
                            CommentsListActivity.this);
                }
            }
        });
        replyCancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                dialog.cancel();
            }
        });
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                replyBody.setText("");
            }
        });
        break;
    }

    case Constants.DIALOG_DELETE:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("Really delete this?");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                removeDialog(Constants.DIALOG_DELETE);
                new DeleteTask(mDeleteTargetKind).execute(mReplyTargetName);
            }
        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        dialog = builder.create();
        break;

    case Constants.DIALOG_SORT_BY:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("Sort by:");
        int selectedSortBy = -1;
        for (int i = 0; i < Constants.CommentsSort.SORT_BY_URL_CHOICES.length; i++) {
            if (Constants.CommentsSort.SORT_BY_URL_CHOICES[i].equals(mSettings.getCommentsSortByUrl())) {
                selectedSortBy = i;
                break;
            }
        }
        builder.setSingleChoiceItems(Constants.CommentsSort.SORT_BY_CHOICES, selectedSortBy,
                sortByOnClickListener);
        dialog = builder.create();
        break;

    case Constants.DIALOG_REPORT:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("Really report this?");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                removeDialog(Constants.DIALOG_REPORT);
                new ReportTask(mReportTargetName.toString()).execute();
            }
        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        dialog = builder.create();
        break;

    // "Please wait"
    case Constants.DIALOG_DELETING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Deleting...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_EDITING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Submitting edit...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_LOGGING_IN:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Logging in...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_REPLYING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Sending reply...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_FIND:
        inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View content = inflater.inflate(R.layout.dialog_find, null);
        final EditText find_box = (EditText) content.findViewById(R.id.input_find_box);
        //          final CheckBox wrap_box = (CheckBox) content.findViewById(R.id.find_wrap_checkbox);

        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setView(content);
        builder.setTitle(R.string.find).setPositiveButton(R.string.find, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String search_text = find_box.getText().toString().toLowerCase();
                //               findCommentText(search_text, wrap_box.isChecked(), false);
                findCommentText(search_text, true, false);
            }
        }).setNegativeButton("Cancel", null);
        dialog = builder.create();
        break;
    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

/**
 * Helper function to add links from mVoteTargetThing to the button
 * @param linkButton Button that should open list of links
 *//*from   ww  w.  ja v a  2  s . c o m*/
private void linkToEmbeddedURLs(Button linkButton) {
    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<MarkdownURL> vtUrls = mVoteTargetThing.getUrls();
    int urlsCount = vtUrls.size();
    for (int i = 0; i < urlsCount; i++) {
        urls.add(vtUrls.get(i).url);
    }
    if (urlsCount == 0) {
        linkButton.setEnabled(false);
    } else {
        linkButton.setEnabled(true);
        linkButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                removeDialog(Constants.DIALOG_COMMENT_CLICK);

                ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(CommentsListActivity.this,
                        android.R.layout.select_dialog_item, vtUrls) {
                    public View getView(int position, View convertView, ViewGroup parent) {
                        TextView tv;
                        if (convertView == null) {
                            tv = (TextView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                                    .inflate(android.R.layout.select_dialog_item, null);
                        } else {
                            tv = (TextView) convertView;
                        }

                        String url = getItem(position).url;
                        String anchorText = getItem(position).anchorText;
                        if (Constants.LOGGING)
                            Log.d(TAG, "links url=" + url + " anchorText=" + anchorText);

                        Drawable d = null;
                        try {
                            d = getPackageManager()
                                    .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                        } catch (NameNotFoundException ignore) {
                        }
                        if (d != null) {
                            d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight());
                            tv.setCompoundDrawablePadding(10);
                            tv.setCompoundDrawables(d, null, null, null);
                        }

                        final String telPrefix = "tel:";
                        if (url.startsWith(telPrefix)) {
                            url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length()));
                        }

                        if (anchorText != null)
                            tv.setText(Html.fromHtml(
                                    "<span>" + anchorText + "</span><br /><small>" + url + "</small>"));
                        else
                            tv.setText(Html.fromHtml(url));

                        return tv;
                    }
                };

                AlertDialog.Builder b = new AlertDialog.Builder(
                        new ContextThemeWrapper(CommentsListActivity.this, mSettings.getDialogTheme()));

                DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() {
                    public final void onClick(DialogInterface dialog, int which) {
                        if (which >= 0) {
                            Common.launchBrowser(CommentsListActivity.this, urls.get(which),
                                    Util.createThreadUri(getOpThingInfo()).toString(), false, false,
                                    mSettings.isUseExternalBrowser(), mSettings.isSaveHistory());
                        }
                    }
                };

                b.setTitle(R.string.select_link_title);
                b.setCancelable(true);
                b.setAdapter(adapter, click);

                b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public final void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                b.show();
            }
        });
    }
}

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

public static void showEditMode(final Activity activity, final ShortcutInfo shortcutInfo) {
    ContextThemeWrapper theme;/* www.j  a  v a  2 s .c o  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:lewa.support.v7.widget.Toolbar.java

/**
 * Allows us to emulate the {@code android:theme} attribute for devices before L.
 */// ww  w  .j  a v  a  2 s. co m
private static Context themifyContext(Context context, AttributeSet attrs, int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Toolbar, defStyleAttr, 0);
    final int themeId = a.getResourceId(R.styleable.Toolbar_theme, 0);
    if (themeId != 0) {
        context = new ContextThemeWrapper(context, themeId);
    }
    a.recycle();
    return context;
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

private AlertDialog.Builder xshowManagePassphrases(final Activity act, Bundle args) {
    String msg = args.getString(extra.RESID_MSG);
    boolean allowDelete = args.getBoolean(extra.ALLOW_DELETE);
    AlertDialog.Builder ad = new AlertDialog.Builder(act);
    View layout;//from  www  .  j a v a2  s .  c  o  m
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        layout = View.inflate(new ContextThemeWrapper(act, R.style.Theme_AppCompat), R.layout.about, null);
    } else {
        LayoutInflater inflater = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layout = inflater.inflate(R.layout.about, null);
    }
    TextView textViewAbout = (TextView) layout.findViewById(R.id.TextViewAbout);
    ad.setTitle(R.string.menu_ManagePassphrases);
    textViewAbout.setText(msg);
    ad.setView(layout);
    ad.setCancelable(true);
    if (allowDelete) { // only have delete key when recent keys exist
        ad.setPositiveButton(R.string.btn_DeleteKeys, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                // delete all more recent keys for now...
                doRemoveMoreRecentKeys();
                refreshView();
            }
        });
    }
    ad.setNegativeButton(R.string.btn_Cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    ad.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });
    return ad;
}

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 a  v a  2  s.com

    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;
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

private AlertDialog.Builder xshowIntroductionInvite(final Activity act, final Bundle args) {
    String exchName = args.getString(extra.EXCH_NAME);
    final String introName = args.getString(extra.INTRO_NAME);
    final byte[] introPhoto = args.getByteArray(extra.PHOTO);
    final byte[] introPush = args.getByteArray(extra.PUSH_REGISTRATION_ID);
    final byte[] introPubKey = args.getByteArray(extra.INTRO_PUBKEY);
    final long msgRowId = args.getLong(extra.MESSAGE_ROW_ID);
    AlertDialog.Builder ad = new AlertDialog.Builder(act);
    View layout;//from   ww  w . j  ava 2  s.  c o  m
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        layout = View.inflate(new ContextThemeWrapper(act, R.style.Theme_AppCompat), R.layout.secureinvite,
                null);
    } else {
        LayoutInflater inflater = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layout = inflater.inflate(R.layout.secureinvite, null);
    }
    TextView textViewExchName = (TextView) layout.findViewById(R.id.textViewExchName);
    TextView textViewIntroName = (TextView) layout.findViewById(R.id.textViewIntroName);
    ImageView imageViewIntroPhoto = (ImageView) layout.findViewById(R.id.imageViewIntroPhoto);
    ad.setTitle(R.string.title_SecureIntroductionInvite);
    textViewExchName.setText(exchName);
    textViewIntroName.setText(introName);
    if (introPhoto != null) {
        try {
            Bitmap bm = BitmapFactory.decodeByteArray(introPhoto, 0, introPhoto.length, null);
            imageViewIntroPhoto.setImageBitmap(bm);
        } catch (OutOfMemoryError e) {
            imageViewIntroPhoto.setImageDrawable(getResources().getDrawable(R.drawable.ic_silhouette));
        }
    }
    ad.setView(layout);
    ad.setCancelable(false);
    ad.setPositiveButton(getString(R.string.btn_Accept), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();

            // accept secure introduction?
            int selected = 0;
            args.putString(extra.NAME + selected, introName);
            args.putByteArray(extra.PHOTO + selected, introPhoto);
            args.putByteArray(SafeSlingerConfig.APP_KEY_PUBKEY + selected, introPubKey);
            args.putByteArray(SafeSlingerConfig.APP_KEY_PUSHTOKEN + selected, introPush);

            String contactLookupKey = getContactLookupKeyByName(introName);
            args.putString(extra.CONTACT_LOOKUP_KEY + selected, contactLookupKey);

            MessageRow inviteMsg = null;
            MessageDbAdapter dbMessage = MessageDbAdapter.openInstance(getApplicationContext());
            Cursor c = dbMessage.fetchMessageSmall(msgRowId);
            if (c != null) {
                try {
                    if (c.moveToFirst()) {
                        inviteMsg = new MessageRow(c, false);
                    }
                } finally {
                    c.close();
                }
            }

            if (inviteMsg == null) {
                showNote(R.string.error_InvalidIncomingMessage);
                return;
            }

            // import the new contacts
            args.putInt(extra.RECIP_SOURCE, RecipientDbAdapter.RECIP_SOURCE_INTRODUCTION);
            args.putString(extra.KEYID, inviteMsg.getKeyId());
            ImportFromExchangeTask importFromExchange = new ImportFromExchangeTask();
            importFromExchange.execute(args);
            setTab(Tabs.MESSAGE);
            refreshView();
        }
    });
    ad.setNegativeButton(getString(R.string.btn_Refuse), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            showNote(String.format(getString(R.string.state_SomeContactsImported), 0));
            refreshView();
        }
    });
    return ad;
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

@SuppressLint("InflateParams")
private void saveThisPage() {
    if (!CompatibilityUtils.hasAccessStorage(activity))
        return;//from  www.jav a  2s .com
    DownloadingService.DownloadingQueueItem check = new DownloadingService.DownloadingQueueItem(
            tabModel.pageModel, presentationModel.source.boardModel, DownloadingService.MODE_DOWNLOAD_ALL);
    String itemName = resources.getString(R.string.downloading_thread_format, tabModel.pageModel.boardName,
            tabModel.pageModel.threadNumber);
    if (DownloadingService.isInQueue(check)) {
        Toast.makeText(activity, resources.getString(R.string.notification_download_already_in_queue, itemName),
                Toast.LENGTH_LONG).show();
    } else {
        Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
                ? new ContextThemeWrapper(activity, R.style.Theme_Neutron)
                : activity;
        View saveThreadDialogView = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_save_thread,
                null);
        final CheckBox saveThumbsChkbox = (CheckBox) saveThreadDialogView
                .findViewById(R.id.dialog_save_thread_thumbs);
        final CheckBox saveAllChkbox = (CheckBox) saveThreadDialogView
                .findViewById(R.id.dialog_save_thread_all);
        switch (settings.getDownloadThreadMode()) {
        case DownloadingService.MODE_DOWNLOAD_ALL:
            saveThumbsChkbox.setChecked(true);
            saveAllChkbox.setChecked(true);
            break;
        case DownloadingService.MODE_DOWNLOAD_THUMBS:
            saveThumbsChkbox.setChecked(true);
            saveAllChkbox.setChecked(false);
            break;
        default:
            saveThumbsChkbox.setChecked(false);
            saveAllChkbox.setChecked(false);
            saveAllChkbox.setEnabled(false);
            break;
        }
        saveThumbsChkbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (saveThumbsChkbox.isChecked()) {
                    saveAllChkbox.setEnabled(true);
                } else {
                    saveAllChkbox.setEnabled(false);
                    saveAllChkbox.setChecked(false);
                }
            }
        });
        DialogInterface.OnClickListener save = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                int mode = DownloadingService.MODE_ONLY_CACHE;
                if (saveThumbsChkbox.isChecked()) {
                    mode = DownloadingService.MODE_DOWNLOAD_THUMBS;
                }
                if (saveAllChkbox.isChecked()) {
                    mode = DownloadingService.MODE_DOWNLOAD_ALL;
                }
                settings.saveDownloadThreadMode(mode);
                Intent savePageIntent = new Intent(activity, DownloadingService.class);
                savePageIntent.putExtra(DownloadingService.EXTRA_DOWNLOADING_ITEM,
                        new DownloadingService.DownloadingQueueItem(tabModel.pageModel,
                                presentationModel.source.boardModel, mode));
                activity.startService(savePageIntent);
            }
        };
        AlertDialog saveThreadDialog = new AlertDialog.Builder(dialogContext).setView(saveThreadDialogView)
                .setTitle(R.string.dialog_save_thread_title)
                .setPositiveButton(R.string.dialog_save_thread_save, save)
                .setNegativeButton(android.R.string.cancel, null).create();
        saveThreadDialog.setCanceledOnTouchOutside(false);
        saveThreadDialog.show();
    }
}