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:ch.citux.td.ui.TDActivity.java

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

    setContentView(R.layout.main);//from  w ww .  j a v a2s .  c  o  m
    ButterKnife.inject(this);

    Context contextThemeWrapper = new ContextThemeWrapper(this, R.style.Theme_TD_Light);
    LayoutInflater inflater = LayoutInflater.from(this).cloneInContext(contextThemeWrapper);
    refreshView = inflater.inflate(R.layout.action_refresh, null);

    initNavigation();
    updateUser();

    if (favoritesFragment == null) {
        Bundle args = new Bundle();
        args.putBoolean(TDConfig.SETTINGS_CHANNEL_NAME, hasUsername);

        favoritesFragment = new FavoritesFragment();
        favoritesFragment.setArgs(args);

        getSupportFragmentManager().beginTransaction().add(R.id.content, favoritesFragment).commit();
    } else {
        replaceFragment(favoritesFragment);
    }
}

From source file:com.binomed.showtime.android.screen.fav.CineShowTimeFavFragment.java

/** Called when the activity is first created. */
@Override/*w ww .  j ava2s  .  c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Bug fix do to pb of theme. Was forced to set manually the theme.
    SharedPreferences pref = PreferenceManager
            .getDefaultSharedPreferences(fragmentInteraction.getMainContext());
    String defaultTheme = fragmentInteraction.getMainContext().getResources()
            .getString(R.string.preference_gen_default_theme);
    String theme = pref.getString(
            fragmentInteraction.getMainContext().getResources().getString(R.string.preference_gen_key_theme),
            defaultTheme);
    int themeRessource = R.style.Theme_Dark_Night;
    if (!theme.equals(defaultTheme)) {
        themeRessource = R.style.Theme_Shine_the_lite;
    }

    LayoutInflater newInflater = inflater
            .cloneInContext(new ContextThemeWrapper(fragmentInteraction.getMainContext(), themeRessource));
    View mainView = newInflater.inflate(R.layout.fragment_fav, container, false);

    tracker = fragmentInteraction.getTracker();
    mainContext = fragmentInteraction.getMainContext();

    initViews(mainView);
    initListeners();

    this.model = new ModelFavFragment();

    return mainView;
}

From source file:piuk.blockchain.android.ui.dialogs.RequestIdentifierDialog.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final FragmentActivity activity = getActivity();
    final LayoutInflater inflater = LayoutInflater.from(activity);

    final Builder dialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.Theme_Dialog));

    dialog.setTitle(R.string.wallet_identifier_title);

    final View view = inflater.inflate(R.layout.wallet_identifier_dialog, null);

    dialog.setView(view);//from   w  ww.  j  av  a2 s  .co  m

    final Button continueButton = (Button) view.findViewById(R.id.identifier_continue);

    continueButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            try {
                final TextView identifierField = (TextView) view.findViewById(R.id.identifier_field);

                final String guid = identifierField.getText().toString();

                validateGUIDorThrow(guid);

                callback.onSuccess(guid);

                dismiss();
            } catch (Exception e) {
                e.printStackTrace();

                dismiss();

                callback.onFail(e.getLocalizedMessage());
            }
        }
    });

    Dialog d = dialog.create();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();

    lp.dimAmount = 0;
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;

    d.show();

    d.getWindow().setAttributes(lp);

    d.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    return d;
}

From source file:piuk.blockchain.android.ui.dialogs.RequestForgotPasswordDialog.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final FragmentActivity activity = (FragmentActivity) getActivity();

    final WalletApplication application = (WalletApplication) activity.getApplication();

    final LayoutInflater inflater = LayoutInflater.from(activity);

    final Builder dialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.Theme_Dialog));

    dialog.setTitle(R.string.main_password_title);

    final View view = inflater.inflate(R.layout.forgot_password_dialog, null);

    dialog.setView(view);//from   w ww  . j  a v a2 s  .  c  om

    final TextView passwordField = (TextView) view.findViewById(R.id.password_field);

    final TextView titleTextView = (TextView) view.findViewById(R.id.title_text_view);

    titleTextView.setText(R.string.main_password_text);

    final Button continueButton = (Button) view.findViewById(R.id.password_continue);
    final Button cancelButton = (Button) view.findViewById(R.id.cancel);

    continueButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            try {
                if (passwordField.getText().toString().trim() == null
                        || passwordField.getText().toString().trim().length() < 1) {
                    callback.onFail();
                }

                String localWallet = application.readLocalWallet();
                if (!application.decryptLocalWallet(localWallet, passwordField.getText().toString().trim())) {
                    callback.onFail();
                    return;
                }

                String password = passwordField.getText().toString().trim();

                application.checkIfWalletHasUpdatedAndFetchTransactions(password, new SuccessCallback() {
                    @Override
                    public void onSuccess() {
                        dismiss();
                        callback.onSuccess();
                    }

                    @Override
                    public void onFail() {
                        dismiss();
                        callback.onFail();
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    cancelButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            dismiss();
        }
    });

    Dialog d = dialog.create();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();

    lp.dimAmount = 0;
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    //      lp.gravity = Gravity.BOTTOM;

    d.show();

    d.getWindow().setAttributes(lp);

    d.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    return d;
}

From source file:com.pspdfkit.cordova.PSPDFCordovaPlugin.java

@SuppressWarnings("ConstantConditions")
@NonNull/*from w w  w  .  j a v a 2  s  .c om*/
private PSPDFActivityConfiguration parseOptionsToConfiguration(@NonNull final JSONObject options)
        throws JSONException {
    final Activity activity = cordova.getActivity();
    int theme;

    try {
        ActivityInfo info = activity.getPackageManager()
                .getActivityInfo(new ComponentName(activity, PSPDFActivity.class), 0);
        theme = info.theme;
    } catch (PackageManager.NameNotFoundException e) {
        theme = R.style.Theme_AppCompat_NoActionBar;
    }

    final ContextThemeWrapper themedContext = new ContextThemeWrapper(activity, theme);
    final PSPDFActivityConfiguration.Builder builder = new PSPDFActivityConfiguration.Builder(themedContext,
            licenseKey);
    final Iterator<String> optionIterator = options.keys();

    while (optionIterator.hasNext()) {
        final String option = optionIterator.next();
        final Object value = options.get(option);

        try {
            if ("backgroundColor".equals(option)) {
                builder.backgroundColor(Color.parseColor((String) value));
            } else if ("disableOutline".equals(option) && ((Boolean) value)) {
                builder.disableOutline();
            } else if ("disableSearch".equals(option) && ((Boolean) value)) {
                builder.disableSearch();
            } else if ("hidePageLabels".equals(option) && ((Boolean) value)) {
                builder.hidePageLabels();
            } else if ("hidePageNumberOverlay".equals(option) && ((Boolean) value)) {
                builder.hidePageNumberOverlay();
            } else if ("hideThumbnailBar".equals(option) && ((Boolean) value)) {
                builder.hideThumbnailBar();
            } else if ("hideThumbnailGrid".equals(option) && ((Boolean) value)) {
                builder.hideThumbnailGrid();
            } else if ("diskCacheSize".equals(option)) {
                builder.diskCacheSize((Integer) value);
            } else if ("memoryCacheSize".equals(option)) {
                builder.memoryCacheSize((Integer) value);
            } else if ("pageFitMode".equals(option)) {
                builder.fitMode(PageFitMode.valueOf((String) value));
            } else if ("scrollDirection".equals(option)) {
                builder.scrollDirection(PageScrollDirection.valueOf((String) value));
            } else if ("scrollMode".equals(option)) {
                builder.scrollMode(PageScrollMode.valueOf((String) value));
            } else if ("invertColors".equals(option)) {
                builder.invertColors((Boolean) value);
            } else if ("toGrayscale".equals(option)) {
                builder.toGrayscale((Boolean) value);
            } else if ("loggingEnabled".equals(option)) {
                builder.loggingEnabled((Boolean) value);
            } else if ("title".equals(option)) {
                builder.title(fromJsonString(options.getString("title")));
            } else if ("startZoomScale".equals(option)) {
                builder.startZoomScale((float) options.getDouble("startZoomScale"));
            } else if ("maxZoomScale".equals(option)) {
                builder.maxZoomScale((float) options.getDouble("maxZoomScale"));
            } else if ("zoomOutBounce".equals(option)) {
                builder.zoomOutBounce(options.getBoolean("zoomOutBounce"));
            } else if ("page".equals(option)) {
                builder.page(options.getInt("page"));
            } else if ("useImmersiveMode".equals(option)) {
                builder.useImmersiveMode(options.getBoolean("useImmersiveMode"));
            } else if ("searchType".equals(option)) {
                final String searchType = options.getString("searchType");
                if ("SEARCH_INLINE".equals(searchType))
                    builder.setSearchType(PSPDFActivityConfiguration.SEARCH_INLINE);
                else if ("SEARCH_MODULAR".equals(searchType))
                    builder.setSearchType(PSPDFActivityConfiguration.SEARCH_MODULAR);
                else
                    throw new IllegalArgumentException(String.format("Invalid search type: %s", value));
            } else if ("autosaveEnabled".equals(option)) {
                builder.autosaveEnabled(options.getBoolean("autosaveEnabled"));
            } else if ("annotationEditing".equals(option)) {
                final AnnotationEditingConfiguration.Builder annotationBuilder = new AnnotationEditingConfiguration.Builder(
                        themedContext);
                final JSONObject annotationEditing = options.getJSONObject("annotationEditing");
                final Iterator<String> annotationOptionIterator = annotationEditing.keys();

                while (annotationOptionIterator.hasNext()) {
                    final String annotationEditingOption = annotationOptionIterator.next();
                    final Object annotationEditingValue = annotationEditing.get(annotationEditingOption);

                    if ("enabled".equals(annotationEditingOption)) {
                        if ((Boolean) annotationEditingValue)
                            annotationBuilder.enableAnnotationEditing();
                        else
                            annotationBuilder.disableAnnotationEditing();
                    } else if ("creatorName".equals(annotationEditingOption)) {
                        annotationBuilder.defaultAnnotationCreator(
                                fromJsonString(annotationEditing.getString("creatorName")));
                    } else {
                        throw new IllegalArgumentException(String
                                .format("Invalid annotation editing option '%s'", annotationEditingOption));
                    }
                }

                builder.annotationEditingConfiguration(annotationBuilder.build());
            } else {
                throw new IllegalArgumentException(String.format("Invalid plugin option '%s'", option));
            }
        } catch (Exception ex) {
            throw new PSPDFCordovaPluginException(String.format("Error while parsing option '%s'", option), ex);
        }
    }

    return builder.build();
}

