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.solovyev.android.games.game2048.PreferenceListFragment.java

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

    if (themeResId == NO_THEME) {
        themeContext = getActivity();//  w  w w .java 2s .c  om
        themeInflater = inflater;
    } else {
        themeContext = new ContextThemeWrapper(getActivity(), themeResId);
        themeInflater = LayoutInflater.from(themeContext);
    }

    if (layoutResId == NO_LAYOUT) {
        final FrameLayout frameLayout = new FrameLayout(themeContext);
        final ListView listView = new ListView(themeContext);
        listView.setId(android.R.id.list);
        frameLayout.addView(listView, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
        root = frameLayout;
    } else {
        root = themeInflater.inflate(layoutResId, null);
    }

    final ListView lv = (ListView) root.findViewById(android.R.id.list);
    prepareListView(lv);

    onCreateView(themeContext, themeInflater, root, container, savedInstanceState);

    return root;
}

From source file:com.mishiranu.dashchan.content.service.AudioPlayerService.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/*from  ww  w.  j a  v a2 s . c  o  m*/
public void onCreate() {
    super.onCreate();
    audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    int notificationColor = 0;
    if (C.API_LOLLIPOP) {
        Context themedContext = new ContextThemeWrapper(this, Preferences.getThemeResource());
        notificationColor = ResourceUtils.getColor(themedContext, android.R.attr.colorAccent);
    }
    this.notificationColor = notificationColor;
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AudioPlayerWakeLock");
    wakeLock.setReferenceCounted(false);
    context = new ContextThemeWrapper(this, R.style.Theme_Special_Notification);
}

From source file:de.mrapp.android.dialog.builder.AbstractMaterialDialogBuilder.java

/**
 * Initializes the builder./* w  ww .j  av a 2s.com*/
 *
 * @param themeResourceId
 *         The resource id of the theme, which should be used by the dialog, as an {@link
 *         Integer} value or 0, if the default theme should be used
 */
private void initialize(@StyleRes final int themeResourceId) {
    int themeId = themeResourceId;

    if (themeId == 0) {
        TypedValue typedValue = new TypedValue();
        getContext().getTheme().resolveAttribute(R.attr.materialDialogTheme, typedValue, true);
        themeId = typedValue.resourceId;
        themeId = themeId != 0 ? themeId : R.style.MaterialDialog_Light;
    }

    setContext(new ContextThemeWrapper(getContext(), themeId));
    this.themeResourceId = themeId;
    obtainStyledAttributes(themeId);
}

