Advertisement
leons1999

Untitled

May 27th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.57 KB | None | 0 0
  1. package com.ogaclejapan.smarttablayout.demo;
  2.  
  3. import android.content.Context;
  4. import android.content.res.Resources;
  5. import android.support.v4.view.PagerAdapter;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.ImageView;
  10.  
  11. import com.ogaclejapan.smarttablayout.SmartTabLayout;
  12.  
  13. public enum Demo {
  14.  
  15.   BASIC(R.string.demo_title_basic, R.layout.demo_basic),
  16.  
  17.   BASIC2(R.string.demo_title_basic2, R.layout.demo_basic_title_offset_auto_center),
  18.  
  19.   SMART_INDICATOR(R.string.demo_title_smart_indicator, R.layout.demo_smart_indicator),
  20.  
  21.   DISTRIBUTE_EVENLY(R.string.demo_title_distribute_evenly, R.layout.demo_distribute_evenly) {
  22.     @Override
  23.     public int[] tabs() {
  24.       return tab3();
  25.     }
  26.   },
  27.  
  28.   ALWAYS_IN_CENTER(R.string.demo_title_always_in_center, R.layout.demo_always_in_center),
  29.  
  30.   CUSTOM_TAB(R.string.demo_title_custom_tab_text, R.layout.demo_custom_tab_text),
  31.  
  32.   CUSTOM_TAB_COLORS(R.string.demo_title_custom_tab_colors, R.layout.demo_custom_tab_colors),
  33.  
  34.   CUSTOM_TAB_ICONS1(R.string.demo_title_custom_tab_icons1, R.layout.demo_custom_tab_icons1) {
  35.     @Override
  36.     public int[] tabs() {
  37.       return new int[] {
  38.           R.string.demo_tab_no_title,
  39.           R.string.demo_tab_no_title,
  40.           R.string.demo_tab_no_title,
  41.           R.string.demo_tab_no_title
  42.       };
  43.     }
  44.  
  45.     @Override
  46.     public void setup(SmartTabLayout layout) {
  47.       super.setup(layout);
  48.  
  49.       final LayoutInflater inflater = LayoutInflater.from(layout.getContext());
  50.       final Resources res = layout.getContext().getResources();
  51.  
  52.       layout.setCustomTabView(new SmartTabLayout.TabProvider() {
  53.         @Override
  54.         public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
  55.           ImageView icon = (ImageView) inflater.inflate(R.layout.custom_tab_icon1, container,
  56.               false);
  57.           switch (position) {
  58.             case 0:
  59.               icon.setImageDrawable(res.getDrawable(R.drawable.ic_home_white_24dp));
  60.               break;
  61.             case 1:
  62.               icon.setImageDrawable(res.getDrawable(R.drawable.ic_search_white_24dp));
  63.               break;
  64.             case 2:
  65.               icon.setImageDrawable(res.getDrawable(R.drawable.ic_person_white_24dp));
  66.               break;
  67.             case 3:
  68.               icon.setImageDrawable(res.getDrawable(R.drawable.ic_flash_on_white_24dp));
  69.               break;
  70.             default:
  71.               throw new IllegalStateException("Invalid position: " + position);
  72.           }
  73.           return icon;
  74.         }
  75.       });
  76.     }
  77.   },
  78.  
  79.   CUSTOM_TAB_ICONS2(R.string.demo_title_custom_tab_icons2, R.layout.demo_custom_tab_icons2) {
  80.     @Override
  81.     public int[] tabs() {
  82.       return new int[] {
  83.           R.string.demo_tab_no_title,
  84.           R.string.demo_tab_no_title,
  85.           R.string.demo_tab_no_title,
  86.           R.string.demo_tab_no_title
  87.       };
  88.     }
  89.  
  90.     @Override
  91.     public void setup(SmartTabLayout layout) {
  92.       super.setup(layout);
  93.  
  94.       final LayoutInflater inflater = LayoutInflater.from(layout.getContext());
  95.       final Resources res = layout.getContext().getResources();
  96.  
  97.       layout.setCustomTabView(new SmartTabLayout.TabProvider() {
  98.         @Override
  99.         public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
  100.           ImageView icon = (ImageView) inflater.inflate(R.layout.custom_tab_icon2, container,
  101.               false);
  102.           switch (position) {
  103.             case 0:
  104.               icon.setImageDrawable(res.getDrawable(R.drawable.ic_home_white_24dp));
  105.               break;
  106.             case 1:
  107.               icon.setImageDrawable(res.getDrawable(R.drawable.ic_search_white_24dp));
  108.               break;
  109.             case 2:
  110.               icon.setImageDrawable(res.getDrawable(R.drawable.ic_person_white_24dp));
  111.               break;
  112.             case 3:
  113.               icon.setImageDrawable(res.getDrawable(R.drawable.ic_flash_on_white_24dp));
  114.               break;
  115.             default:
  116.               throw new IllegalStateException("Invalid position: " + position);
  117.           }
  118.           return icon;
  119.         }
  120.       });
  121.     }
  122.   },
  123.  
  124.   CUSTOM_TAB_ICON_AND_TEXT(R.string.demo_title_custom_tab_icon_and_text,
  125.       R.layout.demo_custom_tab_icon_and_text) {
  126.     @Override
  127.     public int[] tabs() {
  128.       return tab3();
  129.     }
  130.   },
  131.  
  132.   CUSTOM_TAB_ICON_AND_NOTIFICATION_MARK(R.string.demo_title_custom_tab_icon_and_notification_mark,
  133.       R.layout.demo_custom_tab_icon_and_notification_mark) {
  134.     @Override
  135.     public int[] tabs() {
  136.       return tab3();
  137.     }
  138.  
  139.     @Override
  140.     public void startActivity(Context context) {
  141.       DemoTabWithNotificationMarkActivity.startActivity(context, this);
  142.     }
  143.   },
  144.  
  145.   CUSTOM_TAB_MARGIN(R.string.demo_title_custom_tab_margin, R.layout.demo_custom_tab_margin),
  146.  
  147.   INDICATOR_TRICK1(R.string.demo_title_indicator_trick1, R.layout.demo_indicator_trick1),
  148.  
  149.   INDICATOR_TRICK2(R.string.demo_title_indicator_trick2, R.layout.demo_indicator_trick2),
  150.  
  151.   RIGHT_TO_LEFT(R.string.demo_title_right_to_left, R.layout.demo_rtl) {
  152.     @Override
  153.     public void startActivity(Context context) {
  154.       DemoRtlActivity.startActivity(context, this);
  155.     }
  156.   },
  157.  
  158.   LIKE_MEDIUM_TAG(R.string.demo_title_advanced_medium, R.layout.demo_like_a_medium_tag) {
  159.     @Override
  160.     public int[] tabs() {
  161.       return new int[] {
  162.           R.string.demo_tab_like_a_medium_top,
  163.           R.string.demo_tab_like_a_medium_latest
  164.       };
  165.     }
  166.  
  167.     @Override
  168.     public void startActivity(Context context) {
  169.       DemoLikeMediumActivity.startActivity(context, this);
  170.     }
  171.   };
  172.  
  173.   public final int titleResId;
  174.   public final int layoutResId;
  175.  
  176.   Demo(int titleResId, int layoutResId) {
  177.     this.titleResId = titleResId;
  178.     this.layoutResId = layoutResId;
  179.   }
  180.  
  181.   public static int[] tab10() {
  182.     return new int[] {
  183.         R.string.demo_tab_1,
  184.         R.string.demo_tab_2,
  185.         R.string.demo_tab_3,
  186.         R.string.demo_tab_4,
  187.         R.string.demo_tab_5,
  188.         R.string.demo_tab_6,
  189.         R.string.demo_tab_7,
  190.         R.string.demo_tab_8,
  191.         R.string.demo_tab_9,
  192.         R.string.demo_tab_10
  193.     };
  194.   }
  195.  
  196.   public static int[] tab3() {
  197.     return new int[] {
  198.         R.string.demo_tab_8,
  199.         R.string.demo_tab_9,
  200.         R.string.demo_tab_10
  201.     };
  202.   }
  203.  
  204.   public void startActivity(Context context) {
  205.     DemoActivity.startActivity(context, this);
  206.   }
  207.  
  208.   public void setup(final SmartTabLayout layout) {
  209.     //Do nothing.
  210.   }
  211.  
  212.   public int[] tabs() {
  213.     return tab10();
  214.   }
  215.  
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement