當前位置: 首頁>>代碼示例>>Java>>正文


Java WallpaperManager.setBitmap方法代碼示例

本文整理匯總了Java中android.app.WallpaperManager.setBitmap方法的典型用法代碼示例。如果您正苦於以下問題:Java WallpaperManager.setBitmap方法的具體用法?Java WallpaperManager.setBitmap怎麽用?Java WallpaperManager.setBitmap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.WallpaperManager的用法示例。


在下文中一共展示了WallpaperManager.setBitmap方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setColorWallpaper

import android.app.WallpaperManager; //導入方法依賴的package包/類
/**
 * Create a color filled bitmap and changes the current system wallpaper to this bitmap.
 */
public static void setColorWallpaper(Context context, int color) throws IOException {

    // Get the Wallpaper Manager
    final WallpaperManager wpManager = WallpaperManager.getInstance(context);

    // Create the pitch black bitmap
    final Bitmap pitchBlackBitmap = createColorBitmap(color, MIN_SAFE_SIZE, MIN_SAFE_SIZE);

    // Set the wallpaper
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        // On Android N and above use the new API to set both the general system wallpaper and
        // the lock-screen-specific wallpaper
        wpManager.setBitmap(pitchBlackBitmap, null, true, WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK);
    } else {
        wpManager.setBitmap(pitchBlackBitmap);
    }
}
 
開發者ID:appgramming,項目名稱:LoneColor-Android,代碼行數:21,代碼來源:ColorWallpaper.java

示例2: doInBackground

import android.app.WallpaperManager; //導入方法依賴的package包/類
@Override
protected Boolean doInBackground(Void... params) {
    WallpaperManager wm = WallpaperManager.getInstance(context.get());
    Boolean worked;
    try {
        try {
            wm.setBitmap(scaleToActualAspectRatio(resource));
        } catch (OutOfMemoryError ex) {
            if (ShowcaseActivity.DEBUGGING)
                Utils.showLog(context.get(), "OutOfMemoryError: " + ex.getLocalizedMessage());
            showRetrySnackbar();
        }
        worked = true;
    } catch (IOException e2) {
        worked = false;
    }
    return worked;
}
 
開發者ID:PitchedApps,項目名稱:Material-Glass,代碼行數:19,代碼來源:ApplyWallpaper.java

示例3: handleCrop

