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:xyz.klinker.blur.launcher3.Workspace.java

/**
 * 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./*  w  w  w .j  a va2 s .  c  o m*/
 */
public Workspace(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mOutlineHelper = HolographicOutlineHelper.obtain(context);

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

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);
    mSpringLoadedShrinkFactor = res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
    mOverviewModeShrinkFactor = res.getInteger(R.integer.config_workspaceOverviewShrinkPercentage) / 100f;
    mOriginalDefaultPage = mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1);
    a.recycle();

    setOnHierarchyChangeListener(this);
    setHapticFeedbackEnabled(false);

    initWorkspace();

    // Disable multitouch across the workspace/all apps/customize tray
    setMotionEventSplittingEnabled(true);

    mDetector = new GestureDetectorCompat(context, new MyGestureListener());
}

From source file:io.github.runassudo.launchert.Workspace.java

/**
 * Used to inflate the Workspace from XML.
 *
 * @param context/*from   w  w  w.ja va 2  s  . c o  m*/
 *            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);
    mContentIsRefreshable = false;

    mOutlineHelper = HolographicOutlineHelper.obtain(context);

    mDragEnforcer = new DropTarget.DragEnforcer(context);
    // With workspace, data is available straight from the get-go
    setDataIsReady();

    mLauncher = (Launcher) context;
    final Resources res = getResources();
    mWorkspaceFadeInAdjacentScreens = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile()
            .shouldFadeAdjacentWorkspaceScreens();
    mFadeInAdjacentScreens = false;
    mWallpaperManager = WallpaperManager.getInstance(context);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);
    mSpringLoadedShrinkFactor = res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
    mOverviewModeShrinkFactor = grid.getOverviewModeScale();
    mCameraDistance = res.getInteger(R.integer.config_cameraDistance);

    //(LauncherT) Custom default page.
    // mOriginalDefaultPage = mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
    mOriginalDefaultPage = mDefaultPage = Integer.parseInt(sharedPref.getString("desktop_default_screen", "0"));
    a.recycle();

    setOnHierarchyChangeListener(this);
    setHapticFeedbackEnabled(false);

    initWorkspace();

    // Disable multitouch across the workspace/all apps/customize tray
    setMotionEventSplittingEnabled(true);
    setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
}

From source file:com.android.launcher3.Workspace.java

/**
 * 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.//from   w  w  w. ja  va 2s . c  o  m
 */
public Workspace(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mContentIsRefreshable = false;

    mOutlineHelper = HolographicOutlineHelper.obtain(context);

    mDragEnforcer = new DropTarget.DragEnforcer(context);
    // With workspace, data is available straight from the get-go
    setDataIsReady();

    mLauncher = (Launcher) context;
    final Resources res = getResources();
    mWorkspaceFadeInAdjacentScreens = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile()
            .shouldFadeAdjacentWorkspaceScreens();
    mFadeInAdjacentScreens = false;
    mWallpaperManager = WallpaperManager.getInstance(context);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);
    mSpringLoadedShrinkFactor = res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
    mOverviewModeShrinkFactor = grid.getOverviewModeScale();
    mCameraDistance = res.getInteger(R.integer.config_cameraDistance);
    mOriginalDefaultPage = mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1);
    a.recycle();

    setOnHierarchyChangeListener(this);
    setHapticFeedbackEnabled(false);

    initWorkspace();

    // Disable multitouch across the workspace/all apps/customize tray
    setMotionEventSplittingEnabled(true);
    setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
}

From source file:com.phonemetra.turbo.launcher.Workspace.java

/**
 * 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.//w w  w  .jav a 2 s . c  o m
 */
