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.bt.heliniumstudentapp.DayActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() != R.id.i_hwfloating_md)
        return super.onOptionsItemSelected(item);

    final ScheduleFragment.week.day day_data = schedule.day_get(schedule.day_get_index(lastPosition) + 2);

    if (day_data.floatings_get() == 0) {
        Toast.makeText(this, getString(R.string.homework_floating_no), Toast.LENGTH_SHORT).show();
        return true;
    }/*from ww w .  j  a v  a 2 s  . c  om*/

    final AlertDialog.Builder hwf_dialog_builder = new AlertDialog.Builder(
            new ContextThemeWrapper(this, MainActivity.themeDialog));
    AlertDialog hwf_dialog;
    StringBuilder s;
    int i;

    hwf_dialog_builder.setTitle(getString(R.string.homework_floating));

    hwf_dialog_builder.setPositiveButton(android.R.string.ok, null);

    s = new StringBuilder();
    for (i = 0; i < day_data.floatings_get(); i++) {
        s.append(day_data.floating_get(i).course);
        s.append("\n");
        s.append(Html.fromHtml(day_data.floating_get(i).text));
    }

    hwf_dialog_builder.setMessage(s.toString());

    hwf_dialog = hwf_dialog_builder.create();

    hwf_dialog.setCanceledOnTouchOutside(true);
    hwf_dialog.show();

    hwf_dialog.getButton(AlertDialog.BUTTON_POSITIVE)
            .setTextColor(ContextCompat.getColor(this, MainActivity.accentSecondaryColor));

    return true;
}

From source file:com.wanderingcan.floatingactionmenu.FloatingActionMenu.java

private void createLabels() {
    Context context = new ContextThemeWrapper(getContext(), mLabelsStyle);

    for (int i = 0; i < mButtonsCount; i++) {
        FloatingActionButton button = (FloatingActionButton) getChildAt(i);
        String title = button.getLabelText();

        if (button == mMenuButton || title == null || button.getTag(R.id.fab_label) != null)
            continue;

        LabelView label = new LabelView(context);
        if (mLabelsType == LABELS_CARD) {
            label.setLabelType(LabelView.Type.CARD);
        } else {//w w  w. ja va 2  s .  c om
            label.setLabelType(LabelView.Type.TEXT);
        }

        int style;
        if (mLabelsStyle != 0) {
            style = mLabelsStyle;
        } else {
            style = R.style.menu_labels_style_blank;
        }

        label.setTextAppearance(getContext(), style);

        Animation showAnimation = AnimationUtils.loadAnimation(getContext(), mMenuShowAnimation);
        if (mMenuHideAnimation == R.anim.fab_in) {
            showAnimation.setInterpolator(new FastOutSlowInInterpolator());
        }

        Animation hideAnimation = AnimationUtils.loadAnimation(getContext(), mMenuHideAnimation);
        if (mMenuHideAnimation == R.anim.fab_out) {
            hideAnimation.setInterpolator(new FastOutSlowInInterpolator());
        }

        label.setShowAnimation(showAnimation, mAnimationDuration);
        label.setHideAnimation(hideAnimation, mAnimationDuration);

        label.setText(button.getLabelText());
        addView(label);

        button.setLabelView(label);
    }
}

From source file:com.tandong.sa.sherlock.internal.app.ActionBarImpl.java

public Context getThemedContext() {
    if (mThemedContext == null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = mContext.getTheme();
        currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        final int targetThemeRes = outValue.resourceId;

        if (targetThemeRes != 0) { // XXX && mContext.getThemeResId() !=
            // targetThemeRes) {
            mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
        } else {// w w w  .java  2s  . c o m
            mThemedContext = mContext;
        }
    }
    return mThemedContext;
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static Context getActionBarContext(final Context context) {
    final TypedArray a = context.obtainStyledAttributes(new int[] { R.attr.actionBarTheme,
            R.attr.actionBarWidgetTheme, android.R.attr.actionBarTheme, android.R.attr.actionBarWidgetTheme });
    final int resId;
    if (a.hasValue(0) || a.hasValue(1)) {
        resId = a.hasValue(0) ? a.getResourceId(0, 0) : a.getResourceId(1, 0);
    } else {//from w w  w. jav  a  2 s  .c o m
        resId = a.hasValue(2) ? a.getResourceId(2, 0) : a.getResourceId(3, 0);
    }
    a.recycle();
    if (resId == 0)
        return context;
    return new ContextThemeWrapper(context, resId);
}

From source file:com.actionbarsherlock.internal.app.ActionBarImpl.java

public Context getThemedContext() {
    if (mThemedContext == null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = mContext.getTheme();
        currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        final int targetThemeRes = outValue.resourceId;

        if (targetThemeRes != 0) { //XXX && mContext.getThemeResId() != targetThemeRes) {
            mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
        } else {//  w  w w  . ja va2  s.c  om
            mThemedContext = mContext;
        }
    }
    return mThemedContext;
}

From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java

private void updateButtonSharing() {
    final View btnSharing = menu.findViewById(R.id.BtnSharing);
    btnSharing.setOnClickListener(new OnClickListener() {
        @Override//w ww .j av  a  2  s . com
        public void onClick(final View view) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(context, android.R.style.Theme_DeviceDefault_Dialog));
            final String[] popup = new String[] { context.getString(R.string.TxtSendTo),
                    context.getString(R.string.TxtSendItemTextTo),
                    context.getString(R.string.TxtSendItemContentTo),
                    context.getString(R.string.TxtCopyToClipboard) };
            builder.setItems(popup, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialogInterface, final int id) {
                    switch (id) {
                    case 0:
                        DataUtils.sendTo(context, item);
                        break;
                    case 1:
                        DataUtils.sendContentTo(context, item);
                        break;
                    case 2:
                        DataUtils.sendHtmlContentTo(context, item);
                        break;
                    case 3:
                        DataUtils.copyToClipboard(context, item);
                    default:
                    }
                }
            });
            builder.show();
        }
    });
}

