Android 8.1 中Systemui中的常见修改(三)更多开关(开关排序)

有时会接到需求,要求更改systemui中快捷开关的顺序,需要更改成下图的样式来替代原生的更改开关顺序的方式。

                                                        

这里面会使用到之前在系统中添加全局变量的知识,大家如果需要可以去看一下。系统全局变量的使用主要思路就是1.“记录显示开关的顺序”、2.“记录隐藏开关的顺序”、3.“记录是否更改开关顺序”。这三个系统变量。

思路:通过更改系统全局变量来更新快捷开关顺序

https://blog.csdn.net/xiangzaixiansheng/article/details/88524736 

下面的代码只是模拟这个场景,如果需要实现该功能,只需要添加上述的系统全局变量配合数据的变化即可。因为代码量不小,本文只介绍思路,如有需要可以留言联系。

系统中的操作,在下面的方法中,首先判断第一个标志位(是否顺序发生改变),如果发生改变在读取第二个标志为(改变后的开关顺序)。

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

import com.android.systemui.qs.QSTileHost;
import android.provider.Settings.Secure;

public boolean interceptTouchEvent(MotionEvent event) {
//获取标志位,判断开关顺序是否发生改变 
int icon_change= Settings.System.getInt(mContext.getContentResolver(),"system_ui_icon_change",0);
        
        switch (icon_change) {
          case 0:
             
              break;
          case 1:
              ///处理QSTile的数据变化             
              String show_new= Settings.System.getString(mContext.getContentResolver(),"system_ui_icon_show");
              //更改开关顺序
              Secure.putStringForUser(mContext.getContentResolver(), QSTileHost.TILES_SETTING,
                show_new, ActivityManager.getCurrentUser());
              Settings.System.putInt(mContext.getContentResolver(), "system_ui_icon_change",0);
              break;
         }

然后就是自定义dragView的代码了

import android.content.Context;
import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.os.Vibrator;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.provider.Settings;

import com.android.settings.R;

import static android.content.Context.VIBRATOR_SERVICE;


public class DragView extends LinearLayout implements View.OnTouchListener{

    private final static String TAG="DragView";

    private int mHeight,mWidth;
    private ImageView mIV;
    private Context mContext;
    private HashMap mMap;
    private List mShowList,mHideList;
    private TileView mTileShow0,mTileShow1,mTileShow2,mTileShow3,mTileShow4,mTileShow5,mTileShow6,mTileShow7,mTileShow8
            ,mTileShow9,mTileShow10,mTileShow11;
    private TileView mTileHide0,mTileHide1,mTileHide2,mTileHide3;
    private FrameLayout mTouchPanel;
    private LinearLayout mIconLayout;
    private TileView selectedTile=null;
    private WindowManager mWindowManager;
    private WindowManager.LayoutParams mParams;
    private int statusBarHeight,actionBarHeight;
    private int selectPosition,targetPosition;

    private View dragview;
    private Vibrator vibrator;
    private boolean isTouch=false;
    //判断是否是more
    private boolean isMore=false;
    //判断是否在横线处
    private boolean isOnline=false;
    //判断是否在导航栏开始触发移动
    private boolean isBottom=false;

    public DragView(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.drag_view, this);
    }

    public DragView(Context context, AttributeSet attrs) {
        super(context, attrs);
        Log.e(TAG, "init ");
        init(context);
    }

    public DragView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        LayoutInflater.from(context).inflate(R.layout.drag_view, this);
    }

    public DragView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    private void init(Context context){
        mContext=context;
        LayoutInflater.from(mContext).inflate(R.layout.drag_view, this);
        mIconLayout=(LinearLayout)findViewById(R.id.icon_layout);
        mIV=new ImageView(mContext);
        mIV.setBackgroundResource(R.drawable.ic_sequence_airplane_systemui);
        statusBarHeight=72;//need update
        actionBarHeight=168;//need update
        mMap=new HashMap<>();
        mShowList=new ArrayList<>();
        mHideList=new ArrayList<>();
        mTileShow0=(TileView)findViewById(R.id.line0_0);
        mTileShow1=(TileView)findViewById(R.id.line0_1);
        mTileShow2=(TileView)findViewById(R.id.line0_2);
        mTileShow3=(TileView)findViewById(R.id.line0_3);
        mTileShow4=(TileView)findViewById(R.id.line1_0);
        mTileShow5=(TileView)findViewById(R.id.line1_1);
        mTileShow6=(TileView)findViewById(R.id.line1_2);
        mTileShow7=(TileView)findViewById(R.id.line1_3);
        mTileShow8=(TileView)findViewById(R.id.line2_0);
        mTileShow9=(TileView)findViewById(R.id.line2_1);
        mTileShow10=(TileView)findViewById(R.id.line2_2);
        mTileShow11=(TileView)findViewById(R.id.line2_3);
        mTileHide0=(TileView)findViewById(R.id.line3_0);
        mTileHide1=(TileView)findViewById(R.id.line3_1);
        mTileHide2=(TileView)findViewById(R.id.line3_2);
        mTileHide3=(TileView)findViewById(R.id.line3_3);
        mShowList.add(mTileShow0);
        mShowList.add(mTileShow1);
        mShowList.add(mTileShow2);
        mShowList.add(mTileShow3);
        mShowList.add(mTileShow4);
        mShowList.add(mTileShow5);
        mShowList.add(mTileShow6);
        mShowList.add(mTileShow7);
        mShowList.add(mTileShow8);
        mShowList.add(mTileShow9);
        mShowList.add(mTileShow10);
        mShowList.add(mTileShow11);
        mHideList.add(mTileHide0);
        mHideList.add(mTileHide1);
        mHideList.add(mTileHide2);
        mHideList.add(mTileHide3);
        initTiles();
        initFloat();
    }

    private void initFloat(){
        mWindowManager=(WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
        mParams=new WindowManager.LayoutParams();
        mParams.gravity=Gravity.TOP | Gravity.LEFT;
        //for android 7.0
        // mParams.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
        //for android 8.0
        mParams.type=WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        mParams.format = PixelFormat.TRANSPARENT;
        mParams.width = 200;
        mParams.height = 200;
    }

    private void initTiles(){
        //数据读取
        //从settingsprovider中取数据
       // String show_new= Settings.System.getString(getContext().getContentResolver(),"system_ui_icon_show");
       // String[] showTiles=show_new.split(",");
       // String hide_new= Settings.System.getString(getContext().getContentResolver(),"system_ui_icon_hide");
      // String[] hideTiles=hide_new.split(",");
        
                String show = mContext.getResources().getString(R.string.quick_settings_tiles_default_show);
        String[] showTiles=show.split(",");
        String hide = mContext.getResources().getString(R.string.quick_settings_tiles_default_hide);
        String[] hideTiles=hide.split(",");
        Resources res=mContext.getResources();


        SystemUIItemBean nfcBean=new SystemUIItemBean();
        nfcBean.setmName(res.getString(R.string.sequence_nfc));
        nfcBean.setmIcon(R.drawable.ic_sequence_nfc_systemui);
        mMap.put(TileContanst.TILE_NFC, nfcBean);

        SystemUIItemBean gpsBean=new SystemUIItemBean();
        gpsBean.setmName(res.getString(R.string.sequence_gps));
        gpsBean.setmIcon(R.drawable.ic_sequence_gps_systemui);
        mMap.put(TileContanst.TILE_LOCATION, gpsBean);

        SystemUIItemBean dataBean=new SystemUIItemBean();
        dataBean.setmName(res.getString(R.string.sequence_data));
        dataBean.setmIcon(R.drawable.ic_sequence_data_systemui);
        mMap.put(TileContanst.TILE_DATACONNECTION, dataBean);

        SystemUIItemBean hotSpotBean=new SystemUIItemBean();
        hotSpotBean.setmName(res.getString(R.string.sequence_wifi_hotspot));
        hotSpotBean.setmIcon(R.drawable.ic_sequence_hotspot_systemui);
        mMap.put(TileContanst.TILE_HOTSPOT, hotSpotBean);

        SystemUIItemBean batteryBean=new SystemUIItemBean();
        batteryBean.setmName(res.getString(R.string.sequence_power_saving_mode));
        batteryBean.setmIcon(R.drawable.ic_sequence_power_save_systemui);
        mMap.put(TileContanst.TILE_NORMALMODE, batteryBean);

        SystemUIItemBean scanBean=new SystemUIItemBean();
        scanBean.setmName(res.getString(R.string.sequence_scan));
        scanBean.setmIcon(R.drawable.ic_sequence_scan_systemui);
        mMap.put(TileContanst.TILE_SCAN, scanBean);

        SystemUIItemBean btBean=new SystemUIItemBean();
        btBean.setmName(res.getString(R.string.sequence_bluetooth));
        btBean.setmIcon(R.drawable.ic_sequence_bluetooth_systemui);
        mMap.put(TileContanst.TILE_BT, btBean);

        SystemUIItemBean screenShotBean=new SystemUIItemBean();
        screenShotBean.setmName(res.getString(R.string.sequence_screenshot));
        screenShotBean.setmIcon(R.drawable.ic_sequence_screenshot_systemui);
        mMap.put(TileContanst.TILE_SCREENSHOT, screenShotBean);

        SystemUIItemBean audioBean=new SystemUIItemBean();
        audioBean.setmName(res.getString(R.string.sequence_ringtone));
        audioBean.setmIcon(R.drawable.ic_sequence_ringtone_systemui);
        mMap.put(TileContanst.TILE_AUDIOPROFILE, audioBean);

        SystemUIItemBean flashlightBean=new SystemUIItemBean();
        flashlightBean.setmName(res.getString(R.string.sequence_flashlight));
        flashlightBean.setmIcon(R.drawable.ic_sequence_flashlight_systemui);
        mMap.put(TileContanst.TILE_FLASHLIGHT, flashlightBean);

        SystemUIItemBean rotateBean=new SystemUIItemBean();
        rotateBean.setmName(res.getString(R.string.sequence_rotate));
        rotateBean.setmIcon(R.drawable.ic_sequence_rotate_systemui);
        mMap.put(TileContanst.TILE_ROTATION, rotateBean);

        SystemUIItemBean moreBean=new SystemUIItemBean();
        moreBean.setmName(res.getString(R.string.sequence_more));
        moreBean.setmIcon(R.drawable.ic_sequence_more_systemui);
        mMap.put(TileContanst.TILE_TILESORT, moreBean);

        SystemUIItemBean ndbBean=new SystemUIItemBean();
        ndbBean.setmName(res.getString(R.string.sequence_not_disturb));
        ndbBean.setmIcon(R.drawable.ic_sequence_not_disturb_systemui);
        mMap.put(TileContanst.TILE_NOTDISTURB, ndbBean);

        SystemUIItemBean airBean=new SystemUIItemBean();
        airBean.setmName(res.getString(R.string.sequence_airplane));
        airBean.setmIcon(R.drawable.ic_sequence_airplane_systemui);
        mMap.put(TileContanst.TILE_AIRPLANE, airBean);

        SystemUIItemBean eyeBean=new SystemUIItemBean();
        eyeBean.setmName(res.getString(R.string.sequence_protect_eyes));
        eyeBean.setmIcon(R.drawable.ic_sequence_protect_eyes_systemui);
        mMap.put(TileContanst.TILE_EYEMODE, eyeBean);

        SystemUIItemBean WIFIBean=new SystemUIItemBean();
        WIFIBean.setmName(res.getString(R.string.sequence_wlan));
        WIFIBean.setmIcon(R.drawable.ic_sequence_wlan_systemui);
        mMap.put(TileContanst.TILE_WIFI,WIFIBean);
        int i=0;
        for(String tile :showTiles){
            SystemUIItemBean bean=mMap.get(tile);
            TileView tileView=mShowList.get(i++);
            tileView.setTileIcon(bean.getmIcon());
            tileView.setTileTitle(bean.getmName());
            tileView.setOnTouchListener(this);
        }
        i=0;
        for(String tile :hideTiles){
            SystemUIItemBean bean=mMap.get(tile);
            TileView tileView=mHideList.get(i++);
            tileView.setTileIcon(bean.getmIcon());
            tileView.setTileTitle(bean.getmName());
            tileView.setOnTouchListener(this);
        }
    }
/*
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    }

    @Override
    protected void onLayout(boolean b, int i, int i1, int i2, int i3) {
        Log.e(TAG, "left:" + i + " top:" + i1+" right:"+i2+" bottom:"+i3);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }
*/


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                //mParams.x=(int)event.getRawX()-(270/2);
                //mParams.y=(int)event.getRawY()-(60/2);
                //mWindowManager.addView(mIV,mParams);
                mParams.x=(int)event.getRawX()+this.getLeft()-100;
                mParams.y=(int)event.getRawY()+this.getTop()-100;
                //移动的window
                dragview=View.inflate(getContext(),R.layout.drad_item_view,null);
                changeDragview(event);
                if(getPosition(event)!=-1 && getPosition(event)!=11 && getPosition(event)!=12 &&getPosition(event)!=13 &&getPosition(event)!=14 &&getPosition(event)!=15) {
                    //修复位置为-1时出现的问题
                    mWindowManager.addView(dragview, mParams);
                    isTouch=true;
                    isBottom=true;
                }
                //判断more按键
                if(10>>>>" + getPosition(event));
                if(selectedTile == null){
                    return true;
                }
                selectedTile.setVisibility(VISIBLE);
                int position=getPosition(event);
                targetPosition=position;
                if(selectPosition != -1 && targetPosition != -1 && targetPosition !=12 && targetPosition != 13 && targetPosition != 14 && targetPosition!=15 &&selectPosition != 12 &&selectPosition != 13 &&selectPosition != 14 &&selectPosition!=15) {
                    Log.e(TAG, "selectPosition      "+selectPosition+"");
                    Log.e(TAG, "targetPosition      "+targetPosition+"");
                   if (getPosition(event) != 11&& !isMore ) {
                         changePosition(selectPosition, targetPosition);
                    }
                }
                break;
        }
        return true;
    }

    //更改拖动的图片view
    public void changeDragview(MotionEvent event){

        int downPosition=getPosition(event);
        int dragPic;
        ImageView dragiv;
        TextView  dragtv;

        dragview=View.inflate(getContext(),R.layout.drad_item_view,null);
        dragiv=dragview.findViewById(R.id.dragiv);
        dragtv=dragview.findViewById(R.id.dragtv);

        if(downPosition!=-1 && downPosition<12){

            dragiv.setImageResource(mShowList.get(downPosition).getIconId());
            dragtv.setText(mShowList.get(downPosition).getTileTitle());

            Log.e(TAG,mShowList.get(downPosition).getIconId()+"");
        }else if(downPosition>15 && downPosition<20){

            dragiv.setImageResource(mHideList.get(downPosition-16).getIconId());
            dragtv.setText(mHideList.get(downPosition-16).getTileTitle());

            Log.e(TAG,mHideList.get(downPosition-16).getIconId()+"");
        }

    }

    public void loadView(){
        int height=this.getMeasuredHeight();
        int width=this.getMeasuredWidth();
        if(height!=0 && width!=0){
            mHeight=height;
            mWidth=width;
            Log.e(TAG,"width:"+mWidth+" height:"+mHeight);
        }
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        if(view instanceof TileView){
            Log.e(TAG, "touch=======>>>" + ((TileView) view).getTileTitle()+" position:"+getPosition(motionEvent));
            if(getPosition(motionEvent)!=11&& getPosition(motionEvent)!=12 && getPosition(motionEvent)!=13 && getPosition(motionEvent)!=14 && getPosition(motionEvent)!=15) {
                selectedTile = (TileView) view;
                selectedTile.setVisibility(INVISIBLE);
                selectPosition = getPosition(motionEvent);
                //添加震动方法
                vibrator = (Vibrator) mContext.getSystemService(VIBRATOR_SERVICE);
                vibrator.vibrate(70);
            }

        }
        return false;
    }



    private int getPosition(MotionEvent event){
        int position=-1;
        int y=(int)event.getRawY();
        int x=(int)event.getRawX();
        position=(x/270)+(((y-statusBarHeight-actionBarHeight)/240)*4);
        if(position>19)position=-1;
        return position;
    }
   //处理touch后的数据
   
    private String changeString(List ShowList){

        //showlist处理
        StringBuffer sbShow= new StringBuffer();
        Resources res=mContext.getResources();


        for (TileView tileView:ShowList){

            if(res.getString(R.string.sequence_wlan).equals(tileView.getTileTitle())) {
                sbShow. append(TileContanst.TILE_WIFI+",");
            }else if (res.getString(R.string.sequence_gps).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_LOCATION+",");
            }else if (res.getString(R.string.sequence_data).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_DATACONNECTION+",");
            }else if (res.getString(R.string.sequence_wifi_hotspot).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_HOTSPOT+",");
            }else if(res.getString(R.string.sequence_nfc).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_NFC+",");
            } else if (res.getString(R.string.sequence_ringtone).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_AUDIOPROFILE+",");
            }else if(res.getString(R.string.sequence_bluetooth).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_BT+",");
            }else if (res.getString(R.string.sequence_rotate).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_ROTATION+",");
            }else if (res.getString(R.string.sequence_airplane).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_AIRPLANE+",");
            }else if(res.getString(R.string.sequence_screenshot).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_SCREENSHOT+",");
            }else if(res.getString(R.string.sequence_flashlight).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_FLASHLIGHT+",");
            }else if (res.getString(R.string.sequence_more).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_TILESORT+",");
            }else if (res.getString(R.string.sequence_not_disturb).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_NOTDISTURB+",");
            }else if(res.getString(R.string.sequence_power_saving_mode).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_NORMALMODE+",");
            }else if(res.getString(R.string.sequence_protect_eyes).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_EYEMODE+",");
            }else if (res.getString(R.string.sequence_scan).equals(tileView.getTileTitle())){
                sbShow. append(TileContanst.TILE_SCAN+",");
            }
        }


        String newStrShow = sbShow.toString();
        String strShow =newStrShow.substring(0, newStrShow.length() - 1);


        return strShow;
    }

    private void changePosition(int selectPosition,int targetPosition){
        TileView selectView = null,targetView = null;
        int exchangeIconId;
        String exchangTitle;
        if(selectPosition<12){
            Log.e(TAG, "1");
            //selectView=mShowList.get(targetPosition);

            selectView=mShowList.get(selectPosition);
        }else if(selectPosition>15 && selectPosition<20){
            Log.e(TAG, "2");
            selectView=mHideList.get(selectPosition-16);
        }

        exchangeIconId=selectView.getIconId();
        exchangTitle=selectView.getTileTitle();

        if(targetPosition<12){
            Log.e(TAG, "3");
            targetView=mShowList.get(targetPosition);
        }else if(targetPosition>15 && targetPosition<20){
            Log.e(TAG, "4");
            targetView=mHideList.get(targetPosition-16);
        }

        selectView.setTileIcon(targetView.getIconId());
        selectView.setTileTitle(targetView.getTileTitle());
        targetView.setTileIcon(exchangeIconId);
        targetView.setTileTitle(exchangTitle);
        //数据处理
        String showStr=changeString(mShowList);
        Settings.System.putString(mContext.getContentResolver(), "system_ui_icon_show",showStr);
        String hideStr=changeString(mHideList);
        Settings.System.putString(mContext.getContentResolver(), "system_ui_icon_hide",hideStr);
        
        //更改标记位
        Settings.System.putInt(mContext.getContentResolver(), "system_ui_icon_change",1);
        selectView.invalidate();
        targetView.invalidate();

    }

}

