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:org.ciasaboark.tacere.activity.fragment.AdvancedSettingsFragment.java

private void drawEventBufferWidgets() {
    LinearLayout bufferBox = (LinearLayout) rootView.findViewById(R.id.advanced_settings_buffer_box);
    bufferBox.setOnClickListener(new View.OnClickListener() {
        @Override/*from w w w.  j av  a  2s  . c om*/
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(context, R.style.Dialog));
            builder.setTitle("Buffer Minutes");
            final NumberPicker number = new NumberPicker(context);
            String[] nums = new String[32];

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

            number.setMinValue(1);
            number.setMaxValue(nums.length - 1);
            number.setWrapSelectorWheel(false);
            number.setDisplayedValues(nums);
            number.setValue(prefs.getBufferMinutes() + 1);

            builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefs.setBufferMinutes(number.getValue() - 1);
                    drawEventBufferWidgets();
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing
                }
            });

            builder.setView(number);

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

    // the event buffer button
    TextView bufferTV = (TextView) rootView.findViewById(R.id.bufferMinutesDescription);
    String bufferText = getResources().getString(R.string.advanced_settings_section_intervals_buffer_duration);
    bufferTV.setText(String.format(bufferText, prefs.getBufferMinutes()));
}

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

private void resetEvent() {
    boolean eventRepeats = databaseInterface.doesEventRepeat(event.getEventId());
    boolean eventSeriesRingerSet = prefs.getRingerForEventSeries(event.getEventId()) != RingerType.UNDEFINED;
    if (eventRepeats && eventSeriesRingerSet) {
        if (event.getRingerType() == RingerType.UNDEFINED) {
            //this event does not have an instance ringer set, the reset button should prompt that
            //resetting will reset the entire event series
            String message = getResources().getString(R.string.event_dialog_reset_event_series);
            //if this events calendar has a custom ringer then notify the user that this is what
            //we will drop back to, otherwize use the default ringer
            if (prefs.getRingerForCalendar(event.getCalendarId()) != RingerType.UNDEFINED) {
                message = String.format(message, new String[] { "calendar" });
            } else {
                message = String.format(message, new String[] { "default" });
            }//  ww  w  .j  av a  2 s  . co m

            Drawable icon = getResources().getDrawable(R.drawable.history);
            icon.mutate().setColorFilter(getResources().getColor(R.color.dialog_icon_tint),
                    PorterDuff.Mode.MULTIPLY);
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(getActivity(), R.style.Dialog))
                            .setTitle(R.string.event_dialog_repeating_event_conformation_title)
                            .setMessage(message).setPositiveButton(R.string.event_dialog_reset_event_series_ok,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            resetAllEvents();
                                        }
                                    })
                            .setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    //nothing to do here
                                }
                            }).setIcon(icon);
            AlertDialog dialog = builder.show();

        } else {
            //this event has instance and event series ringers set, prompt for which to reset
            long eventRepetions = databaseInterface.getEventRepetitionCount(event.getEventId());
            String message = getResources().getString(R.string.event_dialog_reset_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(message, event.getTitle(), eventRepetions))
                            .setPositiveButton(R.string.event_dialog_save_all_instances,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            resetAllEvents();
                                        }
                                    })
                            .setNegativeButton(R.string.event_dialog_save_instance,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            resetEventInstance();
                                        }
                                    })
                            .setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    //nothing to do here
                                }
                            }).setIcon(icon);
            AlertDialog dialog = builder.show();
        }

    } else {
        resetEventInstance();
    }
}

From source file:io.flutter.plugins.localauth.AuthenticationHelper.java

