FileDocCategorySizeDatePackage
Display.javaAPI DocAndroid 1.5 API4844Wed May 06 22:42:48 BST 2009com.android.settings

Display

public class Display extends android.app.Activity implements View.OnClickListener

Fields Summary
private Spinner.OnItemSelectedListener
mFontSizeChanged
private android.widget.Spinner
mFontSize
private android.widget.TextView
mPreview
private android.util.TypedValue
mTextSizeTyped
private android.util.DisplayMetrics
mDisplayMetrics
private android.content.res.Configuration
mCurConfig
Constructors Summary
Methods Summary
public voidonClick(android.view.View v)

        try {
            ActivityManagerNative.getDefault().updateConfiguration(mCurConfig);
        } catch (RemoteException e) {
        }
        finish();
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        setContentView(R.layout.display);

        mFontSize = (Spinner) findViewById(R.id.fontSize);
        mFontSize.setOnItemSelectedListener(mFontSizeChanged);
        String[] states = new String[3];
        Resources r = getResources();
        states[0] = r.getString(R.string.small_font);
        states[1] = r.getString(R.string.medium_font);
        states[2] = r.getString(R.string.large_font);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, states);
        adapter.setDropDownViewResource(
                android.R.layout.simple_spinner_dropdown_item);
        mFontSize.setAdapter(adapter);

        mPreview = (TextView) findViewById(R.id.preview);
        mPreview.setText(r.getText(R.string.font_size_preview_text));

        Button save = (Button) findViewById(R.id.save);
        save.setText(r.getText(R.string.font_size_save));
        save.setOnClickListener(this);

        mTextSizeTyped = new TypedValue();
        TypedArray styledAttributes = 
            obtainStyledAttributes(android.R.styleable.TextView);
        styledAttributes.getValue(android.R.styleable.TextView_textSize,
                mTextSizeTyped);

        DisplayMetrics metrics = getResources().getDisplayMetrics();
        mDisplayMetrics = new DisplayMetrics();
        mDisplayMetrics.density = metrics.density;
        mDisplayMetrics.heightPixels = metrics.heightPixels;
        mDisplayMetrics.scaledDensity = metrics.scaledDensity;
        mDisplayMetrics.widthPixels = metrics.widthPixels;
        mDisplayMetrics.xdpi = metrics.xdpi;
        mDisplayMetrics.ydpi = metrics.ydpi;
        
        styledAttributes.recycle();
    
public voidonResume()

        super.onResume();
        try {
            mCurConfig.updateFrom(
                ActivityManagerNative.getDefault().getConfiguration());
        } catch (RemoteException e) {
        }
        if (mCurConfig.fontScale < 1) {
            mFontSize.setSelection(0);
        } else if (mCurConfig.fontScale > 1) {
            mFontSize.setSelection(2);
        } else {
            mFontSize.setSelection(1);
        }
        updateFontScale();
    
private voidupdateFontScale()

        mDisplayMetrics.scaledDensity = mDisplayMetrics.density *
                mCurConfig.fontScale;

        float size = mTextSizeTyped.getDimension(mDisplayMetrics);
        mPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);