@Override public void onResume() { super.onResume(); Set<String> transitions = Preferences.General.Transitions.getSelectedTransitions(getActivity()); Set<String> effects = Preferences.General.Effects.getSelectedEffects(getActivity()); Set<String> borders = Preferences.General.Borders.getSelectedBorders(getActivity()); mTransitionsTypes.setValues(transitions); updateTransitionTypeSummary(transitions); mEffectsTypes.setValues(effects); updateEffectTypeSummary(effects); mBordersTypes.setValues(borders); updateBorderTypeSummary(borders); // Update set wallpaper status WallpaperInfo info = WallpaperManager.getInstance(getActivity()).getWallpaperInfo(); mSetAsWallpaper.setEnabled(info == null || !info.getPackageName().equals(getActivity().getPackageName())); }
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); applyItem = menu.findItem(R.id.action_apply); setBagelItem = menu.findItem(R.id.action_set); deleteItem = menu.findItem(R.id.action_delete); WallpaperInfo info = WallpaperManager.getInstance(this).getWallpaperInfo(); applyItem.setVisible(info == null || !info.getPackageName().matches(getPackageName())); return super.onCreateOptionsMenu(menu); }
public void setTransparent() { if (status != null && wallpaperManager != null) { Drawable backgroundDrawable; WallpaperInfo wallpaperInfo = wallpaperManager.getWallpaperInfo(); if (wallpaperInfo != null) backgroundDrawable = wallpaperInfo.loadThumbnail(getContext().getPackageManager()); else { try { backgroundDrawable = wallpaperManager.getDrawable(); } catch (SecurityException e) { setColor(getDefaultColor()); return; } } Bitmap background = ImageUtils.cropBitmapToBar(getContext(), ImageUtils.drawableToBitmap(backgroundDrawable)); if (background != null) { int color = ColorUtils.getAverageColor(background); Boolean transparent = PreferenceUtils.getBooleanPreference(getContext(), PreferenceUtils.PreferenceIdentifier.STATUS_HOME_TRANSPARENT); if (transparent == null || transparent) { status.setBackground(new BitmapDrawable(getResources(), background)); setDarkMode(!ColorUtils.isColorDark(color)); StatusView.this.color = color; } else setColor(color); } else setColor(getDefaultColor()); } }
public static boolean isWallpaperActivated() { final WallpaperManager wallpaperManager = WallpaperManager.getInstance(sApplication); final WallpaperInfo wallpaperInfo = wallpaperManager.getWallpaperInfo(); boolean active = wallpaperInfo != null && sApplication.getPackageName().equalsIgnoreCase(wallpaperInfo.getPackageName()); LWQLoggerHelper.get().logWallpaperActive(active); return active; }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == IMAGE_PICK && resultCode == RESULT_OK) { if (data != null && data.getData() != null) { Uri uri = data.getData(); addTemporaryWallpaperTile(uri, false); } } else if (requestCode == PICK_WALLPAPER_THIRD_PARTY_ACTIVITY) { setResult(RESULT_OK); finish(); } else if (requestCode == PICK_LIVE_WALLPAPER) { WallpaperManager wm = WallpaperManager.getInstance(this); final WallpaperInfo oldLiveWallpaper = mLiveWallpaperInfoOnPickerLaunch; final WallpaperInfo clickedWallpaper = mLastClickedLiveWallpaperInfo; WallpaperInfo newLiveWallpaper = wm.getWallpaperInfo(); // Try to figure out if a live wallpaper was set; if (newLiveWallpaper != null && (oldLiveWallpaper == null || !oldLiveWallpaper.getComponent() .equals(newLiveWallpaper.getComponent()) || clickedWallpaper.getComponent() .equals(oldLiveWallpaper.getComponent()))) { // Return if a live wallpaper was set setResult(RESULT_OK); finish(); } } }
private void toast4Live() { if (bundle == null) { try { WallpaperInfo info = wm.getWallpaperInfo(); if (info != null) { info.toString(); mUtils.sendToast(mResources.getString(R.string.last_known_current_live)); } } catch (NullPointerException ignore) { } } }
private void setWallpaper() { final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); final WallpaperInfo wallpaperInfo = wallpaperManager.getWallpaperInfo(); String wallpaperId; if (isCustom) { wallpaperId = Constants.BG_CUSTOM_ID; } else { wallpaperId = catalogItem.getId(); } sharedPreferences.edit().putString(PREF_BACKGROUND, wallpaperId).apply(); boolean zeroAsLive = true; // Check if Zero is the current live wallpaper if (wallpaperInfo == null) { zeroAsLive = false; } else { if (!wallpaperInfo.getServiceName().equals(SERVICE_NAME)) { zeroAsLive = false; } } if (!zeroAsLive) { // Show dialog new AlertDialog.Builder(this) .setTitle(R.string.set_dialog_notzero_title) .setMessage(R.string.set_dialog_notzero_message) .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Show live-wallpaper preview openLWSetter(context); } }) .setNegativeButton(R.string.common_cancel, null) .show(); } else { Toast.makeText(context, R.string.set_alert_changed, Toast.LENGTH_SHORT).show(); } }
public LiveWallpaperInfo(Drawable thumbnail, WallpaperInfo info) { mThumbnail = thumbnail; mInfo = info; }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { switch (requestCode) { case REQUEST_IMAGE: int size = prefs.getInt(Bagels.BAGELS_SIZE_KEY, 0); SharedPreferences.Editor editor = prefs.edit(); for (int i = 1; i <= size; i++) { editor.putString(Bagels.BAGELS_KEY + i, prefs.getString(Bagels.BAGELS_KEY + (i - 1), null)); } String path = data.getDataString(); try { Cursor cursor = getContentResolver().query(data.getData(), null, null, null, null); String documentId; if (cursor != null) { cursor.moveToFirst(); documentId = cursor.getString(0); documentId = documentId.substring(documentId.lastIndexOf(":") + 1); cursor.close(); } else break; cursor = getContentResolver().query(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Images.Media._ID + " = ? ", new String[]{documentId}, null); if (cursor != null) { cursor.moveToFirst(); path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)); cursor.close(); } } catch (Exception e) { e.printStackTrace(); } editor.putString(Bagels.BAGELS_KEY + 0, path).putInt(Bagels.BAGELS_SIZE_KEY, size + 1).apply(); ((Bagels) getApplicationContext()).getBagels(new Bagels.BagelsListener() { @Override public void onBagels(List<Bagel> bagels) { adapter = new BagelAdapter(getSupportFragmentManager(), bagels); if (viewPager != null) { viewPager.setAdapter(adapter); onPageChange(viewPager.getCurrentItem()); } } }); break; case REQUEST_WALLPAPER: WallpaperInfo info = WallpaperManager.getInstance(this).getWallpaperInfo(); applyItem.setVisible(info == null || !info.getPackageName().matches(getPackageName())); break; } } }
public LiveWallpaperTile(Drawable thumbnail, WallpaperInfo info, Intent intent) { mThumbnail = thumbnail; mInfo = info; }
public void onLiveWallpaperPickerLaunch(WallpaperInfo info) { mLastClickedLiveWallpaperInfo = info; mLiveWallpaperInfoOnPickerLaunch = WallpaperManager.getInstance(this).getWallpaperInfo(); }
public static boolean isCurrent(Context context) { WallpaperManager wm = WallpaperManager.getInstance(context); WallpaperInfo wi = wm.getWallpaperInfo(); return wi != null && new ComponentName(context, EarthWallpaperService.class) .equals(wi.getComponent()); }
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction() != null) { mUtils = new Utils(context); prefs = context.getSharedPreferences(C.PREF, Context.MODE_PRIVATE); if (String.valueOf(intent.getAction()).equals("com.lithidsw.wallbox.UPDATE_RANDOMIZER_WALL")) { int interval = prefs.getInt(C.PREF_RANDOMIZER_INTERVAL, 0); if (interval > 0) { final Context con = context; Thread thread = new Thread() { @Override public void run() { String item = new Utils(con).setRandomizerWallpaperFromFile(); if (item != null) { prefs.edit().putString(C.PREF_LAST_RANDOMIZER_MD5, item).commit(); } } }; thread.start(); } } if (String.valueOf(intent.getAction()).equals("com.lithidsw.wallbox.UPDATE_SATURATE_WALL")) { WallpaperManager wm = WallpaperManager.getInstance(context); try { WallpaperInfo info = wm.getWallpaperInfo(); info.toString(); mUtils.stopSaturatedAlarms(); prefs.edit().putBoolean(C.PREF_SATURATE_START, false).commit(); } catch (NullPointerException e) { int randInt = prefs.getInt(C.PREF_RANDOMIZER_INTERVAL, 0); if (randInt <= 0) { mUtils.setSaturatedWallpaperFromFile(false); } else { mUtils.setSaturatedWallpaperFromFile(true); } } } } }
public void init () { WallpaperManager wpman = WallpaperManager.getInstance (this.context); this.img = wpman.getDrawable (); try { //TODO// Huge memory hog! Need to get rid of this. // SharedPreferences prefs = this.context.getSharedPreferences ("prefs", Context.MODE_PRIVATE); this.mode = prefs.getString ("unitywallpaper_blur", "darken"); if (mode.equals ("scale")) { Drawable blurred = wpman.getDrawable (); BitmapDrawable bmdBlurred = (BitmapDrawable) blurred; Bitmap bmBlurred = bmdBlurred.getBitmap (); float origWidth = bmBlurred.getWidth (); float origHeight = bmBlurred.getHeight (); int width = 200; int height = (int) (origHeight * (200F / origWidth)); bmBlurred = Bitmap.createScaledBitmap (bmBlurred, width, height, true); bmBlurred = Bitmap.createScaledBitmap (bmBlurred, (int) origWidth, (int) origHeight, true); bmdBlurred = new BitmapDrawable (bmBlurred); this.blurred = bmdBlurred; } } catch (OutOfMemoryError ex) // I'd prefer the image not being blurred over the app crashing // { this.blurred = null; ex.printStackTrace (); } WallpaperInfo info = wpman.getWallpaperInfo (); this.liveWallpaper = (info != null); }
/** * 判断是否是使用我们的壁纸 * * @param paramContext * @return */ public static boolean wallpaperIsUsed(Context paramContext) { WallpaperInfo localWallpaperInfo = WallpaperManager.getInstance(paramContext).getWallpaperInfo(); return ((localWallpaperInfo != null) && (localWallpaperInfo.getPackageName().equals(paramContext.getPackageName())) && (localWallpaperInfo.getServiceName().equals(LiveWallpaperService.class.getCanonicalName()))); }