静音模式

这篇博客介绍了如何使用ContentResolver在Android中将Integer转换为String并存储,具体涉及Settings.Global.putInt方法,用于更新或创建设置值。内容包括方法的解释和用途,以及与ContentResolver相关的链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<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 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的相关链接

http://blog.csdn.net/cankingapp/article/details/7792999


1、现在globalaction里面更改

2、adapter notifyDataSetChanged



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值