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.gh4a.IssueListActivity.java

private void showLabelsDialog() {
    String selectedLabels = mFilterData.get("labels");
    String[] checkedLabels = new String[] {};

    if (selectedLabels != null) {
        checkedLabels = selectedLabels.split(",");
    }/*from  w w w .  j  av a  2s  .c  o  m*/
    List<String> checkLabelStringList = Arrays.asList(checkedLabels);
    final boolean[] checkedItems = new boolean[mLabels.size()];

    final String[] allLabelArray = new String[mLabels.size()];

    for (int i = 0; i < mLabels.size(); i++) {
        Label l = mLabels.get(i);
        allLabelArray[i] = l.getName();
        if (checkLabelStringList.contains(l.getName())) {
            checkedItems[i] = true;
        } else {
            checkedItems[i] = false;
        }
    }

    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_labels);
    builder.setMultiChoiceItems(allLabelArray, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
        public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
            if (isChecked) {
                checkedItems[whichButton] = true;
            } else {
                checkedItems[whichButton] = false;
            }
        }
    });

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();
            String labels = "";
            for (int i = 0; i < allLabelArray.length; i++) {
                if (checkedItems[i]) {
                    labels += allLabelArray[i] + ",";
                }
            }
            mFilterData.put("labels", labels);
            reloadIssueList();
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();
        }
    }).create();

    builder.show();
}

From source file:uk.ac.ucl.excites.sapelli.collector.tasks.Backup.java

private void showSuccessDialog(final File destZipFile) {
    // Get dialog builder & configure the dialog...
    new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
            //   Set title:
            .setTitle(R.string.successful_backup)
            //   Set message:
            .setMessage(activity.getString(R.string.backup_in) + "\n" + destZipFile.getAbsolutePath())
            // Set "OK" button:
            .setPositiveButton(R.string.done, null)
            // Set "Share" button:
            .setNegativeButton(R.string.share, new DialogInterface.OnClickListener() {
                @Override//from w  w w  .java2 s  .co  m
                public void onClick(DialogInterface dialog, int which) {
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(destZipFile));
                    sendIntent.setType("application/zip");
                    activity.startActivity(sendIntent);
                }
            })
            // Create & show the dialog:
            .create().show();
}

From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java

/**
 * http://stackoverflow.com/questions/2257963/android-how-to-show-dialog-to-confirm-user-wishes-to-exit-activity
 *///from w w  w .java2 s  .  com
@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;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:org.ciasaboark.tacere.activity.fragment.AdvancedSettingsFragment.java

private void drawQuickSilenceWidget() {
    LinearLayout quicksilenceBox = (LinearLayout) rootView
            .findViewById(R.id.advanced_settings_quicksilence_box);
    quicksilenceBox.setOnClickListener(new View.OnClickListener() {
        @Override/*w  w w .  j  ava 2  s . c o m*/
        public void onClick(View v) {
            LayoutInflater inflater = LayoutInflater.from(v.getContext());
            View dialogView = inflater.inflate(R.layout.dialog_quicksilent, null);
            final AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(context, R.style.Dialog));
            builder.setTitle(R.string.notification_quicksilence_title);
            builder.setView(dialogView);

            final NumberPicker hourP = (NumberPicker) dialogView.findViewById(R.id.hourPicker);
            final NumberPicker minP = (NumberPicker) dialogView.findViewById(R.id.minutePicker);

            String[] hours = new String[25];
            String[] minutes = new String[59];

            for (int i = 0; i < hours.length; i++) {
                hours[i] = Integer.toString(i);
            }

            int i = 0;
            while (i < minutes.length) {
                minutes[i] = Integer.toString(++i);
            }

            hourP.setMinValue(1);
            hourP.setMaxValue(hours.length - 1);
            hourP.setWrapSelectorWheel(false);
            hourP.setDisplayedValues(hours);
            hourP.setValue(prefs.getQuickSilenceHours() + 1);

            minP.setMinValue(1);
            minP.setMaxValue(minutes.length - 1);
            minP.setWrapSelectorWheel(false);
            minP.setDisplayedValues(minutes);
            minP.setValue(prefs.getQuicksilenceMinutes());

            builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    prefs.setQuickSilenceHours(hourP.getValue() - 1);
                    prefs.setQuicksilenceMinutes(minP.getValue());
                    drawQuickSilenceWidget();
                }
            });

            builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    //do nothing
                }
            });

            AlertDialog dialog = builder.show();
        }
    });

    //the quick silence button
    TextView quickTV = (TextView) rootView.findViewById(R.id.quickSilenceDescription);
    String quicksilenceText = getResources()
            .getString(R.string.advanced_settings_section_interval_quicksilence_duration);
    String hrs = "";
    if (prefs.getQuickSilenceHours() > 0) {
        hrs = String.valueOf(prefs.getQuickSilenceHours()) + " " + getString(R.string.hours_lower) + " ";
    }
    quickTV.setText(String.format(quicksilenceText, hrs, prefs.getQuicksilenceMinutes()));
}

