Example usage for android.app WallpaperManager getInstance

List of usage examples for android.app WallpaperManager getInstance

Introduction

In this page you can find the example usage for android.app WallpaperManager getInstance.

Prototype

public static WallpaperManager getInstance(Context context) 

Source Link

Document

Retrieve a WallpaperManager associated with the given Context.

Usage

From source file:com.paranoid.ParanoidWallpapers.Wallpaper.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mContext = this;

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new SimpleOnPageChangeListener() {

        public void onPageSelected(int position) {
            mCurrentFragment = position;

            // Check if item is customizable
            mCustomizable = (mCurrentFragment == 0);
            try {
                Method method = Wallpaper.class.getMethod("invalidateOptionsMenu", new Class[] {});
                method.invoke(Wallpaper.this);
            } catch (Exception e) {
            }// w w w.j  ava2 s.  c om
        }
    });

    mWallpapers.clear();

    final Resources resources = getResources();
    final String packageName = getPackageName();

    fetchWallpapers(resources, packageName, R.array.wallpapers);
    mWallpaperInfo = resources.getStringArray(R.array.info);
    mWallpaperManager = WallpaperManager.getInstance(mContext);

    mSectionsPagerAdapter.notifyDataSetChanged();
}

From source file:uk.co.humbell.anoted.MainActivity.java

private void setupTheme() {

    /*//from   ww w. ja  v a 2s .  c  o  m
     * We can't use android's resources before we set the theme ({@link #setTheme})
     * The constraints below need to be the same as the constants defined in
     * "res/values/strings_activity_settings.xml"
    */
    final String PREF_KEY_THEME = "pref_theme";
    final String PREF_KEY_ENABLE_TRANSPARENCY = "pref_transparency";
    final String PREF_VALUE_THEME_LIGHT = "light";
    final String PREF_VALUE_THEME_DARK = "dark";

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String theme = prefs.getString(PREF_KEY_THEME, PREF_VALUE_THEME_LIGHT);
    Boolean wantsTransparency = prefs.getBoolean(PREF_KEY_ENABLE_TRANSPARENCY, false);

    if (theme.equals(PREF_VALUE_THEME_DARK) && wantsTransparency == false) {
        setTheme(R.style.AppTheme);
    }

    else if (theme.equals(PREF_VALUE_THEME_DARK) && wantsTransparency == true) {
        setTheme(R.style.AppTheme_Trans_Dark);
    }

    else if (theme.equals(PREF_VALUE_THEME_LIGHT) && wantsTransparency == false) {
        setTheme(R.style.AppTheme_Light);
    }

    else if (theme.equals(PREF_VALUE_THEME_LIGHT) && wantsTransparency == true) {
        setTheme(R.style.AppTheme_Trans_Light);
    }

    if (wantsTransparency) {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
        getWindow().setBackgroundDrawable(wallpaperManager.getFastDrawable());
    }
}

From source file:com.xiaomi.account.utils.SysHelper.java

public static void blurWallpaper(Activity activity) {
    activity.getWindow().setBackgroundDrawable(WallpaperManager.getInstance(activity).getFastDrawable());
}

From source file:com.designrifts.ultimatethemeui.fragments.FragmentTheme.java

