如何在quicksettings中增加一个新的buttons

如何在quicksettings中增加一个新的buttons,下面主要是android L版本前(如KK)和android L版本

一,android L版本前(如KK):

下面就以在quicksettings中新增一个mms button为例。

1、新增layout文件

frameworks\base\packages\SystemUI\res\layout\quick_settings_tile_mms.xml   

2、 修改函数 addSystemTiles (在此函数新增如下段code)  frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\QuickSettings.java

      // mms

        QuickSettingsTileView mMsTile = (QuickSettingsTileView)

        inflater.inflate(R.layout.quick_settings_tile, parent, false);

        mMsTile.setContent(R.layout.quick_settings_tile_mms, inflater);

        mMsTile.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

               // mBar.collapseAllPanels(true);

               // showBrightnessDialog();

                Intent intent = new Intent();

                intent.setComponent(new ComponentName(

                        "com.android.mms",

                        "com.android.mms.ui.ConversationList"));

                startSettingsActivity(intent);

            }

        });

            parent.addView(mMsTile);

             mDynamicSpannedTiles.add(mMsTile);

3、新增后效果图

 

 

 

二,android L版本

可以参考mtk 源代码是如何添加mediatek自定义的QS Button:
alps\frameworks\base\packages\SystemUI\src\com\mediatek\systemui\qs\tiles

 

下面我们以添加一个Camera  QS Button开关为例:

如下图添加 Camera QS Button:

 

 

 

1,增加config文件内容

alps\frameworks\base\packages\SystemUI\res\values\config.xml

 



wifi,bt,inversion,cell,airplane,rotation,flashlight,location,cast,hotspot,hotknot,

audioprofile,dataconnection,camera

 

2,在下面目录下,新建CameraController.java和CameraControllerImpl.java文件

alps\frameworks\base\packages\SystemUI\src\com\mediatek\systemui\statusbar\policy

 

2.1 CameraController.java:

package com.mediatek.systemui.statusbar.policy;

import java.util.Set;

public interface CameraController {
boolean isSupportCamera();

}

 2.2 CameraControllerImpl.java:

package com.mediatek.systemui.statusbar.policy;

import android.content.Context;
import java.util.UUID;

public class CameraControllerImpl implements CameraController {
private static final String TAG = "CameraControllerImpl";
private final Context mContext;

public CameraControllerImpl(Context context) {
mContext = context;
}

@Override
public boolean isSupportCamera() {
return true;
}
}

 3,在下面目录下,新建文件CameraTile.java

alps\frameworks\base\packages\SystemUI\src\com\mediatek\systemui\qs\tiles

 CameraTile.java:

package com.mediatek.systemui.qs.tiles;

import android.content.Intent;
import android.content.Context;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import android.net.ConnectivityManager;
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnAttachStateChangeListener;

import com.android.internal.telephony.TelephonyIntents;
import com.android.systemui.R;
import com.android.systemui.qs.QSTile;
import com.android.internal.telephony.IccCardConstants;

import com.mediatek.xlog.Xlog;
import com.mediatek.systemui.statusbar.policy.CameraController;


public class CameraTile extends QSTile {
private static final String TAG = "CameraTile";
private static final boolean DEBUG = true;
private final CameraController mController=null;
private boolean mListening;
private int mDataState = R.drawable.ic_qs_inversion_off;
private IccCardConstants.State mSimState = IccCardConstants.State.UNKNOWN;
private TelephonyManager mTelephonyManager;

public CameraTile(Host host) {
super(host);
;//mController = host.getCameraController();
}
@Override
protected BooleanState newTileState() {
return new BooleanState();
}
@Override
public void setListening(boolean listening) {

}
boolean enabled =false;
@Override
protected void handleClick() {
enabled =!enabled;

if (enabled) {
mDataState = R.drawable.ic_qs_inversion_on;
} else {
mDataState = R.drawable.ic_qs_inversion_off;
}
refreshState();
}
@Override
protected void handleUpdateState(BooleanState state, Object arg) {
state.label ="Camera" ;//mContext.getString(R.string.camera);
state.visible = true;
state.iconId = mDataState;
}

}

 

4,在下面目录下的文件添加新的方法:

alps\frameworks\base\packages\SystemUI\src\com\android\systemui\qs\tiles\QSTile.java

public interface Host {
void startSettingsActivity(Intent intent);

.................

//add new method

CameraController getCameraController ();

5,添加内容

alps\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\QSTileHost.java

 5.1:

/// M: add CameraController  qs
private final CameraController mCameraController ;

 5.2:

public QSTileHost(Context context, PhoneStatusBar statusBar,
BluetoothController bluetooth, LocationController location,
RotationLockController rotation, NetworkController network,
ZenModeController zen, HotspotController hotspot,
CastController cast, FlashlightController flashlight,
UserSwitcherController userSwitcher, KeyguardMonitor keyguard,
SecurityController security,
/// M: add HotKnot in quicksetting
HotKnotController hotknot,
/// M: add AudioProfile in quicksetting
AudioProfileController audioprofile,
/// M: add DataConnection in quicksetting
DataConnectionController dataconnection

CameraController  cameraController  
) {

mContext = context;
mStatusBar = statusBar;

 ....

mCameraController =cameraController

 

 }

 

5.3:

private QSTile createTile(String tileSpec) {

if (tileSpec.equals("camera")) return new CameraTile(this);
else if (tileSpec.equals("wifi")) return new WifiTile(this);
else if (tileSpec.equals("bt")) return new BluetoothTile(this);

 5.4:

@Override
public CameraController   getCameraController() {
return mCameraController ;
}

 

你可能感兴趣的:(MTK)