|
@@ -22,9 +22,9 @@
|
|
|
package com.owncloud.android.ui.whatsnew;
|
|
|
|
|
|
import android.content.Context;
|
|
|
+import android.graphics.drawable.TransitionDrawable;
|
|
|
import android.util.AttributeSet;
|
|
|
import android.view.Gravity;
|
|
|
-import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.FrameLayout;
|
|
|
import android.widget.ImageView;
|
|
@@ -38,10 +38,9 @@ import com.owncloud.android.R;
|
|
|
public class ProgressIndicator extends FrameLayout {
|
|
|
|
|
|
protected LinearLayout mDotsContainer;
|
|
|
- protected ImageView mCurrentProgressDot;
|
|
|
|
|
|
- protected int mNumberOfSteps;
|
|
|
- protected int mCurrentStep;
|
|
|
+ protected int mNumberOfSteps = -1;
|
|
|
+ protected int mCurrentStep = -1;
|
|
|
|
|
|
public ProgressIndicator(Context context) {
|
|
|
super(context);
|
|
@@ -58,61 +57,37 @@ public class ProgressIndicator extends FrameLayout {
|
|
|
setup();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onWindowFocusChanged(boolean hasWindowFocus) {
|
|
|
- super.onWindowFocusChanged(hasWindowFocus);
|
|
|
- // This is not the best place to reset steps but I couldn't find a better one
|
|
|
- setStep(mCurrentStep);
|
|
|
- }
|
|
|
-
|
|
|
public boolean hasNextStep() {
|
|
|
return mNumberOfSteps > mCurrentStep;
|
|
|
}
|
|
|
|
|
|
- public boolean hasPrevStep() {
|
|
|
- return mCurrentStep > 1;
|
|
|
- }
|
|
|
-
|
|
|
- public void animateToNextStep() {
|
|
|
- animateToStep(mCurrentStep+1);
|
|
|
- }
|
|
|
-
|
|
|
- public void animateToPrevStep() {
|
|
|
- animateToStep(mCurrentStep-1);
|
|
|
- }
|
|
|
-
|
|
|
public void setNumberOfSteps(int steps) {
|
|
|
mNumberOfSteps = steps;
|
|
|
mDotsContainer.removeAllViews();
|
|
|
for (int i = 0; i < steps; ++i) {
|
|
|
ImageView iv = new ImageView(getContext());
|
|
|
- iv.setImageDrawable(getContext().getResources().getDrawable(R.drawable.indicator_dot_background));
|
|
|
+ iv.setImageDrawable(getContext().getResources().getDrawable(R.drawable.whats_new_progress_transition));
|
|
|
mDotsContainer.addView(iv);
|
|
|
}
|
|
|
+ animateToStep(1);
|
|
|
}
|
|
|
|
|
|
- private void setStep(int step) {
|
|
|
+ public void animateToStep(int step) {
|
|
|
if (step < 1 || step > mNumberOfSteps) return;
|
|
|
|
|
|
- View dot = mDotsContainer.getChildAt(step-1);
|
|
|
- FrameLayout.LayoutParams lp = (LayoutParams) mCurrentProgressDot.getLayoutParams();
|
|
|
- lp.leftMargin = dot.getLeft();
|
|
|
- lp.topMargin = dot.getTop();
|
|
|
- mCurrentProgressDot.setLayoutParams(lp);
|
|
|
- }
|
|
|
+ if (mCurrentStep != -1) {
|
|
|
+ ImageView prevDot = (ImageView) mDotsContainer.getChildAt(mCurrentStep-1);
|
|
|
+ TransitionDrawable transition = (TransitionDrawable)prevDot.getDrawable();
|
|
|
+ transition.resetTransition();
|
|
|
+ }
|
|
|
|
|
|
- public void animateToStep(int step) {
|
|
|
- if (step < 1 || step > mNumberOfSteps) return;
|
|
|
mCurrentStep = step;
|
|
|
- View dot = mDotsContainer.getChildAt(step-1);
|
|
|
- mCurrentProgressDot
|
|
|
- .animate()
|
|
|
- .x(dot.getLeft())
|
|
|
- .y(dot.getTop());
|
|
|
+ ImageView dot = (ImageView)mDotsContainer.getChildAt(step-1);
|
|
|
+ TransitionDrawable transition = (TransitionDrawable)dot.getDrawable();
|
|
|
+ transition.startTransition(500);
|
|
|
}
|
|
|
|
|
|
private void setup() {
|
|
|
- mCurrentStep = 1;
|
|
|
|
|
|
mDotsContainer = new LinearLayout(getContext());
|
|
|
mDotsContainer.setGravity(Gravity.CENTER);
|
|
@@ -121,14 +96,6 @@ public class ProgressIndicator extends FrameLayout {
|
|
|
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
mDotsContainer.setLayoutParams(params);
|
|
|
addView(mDotsContainer);
|
|
|
-
|
|
|
- mCurrentProgressDot = new ImageView(getContext());
|
|
|
- params = generateDefaultLayoutParams();
|
|
|
- params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
|
- params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
|
- mCurrentProgressDot.setLayoutParams(params);
|
|
|
- mCurrentProgressDot.setImageDrawable(getContext().getResources().getDrawable(R.drawable.indicator_dot_selected));
|
|
|
- addView(mCurrentProgressDot);
|
|
|
}
|
|
|
|
|
|
}
|