private void applyNovaTheme() {
    WallpaperManager setDefaultWallpaper = WallpaperManager.getInstance(getActivity().getApplicationContext());
    try {//  w  w w.  j a v a2 s.  co  m
        Intent novalauncherIntent = new Intent(ACTION_APPLY_ICON_THEME);
        novalauncherIntent.setPackage(NOVA_PACKAGE);
        novalauncherIntent.putExtra(EXTRA_ICON_THEME_TYPE, "GO");
        novalauncherIntent.putExtra(EXTRA_ICON_THEME_PACKAGE, getActivity().getPackageName());
        startActivity(novalauncherIntent);
        setDefaultWallpaper.setResource(R.drawable.wallpaper_default);

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //finish();
}

From source file:com.leo.runningman.ui.ImageDetailActivity.java

private void setWapaper(Bitmap bitmap) {
    try {/*  w  ww . j  av  a 2 s.c  o  m*/
        WallpaperManager wpm = WallpaperManager.getInstance(this);
        float minH = wpm.getDesiredMinimumHeight();
        float minW = wpm.getDesiredMinimumWidth();
        Bitmap targetBitmap = getResizedBitmap(bitmap, (int) minH, (int) minW);
        wpm.setBitmap(targetBitmap);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.example.app_2.utils.Utils.java

public static void setWallpaper(android.view.ViewGroup vg, int reqWidth, int reqHeight, Bitmap wallpaper,
        ScalingLogic sl) {//from w ww.  j a  v a 2  s  .  co  m

    if (wallpaper == null) {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(App_2.getAppContext());
        Drawable wallpaperDrawable = wallpaperManager.getDrawable();
        wallpaper = BitmapCalc.drawableToBitmap(wallpaperDrawable);
    }

    if (reqHeight == 0 || reqWidth == 0) {
        reqHeight = App_2.getMaxHeight();
        reqWidth = App_2.getMaxWidth();
    }

    Resources r = App_2.getAppContext().getResources();
    int orientation = r.getConfiguration().orientation;

    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE: // landscape
        Bitmap wallpaperLandscape = ScalingUtilities.createScaledBitmap(wallpaper, reqHeight, reqWidth, sl);
        if (Utils.hasJellyBean())
            vg.setBackground(new BitmapDrawable(r, wallpaperLandscape));
        else {
            if (vg instanceof LinearLayout) {
                LinearLayout ll = (LinearLayout) vg;
                ll.setBackgroundDrawable(new BitmapDrawable(r, wallpaperLandscape));
            } else if (vg instanceof DrawerLayout) {
                DrawerLayout dl = (DrawerLayout) vg;
                dl.setBackgroundDrawable(new BitmapDrawable(r, wallpaperLandscape));
            }

        }
        //wallpaperLandscape.recycle();
        break;
    case Configuration.ORIENTATION_PORTRAIT: // portrait
        Bitmap wallpaperPortrait = ScalingUtilities.createScaledBitmap(wallpaper, reqWidth, reqHeight, sl);

        if (Utils.hasJellyBean())
            vg.setBackground(new BitmapDrawable(r, wallpaperPortrait));
        else {
            if (vg instanceof LinearLayout) {
                LinearLayout ll = (LinearLayout) vg;
                ll.setBackgroundDrawable(new BitmapDrawable(r, wallpaperPortrait));
            } else if (vg instanceof DrawerLayout) {
                DrawerLayout dl = (DrawerLayout) vg;
                dl.setBackgroundDrawable(new BitmapDrawable(r, wallpaperPortrait));
            }
        }
        //wallpaperPortrait.recycle();
        break;
    default:
        //ll.setBackgroundDrawable(App_2.wallpaperDrawable);
        break;
    }
}

From source file:com.chale22.ico01.fragments.FragmentTheme.java

private void applyNovaTheme() {
    WallpaperManager setDefaultWallpaper = WallpaperManager.getInstance(getActivity().getApplicationContext());
    try {/*from   w w  w . ja  v a 2  s.  c o  m*/
        Intent novalauncherIntent = new Intent(ACTION_APPLY_ICON_THEME);
        novalauncherIntent.setPackage(NOVA_PACKAGE);
        novalauncherIntent.putExtra(EXTRA_ICON_THEME_TYPE, "GO");
        novalauncherIntent.putExtra(EXTRA_ICON_THEME_PACKAGE, getActivity().getPackageName());
        startActivity(novalauncherIntent);

    } catch (ActivityNotFoundException e3) {
        e3.printStackTrace();
        makeToast("Nova Launcher is not installed!");
    }
    //finish();
}

From source file:com.android.ted.gank.main.ViewerFragment.java

private void checkFileAndSetWallPaper(File file) {
    if (null != file && file.exists()) {
        //get the contentUri for this file and start the intent
        Uri contentUri = FileProvider.getUriForFile(getActivity(), "com.android.ted.gank.fileprovider", file);
        //get crop intent
        Intent intent = WallpaperManager.getInstance(getActivity()).getCropAndSetWallpaperIntent(contentUri);
        //start activity for result so we can animate if we finish
        getActivity().startActivityForResult(intent, ViewerActivity.REQUEST_CODE_SET_WALLPAPER);
    }/*w w w .jav  a2 s  .c  o m*/
}

From source file:it.gcaliendo.elytheme.fragments.FragmentTheme.java

private void applySmartTheme() {
    WallpaperManager setDefaultWallpaper = WallpaperManager.getInstance(getActivity().getApplicationContext());
    Intent smart = getActivity().getPackageManager().getLaunchIntentForPackage("ginlemon.flowerfree");
    Intent smartpro = getActivity().getPackageManager().getLaunchIntentForPackage("ginlemon.flowerpro");
    if (smart != null) {
        Intent smartlauncherIntent = new Intent(SMART_PACKAGE);
        smartlauncherIntent.putExtra("package", getActivity().getPackageName());
        startActivity(smartlauncherIntent);
    } else if (smartpro != null) {
        Intent smartlauncherIntent = new Intent(SMART_PACKAGE);
        smartlauncherIntent.putExtra("package", getActivity().getPackageName());
        startActivity(smartlauncherIntent);
    } else {/*from  w w  w . java  2s .  c om*/
        // Direct users to get Smart Launcher
        String playStoreUrl = "https://play.google.com/store/apps/details?id=ginlemon.flowerfree";
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(playStoreUrl)));
    }
}

From source file:com.sky.drovik.player.bitmapfun.ImageDetailActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.set_wallpaper:
        //NavUtils.navigateUpFromSameTask(this);
        Bitmap b = mImageFetcher.processBitmap(Main.getImgagePath(mPager.getCurrentItem(), cataLog));
        System.out.println("b= " + b);
        if (b == null) {
            return false;
        }//  ww  w . j a va2 s. c om
        try {
            WallpaperManager.getInstance(ImageDetailActivity.this).setBitmap(b);
            Toast.makeText(this, R.string.set_wall_paper_menu_toast, Toast.LENGTH_SHORT).show();
            StatService.onEvent(this, "", " ");
        } catch (IOException e) {
            Log.d("ImageDetailActivity", "### " + e.getLocalizedMessage());
            StatService.onEvent(this, "", " ");
        }
        return true;
    case R.id.clear_cache:
        mImageFetcher.clearCache();
        StatService.onEvent(this, "", " ");
        Toast.makeText(this, R.string.clear_cache_complete_toast, Toast.LENGTH_SHORT).show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}