我们从2011年坚守至今,只想做存粹的技术论坛。  由于网站在外面,点击附件后要很长世间才弹出下载,请耐心等待,勿重复点击不要用Edge和IE浏览器下载,否则提示不安全下载不了

 找回密码
 立即注册
搜索
查看: 2353|回复: 2

RK3288 双屏异显的上层 PACK代码

[复制链接]

该用户从未签到

812

主题

399

回帖

499

积分

二级逆天

积分
499

社区居民社区明星忠实会员宣传大使奖终身成就奖特殊贡献奖

QQ
发表于 2015-7-14 20:32:16 | 显示全部楼层 |阅读模式
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.settings.dualscreen;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.os.Handler;
import android.provider.Settings;
import android.util.Log;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.content.res.Configuration;
import android.os.RemoteException;
import android.util.Slog;
import com.android.settings.R;
import com.android.settings.WirelessSettings;

/**
* BluetoothEnabler is a helper to manage the Bluetooth on/off checkbox
* preference. It turns on/off Bluetooth and ensures the summary of the
* preference reflects the current state.
*/
public final class DualScreenEnabler implements CompoundButton.OnCheckedChangeListener {
    private static final String LOG = "DualScreenEnabler";
    private static final boolean DEBUG = true;
    private void LOGD(String msg){
        if(DEBUG){
            Slog.d(LOG, msg);
        }
    }
    private final Context mContext;
    private Switch mSwitch;
    private boolean mValidListener;
   
    private final String store_key = Settings.System.DUAL_SCREEN_MODE;
    private final String icon_key = Settings.System.DUAL_SCREEN_ICON_USED;
    private final int DUAL_SCREEN_CLOSE = 0;
    private final int DUAL_SCREEN_OPEN = 1;


    public DualScreenEnabler(Context context, Switch switch_) {
        mContext = context;
        mSwitch = switch_;
        mValidListener = false;

    }
   
    private int getDualScreenValue(){
        return Settings.System.getInt(
                mContext.getContentResolver(), store_key, DUAL_SCREEN_CLOSE);
    }
   
    private final ContentObserver mValueObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
            final boolean enable = (DUAL_SCREEN_CLOSE != getDualScreenValue());
            LOGD("onchagne enable="+enable + "selfChange="+selfChange);
            
            try {
            IActivityManager am = ActivityManagerNative.getDefault();
            Configuration config = am.getConfiguration();

            // Will set userSetLocale to indicate this isn't some passing default - the user
            // wants this remembered
            config.setDualScreenFlag(enable);

            am.updateConfiguration(config);
            // Trigger the dirty bit for the Settings Provider.
            //BackupManager.dataChanged("com.android.providers.settings");
        } catch (RemoteException e) {
            // Intentionally left blank
        }
        

        }
    };

    public void resume() {
        LOGD("--------resume--------------"+getDualScreenValue());
        handleStateChanged(getDualScreenValue());
        mSwitch.setOnCheckedChangeListener(this);
        mContext.getContentResolver().registerContentObserver(
                Settings.System.getUriFor(store_key), false,
                mValueObserver);
        mValidListener = true;
    }

    public void pause() {
        LOGD("--------pause--------------"+getDualScreenValue());      
        mSwitch.setOnCheckedChangeListener(null);
        mContext.getContentResolver().unregisterContentObserver(mValueObserver);
        mValidListener = false;
    }
   
    void handleStateChanged(int state) {
        switch (state) {
            case DUAL_SCREEN_CLOSE:
                setChecked(false);
                mSwitch.setEnabled(true);
                break;
            case DUAL_SCREEN_OPEN:
                setChecked(true);
                mSwitch.setEnabled(true);
                break;
        }
    }

    public void setSwitch(Switch switch_) {
        LOGD("setSwitch switch=");
        if (mSwitch == switch_) return;
        mSwitch.setOnCheckedChangeListener(null);
        mContext.getContentResolver().unregisterContentObserver(mValueObserver);
        mSwitch = switch_;
        mSwitch.setOnCheckedChangeListener(this);
        mContext.getContentResolver().registerContentObserver(
                Settings.System.getUriFor(store_key), false,
                mValueObserver);

        boolean isOn = getDualScreenValue() != DUAL_SCREEN_CLOSE;
        setChecked(isOn);
        mSwitch.setEnabled(true);
    }

    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//        mSwitch.setEnabled(true);
        LOGD("-----------------------------isChecked:"+isChecked);
        int value = DUAL_SCREEN_CLOSE;
        if(isChecked){
            value = DUAL_SCREEN_OPEN;
        } else {
        Settings.System.putInt(mContext.getContentResolver(), icon_key, 0);
    }
        Settings.System.putInt(
                mContext.getContentResolver(), store_key, value);
    }

    private void setChecked(boolean isChecked) {
        if (isChecked != mSwitch.isChecked()) {
            // set listener to null, so onCheckedChanged won't be called
            // if the checked status on Switch isn't changed by user click
            if (mValidListener) {
                mSwitch.setOnCheckedChangeListener(null);
            }
            mSwitch.setChecked(isChecked);
            if (mValidListener) {
                mSwitch.setOnCheckedChangeListener(this);
            }
        }
    }
}
回复

使用道具 举报

该用户从未签到

6

主题

108

回帖

33

积分

二级逆天

积分
33

社区居民终身成就奖

QQ
发表于 2015-7-14 20:49:25 | 显示全部楼层
回复

使用道具 举报

该用户从未签到

6

主题

144

回帖

8

积分

二级逆天

努力奋斗

积分
8

社区居民终身成就奖

QQ
发表于 2016-1-7 16:17:26 | 显示全部楼层
顶,正要研究双屏异显
硬件设计
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

论坛开启做任务可以
额外奖励金币快速赚
积分升级了


Copyright ©2011-2024 NTpcb.com All Right Reserved.  Powered by Discuz! (NTpcb)

本站信息均由会员发表,不代表NTpcb立场,如侵犯了您的权利请发帖投诉

平平安安
TOP
快速回复 返回顶部 返回列表