admin管理员组

文章数量:1516870

静音模式

<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;}@Overridepublic 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 handleritemView.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);}}


.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 17

Convenience 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

contentresolver的相关链接



1、现在globalaction里面更改

2、adapter notifyDataSetChanged



本文标签: 静音模式