From source file:com.google.samples.apps.topeka.fragment.QuizFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    // Create a themed Context and custom LayoutInflater
    // to get nicely themed views in this Fragment.
    final Theme theme = mCategory.getTheme();
    final ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), theme.getStyleId());
    final LayoutInflater themedInflater = LayoutInflater.from(context);
    return themedInflater.inflate(R.layout.fragment_quiz, container, false);
}

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

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final FragmentActivity activity = getActivity();
    final LayoutInflater inflater = LayoutInflater.from(activity);
    final WalletApplication application = (WalletApplication) activity.getApplication();
    final MyRemoteWallet wallet = application.getRemoteWallet();

    if (wallet == null)
        return null;

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

    String existingNote = wallet.getTxNotes().get(tx);

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

    dialog.setView(view);/* w w w. ja  v a 2  s.  co m*/

    final EditText noteView = (EditText) view.findViewById(R.id.edit_note_field);
    final Button saveButton = (Button) view.findViewById(R.id.save_note_button);

    if (existingNote != null) {
        noteView.setText(existingNote);

        dialog.setTitle(R.string.edit_note);
    } else {
        dialog.setTitle(R.string.add_note);
    }

    saveButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            try {
                String text = noteView.getText().toString().trim();

                if (text.length() == 0) {
                    Toast.makeText(getActivity().getApplication(), R.string.please_enter_note,
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if (wallet.addTxNote(new Hash(tx), text)) {
                    application.saveWallet(new SuccessCallback() {
                        @Override
                        public void onSuccess() {

                            Toast.makeText(getActivity().getApplication(), R.string.note_saved,
                                    Toast.LENGTH_SHORT).show();

                            dismiss();
                        }

                        @Override
                        public void onFail() {

                            Toast.makeText(getActivity().getApplication(), R.string.toast_error_syncing_wallet,
                                    Toast.LENGTH_SHORT).show();

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

                Toast.makeText(getActivity().getApplication(), e.getLocalizedMessage(), Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    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.WelcomeDialog.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))
            .setTitle(R.string.welcome_title);

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

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

    final Button pairDeviceButton = (Button) view.findViewById(R.id.pair_device_button);
    final Button newAccountButton = (Button) view.findViewById(R.id.new_account_button);
    final TextView welcomeText = (TextView) view.findViewById(R.id.welcome_text);

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

    if (application.getRemoteWallet() == null) {
        welcomeText.setText(R.string.welcome_text_no_account);

        dialog.setCancelable(false);
    } else {
        dialog.setCancelable(application.decryptionErrors == 0);

        welcomeText.setText(R.string.welcome_text_has_account);
    }

    pairDeviceButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                dismiss();

                System.out.println("Start activity");

                startActivity(new Intent(getActivity(), PairWalletActivity.class));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    if (application.getRemoteWallet() == null) {

        newAccountButton.setVisibility(View.VISIBLE);

        newAccountButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                try {
                    dismiss();

                    NewAccountDialog.show(getFragmentManager(), application);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    } else {
        newAccountButton.setVisibility(View.GONE);
    }

    return dialog.create();
}

From source file:com.vnapnic.streamgames.ui.TDActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    try {/*from  w  w  w.  j a  va 2s  .  c o m*/
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        root = LayoutInflater.from(this).inflate(R.layout.main, null, false);
        setContentView(root);
        ButterKnife.inject(this);
        initNavigation();
        getSupportActionBar().hide();
        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);
        Animation animationIn = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha_in);
        logo.startAnimation(animationIn);
        showHome();
    } catch (Exception e) {
        root = new View(this);
        setContentView(root);
    }
}

From source file:nya.miku.wishmaster.ui.settings.AutohideActivity.java

@SuppressLint("InflateParams")
@Override//from   w ww.  j  a va  2  s. co  m
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Object item = l.getItemAtPosition(position);
    final int changeId;
    if (item instanceof AutohideRule) {
        changeId = position - 1;
    } else {
        changeId = -1; //-1 - ?  
    }

    Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
            ? new ContextThemeWrapper(this, R.style.Neutron_Medium)
            : this;
    View dialogView = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_autohide_rule, null);
    final EditText regexEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_regex);
    final Spinner chanSpinner = (Spinner) dialogView.findViewById(R.id.dialog_autohide_chan_spinner);
    final EditText boardEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_boardname);
    final EditText threadEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_threadnum);
    final CheckBox inCommentCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_comment);
    final CheckBox inSubjectCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_subject);
    final CheckBox inNameCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_name);

    chanSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, chans));
    if (changeId != -1) {
        AutohideRule rule = (AutohideRule) item;
        regexEditText.setText(rule.regex);
        int chanPosition = chans.indexOf(rule.chanName);
        chanSpinner.setSelection(chanPosition != -1 ? chanPosition : 0);
        boardEditText.setText(rule.boardName);
        threadEditText.setText(rule.threadNumber);
        inCommentCheckBox.setChecked(rule.inComment);
        inSubjectCheckBox.setChecked(rule.inSubject);
        inNameCheckBox.setChecked(rule.inName);
    } else {
        chanSpinner.setSelection(0);
    }

    DialogInterface.OnClickListener save = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String regex = regexEditText.getText().toString();
            if (regex.length() == 0) {
                Toast.makeText(AutohideActivity.this, R.string.autohide_error_empty_regex, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            try {
                Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL);
            } catch (Exception e) {
                CharSequence message = null;
                if (e instanceof PatternSyntaxException) {
                    String eMessage = e.getMessage();
                    if (!TextUtils.isEmpty(eMessage)) {
                        SpannableStringBuilder a = new SpannableStringBuilder(
                                getString(R.string.autohide_error_incorrect_regex));
                        a.append('\n');
                        int startlen = a.length();
                        a.append(eMessage);
                        a.setSpan(new TypefaceSpan("monospace"), startlen, a.length(),
                                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        message = a;
                    }
                }
                if (message == null)
                    message = getString(R.string.error_unknown);
                Toast.makeText(AutohideActivity.this, message, Toast.LENGTH_LONG).show();
                return;
            }

            AutohideRule rule = new AutohideRule();
            int spinnerSelectedPosition = chanSpinner.getSelectedItemPosition();
            rule.regex = regex;
            rule.chanName = spinnerSelectedPosition > 0 ? chans.get(spinnerSelectedPosition) : ""; // 0 ? = ? 
            rule.boardName = boardEditText.getText().toString();
            rule.threadNumber = threadEditText.getText().toString();
            rule.inComment = inCommentCheckBox.isChecked();
            rule.inSubject = inSubjectCheckBox.isChecked();
            rule.inName = inNameCheckBox.isChecked();

            if (!rule.inComment && !rule.inSubject && !rule.inName) {
                Toast.makeText(AutohideActivity.this, R.string.autohide_error_no_condition, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            if (changeId == -1) {
                rulesJson.put(rule.toJson());
            } else {
                rulesJson.put(changeId, rule.toJson());
            }
            rulesChanged();
        }
    };
    AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogView)
            .setTitle(changeId == -1 ? R.string.autohide_add_rule_title : R.string.autohide_edit_rule_title)
            .setPositiveButton(R.string.autohide_save_button, save)
            .setNegativeButton(android.R.string.cancel, null).create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}

