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.example.domiter.fileexplorer.dialog.BaseDialogFragment.java

private int getIconTintColor() {
    // Resolve AlertDialog theme
    TypedValue outValue = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.R.attr.alertDialogTheme, outValue, true);
    int theme = outValue.resourceId;
    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(getActivity(), theme);

    // Try to get title color
    int colorId = getThemedResourceId(contextThemeWrapper.getTheme(), textColorPrimary);
    int tintColor;
    if (colorId == -1) {
        tintColor = getThemedColor(contextThemeWrapper.getTheme(), textColorPrimary);
    } else {/*from www .  jav a 2s  .  c o m*/
        tintColor = contextThemeWrapper.getResources().getColor(colorId);
    }

    return tintColor;
}

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

/**
 * Inflates fragment root view and deals with view injections through ButterKnife
 *
 * Also applies app custom theme/* ww  w  . java  2  s  .  co m*/
 */
protected ViewGroup inflateRootView(@LayoutRes int viewResId, LayoutInflater inflater, ViewGroup container) {
    final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(),
            themeManager.getActiveThemeStyle());
    LayoutInflater themedInflater = inflater.cloneInContext(contextThemeWrapper);

    ViewGroup rootView = (ViewGroup) themedInflater.inflate(viewResId, container, false);
    ButterKnife.inject(this, rootView);
    return rootView;
}

From source file:android.support.v7.internal.widget.AbsActionBarView.java

AbsActionBarView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(R.attr.actionBarPopupTheme, tv, true) && tv.resourceId != 0) {
        mPopupContext = new ContextThemeWrapper(context, tv.resourceId);
    } else {/*  w w  w.  j  a  v  a 2 s .com*/
        mPopupContext = context;
    }
}

From source file:net.simonvt.cathode.ui.BaseActivity.java

@Override
protected void onCreate(Bundle inState) {
    super.onCreate(inState);
    CathodeApp.inject(this);
    CathodeApp.inject(this, injects);

    super.setContentView(R.layout.debug_home);

    settings = PreferenceManager.getDefaultSharedPreferences(this);

    Context drawerContext = new ContextThemeWrapper(this, R.style.Theme_AppCompat);
    LayoutInflater.from(drawerContext).inflate(R.layout.debug_drawer,
            (ViewGroup) ButterKnife.findById(this, R.id.debug_drawer));

    ButterKnife.inject(debugViews, this);

    debugViews.requestFailedEvent.setOnClickListener(new View.OnClickListener() {
        @Override/*from w w  w  . jav  a 2 s .  c  o m*/
        public void onClick(View v) {
            injects.bus.post(new RequestFailedEvent(R.string.error_unknown_retrying));
            debugViews.drawerLayout.closeDrawers();
        }
    });

    debugViews.authFailedEvent.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            injects.bus.post(new AuthFailedEvent());
            debugViews.drawerLayout.closeDrawers();
        }
    });

    int[] statusCodes = new int[] { 200, 401, 404, 502, };
    final IntAdapter httpStatusCodeAdapter = new IntAdapter(statusCodes);
    debugViews.httpStatusCode.setAdapter(httpStatusCodeAdapter);
    debugViews.httpStatusCode.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            injects.httpStatusCodePreference.set(httpStatusCodeAdapter.getItem(position));
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    debugViews.httpStatusCode
            .setSelection(httpStatusCodeAdapter.getPositionForValue(injects.httpStatusCodePreference.get()));

    debugViews.initialSync.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            injects.jobManager.addJob(new InitialSyncJob());
        }
    });

    debugViews.forceUpdate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            injects.jobManager.addJob(new ForceUpdateJob());
        }
    });

    debugViews.updatedLastDay.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String lastUpdated = TimeUtils.getIsoTime();
            settings.edit().putString(Settings.MOVIES_LAST_UPDATED, lastUpdated)
                    .putString(Settings.SHOWS_LAST_UPDATED, lastUpdated).apply();
            injects.jobManager.addJob(new StartSyncUpdatedShows());
            injects.jobManager.addJob(new StartSyncUpdatedMovies());
        }
    });

    debugViews.syncWatching.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            injects.jobManager.addJob(new SyncWatching());
        }
    });

    injects.jobManager.setJobListener(new JobManager.JobListener() {
        @Override
        public void onStatusChanged(JobManager.QueueStatus queueStatus) {
            switch (queueStatus) {
            case DONE:
                debugViews.queueStatus.setText("Done");
                break;

            case RUNNING:
                debugViews.queueStatus.setText("Running");
                break;

            case FAILED:
                debugViews.queueStatus.setText("Failed");
                break;
            }
        }

        @Override
        public void onSizeChanged(int jobCount) {
            debugViews.jobCount.setText(String.valueOf(jobCount));
        }
    });

    debugViews.startJobService.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(BaseActivity.this, JobService.class);
            startService(i);
        }
    });
}

