南阳市桔豆网络科技有限公司
首页 | 联系方式 | 加入收藏 | 设为首页 | 手机站

产品目录

联系方式

联系人:业务部
电话: 00133-648562
邮箱:service@oro-pwower.com

当前位置:首页 >> 新闻中心 >> 正文

android 5.1状态栏添加截屏功能

字号:
摘要:android 5.1状态栏添加截屏功能

本文是参考http://blog.csdn.net/zhang_jun_xiang/article/details/50055085博文写的,主要是为了方便记录下自己学习的过程。

1.在/frameworks/base/packages/SystemUI/res/values/config.xml中添加takescreenshot

<stringname="quick_settings_tiles_default"translatable="false">wifi,bt,inversion,cell,airplane,rotation,flashlight,

location,cast,takescreenshot,hotspot,hotknot,audioprofile</string>



2.在string.xml中添加<stringname="take_screenshot">Take Screen</string>和<stringname="take_screenshot">截屏</string>


3.修改SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java

将class GlobalScreenshot改为public class GlobalScreenshot

将 void takeScreenshot() 改为public voidtakeScreenshot()


4.在SystemUI/src/com/android/systemui/qs/tiles/中添加TakeScreenShotTitle.java

/*
* Copyright (C) 2014 MediaTek Inc.
* Modification based on code covered by the mentioned copyright
* and/or permission notice(s).
*/
/*
 * Copyright (C) 2014 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.systemui.qs.tiles;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.provider.Settings;
import android.util.Log;
import android.os.Handler ;
import android.os.Message ;
import android.os.Messenger ;
import android.view.View;
import android.view.ViewGroup;
import java.lang.Exception ;
import com.android.systemui.screenshot.* ;
import com.android.systemui.R;
import com.android.systemui.qs.QSTile.State;
import com.android.systemui.qs.QSTile.BooleanState;
import com.android.systemui.qs.QSDetailItems;
import com.android.systemui.qs.QSDetailItems.Item;
import com.android.systemui.qs.QSTile;
import com.android.systemui.qs.QSTileView;
import com.android.systemui.qs.SignalTileView;
import com.android.systemui.statusbar.phone.QSTileHost;
import com.android.systemui.statusbar.policy.NetworkController;
import com.android.systemui.statusbar.policy.NetworkController.AccessPointController;
import com.android.systemui.statusbar.policy.NetworkController.AccessPointController.AccessPoint;
import com.android.systemui.statusbar.policy.NetworkController.NetworkSignalChangedCallback;
/** pang test Quick settings tile: TakeScreenShotTitle **/
public class TakeScreenShotTitle extends QSTile<QSTile.BooleanState> {
 private static final String TAG = "TakeScreenShotTile"; 
 
 private static final int TAKE_SCREEN_SHOT_MESSAGE = 10000; 
 private static GlobalScreenshot mScreenshot; 
 
 private int mAudioState = R.drawable.ic_hotknot_qs_on; 
 
 public TakeScreenShotTitle(Host host) { 
 super(host); 
 } 
 
 @Override 
 protected BooleanState newTileState() { 
 return new BooleanState(); 
 } 
 
 @Override 
 public void setListening(boolean listening) { 
 } 
 
 @Override 
 protected void handleClick() { 
 mHost.startSettingsActivity(new Intent()); 
 Message msg = mHandler.obtainMessage(TAKE_SCREEN_SHOT_MESSAGE); 
 mHandler.sendMessageDelayed(msg,1000); 
 } 
 
 protected void handleLongClick() { 
 mHost.startSettingsActivity(new Intent()); 
 Message msg = mHandler.obtainMessage(TAKE_SCREEN_SHOT_MESSAGE); 
 mHandler.sendMessageDelayed(msg,1000); 
 } 
 
 @Override 
 protected void handleUpdateState(BooleanState state, Object arg) { 
 state.label = mContext.getString(R.string.take_screenshot); 
 state.visible = true; 
 state.icon = ResourceIcon.get(mAudioState); 
 } 
 
 Handler mHandler = new Handler() { 
 public void handleMessage(Message msg) { 
 switch (msg.what) { 
 case TAKE_SCREEN_SHOT_MESSAGE: 
 final Messenger callback = msg.replyTo; 
 if (mScreenshot == null) { 
 mScreenshot = new GlobalScreenshot(mContext); 
 } 
 mScreenshot.takeScreenshot(new Runnable() { 
 @Override public void run() { 
 Message reply = Message.obtain(null, 1); 
 try { 
 if(callback != null){ 
 callback.send(reply); 
 } 
 }catch(Exception e){ 
 } 
 } 
 }, msg.arg1 > 0, msg.arg2 > 0); 
 break; 
 default: 
 break; 
 } 
 } 
 }; 
 
}

5.在SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java中添加

importcom.android.systemui.qs.tiles.TakeScreenShotTitle ;

在private QSTile<?> createTile(String tileSpec)中添加

else if(tileSpec.equals("takescreenshot")) return new TakeScreenShotTitle(this);


6.make -j8 编译,编完成后刷机