FileDocCategorySizeDatePackage
Environment.javaAPI DocAndroid 1.5 API7191Wed May 06 22:42:48 BST 2009com.android.inputmethod.pinyin

Environment

public class Environment extends Object
Global environment configurations for showing soft keyboard and candidate view. All original dimension values are defined in float, and the real size is calculated from the float values of and screen size. In this way, this input method can work even when screen size is changed.

Fields Summary
private static final float
KEY_HEIGHT_RATIO_PORTRAIT
The key height for portrait mode. It is relative to the screen height.
private static final float
KEY_HEIGHT_RATIO_LANDSCAPE
The key height for landscape mode. It is relative to the screen height.
private static final float
CANDIDATES_AREA_HEIGHT_RATIO_PORTRAIT
The height of the candidates area for portrait mode. It is relative to screen height.
private static final float
CANDIDATES_AREA_HEIGHT_RATIO_LANDSCAPE
The height of the candidates area for portrait mode. It is relative to screen height.
private static final float
KEY_BALLOON_WIDTH_PLUS_RATIO
How much should the balloon width be larger than width of the real key. It is relative to the smaller one of screen width and height.
private static final float
KEY_BALLOON_HEIGHT_PLUS_RATIO
How much should the balloon height be larger than that of the real key. It is relative to the smaller one of screen width and height.
private static final float
NORMAL_KEY_TEXT_SIZE_RATIO
The text size for normal keys. It is relative to the smaller one of screen width and height.
private static final float
FUNCTION_KEY_TEXT_SIZE_RATIO
The text size for function keys. It is relative to the smaller one of screen width and height.
private static final float
NORMAL_BALLOON_TEXT_SIZE_RATIO
The text size balloons of normal keys. It is relative to the smaller one of screen width and height.
private static final float
FUNCTION_BALLOON_TEXT_SIZE_RATIO
The text size balloons of function keys. It is relative to the smaller one of screen width and height.
private static Environment
mInstance
The configurations are managed in a singleton.
private int
mScreenWidth
private int
mScreenHeight
private int
mKeyHeight
private int
mCandidatesAreaHeight
private int
mKeyBalloonWidthPlus
private int
mKeyBalloonHeightPlus
private int
mNormalKeyTextSize
private int
mFunctionKeyTextSize
private int
mNormalBalloonTextSize
private int
mFunctionBalloonTextSize
private android.content.res.Configuration
mConfig
private boolean
mDebug
Constructors Summary
private Environment()


      
    
Methods Summary
public intgetBalloonTextSize(boolean isFunctionKey)

        if (isFunctionKey) {
            return mFunctionBalloonTextSize;
        } else {
            return mNormalBalloonTextSize;
        }
    
public android.content.res.ConfigurationgetConfiguration()

        return mConfig;
    
public intgetHeightForCandidates()

        return mCandidatesAreaHeight;
    
public static com.android.inputmethod.pinyin.EnvironmentgetInstance()

        if (null == mInstance) {
            mInstance = new Environment();
        }
        return mInstance;
    
public intgetKeyBalloonHeightPlus()

        return mKeyBalloonHeightPlus;
    
public intgetKeyBalloonWidthPlus()

        return mKeyBalloonWidthPlus;
    
public intgetKeyHeight()

        return mKeyHeight;
    
public intgetKeyTextSize(boolean isFunctionKey)

        if (isFunctionKey) {
            return mFunctionKeyTextSize;
        } else {
            return mNormalKeyTextSize;
        }
    
public floatgetKeyXMarginFactor()

        return 1.0f;
    
public floatgetKeyYMarginFactor()

        if (Configuration.ORIENTATION_LANDSCAPE == mConfig.orientation) {
            return 0.7f;
        }
        return 1.0f;
    
public intgetScreenHeight()

        return mScreenHeight;
    
public intgetScreenWidth()

        return mScreenWidth;
    
public intgetSkbHeight()

        if (Configuration.ORIENTATION_PORTRAIT == mConfig.orientation) {
            return mKeyHeight * 4;
        } else if (Configuration.ORIENTATION_LANDSCAPE == mConfig.orientation) {
            return mKeyHeight * 4;
        }
        return 0;
    
public booleanhasHardKeyboard()

        if (mConfig.keyboard == Configuration.KEYBOARD_NOKEYS
                || mConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
            return false;
        }
        return true;
    
public booleanneedDebug()

        return mDebug;
    
public voidonConfigurationChanged(android.content.res.Configuration newConfig, android.content.Context context)

        if (mConfig.orientation != newConfig.orientation) {
            WindowManager wm = (WindowManager) context
                    .getSystemService(Context.WINDOW_SERVICE);
            Display d = wm.getDefaultDisplay();
            mScreenWidth = d.getWidth();
            mScreenHeight = d.getHeight();

            int scale;
            if (mScreenHeight > mScreenWidth) {
                mKeyHeight = (int) (mScreenHeight * KEY_HEIGHT_RATIO_PORTRAIT);
                mCandidatesAreaHeight = (int) (mScreenHeight * CANDIDATES_AREA_HEIGHT_RATIO_PORTRAIT);
                scale = mScreenWidth;
            } else {
                mKeyHeight = (int) (mScreenHeight * KEY_HEIGHT_RATIO_LANDSCAPE);
                mCandidatesAreaHeight = (int) (mScreenHeight * CANDIDATES_AREA_HEIGHT_RATIO_LANDSCAPE);
                scale = mScreenHeight;
            }
            mNormalKeyTextSize = (int) (scale * NORMAL_KEY_TEXT_SIZE_RATIO);
            mFunctionKeyTextSize = (int) (scale * FUNCTION_KEY_TEXT_SIZE_RATIO);
            mNormalBalloonTextSize = (int) (scale * NORMAL_BALLOON_TEXT_SIZE_RATIO);
            mFunctionBalloonTextSize = (int) (scale * FUNCTION_BALLOON_TEXT_SIZE_RATIO);
            mKeyBalloonWidthPlus = (int) (scale * KEY_BALLOON_WIDTH_PLUS_RATIO);
            mKeyBalloonHeightPlus = (int) (scale * KEY_BALLOON_HEIGHT_PLUS_RATIO);
        }

        mConfig.updateFrom(newConfig);