@SuppressLint("InflateParams")
private void showFingerprintDialog() {
    View view = LayoutInflater.from(activity).inflate(R.layout.scan_fp, null, false);
    TextView fpDescription = (TextView) view.findViewById(R.id.fingerprint_description);
    TextView title = (TextView) view.findViewById(R.id.fingerprint_signin);
    TextView status = (TextView) view.findViewById(R.id.fingerprint_status);
    fpDescription.setText((String) call.argument("localizedReason"));
    title.setText((String) call.argument("signInTitle"));
    status.setText((String) call.argument("fingerprintHint"));
    Context context = new ContextThemeWrapper(activity, R.style.AlertDialogCustom);
    OnClickListener cancelHandler = new OnClickListener() {
        @Override//from   www .jav  a2  s . c  o  m
        public void onClick(DialogInterface dialog, int which) {
            stop(false);
        }
    };
    fingerprintDialog = new AlertDialog.Builder(context).setView(view)
            .setNegativeButton((String) call.argument(CANCEL_BUTTON), cancelHandler).setCancelable(false)
            .show();
}

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

public void askBeforeInstall() {
    // 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 alertBuilder = new AlertDialog.Builder(theme);
    alertBuilder.setTitle(R.string.system_install_question);
    String message = InstallExtension.create(getApplicationContext()).getWarningString();
    alertBuilder.setMessage(Html.fromHtml(message));
    alertBuilder.setPositiveButton(R.string.system_install_button_install,
            new DialogInterface.OnClickListener() {
                @Override//from  w  w w .j a v a 2 s.  c  om
                public void onClick(DialogInterface dialog, int which) {
                    checkRootTask.execute();
                }
            });
    alertBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
            InstallExtensionDialogActivity.this.finish();
        }
    });
    alertBuilder.create().show();
}

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

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

    // not support on Android >= 5.1
    if (android.os.Build.VERSION.SDK_INT >= 22) {
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme);
        alertBuilder.setMessage(R.string.system_install_not_supported);
        alertBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            @Override/*from w ww  .ja  va 2  s  .com*/
            public void onClick(DialogInterface dialog, int which) {
                InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
                InstallExtensionDialogActivity.this.finish();
            }
        });
        alertBuilder.create().show();
        return;
    }

    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme);
    alertBuilder.setTitle(R.string.system_install_question);
    String message = InstallExtension.create(getApplicationContext()).getWarningString();
    alertBuilder.setMessage(Html.fromHtml(message));
    alertBuilder.setPositiveButton(R.string.system_install_button_install,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    checkRootTask.execute();
                }
            });
    alertBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
            InstallExtensionDialogActivity.this.finish();
        }
    });
    alertBuilder.create().show();
}

