Skip to content

Commit

Permalink
Update Sample. (#26)
Browse files Browse the repository at this point in the history

* Update sample.
  • Loading branch information
zhpanvip authored Nov 13, 2019
1 parent 099a5ef commit 99d9c31
Show file tree
Hide file tree
Showing 39 changed files with 1,124 additions and 215 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ dependencies {
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-2'
implementation project(path: ':ideahttp')
api 'com.jakewharton:butterknife:10.2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
}
19 changes: 9 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,23 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activity.PageStyleActivity" />
<activity android:name=".activity.IndicatorStyleActivity" />
<activity android:name=".activity.PageTransformerActivity" />
<activity android:name=".activity.NetworkBannerActivity" />
<activity
android:name=".activity.CustomerBannerPageActivity"
android:theme="@style/FullScreenTheme" />
<activity
android:name=".activity.PhotoViewActivity"
android:theme="@style/FullScreenTheme" />
<activity android:name=".activity.MainActivity">
android:name=".activity.WelcomeActivity"
android:theme="@style/FullScreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".activity.PhotoViewActivity"
android:theme="@style/FullScreenTheme" />
<activity android:name=".activity.MainActivity">

</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,43 +1,91 @@
package com.example.zhpan.circleviewpager.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.view.View;
import android.widget.RadioGroup;

import com.example.zhpan.circleviewpager.R;
import com.example.zhpan.circleviewpager.adapter.AdapterFragmentPager;

import butterknife.BindView;
import butterknife.ButterKnife;


public class MainActivity extends AppCompatActivity {

@BindView(R.id.rg_tab)
RadioGroup rgTab;
@BindView(R.id.vp_fragment)
ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
initData();
setListener();
}

public void onClick(View view) {
Intent intent;
switch (view.getId()) {
case R.id.tv_page_style:
intent = new Intent(this, PageStyleActivity.class);
break;
case R.id.btn_view_pager3:
intent = new Intent(this, PhotoViewActivity.class);
break;
case R.id.btn_view_pager5:
intent = new Intent(this, PageTransformerActivity.class);
private void initData() {
AdapterFragmentPager mAdapter = new AdapterFragmentPager(getSupportFragmentManager());
mViewPager.setAdapter(mAdapter);
mViewPager.setOffscreenPageLimit(2);
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {
rgTab.check(getCheckedId(position));
}

@Override
public void onPageScrollStateChanged(int state) {

}
});
}

private int getCheckedId(int position) {
int checkedId = R.id.rb_home;
switch (position) {
case 0:
checkedId = R.id.rb_home;
break;
case R.id.btn_indicator_style:
intent = new Intent(this, IndicatorStyleActivity.class);
case 1:
checkedId = R.id.rb_find;
break;
case R.id.btn_view_pager4:
default:
intent = new Intent(this, NetworkBannerActivity.class);
case 2:
checkedId = R.id.rb_add;
break;
}
startActivity(intent);
return checkedId;
}

private void setListener() {
rgTab.setOnCheckedChangeListener((group, checkedId) -> {
if (checkedId == R.id.rb_home) {
mViewPager.setCurrentItem(AdapterFragmentPager.PAGE_HOME, false);

} else if (checkedId == R.id.rb_find) {
mViewPager.setCurrentItem(AdapterFragmentPager.PAGE_FIND, false);

} else if (checkedId == R.id.rb_add) {
mViewPager.setCurrentItem(AdapterFragmentPager.PAGE_OTHERS, false);
}
});
}

public static void start(Context context) {
context.startActivity(new Intent(context, MainActivity.class));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
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.constants.IndicatorSlideMode;
import com.zhpan.bannerview.constants.TransformerStyle;
import com.zhpan.bannerview.indicator.CircleIndicatorView;
import com.zhpan.bannerview.indicator.IIndicator;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class WelcomeActivity extends AppCompatActivity {

public class CustomerBannerPageActivity extends AppCompatActivity {
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};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_customer_banner);
setContentView(R.layout.activity_welcome);
getData();
setupViewPager();
}
Expand All @@ -38,17 +45,29 @@ private void setupViewPager() {
mViewPager = findViewById(R.id.viewpager);
mViewPager.setAutoPlay(false)
.setCanLoop(false)
.setPageTransformerStyle(transforms[new Random().nextInt(4)])
.setIndicatorVisibility(View.GONE)
.setOnPageClickListener(position -> Toast.makeText(CustomerBannerPageActivity.this,
"点击页面" + mViewPager.getCurrentItem(), Toast.LENGTH_SHORT).show())
.setIndicatorView(getIndicatorView())
.setHolderCreator(() -> {
CustomPageViewHolder customPageViewHolder = new CustomPageViewHolder();
customPageViewHolder.setOnSubViewClickListener((view, position) -> Toast.makeText(CustomerBannerPageActivity.this,
"立即体验" + position, Toast.LENGTH_SHORT).show());
customPageViewHolder.setOnSubViewClickListener((view, position) -> {
MainActivity.start(WelcomeActivity.this);
finish();
});
return customPageViewHolder;
}).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;
}

private List<CustomBean> getData() {
List<CustomBean> list = new ArrayList<>();
for (int i = 0; i < imgRes.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.example.zhpan.circleviewpager.adapter;

import android.util.SparseArray;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;


import com.example.zhpan.circleviewpager.fragment.BaseFragment;
import com.example.zhpan.circleviewpager.fragment.FindFragment;
import com.example.zhpan.circleviewpager.fragment.HomeFragment;
import com.example.zhpan.circleviewpager.fragment.OthersFragment;

import java.util.List;

public class AdapterFragmentPager extends FragmentPagerAdapter {

public static final int PAGE_HOME = 0;

public static final int PAGE_FIND = 1;

public static final int PAGE_OTHERS = 2;

private SparseArray<BaseFragment> fragmentList;

public AdapterFragmentPager(FragmentManager fm) {
super(fm);
fragmentList = getFragments();
}

private SparseArray<BaseFragment> getFragments() {
SparseArray<BaseFragment> fragmentList = new SparseArray<>();
fragmentList.put(PAGE_HOME, HomeFragment.getInstance());
fragmentList.put(PAGE_FIND, FindFragment.getInstance());
fragmentList.put(PAGE_OTHERS, OthersFragment.getInstance());
return fragmentList;
}

@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position);
fragmentList.put(position, (BaseFragment) fragment);
return fragment;
}

@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}

@Override
public int getCount() {
if (fragmentList != null) {
return fragmentList.size();
} else {
return 0;
}
}

}
Loading

0 comments on commit 99d9c31

Please sign in to comment.