Example usage for android.content Intent ACTION_SET_WALLPAPER

List of usage examples for android.content Intent ACTION_SET_WALLPAPER

Introduction

In this page you can find the example usage for android.content Intent ACTION_SET_WALLPAPER.

Prototype

String ACTION_SET_WALLPAPER

To view the source code for android.content Intent ACTION_SET_WALLPAPER.

Click Source Link

Document

Activity Action: Show settings for choosing wallpaper.

Usage

From source file:org.cyanogenmod.theme.chooser.ChooserActivity.java

private void handleIntent(final Intent intent) {
    //Determine if there we need to filter by component (ex icon sets only)
    Bundle extras = intent.getExtras();/*from   w w  w  .j a  v a 2 s  .  c o m*/
    String filter = (extras == null) ? null : extras.getString(EXTRA_COMPONENT_FILTER);

    // If activity started by wallpaper chooser then filter on wallpapers
    if (Intent.ACTION_SET_WALLPAPER.equals(intent.getAction())) {
        filter = "mods_homescreen";
    }

    // Support filters passed in as csv. Since XML prefs do not support
    // passing extras in as arrays.
    ArrayList<String> filtersList = new ArrayList<String>();
    if (filter != null) {
        String[] filters = filter.split(",");
        filtersList.addAll(Arrays.asList(filters));
    }

    Fragment fragment = null;
    if (Intent.ACTION_MAIN.equals(intent.getAction()) && intent.hasExtra(EXTRA_PKGNAME)) {
        String pkgName = intent.getStringExtra(EXTRA_PKGNAME);
        fragment = ChooserDetailFragment.newInstance(pkgName, filtersList);
        // Handle case where Theme Store or some other app wishes to open
        // a detailed theme view for a given package
        try {
            final PackageManager pm = getPackageManager();
            if (pm.getPackageInfo(pkgName, 0) == null) {
                fragment = ChooserBrowseFragment.newInstance(filtersList);
            }
        } catch (PackageManager.NameNotFoundException e) {
            fragment = ChooserBrowseFragment.newInstance(filtersList);
        }
    } else {
        fragment = ChooserBrowseFragment.newInstance(filtersList);
    }

    getSupportFragmentManager().beginTransaction().replace(R.id.content, fragment, "ChooserBrowseFragment")
            .commit();

}

From source file:com.afollestad.polar.ui.MainActivity.java

private void processIntent(Intent intent) {
    if (Intent.ACTION_SET_WALLPAPER.equals(intent.getAction())) {
        for (int i = 0; i < mPages.size(); i++) {
            PagesBuilder.Page page = mPages.get(i);
            if (page.drawerId == R.id.drawer_wallpapers) {
                mPager.setCurrentItem(i);
                break;
            }/*from  w ww  .  j a  v  a  2s.  c o  m*/
        }
    }
}

From source file:com.farmerbb.taskbar.activity.HomeActivity.java

private void setWallpaper() {
    SharedPreferences pref = U.getSharedPreferences(this);
    if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
        LocalBroadcastManager.getInstance(this)
                .sendBroadcast(new Intent("com.farmerbb.taskbar.TEMP_HIDE_TASKBAR"));
    else//from w  w w . j  av a  2 s .  co m
        LocalBroadcastManager.getInstance(this)
                .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));

    try {
        startActivity(Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
                getString(R.string.set_wallpaper)));
    } catch (ActivityNotFoundException e) {
        /* Gracefully fail */ }
}