From source file:org.chromium.chrome.browser.tab.Tab.java

/**
 * Creates an instance of a {@link Tab}.
 *
 * This constructor can be called before the native library has been loaded, so any additions
 * must be vetted for library calls.//from   w  w w. j  a v a 2  s . c o  m
 *
 * @param id          The id this tab should be identified with.
 * @param parentId    The id id of the tab that caused this tab to be opened.
 * @param incognito   Whether or not this tab is incognito.
 * @param context     An instance of a {@link Context}.
 * @param window      An instance of a {@link WindowAndroid}.
 * @param creationState State in which the tab is created, needed to initialize TabUma
 *                      accounting. When null, TabUma will not be initialized.
 * @param frozenState State containing information about this Tab, if it was persisted.
 */
@SuppressLint("HandlerLeak")
public Tab(int id, int parentId, boolean incognito, Context context, WindowAndroid window, TabLaunchType type,
        TabCreationState creationState, TabState frozenState) {
    mId = TabIdManager.getInstance().generateValidId(id);
    mParentId = parentId;
    mIncognito = incognito;
    mThemedApplicationContext = context != null
            ? new ContextThemeWrapper(context.getApplicationContext(), ChromeActivity.getThemeId())
            : null;
    mWindowAndroid = window;
    mLaunchType = type;
    if (mThemedApplicationContext != null) {
        Resources resources = mThemedApplicationContext.getResources();
        mIdealFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_size);
        mDefaultThemeColor = mIncognito
                ? ApiCompatibilityUtils.getColor(resources, R.color.incognito_primary_color)
                : ApiCompatibilityUtils.getColor(resources, R.color.default_primary_color);
        mThemeColor = calculateThemeColor(false);
    } else {
        mIdealFaviconSize = 16;
        mDefaultThemeColor = 0;
        mThemeColor = mDefaultThemeColor;
    }

    // Restore data from the TabState, if it existed.
    if (frozenState != null) {
        assert type == TabLaunchType.FROM_RESTORE;
        restoreFieldsFromState(frozenState);
    }

    setContentViewClient(new TabContentViewClient());

    mTabRedirectHandler = new TabRedirectHandler(mThemedApplicationContext);
    addObserver(mTabObserver);

    if (incognito) {
        CipherFactory.getInstance().triggerKeyGeneration();
    }

    ContextualSearchTabHelper.createForTab(this);
    MediaSessionTabHelper.createForTab(this);

    if (creationState != null) {
        mTabUma = new TabUma(creationState);
        if (frozenState == null) {
            assert creationState != TabCreationState.FROZEN_ON_RESTORE;
        } else {
            assert type == TabLaunchType.FROM_RESTORE && creationState == TabCreationState.FROZEN_ON_RESTORE;
        }
    }
}

From source file:com.serenegiant.aceparrot.BaseFragment.java

protected LayoutInflater getThemedLayoutInflater(final LayoutInflater inflater) {
    final Activity context = getActivity();
    final SharedPreferences pref = context.getPreferences(0);
    final int layout_style = getLayoutStyle(pref.getInt(AppConst.KEY_ICON_TYPE, 0));
    // create ContextThemeWrapper from the original Activity Context with the custom theme
    final Context contextThemeWrapper = new ContextThemeWrapper(context, layout_style);
    // clone the inflater using the ContextThemeWrapper
    return inflater.cloneInContext(contextThemeWrapper);
}

From source file:com.andrewshu.android.reddit.submit.SubmitLinkActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = null;/*from   ww w  . j av  a 2  s. c om*/
    ProgressDialog pdialog;
    switch (id) {
    case Constants.DIALOG_LOGIN:
        dialog = new LoginDialog(this, mSettings, true) {
            @Override
            public void onLoginChosen(String user, String password) {
                removeDialog(Constants.DIALOG_LOGIN);
                new MyLoginTask(user, password).execute();
            }
        };
        break;

    // "Please wait"
    case Constants.DIALOG_LOGGING_IN:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Logging in...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_SUBMITTING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Submitting...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    default:
        break;
    }
    return dialog;
}

From source file:tm.alashow.datmusic.ui.activity.MainActivity.java

public void playAudio(final Audio audio) {
    final LinearLayout rootView = new LinearLayout(this);
    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this,
            R.style.Base_Theme_AppCompat_Light_Dialog);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(contextThemeWrapper);
    alertDialogBuilder.setView(rootView);
    alertDialogBuilder.setNegativeButton(R.string.audio_player_close, null);

    final AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.setCanceledOnTouchOutside(false);

    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override/*from  w w w  .  j a  v  a  2s .co  m*/
        public void onShow(DialogInterface dialog) {
            //change flat button color
            alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE)
                    .setTextColor(getResources().getColor(R.color.primary));
        }
    });
    //destroy mediaPlayer when dialog dismissed
    alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            resetPlayer();
        }
    });

    new PrepareAudioTask(rootView, new OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mediaPlayer, AudioWife audioWife) {
            mMediaPlayer = mediaPlayer;
            alertDialog.show();
            TextView nameView = (TextView) rootView.findViewById(R.id.name);
            if (nameView != null) {
                nameView.setText(audio.getArtist() + " - " + audio.getTitle());
            }
            audioWife.play();
        }

        @Override
        public void onError(Exception e) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    U.showCenteredToast(MainActivity.this, R.string.exception);
                }
            });
        }
    }).execute(Uri.parse(audio.getStreamUrl()));
}