Android之framework修改底部导航栏NavigationBar动态显示和隐藏
原文链接
http://blog.csdn.net/way_ping_li/article/details/45727335
git diff
diff --git a/frameworks/base/core/java/com/android/internal/statusbar/IStatusBar.aidl b/frameworks/base/core/java/com/android/internal/statusbar/IStatusBar.aidl
index a3c0db4..a9091cd 100644
--- a/frameworks/base/core/java/com/android/internal/statusbar/IStatusBar.aidl
+++ b/frameworks/base/core/java/com/android/internal/statusbar/IStatusBar.aidl
@@ -36,7 +36,7 @@ oneway interface IStatusBar
void buzzBeepBlinked();
void notificationLightOff();
void notificationLightPulse(int argb, int millisOn, int millisOff);
-
+ void showNavigationBar();
void showRecentApps(boolean triggeredFromAltTab);
void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey);
void toggleRecentApps();
diff --git a/frameworks/base/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/frameworks/base/core/java/com/android/internal/statusbar/IStatusBarService.aidl
index 40c009f..7bf46cc 100644
--- a/frameworks/base/core/java/com/android/internal/statusbar/IStatusBarService.aidl
+++ b/frameworks/base/core/java/com/android/internal/statusbar/IStatusBarService.aidl
@@ -55,7 +55,7 @@ interface IStatusBarService
void onNotificationExpansionChanged(in String key, in boolean userAction, in boolean expanded);
void setSystemUiVisibility(int vis, int mask, String cause);
void setWindowState(int window, int state);
-
+ void showNavigationBar();
void showRecentApps(boolean triggeredFromAltTab);
void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey);
void toggleRecentApps();
diff --git a/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml b/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml
old mode 100644
new mode 100755
index 898389d..42a5bff
--- a/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml
+++ b/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml
@@ -42,13 +42,28 @@
>
<!-- navigation controls -->
- <View
+ <!--BEGIN liweiping
+ <View
android:layout_width="@dimen/navigation_side_padding"
android:layout_height="match_parent"
android:layout_weight="0"
android:visibility="invisible"
/>
- <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back"
+ -->
+ <FrameLayout
+ android:layout_width="@dimen/navigation_extra_key_width"
+ android:layout_height="match_parent"
+ android:layout_weight="0" >
+ <ImageButton
+ android:id="@+id/hide_bar_btn"
+ android:layout_width="@dimen/navigation_extra_key_width"
+ android:layout_height="match_parent"
+ android:contentDescription="@string/accessibility_hide"
+ android:src="@drawable/ic_sysbar_hide"
+ />
+ </FrameLayout>
+
+ <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back"
android:layout_width="@dimen/navigation_key_width"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_back"
@@ -57,13 +72,30 @@
android:scaleType="center"
android:contentDescription="@string/accessibility_back"
/>
+
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="invisible"
/>
- <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
+ <!--BEGIN liweiping
+ <FrameLayout
+ android:layout_weight="0"
+ android:layout_width="match_parent"
+ android:layout_height="40dp" >
+
+ <ImageButton
+ android:id="@+id/hide_bar_btn"
+ android:layout_width="match_parent"
+ android:layout_height="40dp"
+ android:contentDescription="@string/accessibility_hide"
+ android:src="@drawable/ic_sysbar_hide_land"
+ />
+ </FrameLayout>
+ -->
+
+ <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
android:layout_width="@dimen/navigation_key_width"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_home"
diff --git a/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml b/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml
old mode 100644
new mode 100755
index c3811f8..58a8375
--- a/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml
+++ b/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml
@@ -27,8 +27,9 @@
<string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"关闭最近运行的应用"</string>
<plurals name="status_bar_accessibility_recent_apps">
<item quantity="one" msgid="3969335317929254918">"概览中有 1 个屏幕"</item>
- <item quantity="other" msgid="5523506463832158203">"概览中有 %d 个屏幕"</item>
+ <item quantity="other" msgid="5523506463832158203">"概览中有 %d 个屏幕"</item>
</plurals>
+ <string name="accessibility_hide" msgid="6952821216480289285">"隐藏"</string>
<string name="status_bar_no_notifications_title" msgid="4755261167193833213">"无通知"</string>
<string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"正在进行的"</string>
<string name="status_bar_latest_events_title" msgid="6594767438577593172">"通知"</string>
diff --git a/frameworks/base/packages/SystemUI/res/values/strings.xml b/frameworks/base/packages/SystemUI/res/values/strings.xml
old mode 100644
new mode 100755
index 558d90a..bf1e2e2
--- a/frameworks/base/packages/SystemUI/res/values/strings.xml
+++ b/frameworks/base/packages/SystemUI/res/values/strings.xml
@@ -47,7 +47,7 @@
<!-- The label in the bar at the top of the status bar when there are no notifications
showing. [CHAR LIMIT=40]-->
<string name="status_bar_no_notifications_title">No notifications</string>
-
+ <string name="accessibility_hide">Hide</string>
<!-- The label for the group of notifications for ongoing events in the opened version of
the status bar. An ongoing call is the prime example of this. The MP3 music player
might be another example. [CHAR LIMIT=40] -->
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/frameworks/base/packages/SystemUI/src/com/android/syste
mui/statusbar/CommandQueue.java
old mode 100644
new mode 100755
index 0b1b883..16659a5
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -57,6 +57,7 @@ public class CommandQueue extends IStatusBar.Stub {
private static final int MSG_NOTIFICATION_LIGHT_OFF = 16 << MSG_SHIFT;
private static final int MSG_NOTIFICATION_LIGHT_PULSE = 17 << MSG_SHIFT;
private static final int MSG_SHOW_SCREEN_PIN_REQUEST = 18 << MSG_SHIFT;
+ private static final int MSG_SHOW_NAVIGATIONBAR = 19 << MSG_SHIFT;//ADD liweiping
public static final int FLAG_EXCLUDE_NONE = 0;
public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
@@ -84,6 +85,7 @@ public class CommandQueue extends IStatusBar.Stub {
public void animateCollapsePanels(int flags);
public void animateExpandSettingsPanel();
public void setSystemUiVisibility(int vis, int mask);
+ public void showNavigationBar();//ADD liweiping
public void topAppWindowChanged(boolean visible);
public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
boolean showImeSwitcher);
@@ -157,6 +159,15 @@ public class CommandQueue extends IStatusBar.Stub {
}
}
+ //BEGIN liweiping
+ public void showNavigationBar() {
+ synchronized (mList) {
+ mHandler.removeMessages(MSG_SHOW_NAVIGATIONBAR);
+ mHandler.sendEmptyMessage(MSG_SHOW_NAVIGATIONBAR);
+ }
+ }
+ //END liweiping
+
public void topAppWindowChanged(boolean menuVisible) {
synchronized (mList) {
mHandler.removeMessages(MSG_TOP_APP_WINDOW_CHANGED);
@@ -291,6 +302,11 @@ public class CommandQueue extends IStatusBar.Stub {
case MSG_SET_SYSTEMUI_VISIBILITY:
mCallbacks.setSystemUiVisibility(msg.arg1, msg.arg2);
break;
+ //BEGIN liweiping
+ case MSG_SHOW_NAVIGATIONBAR:
+ mCallbacks.showNavigationBar();
+ break;
+ //END liweiping
case MSG_TOP_APP_WINDOW_CHANGED:
mCallbacks.topAppWindowChanged(msg.arg1 != 0);
break;
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/frameworks/base/packages/SystemUI/src/com/an
droid/systemui/statusbar/phone/NavigationBarView.java
old mode 100644
new mode 100755
index 1e4dfb4..f111101
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -50,6 +50,7 @@ import com.android.systemui.R;
import com.android.systemui.statusbar.BaseStatusBar;
import com.android.systemui.statusbar.DelegateViewHelper;
import com.android.systemui.statusbar.policy.DeadZone;
+import com.android.systemui.statusbar.policy.KeyButtonRipple;
import com.android.systemui.statusbar.policy.KeyButtonView;
import java.io.FileDescriptor;
@@ -270,6 +271,13 @@ public class NavigationBarView extends LinearLayout {
public View getImeSwitchButton() {
return mCurrentView.findViewById(R.id.ime_switcher);
}
+ //BEGIN liweiping
+ public View getHideBarButton() {
+ View view = mCurrentView.findViewById(R.id.hide_bar_btn);
+ view.setBackground(new KeyButtonRipple(getContext(), view));
+ return view;
+ }
+ //END liweiping
private void getIcons(Resources res) {
mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back);
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/frameworks/base/packages/SystemUI/src/com/andro
id/systemui/statusbar/phone/PhoneStatusBar.java
old mode 100644
new mode 100755
index f227107..abcc140
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -522,7 +522,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mHandler.postAtTime(mVisibilityReporter, nextReportUptimeMs);
}
};
-
+
// Tracks notifications currently visible in mNotificationStackScroller and
// emits visibility events via NoMan on changes.
private final Runnable mVisibilityReporter = new Runnable() {
@@ -1100,6 +1100,53 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
}
}
+ ///////////////////////////begin by chenyu////////////////////////////////////////
+^M
+
+ private void removeNavigationBar() {
+ if (DEBUG) Log.d(TAG, "removeNavigationBar: about to remove " + mNavigationBarView);
+ if (mNavigationBarView == null) return;
+
+ mWindowManager.removeView(mNavigationBarView);
+ mNavigationBarView = null;
+ }
+
+ @Override // CommandQueue
+ public void showNavigationBar() {
+
+ Log.i("way", TAG + " showNavigationBar...");
+
+ forceAddNavigationBar();
+
+ }
+^M
+ private void forceAddNavigationBar() {
+ // If we have no Navbar view and we should have one, create it
+ if (mNavigationBarView != null) {
+ return;
+ }
+
+ mNavigationBarView =
+ (NavigationBarView) View.inflate(mContext, R.layout.navigation_bar, null);
+^M
+ mNavigationBarView.setDisabledFlags(mDisabled);
+ mNavigationBarView.setBar(this);
+ addNavigationBar(true); // dynamically adding nav bar, reset System UI visibility!
+ }
+^M
+
+ // For small-screen devices (read: phones) that lack hardware navigation buttons
+ private void addNavigationBar(boolean forceReset) {
+ if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + mNavigationBarView);
+ if (mNavigationBarView == null) return;
+
+ prepareNavigationBarView(forceReset);
+
+ mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams());
+ }
+ //END liweiping
+//////////////////////////////////////////////////////////////
+
@Override
public void hideSearchPanel() {
super.hideSearchPanel();
@@ -1165,6 +1212,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
}
};
+
+
private void awakenDreams() {
if (mDreamManager != null) {
try {
@@ -1174,7 +1223,44 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
}
}
}
-
+ /////////////////////////begin chenyu/////////////////////////////////////
+ private final View.OnClickListener mHideBarClickListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Log.i("way", "mHideBarClickListener onClick...");
+ removeNavigationBar();
+ }
+ };
+
+ private void prepareNavigationBarView(boolean forceReset) {
+ mNavigationBarView.reorient();
+ mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener);
+ mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPreloadOnTouchListener);
+ mNavigationBarView.getRecentsButton().setLongClickable(true);
+ mNavigationBarView.getRecentsButton().setOnLongClickListener(mLongPressBackRecentsListener);
+ mNavigationBarView.getBackButton().setLongClickable(true);
+ mNavigationBarView.getBackButton().setOnLongClickListener(mLongPressBackRecentsListener);
+ mNavigationBarView.getHomeButton().setOnTouchListener(mHomeActionListener);
+ mNavigationBarView.getHideBarButton().setOnClickListener(mHideBarClickListener);//ADD liweiping
+
+ if (forceReset) {
+ // Nav Bar was added dynamically - we need to reset the mSystemUiVisibility and call
+ // setSystemUiVisibility so that mNavigationBarMode is set to the correct value
+ Log.i("way", "prepareNavigationBarView mNavigationBarMode = "+ mNavigationBarMode + " mSystemUiVisibility = " + mSystemUiVisibility + " mNavigati
onIconHints = " + mNavigationIconHints);
+ mNavigationBarMode = 0;
+
+ int newVal = mSystemUiVisibility;
+ mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;
+ setSystemUiVisibility(newVal, /*SYSTEM_UI_VISIBILITY_MASK*/0xffffffff);
+ int hints = mNavigationIconHints;
+ mNavigationIconHints = 0;
+ setNavigationIconHints(hints);
+ topAppWindowChanged(true); //TODO--chenyu
+ }
+
+ updateSearchPanel();
+ }
+//////////////////////////////////////////////////////////////////////////////////////
private void prepareNavigationBarView() {
mNavigationBarView.reorient();
@@ -1185,6 +1271,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mNavigationBarView.getBackButton().setLongClickable(true);
mNavigationBarView.getBackButton().setOnLongClickListener(mLongPressBackRecentsListener);
mNavigationBarView.getHomeButton().setOnTouchListener(mHomeActionListener);
+ mNavigationBarView.getHideBarButton().setOnClickListener(mHideBarClickListener);//ADD liweiping
+
updateSearchPanel();
}
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java b/frameworks/base/packages/SystemUI/src/com/android/sys
temui/statusbar/tv/TvStatusBar.java
old mode 100644
new mode 100755
index 08732e5..5ded51e
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java
@@ -86,7 +86,10 @@ public class TvStatusBar extends BaseStatusBar {
@Override
public void toggleRecentApps() {
}
-
+ @Override // CommandQueue
+ public void showNavigationBar() {
+
+ }
@Override // CommandQueue
public void setWindowState(int window, int state) {
}
diff --git a/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/frameworks/base/policy/src/com/android/internal/policy/imp
l/PhoneWindowManager.java
old mode 100644
new mode 100755
index c1fee0a..c8f09e4
--- a/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -1304,13 +1304,25 @@ public class PhoneWindowManager implements WindowManagerPolicy {
public void onSwipeFromBottom() {
if (mNavigationBar != null && mNavigationBarOnBottom) {
requestTransientBars(mNavigationBar);
- }
+ Log.i("way", "onSwipeFromBottom... mNavigationBar != null && mNavigationBarOnBottom");
+ }//BEGIN liweiping
+ else{
+ Log.i("way", "onSwipeFromBottom...");
+ showNavigationBar();
+ }
+ //END liweiping
}
@Override
public void onSwipeFromRight() {
if (mNavigationBar != null && !mNavigationBarOnBottom) {
requestTransientBars(mNavigationBar);
- }
+ Log.i("way", "onSwipeFromRight... mNavigationBar != null && !mNavigationBarOnBottom");
+ }
+ //BEGIN liweiping
+ else{
+ Log.i("way", "onSwipeFromRight...");
+ showNavigationBar();
+ }//END liweiping
}
@Override
public void onDebug() {
@@ -1349,7 +1361,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {
goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
}
}
-
+ //BEGIN liweiping
+ private void showNavigationBar(){
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ IStatusBarService statusbar = getStatusBarService();
+ if (statusbar != null) {
+ statusbar.showNavigationBar();
+ }
+ } catch (RemoteException e) {
+ // re-acquire status bar service next time it is needed.
+ mStatusBarService = null;
+ }
+ }
+ });
+ }
+ //END liweiping
/**
* Read values from config.xml that may be overridden depending on
* the configuration of the device.
diff --git a/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/frameworks/base/services/core/java/com/android/se
rver/statusbar/StatusBarManagerService.java
old mode 100644
new mode 100755
index cf2ed07..28f3003
--- a/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -378,6 +378,28 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
}
}
+ //BEGIN liweiping
+ @Override
+ public void showNavigationBar() {
+ enforceStatusBar();
+
+ android.util.Log.d("way", TAG + " showNavigationBar...");
+
+ synchronized(mLock) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ if (mBar != null) {
+ try {
+ mBar.showNavigationBar();
+ } catch (RemoteException ex) {
+ }
+ }
+ }
+ });
+ }
+ }
+ //END liweiping
+
private void updateUiVisibilityLocked(final int vis, final int mask) {
if (mSystemUiVisibility != vis) {
mSystemUiVisibility = vis;
(END)