From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//  w ww. j  a  v  a  2s  . c o m
public void onCreate(Bundle savedInstanceState) {
    currentPreferences = Preferences.getCurrent();
    if (C.API_LOLLIPOP) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        requestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
    }
    ResourceUtils.applyPreferredTheme(this);
    expandedScreen = new ExpandedScreen(this, Preferences.isExpandedScreen());
    super.onCreate(savedInstanceState);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    float density = ResourceUtils.obtainDensity(this);
    setContentView(R.layout.activity_main);
    ClickableToast.register(clickableToastHolder);
    FavoritesStorage.getInstance().getObservable().register(this);
    watcherServiceClient.bind(this);
    pageManager = new PageManager();
    actionIconSet = new ActionIconSet(this);
    progressView = findViewById(R.id.progress);
    errorView = findViewById(R.id.error);
    errorText = (TextView) findViewById(R.id.error_text);
    listView = (PullableListView) findViewById(android.R.id.list);
    registerForContextMenu(listView);
    drawerCommon = (ViewGroup) findViewById(R.id.drawer_common);
    drawerWide = (ViewGroup) findViewById(R.id.drawer_wide);
    TypedArray typedArray = obtainStyledAttributes(new int[] { R.attr.styleDrawerSpecial });
    int drawerResId = typedArray.getResourceId(0, 0);
    typedArray.recycle();
    ContextThemeWrapper styledContext = drawerResId != 0 ? new ContextThemeWrapper(this, drawerResId) : this;
    int drawerBackground = ResourceUtils.getColor(styledContext, R.attr.backgroundDrawer);
    drawerCommon.setBackgroundColor(drawerBackground);
    drawerWide.setBackgroundColor(drawerBackground);
    drawerListView = new SortableListView(styledContext, this);
    drawerListView.setId(android.R.id.tabcontent);
    drawerListView.setOnSortingStateChangedListener(this);
    drawerForm = new DrawerForm(styledContext, this, this, watcherServiceClient);
    drawerForm.bind(drawerListView);
    drawerParent = new FrameLayout(this);
    drawerParent.addView(drawerListView);
    drawerCommon.addView(drawerParent);
    uiManager = new UiManager(this, this, expandedScreen);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (C.API_LOLLIPOP) {
        FrameLayout foreground = new FrameLayout(this);
        drawerLayout.addView(foreground, drawerLayout.indexOfChild(drawerCommon), new DrawerLayout.LayoutParams(
                DrawerLayout.LayoutParams.MATCH_PARENT, DrawerLayout.LayoutParams.MATCH_PARENT));
        getLayoutInflater().inflate(R.layout.widget_toolbar, foreground);
        Toolbar toolbar = (Toolbar) foreground.findViewById(R.id.toolbar);
        setActionBar(toolbar);
        toolbarView = toolbar;
        expandedScreen.setToolbar(toolbar, foreground);
    } else {
        getActionBar().setIcon(R.drawable.ic_logo); // Show white logo on search
    }
    drawerToggle = new DrawerToggle(this, drawerLayout);
    if (C.API_LOLLIPOP) {
        drawerCommon.setElevation(6f * density);
        drawerWide.setElevation(4f * density);
    } else {
        drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
    }
    drawerLayout.addDrawerListener(drawerToggle);
    drawerLayout.addDrawerListener(drawerForm);
    if (toolbarView == null) {
        drawerLayout.addDrawerListener(new ExpandedScreenDrawerLocker());
    }
    ViewUtils.applyToolbarStyle(this, toolbarView);
    if (Preferences.isActiveScrollbar()) {
        listView.setFastScrollEnabled(true);
        if (!C.API_LOLLIPOP) {
            ListViewUtils.colorizeListThumb4(listView);
        }
    }
    listView.setOnItemClickListener(this);
    listView.setOnItemLongClickListener(this);
    listView.getWrapper().setOnPullListener(this);
    listView.getWrapper().setPullStateListener(this);
    listView.setClipToPadding(false);
    ScrollListenerComposite scrollListenerComposite = new ScrollListenerComposite();
    listView.setOnScrollListener(scrollListenerComposite);
    scrollListenerComposite.add(new BusyScrollListener(this));
    updateWideConfiguration(true);
    expandedScreen.setDrawerOverToolbarEnabled(!wideMode);
    expandedScreen.setContentListView(listView, scrollListenerComposite);
    expandedScreen.setDrawerListView(drawerParent, drawerListView, drawerForm.getHeaderView());
    expandedScreen.addAdditionalView(progressView, true);
    expandedScreen.addAdditionalView(errorView, true);
    expandedScreen.finishInitialization();
    LocalBroadcastManager.getInstance(this).registerReceiver(newPostReceiver,
            new IntentFilter(C.ACTION_POST_SENT));
    if (savedInstanceState == null) {
        savedInstanceState = pageManager.readFromStorage();
    }
    PageHolder savedCurrentPageHolder = pageManager.restore(savedInstanceState);
    if (savedCurrentPageHolder != null) {
        navigatePageHolder(savedCurrentPageHolder, false);
    } else {
        navigateIntent(getIntent(), false);
    }
    if (savedInstanceState == null) {
        startUpdateTask();
        int drawerInitialPosition = Preferences.getDrawerInitialPosition();
        if (drawerInitialPosition != Preferences.DRAWER_INITIAL_POSITION_CLOSED) {
            if (!wideMode) {
                drawerLayout.post(() -> drawerLayout.openDrawer(Gravity.START));
            }
            if (drawerInitialPosition == Preferences.DRAWER_INITIAL_POSITION_FORUMS) {
                drawerForm.setChanSelectMode(true);
            }
        }
    }
}

