content: /*
   * android-spinnerwheel
   * https://github.com/ai212983/android-spinnerwheel
   *
   * based on
   *
   * Android Wheel Control.
   * https://code.google.com/p/android-wheel/
   *
   * Copyright 2011 Yuri Kanivets
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * AbstractWheelCustomAdapter
   * Created by maytree on 16. 4. 6..
   **/
  
  package antistatic.spinnerwheel.adapters;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  /**
   * Abstract spinnerwheel adapter provides common functionality for adapters.
   */
  public abstract class AbstractWheelCustomAdapter extends AbstractWheelAdapter {
  
      /** No resource constant. */
      protected static final int NO_RESOURCE = 0;
  
      // Current context
      protected Context context;
      // Layout inflater
      protected LayoutInflater inflater;
  
      // Items resources
      protected int itemResourceId;
  
      // Empty items resources
      protected int emptyItemResourceId;
  
      /**
       * Constructor
       * @param context the current context
       */
      protected AbstractWheelCustomAdapter(Context context) {
          this(context, NO_RESOURCE);
      }
  
      /**
       * Constructor
       * @param context the current context
       * @param itemResource the resource ID for a layout file containing a TextView to use when instantiating items views
       */
      protected AbstractWheelCustomAdapter(Context context, int itemResource) {
          this.context = context;
          itemResourceId = itemResource;
  
          inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
      /**
       * Constructor
       * @param inflater the current inflater
       */
      protected AbstractWheelCustomAdapter(LayoutInflater inflater) {
          this(inflater, NO_RESOURCE);
      }
  
      /**
       * Constructor
       * @param inflater the current inflater
       * @param itemResource the resource ID for a layout file containing a TextView to use when instantiating items views
       */
      protected AbstractWheelCustomAdapter(LayoutInflater inflater, int itemResource) {
          this.inflater = inflater;
          itemResourceId = itemResource;
      }
  
      /**
       * Gets resource Id for items views
       * @return the item resource Id
       */
      public int getItemResource() {
          return itemResourceId;
      }
  
      /**
       * Sets resource Id for items views
       * @param itemResourceId the resource Id to set
       */
      public void setItemResource(int itemResourceId) {
          this.itemResourceId = itemResourceId;
      }
  
      /**
       * Gets resource Id for empty items views
       * @return the empty item resource Id
       */
      public int getEmptyItemResource() {
          return emptyItemResourceId;
      }
  
      /**
       * Sets resource Id for empty items views
       * @param emptyItemResourceId the empty item resource Id to set
       */
      public void setEmptyItemResource(int emptyItemResourceId) {
          this.emptyItemResourceId = emptyItemResourceId;
      }
  
      @Override
      public View getItem(int index, View convertView, ViewGroup parent, int currentItemIdx) {
          if (index >= 0 && index < getItemsCount()) {
              if (convertView == null) {
                  convertView = getView(itemResourceId, parent);
              }
  
              configureItemView(convertView, index);
  
              return convertView;
          }
          return null;
      }
  
      @Override
      public View getEmptyItem(View convertView, ViewGroup parent) {
          if (convertView == null) {
              convertView = getView(emptyItemResourceId, parent);
          }
  
          return convertView;
      }
  
      /**
       * Configures item view.
       * @param view the custom view to be configured
       */
      abstract protected void configureItemView(View view, int index);
  
      /**
       * Loads view from resources
       * @param resource the resource Id
       * @return the loaded view or null if resource is not set
       */
      private View getView(int resource, ViewGroup parent) {
          switch (resource) {
              case NO_RESOURCE:
                  return null;
              default:
                  return inflater.inflate(resource, parent, false);
          }
      }
  }
  