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:Main.java

public static Context getDialogContext(Context context) {
    return new ContextThemeWrapper(context, getDialogTheme());
}

From source file:io.trigger.forge.android.modules.contextmenu.API.java

public static void show(final ForgeTask task, @ForgeParam("items") final JsonArray JSONItems)
        throws JSONException {
    final AlertDialog.Builder builder = new AlertDialog.Builder(
            new ContextThemeWrapper(ForgeApp.getActivity(), android.R.style.Theme_Holo));
    final String[] items = toJavaArray(JSONItems);
    builder.setItems(items, new OnClickListener() {
        @Override//from  w  w  w .  j a va 2s. co m
        public void onClick(DialogInterface dialog, int which) {
            task.success(items[which]);
        }
    });
    AlertDialog toShow = builder.create();
    toShow.show();
}

From source file:com.example.spellingcoach.tabs.wordlists.WordListsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // create ContextThemeWrapper from the original Activity Context with the custom theme
    final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.wordlistsListViewTheme);

    // clone the inflater using the ContextThemeWrapper
    LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);

    // inflate the layout using the cloned inflater, not default inflater
    return localInflater.inflate(R.layout.fragment_tab_wordlists, container, false);
}

From source file:io.jari.geenstijl.Dialogs.ConfirmLogoutDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    //force dark dialog CUZ I WANT TO
    ContextThemeWrapper wrapper = new ContextThemeWrapper(activity, android.R.style.Theme_Holo);

    AlertDialog.Builder builder = new AlertDialog.Builder(wrapper);
    builder.setMessage(getResources().getString(R.string.confirm_logout)).setInverseBackgroundForced(true)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    API.logOut(activity);
                    forceOptionsReload();
                }/*from  ww  w .  j  a  v  a2 s.  c om*/
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ConfirmLogoutDialog.this.getDialog().cancel();
                }
            }).setTitle(R.string.logout);

    return builder.create();
}

From source file:com.hybris.mobile.app.commerce.utils.UIUtils.java

/**
 * Show alert message//from   w  w  w .j  ava  2s .  c o m
 *
 * @param context
 * @param title
 * @param message
 */
public static void showAlertMessage(Context context, String title, String message) {

    AlertDialog.Builder builder = new AlertDialog.Builder(
            new ContextThemeWrapper(context, R.style.AlertDialogCustom));
    builder.setTitle(title).setIcon(android.R.drawable.ic_dialog_alert).setMessage(message).setCancelable(true)
            .setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.tortel.deploytrack.fragments.AboutDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context wrappedContext = new ContextThemeWrapper(getActivity(), R.style.Theme_DeployThemeLight);

    MaterialDialog.Builder builder = new MaterialDialog.Builder(wrappedContext);

    LayoutInflater inflater = getActivity().getLayoutInflater().cloneInContext(wrappedContext);
    View view = inflater.inflate(R.layout.about, null);
    TextView text = (TextView) view.findViewById(R.id.about_view);

    text.setText(Html.fromHtml(readRawTextFile(R.raw.about)));
    Linkify.addLinks(text, Linkify.ALL);
    text.setMovementMethod(LinkMovementMethod.getInstance());

    builder.customView(view, false);/*from  w w  w .  jav a  2  s.  co  m*/
    builder.title(R.string.app_name);
    builder.positiveText(R.string.close);

    return builder.build();
}

From source file:org.fdroid.fdroid.installer.ErrorDialogActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Intent intent = getIntent();
    final String title = intent.getStringExtra(EXTRA_TITLE);
    final String message = intent.getStringExtra(EXTRA_MESSAGE);

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

    final AlertDialog.Builder builder = new AlertDialog.Builder(theme);
    builder.setTitle(title);//from  ww  w .  ja  va 2 s.  c  om
    builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            setResult(Activity.RESULT_OK);
            finish();
        }
    });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    builder.setMessage(message);
    builder.create().show();
}

