Android Open Source - photo-picker-plus-android Asset 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. jav  a 2  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 android.net.Uri;

import com.chute.sdk.v2.model.AccountAlbumModel;
import com.chute.sdk.v2.model.AccountBaseModel;
import com.chute.sdk.v2.model.AccountMediaModel;
import com.chute.sdk.v2.model.AssetModel;
import com.getchute.android.photopickerplus.models.DeliverMediaModel;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Helper class containing with static methods regarding {@link AssetModel}s.
 * 
 */
public class AssetUtil {

  /**
   * Creates a list of {@link AssetModel}s from the given
   * {@link DeliverMediaModel} list.
   * 
   * @param resultList
   *            List of {@link DeliverMediaModel}s
   * @return List of {@link AssetModel}s
   */
  public static List<AssetModel> getPhotoCollection(
      List<DeliverMediaModel> resultList) {
    final List<AssetModel> collection = new ArrayList<AssetModel>();
    for (DeliverMediaModel result : resultList) {
      AssetModel asset = getMediaModel(result);
      collection.add(asset);
    }
    return collection;
  }

  /**
   * Creates and {@link AssetModel} out of the given {@link DeliverMediaModel}
   * .
   * 
   * @param model
   *            {@link DeliverMediaModel}
   * @return {@link AssetModel}
   */
  public static AssetModel getMediaModel(DeliverMediaModel model) {
    final AssetModel asset = new AssetModel();
    asset.setId(model.getLocalMediaUri().toString());
    asset.setThumbnail(Uri.fromFile(new File(model.getThumbnail()))
        .toString());
    asset.setUrl(Uri.fromFile(new File(model.getImageUrl())).toString());
    if (model.getVideoUrl() != null) {
    asset.setVideoUrl(Uri.fromFile(new File(model.getVideoUrl()))
        .toString());
    }
    asset.setType(model.getMediaType().name().toLowerCase());
    return asset;
  }

  /**
   * Filters the media items that should be displayed according to the options
   * retrieved from the configuration regarding if the application should
   * support images, videos or both.
   * 
   * @param accountBaseModel
   *            {@link AccountBaseModel}
   * @param supportImages
   *            boolean value indicating whether the application supports
   *            images.
   * @param supportVideos
   *            boolean value indicating whether the application supports
   *            videos.
   * @return {@link AccountBaseModel} containing filtered media files.
   */
  public static AccountBaseModel filterFiles(
      AccountBaseModel accountBaseModel, boolean supportImages,
      boolean supportVideos) {
    AccountBaseModel model = new AccountBaseModel();
    List<AccountAlbumModel> folders = accountBaseModel.getFolders();
    List<AccountMediaModel> files = new ArrayList<AccountMediaModel>();
    List<AccountMediaModel> videos = new ArrayList<AccountMediaModel>();
    List<AccountMediaModel> images = new ArrayList<AccountMediaModel>();
    if (accountBaseModel.getFiles() != null) {
      for (AccountMediaModel file : accountBaseModel.getFiles()) {
        if (file.getVideoUrl() != null && supportVideos == true) {
          videos.add(file);
        }
        if (file.getVideoUrl() == null && supportImages == true) {
          images.add(file);
        }
      }
    }
    files.addAll(images);
    files.addAll(videos);
    model.setFiles(files);
    model.setFolders(folders);
    return model;
  }

}




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