Home | History | Annotate | Download | only in layout
      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 com.android.mms.LogTag;
     21 
     22 import android.content.Context;
     23 import android.util.Log;
     24 
     25 public class HVGALayoutParameters implements LayoutParameters {
     26     private static final String TAG = LogTag.TAG;
     27     private static final boolean DEBUG = false;
     28     private static final boolean LOCAL_LOGV = false;
     29 
     30     private int mType = -1;
     31 
     32     private static int mImageHeightLandscape;
     33     private static int mTextHeightLandscape;
     34     private static int mImageHeightPortrait;
     35     private static int mTextHeightPortrait;
     36     private static int mMaxHeight;
     37     private static int mMaxWidth;
     38 
     39     public HVGALayoutParameters(Context context, int type) {
     40         if ((type != HVGA_LANDSCAPE) && (type != HVGA_PORTRAIT)) {
     41             throw new IllegalArgumentException(
     42                     "Bad layout type detected: " + type);
     43         }
     44 
     45         if (LOCAL_LOGV) {
     46             Log.v(TAG, "HVGALayoutParameters.<init>(" + type + ").");
     47         }
     48         mType = type;
     49 
     50         float scale = context.getResources().getDisplayMetrics().density;
     51         mMaxWidth = (int) (context.getResources().getConfiguration().screenWidthDp * scale + 0.5f);
     52         mMaxHeight =
     53             (int) (context.getResources().getConfiguration().screenHeightDp * scale + 0.5f);
     54 
     55         mImageHeightLandscape = (int) (mMaxHeight * .90f);
     56         mTextHeightLandscape = (int) (mMaxHeight * .10f);
     57         mImageHeightPortrait = (int) (mMaxWidth * .90f);
     58         mTextHeightPortrait = (int) (mMaxWidth * .10f);
     59 
     60         if (LOCAL_LOGV) {
     61             Log.v(TAG, "HVGALayoutParameters mMaxWidth: " + mMaxWidth +
     62                     " mMaxHeight: " + mMaxHeight +
     63                     " mImageHeightLandscape: " + mImageHeightLandscape +
     64                     " mTextHeightLandscape: " + mTextHeightLandscape +
     65                     " mImageHeightPortrait: " + mImageHeightPortrait +
     66                     " mTextHeightPortrait: " + mTextHeightPortrait);
     67         }
     68 
     69     }
     70 
     71     public int getWidth() {
     72         return mType == HVGA_LANDSCAPE ? mMaxWidth
     73                                        : mMaxHeight;
     74     }
     75 
     76     public int getHeight() {
     77         return mType == HVGA_LANDSCAPE ? mMaxHeight
     78                                        : mMaxWidth;
     79     }
     80 
     81     public int getImageHeight() {
     82         return mType == HVGA_LANDSCAPE ? mImageHeightLandscape
     83                                        : mImageHeightPortrait;
     84     }
     85 
     86     public int getTextHeight() {
     87         return mType == HVGA_LANDSCAPE ? mTextHeightLandscape
     88                                        : mTextHeightPortrait;
     89     }
     90 
     91     public int getType() {
     92         return mType;
     93     }
     94 
     95     public String getTypeDescription() {
     96         return mType == HVGA_LANDSCAPE ? "HVGA-L" : "HVGA-P";
     97     }
     98 }
     99