import android.app.WallpaperManager; //導入方法依賴的package包/類
private void handleCrop(int resultCode, Intent result) {
    if (resultCode == RESULT_OK) {


        mImageView.setImageURI(Crop.getOutput(result));

        WallpaperManager myWallpaperManager = WallpaperManager
                .getInstance(getApplicationContext());

        try {

            Bitmap mBitmap = getImageBitmap();
            myWallpaperManager.setBitmap(mBitmap);
            Toast.makeText(DetailActivity.this, "Wallpaper set",
                    Toast.LENGTH_SHORT).show();

        } catch (IOException e) {
            Toast.makeText(DetailActivity.this,
                    "Error setting wallpaper", Toast.LENGTH_SHORT)
                    .show();
        }

    } else if (resultCode == Crop.RESULT_ERROR) {
        Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:Technologx,項目名稱:Fire-Bird-Dashboard-for-Zooper,代碼行數:27,代碼來源:DetailActivity.java

示例4: setWallpaper

import android.app.WallpaperManager; //導入方法依賴的package包/類
public void setWallpaper(View v) {
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
    try {
        wallpaperManager.setBitmap(Wallpaper);
        Toast toast = Toast.makeText(this, "wallpaper set", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:dkanada,項目名稱:frost,代碼行數:12,代碼來源:WallpaperSetActivity.java

示例5: onClick

import android.app.WallpaperManager; //導入方法依賴的package包/類
@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which){
        case 0:
            boolean saveSuccess = false;
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
                String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
                if(ContextCompat.checkSelfPermission(getActivity(), permissions[0]) != PackageManager.PERMISSION_GRANTED){
                    ActivityCompat.requestPermissions(getActivity(),permissions,0);
                }else {
                    saveSuccess = savePicture(pictureBitmap);
                }
            }else {
                saveSuccess = savePicture(pictureBitmap);
            }
            if(saveSuccess){
                Toast.makeText(getActivity(),"圖片已存儲在 /miaosou/picture 文件夾下",Toast.LENGTH_SHORT).show();
            }else {
                Toast.makeText(getActivity(),"圖片保存失敗,請檢查SD卡讀寫權限是否開啟",Toast.LENGTH_SHORT).show();
            }
            break;
        case 1:
            WallpaperManager wallpaperManager = WallpaperManager.getInstance(getContext());
            try {
                    wallpaperManager.setBitmap(pictureBitmap);
            } catch (IOException e) {
                e.printStackTrace();
            }
            break;
    }
}
 
開發者ID:NicoLiutong,項目名稱:miaosou,代碼行數:32,代碼來源:ComicReadFragment.java

示例6: onSetWallpaperForBitmap

import android.app.WallpaperManager; //導入方法依賴的package包/類
/**
     * 使用Bitmap設置壁紙
     * 直接設置為壁紙,不會有任何界麵和彈窗出現
     * 壁紙切換,會有動態的漸變切換
     *
     * @param view
     */
    public void onSetWallpaperForBitmap(View view) {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
        try {
            Bitmap wallpaperBitmap = BitmapFactory.decodeResource(getResources(), R.raw.girl);
            wallpaperManager.setBitmap(wallpaperBitmap);
//            setWallpaper(wallpaperBitmap);
//            setWallpaper(getResources().openRawResource(R.raw.girl));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
開發者ID:coolspan,項目名稱:LiveWallpaper,代碼行數:19,代碼來源:MainActivity.java

示例7: changeWallPaper

import android.app.WallpaperManager; //導入方法依賴的package包/類
public static void changeWallPaper(Context ctx, int drawableResource){
    WallpaperManager myWallpaperManager
            = WallpaperManager.getInstance(ctx);
    try {
        Bitmap bitmap = BitmapFactory.decodeResource(ctx.getResources(), drawableResource);
        myWallpaperManager.setBitmap(bitmap);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
開發者ID:alepacheco,項目名稱:AndroRW,代碼行數:12,代碼來源:Helper.java

示例8: setWallPaper

import android.app.WallpaperManager; //導入方法依賴的package包/類
public static void setWallPaper(Context context,File file){
    WallpaperManager manager = WallpaperManager.getInstance(context);
    try {
        manager.setBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:wavever,項目名稱:GankLock,代碼行數:9,代碼來源:PhotoUtil.java

示例9: doInBackground

import android.app.WallpaperManager; //導入方法依賴的package包/類
@Override
protected Boolean doInBackground(Bitmap... params) {
    Bitmap bitmap = params[0];
    try {
        if (bitmap != null) {
            WallpaperManager wallpaperManager = WallpaperManager.getInstance(mContext);
            wallpaperManager.setBitmap(bitmap);
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
開發者ID:VernonLee,項目名稱:Theogony,代碼行數:15,代碼來源:SetWallpaperTask.java

示例10: onPostExecute

import android.app.WallpaperManager; //導入方法依賴的package包/類
@Override
protected void onPostExecute(Bitmap bitmap) {
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(mContext);
    try {
        wallpaperManager.setBitmap(bitmap);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        Toast.makeText(mContext, getString(R.string.msg_wallpaper_set), Toast.LENGTH_SHORT).show();
        materialDialog.dismiss();
    }
}
 
開發者ID:robertmathew,項目名稱:KeralaAttractions,代碼行數:13,代碼來源:DetailActivity.java

示例11: setWallpaper

import android.app.WallpaperManager; //導入方法依賴的package包/類
private void setWallpaper () {
    WallpaperManager manager = WallpaperManager.getInstance(this);
    boolean canSetWallpaper = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        canSetWallpaper &= manager.isWallpaperSupported();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        canSetWallpaper &= manager.isSetWallpaperAllowed();
    }
    if (canSetWallpaper) {
        Song song = PlayManager.getInstance(this).getCurrentSong();
        if (song != null) {
            Album album = song.getAlbumObj();
            if (album == null) {
                return;
            }
            File source = new File(album.getAlbumArt());
            if (source.exists()) {
                Bitmap bmp = BitmapFactory.decodeFile(source.getAbsolutePath());
                try {
                    manager.setBitmap(bmp);
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    bmp.recycle();
                }
            }
        }
    }
}
 
開發者ID:boybeak,項目名稱:BeMusic,代碼行數:31,代碼來源:PlayDetailActivity.java

示例12: setBitmapAsWallpaper

import android.app.WallpaperManager; //導入方法依賴的package包/類
public void setBitmapAsWallpaper(WallpaperManager wpManager, Bitmap wallpaperBitmap) {
    try {
        // Set wallpaper.
        wpManager.setBitmap(wallpaperBitmap);
        // Write to temp file (to enable saving).
        File tempfile = new File(this.getFilesDir(), "lastwlp.png");
        FileOutputStream outStream = new FileOutputStream(tempfile);
        wallpaperBitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
        // Enable Save menu option if inactive.
        invalidateOptionsMenu();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:glesik,項目名稱:wpgen,代碼行數:15,代碼來源:ColorsActivity.java

示例13: undoLastWallpaperChangeSync

import android.app.WallpaperManager; //導入方法依賴的package包/類
public void undoLastWallpaperChangeSync() throws IOException {
    Bitmap bitmap = retrieveLastWallpaper();
    if (bitmap != null) {
        WallpaperManager wallpaperMgr = WallpaperManager.getInstance(
                contextWeakReference.get());
        wallpaperMgr.setWallpaperOffsetSteps(0.5f, 1.0f);
        wallpaperMgr.setBitmap(bitmap);
    }
}
 
開發者ID:danielgimenes,項目名稱:NasaPic,代碼行數:10,代碼來源:SpacePicInteractor.java

示例14: setWallpaperNow

import android.app.WallpaperManager; //導入方法依賴的package包/類
/**
 * Set wallpaper
 */
private void setWallpaperNow(Bitmap source) throws IOException
{
	DisplayMetrics dm = CommonUtils.getDisplayMetrics(this);
	int status_bar_height = CommonUtils.getStatusBarHeight(this);
	getWindowManager().getDefaultDisplay().getMetrics(dm);
	int screenWidth = dm.widthPixels;
	int screenHeight = dm.heightPixels - status_bar_height;
	
	int bitmapWidth = source.getWidth();
	int bitmapHeight = source.getHeight();
	
	float scaleX = (screenWidth + 0.0f) / bitmapWidth;
	float scaleY = (screenHeight + 0.0f) / bitmapHeight;
	
	Log.D(TAG, "[scaleX=" + scaleX + ", scaleY=" + scaleY + "]");
	
	Bitmap tempBitmap = null;
	Bitmap targetBitmap = null;
	try
	{
		// 按比例縮放達到適配手機屏幕
		// targetBitmap = Bitmap.createBitmap(screenWidth, screenHeight,
		// Config.ARGB_8888);
		
		Matrix matrix = new Matrix();
		matrix.postScale(scaleX, scaleY);
		tempBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
		
		Log.D(TAG, "TargetBitmap: [width=" + tempBitmap.getWidth() + ", height=" + tempBitmap.getHeight() + "]");
		
		WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
		targetBitmap = Bitmap.createBitmap(screenWidth * 3, screenHeight, Config.ARGB_8888);
		Canvas canvas = new Canvas(targetBitmap);
		canvas.drawColor(Color.RED);
		canvas.drawBitmap(tempBitmap, 0, 0, null);
		canvas.drawBitmap(tempBitmap, screenWidth, 0, null);
		canvas.drawBitmap(tempBitmap, screenWidth * 2, 0, null);
		
		wallpaperManager.setBitmap(targetBitmap);
		
		showToastOnUiThread(R.string.hint_wallpaper_ok);
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}
	finally
	{
		if (tempBitmap != null && !tempBitmap.isRecycled())
		{
			tempBitmap.recycle();
			tempBitmap = null;
		}
		if (targetBitmap != null && !targetBitmap.isRecycled())
		{
			targetBitmap.recycle();
			targetBitmap = null;
		}
	}
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:64,代碼來源:WallpaperDisposeActivity.java

示例15: doInBackground

import android.app.WallpaperManager; //導入方法依賴的package包/類
@Override
protected Void doInBackground(Void... params) {

    try {

        final WallpaperManager wallpaperManager = WallpaperManager.getInstance(activity);

        Bitmap bitmap = MediaStore.Images.Media.getBitmap(activity.getContentResolver(), Uri.fromFile(new File(url)));

        wallpaperManager.setBitmap(bitmap);

    } catch (IOException ex) {
        ex.printStackTrace();
    }

    return null;
}
 
開發者ID:enricocid,項目名稱:Gallery-example,代碼行數:18,代碼來源:ApplyWallpaper.java


注:本文中的android.app.WallpaperManager.setBitmap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。