From source file:android.support.v17.leanback.widget.AbstractMediaItemPresenter.java

@Override
protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) {
    Context context = parent.getContext();
    if (mThemeId != 0) {
        context = new ContextThemeWrapper(context, mThemeId);
    }//w  w w  . j  ava  2s  .c o m
    View view = LayoutInflater.from(context).inflate(R.layout.lb_row_media_item, parent, false);
    final ViewHolder vh = new ViewHolder(view);
    vh.mRowPresenter = this;
    if (mBackgroundColorSet) {
        vh.mMediaRowView.setBackgroundColor(mBackgroundColor);
    }
    return vh;
}

From source file:com.gh4a.IssueCreateActivity.java

private void showAssigneesDialog() {
    final String[] assignees = new String[mAllAssignee.size() + 1];
    assignees[0] = getResources().getString(R.string.issue_clear_assignee);

    int checkedItem = 0;

    for (int i = 1; i <= mAllAssignee.size(); i++) {
        User u = mAllAssignee.get(i - 1);
        assignees[i] = u.getLogin();//  w  w w.  j ava2 s .com
        if (mSelectedAssignee != null && u.getLogin().equalsIgnoreCase(mSelectedAssignee.getLogin())) {
            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_assignee);
    builder.setSingleChoiceItems(assignees, checkedItem, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == 0) {
                mSelectedAssignee = null;
            } else {
                mSelectedAssignee = mAllAssignee.get(which - 1);
            }
        }
    });

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if (mSelectedAssignee != null) {
                mTvSelectedAssignee
                        .setText(IssueCreateActivity.this.getResources().getString(R.string.issue_assignee)
                                + " : " + mSelectedAssignee.getLogin());
            } else {
                mTvSelectedAssignee.setText(null);
            }
            dialog.dismiss();
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    }).create();

    builder.show();
}

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

/**
 * 3. Verify that install worked//from www  .j  av  a 2 s.c o m
 */
private void postInstall() {
    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());

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

    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:android.support.v7.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()//from   w  ww . ja v  a2s  . c o m
 */
public void setPopupTheme(int resId) {
    if (mPopupTheme != resId) {
        mPopupTheme = resId;
        if (resId == 0) {
            mPopupContext = getContext();
        } else {
            mPopupContext = new ContextThemeWrapper(getContext(), resId);
        }
    }
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java

@SuppressLint("NewApi")
private View createUpdatesFoundDialogContentsView(Update update) {
    Context context = activity;/*from  ww w .  j ava 2 s .c  o m*/

    final AlertDialog.Builder builder;

    // Workaround for dialog theme problems
    if (android.os.Build.VERSION.SDK_INT > 10) {
        builder = new AlertDialog.Builder(context);
        context = builder.getContext();
    } else {
        context = new ContextThemeWrapper(context, android.R.style.Theme_Dialog);
        builder = new AlertDialog.Builder(context);
    }

    builder.setTitle("Send feedback");

    final LayoutInflater inflater = LayoutInflater.from(context);
    final View dialogContentsView = inflater.inflate(R.layout.updater_dialog_update_found, null, false);

    final TextView messageTextView = (TextView) dialogContentsView
            .findViewById(R.id.dialog_update_found_message);
    final TextView warningTextView = (TextView) dialogContentsView
            .findViewById(R.id.dialog_update_found_warning);
    final TextView whatIsNewTextView = (TextView) dialogContentsView
            .findViewById(R.id.dialog_update_found_what_is_new);

    String warnings = null;
    String message = null;
    String whatIsNew = null;

    if (update.description != null) {
        warnings = update.description.get(UpdateDescription.KEY_WARNINGS);
        message = update.description.get(UpdateDescription.KEY_MESSAGE);
        whatIsNew = update.description.get(UpdateDescription.KEY_WHAT_IS_NEW);
    }

    if (Utilities.isNullOrEmpty(message)) {
        messageTextView.setVisibility(View.GONE);
    } else {
        messageTextView.setText(message);
    }

    if (Utilities.isNullOrEmpty(warnings)) {
        warningTextView.setVisibility(View.GONE);
    } else {
        warningTextView.setText(warnings);
    }

    if (Utilities.isNullOrEmpty(whatIsNew)) {
        whatIsNewTextView.setVisibility(View.GONE);
    } else {
        whatIsNewTextView.setText(whatIsNew);
    }
    return dialogContentsView;
}

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

private void resolveTheme() {
    FragmentActivity activity = getActivity();
    int theme = onProvideTheme();
    if (theme == -1) {
        // Look up the onboardingTheme in the activity's currently specified theme. If it
        // exists, wrap the theme with its value.
        int resId = R.attr.onboardingTheme;
        TypedValue typedValue = new TypedValue();
        boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
        if (DEBUG)
            Log.v(TAG, "Found onboarding theme reference? " + found);
        if (found) {
            mThemeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId);
        }/*  w w  w  . j ava  2s .  c  o m*/
    } else {
        mThemeWrapper = new ContextThemeWrapper(activity, theme);
    }
}