| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import cn.flightfeather.thirdappmodule.CommonApplication; |
| | | import cn.flightfeather.thirdappmodule.R; |
| | | import cn.flightfeather.thirdappmodule.adapter.ContentFragmentAdapter; |
| | | import cn.flightfeather.thirdappmodule.CommonApplication; |
| | | import cn.flightfeather.thirdappmodule.module.login.CardFragment; |
| | | import cn.flightfeather.thirdappmodule.util.updateApp.UpdateAppUtil; |
| | | import cn.flightfeather.thirdappmodule.view.OrientedViewPager; |
| | |
| | | |
| | | public class LoginActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener { |
| | | |
| | | //region 定义变量及对象 |
| | | //横向ViewPager |
| | | private OrientedViewPager movp_main; |
| | | //线性布局 |
| | |
| | | public List<Fragment> fragmentList = new ArrayList<>(); |
| | | //当前位置 |
| | | private int positionCurrent = 0; |
| | | //endregion |
| | | |
| | | //region Activity创建 |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | |
| | | // MyApplication.getInstance().addActivity(this); |
| | | //初始化控件 |
| | | initControl(); |
| | | //初始化碎片集合数据 |
| | | initFragmentListData(); |
| | | //创建内容碎片适配器 |
| | | createContentFragmentAdapter(); |
| | | //设置横向ViewPager |
| | |
| | | checkUpdate(); |
| | | } |
| | | |
| | | /** |
| | | * Dispatch onResume() to fragments. Note that for better inter-operation |
| | | * with older versions of the platform, at the point of this call the |
| | | * fragments attached to the activity are <em>not</em> resumed. This means |
| | | * that in some cases the previous state may still be saved, not allowing |
| | | * fragment transactions that modify the state. To correctly interact |
| | | * with fragments in their proper state, you should instead override |
| | | * {@link #onResumeFragments()}. |
| | | */ |
| | | @Override |
| | | protected void onResume() { |
| | | super.onResume(); |
| | | |
| | | } |
| | | |
| | | //endregion |
| | | |
| | | //region 设置监听 |
| | | private void setListener() { |
| | | //设置ViewPager滑动监听 |
| | | movp_main.setOnPageChangeListener(this); |
| | | } |
| | | //endregion |
| | | |
| | | //region 设置横向ViewPager |
| | | private void setOrientationViewPager() { |
| | | movp_main.setOrientation(OrientedViewPager.Orientation.VERTICAL); |
| | | movp_main.setOffscreenPageLimit(2); |
| | |
| | | fragmentCurrent = (CardFragment) adapter.instantiateItem(movp_main, positionCurrent); |
| | | |
| | | } |
| | | //endregion |
| | | |
| | | //region 创建内容碎片适配器 |
| | | private void createContentFragmentAdapter() { |
| | | adapter = new ContentFragmentAdapter(getSupportFragmentManager(), fragmentList); |
| | | adapter = new ContentFragmentAdapter(getSupportFragmentManager(), getCardFragments()); |
| | | } |
| | | //endregion |
| | | |
| | | //region 初始化Fragment集合数据 |
| | | public void initFragmentListData() { |
| | | fragmentList.add(new CardFragment()); |
| | | fragmentList.add(new CardFragment()); |
| | | fragmentList.add(new CardFragment()); |
| | | protected ContentFragmentAdapter.onGetItemInterface getCardFragments() { |
| | | return position -> { |
| | | int a = position%3; |
| | | if (a < 0) a = 0; |
| | | return CardFragment.newInstance(a + 1, position); |
| | | }; |
| | | // fragmentList.add(CardFragment.newInstance(1, 0)); |
| | | // fragmentList.add(CardFragment.newInstance(2, 1)); |
| | | // fragmentList.add(CardFragment.newInstance(3, 2)); |
| | | } |
| | | //endregion |
| | | |
| | | //region 初始化控件 |
| | | private void initControl() { |
| | | movp_main = (OrientedViewPager) findViewById(R.id.ovp_main); |
| | | mln = (LinearLayout) findViewById(R.id.mln); |
| | | } |
| | | //endregion |
| | | |
| | | //region 初始化半透明状态栏 |
| | | public void initTransparentStatsBar() { |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| | | this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); |
| | |
| | | mln.setPadding(0, getStatusBarHeight(), 0, 0); |
| | | } |
| | | } |
| | | //endregion |
| | | |
| | | //region 获得状态栏高度 |
| | | public int getStatusBarHeight() { |
| | | int result = 0; |
| | | int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); |
| | |
| | | } |
| | | return result; |
| | | } |
| | | //endregion |
| | | |
| | | //region 显示登录按钮 |
| | | public void showButton() { |
| | | // fragmentCurrent = adapter.getCardFragment(); |
| | | fragmentCurrent.showLoginButton(); |
| | | } |
| | | //endregion |
| | | |
| | | //region 隐藏登录按钮 |
| | | public void hideButton() { |
| | | fragmentCurrent.hideLoginButtion(); |
| | | } |
| | | //endregion |
| | | |
| | | //region ViewPager滑动 |
| | | @Override |
| | | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { |
| | | if (position == 0 && positionOffsetPixels == 0) { |
| | |
| | | show = false; |
| | | } |
| | | } |
| | | //endregion |
| | | |
| | | //region ViewPager选中 |
| | | @Override |
| | | public void onPageSelected(int position) { |
| | | fragmentCurrent = (CardFragment) adapter.instantiateItem(movp_main, position); |
| | |
| | | fragmentCurrent.changeLoginColor("#f26d44"); |
| | | } |
| | | } |
| | | //endregion |
| | | |
| | | //region ViewPager滑动状态改变 |
| | | @Override |
| | | public void onPageScrollStateChanged(int state) { |
| | | if (state == 1) { |
| | |
| | | showButton(); |
| | | } |
| | | } |
| | | //endregion |
| | | |
| | | public void setCurFragment(int pos) { |
| | | movp_main.setCurrentItem(pos); |
| | | } |
| | | |
| | | //<editor-fold desc="检查更新"> |
| | | private void checkUpdate() { |
| | | UpdateAppUtil updateAppUtil = new UpdateAppUtil((CommonApplication) getApplication(), this); |
| | | updateAppUtil.checkUpdateApp(false); |
| | | } |
| | | //</editor-fold> |
| | | |
| | | } |