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.andrewshu.android.reddit.threads.ThreadsListActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//from ww  w  .  j a va 2 s .  c o  m
    ProgressDialog pdialog;
    AlertDialog.Builder builder;

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

    case Constants.DIALOG_THREAD_CLICK:
        dialog = new ThreadClickDialog(this, mSettings);
        break;

    case Constants.DIALOG_SORT_BY:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("Sort by:");
        builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_CHOICES, getSelectedSortBy(),
                sortByOnClickListener);
        dialog = builder.create();
        break;
    case Constants.DIALOG_SORT_BY_NEW:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("what's new");
        builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_NEW_CHOICES, getSelectedSortByNew(),
                sortByNewOnClickListener);
        dialog = builder.create();
        break;
    case Constants.DIALOG_SORT_BY_CONTROVERSIAL:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("most controversial");
        builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_CONTROVERSIAL_CHOICES,
                getSelectedSortByControversial(), sortByControversialOnClickListener);
        dialog = builder.create();
        break;
    case Constants.DIALOG_SORT_BY_TOP:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("top scoring");
        builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_TOP_CHOICES, getSelectedSortByTop(),
                sortByTopOnClickListener);
        dialog = builder.create();
        break;

    // "Please wait"
    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;

    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (!mCanChord) {
        // The user has already fired a shortcut with this hold down of the
        // menu key.
        return false;
    }//w ww .  j  a  va2 s. c o  m

    switch (item.getItemId()) {
    case R.id.pick_subreddit_menu_id:
        Intent pickSubredditIntent = new Intent(getApplicationContext(), PickSubredditActivity.class);
        startActivityForResult(pickSubredditIntent, Constants.ACTIVITY_PICK_SUBREDDIT);
        break;
    case R.id.login_menu_id:
        showDialog(Constants.DIALOG_LOGIN);
        break;
    case R.id.logout_menu_id:
        if (mSettings.isConfirmQuitOrLogout()) {
            // Ask the user if they want to logout
            new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()))
                    .setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.confirm_logout_title)
                    .setMessage(R.string.confirm_logout)
                    .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            ThreadsListActivity.this.logout();
                        }
                    }).setNegativeButton(R.string.no, null).show();
        } else {
            logout();
        }
        break;
    case R.id.refresh_menu_id:
        CacheInfo.invalidateCachedSubreddit(getApplicationContext());
        if (mSavedUri == null) {
            mObjectStates.mCurrentDownloadThreadsTask = new MyDownloadThreadsTask(mSubreddit);
        } else {
            mObjectStates.mCurrentDownloadThreadsTask = new MyDownloadThreadsTask(mSavedUri);
        }
        mObjectStates.mCurrentDownloadThreadsTask.execute();
        break;
    case R.id.submit_link_menu_id:
        Intent submitLinkIntent = new Intent(getApplicationContext(), SubmitLinkActivity.class);
        submitLinkIntent.setData(Util.createSubmitUri(mSubreddit));
        startActivity(submitLinkIntent);
        break;
    case R.id.sort_by_menu_id:
        showDialog(Constants.DIALOG_SORT_BY);
        break;
    case R.id.open_browser_menu_id:
        String url;
        if (mSubreddit.equals(Constants.FRONTPAGE_STRING))
            url = Constants.REDDIT_BASE_URL;
        else
            url = Constants.REDDIT_BASE_URL + "/r/" + mSubreddit;
        Common.launchBrowser(this, url, null, false, true, true, false);
        break;
    case R.id.light_dark_menu_id:
        mSettings.setTheme(Util.getInvertedTheme(mSettings.getTheme()));
        relaunchActivity();
        break;
    case R.id.inbox_menu_id:
        Intent inboxIntent = new Intent(getApplicationContext(), InboxActivity.class);
        startActivity(inboxIntent);
        break;
    case R.id.user_profile_menu_id:
        Intent profileIntent = new Intent(getApplicationContext(), ProfileActivity.class);
        startActivity(profileIntent);
        break;
    case R.id.preferences_menu_id:
        Intent prefsIntent = new Intent(getApplicationContext(), RedditPreferencesPage.class);
        startActivity(prefsIntent);
        break;
    case R.id.subscribe_menu_id:
        CacheInfo.invalidateCachedSubreddit(getApplicationContext());
        new SubscribeTask(mSubreddit, getApplicationContext(), mSettings).execute();
        break;
    case R.id.unsubscribe_menu_id:
        CacheInfo.invalidateCachedSubreddit(getApplicationContext());
        new UnsubscribeTask(mSubreddit, getApplicationContext(), mSettings).execute();
        break;
    case android.R.id.home:
        Common.goHome(this);
        break;
    case R.id.search:
        startActivityForResult(new Intent(this, RedditSearchActivity.class), Constants.ACTIVITY_SEARCH_REDDIT);
        break;
    case R.id.saved_comments_menu_id:
        Intent toSC = new Intent(getApplicationContext(), SavedCommentsActivity.class);
        startActivity(toSC);
        //Toast.makeText(ThreadsListActivity.this, "This is a test", Toast.LENGTH_LONG).show();
        break;
    default:
        throw new IllegalArgumentException("Unexpected action value " + item.getItemId());
    }

    return true;
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static Bitmap getTintedBitmapForTheme(Context context, int drawableResId, int themeResId) {
    Context wrappedContext = new ContextThemeWrapper(context, themeResId);
    Drawable d = AppCompatDrawableManager.get().getDrawable(wrappedContext, drawableResId);
    Bitmap b = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    d.setBounds(0, 0, c.getWidth(), c.getHeight());
    d.draw(c);/*from  ww  w  . ja  v a  2 s. co m*/
    return b;
}

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

