Skip to content

Commit

Permalink
Change the way of displaying progress indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Przybylski committed Feb 13, 2016
1 parent 3e515de commit 62b7757
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 64 deletions.
10 changes: 0 additions & 10 deletions res/drawable/indicator_dot_background.xml

This file was deleted.

29 changes: 29 additions & 0 deletions res/drawable/indicator_dot_not_selected.xml
Original file line number Diff line number Diff line change
@@ -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>
20 changes: 19 additions & 1 deletion res/drawable/indicator_dot_selected.xml
Original file line number Diff line number Diff line change
@@ -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"/>
Expand Down
25 changes: 25 additions & 0 deletions res/drawable/whats_new_progress_transition.xml
Original file line number Diff line number Diff line change
@@ -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>
10 changes: 4 additions & 6 deletions src/com/owncloud/android/ui/activity/WhatsNewActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* ownCloud Android client application
*
* @author Bartosz Przybylski
* Copyright (C) 2015 Bartosz Przybylski
* Copyright (C) 2015 ownCloud Inc.
*
Expand Down Expand Up @@ -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) {
Expand All @@ -68,10 +66,10 @@ protected void onCreate(Bundle savedInstanceState) {
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);


Expand All @@ -80,8 +78,8 @@ protected void onCreate(Bundle savedInstanceState) {
@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();
Expand Down
61 changes: 14 additions & 47 deletions src/com/owncloud/android/ui/whatsnew/ProgressIndicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,10 +38,9 @@
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);
Expand All @@ -58,61 +57,37 @@ public ProgressIndicator(Context context, AttributeSet attrs, int defStyleAttr)
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);
Expand All @@ -121,14 +96,6 @@ private void setup() {
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);
}

}

0 comments on commit 62b7757

Please sign in to comment.