List of usage examples for android.view ContextThemeWrapper ContextThemeWrapper
public ContextThemeWrapper(Context base, Resources.Theme theme)
From source file:org.steveleach.scoresheet.ui.ScoresheetActivity.java
private void questionDialog(String prompt, String yesButton, String noButton, final Runnable action) { DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @Override/*from ww w .ja v a 2s . c o m*/ public void onClick(DialogInterface dialog, int button) { switch (button) { case DialogInterface.BUTTON_POSITIVE: action.run(); break; case DialogInterface.BUTTON_NEGATIVE: break; } } }; ContextThemeWrapper wrapper = new ContextThemeWrapper(this, R.style.AppDialog); AlertDialog.Builder builder = new AlertDialog.Builder(wrapper); AlertDialog dialog = builder.setTitle(getString(R.string.confirmAlertTitle)).setMessage(prompt) .setPositiveButton(yesButton, listener).setNegativeButton(noButton, listener).create(); dialog.show(); int color = getResources().getColor(R.color.appdark); TextView tv = (TextView) getDialogView(dialog, "android:id/alertTitle"); tv.setTextColor(color); View divider = getDialogView(dialog, "android:id/titleDivider"); divider.setBackgroundColor(color); }
From source file:org.fdroid.fdroid.installer.InstallIntoSystemDialogActivity.java
/** * 3. Verify that install worked//from w w w . j a v a2 s.c o m */ private void postInstall() { // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId()); final boolean success = Installer.hasSystemPermissions(this, this.getPackageManager()); // enable system installer on installation success Preferences.get().setSystemInstallerEnabled(success); AlertDialog.Builder builder = new AlertDialog.Builder(theme) .setTitle(success ? R.string.system_install_post_success : R.string.system_install_post_fail) .setMessage(success ? R.string.system_install_post_success_message : R.string.system_install_post_fail_message) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { InstallIntoSystemDialogActivity.this .setResult(success ? Activity.RESULT_OK : Activity.RESULT_CANCELED); InstallIntoSystemDialogActivity.this.finish(); startActivity(new Intent(InstallIntoSystemDialogActivity.this, FDroid.class)); } }).setCancelable(false); builder.create().show(); }
From source file:com.gh4a.IssueCreateActivity.java
private void showMilestonesDialog() { final String[] milestones = new String[mAllMilestone.size() + 1]; milestones[0] = getResources().getString(R.string.issue_clear_milestone); int checkedItem = 0; if (mSelectedMilestone != null) { checkedItem = mSelectedMilestone.getNumber(); }//from w w w .ja v a2s . c o m for (int i = 1; i <= mAllMilestone.size(); i++) { Milestone m = mAllMilestone.get(i - 1); milestones[i] = m.getTitle(); 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_milestone); builder.setSingleChoiceItems(milestones, checkedItem, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { mSelectedMilestone = null; } else { mSelectedMilestone = mAllMilestone.get(which - 1); } } }); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (mSelectedMilestone != null) { mTvSelectedMilestone .setText(IssueCreateActivity.this.getResources().getString(R.string.issue_milestone) + " : " + mSelectedMilestone.getTitle()); } else { mTvSelectedMilestone.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:course1778.mobileapp.safeMedicare.Main.FamMemFrag.java
private void add() { LayoutInflater inflater = getActivity().getLayoutInflater(); View addView = inflater.inflate(R.layout.add_edit, null); //AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(getContext(), R.style.AlertDialogCustom)); builder.setTitle(R.string.add_title).setView(addView).setPositiveButton(R.string.ok, this) .setNegativeButton(R.string.cancel, null).show(); Spinner spin = (Spinner) addView.findViewById(R.id.spinner); //spin.setOnItemSelectedListener(FamMemActivity.getContext()); ArrayAdapter<String> aa = new ArrayAdapter<String>(FamMemActivity.getContext(), R.layout.spinner_item_text, items);//from ww w. j a va 2 s .com aa.setDropDownViewResource(R.layout.spinner_dropdown_item); spin.setAdapter(aa); // field for user adding medication name textView = (AutoCompleteTextView) addView.findViewById(R.id.title); /** sheet 1 displays all the drug interactions; * sheet 2 displays the list of all drugs */ crsList = med_list.rawQuery("SELECT * FROM Sheet1", null); crsInteractions = med_interaction.rawQuery("SELECT * FROM DrugDrug", null); String[] array = new String[crsList.getCount()]; int i = 0; while (crsList.moveToNext()) { String uname = crsList.getString(crsList.getColumnIndex("Name")); array[i] = uname; i++; } // Create the adapter and set it to the AutoCompleteTextView ArrayAdapter<String> adapter = new ArrayAdapter<String>(FamMemActivity.getContext(), R.layout.listlayout, R.id.listTextView, array); textView.setAdapter(adapter); }
From source file:in.shick.diode.common.Common.java
/** * Helper function to display a list of URLs. * @param theContext The current application context. * @param settings The settings to use regarding the browser component. * @param theItem The ThingInfo item to get URLs from. *//*from w w w .j a va 2s.com*/ public static void showLinksDialog(final Context theContext, final RedditSettings settings, final ThingInfo theItem) { assert (theContext != null); assert (theItem != null); assert (settings != null); final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<MarkdownURL> vtUrls = theItem.getUrls(); for (MarkdownURL vtUrl : vtUrls) { urls.add(vtUrl.url); } ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(theContext, android.R.layout.select_dialog_item, vtUrls) { public View getView(int position, View convertView, ViewGroup parent) { TextView tv; if (convertView == null) { tv = (TextView) ((LayoutInflater) theContext.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 = theContext.getPackageManager() .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (PackageManager.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(theContext, settings.getDialogTheme())); DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { if (which >= 0) { Common.launchBrowser(settings, theContext, urls.get(which), Util.createThreadUri(theItem).toString(), false, false, settings.isUseExternalBrowser(), settings.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:android.support.v14.preference.PreferenceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragment, TypedArrayUtils.getAttr(mStyledContext, android.support.v7.preference.R.attr.preferenceFragmentStyle, AndroidResources.ANDROID_R_PREFERENCE_FRAGMENT_STYLE), 0);/*from w ww . j a va 2s.c o m*/ mLayoutResId = a.getResourceId(R.styleable.PreferenceFragment_android_layout, mLayoutResId); final Drawable divider = a.getDrawable(R.styleable.PreferenceFragment_android_divider); final int dividerHeight = a.getDimensionPixelSize(R.styleable.PreferenceFragment_android_dividerHeight, -1); a.recycle(); // Need to theme the inflater to pick up the preferenceFragmentListStyle final TypedValue tv = new TypedValue(); getActivity().getTheme().resolveAttribute(android.support.v7.preference.R.attr.preferenceTheme, tv, true); final int theme = tv.resourceId; final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme); final LayoutInflater themedInflater = inflater.cloneInContext(themedContext); final View view = themedInflater.inflate(mLayoutResId, container, false); final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER); if (!(rawListContainer instanceof ViewGroup)) { throw new RuntimeException("Content has view with id attribute " + "'android.R.id.list_container' that is not a ViewGroup class"); } final ViewGroup listContainer = (ViewGroup) rawListContainer; final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState); if (listView == null) { throw new RuntimeException("Could not create RecyclerView"); } mList = listView; listView.addItemDecoration(mDividerDecoration); setDivider(divider); if (dividerHeight != -1) { setDividerHeight(dividerHeight); } listContainer.addView(mList); mHandler.post(mRequestFocus); return view; }
From source file:com.hybris.mobile.app.commerce.adapter.CartProductListAdapter.java
/** * Display the delete item dialog/*from w w w. ja v a 2s . c om*/ * * @param positionToDelete */ private void showDeleteItemDialog(final int positionToDelete) { // Creating the dialog AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(getContext(), R.style.AlertDialogCustom)); builder.setMessage(R.string.cart_menu_delete_item_confirmation_title).setPositiveButton( R.string.cart_menu_delete_item_remove_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { QueryCartEntry queryCartEntry = new QueryCartEntry(); queryCartEntry.setEntryNumber(positionToDelete + ""); CommerceApplication.getContentServiceHelper() .deleteCartEntry(new ResponseReceiver<CartModification>() { @Override public void onResponse(Response<CartModification> response) { updateCart(); } @Override public void onError(Response<ErrorList> response) { UIUtils.showError(response, getContext()); // Update the cart SessionHelper.updateCart(getContext(), mRequestId, false); } }, mRequestId, queryCartEntry, null, false, null, mOnRequestListener); } }).setNegativeButton(R.string.cancel, null); AlertDialog alert = builder.create(); // The dialog is cancelable by 3 ways: cancel button, click outside the dialog, click on the back button alert.setCancelable(true); alert.setCanceledOnTouchOutside(true); alert.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { // We revert to the default quantity when we dismiss the dialog if (mSelectedQuantity != null) { mSelectedQuantity.getEditText().clearFocus(); mSelectedQuantity.getEditText().setText(mSelectedQuantity.getDefaultValue() + ""); } } }); alert.show(); }
From source file:org.ciasaboark.tacere.activity.fragment.EventDetailsFragment.java
private void saveSettings() { if (databaseInterface.doesEventRepeat(event.getEventId())) { long eventRepetions = databaseInterface.getEventRepetitionCount(event.getEventId()); String positiveButtonText = getResources().getString(R.string.event_dialog_save_all_instances_message); Drawable icon = getResources().getDrawable(R.drawable.history); AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(getActivity(), R.style.Dialog)) .setTitle(R.string.event_dialog_repeating_event_conformation_title) .setMessage(String.format(positiveButtonText, event.getTitle(), eventRepetions)) .setPositiveButton(R.string.event_dialog_save_all_instances, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { saveSettingsForAllEvents(); }/*w w w .j av a2s .co m*/ }) .setNegativeButton(R.string.event_dialog_save_instance, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { saveSettingsForEventInstance(); } }) .setIcon(icon); AlertDialog dialog = builder.show(); } else { saveSettingsForEventInstance(); } }
From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java
public static ContextThemeWrapper createThemeWrapper(Context context, int parentStyleAttr, int parentDefaultStyle, int childStyleAttr, int childDefaultStyle) { final TypedArray forParent = context.obtainStyledAttributes(new int[] { parentStyleAttr }); int parentStyle = forParent.getResourceId(0, parentDefaultStyle); forParent.recycle();/* ww w. j a v a2s .c o m*/ TypedArray forChild = context.obtainStyledAttributes(parentStyle, new int[] { childStyleAttr }); int childStyleId = forChild.getResourceId(0, childDefaultStyle); forChild.recycle(); return new ContextThemeWrapper(context, childStyleId); }
From source file:org.fdroid.fdroid.installer.InstallIntoSystemDialogActivity.java
private void uninstall() { // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId()); final boolean systemApp = Installer.hasSystemPermissions(this, this.getPackageManager()); if (systemApp) { AlertDialog.Builder builder = new AlertDialog.Builder(theme).setTitle(R.string.system_uninstall) .setMessage(R.string.system_uninstall_message) .setPositiveButton(R.string.system_uninstall_button, new DialogInterface.OnClickListener() { @Override/*from ww w . j av a 2s . c o m*/ public void onClick(DialogInterface dialogInterface, int i) { checkRootTask.execute(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED); InstallIntoSystemDialogActivity.this.finish(); } }); builder.create().show(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(theme) .setTitle(R.string.system_permission_denied_title) .setMessage(getString(R.string.system_permission_denied_body)) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { InstallIntoSystemDialogActivity.this.setResult(Activity.RESULT_CANCELED); InstallIntoSystemDialogActivity.this.finish(); } }); builder.create().show(); } }