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


Java WallpaperManager類代碼示例

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


WallpaperManager類屬於android.app包,在下文中一共展示了WallpaperManager類的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: onLayout

import android.app.WallpaperManager; //導入依賴的package包/類
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
            int childLeft = lp.x;
            int childTop = lp.y;
            child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);//對子對象進行布局。

            if (lp.dropped) {
                lp.dropped = false;

                final int[] cellXY = mTmpCellXY;
                getLocationOnScreen(cellXY);
                mWallpaperManager.sendWallpaperCommand(getWindowToken(),
                        WallpaperManager.COMMAND_DROP,
                        cellXY[0] + childLeft + lp.width / 2,
                        cellXY[1] + childTop + lp.height / 2, 0, null);
            }
        }
    }
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:25,代碼來源:ShortcutAndWidgetContainer.java

示例3: onLayout

import android.app.WallpaperManager; //導入依賴的package包/類
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();

            if (child instanceof LauncherAppWidgetHostView) {
                LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) child;

                // Scale and center the widget to fit within its cells.
                DeviceProfile profile = mLauncher.getDeviceProfile();
                float scaleX = profile.appWidgetScale.x;
                float scaleY = profile.appWidgetScale.y;

                lahv.setScaleToFit(Math.min(scaleX, scaleY));
                lahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f,
                        -(lp.height - (lp.height * scaleY)) / 2.0f);
            }

            int childLeft = lp.x;
            int childTop = lp.y;
            child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);

            if (lp.dropped) {
                lp.dropped = false;

                final int[] cellXY = mTmpCellXY;
                getLocationOnScreen(cellXY);
                mWallpaperManager.sendWallpaperCommand(getWindowToken(),
                        WallpaperManager.COMMAND_DROP,
                        cellXY[0] + childLeft + lp.width / 2,
                        cellXY[1] + childTop + lp.height / 2, 0, null);
            }
        }
    }
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:39,代碼來源:ShortcutAndWidgetContainer.java

示例4: Workspace

import android.app.WallpaperManager; //導入依賴的package包/類
/**
 * Used to inflate the Workspace from XML.
 *
 * @param context The application's context.
 * @param attrs The attributes set containing the Workspace's customization values.
 * @param defStyle Unused.
 */
public Workspace(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mLauncher = Launcher.getLauncher(context);
    mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
    final Resources res = getResources();
    DeviceProfile grid = mLauncher.getDeviceProfile();
    mWorkspaceFadeInAdjacentScreens = grid.shouldFadeAdjacentWorkspaceScreens();
    mWallpaperManager = WallpaperManager.getInstance(context);

    mWallpaperOffset = new WallpaperOffsetInterpolator(this);
    mOverviewModeShrinkFactor =
            res.getInteger(R.integer.config_workspaceOverviewShrinkPercentage) / 100f;

    setOnHierarchyChangeListener(this);
    setHapticFeedbackEnabled(false);

    initWorkspace();

    // Disable multitouch across the workspace/all apps/customize tray
    setMotionEventSplittingEnabled(true);
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:30,代碼來源:Workspace.java

示例5: onCreate

import android.app.WallpaperManager; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences);

    Preference applyWallpaper = findPreference("applyWallpaper");
    applyWallpaper.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(
                    WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);

            intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                    new ComponentName(getActivity(), Wallpaper.class));

            startActivity(intent);

            return true;
        }
    });
}
 
開發者ID:jajasuperman,項目名稱:HexColorTime,代碼行數:24,代碼來源:Preferences.java

示例6: screenshotWithWallpaper

