Android Open Source - photo-picker-plus-android Sack Of Views Adapter






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)//from  w ww.  ja  v a 2s . c om

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.ui.adapter;

import java.util.ArrayList;
import java.util.List;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * Adapter that simply returns row views from a list.
 * 
 * If you supply a size, you must implement newView(), to create a required
 * view. The adapter will then cache these views.
 * 
 * If you supply a list of views in the constructor, that list will be used
 * directly. If any elements in the list are null, then newView() will be called
 * just for those slots.
 * 
 * Subclasses may also wish to override areAllItemsEnabled() (default: false)
 * and isEnabled() (default: false), if some of their rows should be selectable.
 * 
 * It is assumed each view is unique, and therefore will not get recycled.
 * 
 * Note that this adapter is not designed for long lists. It is more for screens
 * that should behave like a list. This is particularly useful if you combine
 * this with other adapters (e.g., SectionedAdapter) that might have an
 * arbitrary number of rows, so it all appears seamless.
 */
public class SackOfViewsAdapter extends BaseAdapter {
  private List<View> views = null;

  /**
   * Constructor creating an empty list of views, but with a specified count.
   * Subclasses must override newView().
   */
  public SackOfViewsAdapter(int count) {
    super();

    views = new ArrayList<View>(count);

    for (int i = 0; i < count; i++) {
      views.add(null);
    }
  }

  /**
   * Constructor wrapping a supplied list of views. Subclasses must override
   * newView() if any of the elements in the list are null.
   */
  public SackOfViewsAdapter(List<View> views) {
    super();

    this.views = views;
  }

  /**
   * Get the data item associated with the specified position in the data set.
   * 
   * @param position
   *            Position of the item whose data we want
   */
  @Override
  public Object getItem(int position) {
    return (views.get(position));
  }

  /**
   * How many items are in the data set represented by this Adapter.
   */
  @Override
  public int getCount() {
    return (views.size());
  }

  /**
   * Returns the number of types of Views that will be created by getView().
   */
  @Override
  public int getViewTypeCount() {
    return (getCount());
  }

  /**
   * Get the type of View that will be created by getView() for the specified
   * item.
   * 
   * @param position
   *            Position of the item whose data we want
   */
  @Override
  public int getItemViewType(int position) {
    return (position);
  }

  /**
   * Are all items in this ListAdapter enabled? If yes it means all items are
   * selectable and clickable.
   */
  @Override
  public boolean areAllItemsEnabled() {
    return (false);
  }

  /**
   * Returns true if the item at the specified position is not a separator.
   * 
   * @param position
   *            Position of the item whose data we want
   */
  @Override
  public boolean isEnabled(int position) {
    return (false);
  }

  /**
   * Get a View that displays the data at the specified position in the data
   * set.
   * 
   * @param position
   *            Position of the item whose data we want
   * @param convertView
   *            View to recycle, if not null
   * @param parent
   *            ViewGroup containing the returned View
   */
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View result = views.get(position);

    if (result == null) {
      result = newView(position, parent);
      views.set(position, result);
    }

    return (result);
  }

  /**
   * Get the row id associated with the specified position in the list.
   * 
   * @param position
   *            Position of the item whose data we want
   */
  @Override
  public long getItemId(int position) {
    return (position);
  }

  public boolean hasView(View v) {
    return (views.contains(v));
  }

  /**
   * Create a new View to go into the list at the specified position.
   * 
   * @param position
   *            Position of the item whose data we want
   * @param parent
   *            ViewGroup containing the returned View
   */
  protected View newView(int position, ViewGroup parent) {
    throw new RuntimeException("You must override newView()!");
  }
}




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