Merge "The status bar half of making the status bar resize when hdmi is plugged in." into honeycomb
This commit is contained in:
@@ -25,7 +25,8 @@
|
||||
<FrameLayout
|
||||
android:id="@+id/bar_contents_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="@*android:dimen/status_bar_height"
|
||||
android:layout_gravity="bottom"
|
||||
>
|
||||
<RelativeLayout
|
||||
android:id="@+id/bar_contents"
|
||||
@@ -93,7 +94,8 @@
|
||||
<FrameLayout
|
||||
android:id="@+id/bar_shadow_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="@*android:dimen/status_bar_height"
|
||||
android:layout_gravity="bottom"
|
||||
>
|
||||
<!-- lights out shade -->
|
||||
<RelativeLayout
|
||||
|
||||
@@ -52,6 +52,7 @@ public abstract class StatusBar extends SystemUI implements CommandQueue.Callbac
|
||||
// Up-call methods
|
||||
protected abstract View makeStatusBarView();
|
||||
protected abstract int getStatusBarGravity();
|
||||
public abstract int getStatusBarHeight();
|
||||
|
||||
private DoNotDisturb mDoNotDisturb;
|
||||
|
||||
@@ -104,8 +105,7 @@ public abstract class StatusBar extends SystemUI implements CommandQueue.Callbac
|
||||
}
|
||||
|
||||
// Put up the view
|
||||
final Resources res = mContext.getResources();
|
||||
final int height= res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
|
||||
final int height = getStatusBarHeight();
|
||||
|
||||
final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
|
||||
@@ -287,9 +287,13 @@ public class PhoneStatusBar extends StatusBar {
|
||||
return Gravity.TOP | Gravity.FILL_HORIZONTAL;
|
||||
}
|
||||
|
||||
private void addIntruderView() {
|
||||
public int getStatusBarHeight() {
|
||||
final Resources res = mContext.getResources();
|
||||
final int height= res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
|
||||
return res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
|
||||
}
|
||||
|
||||
private void addIntruderView() {
|
||||
final int height = getStatusBarHeight();
|
||||
|
||||
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.statusbar.tablet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Slog;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.WindowManagerImpl;
|
||||
import android.view.WindowManagerPolicy;
|
||||
|
||||
public class HeightReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "StatusBar.HeightReceiver";
|
||||
|
||||
public interface OnBarHeightChangedListener {
|
||||
public void onBarHeightChanged(int height);
|
||||
}
|
||||
|
||||
Context mContext;
|
||||
ArrayList<OnBarHeightChangedListener> mListeners = new ArrayList<OnBarHeightChangedListener>();
|
||||
WindowManager mWindowManager;
|
||||
int mHeight;
|
||||
|
||||
public HeightReceiver(Context context) {
|
||||
mContext = context;
|
||||
mWindowManager = WindowManagerImpl.getDefault();
|
||||
}
|
||||
|
||||
public void addOnBarHeightChangedListener(OnBarHeightChangedListener l) {
|
||||
mListeners.add(l);
|
||||
l.onBarHeightChanged(mHeight);
|
||||
}
|
||||
|
||||
public void removeOnBarHeightChangedListener(OnBarHeightChangedListener l) {
|
||||
mListeners.remove(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final boolean plugged
|
||||
= intent.getBooleanExtra(WindowManagerPolicy.EXTRA_HDMI_PLUGGED_STATE, false);
|
||||
setPlugged(plugged);
|
||||
}
|
||||
|
||||
public void registerReceiver() {
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(WindowManagerPolicy.ACTION_HDMI_PLUGGED);
|
||||
final Intent val = mContext.registerReceiver(this, filter);
|
||||
onReceive(mContext, val);
|
||||
}
|
||||
|
||||
private void setPlugged(boolean plugged) {
|
||||
final Resources res = mContext.getResources();
|
||||
|
||||
Slog.d(TAG, "plugged=" + plugged);
|
||||
int height = -1;
|
||||
if (plugged) {
|
||||
final DisplayMetrics metrics = new DisplayMetrics();
|
||||
mWindowManager.getDefaultDisplay().getMetrics(metrics);
|
||||
Slog.d(TAG, "metrics=" + metrics);
|
||||
height = metrics.heightPixels - 720;
|
||||
}
|
||||
|
||||
final int minHeight
|
||||
= res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
|
||||
if (height < minHeight) {
|
||||
height = minHeight;
|
||||
}
|
||||
Slog.d(TAG, "using height=" + height + " old=" + mHeight);
|
||||
mHeight = height;
|
||||
|
||||
final int N = mListeners.size();
|
||||
for (int i=0; i<N; i++) {
|
||||
mListeners.get(i).onBarHeightChanged(height);
|
||||
}
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return mHeight;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ public class NotificationPanel extends RelativeLayout implements StatusBarPanel,
|
||||
ViewGroup mContentParent;
|
||||
|
||||
Choreographer mChoreo = new Choreographer();
|
||||
int mStatusBarHeight;
|
||||
|
||||
public NotificationPanel(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
@@ -66,11 +65,6 @@ public class NotificationPanel extends RelativeLayout implements StatusBarPanel,
|
||||
|
||||
public NotificationPanel(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
final Resources res = context.getResources();
|
||||
|
||||
mStatusBarHeight = res.getDimensionPixelSize(
|
||||
com.android.internal.R.dimen.status_bar_height);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,7 +74,8 @@ import com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.statusbar.policy.NetworkController;
|
||||
import com.android.systemui.recent.RecentApplicationsActivity;
|
||||
|
||||
public class TabletStatusBar extends StatusBar {
|
||||
public class TabletStatusBar extends StatusBar implements
|
||||
HeightReceiver.OnBarHeightChangedListener {
|
||||
public static final boolean DEBUG = false;
|
||||
public static final String TAG = "TabletStatusBar";
|
||||
|
||||
@@ -97,7 +98,9 @@ public class TabletStatusBar extends StatusBar {
|
||||
|
||||
public static final int LIGHTS_ON_DELAY = 5000;
|
||||
|
||||
int mBarHeight = -1;
|
||||
// The height of the bar, as definied by the build. It may be taller if we're plugged
|
||||
// into hdmi.
|
||||
int mNaturalBarHeight = -1;
|
||||
int mIconSize = -1;
|
||||
int mIconHPadding = -1;
|
||||
|
||||
@@ -134,6 +137,7 @@ public class TabletStatusBar extends StatusBar {
|
||||
|
||||
ViewGroup mPile;
|
||||
|
||||
HeightReceiver mHeightReceiver;
|
||||
BatteryController mBatteryController;
|
||||
NetworkController mNetworkController;
|
||||
|
||||
@@ -269,15 +273,15 @@ public class TabletStatusBar extends StatusBar {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onConfigurationChanged (Configuration newConfig) {
|
||||
protected void onConfigurationChanged(Configuration newConfig) {
|
||||
loadDimens();
|
||||
}
|
||||
|
||||
protected void loadDimens() {
|
||||
final Resources res = mContext.getResources();
|
||||
|
||||
mBarHeight = res.getDimensionPixelSize(
|
||||
com.android.internal.R.dimen.status_bar_height);
|
||||
mNaturalBarHeight = res.getDimensionPixelSize(
|
||||
com.android.internal.R.dimen.status_bar_height);
|
||||
|
||||
int newIconSize = res.getDimensionPixelSize(
|
||||
com.android.internal.R.dimen.status_bar_icon_size);
|
||||
@@ -298,6 +302,10 @@ public class TabletStatusBar extends StatusBar {
|
||||
mWindowManager = IWindowManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.WINDOW_SERVICE));
|
||||
|
||||
// This guy will listen for HDMI plugged broadcasts so we can resize the
|
||||
// status bar as appropriate.
|
||||
mHeightReceiver = new HeightReceiver(mContext);
|
||||
mHeightReceiver.registerReceiver();
|
||||
loadDimens();
|
||||
|
||||
final TabletStatusBarView sb = (TabletStatusBarView)View.inflate(
|
||||
@@ -408,13 +416,33 @@ public class TabletStatusBar extends StatusBar {
|
||||
ScrollView scroller = (ScrollView)mPile.getParent();
|
||||
scroller.setFillViewport(true);
|
||||
|
||||
mHeightReceiver.addOnBarHeightChangedListener(this);
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
public int getStatusBarHeight() {
|
||||
return mHeightReceiver.getHeight();
|
||||
}
|
||||
|
||||
protected int getStatusBarGravity() {
|
||||
return Gravity.BOTTOM | Gravity.FILL_HORIZONTAL;
|
||||
}
|
||||
|
||||
public void onBarHeightChanged(int height) {
|
||||
final WindowManager.LayoutParams lp
|
||||
= (WindowManager.LayoutParams)mStatusBarView.getLayoutParams();
|
||||
if (lp == null) {
|
||||
// haven't been added yet
|
||||
return;
|
||||
}
|
||||
if (lp.height != height) {
|
||||
lp.height = height;
|
||||
final WindowManager wm = WindowManagerImpl.getDefault();
|
||||
wm.updateViewLayout(mStatusBarView, lp);
|
||||
}
|
||||
}
|
||||
|
||||
private class H extends Handler {
|
||||
public void handleMessage(Message m) {
|
||||
switch (m.what) {
|
||||
@@ -1048,7 +1076,7 @@ public class TabletStatusBar extends StatusBar {
|
||||
if (mIconLayout == null) return;
|
||||
|
||||
final LinearLayout.LayoutParams params
|
||||
= new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mBarHeight);
|
||||
= new LinearLayout.LayoutParams(mIconSize + 2*mIconHPadding, mNaturalBarHeight);
|
||||
|
||||
int N = mNotns.size();
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user