From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N_MR1)//from w  w w .ja  va2  s.  c o m
@Override
public boolean onPreferenceClick(Preference p) {
    UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
    LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
    boolean appIsValid = isStartButton || isOverflowMenu
            || !launcherApps.getActivityList(getIntent().getStringExtra("package_name"),
                    userManager.getUserForSerialNumber(userId)).isEmpty();

    if (appIsValid)
        switch (p.getKey()) {
        case "app_info":
            startFreeformActivity();
            launcherApps.startAppDetailsActivity(ComponentName.unflattenFromString(componentName),
                    userManager.getUserForSerialNumber(userId), null, null);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "uninstall":
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInMultiWindowMode()) {
                Intent intent2 = new Intent(ContextMenuActivity.this, DummyActivity.class);
                intent2.putExtra("uninstall", packageName);
                intent2.putExtra("user_id", userId);

                startFreeformActivity();
                startActivity(intent2);
            } else {
                startFreeformActivity();

                Intent intent2 = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + packageName));
                intent2.putExtra(Intent.EXTRA_USER, userManager.getUserForSerialNumber(userId));

                try {
                    startActivity(intent2);
                } catch (ActivityNotFoundException e) {
                    /* Gracefully fail */ }
            }

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "open_taskbar_settings":
            startFreeformActivity();

            Intent intent2 = new Intent(this, MainActivity.class);
            intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent2);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "quit_taskbar":
            Intent quitIntent = new Intent("com.farmerbb.taskbar.QUIT");
            quitIntent.setPackage(BuildConfig.APPLICATION_ID);
            sendBroadcast(quitIntent);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "pin_app":
            PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this);
            if (pba.isPinned(componentName))
                pba.removePinnedApp(this, componentName);
            else {
                Intent intent = new Intent();
                intent.setComponent(ComponentName.unflattenFromString(componentName));

                LauncherActivityInfo appInfo = launcherApps.resolveActivity(intent,
                        userManager.getUserForSerialNumber(userId));
                if (appInfo != null) {
                    AppEntry newEntry = new AppEntry(packageName, componentName, appName,
                            IconCache.getInstance(this).getIcon(this, getPackageManager(), appInfo), true);

                    newEntry.setUserId(userId);
                    pba.addPinnedApp(this, newEntry);
                }
            }
            break;
        case "block_app":
            PinnedBlockedApps pba2 = PinnedBlockedApps.getInstance(this);
            if (pba2.isBlocked(componentName))
                pba2.removeBlockedApp(this, componentName);
            else {
                pba2.addBlockedApp(this, new AppEntry(packageName, componentName, appName, null, false));
            }
            break;
        case "show_window_sizes":
            getPreferenceScreen().removeAll();

            addPreferencesFromResource(R.xml.pref_context_menu_window_size_list);
            findPreference("window_size_standard").setOnPreferenceClickListener(this);
            findPreference("window_size_large").setOnPreferenceClickListener(this);
            findPreference("window_size_fullscreen").setOnPreferenceClickListener(this);
            findPreference("window_size_half_left").setOnPreferenceClickListener(this);
            findPreference("window_size_half_right").setOnPreferenceClickListener(this);
            findPreference("window_size_phone_size").setOnPreferenceClickListener(this);

            SharedPreferences pref = U.getSharedPreferences(this);
            if (pref.getBoolean("save_window_sizes", true)) {
                String windowSizePref = SavedWindowSizes.getInstance(this).getWindowSize(this, packageName);
                CharSequence title = findPreference("window_size_" + windowSizePref).getTitle();
                findPreference("window_size_" + windowSizePref).setTitle('\u2713' + " " + title);
            }

            if (U.isOPreview()) {
                U.showToast(this, R.string.window_sizes_not_available);
            }

            secondaryMenu = true;
            break;
        case "window_size_standard":
        case "window_size_large":
        case "window_size_fullscreen":
        case "window_size_half_left":
        case "window_size_half_right":
        case "window_size_phone_size":
            String windowSize = p.getKey().replace("window_size_", "");

            SharedPreferences pref2 = U.getSharedPreferences(this);
            if (pref2.getBoolean("save_window_sizes", true)) {
                SavedWindowSizes.getInstance(this).setWindowSize(this, packageName, windowSize);
            }

            startFreeformActivity();
            U.launchApp(getApplicationContext(), packageName, componentName, userId, windowSize, false, true);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "app_shortcuts":
            getPreferenceScreen().removeAll();
            generateShortcuts();

            secondaryMenu = true;
            break;
        case "shortcut_1":
        case "shortcut_2":
        case "shortcut_3":
        case "shortcut_4":
        case "shortcut_5":
            U.startShortcut(getApplicationContext(), packageName, componentName,
                    shortcuts.get(Integer.parseInt(p.getKey().replace("shortcut_", "")) - 1));

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "start_menu_apps":
            startFreeformActivity();

            Intent intent = null;

            SharedPreferences pref3 = U.getSharedPreferences(this);
            switch (pref3.getString("theme", "light")) {
            case "light":
                intent = new Intent(this, SelectAppActivity.class);
                break;
            case "dark":
                intent = new Intent(this, SelectAppActivityDark.class);
                break;
            }

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref3.getBoolean("freeform_hack", false)
                    && intent != null && isInMultiWindowMode()) {
                intent.putExtra("no_shadow", true);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);

                U.launchAppMaximized(getApplicationContext(), intent);
            } else
                startActivity(intent);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "volume":
            AudioManager audio = (AudioManager) getSystemService(AUDIO_SERVICE);
            audio.adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME, AudioManager.USE_DEFAULT_STREAM_TYPE,
                    AudioManager.FLAG_SHOW_UI);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "file_manager":
            Intent fileManagerIntent;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                startFreeformActivity();
                fileManagerIntent = new Intent("android.provider.action.BROWSE");
            } else {
                fileManagerIntent = new Intent("android.provider.action.BROWSE_DOCUMENT_ROOT");
                fileManagerIntent.setComponent(
                        ComponentName.unflattenFromString("com.android.documentsui/.DocumentsActivity"));
            }

            fileManagerIntent.addCategory(Intent.CATEGORY_DEFAULT);
            fileManagerIntent
                    .setData(Uri.parse("content://com.android.externalstorage.documents/root/primary"));

            try {
                startActivity(fileManagerIntent);
            } catch (ActivityNotFoundException e) {
                U.showToast(this, R.string.lock_device_not_supported);
            }

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "system_settings":
            startFreeformActivity();

            Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);

            try {
                startActivity(settingsIntent);
            } catch (ActivityNotFoundException e) {
                U.showToast(this, R.string.lock_device_not_supported);
            }

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "lock_device":
            U.lockDevice(this);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "power_menu":
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        case "change_wallpaper":
            Intent intent3 = Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
                    getString(R.string.set_wallpaper));
            intent3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            U.launchAppMaximized(getApplicationContext(), intent3);

            showStartMenu = false;
            shouldHideTaskbar = true;
            contextMenuFix = false;
            break;
        }

    if (!secondaryMenu)
        finish();
    return true;
}