public Workspace(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mContentIsRefreshable = false;

    mOutlineHelper = HolographicOutlineHelper.obtain(context);

    mDragEnforcer = new DropTarget.DragEnforcer(context);
    // With workspace, data is available straight from the get-go
    setDataIsReady();

    mShowSearchBar = SettingsProvider.getBoolean(context, SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
            R.bool.preferences_interface_homescreen_search_default);
    mShowOutlines = SettingsProvider.getBoolean(context,
            SettingsProvider.SETTINGS_UI_HOMESCREEN_SCROLLING_PAGE_OUTLINES,
            R.bool.preferences_interface_homescreen_scrolling_page_outlines_default);
    mHideIconLabels = SettingsProvider.getBoolean(context,
            SettingsProvider.SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS,
            R.bool.preferences_interface_homescreen_hide_icon_labels_default);
    mWorkspaceFadeInAdjacentScreens = SettingsProvider.getBoolean(context,
            SettingsProvider.SETTINGS_UI_HOMESCREEN_SCROLLING_FADE_ADJACENT,
            R.bool.preferences_interface_homescreen_scrolling_fade_adjacent_default);
    TransitionEffect.setFromString(this,
            SettingsProvider.getString(context,
                    SettingsProvider.SETTINGS_UI_HOMESCREEN_SCROLLING_TRANSITION_EFFECT,
                    R.string.preferences_interface_homescreen_scrolling_transition_effect));

    mLauncher = (Launcher) context;
    final Resources res = getResources();

    mFadeInAdjacentScreens = false;
    mWallpaperManager = WallpaperManager.getInstance(context);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);
    mSpringLoadedShrinkFactor = res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
    mOverviewModeShrinkFactor = grid.getOverviewModeScale();
    mCameraDistance = res.getInteger(R.integer.config_cameraDistance);
    mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1);
    mDefaultScreenId = SettingsProvider.getLongCustomDefault(context,
            SettingsProvider.SETTINGS_UI_HOMESCREEN_DEFAULT_SCREEN_ID, -1);
    a.recycle();

    setOnHierarchyChangeListener(this);
    setHapticFeedbackEnabled(false);

    initWorkspace();

    // Disable multitouch across the workspace/all apps/customize tray
    setMotionEventSplittingEnabled(true);
    setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
}

From source file:com.gmail.charleszq.picorner.ui.ImageDetailFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (mLoadedBitmap != null) {
        saveBitmapToShare(mLoadedBitmap, null);
    }//w w  w . ja v  a2 s  .c  o m

    switch (item.getItemId()) {
    case android.R.id.home:
        getActivity().finish();
        return true;
    case R.id.menu_item_share_action_provider_action_bar:
        boolean ready = waitForImageLoaded();
        if (ready) {
            sharePhoto();
        }
        return ready;
    case R.id.menu_item_slide_show:
        ImageDetailActivity act = (ImageDetailActivity) getActivity();
        if (act != null) {
            act.startSlideShow(0);
        }
        return true;
    case R.id.menu_item_see_owner_photos:
        Intent i = new Intent(getActivity(), UserPhotoListActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        i.putExtra(UserPhotoListActivity.MD_TYPE_KEY, mPhoto.getMediaSource().ordinal());
        i.putExtra(UserPhotoListActivity.USER_KEY, mPhoto.getAuthor());
        startActivity(i);
        return true;
    case R.id.menu_item_like:
        ready = waitForImageLoaded();
        if (ready)
            likePhoto(item);
        return ready;
    case R.id.menu_item_vote:
        ready = waitForImageLoaded();
        if (ready)
            votePhoto();
        return ready;
    case R.id.menu_item_save:
        ready = waitForImageLoaded();
        if (ready)
            savePhotoLocally();
        return ready;
    case R.id.menu_item_set_wallpaper:
        ready = waitForImageLoaded();
        if (!ready)
            return false;

        WallpaperManager wm = WallpaperManager.getInstance(getActivity());
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(getShareImageFile(null));
            wm.setStream(fis);
            Toast.makeText(getActivity(), getResources().getString(R.string.msg_wallpaper_changed),
                    Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                }
            }
        }
        return true;
    case R.id.menu_item_detail:
        showPhotoDetailWithPage(null);
        return true;
    case R.id.menu_item_comment:
        showPhotoDetailWithPage(PhotoDetailActivity.COMMENT_PAGE);
        return true;
    case R.id.menu_item_photo_set:
        showPhotoDetailWithPage(PhotoDetailActivity.MY_F_ORG_PHOTO_SET_PAGE);
        return true;
    case R.id.menu_item_add_to_group:
        showPhotoDetailWithPage(PhotoDetailActivity.MY_F_ORG_GROUP_PAGE);
        return true;
    case R.id.menu_item_view_exif:
        showPhotoDetailWithPage(PhotoDetailActivity.EXIF_PAGE);
        return true;
    case R.id.menu_item_view_on_map:
        showPhotoDetailWithPage(PhotoDetailActivity.MAP_PAGE);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.pk.wallpapermanager.PkWallpaperManager.java

