静音模式
2016-03-05 11:14
417 查看
<p> </p><p>GlobalAction.java内静音模式 </p> private final class SilentModeTriStateAction implements Action, View.OnClickListener { private final int[] ITEM_IDS = { R.id.option1, R.id.option2, R.id.option3, R.id.option4 }; private final AudioManager mAudioManager; private final Handler mHandler; private final Context mContext; SilentModeTriStateAction(Context context, AudioManager audioManager, Handler handler) { mAudioManager = audioManager; mHandler = handler; mContext = context; } private int indexToRingerMode(int index) { if (index == 2) { if (mHasVibrator) { return AudioManager.RINGER_MODE_VIBRATE; } else { return AudioManager.RINGER_MODE_NORMAL; } } return AudioManager.RINGER_MODE_NORMAL; } @Override public CharSequence getLabelForAccessibility(Context context) { return null; } public View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater) { View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false); int ringerMode = mAudioManager.getRingerModeInternal(); int zenMode = Global.getInt(mContext.getContentResolver(), Global.ZEN_MODE, Global.ZEN_MODE_OFF); int selectedIndex = 0; if (zenMode != Global.ZEN_MODE_OFF) { if (zenMode == Global.ZEN_MODE_NO_INTERRUPTIONS) { selectedIndex = 0; } else if (zenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) { selectedIndex = 1; } } else if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) { selectedIndex = 2; } else if (ringerMode == AudioManager.RINGER_MODE_NORMAL) { selectedIndex = 3; } for (int i = 0; i < ITEM_IDS.length; i++) { View itemView = v.findViewById(ITEM_IDS[i]); if (!mHasVibrator && i == 2) { itemView.setVisibility(View.GONE); continue; } itemView.setSelected(selectedIndex == i); // Set up click handler itemView.setTag(i); itemView.setOnClickListener(this); } return v; } public void onPress() { } public boolean showDuringKeyguard() { return true; } public boolean showBeforeProvisioning() { return false; } public boolean isEnabled() { return true; } void willCreate() { } public void onClick(View v) { if (!(v.getTag() instanceof Integer)) return; int index = (Integer) v.getTag(); if (index == 0 || index == 1) { int zenMode = index == 0 ? Global.ZEN_MODE_NO_INTERRUPTIONS//这不就是我苦思冥想找了半天的打扰模式么!!! : Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; Global.putInt(mContext.getContentResolver(), Global.ZEN_MODE, zenMode); } else { Global.putInt(mContext.getContentResolver(), Global.ZEN_MODE, Global.ZEN_MODE_OFF); } if (index == 2 || index == 3) { int ringerMode = indexToRingerMode(index); mAudioManager.setRingerModeInternal(ringerMode); } mAdapter.notifyDataSetChanged();//import android.widget.BaseAdapter;里面刷新 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY); } }
http://developer.android.com/intl/zh-cn/reference/android/provider/Settings.Global.html#putInt(android.content.ContentResolver, java.lang.String, int)
把Integer存储为String
public static boolean putInt (ContentResolver cr, String name,
int value)
Added in API level 17Convenience function for updating a single settings value as an integer. This will either create a new entry in the table if the given name does not exist, or modify the value of the existing row with that name.
Note that internally setting values are always stored as strings, so this function converts the given value to a string before storing it.
Parameters | |
---|---|
cr | ContentResolver: The ContentResolver to access. |
name | String: The name of the setting to modify. |
value | int: The new value for the setting. |
Returns | |
---|---|
boolean | true if the value was set, false on database errors |
http://blog.csdn.net/cankingapp/article/details/7792999
1、现在globalaction里面更改
2、adapter notifyDataSetChanged
相关文章推荐
- VCC/AVCC/VDD/AVDD区别
- Firefox禁缓存
- U-boot分析与移植(3)----U-boot stage2分析
- Xcode常用的快捷键
- 第12期 花飞蝶舞惊蛰 3月刊
- Utf8,Unicode,多字节等一些字符集的处理函数
- 软件工程导论第一周作业(你认为一些军事方面的软件系统采用什么样的开发模型比较合适?)
- 第0周学习资源阅读感悟
- 【Android】19.1 SharedPreferences类
- linux下umask详解
- mysql 主从问题集锦
- 大学毕业4年-回顾和总结(1)-钱,金钱观
- 大学毕业4年-回顾和总结(1)-钱,金钱观
- 欢迎使用CSDN-markdown编辑器
- spark streaming插入hbase
- leetcode122 Best Time to Buy and Sell Stock II
- 套期保值
- windows安装redis缓存使用图文教程
- 大学毕业4年-回顾和总结(1)-钱,金钱观
- 31. Next Permutation