riku
2025-10-30 e9aa93f381afcf9f9cf0c39f2b9e32375ed49528
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package cn.flightfeather.thirdappmodule.activity;
 
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
 
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.module.login.CardFragment;
import cn.flightfeather.thirdappmodule.util.updateApp.UpdateAppUtil;
import cn.flightfeather.thirdappmodule.view.OrientedViewPager;
import cn.flightfeather.thirdappmodule.view.VerticalStackTransformer;
 
 
public class LoginActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener {
 
    //横向ViewPager
    private OrientedViewPager movp_main;
    //线性布局
    private LinearLayout mln;
    //卡片碎片
    private CardFragment fragmentCurrent;
    //内容碎片适配器
    private ContentFragmentAdapter adapter;
    //是否显示
    private Boolean show = false;
    //碎片集合
    public List<Fragment> fragmentList = new ArrayList<>();
    //当前位置
    private int positionCurrent = 0;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
//        //将此Activity加入集合中
//        MyApplication.getInstance().addActivity(this);
        //初始化控件
        initControl();
        //创建内容碎片适配器
        createContentFragmentAdapter();
        //设置横向ViewPager
        setOrientationViewPager();
        //设置监听
        setListener();
        //初始化半透明状态栏
        initTransparentStatsBar();
        //更新检查
        checkUpdate();
    }
 
 
    private void setListener() {
        //设置ViewPager滑动监听
        movp_main.setOnPageChangeListener(this);
    }
 
    private void setOrientationViewPager() {
        movp_main.setOrientation(OrientedViewPager.Orientation.VERTICAL);
        movp_main.setOffscreenPageLimit(2);
        movp_main.setPageTransformer(true, (ViewPager.PageTransformer) new VerticalStackTransformer(this));
        movp_main.setAdapter(adapter);
        movp_main.setDisableTouch(true);
        SharedPreferences sharedPre = getSharedPreferences("config", MODE_PRIVATE);
        positionCurrent = sharedPre.getInt("pos", 0);
        //设置默认显示碎片
        fragmentCurrent = (CardFragment) adapter.instantiateItem(movp_main, positionCurrent);
 
    }
 
    private void createContentFragmentAdapter() {
        adapter = new ContentFragmentAdapter(getSupportFragmentManager(), getCardFragments());
    }
 
    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));
    }
 
    private void initControl() {
        movp_main = (OrientedViewPager) findViewById(R.id.ovp_main);
        mln = (LinearLayout) findViewById(R.id.mln);
    }
 
    public void initTransparentStatsBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            this.getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.transStatusBar));
            mln.setPadding(0, getStatusBarHeight(), 0, 0);
        }
    }
 
    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
 
    public void showButton() {
        //   fragmentCurrent = adapter.getCardFragment();
        fragmentCurrent.showLoginButton();
    }
 
    public void hideButton() {
        fragmentCurrent.hideLoginButtion();
    }
 
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        if (position == 0 && positionOffsetPixels == 0) {
            show = true;
        } else {
            show = false;
        }
    }
 
    @Override
    public void onPageSelected(int position) {
        fragmentCurrent = (CardFragment) adapter.instantiateItem(movp_main, position);
        showButton();
        int a = position % 3;
        if (a == 0) {
            mln.setBackgroundColor(getResources().getColor(R.color.lightBlue));
            fragmentCurrent.changeLoginColor("#03A9F4");
        } else if (a == 1) {
            mln.setBackgroundColor(getResources().getColor(R.color.lightGreen));
            fragmentCurrent.changeLoginColor("#8BC34A");
        } else if (a == 2) {
            mln.setBackgroundColor(getResources().getColor(R.color.orange));
            fragmentCurrent.changeLoginColor("#f26d44");
        }
    }
 
    @Override
    public void onPageScrollStateChanged(int state) {
        if (state == 1) {
 
            hideButton();
        } else if (state == 2) {
            showButton();
        } else if (state == 0 && show) {
            showButton();
        }
    }
 
    public void setCurFragment(int pos) {
        movp_main.setCurrentItem(pos);
    }
 
    private void checkUpdate() {
        UpdateAppUtil updateAppUtil = new UpdateAppUtil((CommonApplication) getApplication(), this);
        updateAppUtil.checkUpdateApp(false);
    }
 
}