/**
 * Sets the system wallpaper to the Wallpaper object passed.
 * May throw an exception if the data is invalid.
 * <p>/*  w  w  w . j  a  v  a2 s .c o m*/
 * Note: Do NOT call this from the main UI thread if you're 
 * setting it to a cloud wallpaper! Call setWallpaperAsync instead.
 * 
 * @param mWall
 * @throws NumberFormatException
 * @throws IOException
 */
public void setWallpaper(Wallpaper mWall) throws NumberFormatException, IOException {
    if (debugEnabled)
        Log.d(LOG_TAG, "Setting wallpaper...");

    // Load the original system WallpaperManager
    WallpaperManager wallManager = WallpaperManager.getInstance(mContext);
    Bitmap bitmap = null;

    // Set resource if local, otherwise download it and set it
    if (mWall.isLocal())
        wallManager.setResource(mWall.getFullResource());
    else {
        bitmap = getBitmapFromURL(mWall.getFullURL());
        wallManager.setBitmap(bitmap);
    }

    // Loop through all listeners notifying them
    for (WallpaperSetListener mListener : mWallpaperSetListeners) {
        mListener.onWallpaperSet(bitmap);
    }

    if (debugEnabled)
        Log.d(LOG_TAG, "Successfully set wallpaper!");
}

