1 /* 2 * Copyright (C) 2008 Esmertec AG. 3 * Copyright (C) 2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mms.layout; 19 20 import android.content.Context; 21 import android.util.Log; 22 23 public class HVGALayoutParameters implements LayoutParameters { 24 private static final String TAG = "HVGALayoutParameters"; 25 private static final boolean DEBUG = false; 26 private static final boolean LOCAL_LOGV = false; 27 28 private int mType = -1; 29 30 private static int mImageHeightLandscape; 31 private static int mTextHeightLandscape; 32 private static int mImageHeightPortrait; 33 private static int mTextHeightPortrait; 34 private static int mMaxHeight; 35 private static int mMaxWidth; 36 37 public HVGALayoutParameters(Context context, int type) { 38 if ((type != HVGA_LANDSCAPE) && (type != HVGA_PORTRAIT)) { 39 throw new IllegalArgumentException( 40 "Bad layout type detected: " + type); 41 } 42 43 if (LOCAL_LOGV) { 44 Log.v(TAG, "HVGALayoutParameters.<init>(" + type + ")."); 45 } 46 mType = type; 47 48 float scale = context.getResources().getDisplayMetrics().density; 49 mMaxWidth = (int) (context.getResources().getConfiguration().screenWidthDp * scale + 0.5f); 50 mMaxHeight = 51 (int) (context.getResources().getConfiguration().screenHeightDp * scale + 0.5f); 52 53 mImageHeightLandscape = (int) (mMaxHeight * .90f); 54 mTextHeightLandscape = (int) (mMaxHeight * .10f); 55 mImageHeightPortrait = (int) (mMaxWidth * .90f); 56 mTextHeightPortrait = (int) (mMaxWidth * .10f); 57 58 if (LOCAL_LOGV) { 59 Log.v(TAG, "HVGALayoutParameters mMaxWidth: " + mMaxWidth + 60 " mMaxHeight: " + mMaxHeight + 61 " mImageHeightLandscape: " + mImageHeightLandscape + 62 " mTextHeightLandscape: " + mTextHeightLandscape + 63 " mImageHeightPortrait: " + mImageHeightPortrait + 64 " mTextHeightPortrait: " + mTextHeightPortrait); 65 } 66 67 } 68 69 public int getWidth() { 70 return mType == HVGA_LANDSCAPE ? mMaxWidth 71 : mMaxHeight; 72 } 73 74 public int getHeight() { 75 return mType == HVGA_LANDSCAPE ? mMaxHeight 76 : mMaxWidth; 77 } 78 79 public int getImageHeight() { 80 return mType == HVGA_LANDSCAPE ? mImageHeightLandscape 81 : mImageHeightPortrait; 82 } 83 84 public int getTextHeight() { 85 return mType == HVGA_LANDSCAPE ? mTextHeightLandscape 86 : mTextHeightPortrait; 87 } 88 89 public int getType() { 90 return mType; 91 } 92 93 public String getTypeDescription() { 94 return mType == HVGA_LANDSCAPE ? "HVGA-L" : "HVGA-P"; 95 } 96 } 97