android4.4动态显示隐藏statusbar和禁止下拉

android4.4增加动态显示隐藏statusbar和禁止statusbar下拉功能

首先还是在设置->显示里加上图形界面

修改packages/apps/Settings/res/xml/display_settings.xml

增加

        <CheckBoxPreference
            android:key="drop_statusbar"
            android:title="@string/prohibit_statusbar_title"
            android:persistent="false" />
        <CheckBoxPreference
            android:key="hide_statusbar"
            android:title="@string/hide_statusbar_title"
            android:persistent="false" />
修改packages/apps/Settings/res/values/strings.xml增加


    <string name="hide_statusbar_title">Hide StatusBar</string>
    <string name="prohibit_statusbar_title">Prohibit statusbar drop-down</string>
修改packages/apps/Settings/src/com/android/settings/DisplaySettings.java增加

    private static final String KEY_STATUSBAR_BAR_DROP = "drop_statusbar";
    private static final String KEY_STATUSBAR_BAR_HIDE = "hide_statusbar";
    public static String ACTION_SHOW_STATUS_BAR = "gzys.hclydao.action.show_status_bar";
    public static String ACTION_HIDE_STATUS_BAR = "gzys.hclydao.action.hide_status_bar";
    private CheckBoxPreference mDropSta; //add by hclydao
    private CheckBoxPreference mHideSta; //add by hclydao
增加初始化

        mDropSta = (CheckBoxPreference) findPreference(KEY_STATUSBAR_BAR_DROP);
        mDropSta.setPersistent(false);
        mHideSta = (CheckBoxPreference) findPreference(KEY_STATUSBAR_BAR_HIDE);
        mHideSta.setPersistent(false);
在onCreate最后

        navcheck = Settings.Global.getInt(resolver, Settings.Global.DROP_STATUSBAR,0);
        if(navcheck == 1)
            mDropSta.setChecked(true);
        navcheck = Settings.Global.getInt(resolver, Settings.Global.HIDE_STATUSBAR,0);
        if(navcheck == 1)
            mHideSta.setChecked(true);
基于上篇隐藏Navigationbar已经定义了navcheck
在onPreferenceTreeClick中增加判断


                else if(preference == mDropSta) { //add by hclydao
            boolean isCheck = mDropSta.isChecked();
            Settings.Global.putInt(getContentResolver(), Settings.Global.DROP_STATUSBAR, isCheck ? 1 : 0);
        } else if(preference == mHideSta) { //add by hclydao
            boolean isCheck = mHideSta.isChecked();
            Settings.Global.putInt(getContentResolver(), Settings.Global.HIDE_STATUSBAR, isCheck ? 1 : 0);
            Intent mychange;
            if(isCheck) {
                    mychange = new Intent(ACTION_HIDE_STATUS_BAR);
            } else {
                    mychange = new Intent(ACTION_SHOW_STATUS_BAR);
            }
            getActivity().sendBroadcast(mychange);
        }
图形界面部分就修改完了,接着完善功能
修改frameworks/base/core/java/android/provider/Settings.java增加


       public static final String HIDE_STATUSBAR = "hide_statusbar";
       public static final String DROP_STATUSBAR = "drop_statusbar";
保存全局设置
禁止statusbar下拉的完善

修改frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelBar.java增加


import android.provider.Settings;
import android.content.ContentResolver;
    private Context mContext;//add by hclydao
在public PanelBar(Context context, AttributeSet attrs) {最后增加

mContext = context;
修改public PanelView selectPanelForTouch函数


    public PanelView selectPanelForTouch(MotionEvent touch) {
        final int N = mPanels.size();
        int dropstatus = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.DROP_STATUSBAR,0);
        if(dropstatus == 1) //add by hclydao
            return null;//modify by hclydao
        else
            return mPanels.get((int)(N * touch.getX() / getMeasuredWidth()));
    }
修改frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java增加
import android.provider.Settings;
import android.content.ContentResolver;
    private Context mContext;//add by hclydao
修改函数public PanelView selectPanelForTouch最后的return


        int dropstatus = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.DROP_STATUSBAR,0);
        if(dropstatus == 1) //add by hclydao
            return null;//modify by hclydao
        else
            return showSettings ? mSettingsPanel : mNotificationPanel;
隐藏statusbar功能完善
修改frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

增加


    public static String ACTION_SHOW_STATUS_BAR = "gzys.hclydao.action.show_status_bar";
    public static String ACTION_HIDE_STATUS_BAR = "gzys.hclydao.action.hide_status_bar";
在addStatusBarWindow函数最后加上

        //add by hclydao
        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTION_HIDE_NAV_BAR);
        filter.addAction(ACTION_SHOW_NAV_BAR);
        filter.addAction(ACTION_SHOW_STATUS_BAR);
        filter.addAction(ACTION_HIDE_STATUS_BAR);
        mContext.registerReceiver(mHideNavBarReceiver, filter);
        int navcheck = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.HIDE_STATUSBAR,0);
        if(navcheck != 0)
            showStatusBar(false);
在destroy函数最后加上

        mContext.unregisterReceiver(mHideNavBarReceiver);//hclydao
文件最后增加

    //add by hclydao
    public void showStatusBar(boolean isshow) {
        if(mStatusBarWindow != null) {/*
            WindowManager.LayoutParams lp = (WindowManager.LayoutParams) mStatusBarWindow.getLayoutParams();
            if(isshow)
                lp.height = getStatusBarHeight();
            else
                lp.height = 0;
            mWindowManager.updateViewLayout(mStatusBarWindow, lp);*/
            mStatusBarWindow.setVisibility(isshow ? View.VISIBLE : View.GONE);
        }
    }
 
    BroadcastReceiver mHideNavBarReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if(intent.getAction().equals(ACTION_HIDE_NAV_BAR)) {
                //hideNavBar();
            } else if(intent.getAction().equals(ACTION_SHOW_NAV_BAR)) {
                //showNavBar();
            } else if(intent.getAction().equals(ACTION_SHOW_STATUS_BAR)) {
                showStatusBar(true);
            } else if(intent.getAction().equals(ACTION_HIDE_STATUS_BAR)) {
                showStatusBar(false);
            }
        }
    };
修改frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java增加

    public static String ACTION_SHOW_STATUS_BAR = "gzys.hclydao.action.show_status_bar";
    public static String ACTION_HIDE_STATUS_BAR = "gzys.hclydao.action.hide_status_bar";
int oStatusBarHeight;//add by hclydao
基于前一篇隐藏Navigationbar中在         context.registerReceiver(mHideNavBarReceiver, filter);前增加

        filter.addAction(ACTION_SHOW_STATUS_BAR);
        filter.addAction(ACTION_HIDE_STATUS_BAR);
在             hideNavBar();下增加

        navcheck = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.HIDE_STATUSBAR,0);
        if(navcheck != 0)
            showStatusBar(false);
在mHideNavBarReceiver中增加判断

            } else if(intent.getAction().equals(ACTION_SHOW_STATUS_BAR)) {
                showStatusBar(true);
            } else if(intent.getAction().equals(ACTION_HIDE_STATUS_BAR)) {
                showStatusBar(false);
增加showStatusBar函数

    public void showStatusBar(boolean isshow) {
        if(isshow) {
            mStatusBarHeight = oStatusBarHeight;
        } else {
            if(mStatusBarHeight == 0)
                return;
            oStatusBarHeight = mStatusBarHeight;
            mStatusBarHeight = 0;
        }
        updateRotation(false);
    }

转载地址:https://blog.csdn.net/hclydao/article/details/78181970

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值