导航栏添加按钮
来源:互联网 发布:linux添加用户密码 编辑:程序博客网 时间:2024/05/16 12:27
Platform: MTK
OS:安卓5.1
Kernel: 3.10.49
实现功能:1.导航栏添加声音图标(声音有两种状态,打开和关闭)
2.在打开状态下———点击———》图标会改变成关闭状态。
3.点击时同时会发送广播,通知应用。
com.android.open.sound
com.android.close.sound
文件修改:
xml布局文件:
--- a/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml+++ b/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml@@ -87,7 +87,22 @@+++ b/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml@@ -87,7 +87,22 @@ android:scaleType="center" android:visibility="gone" android:contentDescription="@string/accessibility_recent"+ />++ <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/sound"+ android:layout_width="@dimen/navigation_key_width"+ android:layout_height="match_parent"+ android:src="@drawable/ic_sysbar_sound"+ android:layout_weight="0"+ android:scaleType="center"+ android:contentDescription="@string/accessibility_sound"+ /> <FrameLayout android:layout_width="@dimen/navigation_side_padding" android:layout_height="match_parent"@@ -232,7 +247,22 @@ android:layout_width="match_parent" android:layout_weight="1" android:visibility="invisible"+ />+ + <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/sound"+ android:layout_height="@dimen/navigation_key_width"+ android:layout_width="match_parent"+ android:src="@drawable/ic_sysbar_sound_land"+ android:scaleType="center"+ android:layout_weight="0"+ android:contentDescription="@string/accessibility_sound" />+ <View + android:layout_height="match_parent"+ android:layout_width="match_parent"+ android:layout_weight="1"+ android:visibility="invisible"+ /> <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
--- a/frameworks/base/packages/SystemUI/res/layout-sw600dp/navigation_bar.xml+++ b/frameworks/base/packages/SystemUI/res/layout-sw600dp/navigation_bar.xml@@ -80,7 +80,15 @@ android:layout_weight="0" android:visibility="gone" android:contentDescription="@string/accessibility_recent"- />+ />+ <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/sound"+ android:layout_width="128dp" android:paddingStart="25dp" android:paddingEnd="25dp"+ android:layout_height="match_parent"+ android:src="@drawable/ic_sysbar_sound"+ android:scaleType="centerInside"+ android:layout_weight="0"+ android:contentDescription="@string/accessibility_sound"+ /> <Space android:layout_width="match_parent" android:layout_height="match_parent"@@ -226,7 +234,15 @@ android:layout_weight="0" android:visibility="gone" android:contentDescription="@string/accessibility_recent"- />+ />+ <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/sound"+ android:layout_width="162dp" android:paddingStart="42dp" android:paddingEnd="42dp"+ android:layout_height="match_parent"+ android:src="@drawable/ic_sysbar_sound"+ android:scaleType="centerInside"+ android:layout_weight="0"+ android:contentDescription="@string/accessibility_sound"+ /> <Space
--- a/frameworks/base/packages/SystemUI/res/values/strings.xml+++ b/frameworks/base/packages/SystemUI/res/values/strings.xml@@ -204,6 +204,8 @@ <string name="accessibility_menu">Menu</string> <!-- Content description of the recents button for accessibility (not shown on the screen). [CHAR LIMIT=NONE] --> <string name="accessibility_recent">Overview</string>+ <string name="accessibility_sound">Sound</string>+ <string name="accessibility_nosound">Nosound</string>
--- a/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml+++ b/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml@@ -85,6 +85,8 @@ <string name="accessibility_home" msgid="8217216074895377641">"主屏幕"</string> <string name="accessibility_menu" msgid="316839303324695949">"菜单"</string> <string name="accessibility_recent" msgid="5208608566793607626">"概览"</string>+ <string name="accessibility_sound" msgid="5208608566793607777">"打开声音"</string>+ <string name="accessibility_nosound" msgid="5208608566793607888">"关闭声音"</string>
java代码的修改:
--- 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@@ -45,6 +45,13 @@ import android.view.inputmethod.InputMethodManager; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout;+import android.content.BroadcastReceiver;+import android.widget.Toast; +import android.os.IBinder;+import android.media.AudioManager;+import android.media.MediaPlayer;+import android.content.Intent;+import android.content.IntentFilter; import com.android.systemui.R; import com.android.systemui.statusbar.BaseStatusBar;@@ -90,7 +97,7 @@ public class NavigationBarView extends LinearLayout { // performs manual animation in sync with layout transitions private final NavTransitionListener mTransitionListener = new NavTransitionListener();-+ AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); private OnVerticalChangedListener mOnVerticalChangedListener; private boolean mIsLayoutRtl; private boolean mDelegateIntercepted;@@ -255,6 +262,40 @@ public class NavigationBarView extends LinearLayout { return mCurrentView.findViewById(R.id.recent_apps); } + //add by zk+ public View getAddVolume(){ + + IntentFilter mfilter = new IntentFilter( );+ mfilter.addAction("com.android.open.audio");+ mfilter.addAction("com.android.close.audio");+ mContext.registerReceiver( mReceiver, mfilter );+ ++ ImageView mView = (ImageView)mCurrentView.findViewById(R.id.sound); + + + + return mView; + } + BroadcastReceiver mReceiver = new BroadcastReceiver( ) {//接收应用发送过来的广播,保存了关机前的状态。+ @Override+ public void onReceive( Context context, Intent intent ) {+ String action = intent.getAction( );+ Log.e(TAG, "action ======= " + action);+ ImageView mView = (ImageView)mCurrentView.findViewById(R.id.sound); + if(action.equals("com.android.open.audio"))+ {+ mView.setImageResource(R.drawable.ic_sysbar_sound); //显示打开音量图标 + }else if(action.equals("com.android.close.audio"))+ {+ mView.setImageResource(R.drawable.ic_sysbar_nosound);//显示关闭的图标+ }+ }+ };+ + + //end+ public View getMenuButton() { return mCurrentView.findViewById(R.id.menu); }@@ -369,6 +410,7 @@ public class NavigationBarView extends LinearLayout { getBackButton() .setVisibility(disableBack ? View.INVISIBLE : View.VISIBLE); getHomeButton() .setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE); getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE);+ getAddVolume().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE); getRecentsButton().setVisibility(View.GONE); mBarTransitions.applyBackButtonQuiescentAlpha(mBarTransitions.getMode(), true /*animate*/);@@ -477,7 +519,7 @@ public class NavigationBarView extends LinearLayout { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b);- mDelegateHelper.setInitialTouchRegion(getHomeButton(), getBackButton(), getRecentsButton());+ mDelegateHelper.setInitialTouchRegion(getHomeButton(), getBackButton(), getRecentsButton(),getAddVolume()); } @Override@@ -650,7 +692,7 @@ public class NavigationBarView extends LinearLayout { dumpButton(pw, "home", getHomeButton()); dumpButton(pw, "rcnt", getRecentsButton()); dumpButton(pw, "menu", getMenuButton());-+ dumpButton(pw, "menu", getAddVolume()); pw.println(" }");
--- 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@@ -184,6 +184,15 @@ import com.android.systemui.statusbar.stack.StackScrollAlgorithm; import com.android.systemui.statusbar.stack.StackScrollState.ViewState; import com.android.systemui.volume.VolumeComponent; +import android.media.AudioManager;+import android.media.MediaPlayer;+import android.content.Intent; +import android.app.Application;+import android.view.KeyCharacterMap;+import android.view.KeyCharacterMap.FallbackAction;+import android.view.KeyEvent;++ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList;@@ -211,7 +220,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, = "com.android.internal.policy.statusbar.START"; public static final boolean SHOW_LOCKSCREEN_MEDIA_ARTWORK = true;-+ + private static int sound_flag = 0; private static final int MSG_OPEN_NOTIFICATION_PANEL = 1000; private static final int MSG_CLOSE_PANELS = 1001; private static final int MSG_OPEN_SETTINGS_PANEL = 1002;@@ -643,7 +653,29 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, notifyUserAboutHiddenNotifications(); mScreenPinningRequest = new ScreenPinningRequest(mContext);+ //add by zk+ IntentFilter mfilter = new IntentFilter( );+ mfilter.addAction("com.android.open.audio");+ mfilter.addAction("com.android.close.audio");+ mContext.registerReceiver( mReceiver, mfilter );+ }+ BroadcastReceiver mReceiver = new BroadcastReceiver( ) {//接收应用发送过来的广播,保存的是关机之前的状态。+ @Override+ public void onReceive( Context context, Intent intent ) {+ String action = intent.getAction( );+ Log.e(TAG, "action ======= " + action);+ if(action.equals("com.android.open.audio"))+ {+ sound_flag = 1; + }else if(action.equals("com.android.close.audio"))+ {+ sound_flag = 0;+ }+ }+ };+ + boolean isMSim() { return (TelephonyManager.getDefault().getPhoneCount() > 1);@@ -1299,6 +1331,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, mNavigationBarView.getBackButton().setLongClickable(true); mNavigationBarView.getBackButton().setOnLongClickListener(mLongPressBackRecentsListener); mNavigationBarView.getHomeButton().setOnTouchListener(mHomeActionListener);+ mNavigationBarView.getAddVolume().setOnClickListener(mAddVolumeClickListener);//监听那个按键被按下。 mNavigationBarView.getRecentsButton().setVisibility(View.GONE); updateSearchPanel(); }@@ -2844,6 +2877,37 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, } checkBarModes(); }+ + private boolean flag=false; + private View.OnClickListener mAddVolumeClickListener = new View.OnClickListener() {+ @Override + public void onClick(View view) { + + + ImageView mView = (ImageView)view;+ + if(sound_flag == 0){//根据标志位判断显示的状态。+ //unmute+ Log.d(TAG, "sendBroadcast:com.android.open.sound");+ mView.setImageResource(R.drawable.ic_sysbar_sound);+ Intent intent = new Intent();+ intent.setAction("com.android.open.sound");//向应用发送广播。+ mContext.sendBroadcast(intent);+ sound_flag = 1;+ + + }else {+ //mute+ Log.d(TAG, "sendBroadcast:com.android.close.sound");+ mView.setImageResource(R.drawable.ic_sysbar_nosound); + Intent intent = new Intent();+ intent.setAction("com.android.close.sound");//向应用发送广播。+ mContext.sendBroadcast(intent);+ sound_flag = 0;+ }+ } + };
图片资源目录:
# frameworks/base/packages/SystemUI/res/drawable-hdpi/
# frameworks/base/packages/SystemUI/res/drawable-mdpi/
# frameworks/base/packages/SystemUI/res/drawable-xhdpi/
# frameworks/base/packages/SystemUI/res/drawable-xxhdpi
阅读全文
1 0
- 导航栏添加按钮
- ios导航栏添加多个按钮
- ios----导航栏添加多个按钮
- 导航栏添加左右按钮方法
- 在导航栏上添加按钮
- xamarin.iOS 导航栏添加按钮
- 创建按钮 ,添加到导航栏
- 为导航条添加按钮
- ios导航条添加按钮
- ios导航条添加按钮
- iOS添加左右导航按钮
- IOS开发(10)UIBarButtonItem导航栏添加按钮
- Android SystemUI在导航栏添加音量加减按钮
- iOS在控制器导航栏右上角添加按钮
- iOS中为导航栏的右上方添加各种按钮
- (iOS开发)导航栏navigationBar中间添加按钮
- 2016.11.23添加自定义导航栏左按钮
- iOS在控制器导航栏右上角添加按钮
- Ubuntu16.04安装搜狗输入法+无法输入中文解决
- Base64图片编码
- yum安装lnmp-redis
- 学习java第11天
- HBase(2.5)-LSM树(基于日志结构的合并树)
- 导航栏添加按钮
- 决策树ID3
- Menu菜单(常用型)
- linux Oracle 定时自动备份
- 请别把加班说的那么“高大上”
- 为什么Floyd算法中k必须放在最外层
- jdk中栈的实现
- 基于SNMP的网络管理软件设计方案和实现
- CentOS7 Failed to start LSB: Bring up/down解决方法