-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new API setOnPageSelectedListener. * New Api disableTouchScroll * Optimize BannerViewPager * Fix issue #27 * update sample
- Loading branch information
Showing
38 changed files
with
450 additions
and
383 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
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 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 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
89 changes: 60 additions & 29 deletions
89
app/src/main/java/com/example/zhpan/circleviewpager/activity/WelcomeActivity.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 |
---|---|---|
@@ -1,81 +1,112 @@ | ||
package com.example.zhpan.circleviewpager.activity; | ||
|
||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.content.Intent; | ||
import android.animation.Animator; | ||
import android.animation.AnimatorListenerAdapter; | ||
import android.animation.ObjectAnimator; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.example.zhpan.circleviewpager.R; | ||
import com.example.zhpan.circleviewpager.bean.CustomBean; | ||
import com.example.zhpan.circleviewpager.viewholder.CustomPageViewHolder; | ||
import com.zhpan.bannerview.BannerViewPager; | ||
import com.zhpan.bannerview.adapter.OnPageChangeListenerAdapter; | ||
import com.zhpan.bannerview.constants.IndicatorSlideMode; | ||
import com.zhpan.bannerview.constants.TransformerStyle; | ||
import com.zhpan.bannerview.indicator.CircleIndicatorView; | ||
import com.zhpan.bannerview.indicator.IIndicator; | ||
import com.zhpan.bannerview.holder.HolderCreator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class WelcomeActivity extends AppCompatActivity { | ||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
import butterknife.OnClick; | ||
|
||
public class WelcomeActivity extends BaseDataActivity implements | ||
HolderCreator<CustomPageViewHolder> { | ||
|
||
private BannerViewPager<CustomBean, CustomPageViewHolder> mViewPager; | ||
private int[] imgRes = {R.drawable.guide0, R.drawable.guide1, R.drawable.guide2}; | ||
|
||
private String[] des = {"在这里\n你可以听到周围人的心声", "在这里\nTA会在下一秒遇见你", "在这里\n不再错过可以改变你一生的人"}; | ||
|
||
private int[] transforms = {TransformerStyle.NONE, TransformerStyle.ACCORDION, TransformerStyle.STACK, TransformerStyle.DEPTH, TransformerStyle.ROTATE}; | ||
|
||
@BindView(R.id.btn_start) | ||
TextView mTvStart; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_welcome); | ||
getData(); | ||
ButterKnife.bind(this); | ||
setupViewPager(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
mViewPager.stopLoop(); | ||
super.onDestroy(); | ||
} | ||
|
||
private void setupViewPager() { | ||
mViewPager = findViewById(R.id.viewpager); | ||
mViewPager.setAutoPlay(false) | ||
.setCanLoop(false) | ||
.setPageTransformerStyle(transforms[new Random().nextInt(4)]) | ||
.setPageTransformerStyle(transforms[new Random().nextInt(5)]) | ||
.setIndicatorVisibility(View.GONE) | ||
.setIndicatorView(getIndicatorView()) | ||
.setHolderCreator(() -> { | ||
CustomPageViewHolder customPageViewHolder = new CustomPageViewHolder(); | ||
customPageViewHolder.setOnSubViewClickListener((view, position) -> { | ||
MainActivity.start(WelcomeActivity.this); | ||
finish(); | ||
}); | ||
return customPageViewHolder; | ||
}).create(getData()); | ||
.setIndicatorView(findViewById(R.id.indicator)) | ||
.setIndicatorGap((int) getResources().getDimension(R.dimen.dp_10)) | ||
.setIndicatorColor(getResources().getColor(R.color.white), | ||
getResources().getColor(R.color.white_alpha_75)) | ||
.setIndicatorSlideMode(IndicatorSlideMode.SMOOTH) | ||
.setIndicatorRadius((int) getResources().getDimension(R.dimen.dp_3), (int) getResources().getDimension(R.dimen.dp_4_5)) | ||
.setOnPageChangeListener(new OnPageChangeListenerAdapter() { | ||
@Override | ||
public void onPageSelected(int position) { | ||
showStartButton(position); | ||
} | ||
}) | ||
.setHolderCreator(this) | ||
.create(getData()); | ||
} | ||
|
||
private IIndicator getIndicatorView() { | ||
CircleIndicatorView indicatorView = findViewById(R.id.indicator); | ||
indicatorView.setNormalColor(getResources().getColor(R.color.white)); | ||
indicatorView.setCheckedColor(getResources().getColor(R.color.white_alpha_75)); | ||
indicatorView.setIndicatorWidth((int) getResources().getDimension(R.dimen.dp_6), | ||
(int) getResources().getDimension(R.dimen.dp_9)); | ||
indicatorView.setIndicatorGap((int) getResources().getDimension(R.dimen.dp_10)); | ||
return indicatorView; | ||
@OnClick(R.id.btn_start) | ||
public void onClick(View view) { | ||
MainActivity.start(WelcomeActivity.this); | ||
finish(); | ||
} | ||
|
||
private void showStartButton(int position) { | ||
if (position == mViewPager.getList().size() - 1 && mTvStart.getVisibility() == View.GONE) { | ||
mTvStart.setVisibility(View.VISIBLE); | ||
ObjectAnimator | ||
.ofFloat(mTvStart, "alpha", 0, 1) | ||
.setDuration(1500).start(); | ||
} else { | ||
mTvStart.setVisibility(View.GONE); | ||
} | ||
} | ||
|
||
private List<CustomBean> getData() { | ||
List<CustomBean> list = new ArrayList<>(); | ||
for (int i = 0; i < imgRes.length; i++) { | ||
for (int i = 0; i < mDrawableList.size(); i++) { | ||
CustomBean customBean = new CustomBean(); | ||
customBean.setImageRes(imgRes[i]); | ||
customBean.setImageRes(mDrawableList.get(i)); | ||
customBean.setImageDescription(des[i]); | ||
list.add(customBean); | ||
} | ||
return list; | ||
} | ||
|
||
@Override | ||
public CustomPageViewHolder createViewHolder() { | ||
CustomPageViewHolder customPageViewHolder = new CustomPageViewHolder(); | ||
customPageViewHolder.setOnSubViewClickListener((view, position) -> | ||
Toast.makeText(WelcomeActivity.this, "Logo Clicked,Item: " + position, Toast.LENGTH_SHORT).show()); | ||
return customPageViewHolder; | ||
} | ||
} |
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
Oops, something went wrong.