From source file:rikka.materialpreference.PreferenceFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;
    if (theme <= 0) {
        throw new IllegalStateException("Must specify preferenceTheme in theme");
    }/*from  w w w.  j a va2s  . c om*/
    mStyledContext = new ContextThemeWrapper(getActivity(), theme);

    mPreferenceManager = new PreferenceManager(mStyledContext, this);
    mPreferenceManager.setOnNavigateToScreenListener(this);
    final Bundle args = getArguments();
    final String rootKey;
    if (args != null) {
        rootKey = getArguments().getString(ARG_PREFERENCE_ROOT);
    } else {
        rootKey = null;
    }
    onCreatePreferences(savedInstanceState, rootKey);
}

From source file:android.support.v7.preference.PreferenceController.java

@Override
@NonNull/*from w  ww.j a  va 2s.  c  om*/
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    mInitDone = false;
    mHavePrefs = false;

    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;
    if (theme == 0) {
        throw new IllegalStateException("Must specify preferenceTheme in theme");
    }
    mStyledContext = new ContextThemeWrapper(getActivity(), theme);

    mPreferenceManager = new PreferenceManager(mStyledContext);
    final String rootKey = getArgs().getString(ARG_PREFERENCE_ROOT);
    onCreatePreferences(savedInstanceState, rootKey);

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat,
            R.attr.preferenceFragmentCompatStyle, 0);

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId);

    mDividerDecoration = new DividerDecoration();
    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider);
    final int dividerHeight = a
            .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1);
    final boolean allowDividerAfterLastItem = a
            .getBoolean(R.styleable.PreferenceFragmentCompat_allowDividerAfterLastItem, true);

    a.recycle();

    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);
    }
    mDividerDecoration.setAllowDividerAfterLastItem(allowDividerAfterLastItem);

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);

    onViewCreated(view, savedInstanceState);

    return view;
}

From source file:android.support.v7.preference.PreferenceFragmentCompat.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;
    if (theme <= 0) {
        throw new IllegalStateException("Must specify preferenceTheme in theme");
    }//from   w  ww.ja  va2  s .  c o  m
    mStyledContext = new ContextThemeWrapper(getActivity(), theme);

    mPreferenceManager = new PreferenceManager(mStyledContext);
    mPreferenceManager.setOnNavigateToScreenListener(this);
    final Bundle args = getArguments();
    final String rootKey;
    if (args != null) {
        rootKey = getArguments().getString(ARG_PREFERENCE_ROOT);
    } else {
        rootKey = null;
    }
    onCreatePreferences(savedInstanceState, rootKey);
}

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

private void showExportYesNoDialog() {
    // TODO query _before_ asking!?
    // Get dialog builder & configure the dialog...
    new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme))
            //   Set title:
            .setTitle(R.string.preBackupExportTitle)
            //   Set message:
            .setMessage(R.string.preBackupExportMsg)
            // Set "Yes button:
            .setPositiveButton(R.string.preBackupExportYes, new DialogInterface.OnClickListener() {
                @Override//w  ww.  j av a  2  s  . co m
                public void onClick(DialogInterface dialog, int which) {
                    // Query to see if there are any records to export:
                    new RecordsTasks.QueryTask(activity, Backup.this).execute(new RecordsQuery(
                            Source.With(CollectorClient.SCHEMA_FLAGS_COLLECTOR_DATA), Order.UNDEFINED));
                    // TODO order by form, deviceid, timestamp
                    // TODO let Backup & ExportFragment share this code somehow
                }
            })
            // Set "No" button:
            .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) { // go straight to back-up:
                    doBackup();
                }
            })
            // Create & show the dialog:
            .create().show();
}