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