mt6735 如何在状态栏添加一 个general和outdoor对应的图标
时间:10-02
整理:3721RD
点击:
[DESCRIPTION]
目前我们在状态栏上,默认的行为是只有meeting和silent才有图标,但general和outdoor没有。 如何添加?
[SOLUTION]
在PhoneStatusBarPolicy.java中修改如下:
1. 引入文件
import com.mediatek.audioprofile.AudioProfileManager;
import com.mediatek.audioprofile.AudioProfileManager.Scenario;
import com.mediatek.common.audioprofile.AudioProfileListener;
2. 添加定义
private AudioProfileManager mProfileManager;
3. 在PhoneStatusBarPolicy的定义中
(1) 赋值和创建监听
mProfileManager = (AudioProfileManager) context.getSystEMService(Context.AUDIOPROFILE_SERVICE);
mProfileManager.listenAudioProfie(mAudioProfileListener,
AudioProfileListener.LISTEN_AUDIOPROFILE_CHANGEG);
(2) 将
mService.setIconVisibility("volume", false);
updateVolume();
修改为:
mService.setIconVisibility("volume", true);
// updateVolume();
updateIcon(null);
4.在 mIntentReceiver 中修改:
/* else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
updateVolume();
}*/
即,将其注释掉
5. 新增加函数mAudioProfileListener和updateIcon, 如下:
private AudioProfileListener mAudioProfileListener = new AudioProfileListener() {
@Override
public void onAudioProfileChanged(String profileKey) {
updateIcon(profileKey);
}
};
private final void updateIcon(String profileKey){
final int iconId;
String contentDescription = null;
Scenario activeScenario = Scenario.GENERAL;
if (profileKey != null) {
activeScenario = mProfileManager.getScenario(profileKey);
}
if(activeScenario == Scenario.GENERAL){
iconId = R.drawable.stat_sys_ringer_general;
contentDescription = mContext.getString(R.string.accessibility_ringer_general);
}else if(activeScenario == Scenario.SILENT){
iconId = R.drawable.stat_sys_ringer_silent;
contentDescription = mContext.getString(R.string.accessibility_ringer_silent);
}else if(activeScenario == Scenario.MEETING){
iconId = R.drawable.stat_sys_ringer_vibrate;
contentDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
}else{ //activeScenario == Scenario.OUTDOOR
iconId = R.drawable.stat_sys_ringer_outdoor;
contentDescription = mContext.getString(R.string.accessibility_ringer_outdoor);
}
mService.setIcon("volume", iconId, 0, contentDescription);
Log.v(TAG, "updateIcon setIcon, contentDescription = " + contentDescription);
}
其中R.drawable.stat_sys_ringer_general、R.drawable.stat_sys_ringer_outdoor、
R.string.accessibility_ringer_general、R.string.accessibility_ringer_outdoor,由客户自行添加资源
目前我们在状态栏上,默认的行为是只有meeting和silent才有图标,但general和outdoor没有。 如何添加?
[SOLUTION]
在PhoneStatusBarPolicy.java中修改如下:
1. 引入文件
import com.mediatek.audioprofile.AudioProfileManager;
import com.mediatek.audioprofile.AudioProfileManager.Scenario;
import com.mediatek.common.audioprofile.AudioProfileListener;
2. 添加定义
private AudioProfileManager mProfileManager;
3. 在PhoneStatusBarPolicy的定义中
(1) 赋值和创建监听
mProfileManager = (AudioProfileManager) context.getSystEMService(Context.AUDIOPROFILE_SERVICE);
mProfileManager.listenAudioProfie(mAudioProfileListener,
AudioProfileListener.LISTEN_AUDIOPROFILE_CHANGEG);
(2) 将
mService.setIconVisibility("volume", false);
updateVolume();
修改为:
mService.setIconVisibility("volume", true);
// updateVolume();
updateIcon(null);
4.在 mIntentReceiver 中修改:
/* else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
updateVolume();
}*/
即,将其注释掉
5. 新增加函数mAudioProfileListener和updateIcon, 如下:
private AudioProfileListener mAudioProfileListener = new AudioProfileListener() {
@Override
public void onAudioProfileChanged(String profileKey) {
updateIcon(profileKey);
}
};
private final void updateIcon(String profileKey){
final int iconId;
String contentDescription = null;
Scenario activeScenario = Scenario.GENERAL;
if (profileKey != null) {
activeScenario = mProfileManager.getScenario(profileKey);
}
if(activeScenario == Scenario.GENERAL){
iconId = R.drawable.stat_sys_ringer_general;
contentDescription = mContext.getString(R.string.accessibility_ringer_general);
}else if(activeScenario == Scenario.SILENT){
iconId = R.drawable.stat_sys_ringer_silent;
contentDescription = mContext.getString(R.string.accessibility_ringer_silent);
}else if(activeScenario == Scenario.MEETING){
iconId = R.drawable.stat_sys_ringer_vibrate;
contentDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
}else{ //activeScenario == Scenario.OUTDOOR
iconId = R.drawable.stat_sys_ringer_outdoor;
contentDescription = mContext.getString(R.string.accessibility_ringer_outdoor);
}
mService.setIcon("volume", iconId, 0, contentDescription);
Log.v(TAG, "updateIcon setIcon, contentDescription = " + contentDescription);
}
其中R.drawable.stat_sys_ringer_general、R.drawable.stat_sys_ringer_outdoor、
R.string.accessibility_ringer_general、R.string.accessibility_ringer_outdoor,由客户自行添加资源