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:android.support.v7ox.widget.Toolbar.java

/**
 * Specifies the theme to use when inflating popup menus. By default, uses
 * the same theme as the toolbar itself.
 *
 * @param resId theme used to inflate popup menus
 * @see #getPopupTheme()/*w ww  . j  av a 2  s.c  o  m*/
 */
public void setPopupTheme(@StyleRes int resId) {
    if (mPopupTheme != resId) {
        mPopupTheme = resId;
        if (resId == 0) {
            mPopupContext = getContext();
        } else {
            mPopupContext = new ContextThemeWrapper(getContext(), resId);
        }
    }
}

From source file:com.gh4a.IssueListActivity.java

private void showMilestonesDialog() {
    String[] milestones = new String[mMilestones.size() + 1];
    final int[] milestoneIds = new int[mMilestones.size() + 1];

    milestones[0] = getResources().getString(R.string.issue_filter_by_any_milestone);
    milestoneIds[0] = 0;// w ww  .ja  v a 2 s. c o m

    String checkedMilestoneNumber = mFilterData.get("milestone");
    int checkedItem = checkedMilestoneNumber != null && !"".equals(checkedMilestoneNumber)
            ? Integer.parseInt(checkedMilestoneNumber)
            : 0;

    for (int i = 1; i <= mMilestones.size(); i++) {
        Milestone m = mMilestones.get(i - 1);
        milestones[i] = m.getTitle();
        milestoneIds[i] = m.getNumber();
        if (m.getNumber() == checkedItem) {
            checkedItem = i;
        }
    }

    int dialogTheme = Gh4Application.THEME == R.style.DefaultTheme ? R.style.Theme_Sherlock_Dialog
            : R.style.Theme_Sherlock_Light_Dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, dialogTheme));
    builder.setCancelable(true);
    builder.setTitle(R.string.issue_filter_by_milestone);
    builder.setSingleChoiceItems(milestones, checkedItem, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == 0) {
                mFilterData.remove("milestone");
            } else {
                mFilterData.put("milestone", String.valueOf(milestoneIds[which]));
            }
        }
    });

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            reloadIssueList();
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    }).create();

    builder.show();
}

From source file:com.andrewshu.android.reddit.reddits.PickSubredditActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;/* ww w . j av a 2s.  c o  m*/
    ProgressDialog pdialog;

    switch (id) {
    // "Please wait"
    case Constants.DIALOG_LOADING_REDDITS_LIST:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Loading your reddits...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:android.support.v7.internal.app.ToolbarActionBar.java

private void ensureListMenuPresenter(Menu menu) {
    if (mListMenuPresenter == null && (menu instanceof MenuBuilder)) {
        MenuBuilder mb = (MenuBuilder) menu;

        Context context = mDecorToolbar.getContext();
        final TypedValue outValue = new TypedValue();
        final Resources.Theme widgetTheme = context.getResources().newTheme();
        widgetTheme.setTo(context.getTheme());

        // Apply the panelMenuListTheme
        widgetTheme.resolveAttribute(R.attr.panelMenuListTheme, outValue, true);
        if (outValue.resourceId != 0) {
            widgetTheme.applyStyle(outValue.resourceId, true);
        } else {/*w w  w . j av a2s . c  o m*/
            widgetTheme.applyStyle(R.style.Theme_AppCompat_CompactMenu, true);
        }

        context = new ContextThemeWrapper(context, 0);
        context.getTheme().setTo(widgetTheme);

        // Finally create the list menu presenter
        mListMenuPresenter = new ListMenuPresenter(context, R.layout.abc_list_menu_item_layout);
        mListMenuPresenter.setCallback(new PanelMenuPresenterCallback());
        mb.addMenuPresenter(mListMenuPresenter);
    }
}

From source file:in.shick.diode.threads.ThreadsListActivity.java

/**
 * http://stackoverflow.com/questions/2257963/android-how-to-show-dialog-to-confirm-user-wishes-to-exit-activity
 *///  w w w. j  a  va  2  s . c  o  m
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //Handle the back button
    if (mSettings.isConfirmQuitOrLogout() && keyCode == KeyEvent.KEYCODE_BACK && isTaskRoot()) {
        //Ask the user if they want to quit
        new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()))
                .setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.quit)
                .setMessage(R.string.really_quit)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        //Stop the activity
                        finish();
                    }
                }).setNegativeButton(R.string.no, null).show();

        return true;
    }
    //if the search button is pressed
    else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        //start activity
        startActivityForResult(new Intent(this, RedditSearchActivity.class), Constants.ACTIVITY_SEARCH_REDDIT);
        return true;

    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:org.fdroid.fdroid.privileged.install.InstallExtensionDialogActivity.java

/**
 * 3. Verify that install worked/*  w  ww  . java 2 s  . com*/
 */
