22
33import android .animation .Animator ;
44import android .animation .ObjectAnimator ;
5+ import android .content .Intent ;
6+ import android .net .Uri ;
57import android .os .Build ;
68import android .os .Bundle ;
79import android .view .View ;
2830import java .util .List ;
2931
3032import androidx .appcompat .app .AppCompatActivity ;
33+ import androidx .recyclerview .widget .LinearLayoutManager ;
34+ import androidx .recyclerview .widget .RecyclerView ;
3135
3236/**
3337 * Created by xmuSistone on 2017/5/12.
3438 */
35- public class MainActivity extends AppCompatActivity {
39+ public class MainActivity extends AppCompatActivity implements View . OnClickListener {
3640
37- private View positionView ;
38- private StackViewLayout pileLayout ;
39- private List <ItemEntity > dataList ;
41+ private RecyclerView recyclerView ;
4042
41- private int lastDisplay = -1 ;
42-
43- private ObjectAnimator transitionAnimator ;
44- private float transitionValue ;
45- private HorizontalTransitionLayout countryView , temperatureView ;
46- private VerticalTransitionLayout addressView , timeView ;
47- private FadeTransitionImageView bottomView ;
48- private Animator .AnimatorListener animatorListener ;
49- private TextView descriptionView ;
5043
5144 @ Override
5245 protected void onCreate (Bundle savedInstanceState ) {
5346 super .onCreate (savedInstanceState );
5447 setContentView (R .layout .activity_main );
48+ recyclerView = findViewById (R .id .recyclerView );
49+ findViewById (R .id .bt_web ).setOnClickListener (this );
50+ findViewById (R .id .bt_app ).setOnClickListener (this );
5551
56- positionView = findViewById (R .id .positionView );
57- countryView = findViewById (R .id .countryView );
58- temperatureView = findViewById (R .id .temperatureView );
59- pileLayout = findViewById (R .id .pileLayout );
60- addressView = findViewById (R .id .addressView );
61- descriptionView = findViewById (R .id .descriptionView );
62- timeView = findViewById (R .id .timeView );
63- bottomView = findViewById (R .id .bottomImageView );
64-
65- // 1. 状态栏侵入
66- boolean adjustStatusHeight = false ;
67- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .KITKAT ) {
68- adjustStatusHeight = true ;
69- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
70- //getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
71- } else {
72- //getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
73- }
74- }
75-
76- // 2. 状态栏占位View的高度调整
77- String brand = Build .BRAND ;
78- if (brand .contains ("Xiaomi" )) {
79- Utils .setXiaomiDarkMode (this );
80- } else if (brand .contains ("Meizu" )) {
81- Utils .setMeizuDarkMode (this );
82- } else if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
83- View decor = getWindow ().getDecorView ();
84- //decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
85- //adjustStatusHeight = false;
86- }
87- if (adjustStatusHeight ) {
88- //adjustStatusBarHeight(); // 调整状态栏高度
89- }
90-
91- animatorListener = new Animator .AnimatorListener () {
92- @ Override
93- public void onAnimationStart (Animator animation ) {
94-
95- }
96-
97- @ Override
98- public void onAnimationEnd (Animator animation ) {
99- countryView .onAnimationEnd ();
100- temperatureView .onAnimationEnd ();
101- addressView .onAnimationEnd ();
102- bottomView .onAnimationEnd ();
103- timeView .onAnimationEnd ();
104- }
105-
106- @ Override
107- public void onAnimationCancel (Animator animation ) {
108-
109- }
110-
111- @ Override
112- public void onAnimationRepeat (Animator animation ) {
113-
114- }
115- };
116-
117-
118- // 3. PileLayout绑定Adapter
119- initDataList ();
120- pileLayout .setAdapter (new StackViewLayout .StackViewAdapter () {
121- @ Override
122- public int getLayoutId () {
123- return R .layout .item_layout ;
124- }
125-
126- @ Override
127- public void bindView (View view , int position ) {
128- ViewHolder viewHolder = (ViewHolder ) view .getTag ();
129- if (viewHolder == null ) {
130- viewHolder = new ViewHolder ();
131- viewHolder .imageView = (ImageView ) view .findViewById (R .id .imageView );
132- view .setTag (viewHolder );
133- }
134-
135- Glide .with (MainActivity .this ).load (dataList .get (position ).getCoverImageUrl ()).into (viewHolder .imageView );
136- }
137-
138- @ Override
139- public int getItemCount () {
140- return dataList .size ();
141- }
142-
143- @ Override
144- public void displaying (int position ) {
145- descriptionView .setText (dataList .get (position ).getDescription () + " Since the world is so beautiful, You have to believe me, and this index is " + position );
146- if (lastDisplay < 0 ) {
147- //initSecene(position);
148- lastDisplay = 0 ;
149- } else if (lastDisplay != position ) {
150- //transitionSecene(position);
151- lastDisplay = position ;
152- }
153- }
154-
155- @ Override
156- public void onItemClick (View view , int position ) {
157- super .onItemClick (view , position );
158- Toast .makeText (view .getContext (),"click:" +position ,Toast .LENGTH_SHORT ).show ();
159- }
160- });
161- }
162-
163- private void initSecene (int position ) {
164- countryView .firstInit (dataList .get (position ).getCountry ());
165- temperatureView .firstInit (dataList .get (position ).getTemperature ());
166- addressView .firstInit (dataList .get (position ).getAddress ());
167- bottomView .firstInit (dataList .get (position ).getMapImageUrl ());
168- timeView .firstInit (dataList .get (position ).getTime ());
52+ recyclerView .setLayoutManager (new LinearLayoutManager (this ));
53+ recyclerView .setAdapter (new StackAdapter ());
16954 }
17055
171- private void transitionSecene (int position ) {
172- if (transitionAnimator != null ) {
173- transitionAnimator .cancel ();
56+ @ Override
57+ public void onClick (View v ) {
58+ switch (v .getId ()){
59+ case R .id .bt_app :
60+ updateApp ();
61+ break ;
62+ case R .id .bt_web :
63+ updateWeb ();
64+ break ;
65+ default :
17466 }
175-
176- countryView .saveNextPosition (position , dataList .get (position ).getCountry () + "-" + position );
177- temperatureView .saveNextPosition (position , dataList .get (position ).getTemperature ());
178- addressView .saveNextPosition (position , dataList .get (position ).getAddress ());
179- bottomView .saveNextPosition (position , dataList .get (position ).getMapImageUrl ());
180- timeView .saveNextPosition (position , dataList .get (position ).getTime ());
181-
182- transitionAnimator = ObjectAnimator .ofFloat (this , "transitionValue" , 0.0f , 1.0f );
183- transitionAnimator .setDuration (300 );
184- transitionAnimator .start ();
185- transitionAnimator .addListener (animatorListener );
186-
18767 }
18868
189- /**
190- * 调整沉浸状态栏
191- */
192- private void adjustStatusBarHeight () {
193- int statusBarHeight = Utils .getStatusBarHeight (this );
194- ViewGroup .LayoutParams lp = positionView .getLayoutParams ();
195- lp .height = statusBarHeight ;
196- positionView .setLayoutParams (lp );
69+ void updateWeb (){//"http://app.qq.com/#id=detail&appid=1104844480");//
70+ Uri uri = Uri .parse (String .format ("http://a.app.qq.com/o/simple.jsp?pkgname=%s" ,"cn.com.bailian.bailianmobile" ));
71+ Intent it = new Intent (Intent .ACTION_VIEW , uri );
72+ startActivity (it );
19773 }
19874
199-
200- /**
201- * 从asset读取文件json数据
202- */
203- private void initDataList () {
204- dataList = new ArrayList <>();
75+ void updateApp (){
20576 try {
206- InputStream in = getAssets ().open ("preset.config" );
207- int size = in .available ();
208- byte [] buffer = new byte [size ];
209- in .read (buffer );
210- String jsonStr = new String (buffer , "UTF-8" );
211- JSONObject jsonObject = new JSONObject (jsonStr );
212- JSONArray jsonArray = jsonObject .optJSONArray ("result" );
213- if (null != jsonArray ) {
214- int len = jsonArray .length ();
215- //for (int j = 0; j < 3; j++) {
216- for (int i = 0 ; i < len ; i ++) {
217- JSONObject itemJsonObject = jsonArray .getJSONObject (i );
218- ItemEntity itemEntity = new ItemEntity (itemJsonObject );
219- dataList .add (itemEntity );
220- }
221- //}
222- }
223- } catch (Exception e ) {
224- e .printStackTrace ();
77+ Uri uri = Uri .parse (String .format ("market://details?id=%s" , "cn.com.bailian.bailianmobile" ));
78+ Intent it = new Intent (Intent .ACTION_VIEW , uri );
79+ it .setPackage ("com.tencent.android.qqdownloader" );//com.tencent.android.qqdownloader com.huawei.appmarket
80+ it .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
81+ startActivity (it );
82+ }catch (Exception ex ){
83+ ex .printStackTrace ();
84+ Toast .makeText (this ,"应用宝未安装" ,Toast .LENGTH_SHORT ).show ();
22585 }
22686 }
227-
228- /**
229- * 属性动画
230- */
231- public void setTransitionValue (float transitionValue ) {
232- this .transitionValue = transitionValue ;
233- countryView .duringAnimation (transitionValue );
234- temperatureView .duringAnimation (transitionValue );
235- addressView .duringAnimation (transitionValue );
236- bottomView .duringAnimation (transitionValue );
237- timeView .duringAnimation (transitionValue );
238- }
239-
240- public float getTransitionValue () {
241- return transitionValue ;
242- }
243-
244- class ViewHolder {
245- ImageView imageView ;
246- }
24787}
0 commit comments