From source file:com.android.launcher3.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(//from   w w w.j  av  a  2 s . c om
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (LauncherAppState.PROFILE_STARTUP) {
            Trace.beginSection("Launcher-onCreate");
        }
    }

    predictiveAppsProvider = new PredictiveAppsProvider(this);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.preOnCreate();
    }

    super.onCreate(savedInstanceState);

    app = LauncherAppState.getInstance();

    // Load configuration-specific DeviceProfile
    mDeviceProfile = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            ? app.getInvariantDeviceProfile().landscapeProfile
            : app.getInvariantDeviceProfile().portraitProfile;

    mSharedPrefs = Utilities.getPrefs(this);
    mIsSafeModeEnabled = getPackageManager().isSafeMode();
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mAccessibilityDelegate = new LauncherAccessibilityDelegate(this);

    mDragController = new DragController(this);
    mAllAppsController = new AllAppsTransitionController(this);
    mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, mAllAppsController);

    mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);

    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    setContentView(R.layout.launcher);

    //Shortcuts variable init
    masterLayout = (InsettableFrameLayout) findViewById(R.id.launcher);
    gridSize = new GridSize((int) app.getInvariantDeviceProfile().numColumns,
            (int) app.getInvariantDeviceProfile().numRows);

    IS_ALLOW_MIC = Utilities.isAllowVoiceInSearchBarPrefEnabled(getApplicationContext());

    setupViews();
    mDeviceProfile.layout(this, false /* notifyListeners */);
    mExtractedColors = new ExtractedColors();
    loadExtractedColorsAndColorItems();

    ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)).addAccessibilityStateChangeListener(this);

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    if (LauncherAppState.PROFILE_STARTUP) {
        Trace.endSection();
    }

    // We only load the page synchronously if the user rotates (or triggers a
    // configuration change) while launcher is in the foreground
    if (!mModel.startLoader(mWorkspace.getRestorePage())) {
        // If we are not binding synchronously, show a fade in animation when
        // the first page bind completes.
        mDragLayer.setAlpha(0);
    } else {
        setWorkspaceLoading(true);
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(ACTION_APPWIDGET_HOST_RESET);
    registerReceiver(mUiBroadcastReceiver, filter);

    mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
    // In case we are on a device with locked rotation, we should look at preferences to check
    // if the user has specifically allowed rotation.
    if (!mRotationEnabled) {
        mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
        mRotationPrefChangeHandler = new RotationPrefChangeHandler();
        mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
    }

    // On large interfaces, or on devices that a user has specifically enabled screen rotation,
    // we want the screen to auto-rotate based on the current orientation
    setOrientation();

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
    }

    activity = this;
    /*if (!isTaskRoot()) {
    finish();
    return;
    }*/

    adminComponent = new ComponentName(Launcher.this, DarClass.class);
    devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

    appHasFingerprint = Utilities.getAppHasFingerprint(getApplicationContext());
    appHasPassword = Utilities.getAppHasPassword(getApplicationContext());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
    }

    icons = Utilities.getIconPack(Utilities.getAppIconPackageNamePrefEnabled(getApplicationContext()));
    if (icons == null || icons.isEmpty() || icons.size() == 0) {
        if (Utilities.getAppIconPackageNamePrefEnabled(getApplicationContext()) != null && !Utilities
                .getAppIconPackageNamePrefEnabled(getApplicationContext()).equalsIgnoreCase("NULL")) {
            Utilities.answerToRestoreIconPack(this,
                    Utilities.getAppIconPackageNamePrefEnabled(getApplicationContext()));
        }
    }

    if (FirstRun.isFirstLaunch(getApplicationContext())) {
        WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
        try {
            myWallpaperManager.setResource(R.drawable.wallpaper);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (Utilities.doCheckPROVersion(getApplicationContext())) {

    }

    mDefaultScreenId = Utilities.getLongCustomDefault(this, Utilities.SETTINGS_UI_HOMESCREEN_DEFAULT_SCREEN_ID,
            1);
}

From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java

@SuppressWarnings("NewApi")
@Override//from   w  w w . j a v  a2  s .  c o  m
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case android.R.id.home:
        onBackPressed();
        return true;
    case R.id.share_image:
        shareImage();
        return true;
    case R.id.add_to_favourite:
        setFavourite();
        return true;
    case R.id.set_as_wallpaper:
        //                setAsWallpaper(imageId);

        WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
        try {
            myWallpaperManager.setBitmap(universalitmap);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return true;
    case R.id.download_image_original:
        downloadOriginalImage();
        return true;
    case R.id.downloadOriginalImage:
        downloadOriginalImage();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:info.tellmetime.TellmetimeActivity.java

private void switchBackgroundMode(int position) {
    mBackgroundImage.setBackgroundResource(0);

    switch (position) {
    case MODE_BACKGROUND_SOLID:
        mBackgroundImage.setVisibility(View.GONE);
        break;/*from w  ww .  ja v  a  2  s .  c o  m*/

    case MODE_BACKGROUND_WALLPAPER:
        mBackgroundImage.setVisibility(View.VISIBLE);
        mBackgroundImage.setImageDrawable(WallpaperManager.getInstance(this).getDrawable());
        break;

    case MODE_BACKGROUND_IMAGE:
        if (mImage == null) {
            try {
                File f = new File(getFilesDir(), IMAGE_FILE_NAME);
                mImage = BitmapFactory.decodeStream(new FileInputStream(f));
            } catch (FileNotFoundException e) {
                pickImage(null);
            }
        }

        mBackgroundImage.setVisibility(View.VISIBLE);
        mBackgroundImage.setImageBitmap(mImage);
        break;

    }
}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
public void onClick(View v) {
    // If OK(setPin) clicked, ask user if sure; if yes, store PIN; else, go back
    if (v.getId() == R.id.setPin) {
        // If PIN length between 4 and 6, store PIN and toast successful
        if (pinEdit.length() >= 4 && pinEdit.length() <= 6) {
            new AlertDialog.Builder(this).setMessage(R.string.set_pin_confirmation)
                    .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                settings.put("pin", String.valueOf(pinEdit.getText()));

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }/*from  ww w .  j  a  v  a 2 s. com*/

                            writeToJSON();

                            Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_pin_set,
                                    Toast.LENGTH_SHORT);
                            toast.show();

                            imm.hideSoftInputFromWindow(pinEdit.getWindowToken(), 0);

                        }
                    }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            imm.hideSoftInputFromWindow(pinEdit.getWindowToken(), 0);
                            // Do nothing, close dialog
                        }
                    }).show();
        }

        // Toast user that PIN needs to be at least 4 digits long
        else {
            Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_pin_needs4digits,
                    Toast.LENGTH_LONG);
            toast.show();
        }
    }

    // If 'Refresh wallpaper' pressed, check if Android 4.2 or above, if yes
    // Store new blur var, if blur bigger than 0 re-blur wallpaper
    else if (v.getId() == R.id.refreshWallpaper) {
        if (Build.VERSION.SDK_INT > 16) {
            try {
                settings.put("blur", blur);

            } catch (JSONException e) {
                e.printStackTrace();
            }

            writeToJSON();

            // If blur is 0, don't change anything, just toast
            if (blur == 0) {
                Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_wallpaper_refreshed,
                        Toast.LENGTH_SHORT);
                toast.show();
            }

            // If blur is bigger than 0, get default wallpaper - to bitmap - fastblur bitmap - store
            else {
                // Check if TapUnlock folder exists, if not, create directory
                File folder = new File(Environment.getExternalStorageDirectory() + "/TapUnlock");
                boolean folderSuccess = true;

                if (!folder.exists()) {
                    folderSuccess = folder.mkdir();
                }

                if (folderSuccess) {
                    WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
                    final Drawable wallpaperDrawable = wallpaperManager.peekFastDrawable();

                    if (wallpaperDrawable != null) {
                        // Display indeterminate progress bar while blurring
                        progressBar.setVisibility(View.VISIBLE);

                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                Bitmap bitmapToBlur = ImageUtils.drawableToBitmap(wallpaperDrawable);

                                Bitmap blurredWallpaper = null;
                                if (bitmapToBlur != null)
                                    blurredWallpaper = ImageUtils.fastBlur(MainActivity.this, bitmapToBlur,
                                            blur);

                                boolean stored = false;
                                if (blurredWallpaper != null) {
                                    stored = ImageUtils.storeImage(blurredWallpaper);

                                    final boolean finalStored = stored;
                                    runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            progressBar.setVisibility(View.INVISIBLE);

                                            if (finalStored) {
                                                Toast toast = Toast.makeText(getApplicationContext(),
                                                        R.string.toast_wallpaper_refreshed, Toast.LENGTH_SHORT);
                                                toast.show();
                                            }
                                        }
                                    });
                                }

                                if (bitmapToBlur == null || blurredWallpaper == null || !stored) {
                                    runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            progressBar.setVisibility(View.INVISIBLE);

                                            Toast toast = Toast.makeText(getApplicationContext(),
                                                    R.string.toast_wallpaper_not_refreshed, Toast.LENGTH_SHORT);
                                            toast.show();
                                        }
                                    });
                                }
                            }
                        }).start();
                    }

                    else {
                        Toast toast = Toast.makeText(getApplicationContext(),
                                R.string.toast_wallpaper_not_refreshed, Toast.LENGTH_SHORT);
                        toast.show();
                    }
                }
            }
        }

        // If Android version less than 4.2, display toast cannot blur
        else {
            Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_cannot_blur,
                    Toast.LENGTH_SHORT);
            toast.show();
        }
    }

    // If '+' pressed
    else if (v.getId() == R.id.newTag) {
        if (nfcAdapter != null) {
            // If NFC is on, show scan dialog and enableForegroundDispatch
            if (nfcAdapter.isEnabled()) {
                nfcAdapter.enableForegroundDispatch(this, pIntent,
                        new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED) },
                        new String[][] { new String[] { "android.nfc.tech.MifareClassic" },
                                new String[] { "android.nfc.tech.MifareUltralight" },
                                new String[] { "android.nfc.tech.NfcA" },
                                new String[] { "android.nfc.tech.NfcB" },
                                new String[] { "android.nfc.tech.NfcF" },
                                new String[] { "android.nfc.tech.NfcV" },
                                new String[] { "android.nfc.tech.Ndef" },
                                new String[] { "android.nfc.tech.IsoDep" },
                                new String[] { "android.nfc.tech.NdefFormatable" } });

                MainActivity.this.showDialog(DIALOG_READ);
            }

            // NFC is off, prompt user to enable it and send him to NFC settings
            else {
                new AlertDialog.Builder(this).setTitle(R.string.nfc_off_dialog_title)
                        .setMessage(R.string.nfc_off_dialog_message)
                        .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS);
                                startActivity(intent);
                            }
                        }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // Do nothing, close dialog
                            }
                        }).show();
            }
        }

        // NFC adapter is null
        else {
            new AlertDialog.Builder(this).setTitle(R.string.nfc_off_dialog_title)
                    .setMessage(R.string.nfc_off_dialog_message)
                    .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS);
                            startActivity(intent);
                        }
                    }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing, close dialog
                        }
                    }).show();
        }
    }
}