Android Open Source - photo-picker-plus-android Photo Picker Preference Util






From Project

Back to project page photo-picker-plus-android.

License

The source code is released under:

MIT License

If you think the Android project photo-picker-plus-android 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

/**
 * The MIT License (MIT)//w ww .ja v a2 s . c  o  m

Copyright (c) 2013 Chute

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package com.getchute.android.photopickerplus.util;

import java.util.ArrayList;

import com.getchute.android.photopickerplus.models.enums.LocalServiceType;
import com.chute.sdk.v2.model.enums.AccountType;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * {@link PhotoPickerPreferenceUtil} contains name value pairs that can be
 * stored and retrieved across various activity in an application.
 * 
 * {@link PhotoPickerPreferenceUtil} stores {@link AccountType}, list of
 * {@link AccountType} services as well as list of {@link LocalServiceType}
 * services.
 * 
 */
public class PhotoPickerPreferenceUtil {

  private static final String KEY_ACCOUNT_TYPE = "accountType";
  private static final String KEY_ACCOUNT_SERVICE_LIST = "accountServiceList";
  private static final String KEY_LOCAL_SERVICE_LIST = "localServiceList";
  private final Context context;

  private PhotoPickerPreferenceUtil(Context context) {
    this.context = context;
  }

  static PhotoPickerPreferenceUtil instance;

  public static PhotoPickerPreferenceUtil get() {
    return instance;
  }

  public static boolean isInitialized() {
    return instance != null;
  }

  public static void init(Context context) {
    if (instance == null) {
      instance = new PhotoPickerPreferenceUtil(
          context.getApplicationContext());
    }
  }

  public SharedPreferences getPreferences() {
    return PreferenceManager.getDefaultSharedPreferences(context);
  }

  private final <T> void setPreference(final String key, final T value) {
    SharedPreferences.Editor edit = getPreferences().edit();
    if (value.getClass().equals(String.class)) {
      edit.putString(key, (String) value);
    } else if (value.getClass().equals(Boolean.class)) {
      edit.putBoolean(key, (Boolean) value);
    } else if (value.getClass().equals(Integer.class)) {
      edit.putInt(key, (Integer) value);
    } else if (value.getClass().equals(Long.class)) {
      edit.putLong(key, (Long) value);
    } else if (value.getClass().equals(Float.class)) {
      edit.putFloat(key, (Float) value);
    } else {
      throw new UnsupportedOperationException(
          "Need to add a primitive type to shared prefs");
    }
    edit.commit();
  }

  public void clearAll() {
    getPreferences().edit().clear().commit();
  }

  public void setAccountType(AccountType accountType) {
    setPreference(KEY_ACCOUNT_TYPE, accountType.name());
  }

  public AccountType getAccountType() {
    String accountName = getPreferences().getString(KEY_ACCOUNT_TYPE, null);
    AccountType type = null;
    for (AccountType accountType : AccountType.values()) {
      if (accountName != null
          && accountName.equalsIgnoreCase(accountType.name())) {
        type = accountType;
      }
    }
    return type;
  }

  public void setAccountServiceList(ArrayList<AccountType> accountList) {
    for (AccountType accountType : accountList) {
      setPreference(KEY_ACCOUNT_SERVICE_LIST + "_" + accountType,
          accountType.name());
    }
  }

  public ArrayList<AccountType> getAccountServiceList() {
    ArrayList<AccountType> accountList = new ArrayList<AccountType>();
    for (AccountType accountType : AccountType.values()) {
      if (getPreferences().contains(
          KEY_ACCOUNT_SERVICE_LIST + "_" + accountType)) {
        accountList.add(accountType);
      }
    }
    return accountList;
  }

  public void setLocalServiceList(ArrayList<LocalServiceType> localServiceList) {
    for (LocalServiceType localMediaType : localServiceList) {
      setPreference(KEY_LOCAL_SERVICE_LIST + "_" + localMediaType,
          localMediaType.name());
    }
  }

  public ArrayList<LocalServiceType> getLocalServiceList() {
    ArrayList<LocalServiceType> localServiceList = new ArrayList<LocalServiceType>();
    for (LocalServiceType localMediaType : LocalServiceType.values()) {
      if (getPreferences().contains(
          KEY_LOCAL_SERVICE_LIST + "_" + localMediaType)) {
        localServiceList.add(localMediaType);
      }
    }
    return localServiceList;
  }

}




Java Source Code List

