Android Open Source - photo-paper Settings






From Project

Back to project page photo-paper.

License

The source code is released under:

MIT License

If you think the Android project photo-paper listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lukekorth.android_500px.helpers;
/*  w w  w. jav  a 2s  .co  m*/
import android.app.WallpaperManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import java.util.HashSet;
import java.util.Set;

public class Settings {

    private static SharedPreferences getPrefs(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context);
    }

    public static String getFeature(Context context) {
        return getPrefs(context).getString("feature", "popular");
    }

    public static void setFeature(Context context, String feature) {
        getPrefs(context).edit().putString("feature", feature).apply();
    }

    public static String getSearchQuery(Context context) {
        return getPrefs(context).getString("search_query", "");
    }

    public static void setSearchQuery(Context context, String query) {
        getPrefs(context).edit().putString("search_query", query).apply();
    }

    public static int[] getCategories(Context context) {
        Set<String> defaultCategory = new HashSet<String>();
        defaultCategory.add("8");
        Set<String> prefCategories = getPrefs(context).getStringSet("categories", defaultCategory);

        int[] categories = new int[prefCategories.size()];
        int i = 0;
        for (String category : prefCategories) {
            categories[i] = Integer.parseInt(category);
            i++;
        }

        return categories;
    }

    public static void setCategories(Context context, Set<String> categories) {
        getPrefs(context).edit().putStringSet("categories", categories).apply();
    }

    public static boolean allowNSFW(Context context) {
        return getPrefs(context).getBoolean("allow_nsfw", false);
    }

    public static boolean isEnabled(Context context) {
        return getPrefs(context).getBoolean("enable", false);
    }

    public static int getUpdateInterval(Context context) {
        return Integer.parseInt(getPrefs(context).getString("update_interval", "3600"));
    }

    public static void setUpdateInterval(Context context, String interval) {
        getPrefs(context).edit().putString("update_interval", interval).apply();
    }

    public static boolean useParallax(Context context) {
        return getPrefs(context).getBoolean("use_parallax", false);
    }

    public static boolean useOnlyWifi(Context context) {
        return getPrefs(context).getBoolean("use_only_wifi", true);
    }

    public static long getLastUpdated(Context context) {
        return getPrefs(context).getLong("last_updated", 0);
    }

    public static void setUpdated(Context context) {
        getPrefs(context).edit().putLong("last_updated", System.currentTimeMillis()).apply();
    }

    public static int getDesiredHeight(Context context) {
        int desiredHeight = getPrefs(context).getInt("desired_height", 0);
        if (desiredHeight == 0) {
            desiredHeight = getWallpaperManager(context).getDesiredMinimumHeight();
            setDesiredHeight(context, desiredHeight);
        }

        return desiredHeight;
    }

    public static void setDesiredHeight(Context context, int desiredHeight) {
        getPrefs(context).edit().putInt("desired_height", desiredHeight).apply();
    }

    public static int getDesiredWidth(Context context) {
        int desiredWidth = getPrefs(context).getInt("desired_width", 0);
        if (desiredWidth == 0) {
            desiredWidth = getWallpaperManager(context).getDesiredMinimumWidth();
            if (!Settings.useParallax(context)) {
                desiredWidth = desiredWidth / 2;
            }
            setDesiredWidth(context, desiredWidth);
        }

        return desiredWidth;
    }

    public static void setDesiredWidth(Context context, int desiredWidth) {
        getPrefs(context).edit().putInt("desired_width", desiredWidth).apply();
    }

    private static WallpaperManager getWallpaperManager(Context context) {
        return WallpaperManager.getInstance(context);
    }

}




Java Source Code List

com.lukekorth.android_500px.HistoryActivity.java
com.lukekorth.android_500px.PhotoFragment.java
com.lukekorth.android_500px.SearchActivity.java
com.lukekorth.android_500px.SettingsActivity.java
com.lukekorth.android_500px.ViewPhotoActivity.java
com.lukekorth.android_500px.WallpaperApplication.java
com.lukekorth.android_500px.helpers.Cache.java
com.lukekorth.android_500px.helpers.LogReporting.java
com.lukekorth.android_500px.helpers.Settings.java
com.lukekorth.android_500px.helpers.ThreadBus.java
com.lukekorth.android_500px.helpers.Utils.java
com.lukekorth.android_500px.models.ActivityResumedEvent.java
com.lukekorth.android_500px.models.EnableCategoriesEvent.java
com.lukekorth.android_500px.models.Photos.java
com.lukekorth.android_500px.models.SearchCompleteEvent.java
com.lukekorth.android_500px.models.UserUpdatedEvent.java
com.lukekorth.android_500px.models.User.java
com.lukekorth.android_500px.models.WallpaperChangedEvent.java
com.lukekorth.android_500px.receivers.UserPresentReceiver.java
com.lukekorth.android_500px.receivers.WifiReceiver.java
com.lukekorth.android_500px.services.ApiService.java
com.lukekorth.android_500px.services.ClearCacheIntentService.java
com.lukekorth.android_500px.services.UserInfoIntentService.java
com.lukekorth.android_500px.services.WallpaperService.java
com.lukekorth.android_500px.views.FeatureListPreference.java
com.lukekorth.android_500px.views.SquareImageView.java
com.squareup.picasso.PicassoTools.java