Skip to content
This repository was archived by the owner on Aug 22, 2020. It is now read-only.

Commit 245ec88

Browse files
committed
VerticalStepper: New attr isAnimationEnabled
Signed-off-by: Fung <fython@163.com>
1 parent eeeeff7 commit 245ec88

5 files changed

Lines changed: 51 additions & 6 deletions

File tree

demo/src/main/java/moe/feng/common/stepperview/demo/fragment/VerticalStepperAdapterDemoFragment.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.view.LayoutInflater;
88
import android.view.View;
99
import android.view.ViewGroup;
10+
import android.widget.Button;
1011
import android.widget.TextView;
1112
import moe.feng.common.stepperview.IStepperViewAdapter;
1213
import moe.feng.common.stepperview.VerticalStepperItemView;
@@ -51,7 +52,7 @@ public int size() {
5152
}
5253

5354
@Override
54-
public View onCreateCustomView(int index, Context context, VerticalStepperItemView parent) {
55+
public View onCreateCustomView(final int index, Context context, VerticalStepperItemView parent) {
5556
View inflateView = LayoutInflater.from(context).inflate(R.layout.vertical_stepper_sample_item, parent, false);
5657
TextView contentView = inflateView.findViewById(R.id.item_content);
5758
contentView.setText(
@@ -65,10 +66,16 @@ public void onClick(View view) {
6566
}
6667
}
6768
});
69+
Button prevButton = inflateView.findViewById(R.id.button_prev);
70+
prevButton.setText(index == 0 ? R.string.toggle_animation_button : android.R.string.cancel);
6871
inflateView.findViewById(R.id.button_prev).setOnClickListener(new View.OnClickListener() {
6972
@Override
7073
public void onClick(View view) {
71-
mVerticalStepperView.prevStep();
74+
if (index != 0) {
75+
mVerticalStepperView.prevStep();
76+
} else {
77+
mVerticalStepperView.setAnimationEnabled(!mVerticalStepperView.isAnimationEnabled());
78+
}
7279
}
7380
});
7481
return inflateView;

demo/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
<string name="content_step_1">This is the second step. Click OK button to next step or Cancel button to previous step.\n\nThe summary text of each step is optional. If you haven\'t set, summary view won\'t be displayed.</string>
1717
<string name="content_step_2">This is the last step. You can finish steps now.</string>
1818

19+
<string name="toggle_animation_button">Toggle Animation</string>
20+
1921
</resources>

