android4.0修改bug系列三

1.在状态栏上加虚拟按键的第一种方法,如音量加减键。

(1)在frameworks/base/packages/SystemUI/res/layout-sw600dp/status_bar.xml中加入两个按键

<com.android.systemui.statusbar.tablet.TabletStatusBarView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
    android:background="@drawable/status_bar_background"
    >
    
    <FrameLayout
        android:id="@+id/bar_contents_holder"
        android:layout_width="match_parent"
        android:layout_height="@*android:dimen/status_bar_height"
        android:layout_gravity="bottom"
        >
        <RelativeLayout
            android:id="@+id/bar_contents"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipChildren="false"
            >


            <!-- notification icons & panel access -->
            <include layout="@layout/status_bar_notification_area" 
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_marginTop="1dp"
                />


            <!-- navigation controls -->
            <LinearLayout
                android:id="@+id/navigationArea"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:orientation="horizontal"
                android:clipChildren="false"
                android:clipToPadding="false"
                >
                <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back"
                    android:layout_width="80dip"
                    android:layout_height="match_parent"
                    android:src="@drawable/ic_sysbar_back"
                    systemui:keyCode="4"
                    android:contentDescription="@string/accessibility_back"
                    systemui:glowBackground="@drawable/ic_sysbar_highlight"
                    />
                <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
                    android:layout_width="80dip"
                    android:layout_height="match_parent"
                    android:src="@drawable/ic_sysbar_home"
                    systemui:keyCode="3"
                    android:contentDescription="@string/accessibility_home"
                    systemui:glowBackground="@drawable/ic_sysbar_highlight"
                    />
                <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/recent_apps"
                    android:layout_width="80dip"
                    android:layout_height="match_parent"
                    android:src="@drawable/ic_sysbar_recent"
                    android:contentDescription="@string/accessibility_recent"
                    systemui:glowBackground="@drawable/ic_sysbar_highlight"
                    />
                    
              <ImageView 
android:id="@+id/status_bar_sub"
android:layout_width="80dip" 
android:layout_height="match_parent"
android:src="@drawable/sub_btu" 
systemui:glowBackground="@drawable/ic_sysbar_highlight" />

<ImageView
android:id="@+id/status_bar_add"
android:layout_width="80dip" 
android:layout_height="match_parent"
android:src="@drawable/add_btu" 
systemui:glowBackground="@drawable/ic_sysbar_highlight" />

                <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/menu"
                    android:layout_width="80dip"
                    android:layout_height="match_parent"
                    android:src="@drawable/ic_sysbar_menu"
                    systemui:keyCode="82"
                    android:visibility="invisible"
                    android:contentDescription="@string/accessibility_menu"
                    systemui:glowBackground="@drawable/ic_sysbar_highlight"
                    />
            </LinearLayout>


            <!-- fake space bar zone -->
            <com.android.systemui.statusbar.policy.EventHole android:id="@+id/fake_space_bar"
                android:layout_height="match_parent"
                android:layout_width="0dp"
                android:paddingLeft="8dip"
                android:paddingRight="8dip"
                android:layout_toRightOf="@+id/navigationArea"
                android:layout_toLeftOf="@+id/notificationArea"
                android:visibility="gone"
                />
        </RelativeLayout>
    </FrameLayout>


    <FrameLayout
        android:id="@+id/bar_shadow_holder"
        android:layout_width="match_parent"
        android:layout_height="@*android:dimen/status_bar_height"
        android:layout_gravity="bottom"
        >
        <!-- lights out shade -->
        <RelativeLayout
            android:id="@+id/bar_shadow"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FF000000"
            android:visibility="gone"
            >
            <ImageView
                android:id="@+id/dot0"
                android:layout_width="80dip"
                android:layout_height="48dip"
                android:src="@drawable/ic_sysbar_lights_out_dot_small"
                android:layout_alignParentLeft="true"
                android:layout_alignParentBottom="true"
                />
            <ImageView
                android:id="@+id/dot1"
                android:layout_width="80dip"
                android:layout_height="48dip"
                android:src="@drawable/ic_sysbar_lights_out_dot_large"
                android:layout_toRightOf="@+id/dot0"
                android:layout_alignParentBottom="true"
                />
            <ImageView
                android:id="@+id/dot2"
                android:layout_width="80dip"
                android:layout_height="48dip"
                android:src="@drawable/ic_sysbar_lights_out_dot_small"
                android:layout_toRightOf="@+id/dot1"
                android:layout_alignParentBottom="true"
                />
            <ImageView
                android:id="@+id/dot3"
                android:layout_width="80dip"
                android:layout_height="48dip"
                android:src="@drawable/ic_sysbar_lights_out_dot_small"
                android:layout_alignParentRight="true"
                android:layout_alignParentBottom="true"
                />
        </RelativeLayout>
    </FrameLayout>
