summaryrefslogtreecommitdiffstats
path: root/policy
diff options
context:
space:
mode:
Diffstat (limited to 'policy')
-rw-r--r--policy/src/com/android/internal/policy/impl/PhoneWindow.java67
-rwxr-xr-xpolicy/src/com/android/internal/policy/impl/PhoneWindowManager.java33
2 files changed, 96 insertions, 4 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index 38eed50..1fc2e6c 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -15,6 +15,9 @@
package com.android.internal.policy.impl;
+import static android.view.View.MeasureSpec.AT_MOST;
+import static android.view.View.MeasureSpec.EXACTLY;
+import static android.view.View.MeasureSpec.getMode;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
@@ -52,6 +55,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.AndroidRuntimeException;
import android.util.Config;
+import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.Log;
import android.util.SparseArray;
@@ -72,6 +76,7 @@ import android.view.ViewManager;
import android.view.ViewStub;
import android.view.Window;
import android.view.WindowManager;
+import android.view.View.MeasureSpec;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.Animation;
@@ -98,7 +103,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
* Simple callback used by the context menu and its submenus. The options
* menu submenus do not use this (their behavior is more complex).
*/
- DialogMenuCallback mContextMenuCallback = new DialogMenuCallback(FEATURE_CONTEXT_MENU);
+ final DialogMenuCallback mContextMenuCallback = new DialogMenuCallback(FEATURE_CONTEXT_MENU);
+
+ final TypedValue mMinWidthMajor = new TypedValue();
+ final TypedValue mMinWidthMinor = new TypedValue();
// This is the top-level view of the window, containing the window decor.
private DecorView mDecor;
@@ -1866,6 +1874,45 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
}
@Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
+ final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
+
+ final int widthMode = getMode(widthMeasureSpec);
+
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+
+ int width = getMeasuredWidth();
+ boolean measure = false;
+
+ widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, EXACTLY);
+
+ final TypedValue tv = isPortrait ? mMinWidthMinor : mMinWidthMajor;
+
+ if (widthMode == AT_MOST && tv.type != TypedValue.TYPE_NULL) {
+ final int min;
+ if (tv.type == TypedValue.TYPE_DIMENSION) {
+ min = (int)tv.getDimension(metrics);
+ } else if (tv.type == TypedValue.TYPE_FRACTION) {
+ min = (int)tv.getFraction(metrics.widthPixels, metrics.widthPixels);
+ } else {
+ min = 0;
+ }
+
+ if (width < min) {
+ widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, EXACTLY);
+ measure = true;
+ }
+ }
+
+ // TODO: Support height?
+
+ if (measure) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
+ }
+
+ @Override
public void draw(Canvas canvas) {
super.draw(canvas);
@@ -2274,6 +2321,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
setFlags(FLAG_SPLIT_TOUCH, FLAG_SPLIT_TOUCH&(~getForcedWindowFlags()));
}
+ a.getValue(com.android.internal.R.styleable.Window_windowMinWidthMajor, mMinWidthMajor);
+ a.getValue(com.android.internal.R.styleable.Window_windowMinWidthMinor, mMinWidthMinor);
+
if (getContext().getApplicationInfo().targetSdkVersion
< android.os.Build.VERSION_CODES.HONEYCOMB) {
addFlags(WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY);
@@ -2329,7 +2379,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
// System.out.println("Features: 0x" + Integer.toHexString(features));
if ((features & ((1 << FEATURE_LEFT_ICON) | (1 << FEATURE_RIGHT_ICON))) != 0) {
if (mIsFloating) {
- layoutResource = com.android.internal.R.layout.dialog_title_icons;
+ TypedValue res = new TypedValue();
+ getContext().getTheme().resolveAttribute(
+ com.android.internal.R.attr.dialogTitleIconsDecorLayout, res, true);
+ layoutResource = res.resourceId;
} else {
layoutResource = com.android.internal.R.layout.screen_title_icons;
}
@@ -2346,7 +2399,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
// Special case for a window with a custom title.
// If the window is floating, we need a dialog layout
if (mIsFloating) {
- layoutResource = com.android.internal.R.layout.dialog_custom_title;
+ TypedValue res = new TypedValue();
+ getContext().getTheme().resolveAttribute(
+ com.android.internal.R.attr.dialogCustomTitleDecorLayout, res, true);
+ layoutResource = res.resourceId;
} else {
layoutResource = com.android.internal.R.layout.screen_custom_title;
}
@@ -2356,7 +2412,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
// If no other features and not embedded, only need a title.
// If the window is floating, we need a dialog layout
if (mIsFloating) {
- layoutResource = com.android.internal.R.layout.dialog_title;
+ TypedValue res = new TypedValue();
+ getContext().getTheme().resolveAttribute(
+ com.android.internal.R.attr.dialogTitleDecorLayout, res, true);
+ layoutResource = res.resourceId;
} else if ((features & (1 << FEATURE_ACTION_BAR)) != 0) {
if ((features & (1 << FEATURE_ACTION_BAR_OVERLAY)) != 0) {
layoutResource = com.android.internal.R.layout.screen_action_bar_overlay;
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 3e8318e..243fa07 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -122,6 +122,8 @@ import android.media.IAudioService;
import android.media.AudioManager;
import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
import java.util.ArrayList;
/**
@@ -712,6 +714,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
}
+ mHdmiPlugged = !readHdmiState();
+ setHdmiPlugged(!mHdmiPlugged);
// Note: the Configuration is not stable here, so we cannot load mStatusBarCanHide from
// config_statusBarCanHide because the latter depends on the screen size
@@ -2000,11 +2004,40 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mHdmiPlugged = plugged;
updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
Intent intent = new Intent(ACTION_HDMI_PLUGGED);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
mContext.sendStickyBroadcast(intent);
}
}
+ boolean readHdmiState() {
+ final String filename = "/sys/class/switch/hdmi/state";
+ FileReader reader = null;
+ try {
+ reader = new FileReader(filename);
+ char[] buf = new char[15];
+ int n = reader.read(buf);
+ if (n > 1) {
+ return 0 != Integer.parseInt(new String(buf, 0, n-1));
+ } else {
+ return false;
+ }
+ } catch (IOException ex) {
+ Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex);
+ return false;
+ } catch (NumberFormatException ex) {
+ Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex);
+ return false;
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException ex) {
+ }
+ }
+ }
+ }
+
/**
* @return Whether music is being played right now.
*/