From source file:air.com.snagfilms.utils.Utils.java

public static AlertDialog showConfirmationDialog(String title, Context mContext) {

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            new ContextThemeWrapper(mContext, R.style.AlertDialogCustom));
    if (title != null) {
        alertDialogBuilder.setMessage(title);
    } else {//from  w w  w .  java  2 s.  c om
        alertDialogBuilder.setMessage("INFO:");
    }

    alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    return alertDialogBuilder.create();

}

From source file:it.mb.whatshare.PatchedDialogFragment.java

/**
 * Returns a builder that will create a dialog that is hidden when clicking
 * ok or outside of it.//from ww w  .j a v  a 2s .c o  m
 * 
 * <p>
 * The builder has already the correct theme set (for making it look ok even
 * on wonderful Android pre-v11), so {@link Builder#getContext()} can be
 * used to inflate layouts with.
 * 
 * @param activity
 *            the caller activity
 * @return a builder to be used to create a dialog with
 */
protected Builder getBuilder(final FragmentActivity activity) {
    context = new ContextThemeWrapper(activity, R.style.DialogTheme);
    // @formatter:off
    return new AlertDialog.Builder(context).setPositiveButton(android.R.string.ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            //  just hide dialog
        }
    });
    // @formatter:on
}

From source file:ca.hoogit.soundchooser.SoundChooserDialog.java

