Android Open Source - photo-paper Utils






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;
// ww w.j av  a 2 s  . co m
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Point;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import com.lukekorth.android_500px.models.Photos;

public class Utils {

    public static boolean shouldGetPhotos(Context context) {
        return Settings.isEnabled(context) && Utils.needMorePhotos(context) &&
                isCurrentNetworkOk(context);
    }

    public static boolean shouldUpdateWallpaper(Context context) {
        return Settings.isEnabled(context) && (Settings.getLastUpdated(context) +
                 (Settings.getUpdateInterval(context) * 1000) < System.currentTimeMillis());
    }

    public static boolean isCurrentNetworkOk(Context context) {
        return !Settings.useOnlyWifi(context) ||
                (Settings.useOnlyWifi(context) && Utils.isConnectedToWifi(context));
    }

    public static boolean needMorePhotos(Context context) {
        return (Photos.unseenPhotoCount(context) == 0 ||
                (86400 / Photos.unseenPhotoCount(context)) > Settings.getUpdateInterval(context));
    }

    public static boolean isConnectedToWifi(Context context) {
        ConnectivityManager connectivityManager =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
        return (activeNetwork != null && activeNetwork.isConnectedOrConnecting() &&
                activeNetwork.getType() == ConnectivityManager.TYPE_WIFI);
    }

    public static int dpToPx(Context context, int dp) {
        return Math.round(dp * (context.getResources().getDisplayMetrics().xdpi / DisplayMetrics.DENSITY_DEFAULT));
    }

    public static int getWallpaperHeight(Context context) {
        return WallpaperManager.getInstance(context).getDesiredMinimumHeight();
    }

    public static int getWallpaperWidth(Context context) {
        return WallpaperManager.getInstance(context).getDesiredMinimumWidth();
    }

    public static int getScreenHeight(Context context) {
        return getScreenResolution(context).y;
    }

    public static int getScreenWidth(Context context) {
        return getScreenResolution(context).x;
    }

    private static Point getScreenResolution(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Point point = new Point();
        windowManager.getDefaultDisplay().getSize(point);
        return point;
    }

    public static boolean supportsParallax(Context context) {
        return ((double) getWallpaperWidth(context) / getScreenWidth(context)) >= 2;
    }

    public static String getListSummary(Context context, int indexArrayId, int valueArrayId,
                                        String index, String defaultValue) {
        String[] indexArray = context.getResources().getStringArray(indexArrayId);
        String[] valueArray = context.getResources().getStringArray(valueArrayId);
        int i;
        for (i = 0; i < indexArray.length; i++) {
            if (indexArray[i].equals(index)) {
                return valueArray[i];
            }
        }
        return defaultValue;
    }

}




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