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.intellisol.plugin.Wallpaper.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    try {//from w  w w  .j a  v a  2s.  c  o  m
        // get path from argument
        String path = args.getString(0);

        // get context (Android)
        Context ctxt = cordova.getActivity().getBaseContext();
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(ctxt);

        // get image file
        InputStream bitmapIn = cordova.getActivity().getAssets().open(path);
        Bitmap bitmap = BitmapFactory.decodeStream(bitmapIn);

        // set wallpaper
        wallpaperManager.setBitmap(bitmap);

    } catch (JSONException e) {
        // log error
        Log.d("Wallpaper", e.toString());
        return false;
    } catch (Exception e) {
        // log error
        Log.d("Wallpaper", e.toString());
        return false;
    }
    return true;
}

From source file:com.android.launcher3.dynamicui.ExtractionUtils.java

private static boolean hasWallpaperIdChanged(Context context) {
    if (!Utilities.isNycOrAbove()) {
        // TODO: update an id in sharedprefs in onWallpaperChanged broadcast, and read it here.
        return false;
    }//from w w w . j  a  v  a2  s . co m
    final SharedPreferences sharedPrefs = Utilities.getPrefs(context);
    int wallpaperId = getWallpaperId(WallpaperManager.getInstance(context));
    int savedWallpaperId = sharedPrefs.getInt(ExtractionUtils.WALLPAPER_ID_PREFERENCE_KEY, -1);
    return wallpaperId != savedWallpaperId;
}

From source file:com.lithidsw.wallbox.app.saturate.SaturateFrag.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    fa = super.getActivity();
    ll = (LinearLayout) inflater.inflate(R.layout.saturate_frag, container, false);
    prefs = fa.getSharedPreferences(C.PREF, Context.MODE_PRIVATE);
    mUtils = new Utils(fa);
    wm = WallpaperManager.getInstance(fa);
    image = (ImageView) ll.findViewById(R.id.main_image);
    try {/*from   w ww  . j  av a  2s.  c om*/
        WallpaperInfo info = wm.getWallpaperInfo();
        info.toString();
        mUtils.sendToast(getResources().getString(R.string.live_wallpaper));
    } catch (NullPointerException ignore) {
    }
    time_text = (TextView) ll.findViewById(R.id.time_text);
    seek = (SeekBar) ll.findViewById(R.id.seeker);
    seek.setMax(23);
    Calendar cal = Calendar.getInstance();
    hour = cal.get(Calendar.HOUR_OF_DAY);
    time_text.setText(mUtils.getHour(hour));
    seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar v, int num, boolean isU) {
            if (!isRunning) {
                time_text.setText(mUtils.getHour(num));
                seekerFl = mUtils.getFloat(num);
                Drawable d = mUtils.convertToGrayscale(wm.getDrawable(), seekerFl);
                image.setImageDrawable(d);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub
        }
    });

    if (!prefs.getBoolean(C.PREF_SATURATE_FIRST_RUN_MAIN, false)) {
        prefs.edit().putBoolean(C.PREF_SATURATE_FIRST_RUN_MAIN, true).commit();
        String title = getResources().getString(R.string.main_title_saturate);
        String message = getResources().getString(R.string.saturate_description);
        new CustomDialogs().openFirstDialog(fa, title, message);
    }
    setHasOptionsMenu(true);
    return ll;
}

From source file:com.lithidsw.wallbox.app.wallsnap.WallSnapFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mActivity = super.getActivity();
    mResources = mActivity.getResources();
    mLayout = (LinearLayout) inflater.inflate(R.layout.wallsnap_frag, container, false);
    if (mLayout != null) {
        bundle = getArguments();/*from  w  w w.ja v a  2 s  . co  m*/
        wm = WallpaperManager.getInstance(mActivity);
        mUtils = new Utils(mActivity);
        prefs = mActivity.getSharedPreferences(C.PREF, Context.MODE_PRIVATE);
        mSeekBlur = (SeekBar) mLayout.findViewById(R.id.blur_seeker);
        mSeekBlur.setOnSeekBarChangeListener(this);
        mSeekSat = (SeekBar) mLayout.findViewById(R.id.sat_seeker);
        mSeekSat.setOnSeekBarChangeListener(this);
        mSeekHue = (SeekBar) mLayout.findViewById(R.id.hue_seeker);
        mSeekHue.setOnSeekBarChangeListener(this);
        mSeekBright = (SeekBar) mLayout.findViewById(R.id.bright_seeker);
        mSeekBright.setOnSeekBarChangeListener(this);
        mSeekContrast = (SeekBar) mLayout.findViewById(R.id.contrast_seeker);
        mSeekContrast.setOnSeekBarChangeListener(this);
        mLayoutMainClick = (LinearLayout) mLayout.findViewById(R.id.main_layout);
        mLayoutMainClick.setOnClickListener(this);
        mImageView = (ImageView) mLayout.findViewById(R.id.main_image);
        mImageView.setImageDrawable(getMainDrawable());
        setSeekers();
    }

    if (!prefs.getBoolean(C.PREF_WALLSNAP_FIRST_RUN_MAIN, false)) {
        prefs.edit().putBoolean(C.PREF_WALLSNAP_FIRST_RUN_MAIN, true).commit();
        String title = mResources.getString(R.string.main_title_wallsnap);
        String message = mResources.getString(R.string.wallsnap_description);
        new CustomDialogs().openFirstDialog(mActivity, title, message);
    }
    setHasOptionsMenu(true);
    return mLayout;
}

