/*
* Copyright (c) 2014,KJFrameForAndroid 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 org.kymjs.kjframe.utils;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Parcelable;
import android.view.View;
/**
* 系统界面工具类<br>
*
* <b>创建时间</b> 2014-8-14
*
* @author kymjs (https://github.com/kymjs)
* @version 1.1
*/
public class ViewUtils {
/**
* 截图
*
* @param v
* 需要进行截图的控件
* @return 该控件截图的Bitmap对象。
*/
public static Bitmap captureView(View v) {
v.setDrawingCacheEnabled(true);
v.buildDrawingCache();
return v.getDrawingCache();
}
/**
* 创建快捷方式
*
* @param cxt
* Context
* @param icon
* 快捷方式图标
* @param title
* 快捷方式标题
* @param cls
* 要启动的类
*/
public void createDeskShortCut(Context cxt, int icon, String title,
Class<?> cls) {
// 创建快捷方式的Intent
Intent shortcutIntent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
// 不允许重复创建
shortcutIntent.putExtra("duplicate", false);
// 需要现实的名称
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
// 快捷图片
Parcelable ico = Intent.ShortcutIconResource.fromContext(
cxt.getApplicationContext(), icon);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ico);
Intent intent = new Intent(cxt, cls);
// 下面两个属性是为了当应用程序卸载时桌面上的快捷方式会删除
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
// 点击快捷图片,运行的程序主入口
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
// 发送广播。OK
cxt.sendBroadcast(shortcutIntent);
}
}