Android Open Source - PicSync Service Utils






From Project

Back to project page PicSync.

License

The source code is released under:

Apache License

If you think the Android project PicSync 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.darrenmowat.gdcu.service;
/*from www .  ja va2 s.c o  m*/
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.BatteryManager;
import android.preference.PreferenceManager;

import com.darrenmowat.gdcu.R;
import com.darrenmowat.gdcu.otto.DataBus;
import com.darrenmowat.gdcu.otto.UploadStatusEvent;

public class ServiceUtils {

  public static boolean shouldUpload(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean shouldOnlyUploadWifi = prefs.getBoolean("wifiOnly", false);
    if (shouldOnlyUploadWifi) {
      if (!isOnWiFi(context)) {
        String title = context.getResources().getString(
            R.string.pref_title_upload_status_uploads_pending);
        String msg = context.getResources().getString(
            R.string.pref_summary_upload_status_uploading_pending_for_wifi);
        sendServiceUpdate(title, msg);
        return false;
      }
    }
    boolean shouldOnlyUploadCharging = prefs.getBoolean("chargingOnly", false);
    if (shouldOnlyUploadCharging) {
      if (!isCharging(context)) {
        String title = context.getResources().getString(
            R.string.pref_title_upload_status_uploads_pending);
        String msg = context.getResources().getString(
            R.string.pref_summary_upload_status_uploading_pending_for_power);
        sendServiceUpdate(title, msg);
        return false;
      }
    }
    return true;
  }

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

  public static boolean isCharging(Context context) {
    Intent intent = context.registerReceiver(null, new IntentFilter(
        Intent.ACTION_BATTERY_CHANGED));
    int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
    return plugged == BatteryManager.BATTERY_PLUGGED_AC
        || plugged == BatteryManager.BATTERY_PLUGGED_USB;
  }
  
  public static void sendServiceUpdate(String title, String msg) {
    DataBus.postUploadStatusEventProducer(new UploadStatusEvent(title, msg));
  }
}




Java Source Code List

com.darrenmowat.gdcu.GDCU.java
com.darrenmowat.gdcu.Keys.java
com.darrenmowat.gdcu.activity.AuthActivity.java
com.darrenmowat.gdcu.activity.RenameFolderActivity.java
com.darrenmowat.gdcu.activity.SettingsActivity.java
com.darrenmowat.gdcu.activity.WebviewActivity.java
com.darrenmowat.gdcu.data.Database.java
com.darrenmowat.gdcu.data.Preferences.java
com.darrenmowat.gdcu.drive.DriveApi.java
com.darrenmowat.gdcu.otto.DataBus.java
com.darrenmowat.gdcu.otto.UploadStatusEventProducer.java
com.darrenmowat.gdcu.otto.UploadStatusEvent.java
com.darrenmowat.gdcu.security.PackageSecurityException.java
com.darrenmowat.gdcu.security.PackageSecurity.java
com.darrenmowat.gdcu.service.GalleryAlarmListener.java
com.darrenmowat.gdcu.service.GalleryObserver.java
com.darrenmowat.gdcu.service.MediaService.java
com.darrenmowat.gdcu.service.MediaThread.java
com.darrenmowat.gdcu.service.Notifier.java
com.darrenmowat.gdcu.service.ServiceUtils.java
com.darrenmowat.gdcu.service.UploadService.java
com.darrenmowat.gdcu.service.UploadThread.java
com.darrenmowat.gdcu.service.helpers.CloudSyncer.java
com.darrenmowat.gdcu.service.helpers.Media.java
com.darrenmowat.gdcu.service.helpers.ServiceIntents.java
com.darrenmowat.gdcu.service.helpers.ThreadCallbacks.java
com.darrenmowat.gdcu.tasks.GetTokenTask.java
com.darrenmowat.gdcu.tasks.RenameFolderTask.java
com.darrenmowat.gdcu.ui.ProgressDialogFragment.java
com.darrenmowat.gdcu.utils.HexConversions.java
com.darrenmowat.gdcu.utils.MD5Utils.java
com.darrenmowat.gdcu.utils.Preconditions.java