summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/AppDrawerScrubber.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/AppDrawerScrubber.java')
-rw-r--r--src/com/android/launcher3/AppDrawerScrubber.java97
1 files changed, 43 insertions, 54 deletions
diff --git a/src/com/android/launcher3/AppDrawerScrubber.java b/src/com/android/launcher3/AppDrawerScrubber.java
index 41c3199b5..dff02661a 100644
--- a/src/com/android/launcher3/AppDrawerScrubber.java
+++ b/src/com/android/launcher3/AppDrawerScrubber.java
@@ -19,50 +19,40 @@ package com.android.launcher3;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
-import android.util.AttributeSet;
-import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
import android.widget.LinearLayout;
-import android.widget.ListAdapter;
-import android.widget.ListView;
-import android.widget.SectionIndexer;
import android.widget.SeekBar;
import android.widget.TextView;
-public class AppDrawerScrubber extends LinearLayout implements OnClickListener {
+public class AppDrawerScrubber extends LinearLayout {
private final int SCRUBBER_INDICATOR_DISPLAY_DURATION = 200;
private final float SCRUBBER_INDICATOR_DISPLAY_TRANSLATIONY = 20f;
private AppDrawerListAdapter mAdapter;
private RecyclerView mListView;
- private TextView mFirstIndicator, mLastIndicator;
private TextView mScrubberIndicator;
private SeekBar mSeekBar;
private String[] mSections;
private LinearLayoutManager mLayoutManager;
+ public AppDrawerScrubber(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(context);
+ }
+
public AppDrawerScrubber(Context context) {
super(context);
- LayoutInflater.from(context).inflate(R.layout.scrub_layout, this);
- mFirstIndicator = ((TextView) findViewById(R.id.firstSection));
- mFirstIndicator.setOnClickListener(this);
- mLastIndicator = ((TextView) findViewById(R.id.lastSection));
- mLastIndicator.setOnClickListener(this);
- mScrubberIndicator = (TextView) findViewById(R.id.scrubberIndicator);
- mSeekBar = (SeekBar) findViewById(R.id.scrubber);
- init();
+ init(context);
}
public void updateSections() {
mSections = (String[]) mAdapter.getSections();
mSeekBar.setMax(mSections.length - 1);
- mFirstIndicator.setText(mSections[0]);
- mLastIndicator.setText(mSections[mSections.length - 1]);
}
public void setSource(RecyclerView listView) {
@@ -71,13 +61,20 @@ public class AppDrawerScrubber extends LinearLayout implements OnClickListener {
mLayoutManager = (LinearLayoutManager) listView.getLayoutManager();
}
+ public void setScrubberIndicator(TextView scrubberIndicator) {
+ mScrubberIndicator = scrubberIndicator;
+ }
+
private boolean isReady() {
return mListView != null &&
mAdapter != null &&
mSections != null;
}
- private void init() {
+ private void init(Context context) {
+ LayoutInflater.from(context).inflate(R.layout.scrub_layout, this);
+ mSeekBar = (SeekBar) findViewById(R.id.scrubber);
+
mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, final int progress, boolean fromUser) {
@@ -85,57 +82,49 @@ public class AppDrawerScrubber extends LinearLayout implements OnClickListener {
return;
}
resetScrubber();
- mScrubberIndicator.setTranslationX((progress * seekBar.getWidth()) /
- mSections.length);
+
String section = String.valueOf(mSections[progress]);
+
+ if (mScrubberIndicator != null) {
+ float translateX = (progress * seekBar.getWidth()) / mSections.length;
+ translateX -= (mScrubberIndicator.getWidth() / 6); // offset for alignment
+ mScrubberIndicator.setTranslationX(translateX);
+ mScrubberIndicator.setText(section);
+ }
+
mLayoutManager.scrollToPositionWithOffset(
mAdapter.getPositionForSection(progress), 0);
- mScrubberIndicator.setText(section);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
- if (!isReady()) {
- return;
- }
resetScrubber();
- mScrubberIndicator.setAlpha(1f);
- mScrubberIndicator.setVisibility(View.VISIBLE);
+ if (mScrubberIndicator != null) {
+ mScrubberIndicator.setAlpha(1f);
+ mScrubberIndicator.setVisibility(View.VISIBLE);
+ }
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
- if (!isReady()) {
- return;
- }
resetScrubber();
- mScrubberIndicator.animate()
- .alpha(0f)
- .translationYBy(SCRUBBER_INDICATOR_DISPLAY_TRANSLATIONY)
- .setDuration(SCRUBBER_INDICATOR_DISPLAY_DURATION)
- .setListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- mScrubberIndicator.setVisibility(View.INVISIBLE);
- }
- });
+ if (mScrubberIndicator != null) {
+ mScrubberIndicator.animate().alpha(0f).translationYBy(20f)
+ .setDuration(200).setListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mScrubberIndicator.setVisibility(View.INVISIBLE);
+ }
+ });
}
+ }
private void resetScrubber() {
- mScrubberIndicator.animate().cancel();
- mScrubberIndicator.setTranslationY(0f);
+ if (mScrubberIndicator != null) {
+ mScrubberIndicator.animate().cancel();
+ mScrubberIndicator.setTranslationY(0f);
+ }
}
});
}
-
- @Override
- public void onClick(View v) {
- if (v == mFirstIndicator) {
- int positionForFirstSection = mAdapter.getPositionForSection(0);
- mLayoutManager.scrollToPositionWithOffset(positionForFirstSection, 0);
- } else if (v == mLastIndicator) {
- int positionForLastSection = mAdapter.getPositionForSection(mSections.length - 1);
- mLayoutManager.scrollToPositionWithOffset(positionForLastSection, 0);
- }
- }
} \ No newline at end of file