-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
329 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
library/src/main/java/com/twiceyuan/dropdownmenu/widget/BaseDropListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.twiceyuan.dropdownmenu.widget; | ||
|
||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseAdapter; | ||
|
||
import java.util.List; | ||
|
||
public abstract class BaseDropListAdapter<T, VH> extends BaseAdapter { | ||
|
||
private final List<T> mData; | ||
|
||
private int selected = -1; | ||
|
||
public BaseDropListAdapter(List<T> strings) { | ||
mData = strings; | ||
} | ||
|
||
public void setSelected(int selected) { | ||
this.selected = selected; | ||
notifyDataSetChanged(); | ||
} | ||
|
||
protected abstract VH createHolder(View rootView); | ||
|
||
@Override | ||
public int getCount() { | ||
return mData.size(); | ||
} | ||
|
||
@Override | ||
public T getItem(int position) { | ||
return mData.get(position); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return mData.get(position).hashCode(); | ||
} | ||
|
||
protected abstract int itemLayoutId(); | ||
|
||
@Override | ||
public View getView(int position, View convertView, ViewGroup parent) { | ||
VH holder; | ||
if (convertView == null) { | ||
convertView = View.inflate(parent.getContext(), itemLayoutId(), null); | ||
holder = createHolder(convertView); | ||
convertView.setTag(holder); | ||
} else { | ||
//noinspection unchecked | ||
holder = (VH) convertView.getTag(); | ||
} | ||
|
||
if (selected == position) { | ||
onBindSelected(getItem(position), holder); | ||
} else { | ||
onBindNormal(getItem(position), holder); | ||
} | ||
|
||
return convertView; | ||
} | ||
|
||
protected abstract void onBindSelected(T t, VH holder); | ||
|
||
protected abstract void onBindNormal(T t, VH holder); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
<solid android:color="#EEE" /> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
sample/src/main/java/com/twiceyuan/ddmsample/custom/AnimatedHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.twiceyuan.ddmsample.custom; | ||
|
||
import android.animation.Animator; | ||
import android.animation.AnimatorListenerAdapter; | ||
import android.animation.ObjectAnimator; | ||
import android.content.res.Resources; | ||
import android.graphics.drawable.Drawable; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.twiceyuan.ddmsample.R; | ||
import com.twiceyuan.dropdownmenu.contract.DropdownHeader; | ||
import com.twiceyuan.dropdownmenu.listener.OnShowListener; | ||
|
||
/** | ||
* 带动画指示器的头部 | ||
*/ | ||
public class AnimatedHeader implements DropdownHeader<String> { | ||
|
||
private final ViewGroup layout; | ||
private final TextView title; | ||
private final ImageView indicator; | ||
|
||
public AnimatedHeader(ViewGroup layout) { | ||
this.layout = layout; | ||
title = (TextView) layout.getChildAt(0); | ||
indicator = (ImageView) layout.getChildAt(1); | ||
} | ||
|
||
@Override | ||
public void setupShowListener(OnShowListener onShowListener) { | ||
layout.setOnClickListener(v -> onShowListener.onShow(layout)); | ||
} | ||
|
||
@Override | ||
public void onChoose(String result) { | ||
title.setText(result); | ||
} | ||
|
||
@Override | ||
public void onChange(boolean isExpand) { | ||
Resources resources = layout.getContext().getResources(); | ||
|
||
Drawable upIcon = resources.getDrawable(R.drawable.ddm_ic_arrow_up); | ||
Drawable downIcon = resources.getDrawable(R.drawable.ddm_ic_arrow_down); | ||
|
||
Drawable indicatorIcon = isExpand ? upIcon : downIcon; | ||
|
||
ObjectAnimator animator = ObjectAnimator.ofFloat( | ||
indicator, "rotation", 0f, 180f | ||
); | ||
|
||
animator.setDuration(300); | ||
animator.addListener(new AnimatorListenerAdapter() { | ||
@Override | ||
public void onAnimationEnd(Animator animation) { | ||
super.onAnimationEnd(animation); | ||
indicator.setRotation(0f); | ||
indicator.setImageDrawable(indicatorIcon); | ||
} | ||
}); | ||
|
||
animator.start(); | ||
} | ||
} |
Oops, something went wrong.