public static void answerToRestoreIconPack(final Activity context, String packName) {
    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_icon) + " " + packName + "?");

    alert.setPositiveButton(context.getResources().getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    applyChange(context);
                }//from   w w w  .ja v a2s. c om
            });

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

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

private void resolveTheme() {
    // Look up the guidedStepTheme in the currently specified theme.  If it exists,
    // replace the theme with its value.
    Activity activity = getActivity();/*from   ww  w.j a  v  a2s.  co m*/
    if (mTheme == -1 && !isGuidedStepTheme(activity)) {
        // Look up the guidedStepTheme in the activity's currently specified theme.  If it
        // exists, replace the theme with its value.
        int resId = R.attr.guidedStepTheme;
        TypedValue typedValue = new TypedValue();
        boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
        if (DEBUG)
            Log.v(TAG, "Found guided step theme reference? " + found);
        if (found) {
            ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId);
            if (isGuidedStepTheme(themeWrapper)) {
                mTheme = typedValue.resourceId;
                mThemeWrapper = themeWrapper;
            } else {
                found = false;
                mThemeWrapper = null;
            }
        }
        if (!found) {
            Log.e(TAG, "GuidedStepFragment does not have an appropriate theme set.");
        }
    } else if (mTheme != -1) {
        mThemeWrapper = new ContextThemeWrapper(activity, mTheme);
    }
}

From source file:com.rbware.github.androidcouchpotato.app.GuidedStepFragment.java

private void resolveTheme() {
    // Look up the guidedStepTheme in the currently specified theme.  If it exists,
    // replace the theme with its value.
    Activity activity = getActivity();//from  w  ww . j av  a  2 s  . c om
    int theme = onProvideTheme();
    if (theme == -1 && !isGuidedStepTheme(activity)) {
        // Look up the guidedStepTheme in the activity's currently specified theme.  If it
        // exists, replace the theme with its value.
        int resId = R.attr.guidedStepTheme;
        TypedValue typedValue = new TypedValue();
        boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
        if (DEBUG)
            Log.v(TAG, "Found guided step theme reference? " + found);
        if (found) {
            ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId);
            if (isGuidedStepTheme(themeWrapper)) {
                mThemeWrapper = themeWrapper;
            } else {
                found = false;
                mThemeWrapper = null;
            }
        }
        if (!found) {
            Log.e(TAG, "GuidedStepFragment does not have an appropriate theme set.");
        }
    } else if (theme != -1) {
        mThemeWrapper = new ContextThemeWrapper(activity, theme);
    }
}

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

public static void answerToChangeDefaultLauncher(final Context context) {
    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_default));

    alert.setPositiveButton(context.getResources().getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    changeDefaultLauncher(context);
                }//from w  w w .ja  v  a 2s  .c o m
            });

    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:android.support.v17.leanback.app.GuidedStepSupportFragment.java

private void resolveTheme() {
    // Look up the guidedStepTheme in the currently specified theme.  If it exists,
    // replace the theme with its value.
    FragmentActivity activity = getActivity();
    if (mTheme == -1 && !isGuidedStepTheme(activity)) {
        // Look up the guidedStepTheme in the activity's currently specified theme.  If it
        // exists, replace the theme with its value.
        int resId = R.attr.guidedStepTheme;
        TypedValue typedValue = new TypedValue();
        boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
        if (DEBUG)
            Log.v(TAG, "Found guided step theme reference? " + found);
        if (found) {
            ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId);
            if (isGuidedStepTheme(themeWrapper)) {
                mTheme = typedValue.resourceId;
                mThemeWrapper = themeWrapper;
            } else {
                found = false;//from  w  w w. ja  v a  2s .  com
                mThemeWrapper = null;
            }
        }
        if (!found) {
            Log.e(TAG, "GuidedStepSupportFragment does not have an appropriate theme set.");
        }
    } else if (mTheme != -1) {
        mThemeWrapper = new ContextThemeWrapper(activity, mTheme);
    }
}

From source file:com.rbware.github.androidcouchpotato.app.GuidedStepSupportFragment.java

private void resolveTheme() {
    // Look up the guidedStepTheme in the currently specified theme.  If it exists,
    // replace the theme with its value.
    FragmentActivity activity = getActivity();
    int theme = onProvideTheme();
    if (theme == -1 && !isGuidedStepTheme(activity)) {
        // Look up the guidedStepTheme in the activity's currently specified theme.  If it
        // exists, replace the theme with its value.
        int resId = R.attr.guidedStepTheme;
        TypedValue typedValue = new TypedValue();
        boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
        if (DEBUG)
            Log.v(TAG, "Found guided step theme reference? " + found);
        if (found) {
            ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId);
            if (isGuidedStepTheme(themeWrapper)) {
                mThemeWrapper = themeWrapper;
            } else {
                found = false;//from w w w.  jav a2s .c o  m
                mThemeWrapper = null;
            }
        }
        if (!found) {
            Log.e(TAG, "GuidedStepSupportFragment does not have an appropriate theme set.");
        }
    } else if (theme != -1) {
        mThemeWrapper = new ContextThemeWrapper(activity, theme);
    }
}