com.chute.android.photopickerplus.ApplicationTest.java
com.chute.android.photopickerplustutorial.ApplicationTest.java
com.chute.android.photopickerplustutorial.PhotoPickerPlusTutorialApp.java
com.chute.android.photopickerplustutorial.activity.PhotoGridActivity.java
com.chute.android.photopickerplustutorial.activity.PhotoPickerPlusTutorialActivity.java
com.chute.android.photopickerplustutorial.activity.VideoPlayerActivity.java
com.chute.android.photopickerplustutorial.adapter.GridAdapter.java
com.chute.android.photopickerplustutorial.config.ConfigEndpointURLs.java
com.getchute.android.photopickerplus.PhotoPickerPlusApp.java
com.getchute.android.photopickerplus.callback.CustomAuthenticationProvider.java
com.getchute.android.photopickerplus.callback.ImageDataRequest.java
com.getchute.android.photopickerplus.callback.ImageDataResponseLoader.java
com.getchute.android.photopickerplus.config.DefaultConfigurationFactory.java
com.getchute.android.photopickerplus.config.PhotoPickerConfiguration.java
com.getchute.android.photopickerplus.config.PhotoPicker.java
com.getchute.android.photopickerplus.config.ServiceRequest.java
com.getchute.android.photopickerplus.config.ServiceResponseModel.java
com.getchute.android.photopickerplus.config.ServiceResponseParser.java
com.getchute.android.photopickerplus.dao.MediaDAO.java
com.getchute.android.photopickerplus.loaders.AbstractSingleDataInstanceAsyncTaskLoader.java
com.getchute.android.photopickerplus.loaders.LocalImagesAsyncTaskLoader.java
com.getchute.android.photopickerplus.loaders.LocalVideosAsyncTaskLoader.java
com.getchute.android.photopickerplus.models.DeliverMediaModel.java
com.getchute.android.photopickerplus.models.MediaDataModel.java
com.getchute.android.photopickerplus.models.MediaModel.java
com.getchute.android.photopickerplus.models.MediaResponseModel.java
com.getchute.android.photopickerplus.models.OptionsModel.java
com.getchute.android.photopickerplus.models.enums.DisplayType.java
com.getchute.android.photopickerplus.models.enums.LocalServiceType.java
com.getchute.android.photopickerplus.models.enums.MediaType.java
com.getchute.android.photopickerplus.models.enums.PhotoFilterType.java
com.getchute.android.photopickerplus.ui.activity.AssetActivity.java
com.getchute.android.photopickerplus.ui.activity.ServicesActivity.java
com.getchute.android.photopickerplus.ui.adapter.AssetAccountAdapter.java
com.getchute.android.photopickerplus.ui.adapter.BaseCursorAdapter.java
com.getchute.android.photopickerplus.ui.adapter.CursorAdapterImages.java
com.getchute.android.photopickerplus.ui.adapter.CursorAdapterVideos.java
com.getchute.android.photopickerplus.ui.adapter.MergeAdapter.java
com.getchute.android.photopickerplus.ui.adapter.SackOfViewsAdapter.java
com.getchute.android.photopickerplus.ui.adapter.ServicesAdapter.java
com.getchute.android.photopickerplus.ui.components.SquareFrameLayout.java
com.getchute.android.photopickerplus.ui.fragment.FragmentEmpty.java
com.getchute.android.photopickerplus.ui.fragment.FragmentRoot.java
com.getchute.android.photopickerplus.ui.fragment.FragmentServices.java
com.getchute.android.photopickerplus.ui.fragment.FragmentSingle.java
com.getchute.android.photopickerplus.ui.listener.ListenerAccountAssetsSelection.java
com.getchute.android.photopickerplus.ui.listener.ListenerFilesAccount.java
com.getchute.android.photopickerplus.ui.listener.ListenerFilesCursor.java
com.getchute.android.photopickerplus.ui.listener.ListenerFragmentRoot.java
com.getchute.android.photopickerplus.ui.listener.ListenerFragmentSingle.java
com.getchute.android.photopickerplus.ui.listener.ListenerImageSelection.java
com.getchute.android.photopickerplus.ui.listener.ListenerItemCount.java
com.getchute.android.photopickerplus.ui.listener.ListenerVideoSelection.java
com.getchute.android.photopickerplus.util.AppUtil.java
com.getchute.android.photopickerplus.util.AssetUtil.java
com.getchute.android.photopickerplus.util.Constants.java
com.getchute.android.photopickerplus.util.FragmentUtil.java
com.getchute.android.photopickerplus.util.NotificationUtil.java
com.getchute.android.photopickerplus.util.PhotoPickerPreferenceUtil.java
com.getchute.android.photopickerplus.util.UIUtil.java
com.getchute.android.photopickerplus.util.intent.IntentUtil.java
com.getchute.android.photopickerplus.util.intent.IntentWrapper.java
com.getchute.android.photopickerplus.util.intent.PhotoPickerPlusIntentWrapper.java
com.getchute.android.photopickerplus.util.intent.PhotosIntentWrapper.java