Galaxy Nexus は物理的にも幅があるので、ナビゲーションバーを 5 つボタンに変更し、
片手で操作できるように、ステータスバー開閉ボタンを追加しました。
この機能により、ナビゲーションバーからステータスバーの開閉(上げ下げ)ができます。

※左から 『 戻る 』『 旧メニュー 』『 ホーム 』『 ステータスバー開閉 』『 最近使ったアプリ 』 ボタン
※Galaxy Nexus の幅は720 pixel、Density 2.0 なので、全幅は 360 dp
※幅いっぱいに、5 個のボタンを均等に配置すると、1ボタンあたり 72 dp(元々は 80 dp + パディング View)
変更点
※以下、android-4.0.3_r1/frameworks/base/packages/SystemUI のコード
- res/drawable-hdp へステータスバー開閉用のボタンイメージを追加
- ic_sysbar_expand.png
- ic_sysbar_expand_land.png
※上記のイメージを右クリックなどからダウンロードできます(透過で見えないため、ブログの背景色を変更しています)
- src/com/android/systemui/statusbar/phone/NavigationBarView.java
- (他のボタンと同様に)ボタンへのアクセッサ追加(getExpandButton)
- ステータスバー開閉機能追加(expand, collapse)
- setDisabledFlags() に追加したボタンの表示状態を設定する処理を追加
- デバッグダンプ用コード追加(任意(以下では省略))
public View getBackButton() {
return mCurrentView.findViewById(R.id.back);
}
public View getHomeButton() {
return mCurrentView.findViewById(R.id.home);
}
// -> added for toggle statusbar (1)
public View getExpandButton() {
return mCurrentView.findViewById(R.id.expand);
}
// <- added for toggle statusbar
// -> added for toggle statusbar (2)
public void expand() {
try {
mBarService.expand();
} catch (android.os.RemoteException ex) {
}
}
// <- added for toggle statusbar
// -> added for toggle statusbar (2)
public void collapse() {
try {
mBarService.collapse();
} catch (android.os.RemoteException ex) {
}
}
// <- added for toggle statusbar
public void setDisabledFlags(int disabledFlags, boolean force) {
if (!force && mDisabledFlags == disabledFlags) return;
mDisabledFlags = disabledFlags;
final boolean disableHome = ((disabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0);
final boolean disableRecent = ((disabledFlags & View.STATUS_BAR_DISABLE_RECENT) != 0);
final boolean disableMyMenu = ((disabledFlags & View.STATUS_BAR_DISABLE_RECENT) != 0);
final boolean disableBack = ((disabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0);
// -> added for toggle statusbar (3)
final boolean disableExpand = ((disabledFlags & View.STATUS_BAR_DISABLE_RECENT) != 0);
// <- added for toggle statusbar
getBackButton() .setVisibility(disableBack ? View.INVISIBLE : View.VISIBLE);
getHomeButton() .setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE);
getMyMenuButton() .setVisibility(disableMyMenu ? View.INVISIBLE : View.VISIBLE);
getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE);
// -> added for toggle statusbar (3)
getExpandButton(). setVisibility(disableExpand ? View.INVISIBLE : View.VISIBLE);
// <- added for toggle statusbar
}
- src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
- ボタンクリック時にステータスバーを開閉するリスナー追加
- ナビゲーションバー初期化時にボタンクリック時のリスナー設定
private View.OnClickListener mRecentsClickListener = new View.OnClickListener() {
public void onClick(View v) {
toggleRecentApps();
}
};
// -> added for toggle statusbar (1)
private View.OnClickListener mExpandClickListener = new View.OnClickListener() {
public void onClick(View v) {
if (!mAnimating) {
if (mExpanded) {
mNavigationBarView.collapse();
} else {
mNavigationBarView.expand();
}
}
}
};
// <- added for toggle statusbar
private void prepareNavigationBarView() {
mNavigationBarView.reorient();
mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener);
mNavigationBarView.getRecentsButton().setOnTouchListener(mRecentsPanel);
// -> added for toggle statusbar (2)
mNavigationBarView.getExpandButton().setOnClickListener(mExpandClickListener);
// <- added for toggle statusbar
}
// For small-screen devices (read: phones) that lack hardware navigation buttons
private void addNavigationBar() {
if (mNavigationBarView == null) return;
- res/layout/navigation_bar.xml
- ナビゲーションバーに新規ボタン追加(android:id="@+id/expand")
- ナビゲーションバーのボタン幅を 80dp から 72 dp に変更(72dp x 5 = 360dp = 画面幅)
- ナビゲーションバーの空きスペースを埋めるための View を削除
<FrameLayout android:id="@+id/rot0"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
android:clipChildren="false"
android:clipToPadding="false"
android:id="@+id/nav_buttons"
android:animateLayoutChanges="true"
>
<!-- navigation controls -->
<!-- changed 80dp to 72dp (2) -->
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back"
android:layout_width="72dp"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_back"
systemui:keyCode="4"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:contentDescription="@string/accessibility_back"
/>
<!-- comment out (3)
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="invisible"
/>
-->
<!-- changed 80dp to 72dp (2) -->
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/mymenu"
android:layout_width="72dp"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_menu"
systemui:keyCode="82"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:contentDescription="@string/accessibility_menu"
/>
<!-- comment out (3)
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="invisible"
/>
-->
<!-- changed 80dp to 72dp (2) -->
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
android:layout_width="72dp"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_home"
systemui:keyCode="3"
systemui:keyRepeat="false"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:contentDescription="@string/accessibility_home"
/>
<!-- comment out (3)
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="invisible"
/>
-->
<!-- added (1) -->
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/expand"
android:layout_width="72dp"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_expand"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
/>
<!-- changed 80dp to 72dp (2) -->
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/recent_apps"
android:layout_width="72dp"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_recent"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:contentDescription="@string/accessibility_recent"
/>
<!-- comment out (3)
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="invisible"
/>
-->
</LinearLayout>
・・・
<View android:id="@+id/deadzone"
android:layout_height="@dimen/navigation_bar_deadzone_size"
android:layout_width="match_parent"
android:layout_gravity="top"
android:clickable="true"
/>
</FrameLayout>
<FrameLayout android:id="@+id/rot90"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"
android:paddingTop="0dp"
>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:clipChildren="false"
android:clipToPadding="false"
android:id="@+id/nav_buttons"
android:animateLayoutChanges="true"
>
<!-- navigation controls -->
<!-- changed 80dp to 72dp (2) -->
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/recent_apps"
android:layout_height="72dp"
android:layout_width="match_parent"
android:src="@drawable/ic_sysbar_recent_land"
android:layout_weight="0"
android:contentDescription="@string/accessibility_recent"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
/>
<!-- added (1) -->
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/expand"
android:layout_height="72dp"
android:layout_width="match_parent"
android:src="@drawable/ic_sysbar_expand_land"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
/>
<!-- comment out (3)
<View
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:visibility="invisible"
/>
-->
<!-- changed 80dp to 72dp (2) -->
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
android:layout_height="72dp"
android:layout_width="match_parent"
android:src="@drawable/ic_sysbar_home_land"
systemui:keyCode="3"
systemui:keyRepeat="false"
android:layout_weight="0"
android:contentDescription="@string/accessibility_home"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
/>
<!-- comment out (3)
<View
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:visibility="invisible"
/>
-->
<!-- changed 80dp to 72dp (2) -->
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/mymenu"
android:layout_height="72dp"
android:layout_width="match_parent"
android:src="@drawable/ic_sysbar_menu_land"
systemui:keyCode="82"
android:layout_weight="0"
android:contentDescription="@string/accessibility_menu"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
/>
<!-- comment out (3)
<View
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:visibility="invisible"
/>
-->
<!-- changed 80dp to 72dp (2) -->
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back"
android:layout_height="72dp"
android:layout_width="match_parent"
android:src="@drawable/ic_sysbar_back_land"
systemui:keyCode="4"
android:layout_weight="0"
android:contentDescription="@string/accessibility_back"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
/>
<!-- comment out (3)
<View
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:visibility="invisible"
/>
-->
</LinearLayout>