Advertisement
msveemac

Vee's QuickScroll.java

Jul 2nd, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.33 KB | None | 0 0
  1. package com.vanessaem.FlowIcons;
  2.  
  3. import android.annotation.SuppressLint;
  4. import android.content.Context;
  5. import android.graphics.Canvas;
  6. import android.graphics.Color;
  7. import android.graphics.Paint;
  8. import android.graphics.Path;
  9. import android.graphics.drawable.GradientDrawable;
  10. import android.graphics.drawable.StateListDrawable;
  11. import android.os.Build;
  12. import android.util.AttributeSet;
  13. import android.util.TypedValue;
  14. import android.view.Gravity;
  15. import android.view.MotionEvent;
  16. import android.view.View;
  17. import android.view.ViewGroup;
  18. import android.view.ViewGroup.LayoutParams;
  19. import android.view.animation.AlphaAnimation;
  20. import android.view.animation.Animation;
  21. import android.view.animation.Animation.AnimationListener;
  22. import android.widget.AbsListView;
  23. import android.widget.AbsListView.OnScrollListener;
  24. import android.widget.GridView;
  25. import android.widget.RelativeLayout;
  26. import android.widget.TextView;
  27.  
  28. /** Scroller used for the Advanced Sample **/
  29. public class QuickScroll extends View
  30. {
  31. // IDs
  32. private static final int ID_PIN = 512;
  33. private static final int ID_PIN_TEXT = 513;
  34. // type statics
  35. public static final int TYPE_POPUP = 0;
  36. public static final int TYPE_INDICATOR = 1;
  37. public static final int TYPE_POPUP_WITH_HANDLE = 2;
  38. public static final int TYPE_INDICATOR_WITH_HANDLE = 3;
  39. // style statics
  40. public static final int STYLE_NONE = 0;
  41. public static final int STYLE_HOLO = 1;
  42. // base colors
  43. public static final int GREY_DARK = Color.parseColor("#e0585858");
  44. public static final int GREY_LIGHT = Color.parseColor("#cc538cc6");
  45. public static final int GREY_SCROLLBAR = Color.parseColor("#64404040");
  46. public static final int BLUE_LIGHT = Color.parseColor("#FF538cc6");
  47. public static final int BLUE_LIGHT_SEMITRANSPARENT = Color.parseColor("#66538cc6");
  48. private static final int mScrollbarMargin = 10;
  49. // base variables
  50. private boolean mScrolling;
  51. private AlphaAnimation mFadeIn, mFadeOut;
  52. private TextView mScrollIndicatorText;
  53. private Scrollable mScrollable;
  54. private GridView mList;
  55. private View mScrollbar;
  56. private int mGroupPosition;
  57. private int mItemCount;
  58. private long mFadeDuration = 150;
  59. private int mType;
  60. private boolean mInitialized = false;
  61. private static final int mTextPadding = 4;
  62. // handlebar variables
  63. private View mHandlebar;
  64. // indicator variables
  65. private RelativeLayout mScrollIndicator;
  66.  
  67. // default constructors
  68. public QuickScroll(Context context)
  69. {
  70. super(context);
  71. }
  72.  
  73. public QuickScroll(Context context, AttributeSet attrs)
  74. {
  75. super(context, attrs);
  76. }
  77.  
  78. public QuickScroll(Context context, AttributeSet attrs, int defStyle)
  79. {
  80. super(context, attrs, defStyle);
  81. }
  82.  
  83. /**
  84. * Initializing the QuickScroll, this function must be called.
  85. * <p/>
  86. *
  87. * @param type
  88. * the QuickScroll type. Available inputs: <b>QuickScroll.TYPE_POPUP</b> or <b>QuickScroll.TYPE_INDICATOR</b>
  89. * @param list
  90. * the GridView
  91. * @param scrollable
  92. * the adapter, must implement Scrollable interface
  93. */
  94. public void init(final int type, final GridView list, final Scrollable scrollable, final int style)
  95. {
  96. if (mInitialized)
  97. return;
  98.  
  99. mType = type;
  100. mList = list;
  101. mScrollable = scrollable;
  102. mGroupPosition = -1;
  103. mFadeIn = new AlphaAnimation(.0f, 1.0f);
  104. mFadeIn.setFillAfter(true);
  105. mFadeOut = new AlphaAnimation(1.0f, .0f);
  106. mFadeOut.setFillAfter(true);
  107. mFadeOut.setAnimationListener(new AnimationListener()
  108. {
  109.  
  110. public void onAnimationStart(Animation animation)
  111. {
  112. }
  113.  
  114. public void onAnimationRepeat(Animation animation)
  115. {
  116. }
  117.  
  118. public void onAnimationEnd(Animation animation)
  119. {
  120. mScrolling = false;
  121. }
  122. });
  123. mScrolling = false;
  124.  
  125. final float density = getResources().getDisplayMetrics().density;
  126.  
  127. mList.setOnTouchListener(new OnTouchListener()
  128. {
  129.  
  130. public boolean onTouch(View v, MotionEvent event)
  131. {
  132. if (mScrolling && (event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_DOWN))
  133. {
  134. return true;
  135. }
  136. return false;
  137. }
  138. });
  139.  
  140. final RelativeLayout.LayoutParams containerparams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  141. final RelativeLayout container = new RelativeLayout(getContext());
  142. container.setBackgroundColor(Color.TRANSPARENT);
  143. containerparams.addRule(RelativeLayout.ALIGN_TOP, getId());
  144. containerparams.addRule(RelativeLayout.ALIGN_BOTTOM, getId());
  145. container.setLayoutParams(containerparams);
  146.  
  147. if (mType == TYPE_POPUP || mType == TYPE_POPUP_WITH_HANDLE)
  148. {
  149.  
  150. mScrollIndicatorText = new TextView(getContext());
  151. mScrollIndicatorText.setTextColor(Color.WHITE);
  152. mScrollIndicatorText.setVisibility(View.INVISIBLE);
  153. mScrollIndicatorText.setGravity(Gravity.CENTER);
  154. final RelativeLayout.LayoutParams popupparams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  155.  
  156. popupparams.addRule(RelativeLayout.CENTER_IN_PARENT);
  157. mScrollIndicatorText.setLayoutParams(popupparams);
  158.  
  159. setPopupColor(GREY_LIGHT, GREY_DARK, 1, Color.WHITE, 1);
  160. setTextPadding(mTextPadding, mTextPadding, mTextPadding, mTextPadding);
  161.  
  162. container.addView(mScrollIndicatorText);
  163. }
  164. else if (mType == TYPE_INDICATOR || mType == TYPE_INDICATOR_WITH_HANDLE)
  165. {
  166. mScrollIndicator = createPin();
  167. mScrollIndicatorText = (TextView) mScrollIndicator.findViewById(ID_PIN_TEXT);
  168.  
  169. (mScrollIndicator.findViewById(ID_PIN)).getLayoutParams().width = 25;
  170.  
  171. container.addView(mScrollIndicator);
  172. }
  173.  
  174. // setting scrollbar width
  175. getLayoutParams().width = (int) (30 * density);
  176. mScrollIndicatorText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 32);
  177.  
  178. // scrollbar setup
  179. if (style != STYLE_NONE)
  180. {
  181. final RelativeLayout layout = new RelativeLayout(getContext());
  182. final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  183. params.addRule(RelativeLayout.ALIGN_LEFT, getId());
  184. params.addRule(RelativeLayout.ALIGN_TOP, getId());
  185. params.addRule(RelativeLayout.ALIGN_RIGHT, getId());
  186. params.addRule(RelativeLayout.ALIGN_BOTTOM, getId());
  187. layout.setLayoutParams(params);
  188.  
  189. mScrollbar = new View(getContext());
  190. mScrollbar.setBackgroundColor(GREY_SCROLLBAR);
  191. final RelativeLayout.LayoutParams scrollbarparams = new RelativeLayout.LayoutParams(1, LayoutParams.MATCH_PARENT);
  192. scrollbarparams.addRule(RelativeLayout.CENTER_HORIZONTAL);
  193. scrollbarparams.topMargin = mScrollbarMargin;
  194. scrollbarparams.bottomMargin = mScrollbarMargin;
  195. mScrollbar.setLayoutParams(scrollbarparams);
  196. layout.addView(mScrollbar);
  197. ((ViewGroup) mList.getParent()).addView(layout);
  198. // creating the handlebar
  199. if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE)
  200. {
  201. mHandlebar = new View(getContext());
  202. setHandlebarColor(BLUE_LIGHT, BLUE_LIGHT, BLUE_LIGHT_SEMITRANSPARENT);
  203. final RelativeLayout.LayoutParams handleparams = new RelativeLayout.LayoutParams((int) (12 * density), (int) (36 * density));
  204. mHandlebar.setLayoutParams(handleparams);
  205. ((RelativeLayout.LayoutParams) mHandlebar.getLayoutParams()).addRule(RelativeLayout.CENTER_HORIZONTAL);
  206. layout.addView(mHandlebar);
  207.  
  208. mList.setOnScrollListener(new OnScrollListener()
  209. {
  210.  
  211. public void onScrollStateChanged(AbsListView view, int scrollState)
  212. {
  213.  
  214. }
  215.  
  216. @SuppressLint("NewApi")
  217. public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
  218. {
  219. if (!mScrolling && totalItemCount - visibleItemCount > 0)
  220. {
  221. moveHandlebar(getHeight() * firstVisibleItem / (totalItemCount - visibleItemCount));
  222. }
  223. }
  224. });
  225. }
  226. }
  227.  
  228. mInitialized = true;
  229.  
  230. ((ViewGroup) mList.getParent()).addView(container);
  231. }
  232.  
  233. @Override
  234. public boolean onTouchEvent(MotionEvent event)
  235. {
  236. if (mList.getAdapter() == null)
  237. return false;
  238. mItemCount = mList.getAdapter().getCount();
  239. if (mItemCount == 0)
  240. return false;
  241.  
  242. if (mScrolling && event.getAction() == MotionEvent.ACTION_CANCEL)
  243. {
  244. if (mType == TYPE_POPUP || mType == TYPE_POPUP_WITH_HANDLE)
  245. {
  246.  
  247. mScrollIndicatorText.startAnimation(mFadeOut);
  248. }
  249. else
  250. {
  251.  
  252. mScrollIndicator.startAnimation(mFadeOut);
  253. }
  254. if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE)
  255. mHandlebar.setSelected(false);
  256. }
  257.  
  258. switch (mType)
  259. {
  260. case TYPE_POPUP:
  261. return PopupTouchEvent(event);
  262. case TYPE_POPUP_WITH_HANDLE:
  263. return PopupTouchEvent(event);
  264. case TYPE_INDICATOR:
  265. return IndicatorTouchEvent(event);
  266. case TYPE_INDICATOR_WITH_HANDLE:
  267. return IndicatorTouchEvent(event);
  268. default:
  269. break;
  270. }
  271. return false;
  272. }
  273.  
  274. private boolean IndicatorTouchEvent(final MotionEvent event)
  275. {
  276. switch (event.getAction())
  277. {
  278. case MotionEvent.ACTION_DOWN:
  279.  
  280. mScrollIndicator.startAnimation(mFadeIn);
  281. mScrollIndicator.setPadding(0, 0, getWidth(), 0);
  282. scroll(event.getY());
  283. mScrolling = true;
  284. return true;
  285. case MotionEvent.ACTION_MOVE:
  286. scroll(event.getY());
  287. return true;
  288. case MotionEvent.ACTION_UP:
  289.  
  290. mScrollIndicator.startAnimation(mFadeOut);
  291.  
  292. if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE)
  293. mHandlebar.setSelected(false);
  294. return true;
  295. default:
  296. break;
  297. }
  298. return false;
  299. }
  300.  
  301. private boolean PopupTouchEvent(final MotionEvent event)
  302. {
  303. switch (event.getAction())
  304. {
  305. case MotionEvent.ACTION_DOWN:
  306.  
  307. mScrollIndicatorText.startAnimation(mFadeIn);
  308. mScrolling = true;
  309. scroll(event.getY());
  310. return true;
  311. case MotionEvent.ACTION_MOVE:
  312. scroll(event.getY());
  313. return true;
  314. case MotionEvent.ACTION_UP:
  315.  
  316. mScrollIndicatorText.startAnimation(mFadeOut);
  317.  
  318. if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE)
  319. mHandlebar.setSelected(false);
  320. return true;
  321. default:
  322. break;
  323. }
  324. return false;
  325. }
  326.  
  327. @SuppressLint("NewApi")
  328. private void scroll(final float height)
  329. {
  330. if (mType == TYPE_INDICATOR || mType == TYPE_INDICATOR_WITH_HANDLE)
  331. {
  332. float move = height - (mScrollIndicator.getHeight() / 2);
  333.  
  334. if (move < 0)
  335. move = 0;
  336. else if (move > getHeight() - mScrollIndicator.getHeight())
  337. move = getHeight() - mScrollIndicator.getHeight();
  338.  
  339. mScrollIndicator.setTranslationY(move);
  340. }
  341.  
  342. if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE)
  343. {
  344. mHandlebar.setSelected(true);
  345. moveHandlebar(height - (mHandlebar.getHeight() / 2));
  346. }
  347.  
  348. int postition = (int) ((height / getHeight()) * mItemCount);
  349.  
  350. if (postition < 0)
  351. postition = 0;
  352. else if (postition >= mItemCount)
  353. postition = mItemCount - 1;
  354. mScrollIndicatorText.setText(mScrollable.getIndicatorForPosition(postition, mGroupPosition));
  355. mList.setSelection(mScrollable.getScrollPosition(postition, mGroupPosition));
  356. }
  357.  
  358. private void moveHandlebar(final float where)
  359. {
  360. float move = where;
  361. if (move < mScrollbarMargin)
  362. move = mScrollbarMargin;
  363. else if (move > getHeight() - mHandlebar.getHeight() - mScrollbarMargin)
  364. move = getHeight() - mHandlebar.getHeight() - mScrollbarMargin;
  365.  
  366. mHandlebar.setTranslationY(move);
  367. }
  368.  
  369. /**
  370. * Sets the fade in and fade out duration of the indicator; default is 150 ms.
  371. * <p/>
  372. *
  373. * @param millis
  374. * the fade duration in milliseconds
  375. */
  376. public void setFadeDuration(long millis)
  377. {
  378. mFadeDuration = millis;
  379. mFadeIn.setDuration(mFadeDuration);
  380. mFadeOut.setDuration(mFadeDuration);
  381. }
  382.  
  383. /**
  384. * Sets the indicator colors, when QuickScroll.TYPE_INDICATOR is selected as type.
  385. * <p/>
  386. *
  387. * @param background
  388. * the background color of the square
  389. * @param tip
  390. * the background color of the tip triangle
  391. * @param text
  392. * the color of the text
  393. */
  394. public void setIndicatorColor(final int background, final int tip, final int text)
  395. {
  396. if (mType == TYPE_INDICATOR || mType == TYPE_INDICATOR_WITH_HANDLE)
  397. {
  398. ((Pin) mScrollIndicator.findViewById(ID_PIN)).setColor(tip);
  399. mScrollIndicatorText.setTextColor(text);
  400. mScrollIndicatorText.setBackgroundColor(background);
  401. }
  402. }
  403.  
  404. /**
  405. * Sets the popup colors, when QuickScroll.TYPE_POPUP is selected as type.
  406. * <p/>
  407. *
  408. * @param backgroundcolor
  409. * the background color of the TextView
  410. * @param bordercolor
  411. * the background color of the border surrounding the TextView
  412. * @param textcolor
  413. * the color of the text
  414. */
  415. @SuppressWarnings("deprecation")
  416. @SuppressLint("NewApi")
  417. public void setPopupColor(final int backgroundcolor, final int bordercolor, final int borderwidthDPI, final int textcolor, float cornerradiusDPI)
  418. {
  419.  
  420. final GradientDrawable popupbackground = new GradientDrawable();
  421. popupbackground.setCornerRadius(cornerradiusDPI * getResources().getDisplayMetrics().density);
  422. popupbackground.setStroke((int) (borderwidthDPI * getResources().getDisplayMetrics().density), bordercolor);
  423. popupbackground.setColor(backgroundcolor);
  424.  
  425. if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
  426. mScrollIndicatorText.setBackgroundDrawable(popupbackground);
  427. else
  428. mScrollIndicatorText.setBackground(popupbackground);
  429.  
  430. mScrollIndicatorText.setTextColor(textcolor);
  431. }
  432.  
  433. /**
  434. * Sets the width and height of the TextView containing the indicatortext. Default is WRAP_CONTENT, WRAP_CONTENT.
  435. * <p/>
  436. *
  437. * @param widthDP
  438. * width in DP
  439. * @param heightDP
  440. * height in DP
  441. */
  442. public void setSize(final int widthDP, final int heightDP)
  443. {
  444. final float density = getResources().getDisplayMetrics().density;
  445. mScrollIndicatorText.getLayoutParams().width = (int) (widthDP * density);
  446. mScrollIndicatorText.getLayoutParams().height = (int) (heightDP * density);
  447. }
  448.  
  449. /**
  450. * Sets the padding of the TextView containing the indicator text. Default is 4 dp.
  451. * <p/>
  452. *
  453. * @param paddingLeftDP
  454. * left padding in DP
  455. * @param paddingTopDP
  456. * top param in DP
  457. * @param paddingBottomDP
  458. * bottom param in DP
  459. * @param paddingRightDP
  460. * right param in DP
  461. */
  462. public void setTextPadding(final int paddingLeftDP, final int paddingTopDP, final int paddingBottomDP, final int paddingRightDP)
  463. {
  464. final float density = getResources().getDisplayMetrics().density;
  465. mScrollIndicatorText.setPadding((int) (paddingLeftDP * density), (int) (paddingTopDP * density), (int) (paddingRightDP * density), (int) (paddingBottomDP * density));
  466.  
  467. }
  468.  
  469. /**
  470. * Turns on fixed size for the TextView containing the indicatortext. Do not use with setSize()! This mode looks good if the indicatortext length is fixed, e.g. it's always two characters long.
  471. * <p/>
  472. *
  473. * @param sizeEMS
  474. * number of characters in the indicatortext
  475. */
  476. public void setFixedSize(final int sizeEMS)
  477. {
  478. mScrollIndicatorText.setEms(sizeEMS);
  479. }
  480.  
  481. /**
  482. * Set the textsize of the TextView containing the indicatortext.
  483. *
  484. * @param unit
  485. * - use TypedValue statics
  486. * @param size
  487. * - the size according to the selected unit
  488. */
  489. public void setTextSize(final int unit, final float size)
  490. {
  491. mScrollIndicatorText.setTextSize(unit, size);
  492. }
  493.  
  494. /**
  495. * Set the colors of the handlebar.
  496. *
  497. * @param inactive
  498. * - color of the inactive handlebar
  499. * @param activebase
  500. * - base color of the active handlebar
  501. * @param activestroke
  502. * - stroke of the active handlebar
  503. */
  504. @SuppressWarnings("deprecation")
  505. @SuppressLint("NewApi")
  506. public void setHandlebarColor(final int inactive, final int activebase, final int activestroke)
  507. {
  508. if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE)
  509. {
  510. final float density = getResources().getDisplayMetrics().density;
  511. final GradientDrawable bg_inactive = new GradientDrawable();
  512. bg_inactive.setCornerRadius(density);
  513. bg_inactive.setColor(inactive);
  514. bg_inactive.setStroke((int) (5 * density), Color.TRANSPARENT);
  515. final GradientDrawable bg_active = new GradientDrawable();
  516. bg_active.setCornerRadius(density);
  517. bg_active.setColor(activebase);
  518. bg_active.setStroke((int) (5 * density), activestroke);
  519. final StateListDrawable states = new StateListDrawable();
  520. states.addState(new int[] { android.R.attr.state_selected }, bg_active);
  521. states.addState(new int[] { android.R.attr.state_enabled }, bg_inactive);
  522.  
  523. if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
  524. mHandlebar.setBackgroundDrawable(states);
  525. else
  526. mHandlebar.setBackground(states);
  527. }
  528. }
  529.  
  530. private RelativeLayout createPin()
  531. {
  532. final RelativeLayout pinLayout = new RelativeLayout(getContext());
  533. pinLayout.setVisibility(View.INVISIBLE);
  534.  
  535. final Pin pin = new Pin(getContext());
  536. pin.setId(ID_PIN);
  537. final RelativeLayout.LayoutParams pinParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  538. pinParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  539. pinParams.addRule(RelativeLayout.ALIGN_BOTTOM, ID_PIN_TEXT);
  540. pinParams.addRule(RelativeLayout.ALIGN_TOP, ID_PIN_TEXT);
  541. pin.setLayoutParams(pinParams);
  542. pinLayout.addView(pin);
  543.  
  544. final TextView indicatorTextView = new TextView(getContext());
  545. indicatorTextView.setId(ID_PIN_TEXT);
  546. final RelativeLayout.LayoutParams indicatorParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  547. indicatorParams.addRule(RelativeLayout.LEFT_OF, ID_PIN);
  548. indicatorTextView.setLayoutParams(indicatorParams);
  549. indicatorTextView.setTextColor(Color.WHITE);
  550. indicatorTextView.setGravity(Gravity.CENTER);
  551. indicatorTextView.setBackgroundColor(GREY_LIGHT);
  552. pinLayout.addView(indicatorTextView);
  553.  
  554. return pinLayout;
  555. }
  556.  
  557. public static class Pin extends View
  558. {
  559.  
  560. private static final int mPinColor = Color.argb(224, 66, 66, 66);
  561. private Paint mPaint;
  562. private Path mPath;
  563.  
  564. public Pin(Context context)
  565. {
  566. super(context);
  567. init();
  568. }
  569.  
  570. public Pin(Context context, AttributeSet attrs)
  571. {
  572. super(context, attrs);
  573. init();
  574. }
  575.  
  576. public Pin(Context context, AttributeSet attrs, int defStyle)
  577. {
  578. super(context, attrs, defStyle);
  579. init();
  580. }
  581.  
  582. public void setColor(int color)
  583. {
  584. mPaint.setColor(color);
  585. }
  586.  
  587. private void init()
  588. {
  589. mPath = new Path();
  590. mPaint = new Paint();
  591. mPaint.setAntiAlias(true);
  592. mPaint.setStyle(Paint.Style.FILL);
  593. setColor(mPinColor);
  594. }
  595.  
  596. @Override
  597. protected void onLayout(boolean changed, int left, int top, int right, int bottom)
  598. {
  599. if (changed)
  600. {
  601. mPath.reset();
  602. mPath.moveTo(0, getHeight());
  603. mPath.lineTo(getWidth(), getHeight() / 2);
  604. mPath.lineTo(0, 0);
  605. mPath.close();
  606. }
  607. super.onLayout(changed, left, top, right, bottom);
  608. }
  609.  
  610. @Override
  611. protected void onDraw(Canvas canvas)
  612. {
  613. canvas.drawPath(mPath, mPaint);
  614. super.onDraw(canvas);
  615. }
  616.  
  617. }
  618.  
  619.  
  620. public interface Scrollable
  621. {
  622.  
  623. /**
  624. * This function returns the corresponding String to display at any given position
  625. * <p>
  626. *
  627. * @param childposition
  628. * equals childposition if used with ExpandableListView, position otherwise.
  629. * @param groupposition
  630. * equals groupposition if used with ExpandableListView, zero otherwise.
  631. */
  632. String getIndicatorForPosition(final int childposition, final int groupposition);
  633.  
  634. /**
  635. * This second function is responsible for is for implementing scroll behaviour. This can be used to perform special tasks, e.g. if you want to snap to the first item starting with a letter in an
  636. * alphabetically ordered list or jump between groups in an ExpandableListView. If you want the normal approach, simply return childposition.
  637. * <p>
  638. *
  639. * @param childposition
  640. * equals childposition if used with ExpandableListView, position otherwise.
  641. * @param groupposition
  642. * equals groupposition if used with ExpandableListView, zero otherwise.
  643. */
  644. int getScrollPosition(final int childposition, final int groupposition);
  645.  
  646. }
  647. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement