LayoutManager.java revision 72735c62aba8fd2a9420a0f9f83d22543e3c164f
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 18package com.android.mms.layout; 19 20import android.content.Context; 21import android.content.res.Configuration; 22import android.util.Config; 23import android.util.Log; 24import android.view.Display; 25import android.view.WindowManager; 26 27/** 28 * MMS presentation layout management. 29 */ 30public class LayoutManager { 31 private static final String TAG = "LayoutManager"; 32 private static final boolean DEBUG = false; 33 private static final boolean LOCAL_LOGV = DEBUG ? Config.LOGD : Config.LOGV; 34 35 private final Context mContext; 36 private LayoutParameters mLayoutParams; 37 38 private static LayoutManager sInstance; 39 40 private LayoutManager(Context context) { 41 mContext = context; 42 initLayoutParameters(context.getResources().getConfiguration()); 43 } 44 45 private void initLayoutParameters(Configuration configuration) { 46 mLayoutParams = getLayoutParameters( 47 configuration.orientation == Configuration.ORIENTATION_PORTRAIT 48 ? LayoutParameters.HVGA_PORTRAIT 49 : LayoutParameters.HVGA_LANDSCAPE); 50 51 if (LOCAL_LOGV) { 52 Log.v(TAG, "LayoutParameters: " + mLayoutParams.getTypeDescription() 53 + ": " + mLayoutParams.getWidth() + "x" + mLayoutParams.getHeight()); 54 } 55 } 56 57 private static LayoutParameters getLayoutParameters(int displayType) { 58 switch (displayType) { 59 case LayoutParameters.HVGA_LANDSCAPE: 60 return new HVGALayoutParameters(LayoutParameters.HVGA_LANDSCAPE); 61 case LayoutParameters.HVGA_PORTRAIT: 62 return new HVGALayoutParameters(LayoutParameters.HVGA_PORTRAIT); 63 } 64 65 throw new IllegalArgumentException( 66 "Unsupported display type: " + displayType); 67 } 68 69 public static void init(Context context) { 70 if (LOCAL_LOGV) { 71 Log.v(TAG, "DefaultLayoutManager.init()"); 72 } 73 74 if (sInstance != null) { 75 Log.w(TAG, "Already initialized."); 76 } 77 sInstance = new LayoutManager(context); 78 } 79 80 public static LayoutManager getInstance() { 81 if (sInstance == null) { 82 throw new IllegalStateException("Uninitialized."); 83 } 84 return sInstance; 85 } 86 87 public void onConfigurationChanged(Configuration newConfig) { 88 if (LOCAL_LOGV) { 89 Log.v(TAG, "-> LayoutManager.onConfigurationChanged()."); 90 } 91 initLayoutParameters(newConfig); 92 } 93 94 public int getLayoutType() { 95 return mLayoutParams.getType(); 96 } 97 98 public int getLayoutWidth() { 99 return mLayoutParams.getWidth(); 100 } 101 102 public int getLayoutHeight() { 103 return mLayoutParams.getHeight(); 104 } 105 106 public LayoutParameters getLayoutParameters() { 107 return mLayoutParams; 108 } 109} 110