• 魅情景


      魅情景提供4种常用的情景模式(“响铃”、“震动”、“震动和响铃”、“静音”),三阶亮度调节分别对应户外,室内,夜晚的亮度(可长按进入设置亮度)。软件占用资源极小,为魅族用户提供一些便利操作(魅族的机器自动亮度的时候也可以调节亮度的)。  

      如果你是使用本软件觉得还可以的话,希望给个好评~

      软件下载地址:http://app.meizu.com/phone/appsbyid/827024

      以下是一些简要说明及源代码,如果有不好的地方,希望指正

    0.软件效果

    第一个为M9效果,后面为MX效果,自动适配当前机器所使用的语言

        

    1.环境:

      终于知道为什么官网会给出M9的sdk了,原来真的不一样,第一次发布的时候以为2.3手机实测过了,模拟器都过了就没事了,后来发现在M9上的显示很不满意,不过通过查阅一些网上资料,解决了适配问题——activity的多个主题的实现。

      其实如果你有android开发环境,只用将下载的M9SDK_windows_1.0.zip中platforms目录下android-2.3.1放到自己配置环境的platforms目录下,重启就能搜到了,不要更新。

      某些用户按官方说明最后出来的模拟器可能是官方的2.3版本,其实只要重新将android-2.3.1拷贝过来倒platforms目录即可。

    2.使用方法:

      “响铃”表示响铃并且不震动
      “震动”表示不响铃,只有震动
      “静音”表示不响铃也不震动
      “响震”表示响铃并且震动

      红色表示当前状态(仅第一次的时候“响震”的状态会识别为“响铃”,其他应该没问题),蓝色表示当前所选择,用于提示所选中的项目。
      以上修改点确定更改生效,取消则无效

      有“室外”“室内”“夜晚”三个档,亮度由亮到暗
      亮度单击即可切换,长按亮度进入设置,并更改为选中档的亮度值

      进入设置界面的时候,进度条所显示的亮度为选中档的亮度,返回则表示不保存,确定表示保存。
      亮度小于80之后没什么实用价值,故最小亮度定义为80。

    3.解决的问题:

      情景模式:对手机的震动响铃的检测及修改

      亮度调节:对亮度的调节,及自动亮度调节的修改

      存储用户设置

      多适配:activity的Dialog和Transparent同时实现,让M9不再难看。自动适配本地语言

    4.代码实现:

     

    显示Activity部分

    ContextualModelActivity.java显示第一个Dialog化的Activity

    ContextualModelActivity.java
    package meizu.activity;
    
    import meizu.phone.R;
    import meizu.server.SaveUserInfo;
    import meizu.server.SetLight;
    import meizu.server.SetModel;
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.graphics.Color;
    import android.media.AudioManager;
    import android.os.Bundle;
    import android.view.ContextMenu;
    import android.view.ContextMenu.ContextMenuInfo;
    import android.view.View;
    import android.view.Window;
    import android.widget.TextView;
    
    public class ContextualModelActivity extends Activity implements View.OnClickListener{
        //情景模式
        private TextView ring =null;
        private TextView vibrate = null;
        private TextView silent = null;
        private TextView both = null;
        //亮度调节
        private TextView outside = null;
        private TextView inside = null;
        private TextView night = null;
        
        //控制
        private TextView mksur = null;
        private TextView quit = null;
        
        //确定是否是震动+响铃,1表示是
        private static int FLAG = 0;
        //当前模式及点击位置
        private static int MODEL = 0;
        private static int INDEX = 0;
        //显示的是第几档亮度的R.id.*的值
        private static int BRIGHTNESS = 0;
        //默认初始值,仅第一次有用
        private static int LOW =130;
        private static int MIDDLE = 200;
        private static int HIGH = 255;
        
        public SharedPreferences sp = null;
        
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
         //取消标题栏  
            this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
          //只能被被本程序读写,前面的字符串是一个xml文件,系统自动帮我们加上.xml
            sp = this.getSharedPreferences("userinfo", Context.MODE_PRIVATE);
            setContentView(R.layout.main);        
            initFindById();
            showNowChoice();
            
        }
        /**
         * 显示现在正在用的模式
         */
        public void showNowChoice()
        {
            AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            TextView cpy = null;
            FLAG = sp.getInt("FLAG", 0);
            switch(audio.getRingerMode()+FLAG){
                case  AudioManager.RINGER_MODE_NORMAL:
                    INDEX = R.id.ring;
                    cpy = ring;
                    break;
                case AudioManager.RINGER_MODE_VIBRATE:
                    INDEX = R.id.vibrate;
                    cpy = vibrate;
                    break;
                case AudioManager.RINGER_MODE_SILENT:
                    INDEX = R.id.silent;
                    cpy = silent;
                    break;
                default:
                    INDEX = R.id.both;
                    cpy = both;
            }
            cpy.setBackgroundColor(Color.RED);
            cpy=null;
            
            BRIGHTNESS = sp.getInt("brightness", 0);
            if(BRIGHTNESS != 0)
            {
                TextView tmp = (TextView)findViewById(BRIGHTNESS);
                tmp.setBackgroundColor(android.graphics.Color.parseColor(this.getString(R.string.click_color)));
            }
        }
        /**
         * 分别找到自己的id,并且添加监听器
         */
        public void initFindById()
        {
            ring = (TextView)findViewById(R.id.ring);
            ring.setOnClickListener(this);
            vibrate = (TextView)findViewById(R.id.vibrate);
            vibrate.setOnClickListener(this);
            silent = (TextView)findViewById(R.id.silent);
            silent.setOnClickListener(this);
            both = (TextView)findViewById(R.id.both);
            both.setOnClickListener(this);
            
            outside = (TextView)findViewById(R.id.outside);
            outside.setOnClickListener(this);
            outside.setBackgroundColor(android.graphics.Color.parseColor(this.getString(R.string.outside_color)));
            registerForContextMenu(outside);
            inside = (TextView)findViewById(R.id.inside);
            inside.setOnClickListener(this);
            inside.setBackgroundColor(android.graphics.Color.parseColor(this.getString(R.string.inside_color)));
            registerForContextMenu(inside);
            night = (TextView)findViewById(R.id.night);
            night.setOnClickListener(this);
            night.setBackgroundColor(android.graphics.Color.parseColor(this.getString(R.string.night_color)));
            registerForContextMenu(night);
            
            mksur=(TextView)findViewById(R.id.mksur);
            mksur.setOnClickListener(this);
            quit = (TextView)findViewById(R.id.quit);
            quit.setOnClickListener(this);
        }
        /**
         * 为亮度调节设置长按事件
         */
        public void onCreateContextMenu(ContextMenu menu, View v,  
                ContextMenuInfo menuInfo) {   
            int ID = v.getId();
            BRIGHTNESS = ID;
            changeBrightness();
            Intent intent = new Intent();
            String tmp = "";
            if(ID == R.id.outside)
                tmp = "HIGH";
            else if(ID == R.id.inside)
                tmp = "MIDDLE";
            else
                tmp = "LOW";
            
            intent.putExtra("ID", tmp);
            intent.setClass(ContextualModelActivity.this, SetNum.class);
            ContextualModelActivity.this.startActivity(intent);
        } 
        /**
         * 监听器
         */
        @Override
        public void onClick(View v) {
            AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            int checkedId = v.getId();
            if(checkedId!=R.id.mksur && checkedId != R.id.quit)
            {
                if(checkedId != R.id.outside && checkedId !=R.id.inside && checkedId != R.id.night)
                    clickModel(checkedId);
                else
                    clickLight(checkedId);
            }
            else if(checkedId == R.id.mksur)
            {
                FLAG = 0;
                switch(MODEL)
                {
                    case R.id.ring:
                        SetModel.changRing(audio);
                        break;
                    case R.id.vibrate:
                        SetModel.changVibrate(audio);
                        break;
                    case R.id.silent:
                        SetModel.changeSilent(audio);
                        break;
                    default:
                        SetModel.changeBoth(audio);
                        FLAG = 1;
                }    
                meizu.server.SaveUserInfo.saveFLAG(sp, FLAG);
                finish();
            }
            else
            {
                finish();
            }
        }
        /**
         * 选中模式
         * @param checkedId
         */
        private void clickModel(int checkedId)
        {
            if(MODEL == 0)
            {
                MODEL = checkedId;
            }
            if(MODEL!=0)//此时MODEL为上次点击的值
            {
                TextView tmp = (TextView)findViewById(MODEL);
                //如果离开的不是当前情景模式(红色),则离开后无色,否则,恢复红色
                if(MODEL != INDEX)
                    tmp.setBackgroundColor(0);
                else
                    tmp.setBackgroundColor(Color.RED);
                tmp = (TextView)findViewById(checkedId);
                tmp.setBackgroundColor(Color.BLUE);
                MODEL = checkedId;
            }
        }
        /**
         * 选中亮度
         * @param checkedId
         */
        private void clickLight(int checkedId)
        {
            BRIGHTNESS = checkedId;
            TextView tmp = (TextView)findViewById(checkedId);
            initClick();
            tmp.setBackgroundColor(android.graphics.Color.parseColor(this.getString(R.string.click_color)));
            changeBrightness();
        }
        /**
         * 亮度改变
         */
        public void changeBrightness()
        {
            //亮度调节
            int level ;
            switch(BRIGHTNESS)
            {
                case R.id.outside:
                    if(sp.getInt("HIGH", 0) != 0) HIGH = sp.getInt("HIGH", 0);
                    level = HIGH;
                    break;
                case R.id.inside:
                    if(sp.getInt("MIDDLE", 0) != 0) MIDDLE = sp.getInt("MIDDLE", 0);
                    level = MIDDLE;
                    break;
                default:
                    if(sp.getInt("LOW", 0) != 0) LOW = sp.getInt("LOW", 0);
                    level = LOW;
            }
            SetLight.setLevelBrightness(this, sp, level, sp.getInt("auto", 0));
            SaveUserInfo.saveBRIGHTNESS(sp, BRIGHTNESS);
            //保存调节后的值
            BRIGHTNESS = sp.getInt("brightness", 0);
            if(BRIGHTNESS != 0)
            {
                initClick();
                TextView tmp = (TextView)findViewById(BRIGHTNESS);
                tmp.setBackgroundColor(android.graphics.Color.parseColor(this.getString(R.string.click_color)));
            }
        }
        /**
         * 亮度三级模式初始化
         */
        public void initClick()
        {
            outside.setBackgroundColor(android.graphics.Color.parseColor(this.getString(R.string.outside_color)));
            inside.setBackgroundColor(android.graphics.Color.parseColor(this.getString(R.string.inside_color)));
            night.setBackgroundColor(android.graphics.Color.parseColor(this.getString(R.string.night_color)));
        }
    }

     SetNum.java设置亮度部分

    SetNum.java
    package meizu.activity;
    
    import meizu.phone.R;
    import meizu.server.ChangeTextColor;
    import meizu.server.SaveUserInfo;
    import meizu.server.SetLight;
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.view.View;
    import android.view.Window;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.CompoundButton;
    import android.widget.SeekBar;
    import android.widget.SeekBar.OnSeekBarChangeListener;
    import android.widget.TextView;
    
    public class SetNum extends Activity implements View.OnClickListener, CheckBox.OnCheckedChangeListener{
        
        private SharedPreferences sp = null;
        
        private TextView wordShow = null;
        private CheckBox checkBox = null;
        private SeekBar seekBar = null;
        private Button mksur = null;
        private Button change = null;
        
        private String ID = null;
        //亮度值
        private int BRIGHTNESS = 0;
        private int AUTO = 0;
        private int ENUM = 0;
            
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            this.requestWindowFeature(Window.FEATURE_NO_TITLE);
            sp = this.getSharedPreferences("userinfo", Context.MODE_PRIVATE);
            setContentView(R.layout.setting);
            
            Intent intent = getIntent();
            ID = intent.getStringExtra("ID");
            
            initFindViewById();
            //先给个背景
            changeColor();
        }
        /**
         * onPause时候结束,并且恢复调试前状态
         * 按home键或者其他中断事务
         */
        protected void onPause(){
            super.onResume();
            SetLight.setBrightness(this, BRIGHTNESS);
            SetLight.saveBrightness(getContentResolver(), BRIGHTNESS);
            seekBar.setProgress(BRIGHTNESS);
            SetLight.setBackAuto(this, sp);
        }
        /**
         * 找各自的ID并且加上触发器
         */
        private void initFindViewById() {
            // TODO Auto-generated method stub
            wordShow = (TextView)findViewById(R.id.wordshow);
            wordShow.setOnClickListener(this);
            checkBox = (CheckBox)findViewById(R.id.checkbox);
            AUTO = sp.getInt("auto", 0);
            if(AUTO == 1) checkBox.setChecked(true) ;
            else checkBox.setChecked(false);
            checkBox.setOnCheckedChangeListener(this);
            seekBar = (SeekBar)findViewById(R.id.seekbar);
            changeBySeekBar();
            mksur = (Button)findViewById(R.id.sure);
            mksur.setOnClickListener(this);
            change = (Button)findViewById(R.id.change);
            change.setOnClickListener(this);
        }
        /**
         * seekBar 触发功能
         */
        private void changeBySeekBar()
        {
            // 进度条绑定最大亮度,255是最大亮度
                    seekBar.setMax(255);
                    // 取得当前亮度
                    int normal = SetLight.getScreenBrightness(this);
                    BRIGHTNESS = normal;
                    // 进度条绑定当前亮度
                    if(normal<80)        normal=80;
                    seekBar.setProgress(normal);
                    seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
    
                        public void onStopTrackingTouch(SeekBar seekBar) {
                            // 取得当前进度
                            int tmp = seekBar.getProgress();
                            //小于80时候回到80
                            if(tmp<80)        tmp=80;
                            seekBar.setProgress(tmp);
                            if(SetLight.isAutoBrightness(getContentResolver()))
                            {
                                SetLight.stopAutoBrightness(SetNum.this);
                            }
                            SetLight.setBrightness(SetNum.this, tmp);
                            //不保存亮度的话,勾选自动亮度调节,默认的亮度为当前亮度,而不是本activity的亮度
                            SetLight.saveBrightness(getContentResolver(), tmp);
                            if(AUTO == 1)
                                SetLight.startAutoBrightness(SetNum.this);
    //                        SetLight.setLevelBrightness(SetNum.this, sp, tmp, AUTO);
                        }
    
                        public void onStartTrackingTouch(SeekBar seekBar) {
                            // TODO Auto-generated method stub
                        }
    
                        public void onProgressChanged(SeekBar seekBar, int progress,
                                boolean fromUser) {
                            // TODO Auto-generated method stub
                        }
                    });
        }
        /**
         * 确定和点一下的触发
         */
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            int chechId = v.getId();
            if(chechId == R.id.sure)
            {
                BRIGHTNESS = SetLight.getScreenBrightness(this);
                SaveUserInfo.saveInfo(sp, BRIGHTNESS, ID, AUTO);
                SetLight.saveBrightness(getContentResolver(), BRIGHTNESS);
                finish();
            }
            else if(chechId == R.id.change)
            {
                changeColor();
            }
            
        }        
        /**
         *checkbox 选中触发
         */
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if(checkBox.isChecked())
            {
                AUTO = 1;
                if(!SetLight.isAutoBrightness(getContentResolver()))
                    SetLight.startAutoBrightness(this);
            }
            else
            {
                AUTO = 0;
                if(SetLight.isAutoBrightness(getContentResolver()))
                    SetLight.stopAutoBrightness(this);
            }
        }
        /**
         * 改变颜色及背景
         */
        private void changeColor() {
            // TODO Auto-generated method stub
            ChangeTextColor ctc = new ChangeTextColor();
            ChangeTextColor.Couple[] couple = null;
            couple = ctc.initCouple();
            wordShow.setTextColor(couple[ENUM].getText());
            wordShow.setBackgroundColor(couple[ENUM].getBackground());
            ENUM = (ENUM+1)%(ctc.getN());
        }
    }

    接下来是控制层

    ChangeTextColor.java作用是显示出不同的文字情景,用于方便使用者将亮度调节至合适

    ChangeTextColor.java
    package meizu.server;
    
    import android.graphics.Color;
    
    public class ChangeTextColor {
        
        private final int N = 2;
        private Couple[] couple = new Couple[N];
        
        public ChangeTextColor() {
            super();
            // TODO Auto-generated constructor stub
        }
        
        public int getN() {
            return N;
        }
    
    
        public  Couple[] initCouple ()
        {
            //白底灰字
            couple[0] = new Couple(Color.GRAY,Color.WHITE);
            //黑底灰字
            couple[1] = new Couple(Color.GRAY,Color.BLACK);
            return couple;
        }
    
        public class Couple
        {
            private int text = 0;
            private int background = 0;
            public Couple() {
                super();
                // TODO Auto-generated constructor stub
            }
            public Couple(int text, int background) {
                super();
                this.text = text;
                this.background = background;
            }
            public int getText() {
                return text;
            }
            public void setText(int text) {
                this.text = text;
            }
            public int getBackground() {
                return background;
            }
            public void setBackground(int background) {
                this.background = background;
            }
            
        }
    }    

    SaveUserInfo.java的用处是用SharedPreferences存储用户消息

    SaveUserInfo.java
    package meizu.server;
    
    import android.content.SharedPreferences;
    import android.content.SharedPreferences.Editor;
    
    public class SaveUserInfo {
        
        public SaveUserInfo() {
            super();
            // TODO Auto-generated constructor stub\
        }
    
        /**
         * FLAG=1表示响铃并且震动
         * FLAG=0表示只有响铃并且震动的模式
         * @param sp
         * @param FLAG
         */
        public static void saveFLAG(SharedPreferences sp, int FLAG)
        {
                Editor editor = sp.edit();
                editor.putInt("FLAG", FLAG);
                editor.commit();
        }
        
        /**
         * 显示的是第几档亮度的R.id.*的值,用于下次程序运行时候显示
         * @param sp
         * @param BRIGHTNESS
         */
        public static void saveBRIGHTNESS(SharedPreferences sp, int BRIGHTNESS) {
            Editor editor = sp.edit();
            editor.putInt("brightness", BRIGHTNESS);
            editor.commit();
        }
        /**
         * 存储亮度的值,调整的档的名称及是否开启自动
         * @param sp
         * @param brightness
         * @param ID
         * @param AUTO
         */
        public static void saveInfo(SharedPreferences sp, int brightness, String ID, int AUTO) {
            // TODO Auto-generated method stub
            Editor editor = sp.edit();
            //更新相应亮度档次的值
            editor.putInt(ID, brightness);
            //改变亮度之后是否启用亮度自动调整:1表示是自动,0表示关闭自动
            editor.putInt("auto", AUTO);
            editor.commit();
        }
    }

    SetLight.java用于调节亮度和控制自动亮度调节

    SetLight.java
    package meizu.server;
    
    import android.app.Activity;
    import android.content.ContentResolver;
    import android.content.SharedPreferences;
    import android.net.Uri;
    import android.provider.Settings;
    import android.provider.Settings.SettingNotFoundException;
    import android.view.WindowManager;
    
    public class SetLight {
        
        public SetLight() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * 判断是否开启了自动亮度调节
         */
        public static boolean isAutoBrightness(ContentResolver aContentResolver) {
                boolean automicBrightness = false;
                try {
                    automicBrightness = Settings.System.getInt(aContentResolver,
                            Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
                } catch (SettingNotFoundException e) {
                e.printStackTrace();
            }
            return automicBrightness;
        }
        
        /**
         * 获取屏幕的亮度
         */
        public static int getScreenBrightness(Activity activity) {
            int nowBrightnessValue = 0;
            ContentResolver resolver = activity.getContentResolver();
            try {
                nowBrightnessValue = android.provider.Settings.System.getInt(
                        resolver, Settings.System.SCREEN_BRIGHTNESS);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return nowBrightnessValue;
        }
        
        /**
         * 设置亮度
         */
        public static void setBrightness(Activity activity, int brightness) {
            WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
            lp.screenBrightness = Float.valueOf(brightness) * (1f / 255f);
            activity.getWindow().setAttributes(lp);
         
        }
        
        /**
         * 停止自动亮度调节
         */
        public static void stopAutoBrightness(Activity activity) {
            Settings.System.putInt(activity.getContentResolver(),
                    Settings.System.SCREEN_BRIGHTNESS_MODE,
                    Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
        }
        
        /**
         * 开启亮度自动调节
         * 
         * @param activity
         */
        public static void startAutoBrightness(Activity activity) {
            Settings.System.putInt(activity.getContentResolver(),
                    Settings.System.SCREEN_BRIGHTNESS_MODE,
                    Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
        }
        
        /**
         * 保存亮度设置状态
         */
        public static void saveBrightness(ContentResolver resolver, int brightness) {
            Uri uri = android.provider.Settings.System
                    .getUriFor("screen_brightness");
            android.provider.Settings.System.putInt(resolver, "screen_brightness",
                    brightness);
            // resolver.registerContentObserver(uri, true, myContentObserver);
            resolver.notifyChange(uri, null);
        }
        /**
         * 设置成相应的亮度
         */
        public static void setLevelBrightness(Activity activity, SharedPreferences sp, int level, int auto) {
            // TODO Auto-generated method stub
            if(isAutoBrightness(activity.getContentResolver()))
            {
                stopAutoBrightness(activity);
            }
            setBrightness(activity, level);
            saveBrightness(activity.getContentResolver(), level);
            if(auto == 1)
                startAutoBrightness(activity);
        }
        
        public static void setBackAuto(Activity activity, SharedPreferences sp)
        {
            int auto = sp.getInt("auto", 0);
            if(auto == 1)
            {
                if(!isAutoBrightness(activity.getContentResolver()))
                    startAutoBrightness(activity);
            }
            else
            {
                if(isAutoBrightness(activity.getContentResolver()))
                    stopAutoBrightness(activity);
            }
        }
    }

    SetModel.java用于控制情景模式中的响铃和震动

    SetModel.java
    package meizu.server;
    
    import android.media.AudioManager;
    
    public class SetModel {
    
        public SetModel() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        //开铃声
        public static void changRing(AudioManager audio) {
            // TODO Auto-generated method stub
            audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
            audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
        }
        //开震动
        public static void changVibrate(AudioManager audio) {
            // TODO Auto-generated method stub
            audio.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
            audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
            audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
        }
        //关铃声
        public static void changeSilent(AudioManager audio) {
            // TODO Auto-generated method stub
            audio.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
            audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
        }
        //双开
        public static void changeBoth(AudioManager audio) {
            // TODO Auto-generated method stub
            audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
            audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
        }
    }

    以下是一些配置文件

    AndroidManifest.xml需要一些控制权限

    AndroidManifest.xml
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="meizu.phone"
        android:versionCode="1"
        android:versionName="1.0" >
    
    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.CHANGE_CONFIGURATION"></uses-permission>    
    <uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission> 
    <uses-permission android:name="android.permission.VIBRATE" ></uses-permission>
        <application
            android:icon="@drawable/eye_106">
            <activity
                android:name="meizu.activity.ContextualModelActivity"
                android:label="@string/app_name" 
                android:theme="@style/Theme.Transparent"
                >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name="meizu.activity.SetNum"
                android:label="@string/app_name" 
                >
            </activity>
        </application>
    
    </manifest>

    layout中的配置

    main.xml:是ContextualModelActivity.java的布局

    main.xml
    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        android:paddingTop="10dip"
        android:paddingBottom="10dip"
        >
    
       <TableRow >
           <TextView 
               android:id="@+id/ring"
               android:layout_weight="1"
               android:text="@string/ring"
               android:gravity="center"
               android:textSize="22dip"
               android:paddingRight="20dip"
               android:paddingLeft="20dip"
               android:textColor="#C0C0C0"
               ></TextView>
           <TextView 
               android:id="@+id/vibrate"
               android:layout_weight="1"
               android:text="@string/vibrate"
               android:gravity="center"
               android:textSize="22dip"
               android:paddingRight="20dip"
               android:paddingLeft="20dip"
               android:textColor="#C0C0C0"
               ></TextView>
               <TextView 
               android:id="@+id/outside"
               android:layout_weight="1"
               android:text="@string/outside"
               android:gravity="center"
               android:textSize="22dip"
               android:paddingRight="20dip"
               android:paddingLeft="20dip"
               android:textColor="#C0C0C0"
               ></TextView>
       </TableRow>
       <TableRow >
               <TextView 
                   android:id="@+id/silent"
                   android:layout_weight="1"
                   android:text="@string/silent"
                android:gravity="center"
               android:textSize="22dip"
               android:paddingRight="20dip"
               android:paddingLeft="20dip"
               android:textColor="#C0C0C0"
                   ></TextView>
               <TextView 
                   android:id="@+id/both"
                   android:layout_weight="1"
                   android:text="@string/both"
                android:gravity="center"
               android:textSize="22dip"
               android:paddingRight="20dip"
               android:paddingLeft="20dip"
               android:textColor="#C0C0C0"
                   ></TextView>
               <TextView 
               android:id="@+id/inside"
               android:layout_weight="1"
               android:text="@string/inside"
               android:gravity="center"
               android:textSize="22dip"
               android:paddingRight="20dip"
               android:paddingLeft="20dip"
               android:textColor="#C0C0C0"
               ></TextView>
        </TableRow>
        <TableRow >
            <View 
                android:layout_span="2"
                android:layout_width="wrap_content" 
                android:layout_height="2dip"
                android:background="#7CFC00"
                />
            <View 
                android:layout_span="2"
                android:layout_width="wrap_content" 
                android:layout_height="2dip"
                android:background="#2E3A1F"
                />
        </TableRow>
       <TableRow>
    
           <TextView
               android:id="@+id/mksur"
               android:layout_weight="1"
               android:gravity="center"
               android:text="@string/mksur"
               android:textSize="22dip"
               android:paddingRight="20dip"
               android:paddingLeft="20dip"
               android:textColor="#C0C0C0" />
    
           <TextView
               android:id="@+id/quit"
               android:layout_weight="1"
               android:gravity="center"
               android:text="@string/quit"
               android:textSize="22dip" 
               android:paddingRight="20dip"
               android:paddingLeft="20dip"
               android:textColor="#C0C0C0"/>
           
               <TextView 
               android:id="@+id/night"
               android:layout_weight="1"
               android:text="@string/night"
               android:gravity="center"
               android:textSize="22dip"
               android:paddingRight="20dip"
               android:paddingLeft="20dip"
               android:textColor="#C0C0C0"
               ></TextView>
       </TableRow>
    
    </TableLayout>

    setting.xml:是SetNum.java的布局

    setting.xml
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/wordshow"
            android:layout_width="fill_parent"
            android:layout_height="300dip"
            android:layout_weight="0.46"
            android:background="#FFFFFF"
            android:textSize="15dip"
            android:autoLink="all"
            android:text="@string/info" />
    
        <CheckBox
            android:id="@+id/checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/auto" />
    
        <SeekBar
            android:id="@+id/seekbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:paddingLeft="30dip"
            android:paddingRight="30dip"/>
    
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
    
                <Button
                    android:id="@+id/sure"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:paddingLeft="30dip"
                    android:paddingRight="30dip"
                    android:text="@string/mksur" />
    
                <Button
                    android:id="@+id/change"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:paddingLeft="30dip"
                    android:paddingRight="30dip"
                    android:text="@string/click" />
            </TableRow>
        </TableLayout>
    
    </LinearLayout>

    values默认本地语言英文的时候使用

    values-zh-rcn表示简体中文

    values-zh-rtw表示繁体中文

    这里strings.mxl给出一份,如果有需求可以自己改动即可

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="app_name">魅情景</string>
        
        <string name="outside_color">#726930</string>
        <string name="inside_color">#454926</string>
        <string name="night_color">#2E3A1F</string>
        
        <string name="click_color">#843900</string>
        
        <string name="ring">响铃</string>
        <string name="vibrate">震动</string>
        <string name="silent">静音</string>
        <string name="both">响震</string>
        
        <string name="mksur">确定</string>
        <string name="quit">取消</string>
        
        <string name="outside">室外</string>
        <string name="inside">室内</string>
        <string name="night">夜晚</string>
        
        <string name="auto">自动亮度调节</string>
        <string name="info">这里仅仅是一个测试:\n1、通过点击下面的”点一下“按钮可以切换为不同的情景方便您选择合适的亮度\n2、通过滑动下面的进度条来控制亮度,因为亮度小于80基本无任何意义,故最低限制为80的亮度\n3、勾选“自动亮度调节”来决定是否开启亮度调节。\n4、按“确定”保存设置\nPS:手机自动调节能力不太行的建议关掉,比较优秀的建议开启\n\n如果你对本软件有任何意见或者建议,欢迎联系我\n我的联系方式:freeaquar@163.com\n\n源代码已经上传至我的blog,欢迎一起交流~\n我的博客:http://www.cnblogs.com/FreeAquar/archive/2013/01/18/2866201.html\n</string>
        <string name="click">点一下</string>
    </resources>
    strings.xml

    styles.xml:用于多主题的显示:比如我这个要求透明并且对话框的

    在AndroidManifest.xml的<activity>标签中加入以下一句话activityandroid:theme="@style/Theme.Transparent"

    这些加上后可能重新编译回不过,删掉DDMS下data/data/meizu.phone/shared_prefs中的那个xml重新试试就行。

    如果是真机,没有root的可能看不了,卸载了再运行吧,虚拟机可以看

    styles.xml
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="Theme.Transparent" parent="@android:style/Theme.Dialog">
    
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@color/transparent_background</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">true</item>
    
    </style>
    </resources>

    color.xml对应styles.xml的@color/transparent_background,自己写的颜色好一点,可控制性强一点

    前两位表示透明度,后面6位表示颜色

    color.xml
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
            <color name="transparent_background">#90000000</color>
    </resources>

    5.还希望做的东西

    只是设想,并不一定能够实现,但是会慢慢改进的

    1、显示或提示的颜色可以自行设定

    2、可以自定义时间段对应相应的亮度或者情景模式

    3、背光灯当手电筒,屏幕当手电筒双选

    4、程序运行完成后不在最近打开那一栏里面显示

    5、开前置摄像头

    6.鸣谢

    严重感谢:
    cskiller同学的图标制作(这个图是我的想法,他把我的想法都实现了,嫌不好看喷我吧。。。。囧)。
    zhongsharp同学友情英文翻译,翻译的比较搞~
    off人同学的支持和M9真机实测帮我找到M9不兼容的问题。

    祝大家新年快乐~~

    作者:FreeAquar
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    【转】pymongo实现模糊查询
    使用pip安装包提示TLS证书错误解决办法
    sed用法去除行首和行末的中括号
    logstash之filter处理中括号包围的内容
    根据IP查地理位置信息
    shell生成连续天数日期
    linux grep 取出特定字符串并统计个数
    【转】css3实现文字闪烁,改变透明度
    【转】Django中使用POST方法获取POST数据
    [算法]机器人运动范围
  • 原文地址:https://www.cnblogs.com/FreeAquar/p/2866201.html
Copyright © 2020-2023  润新知