写一个javaBean的类用户方便对对象的操作

public class SystemUIItemBean {

    private String mName;
    private int mIcon;
    private String tag;

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public int getmIcon() {
        return mIcon;
    }

    public void setmIcon(int mIcon) {
        this.mIcon = mIcon;
    }

    public String getmName() {
        return mName;
    }

    public void setmName(String mName) {
        this.mName = mName;
    }
}

每一个Titleview

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.w3c.dom.Text;

import com.android.settings.R;


public class TileView extends RelativeLayout {

    private final static String TAG="TileView";
    private String mName;
    private int mIcon;
    private TextView mTv;
    private ImageView mIV;
    private int mId;

    public TileView(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.tile_view,this);
        mTv=(TextView)findViewById(R.id.tile_text);
        mIV=(ImageView)findViewById(R.id.tile_icon);
    }

    public TileView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // getAttrs(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.tile_view,this);
        mTv=(TextView)findViewById(R.id.tile_text);
        mIV=(ImageView)findViewById(R.id.tile_icon);
        mTv.setText(mName);
        mIV.setBackgroundResource(mIcon);
    }

    public TileView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public TileView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    private void getAttrs(Context context, AttributeSet attrs) {
       // TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.tileViewAttr);
       // mName = ta.getString(R.styleable.tileViewAttr_tilename);
      //  mIcon = ta.getResourceId(R.styleable.tileViewAttr_tileicon, R.mipmap.ic_launcher);
      //  ta.recycle();
    }

    public void setTileIcon(int id){
        mIV.setBackgroundResource(id);
        mId=id;
    }

    public void setTileTitle(String title){
        mTv.setText(title);
    }

    public String getTileTitle(){
        return mTv.getText().toString();
    }

    public int getIconId(){
        return mId;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if(event.getAction()==MotionEvent.ACTION_DOWN){
            //this.setVisibility(INVISIBLE);
            Log.e(TAG,"down====>>>>>"+mTv.getText());
        }
        if(event.getAction()==MotionEvent.ACTION_UP){
            //this.setVisibility(VISIBLE);
            Log.e(TAG, "up====>>>>>" + mTv.getText());

        }
        if(event.getAction()==MotionEvent.ACTION_MOVE){
            Log.e(TAG, "move====>>>>>" + mTv.getText());
        }
        if(event.getAction()==MotionEvent.ACTION_CANCEL){
            Log.e(TAG, "ACTION_CANCEL====>>>>>" + mTv.getText());
        }
        return super.onTouchEvent(event);
    }
}

存放title的类

public class TileContanst {
    public final static String TILE_NFC="nfc";
    public final static String TILE_LOCATION="location";
    public final static String TILE_DATACONNECTION="cell";
    public final static String TILE_HOTSPOT="hotspot";
    public final static String TILE_AUDIOPROFILE="sound";
    public final static String TILE_EYEMODE="eyemode";
    public final static String TILE_BT="bt";
    public final static String TILE_ROTATION="rotation";
    public final static String TILE_AIRPLANE="airplane";
    public final static String TILE_SCREENSHOT="screenshot";
    public final static String TILE_FLASHLIGHT="flashlight";
    public final static String TILE_TILESORT="more";
    public final static String TILE_NOTDISTURB="notdisturb";
    public final static String TILE_NORMALMODE="battery";
    public final static String TILE_WIFI="wifi";
    public final static String TILE_SCAN="scan";
}

申请权限

    
    
    

大致思路就是这样了,如果有什么疑问我们也可以通过评论交流。

你可能感兴趣的:(android)