From source file:jahirfiquitiva.iconshowcase.activities.ShowcaseActivity.java

private void getAction() {
    String action;/*from w w w .jav a2s.c om*/
    try {
        action = getIntent().getAction();
    } catch (Exception e) {
        action = "action";
    }

    try {
        switch (action) {
        case adw_action:
        case turbo_action:
        case nova_action:
        case Intent.ACTION_PICK:
        case Intent.ACTION_GET_CONTENT:
            iconsPicker = true;
            wallsPicker = false;
            break;
        case Intent.ACTION_SET_WALLPAPER:
            iconsPicker = false;
            wallsPicker = true;
            break;
        default:
            iconsPicker = false;
            wallsPicker = false;
            break;
        }
    } catch (ActivityNotFoundException | NullPointerException e) {
        iconsPicker = false;
        wallsPicker = false;
    }
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

/**
 * Event handler for the wallpaper picker button that appears after a long press
 * on the home screen./*from   www  .j  a  va2 s .co  m*/
 */
protected void onClickWallpaperPicker(View v) {
    if (LOGD)
        Log.d(TAG, "onClickWallpaperPicker");
    final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
    startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
}

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

private void startWallpaper() {
    showWorkspace(true);//  w w w .  ja v a  2s . c  o  m
    final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
    Intent chooser = Intent.createChooser(pickWallpaper, getText(R.string.chooser_wallpaper));
    // NOTE: Adds a configure option to the chooser if the wallpaper supports it
    //       Removed in Eclair MR1
    //        WallpaperManager wm = (WallpaperManager)
    //                getSystemService(Context.WALLPAPER_SERVICE);
    //        WallpaperInfo wi = wm.getWallpaperInfo();
    //        if (wi != null && wi.getSettingsActivity() != null) {
    //            LabeledIntent li = new LabeledIntent(getPackageName(),
    //                    R.string.configure_wallpaper, 0);
    //            li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
    //            chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
    //        }
    startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
}

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

protected void startWallpaper() {
    final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
    pickWallpaper.setComponent(getWallpaperPickerComponent());
    startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
}

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

/**
 * Event handler for the wallpaper picker button that appears after a long press
 * on the home screen.//  ww w .j  av a  2s  . co m
 */
protected void onClickWallpaperPicker(View v) {
    if (LOGD)
        Log.d(TAG, "onClickWallpaperPicker");
    startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName()),
            REQUEST_PICK_WALLPAPER);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onClickWallpaperPicker(v);
    }
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

/**
 * Event handler for the wallpaper picker button that appears after a long press
 * on the home screen./*w ww .j  ava  2  s . c  o  m*/
 */
protected void onClickWallpaperPicker(View v) {
    if (!Utilities.isWallapaperAllowed(this)) {
        Toast.makeText(this, R.string.msg_disabled_by_admin, Toast.LENGTH_SHORT).show();
        return;
    }

    if (LOGD)
        Log.d(TAG, "onClickWallpaperPicker");
    int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
    float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
    startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName())
            .putExtra(WallpaperPickerActivity.EXTRA_WALLPAPER_OFFSET, offset), REQUEST_PICK_WALLPAPER);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onClickWallpaperPicker(v);
    }
}