中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

創(chuàng)建Android桌面上的應用程序的快捷方式圖標

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity {

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        installShortCut();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    private void installShortCut(){ 
        Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); 
        shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); 
        // 是否可以有多個快捷方式的副本,參數(shù)如果是true就可以生成多個快捷方式,如果是false就不會重復添加 
        shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, generatorContactCountIcon(((BitmapDrawable)(getResources().getDrawable(R.drawable.ic_launcher))).getBitmap())); 
        shortcutIntent.putExtra("duplicate", false); 
        Intent mainIntent = new Intent(Intent.ACTION_MAIN); 
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 

        // 要刪除的應用程序的ComponentName,即應用程序包名+activity的名字 
        //intent2.setComponent(new ComponentName(this.getPackageName(), this.getPackageName() + ".MainActivity")); 
        mainIntent.setClass(this, this.getClass()); 

        shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mainIntent); 
        //shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon)); 
        shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, generatorContactCountIcon(((BitmapDrawable)(getResources().getDrawable(R.drawable.ic_launcher))).getBitmap())); 
        sendBroadcast(shortcutIntent); 
    } 

    private Bitmap generatorContactCountIcon(Bitmap icon){ 
        //初始化畫布 
        int iconSize=(int)getResources().getDimension(android.R.dimen.app_icon_size); 
        Bitmap contactIcon=Bitmap.createBitmap(iconSize, iconSize, Config.ARGB_8888); 
        Canvas canvas=new Canvas(contactIcon); 

        //拷貝圖片 
        Paint iconPaint=new Paint(); 
        iconPaint.setDither(true);//防抖動 
        iconPaint.setFilterBitmap(true);//用來對Bitmap進行濾波處理,這樣,當你選擇Drawable時,會有抗鋸齒的效果 
        Rect src=new Rect(0, 0, icon.getWidth(), icon.getHeight()); 
        Rect dst=new Rect(0, 0, iconSize, iconSize); 
        canvas.drawBitmap(icon, src, dst, iconPaint); 

        //在圖片上創(chuàng)建一個覆蓋的聯(lián)系人個數(shù) 
        int contacyCount=11; 
        //啟用抗鋸齒和使用設備的文本字距 
        Paint countPaint=new Paint(Paint.ANTI_ALIAS_FLAG|Paint.DEV_KERN_TEXT_FLAG); 
        countPaint.setColor(Color.RED); 
        countPaint.setTextSize(20f); 
        countPaint.setTypeface(Typeface.DEFAULT_BOLD); 
        canvas.drawText(String.valueOf(contacyCount), iconSize-18, 25, countPaint); 
        return contactIcon; 
    } 
}

標簽:

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:iOS相應觸屏事件代碼

下一篇:Android 獲取SD卡路徑和空間使用情況