From source file:arun.com.chameleonskinforkwlp.MainActivity.java

/**
 * Prompt the user to set our app as live wallpaper if the user has not set it.
 *///  ww  w  . j a  v a 2  s.co m
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();
    }
}

From source file:jahirfiquitiva.iconshowcase.tasks.ApplyWallpaper.java

@Override
protected Boolean doInBackground(Void... params) {
    Boolean worked = false;/*from   w  ww.j av  a2  s. co m*/
    if ((!wasCancelled) && (activity != null)) {
        WallpaperManager wm = WallpaperManager.getInstance(activity);
        try {
            try {
                wm.setBitmap(scaleToActualAspectRatio(resource));
            } catch (OutOfMemoryError ex) {
                if (ShowcaseActivity.DEBUGGING)
                    Utils.showLog(activity, "OutOfMemoryError: " + ex.getLocalizedMessage());
                showRetrySnackbar();
            }
            worked = true;
        } catch (IOException e2) {
            worked = false;
        }
    } else {
        worked = false;
    }
    return worked;
}

From source file:com.lithidsw.wallbox.app.colorwall.ColorWallFrag.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    fa = super.getActivity();
    prefs = fa.getSharedPreferences(C.PREF, Context.MODE_PRIVATE);
    ll = (LinearLayout) inflater.inflate(R.layout.colorwall_frag, container, false);
    mColorCode = (EditText) ll.findViewById(R.id.color_code);
    mColorCode.addTextChangedListener(new TextWatcher() {
        @Override/*w w  w  . j  a v a2 s. com*/
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() == 7) {
                if (s.toString().startsWith("#")) {
                    try {
                        mColor = Color.parseColor(s.toString());
                        mPicker.setImageDrawable(new ColorDrawable(mColor));
                    } catch (NumberFormatException e) {
                        mColorCode.setText("");
                        Toast.makeText(fa, "Invalid color format: " + s.toString()
                                + "\nPlease use a valid 6 digit color code", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    mColorCode.setText("");
                    Toast.makeText(fa, "Needs to start with # symbol before color code", Toast.LENGTH_SHORT)
                            .show();
                }
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    wm = WallpaperManager.getInstance(fa);
    ll.findViewById(R.id.color_black).setOnClickListener(this);
    ll.findViewById(R.id.color_white).setOnClickListener(this);
    ll.findViewById(R.id.color_blue).setOnClickListener(this);
    ll.findViewById(R.id.color_green).setOnClickListener(this);
    ll.findViewById(R.id.color_purple).setOnClickListener(this);
    ll.findViewById(R.id.color_yellow).setOnClickListener(this);
    ll.findViewById(R.id.color_red).setOnClickListener(this);

    mPicker = (ImageView) ll.findViewById(R.id.picker);

    if (!prefs.getBoolean(C.PREF_COLORWALL_FIRST_RUN_MAIN, false)) {
        prefs.edit().putBoolean(C.PREF_COLORWALL_FIRST_RUN_MAIN, true).commit();
        String title = getResources().getString(R.string.main_title_colorwall);
        String message = getResources().getString(R.string.colorwall_description);
        new CustomDialogs().openFirstDialog(fa, title, message);
    }
    setHasOptionsMenu(true);
    return ll;
}

From source file:cw.kop.autobackground.settings.AppSettings.java

public static void initPrefs(SharedPreferences preferences, Context context) {
    prefs = preferences;//from   w  w w  .  ja v a  2  s . c  om
    if (isFirstRun()) {
        prefs.edit().putString("user_width",
                "" + (WallpaperManager.getInstance(context).getDesiredMinimumWidth() / 2)).commit();
        prefs.edit().putString("user_height",
                "" + (WallpaperManager.getInstance(context).getDesiredMinimumHeight() / 2)).commit();
        setNotificationOptionTitle(0, "Copy");
        setNotificationOptionTitle(1, "Cycle");
        setNotificationOptionTitle(2, "Delete");
        setNotificationOptionDrawable(0, R.drawable.ic_content_copy_white_24dp);
        setNotificationOptionDrawable(1, R.drawable.ic_refresh_white_24dp);
        setNotificationOptionDrawable(2, R.drawable.ic_delete_white_24dp);
        prefs.edit().putBoolean("use_timer", true).commit();
        setTimerDuration(172800000);
        prefs.edit().putBoolean("first_run", false).commit();
    }
}

From source file:info.tellmetime.DaydreamService.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    setInteractive(true);//from w w  w  .  ja  va  2s  .com

    setFullscreen(true);

    setContentView(R.layout.daydream);

    LinearLayout mClock = (LinearLayout) findViewById(R.id.clock);

    SharedPreferences settings = getSharedPreferences("PREFS", Context.MODE_PRIVATE);
    mHighlightColor = settings.getInt(TellmetimeActivity.HIGHLIGHT, Color.WHITE);
    mBacklightColor = settings.getInt(TellmetimeActivity.BACKLIGHT,
            getResources().getColor(R.color.backlight_light));
    mMinutesSize = settings.getInt(TellmetimeActivity.MINUTES_SIZE, 36);
    isNightMode = settings.getBoolean(TellmetimeActivity.NIGHTMODE, false);

    setScreenBright(!isNightMode);
    findViewById(R.id.overlay).setBackgroundColor(
            getResources().getColor(isNightMode ? R.color.night_mode_overlay : android.R.color.transparent));

    RelativeLayout mSurface = (RelativeLayout) findViewById(R.id.surface);
    mSurface.setBackgroundColor(
            settings.getInt(TellmetimeActivity.BACKGROUND, getResources().getColor(R.color.background)));
    switch (settings.getInt(TellmetimeActivity.BACKGROUND_MODE, TellmetimeActivity.MODE_BACKGROUND_SOLID)) {
    case TellmetimeActivity.MODE_BACKGROUND_WALLPAPER:
        ((ImageView) findViewById(R.id.background_image))
                .setImageDrawable(WallpaperManager.getInstance(this).getDrawable());
        break;

    case TellmetimeActivity.MODE_BACKGROUND_IMAGE:
        try {
            ((ImageView) findViewById(R.id.background_image)).setImageBitmap(BitmapFactory.decodeStream(
                    new FileInputStream(new File(getFilesDir(), TellmetimeActivity.IMAGE_FILE_NAME))));
        } catch (Exception ignored) {
            // Image is not set, set background color loaded from setting is visible.
        }

        break;
    }

    mShorterEdge = Math.min(getResources().getDisplayMetrics().widthPixels,
            getResources().getDisplayMetrics().heightPixels);
    mDensity = getResources().getDisplayMetrics().density;

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);
    lp.width = mShorterEdge;
    mClock.setLayoutParams(lp);

    Typeface mTypeface = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf");
    final float mItemSize = mShorterEdge / mClock.getChildCount();
    final int mRowMargin = (int) -(mItemSize / 2.2);

    for (int i = 0; i < mClock.getChildCount(); i++) {
        LinearLayout row = (LinearLayout) mClock.getChildAt(i);

        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams();
        params.bottomMargin = mRowMargin;
        row.setLayoutParams(params);

        for (int j = 0; j < row.getChildCount(); j++) {
            TextView tv = (TextView) row.getChildAt(j);

            tv.setTypeface(mTypeface);
            tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemSize);
            tv.setTextColor(mBacklightColor);
            tv.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor);
        }
    }
    LinearLayout lastRow = (LinearLayout) mClock.getChildAt(mClock.getChildCount() - 1);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastRow.getLayoutParams();
    params.bottomMargin = 0;
    lastRow.setLayoutParams(params);

    TextView twenty = (TextView) findViewById(R.id.twenty);
    params = (LinearLayout.LayoutParams) twenty.getLayoutParams();
    params.leftMargin = 0;
    twenty.setLayoutParams(params);

    inflateMinutesIndicators();
}

From source file:com.crystal.CrystalBeanWallpapers.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);
            Wallpaper.this.invalidateOptionsMenu();
        }/*from w w  w .ja  va  2s  .c  o  m*/
    });

    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);
}