From source file:pl.mrwojtek.sensrec.app.HeartRateDialog.java

@NonNull
@Override/*from www.  j a v a 2  s  .co  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), R.style.DialogTheme);
    LayoutInflater inflater = getActivity().getLayoutInflater().cloneInContext(context);
    View view = inflater.inflate(R.layout.heart_rate_dialog, null);

    prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

    progress = (ProgressBar) view.findViewById(R.id.progress);
    button = (Button) view.findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (bluetoothAdapter.isEnabled()) {
                scanLeDevice(true);
            } else {
                requestEnableBluetooth();
            }
        }
    });

    updateProgressAndButton();

    list = (ListView) view.findViewById(R.id.devices_list);
    list.setAdapter(adapter);

    textColorPrimary = ContextCompat.getColor(context, R.color.colorTextPrimary);
    textColorSecondary = ContextCompat.getColor(context, R.color.colorTextSecondary);
    textColorTertiary = ContextCompat.getColor(context, R.color.colorTextHint);

    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.DialogTheme);
    builder.setTitle(R.string.ble_title);
    builder.setView(view);
    builder.setNegativeButton(R.string.action_cancel, null);
    builder.setPositiveButton(R.string.action_ok, this);
    return MaterialUtils.fixTitle(context, builder.create(), null);
}

From source file:com.nextgis.libngui.dialog.StyledDialogFragment.java

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

    if (null == getParentFragment()) {
        setRetainInstance(mKeepInstance);
    }//from   w w w  . j  ava 2 s.c o m

    // StyledDialogFragment themes. These are fixed. To change the colors see colors.xml
    // Or use setThemeResId()
    if (null != mThemeResId) {
        mContext = new ContextThemeWrapper(getActivity(), mThemeResId);
    } else if (mIsThemeDark) {
        mContext = new ContextThemeWrapper(getActivity(), R.style.SdfTheme_Dark);
    } else {
        mContext = new ContextThemeWrapper(getActivity(), R.style.SdfTheme_Light);
    }
}