From source file:com.asksven.betterbatterystats.ShareDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the Builder class for convenient dialog construction
    //ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Light_Dialog);
    ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), BaseActivity.getTheme(getActivity()));

    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    final ArrayList<Integer> selectedSaveActions = new ArrayList<Integer>();

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    boolean saveAsText = sharedPrefs.getBoolean("save_as_text", true);
    boolean saveAsJson = sharedPrefs.getBoolean("save_as_json", false);
    boolean saveLogcat = sharedPrefs.getBoolean("save_logcat", false);
    boolean saveDmesg = sharedPrefs.getBoolean("save_dmesg", false);

    final String m_refFromName = "";
    final String m_refToName = "";

    if (saveAsText) {
        selectedSaveActions.add(0);//from  ww w  .  j  ava2 s. c om
    }
    if (saveAsJson) {
        selectedSaveActions.add(1);
    }
    if (saveLogcat) {
        selectedSaveActions.add(2);
    }
    if (saveDmesg) {
        selectedSaveActions.add(3);
    }

    builder.setTitle("Title");

    builder.setMultiChoiceItems(R.array.saveAsLabels,
            new boolean[] { saveAsText, saveAsJson, saveLogcat, saveDmesg },
            new DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    if (isChecked) {
                        // If the user checked the item, add it to the
                        // selected items
                        selectedSaveActions.add(which);
                    } else if (selectedSaveActions.contains(which)) {
                        // Else, if the item is already in the array,
                        // remove it
                        selectedSaveActions.remove(Integer.valueOf(which));
                    }
                }
            })
            // Set the action buttons
            .setPositiveButton(R.string.label_button_share, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    ArrayList<Uri> attachements = new ArrayList<Uri>();

                    Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, getActivity());
                    Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, getActivity());

                    Reading reading = new Reading(getActivity(), myReferenceFrom, myReferenceTo);

                    // save as text is selected
                    if (selectedSaveActions.contains(0)) {
                        attachements.add(reading.writeToFileText(getActivity()));
                    }
                    // save as JSON if selected
                    if (selectedSaveActions.contains(1)) {
                        attachements.add(reading.writeToFileJson(getActivity()));
                    }
                    // save logcat if selected
                    if (selectedSaveActions.contains(2)) {
                        attachements.add(StatsProvider.getInstance(getActivity()).writeLogcatToFile());
                    }
                    // save dmesg if selected
                    if (selectedSaveActions.contains(3)) {
                        attachements.add(StatsProvider.getInstance(getActivity()).writeDmesgToFile());
                    }

                    if (!attachements.isEmpty()) {
                        Intent shareIntent = new Intent();
                        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachements);
                        shareIntent.setType("text/*");
                        startActivity(Intent.createChooser(shareIntent, "Share info to.."));
                    }
                }
            }).setNeutralButton(R.string.label_button_save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {

                    Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, getActivity());
                    Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, getActivity());

                    Reading reading = new Reading(getActivity(), myReferenceFrom, myReferenceTo);

                    // save as text is selected
                    // save as text is selected
                    if (selectedSaveActions.contains(0)) {
                        reading.writeToFileText(getActivity());
                    }
                    // save as JSON if selected
                    if (selectedSaveActions.contains(1)) {
                        reading.writeToFileJson(getActivity());
                    }
                    // save logcat if selected
                    if (selectedSaveActions.contains(2)) {
                        StatsProvider.getInstance(getActivity()).writeLogcatToFile();
                    }
                    // save dmesg if selected
                    if (selectedSaveActions.contains(3)) {
                        StatsProvider.getInstance(getActivity()).writeDmesgToFile();
                    }

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

    // Create the AlertDialog object and return it
    return builder.create();
}

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

/**
 * Creates a themed context based on the explicit style resource or the parent context's default
 * theme./*from   w  w  w . java  2  s. c o  m*/
 * <p>
 * The theme which will be applied on top of the parent {@code context}'s theme is determined
 * by the primary color defined in the given {@code style}, or in the parent {@code context}.
 *
 * @param context the parent context
 * @param style the resource ID of the style against which to inflate this context, or
 *              {@code 0} to use the parent {@code context}'s default theme.
 * @return The themed context.
 */
public static Context createThemedContext(Context context, int style) {
    int theme;
    if (isLightTheme(context)) {
        if (getControllerColor(context, style) == COLOR_DARK_ON_LIGHT_BACKGROUND) {
            theme = R.style.Theme_MediaRouter_Light;
        } else {
            theme = R.style.Theme_MediaRouter_Light_DarkControlPanel;
        }
    } else {
        if (getControllerColor(context, style) == COLOR_DARK_ON_LIGHT_BACKGROUND) {
            theme = R.style.Theme_MediaRouter_LightControlPanel;
        } else {
            theme = R.style.Theme_MediaRouter;
        }
    }
    return new ContextThemeWrapper(context, theme);
}

From source file:fr.steren.climbtracker.GradePickerFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // TODO: create a custom layout with a nicer Grade selector (centered?), see http://developer.android.com/guide/topics/ui/dialogs.html

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences((Activity) mListener);
    String gradeSystemTypePref = sharedPref.getString(Path.PREF_GRAD_SYSTEM_TYPE, GradeList.SYSTEM_DEFAULT);

    mGradeList = new GradeList((Activity) mListener, gradeSystemTypePref);

    AlertDialog.Builder builder = new AlertDialog.Builder(
            new ContextThemeWrapper(getActivity(), R.style.PickerDialog));

    ArrayList<String> grades = mGradeList.getGradeStringList();
    CharSequence[] cs = grades.toArray(new CharSequence[grades.size()]);
    builder.setTitle(R.string.pick_grade).setItems(cs, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            mListener.onGradeSelected(mGradeList.get(which).label);
        }//from   w ww.  j  av  a  2  s .  co  m

    });

    return builder.create();
}