From source file:ru.orangesoftware.financisto.widget.QuickAmountInput.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    Activity activity = getActivity();/*ww w .j  ava2 s  .co  m*/
    LinearLayout layout = new LinearLayout(activity);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setBackgroundColor(ContextCompat.getColor(activity, R.color.calculator_background));

    LinearLayout.LayoutParams lpWrapWrap = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    lpWrapWrap.weight = 1;

    // picker
    Currency currency = CurrencyCache.getCurrencyOrEmpty(currencyId);
    picker = new AmountPicker(activity, currency.decimals);
    layout.addView(picker, lpWrapWrap);
    picker.setCurrent(new BigDecimal(amount));
    picker.setOnChangeListener((picker, oldVal, newVal) -> setTitle());

    // buttons
    LinearLayout buttonsLayout = new LinearLayout(new ContextThemeWrapper(activity, R.style.ButtonBar), null,
            R.style.ButtonBar);
    buttonsLayout.setOrientation(LinearLayout.HORIZONTAL);

    Button bOK = new Button(activity);
    bOK.setText(R.string.ok);
    bOK.setOnClickListener(arg0 -> {
        listener.onAmountChanged(picker.getCurrent().toPlainString());
        dismiss();
    });
    buttonsLayout.addView(bOK, lpWrapWrap);

    Button bClear = new Button(activity);
    bClear.setText(R.string.reset);
    bClear.setOnClickListener(arg0 -> picker.setCurrent(BigDecimal.ZERO));
    buttonsLayout.addView(bClear, lpWrapWrap);

    Button bCancel = new Button(activity);
    bCancel.setText(R.string.cancel);
    bCancel.setOnClickListener(arg0 -> dismiss());

    buttonsLayout.addView(bCancel, lpWrapWrap);
    layout.addView(buttonsLayout,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    return layout;
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = (ViewGroup) inflater.inflate(layout, container, false);

    TextView sampleReport = (TextView) rootView.findViewById(R.id.tutorial_report_sample_button);
    sampleReport.setOnClickListener(new View.OnClickListener() {
        @Override//from w w w .  j a  va  2s .  c o m
        public void onClick(View v) {

            AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(getActivity(), android.R.style.Theme_DeviceDefault_Dialog));
            builder.setTitle(R.string.tutorial_crash_report_sample_title).setPositiveButton(R.string.close,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //nothing to do
                        }
                    });
            WebView webView = new WebView(getActivity());
            webView.loadUrl("file:///android_asset/sample_bug_report.html");
            builder.setView(webView);
            builder.show();
        }
    });

    final CheckBox sendReportsCheckbox = (CheckBox) rootView.findViewById(R.id.tutorial_crash_report_checkbox);
    final CrashReportManager crashReportManager = new CrashReportManager(getActivity());

    sendReportsCheckbox.setChecked(crashReportManager.isReportsEnabled());
    sendReportsCheckbox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            boolean willSendReports = sendReportsCheckbox.isChecked();
            crashReportManager.setReportsEnabled(willSendReports);
        }
    });
    return rootView;
}

From source file:com.google.samples.apps.topeka.view.quiz.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 = (Theme) getArguments().getSerializable(KEY_THEME);
    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:it.mb.whatshare.PatchedDialogFragment.java

/**
 * Returns a builder that will create a dialog that can only be canceled by
 * clicking OK or by pressing back.//from w w  w  .j  av  a2 s  .c  om
 * 
 * <p>
 * Whenever the dialog is dismissed, {@link Activity#finish()} is called on
 * the argument <tt>activity</tt>.
 * 
 * <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 getNoUiBuilder(final FragmentActivity activity) {
    context = new ContextThemeWrapper(activity, R.style.DialogTheme);
    // @formatter:off
    return new AlertDialog.Builder(context).setCancelable(false)
            .setOnKeyListener(new DialogInterface.OnKeyListener() {
                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP
                            && !event.isCanceled()) {
                        dialog.cancel();
                        activity.finish();
                        return true;
                    }
                    return false;
                }
            }).setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    activity.finish();
                }
            });
    // @formatter:on
}

From source file:org.solovyev.android.messenger.preferences.PreferenceListFragment.java

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

    if (themeResId == NO_THEME) {
        themeContext = getActivity();/*from  ww w  .j  a  v a2  s. c o  m*/
        themeInflater = inflater;
    } else {
        themeContext = new ContextThemeWrapper(getActivity(), themeResId);
        themeInflater = LayoutInflater.from(themeContext);
    }

    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:sg.fxl.topekaport.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 = quiz.getTheme();
    final ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), theme.getStyleId());
    final LayoutInflater themedInflater = LayoutInflater.from(context);
    return themedInflater.inflate(R.layout.fragment_quiz, container, false);
}