浏览代码

Change the way of displaying progress indicator

Bartosz Przybylski 9 年之前
父节点
当前提交
907a61b01e

+ 0 - 10
res/drawable/indicator_dot_background.xml

@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:bottom="2dp" android:top="2dp" android:right="2dp" android:left="2dp">
-        <shape
-            android:shape="oval">
-            <solid android:color="@color/owncloud_blue_dark_transparent"/>
-            <size android:width="8dp" android:height="8dp" />
-        </shape>
-    </item>
-</layer-list>

+ 29 - 0
res/drawable/indicator_dot_not_selected.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ownCloud Android client application
+
+  Copyright (C) 2015 Bartosz Przybylski
+  Copyright (C) 2015 ownCloud Inc.
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License version 2,
+  as published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:bottom="5dp" android:top="5dp" android:right="5dp" android:left="5dp">
+
+        <shape
+            android:shape="oval">
+            <solid android:color="@color/owncloud_blue_dark_transparent"/>
+            <size android:width="8dp" android:height="8dp" />
+        </shape>
+    </item>
+</layer-list>

+ 19 - 1
res/drawable/indicator_dot_selected.xml

@@ -1,6 +1,24 @@
 <?xml version="1.0" encoding="utf-8"?>
+<!--
+  ownCloud Android client application
+
+  Copyright (C) 2015 Bartosz Przybylski
+  Copyright (C) 2015 ownCloud Inc.
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License version 2,
+  as published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:bottom="2dp" android:top="2dp" android:right="2dp" android:left="2dp">
+    <item android:bottom="5dp" android:top="5dp" android:right="5dp" android:left="5dp">
         <shape
             android:shape="oval">
             <solid android:color="@color/owncloud_blue_accent"/>

+ 25 - 0
res/drawable/whats_new_progress_transition.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ownCloud Android client application
+
+  Copyright (C) 2015 Bartosz Przybylski
+  Copyright (C) 2015 ownCloud Inc.
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License version 2,
+  as published by the Free Software Foundation.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<transition xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:drawable="@drawable/indicator_dot_not_selected" />
+    <item android:drawable="@drawable/indicator_dot_selected" />
+</transition>

+ 4 - 6
src/com/owncloud/android/ui/activity/WhatsNewActivity.java

@@ -1,7 +1,6 @@
 /**
  *   ownCloud Android client application
  *
- *   @author Bartosz Przybylski
  *   Copyright (C) 2015 Bartosz Przybylski
  *   Copyright (C) 2015 ownCloud Inc.
  *
@@ -58,7 +57,6 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
     private ImageButton mForwardFinishButton;
     private ProgressIndicator mProgress;
     private ViewPager mPager;
-    private FeaturesViewAdapter mAdapter;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -68,10 +66,10 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
         mProgress = (ProgressIndicator) findViewById(R.id.progressIndicator);
         mPager = (ViewPager)findViewById(R.id.contentPanel);
         final boolean isBeta = getResources().getBoolean(R.bool.is_beta);
-        mAdapter = new FeaturesViewAdapter(getSupportFragmentManager(), FeatureList.getFiltered(getLastSeenVersionCode(), isFirstRun(), isBeta));
+        FeaturesViewAdapter adapter = new FeaturesViewAdapter(getSupportFragmentManager(), FeatureList.getFiltered(getLastSeenVersionCode(), isFirstRun(), isBeta));
 
-        mProgress.setNumberOfSteps(mAdapter.getCount());
-        mPager.setAdapter(mAdapter);
+        mProgress.setNumberOfSteps(adapter.getCount());
+        mPager.setAdapter(adapter);
         mPager.addOnPageChangeListener(this);
 
 
@@ -80,8 +78,8 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
             @Override
             public void onClick(View view) {
                 if (mProgress.hasNextStep()) {
-                    mProgress.animateToNextStep();
                     mPager.setCurrentItem(mPager.getCurrentItem()+1, true);
+                    mProgress.animateToStep(mPager.getCurrentItem()+1);
                 } else {
                     onFinish();
                     finish();

+ 14 - 47
src/com/owncloud/android/ui/whatsnew/ProgressIndicator.java

@@ -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);
 	}
 
 }