import android.app.WallpaperManager; //導入依賴的package包/類
public static Bitmap screenshotWithWallpaper(Context context, View view, Rect clipRect) {

        Bitmap bitmap = Bitmap.createBitmap(clipRect.width(), clipRect.height(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);

        // Translate for clipRect.
        canvas.translate(-clipRect.left, -clipRect.top);

        Drawable wallpaper = WallpaperManager.getInstance(context).getFastDrawable();
        // Center wallpaper on screen, as in launcher.
        DisplayMetrics displayMetrics = view.getResources().getDisplayMetrics();
        wallpaper.setBounds(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
        // Translate the canvas to draw wallpaper on the correct location.
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        canvas.save();
        canvas.translate(-location[0], -location[1]);
        wallpaper.draw(canvas);
        canvas.restore();

        view.draw(canvas);

        return bitmap;
    }
 
開發者ID:HanyeeWang,項目名稱:GeekZone,代碼行數:26,代碼來源:ScreenshotUtils.java

示例7: setWallpaper

import android.app.WallpaperManager; //導入依賴的package包/類
private void setWallpaper() {
    Observable.just(null)
            .compose(bindToLifecycle())
            .compose(ensurePermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE))
            .filter(granted -> {
                if (granted) {
                   return true;
                } else {
                    Toasty.info(this, getString(R.string.permission_required),
                            Toast.LENGTH_LONG).show();
                    return false;
                }
            })
            .flatMap(granted -> download(picture.downloadUrl))
            .map(file -> FileProvider.getUriForFile(this, AUTHORITIES, file))
            .doOnNext(uri -> {
                final WallpaperManager wm = WallpaperManager.getInstance(this);
                startActivity(wm.getCropAndSetWallpaperIntent(uri));
            })
            .subscribe();
}
 
開發者ID:Assassinss,項目名稱:Moment,代碼行數:22,代碼來源:PictureActivity.java

示例8: setLiveWallpaper

import android.app.WallpaperManager; //導入依賴的package包/類
/**
 * 跳轉到係統設置壁紙界麵
 *
 * @param context
 * @param paramActivity
 */
public static void setLiveWallpaper(Context context, Activity paramActivity, int requestCode) {
    try {
        Intent localIntent = new Intent();
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {//ICE_CREAM_SANDWICH_MR1  15
            localIntent.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);//android.service.wallpaper.CHANGE_LIVE_WALLPAPER
            //android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT
            localIntent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT
                    , new ComponentName(context.getApplicationContext().getPackageName()
                            , LiveWallpaperService.class.getCanonicalName()));
        } else {
            localIntent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);//android.service.wallpaper.LIVE_WALLPAPER_CHOOSER
        }
        paramActivity.startActivityForResult(localIntent, requestCode);
    } catch (Exception localException) {
        localException.printStackTrace();
    }
}
 
開發者ID:coolspan,項目名稱:LiveWallpaper,代碼行數:24,代碼來源:WallpaperUtil.java

示例9: initSetWallpaperPrompt

import android.app.WallpaperManager; //導入依賴的package包/類
/**
 * Prompt the user to set our app as live wallpaper if the user has not set it.
 */
private void initSetWallpaperPrompt() {
    final WallpaperManager wm = WallpaperManager.getInstance(getApplicationContext());
    if ((wm.getWallpaperInfo() != null && wm.getWallpaperInfo().getPackageName().equalsIgnoreCase(getPackageName()))) {
        // We are good
    } else {
        // Ask user.
        Snackbar.make(binding.coordinatorLayout, R.string.set_live_wallpaper_promt, Snackbar.LENGTH_INDEFINITE)
                .setAction(android.R.string.ok, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        launchSetWallpaperScreen();
                    }
                }).show();
    }
}
 
開發者ID:arunkumar9t2,項目名稱:chameleon-live-wallpaper,代碼行數:19,代碼來源:MainActivity.java

示例10: loadWallpaper

import android.app.WallpaperManager; //導入依賴的package包/類
protected void loadWallpaper() {
    new AsyncTask<Void, Void, Bitmap>() {
        @Override
        protected void onPostExecute(Bitmap bitmap) {
            mWallPaperView.showWallPaper(bitmap);
            SetLockWallPaper(bitmap);
        }

        @Override
        protected Bitmap doInBackground(Void... params) {
            WallpaperManager wallpaperManager = WallpaperManager
                    .getInstance(mContext);
            // 獲取當前壁紙
            return ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
        }
    }.execute();
}
 
開發者ID:auv1107,項目名稱:TextEmoji,代碼行數:18,代碼來源:WallpaperPresenter.java

示例11: setDefaultOnLock

