Android Open Source - Resonos-Android-Framework Custom View Pager






From Project

Back to project page Resonos-Android-Framework.

License

The source code is released under:

Apache License

If you think the Android project Resonos-Android-Framework 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.resonos.apps.library.tabviewpager;
/* w  w w  . j a  v a 2s. c  o  m*/
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;

public class CustomViewPager extends ViewPager {
  
  // constants
  private static final String STATE_SUPER = "cvpSuper", STATE_POS = "cvpRealPos";

  /**
   * Create a custom viewpager for use with {@link TabViewPagerFragment}
   *  and {@link TabViewPagerAdapter}
   * @param context
   */
  public CustomViewPager(Context context) {
    super(context);
  }

  /**
   * Create a custom viewpager for use with {@link TabViewPagerFragment}
   *  and {@link TabViewPagerAdapter}
   * @param context
   * @param attrs
   */
  public CustomViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  @Override
  public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    Bundle b = new Bundle();
    b.putParcelable(STATE_SUPER, superState);
    if (getAdapter() != null) {
      int item = this.getCurrentItem();
      try {
        b.putInt(STATE_POS, getVPAdapter().getRealPage(item));
      } catch (ArrayIndexOutOfBoundsException ex) {
        // occurs very rarely when something triggers a future backstack pop while the activity is hidden
        // this is because the adapter has not gotten a chance to construct its mapping yet
        // it is not necessary to save this information in this case
        // ignore the error and move on
      }
    }
    return b;
  }

  @Override
  public void onRestoreInstanceState(Parcelable state) {
    if (!(state instanceof Bundle)) {
      super.onRestoreInstanceState(state);
      return;
    }
    
    if (state != null) {
      Bundle b = (Bundle)state;
      super.onRestoreInstanceState(b.getParcelable(STATE_SUPER));
      if (getAdapter() != null) {
        int item = ((TabViewPagerAdapter)getAdapter()).getFunctionalPage(b.getInt(STATE_POS));
        if (item >= 0)
          this.setCurrentItem(item);
      }
    }
  }
  
  /**
   * Shortcut to get the adapter cast as a {@link TabViewPagerAdapter}
   * @return the viewpager's adapter
   */
  public TabViewPagerAdapter getVPAdapter() {
    return (TabViewPagerAdapter)super.getAdapter();
  }
}




Java Source Code List

com.resonos.apps.library.Action.java
com.resonos.apps.library.AlertFragment.java
com.resonos.apps.library.App.java
com.resonos.apps.library.BaseFragment.java
com.resonos.apps.library.FragmentBaseActivity.java
com.resonos.apps.library.file.AltAndroidFileHandle.java
com.resonos.apps.library.file.AltAndroidFiles.java
com.resonos.apps.library.file.AltFileHandle.java
com.resonos.apps.library.file.FileCache.java
com.resonos.apps.library.media.AudioVisualizer.java
com.resonos.apps.library.media.BitmapMemoryCache.java
com.resonos.apps.library.media.HueColorFilter.java
com.resonos.apps.library.media.ImageLoader.java
com.resonos.apps.library.media.MediaScannerNotifier.java
com.resonos.apps.library.model.Coord.java
com.resonos.apps.library.model.ImmutableCoord.java
com.resonos.apps.library.tabviewpager.CustomViewPager.java
com.resonos.apps.library.tabviewpager.PageIndicator.java
com.resonos.apps.library.tabviewpager.TabPageIndicator.java
com.resonos.apps.library.tabviewpager.TabViewPagerAdapter.java
com.resonos.apps.library.tabviewpager.TabViewPagerFragment.java
com.resonos.apps.library.tabviewpager.TitleProvider.java
com.resonos.apps.library.util.AppUtils.java
com.resonos.apps.library.util.ErrorReporter.java
com.resonos.apps.library.util.LifecycleTaskQueue.java
com.resonos.apps.library.util.M.java
com.resonos.apps.library.util.NetworkClient.java
com.resonos.apps.library.util.NetworkRequest.java
com.resonos.apps.library.util.ParameterList.java
com.resonos.apps.library.util.SensorReader.java
com.resonos.apps.library.util.TouchViewWorker.java
com.resonos.apps.library.util.ViewServer.java
com.resonos.apps.library.widget.DashboardLayout.java
com.resonos.apps.library.widget.FormBuilder.java
com.resonos.apps.library.widget.FormElement.java
com.resonos.apps.library.widget.ListFormBuilder.java
com.resonos.apps.library.widget.PopupWindows3D.java
com.resonos.apps.library.widget.QuickAction3D.java
com.resonos.apps.library.widget.RangeSeekBar.java
com.resonos.apps.library.widget.SeekBar.java
com.resonos.apps.library.widget.ToolBarButton.java
com.resonos.apps.library.widget.ToolBar.java