Skip to content

Commit 11f8ad3

Browse files
author
juhonggang
committed
添加仿网易云音乐启动页示例 添加全局弹框 添加Fragment管理器
1 parent 0b5fe60 commit 11f8ad3

26 files changed

Lines changed: 412 additions & 75 deletions

File tree

0 Bytes
Binary file not shown.

BaseComponentDemo/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717

1818
<activity android:name="com.sxu.module1.BaseProgressFragmentStyleActivity"/>
1919

20+
<service android:name=".ShowMagicDialogTestService"/>
2021
</application>
2122
</manifest>

BaseComponentDemo/src/main/java/com/sxu/module1/BaseHomeActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ protected void initActivity() {
112112
// UserManager.getInstance().clearUserInfo();
113113
// LogUtil.i("isLogin====" + UserManager.getInstance().isLogin());
114114

115+
startService(new Intent(this, ShowMagicDialogTestService.class));
115116
for (int i = 0; i < 10; i++) {
116117
new Thread(new Runnable() {
117118
@Override
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.sxu.module1;
2+
3+
import android.app.Service;
4+
import android.content.Intent;
5+
import android.os.Handler;
6+
import android.os.IBinder;
7+
import android.os.Message;
8+
import android.support.annotation.Nullable;
9+
import android.view.Gravity;
10+
import android.view.View;
11+
import android.widget.TextView;
12+
13+
import com.sxu.basecomponent.uiwidget.MagicDialog;
14+
import com.sxu.baselibrary.commonutils.DisplayUtil;
15+
16+
/*******************************************************************************
17+
* Description:
18+
*
19+
* Author: Freeman
20+
*
21+
* Date: 2018/12/16
22+
*
23+
* Copyright: all rights reserved by Freeman.
24+
*******************************************************************************/
25+
public class ShowMagicDialogTestService extends Service {
26+
27+
private Handler handler = new Handler() {
28+
@Override
29+
public void handleMessage(Message msg) {
30+
super.handleMessage(msg);
31+
TextView textView = new TextView(ShowMagicDialogTestService.this);
32+
textView.setGravity(Gravity.CENTER);
33+
textView.setMinimumHeight(DisplayUtil.dpToPx(100));
34+
textView.setText("测试全局弹框");
35+
MagicDialog.show(ShowMagicDialogTestService.this, textView, false);
36+
handler.sendEmptyMessageDelayed(0, 4000);
37+
}
38+
};
39+
40+
@Nullable
41+
@Override
42+
public IBinder onBind(Intent intent) {
43+
return null;
44+
}
45+
46+
@Override
47+
public int onStartCommand(Intent intent, int flags, int startId) {
48+
handler.sendEmptyMessageDelayed(0, 3000);
49+
return super.onStartCommand(intent, flags, startId);
50+
}
51+
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</intent-filter>
2020
</activity>
2121

22-
<activity android:name=".NewUserGuideActivity"
22+
<activity android:name=".WelcomeActivity"
2323
android:taskAffinity=""/>
2424

2525
<service android:name=".InitService"/>

app/src/main/java/com/sxu/simpleproject/MyApplication.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.sxu.basecomponent.utils.ChannelUtil;
1010
import com.sxu.baselibrary.commonutils.LogUtil;
1111
import com.sxu.baselibrary.commonutils.ToastUtil;
12+
import com.sxu.imageloader.FrescoInstance;
13+
import com.sxu.imageloader.ImageLoaderManager;
1214

1315
import org.aspectj.lang.ProceedingJoinPoint;
1416

@@ -31,6 +33,7 @@ public void onCreate() {
3133
ARouter.openDebug();
3234
ARouter.openLog();
3335
ARouter.init(this);
36+
ImageLoaderManager.getInstance().init(this, new FrescoInstance());
3437
LogUtil.i("channel=====" + ChannelUtil.getChannel(this));
3538
}
3639

app/src/main/java/com/sxu/simpleproject/SplashFragment.java

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
import android.app.Activity;
44
import android.content.Intent;
5+
import android.graphics.Bitmap;
56
import android.graphics.Color;
7+
import android.os.Handler;
68
import android.view.View;
7-
import android.widget.Button;
9+
import android.widget.ImageView;
810
import android.widget.TextView;
911
import com.alibaba.android.arouter.launcher.ARouter;
1012

11-
import com.sxu.basecomponent.activity.BaseActivity;
1213
import com.sxu.basecomponent.fragment.BaseFragment;
1314
import com.sxu.basecomponent.utils.PreferenceTag;
14-
import com.sxu.baselibrary.commonutils.LaunchUtil;
15-
import com.sxu.baselibrary.commonutils.SpannableStringUtil;
1615
import com.sxu.baselibrary.datasource.preference.PreferencesManager;
17-
18-
import java.util.logging.Handler;
16+
import com.sxu.imageloader.ImageLoaderListener;
17+
import com.sxu.imageloader.ImageLoaderManager;
18+
import com.sxu.imageloader.WrapImageView;
1919

2020
/**
2121
* 启动页的主要逻辑包括:
@@ -36,7 +36,12 @@
3636
*******************************************************************************/
3737
public class SplashFragment extends BaseFragment {
3838

39-
private TextView descText;
39+
private ImageView nameIcon;
40+
private TextView rightText;
41+
private View bottomLayout;
42+
private WrapImageView adImage;
43+
44+
private Handler handler = new Handler();
4045

4146
@Override
4247
protected int getLayoutResId() {
@@ -45,34 +50,52 @@ protected int getLayoutResId() {
4550

4651
@Override
4752
protected void getViews() {
48-
descText = contentView.findViewById(R.id.desc_text);
53+
adImage = contentView.findViewById(R.id.ad_image);
54+
nameIcon = contentView.findViewById(R.id.name_icon);
55+
rightText = contentView.findViewById(R.id.right_text);
56+
bottomLayout = contentView.findViewById(R.id.bottom_layout);
4957
}
5058

5159
@Override
5260
protected void initFragment() {
53-
String desc = "将启动页的主题背景设置成和启动页相同的背景,即可解决黑白屏问题,具体可参考:";
54-
String urlDesc = "Android开发细节";
55-
SpannableStringUtil.setText(descText, desc + urlDesc, SpannableStringUtil.SPAN_TYPE_TEXT_COLOR,
56-
Color.BLUE, desc.length(), urlDesc.length());
61+
ImageLoaderManager.getInstance().displayImage("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1544963782112&di=88042f9c65595a79866c0d2576279de1&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimage%2Fc0%253Dshijue1%252C0%252C0%252C294%252C40%2Fsign%3D890c50c9db00baa1ae214ff82f79d367%2Fcc11728b4710b912decd6bdbc9fdfc0392452282.jpg", adImage, new ImageLoaderListener() {
62+
@Override
63+
public void onStart() {
64+
65+
}
66+
67+
@Override
68+
public void onProcess(int i, int i1) {
69+
70+
}
5771

58-
descText.setOnClickListener(new View.OnClickListener() {
5972
@Override
60-
public void onClick(View v) {
61-
LaunchUtil.openBrowse(context,
62-
"https://juejin.im/post/5b3e14f8e51d45190570afae");
73+
public void onCompleted(Bitmap bitmap) {
74+
updateView();
75+
}
76+
77+
@Override
78+
public void onFailure(Exception e) {
79+
updateView();
6380
}
6481
});
6582

66-
new android.os.Handler().postDelayed(new Runnable() {
83+
handler.postDelayed(new Runnable() {
6784
@Override
6885
public void run() {
6986
if (PreferencesManager.getBoolean(PreferenceTag.KEY_IS_NEW_USER, true)) {
70-
context.startActivity(new Intent(context, NewUserGuideActivity.class));
87+
context.startActivity(new Intent(context, WelcomeActivity.class));
7188
} else {
7289
ARouter.getInstance().build("/main/home").navigation();
7390
}
7491
((Activity)context).finish();
7592
}
7693
}, 3000);
7794
}
95+
96+
private void updateView() {
97+
nameIcon.setImageResource(R.drawable.app_black_name_icon);
98+
rightText.setTextColor(Color.GRAY);
99+
bottomLayout.setBackgroundColor(Color.WHITE);
100+
}
78101
}

app/src/main/java/com/sxu/simpleproject/NewUserGuideActivity.java renamed to app/src/main/java/com/sxu/simpleproject/WelcomeActivity.java

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
package com.sxu.simpleproject;
22

3-
import android.app.ActivityManager;
4-
import android.content.Context;
5-
import android.content.Intent;
6-
import android.graphics.Color;
73
import android.support.annotation.NonNull;
84
import android.support.v4.view.PagerAdapter;
95
import android.support.v4.view.ViewPager;
10-
import android.support.v7.app.AppCompatActivity;
11-
import android.os.Bundle;
126
import android.view.Gravity;
137
import android.view.View;
148
import android.view.ViewGroup;
15-
import android.view.Window;
16-
import android.view.WindowManager;
179
import android.widget.Button;
10+
import android.widget.ImageView;
1811
import android.widget.TextView;
1912

2013
import com.alibaba.android.arouter.launcher.ARouter;
2114
import com.sxu.basecomponent.activity.BaseActivity;
2215
import com.sxu.basecomponent.utils.PreferenceTag;
23-
import com.sxu.baselibrary.commonutils.DisplayUtil;
24-
import com.sxu.baselibrary.commonutils.LaunchUtil;
25-
import com.sxu.baselibrary.commonutils.LogUtil;
26-
import com.sxu.baselibrary.commonutils.SpannableStringUtil;
2716
import com.sxu.baselibrary.datasource.preference.PreferencesManager;
2817

29-
import java.util.List;
30-
3118
/**
3219
* 说明:新用户引导页通常都是几张图片,且一般都是大图,所以在显示时需要进行相应的优化,否则
3320
* 可能在低端机上出现卡顿甚至OOM。具体的图片优化可参考:
@@ -46,13 +33,16 @@
4633
*
4734
* Copyright: all rights reserved by Freeman.
4835
*******************************************************************************/
49-
public class NewUserGuideActivity extends BaseActivity {
36+
public class WelcomeActivity extends BaseActivity {
5037

5138
private Button entryButton;
5239
private ViewPager guidePager;
5340

54-
private static String[] items = new String[] {
55-
"Page1", "Page2", "Page3", "Page4"
41+
private static int[] items = new int[] {
42+
R.drawable.guide_one_image,
43+
R.drawable.guide_two_image,
44+
R.drawable.guide_three_image,
45+
R.drawable.guide_four_image,
5646
};
5747

5848
@Override
@@ -87,16 +77,24 @@ public void onClick(View v) {
8777
guidePager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
8878
@Override
8979
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
90-
80+
if (positionOffset > 0 && positionOffset < 1) {
81+
entryButton.setVisibility(View.GONE);
82+
} else {
83+
if (position == items.length - 1) {
84+
entryButton.setVisibility(View.VISIBLE);
85+
} else {
86+
entryButton.setVisibility(View.GONE);
87+
}
88+
}
9189
}
9290

9391
@Override
9492
public void onPageSelected(int position) {
95-
if (position == items.length - 1) {
96-
entryButton.setVisibility(View.VISIBLE);
97-
} else {
98-
entryButton.setVisibility(View.GONE);
99-
}
93+
// if (position == items.length - 1) {
94+
// entryButton.setVisibility(View.VISIBLE);
95+
// } else {
96+
// entryButton.setVisibility(View.GONE);
97+
// }
10098
}
10199

102100
@Override
@@ -121,11 +119,10 @@ public int getCount() {
121119
@NonNull
122120
@Override
123121
public Object instantiateItem(@NonNull ViewGroup container, int position) {
124-
TextView textView = new TextView(container.getContext());
125-
textView.setGravity(Gravity.CENTER);
126-
textView.setText(items[position]);
127-
container.addView(textView);
128-
return textView;
122+
ImageView imageView = new ImageView(container.getContext());
123+
imageView.setImageResource(items[position]);
124+
container.addView(imageView);
125+
return imageView;
129126
}
130127

131128
@Override
6.22 KB
Loading
5.16 KB
Loading

0 commit comments

Comments
 (0)