Search in sources :

Example 1 with FontFamily

use of org.chromium.components.dom_distiller.core.FontFamily in project AndroidChromium by JackyAndroid.

the class DistilledPagePrefsView method initFontFamilySpinner.

private void initFontFamilySpinner() {
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(), android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.distiller_mode_font_family_values)) {

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            return overrideTypeFace(view, position);
        }

        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            View view = super.getDropDownView(position, convertView, parent);
            return overrideTypeFace(view, position);
        }

        private View overrideTypeFace(View view, int position) {
            if (view instanceof TextView) {
                TextView textView = (TextView) view;
                FontFamily family = FontFamily.values()[position];
                if (family == FontFamily.MONOSPACE) {
                    textView.setTypeface(Typeface.MONOSPACE);
                } else if (family == FontFamily.SANS_SERIF) {
                    textView.setTypeface(Typeface.SANS_SERIF);
                } else if (family == FontFamily.SERIF) {
                    textView.setTypeface(Typeface.SERIF);
                }
            }
            return view;
        }
    };
    adapter.setDropDownViewResource(R.layout.distilled_page_font_family_spinner);
    mFontFamilySpinner.setAdapter(adapter);
    mFontFamilySpinner.setSelection(mDistilledPagePrefs.getFontFamily().ordinal());
    mFontFamilySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            FontFamily family = FontFamily.getFontFamilyForValue(position);
            if (family != null) {
                mDistilledPagePrefs.setFontFamily(family);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // Nothing to do.
        }
    });
}
Also used : FontFamily(org.chromium.components.dom_distiller.core.FontFamily) ViewGroup(android.view.ViewGroup) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 OnItemSelectedListener (android.widget.AdapterView.OnItemSelectedListener)1 ArrayAdapter (android.widget.ArrayAdapter)1 TextView (android.widget.TextView)1 FontFamily (org.chromium.components.dom_distiller.core.FontFamily)1