library/src/main/java/moe/feng/common/stepperview/VerticalStepperItemView.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class VerticalStepperItemView extends FrameLayout {
4141
private int mAnimationDuration;
4242
private int mNormalColor, mActivatedColor;
4343
private Drawable mDoneIcon;
44+
private boolean mAnimationEnabled = true;
4445

4546
private @Nullable VerticalStepperItemView mPrevItemView, mNextItemView;
4647

@@ -78,6 +79,7 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
7879
mNormalColor = a.getColor(R.styleable.VerticalStepperItemView_step_normal_color, mNormalColor);
7980
mActivatedColor = a.getColor(R.styleable.VerticalStepperItemView_step_activated_color, mActivatedColor);
8081
mAnimationDuration = a.getInt(R.styleable.VerticalStepperItemView_step_animation_duration, mAnimationDuration);
82+
mAnimationEnabled = a.getBoolean(R.styleable.VerticalStepperItemView_step_enable_animation, true);
8183

8284
if (a.hasValue(R.styleable.VerticalStepperItemView_step_done_icon)) {
8385
mDoneIcon = a.getDrawable(R.styleable.VerticalStepperItemView_step_done_icon);
@@ -92,6 +94,7 @@ public VerticalStepperItemView(Context context, AttributeSet attrs, int defStyle
9294
setState(mState);
9395
setIsLastStep(isLastStep);
9496
setDoneIcon(mDoneIcon);
97+
setAnimationEnabled(mAnimationEnabled);
9598
}
9699

97100
@Override
@@ -228,14 +231,19 @@ public boolean isLastStep() {
228231
return isLastStep;
229232
}
230233

231-
public void setShouldAnimateWhenCustomViewShowHide(boolean shouldAnimate) {
234+
public void setAnimationEnabled(boolean shouldAnimate) {
235+
mAnimationEnabled = shouldAnimate;
232236
if (shouldAnimate) {
233237
mRightContainer.setLayoutTransition(new LayoutTransition());
234238
} else {
235239
mRightContainer.setLayoutTransition(null);
236240
}
237241
}
238242

243+
public boolean isAnimationEnabled() {
244+
return mAnimationEnabled;
245+
}
246+
239247
public void setDoneIcon(Drawable drawable) {
240248
mDoneIcon = drawable;
241249
mDoneIconView.setImageDrawable(drawable);

library/src/main/java/moe/feng/common/stepperview/VerticalStepperView.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class VerticalStepperView extends FrameLayout implements IStepperView {
1717

1818
private IStepperViewAdapter mViewAdapter;
1919
private int mCurrentStep = 0;
20+
private boolean mAnimationEnabled;
2021

2122
private int mAnimationDuration;
2223
private int mNormalColor, mActivatedColor;
@@ -46,13 +47,16 @@ public VerticalStepperView(Context context, AttributeSet attrs, int defStyleAttr
4647
mNormalColor = a.getColor(R.styleable.VerticalStepperView_step_normal_color, mNormalColor);
4748
mActivatedColor = a.getColor(R.styleable.VerticalStepperView_step_activated_color, mActivatedColor);
4849
mAnimationDuration = a.getInt(R.styleable.VerticalStepperView_step_animation_duration, mAnimationDuration);
50+
mAnimationEnabled = a.getBoolean(R.styleable.VerticalStepperView_step_enable_animation, true);
4951

5052
if (a.hasValue(R.styleable.VerticalStepperView_step_done_icon)) {
5153
mDoneIcon = a.getDrawable(R.styleable.VerticalStepperView_step_done_icon);
5254
}
5355

5456
a.recycle();
5557
}
58+
59+
setAnimationEnabled(mAnimationEnabled);
5660
}
5761

5862
private void prepareListView(Context context) {
@@ -90,7 +94,11 @@ public boolean canPrev() {
9094
public boolean nextStep() {
9195
if (canNext()) {
9296
mCurrentStep++;
93-
mAdapter.notifyItemRangeChanged(mCurrentStep - 1, 2);
97+
if (mAnimationEnabled) {
98+
mAdapter.notifyItemRangeChanged(mCurrentStep - 1, 2);
99+
} else {
100+
mAdapter.notifyDataSetChanged();
101+
}
94102
return true;
95103
}
96104
return false;
@@ -99,7 +107,11 @@ public boolean nextStep() {
99107
public boolean prevStep() {
100108
if (canPrev()) {
101109
mCurrentStep--;
102-
mAdapter.notifyItemRangeChanged(mCurrentStep, 2);
110+
if (mAnimationEnabled) {
111+
mAdapter.notifyItemRangeChanged(mCurrentStep, 2);
112+
} else {
113+
mAdapter.notifyDataSetChanged();
114+
}
103115
return true;
104116
}
105117
return false;
@@ -135,12 +147,24 @@ public Drawable getDoneIcon() {
135147
return mDoneIcon;
136148
}
137149

150+
public void setAnimationEnabled(boolean enabled) {
151+
mAnimationEnabled = enabled;
152+
}
153+
154+
public boolean isAnimationEnabled() {
155+
return mAnimationEnabled;
156+
}
157+
138158
public void setCurrentStep(int currentStep) {
139159
int minIndex = Math.min(currentStep, mCurrentStep);
140160
int count = Math.abs(mCurrentStep - currentStep) + 1;
141161

142162
mCurrentStep = currentStep;
143-
mAdapter.notifyItemRangeChanged(minIndex, count);
163+
if (mAnimationEnabled) {
164+
mAdapter.notifyItemRangeChanged(minIndex, count);
165+
} else {
166+
mAdapter.notifyDataSetChanged();
167+
}
144168
}
145169

146170
class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ItemHolder> {
@@ -160,6 +184,7 @@ public void onBindViewHolder(ItemHolder holder, int position) {
160184
holder.mItemView.setActivatedColor(mActivatedColor);
161185
holder.mItemView.setAnimationDuration(mAnimationDuration);
162186
holder.mItemView.setDoneIcon(mDoneIcon);
187+
holder.mItemView.setAnimationEnabled(mAnimationEnabled);
163188
if (getCurrentStep() > position) {
164189
holder.mItemView.setState(VerticalStepperItemView.STATE_DONE);
165190
} else if (getCurrentStep() < position) {

library/src/main/res/values/attrs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
<attr name="step_activated_color" format="color"/>
66
<attr name="step_done_icon" format="reference"/>
77
<attr name="step_animation_duration" format="integer"/>
8+
<attr name="step_enable_animation" format="boolean"/>
89

910
<declare-styleable name="VerticalStepperView">
1011
<attr name="step_normal_color"/>
1112
<attr name="step_activated_color"/>
1213
<attr name="step_done_icon"/>
1314
<attr name="step_animation_duration"/>
15+
<attr name="step_enable_animation"/>
1416
</declare-styleable>
1517

1618
<declare-styleable name="VerticalStepperItemView">
@@ -27,6 +29,7 @@
2729
<attr name="step_activated_color"/>
2830
<attr name="step_done_icon"/>
2931
<attr name="step_animation_duration"/>
32+
<attr name="step_enable_animation"/>
3033
</declare-styleable>
3134

3235
</resources>

0 commit comments

Comments
 (0)