@NonNull
@Override//from www. java2s.co  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    View view;
    ContextThemeWrapper context;
    if (mThemeId != 0) {
        context = new ContextThemeWrapper(getActivity(), mThemeId);
        view = View.inflate(context, R.layout.sound_picker_dialog, null);
    } else {
        context = new ContextThemeWrapper(getActivity(), R.style.AlertDialog_AppCompat_Light);
        view = LayoutInflater.from(getActivity()).inflate(R.layout.sound_picker_dialog, null);
    }

    mPalette = (SoundChooserPalette) view.findViewById(R.id.sound_picker);
    mPalette.init(mCircleColor, mSize, mColumns, this);

    mSoundPlayer = new SoundPlayer(activity, mStreamType);

    if (mSounds != null) {
        showPaletteView();
    }

    mAlertDialog = new AlertDialog.Builder(context).setTitle(mTitle).setView(view)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mListener.onPositive(dialog, mLastSound);
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mListener.onNegative(dialog);
                }
            }).create();

    return mAlertDialog;
}

From source file:pct.droid.fragments.dialog.EpisodeDialogFragment.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override//  w  ww  .j a v  a2s .  co m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = LayoutInflater.from(new ContextThemeWrapper(getActivity(), R.style.Theme_PopcornTime))
            .inflate(R.layout.fragment_dialog_episode, container, false);
    ButterKnife.bind(this, v);

    if (!VersionUtils.isJellyBean()) {
        mPlayButton.setBackgroundDrawable(PixelUtils.changeDrawableColor(mPlayButton.getContext(),
                R.drawable.play_button_circle, mShow.color));
    } else {
        mPlayButton.setBackground(PixelUtils.changeDrawableColor(mPlayButton.getContext(),
                R.drawable.play_button_circle, mShow.color));
    }

    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mPlaceholder.getLayoutParams();
    layoutParams.height = PixelUtils.getScreenHeight(mActivity);
    mPlaceholder.setLayoutParams(layoutParams);

    return v;
}

From source file:com.ayuget.redface.ui.fragment.PrivateMessageListFragment.java

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

    pmAdapter = new PrivateMessagesAdapter(
            new ContextThemeWrapper(getActivity(), themeManager.getActiveThemeStyle()), themeManager,
            settings.isCompactModeEnabled());
    pmAdapter.setOnPMClickedListener(this);
    pmAdapter.setOnPMLongClickListener(this);
}