</com.android.systemui.statusbar.tablet.TabletStatusBarView>

(2)在frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java中加入两个按键的方法

ImageView mbut_add;
  ImageView mbut_sub;
  boolean is_down = false;    
private final int ADJUST_VOLUME_DELAY = 250;

在protected View makeStatusBarView()函数中加入

mbut_add=(ImageView)mNavigationArea.findViewById(R.id.status_bar_add);
        mbut_sub=(ImageView)mNavigationArea.findViewById(R.id.status_bar_sub);
        mbut_add.setOnTouchListener(new OnTouchListener(){
            public boolean onTouch (View v, MotionEvent event){
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    is_down = true;
                    Adjust_Volume(true);
                    maddHandler.postDelayed(maddRun, ADJUST_VOLUME_DELAY * 2);
                    mbut_add.setImageResource(R.drawable.add_pressed);
//                    mbut_add.setBackgroundResource(R.drawable.add_pressed);
                }else if (event.getAction() == MotionEvent.ACTION_UP){
                    is_down = false;
                    maddHandler.removeCallbacks(maddRun);
                    mbut_add.setImageResource(R.drawable.add_normal);
//                    mbut_add.setBackgroundResource(R.drawable.add_normal);
                }else if (event.getAction() == MotionEvent.ACTION_MOVE){
                    if((event.getX() < 0) || (event.getY() < 0) 
                                    || (event.getX() > v.getWidth())
                                    || (event.getY() > v.getHeight())){
                            is_down = false;
                    maddHandler.removeCallbacks(maddRun);
                    mbut_add.setImageResource(R.drawable.add_normal);
//                    mbut_add.setBackgroundResource(R.drawable.add_normal);
                    }
                }else{
                }
                return true;
            }
        });
        
        mbut_sub.setOnTouchListener(new OnTouchListener(){
            public boolean onTouch (View v, MotionEvent event){
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    is_down = true;
                    Adjust_Volume(false);
                    msubHandler.postDelayed(msubRun, ADJUST_VOLUME_DELAY * 2);
                    mbut_sub.setImageResource(R.drawable.sub_pressed);
//                    mbut_sub.setBackgroundResource(R.drawable.sub_pressed);
                }else if (event.getAction() == MotionEvent.ACTION_UP){
                    is_down = false;
                    msubHandler.removeCallbacks(msubRun);
                   mbut_sub.setImageResource(R.drawable.sub_normal);
//                    mbut_sub.setBackgroundResource(R.drawable.sub_normal);
                }else if (event.getAction() == MotionEvent.ACTION_MOVE){
                    if((event.getX() < 0) || (event.getY() < 0) 
                               || (event.getX() > v.getWidth())
                               || (event.getY() > v.getHeight())){
                        is_down = false;
                        msubHandler.removeCallbacks(msubRun);
                        mbut_sub.setImageResource(R.drawable.sub_normal);
//                        mbut_sub.setBackgroundResource(R.drawable.sub_normal);
                    }
                }else{
                }
                return true;
        }
        });