import android.app.WallpaperManager; //導入依賴的package包/類
private boolean setDefaultOnLock(WallpaperPickerActivity a) {
    boolean succeeded = true;
    try {
        Bitmap defaultWallpaper = ((BitmapDrawable) WallpaperManager.getInstance(
                a.getApplicationContext()).getBuiltInDrawable()).getBitmap();
        ByteArrayOutputStream tmpOut = new ByteArrayOutputStream(2048);
        if (defaultWallpaper.compress(Bitmap.CompressFormat.PNG, 100, tmpOut)) {
            byte[] outByteArray = tmpOut.toByteArray();
            WallpaperManagerCompat.getInstance(a.getApplicationContext())
                    .setStream(new ByteArrayInputStream(outByteArray), null,
                            true, WallpaperManagerCompat.FLAG_SET_LOCK);
        }
    } catch (IOException e) {
        Log.w(TAG, "Setting wallpaper to default threw exception", e);
        succeeded = false;
    }
    return succeeded;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:19,代碼來源:DefaultWallpaperInfo.java

示例12: onLayout

import android.app.WallpaperManager; //導入依賴的package包/類
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
            int childLeft = lp.x;
            int childTop = lp.y;
            child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);

            if (lp.dropped) {
                lp.dropped = false;

                final int[] cellXY = mTmpCellXY;
                getLocationOnScreen(cellXY);
                mWallpaperManager.sendWallpaperCommand(getWindowToken(),
                        WallpaperManager.COMMAND_DROP,
                        cellXY[0] + childLeft + lp.width / 2,
                        cellXY[1] + childTop + lp.height / 2, 0, null);
            }
        }
    }
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:25,代碼來源:ShortcutAndWidgetContainer.java

示例13: setWallpaper

import android.app.WallpaperManager; //導入依賴的package包/類
private void setWallpaper() {
    try {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
        InputStream inputStream = getContentResolver().openInputStream(imageUri);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            Rect croppedRect = getCroppedRect();
            wallpaperManager.setStream(inputStream, croppedRect, true);
        } else {
            wallpaperManager.setStream(inputStream);
        }

        SubsamplingScaleImageView imageView = findViewById(R.id.imageView);
        imageView.recycle();

        this.finish();
    } catch (IOException | IllegalArgumentException e) {
        e.printStackTrace();
        Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
    }
}
 
開發者ID:kollerlukas,項目名稱:Camera-Roll-Android-App,代碼行數:21,代碼來源:SetWallpaperActivity.java

示例14: onClick

import android.app.WallpaperManager; //導入依賴的package包/類
@Override
public void onClick(WallpaperPickerActivity a) {
    CropView c = a.getCropView();
    Drawable defaultWallpaper = WallpaperManager.getInstance(a.getContext())
            .getBuiltInDrawable(c.getWidth(), c.getHeight(), false, 0.5f, 0.5f);
    if (defaultWallpaper == null) {
        Log.w(TAG, "Null default wallpaper encountered.");
        c.setTileSource(null, null);
        return;
    }

    LoadRequest req = new LoadRequest();
    req.moveToLeft = false;
    req.touchEnabled = false;
    req.scaleAndOffsetProvider = new CropViewScaleAndOffsetProvider();
    req.result = new DrawableTileSource(a.getContext(),
            defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE);
    a.onLoadRequestComplete(req, true);
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:20,代碼來源:WallpaperPickerActivity.java

示例15: onClick

import android.app.WallpaperManager; //導入依賴的package包/類
@Override
public void onClick(WallpaperPickerActivity a) {
    CropView c = a.getCropView();
    Drawable defaultWallpaper = WallpaperManager.getInstance(a.getContext())
            .getBuiltInDrawable(c.getWidth(), c.getHeight(), false, 0.5f, 0.5f);
    if (defaultWallpaper == null) {
        Log.w(TAG, "Null default wallpaper encountered.");
        c.setTileSource(null, null);
        return;
    }

    LoadRequest req = new LoadRequest();
    req.moveToLeft = false;
    req.touchEnabled = false;
    req.scaleProvider = new CropViewScaleProvider() {

        @Override
        public float getScale(TileSource src) {
            return 1f;
        }
    };
    req.result = new DrawableTileSource(a.getContext(),
            defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE);
    a.onLoadRequestComplete(req, true);
}
 
開發者ID:Mr-lin930819,項目名稱:SimplOS,代碼行數:26,代碼來源:WallpaperPickerActivity.java


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