private void postInstall() {
    int isInstalledCorrectly = PrivilegedInstaller.isExtensionInstalledCorrectly(this);

    String title;
    String message;
    final int result;
    switch (isInstalledCorrectly) {
    case PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES:
        title = getString(R.string.system_install_post_success);
        message = getString(R.string.system_install_post_success_message);
        result = Activity.RESULT_OK;

        // enable system installer on installation success
        Preferences.get().setPrivilegedInstallerEnabled(true);
        break;
    case PrivilegedInstaller.IS_EXTENSION_INSTALLED_NO:
        title = getString(R.string.system_install_post_fail);
        message = getString(R.string.system_install_post_fail_message);
        result = Activity.RESULT_CANCELED;
        break;
    case PrivilegedInstaller.IS_EXTENSION_INSTALLED_SIGNATURE_PROBLEM:
        title = getString(R.string.system_install_post_fail);
        message = getString(R.string.system_install_post_fail_message) + "\n\n"
                + getString(R.string.system_install_denied_signature);
        result = Activity.RESULT_CANCELED;
        break;
    case PrivilegedInstaller.IS_EXTENSION_INSTALLED_PERMISSIONS_PROBLEM:
        title = getString(R.string.system_install_post_fail);
        message = getString(R.string.system_install_post_fail_message) + "\n\n"
                + getString(R.string.system_install_denied_permissions);
        result = Activity.RESULT_CANCELED;
        break;
    default:
        throw new RuntimeException("unhandled return");
    }

    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    AlertDialog.Builder builder = new AlertDialog.Builder(theme).setTitle(title).setMessage(message)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    InstallExtensionDialogActivity.this.setResult(result);
                    InstallExtensionDialogActivity.this.finish();
                    startActivity(new Intent(InstallExtensionDialogActivity.this, FDroid.class));
                }
            }).setCancelable(false);
    builder.create().show();
}

From source file:com.jtechme.apphub.privileged.install.InstallExtensionDialogActivity.java

private void uninstall() {
    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

    final boolean isInstalled = PrivilegedInstaller.isExtensionInstalled(this);

    if (isInstalled) {
        String message = InstallExtension.create(getApplicationContext()).getWarningString();

        AlertDialog.Builder builder = new AlertDialog.Builder(theme).setTitle(R.string.system_uninstall)
                .setMessage(Html.fromHtml(message))
                .setPositiveButton(R.string.system_uninstall_button, new DialogInterface.OnClickListener() {
                    @Override/*w w w.  ja  v  a2 s  . com*/
                    public void onClick(DialogInterface dialogInterface, int i) {
                        checkRootTask.execute();
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
                        InstallExtensionDialogActivity.this.finish();
                    }
                });
        builder.create().show();
    } else {
        throw new RuntimeException("Uninstall invoked, but extension is not installed!");
    }
}

From source file:de.vanita5.twittnuker.fragment.support.AccountsDashboardFragment.java

private Context getThemedContext() {
    if (mThemedContext != null)
        return mThemedContext;
    final Context context = getActivity();
    final int themeResource = ThemeUtils.getDrawerThemeResource(context);
    return mThemedContext = new ContextThemeWrapper(context, themeResource);
}

From source file:android.support.v7.app.ActionBarImplBase.java

@Override
public Context getThemedContext() {
    if (mThemedContext == null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = mContext.getTheme();
        currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        final int targetThemeRes = outValue.resourceId;

        if (targetThemeRes != 0) {
            mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
        } else {//from w  w w.  j a v  a 2  s  . c o  m
            mThemedContext = mContext;
        }
    }
    return mThemedContext;
}

From source file:android.support.v7.app.ToolbarActionBar.java

private void ensureListMenuPresenter(Menu menu) {
    if (mListMenuPresenter == null && (menu instanceof MenuBuilder)) {
        MenuBuilder mb = (MenuBuilder) menu;

        Context context = mDecorToolbar.getContext();
        final TypedValue outValue = new TypedValue();
        final Resources.Theme widgetTheme = context.getResources().newTheme();
        widgetTheme.setTo(context.getTheme());

        // First apply the actionBarPopupTheme
        widgetTheme.resolveAttribute(R.attr.actionBarPopupTheme, outValue, true);
        if (outValue.resourceId != 0) {
            widgetTheme.applyStyle(outValue.resourceId, true);
        }/*from  www.  j a v a 2 s. co  m*/

        // Apply the panelMenuListTheme
        widgetTheme.resolveAttribute(R.attr.panelMenuListTheme, outValue, true);
        if (outValue.resourceId != 0) {
            widgetTheme.applyStyle(outValue.resourceId, true);
        } else {
            widgetTheme.applyStyle(R.style.Theme_AppCompat_CompactMenu, true);
        }

        context = new ContextThemeWrapper(context, 0);
        context.getTheme().setTo(widgetTheme);

        // Finally create the list menu presenter
        mListMenuPresenter = new ListMenuPresenter(context, R.layout.abc_list_menu_item_layout);
        mListMenuPresenter.setCallback(new PanelMenuPresenterCallback());
        mb.addMenuPresenter(mListMenuPresenter);
    }
}