在外面加入以下函数

   public void Adjust_Volume(boolean opition){
        AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
        if (audioManager != null) {
            //
             // Adjust the volume in on key down since it is more
             // responsive to the user.
             //
                if(opition){
               
                        audioManager.adjustSuggestedStreamVolume(
                        AudioManager.ADJUST_RAISE,
                      // AudioManager.USE_DEFAULT_STREAM_TYPE,
// AudioManager.STREAM_MUSIC,
                        AudioManager.STREAM_MUSIC,
//                       AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE );
                        AudioManager.FLAG_SHOW_UI |AudioManager.FLAG_PLAY_SOUND );
                }else{                  
                        audioManager.adjustSuggestedStreamVolume(
                     AudioManager.ADJUST_LOWER,
                   // AudioManager.USE_DEFAULT_STREAM_TYPE,
                     AudioManager.STREAM_MUSIC,
//                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE );
                     AudioManager.FLAG_SHOW_UI |AudioManager.FLAG_PLAY_SOUND  );
                }
        }
        }
    private Handler maddHandler = new Handler();        
    private Runnable maddRun = new Runnable() {
                public void run() { 
                        maddHandler.removeCallbacks(maddRun);
                        if(is_down){
                                Adjust_Volume(true);
                                maddHandler.postDelayed(maddRun, ADJUST_VOLUME_DELAY);
                        }
                }
        };
        private Handler msubHandler = new Handler();    
        private Runnable msubRun = new Runnable() {
                    public void run() { 
                            msubHandler.removeCallbacks(msubRun);
                            if(is_down){
                                    Adjust_Volume(false);
                                    msubHandler.postDelayed(msubRun, ADJUST_VOLUME_DELAY);
                            }
                    }
            };
    private Handler removerButtonHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
                is_down = false;
                msubHandler.removeCallbacks(msubRun);
               mbut_sub.setImageResource(R.drawable.sub_normal);
//                mbut_sub.setBackgroundResource(R.drawable.sub_normal);
                maddHandler.removeCallbacks(maddRun);
                mbut_add.setImageResource(R.drawable.add_normal);
//                mbut_add.setBackgroundResource(R.drawable.add_normal); 
        } 


在      protected void onConfigurationChanged(Configuration newConfig) {
        mHeightReceiver.updateHeight(); // display size may have changed
        loadDimens();
        mNotificationPanelParams.height = getNotificationPanelHeight();
        WindowManagerImpl.getDefault().updateViewLayout(mNotificationPanel,
                mNotificationPanelParams);
        mRecentsPanel.updateValuesFromResources();

横屏的时候显示,竖屏的时候隐藏
        if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE)
        {
        Log.i("orien", "Configuration.ORIENTATION_LANDSCAPE");
        mbut_add.setVisibility(View.VISIBLE);
            mbut_sub.setVisibility(View.VISIBLE);
        }
        else if(newConfig.orientation==Configuration.ORIENTATION_PORTRAIT)
        {
        Log.i("orien", "Configuration.ORIENTATION_PORTRAIT");
        mbut_add.setVisibility(View.GONE);
            mbut_sub.setVisibility(View.GONE);
    }

    }


2.在状态栏上加虚拟按键的第二种方法,如音量加减键。

只需要在frameworks/base/packages/SystemUI/res/layout-sw600dp/status_bar.xml中加入两个按键

主要是通过systemui:keyCode,这些键值在com.android.systemui.statusbar.policy.KeyButtonView中都有相应的操作

         <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/volume_down"
                android:layout_width="80dp"
                android:layout_height="match_parent"
                android:src="@drawable/sub_normal"
                systemui:keyCode="25"
                systemui:keyRepeat="false"
                android:layout_weight="0"
                systemui:glowBackground="@drawable/ic_sysbar_highlight"
                android:contentDescription="@string/accessibility_home"
               />
    
            <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/volume_up"
                android:layout_width="80dp"
                android:layout_height="match_parent"
                android:src="@drawable/add_normal"
                systemui:keyCode="24"
                systemui:keyRepeat="false"
               android:layout_weight="0"
                systemui:glowBackground="@drawable/ic_sysbar_highlight"
                android:contentDescription="@string/accessibility_home"
               />


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值