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.
}
});
}
Aggregations