Skip to content

Commit

Permalink
添加仿网易云音乐启动页示例 添加全局弹框 添加Fragment管理器
Browse files Browse the repository at this point in the history
  • Loading branch information
juhonggang committed Dec 16, 2018
1 parent 0b5fe60 commit 11f8ad3
Show file tree
Hide file tree
Showing 26 changed files with 412 additions and 75 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
1 change: 1 addition & 0 deletions BaseComponentDemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@

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

<service android:name=".ShowMagicDialogTestService"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ protected void initActivity() {
// UserManager.getInstance().clearUserInfo();
// LogUtil.i("isLogin====" + UserManager.getInstance().isLogin());

startService(new Intent(this, ShowMagicDialogTestService.class));
for (int i = 0; i < 10; i++) {
new Thread(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.sxu.module1;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.sxu.basecomponent.uiwidget.MagicDialog;
import com.sxu.baselibrary.commonutils.DisplayUtil;

/*******************************************************************************
* Description:
*
* Author: Freeman
*
* Date: 2018/12/16
*
* Copyright: all rights reserved by Freeman.
*******************************************************************************/
public class ShowMagicDialogTestService extends Service {

private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
TextView textView = new TextView(ShowMagicDialogTestService.this);
textView.setGravity(Gravity.CENTER);
textView.setMinimumHeight(DisplayUtil.dpToPx(100));
textView.setText("测试全局弹框");
MagicDialog.show(ShowMagicDialogTestService.this, textView, false);
handler.sendEmptyMessageDelayed(0, 4000);
}
};

@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
handler.sendEmptyMessageDelayed(0, 3000);
return super.onStartCommand(intent, flags, startId);
}
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</intent-filter>
</activity>

<activity android:name=".NewUserGuideActivity"
<activity android:name=".WelcomeActivity"
android:taskAffinity=""/>

<service android:name=".InitService"/>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/sxu/simpleproject/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.sxu.basecomponent.utils.ChannelUtil;
import com.sxu.baselibrary.commonutils.LogUtil;
import com.sxu.baselibrary.commonutils.ToastUtil;
import com.sxu.imageloader.FrescoInstance;
import com.sxu.imageloader.ImageLoaderManager;

import org.aspectj.lang.ProceedingJoinPoint;

Expand All @@ -31,6 +33,7 @@ public void onCreate() {
ARouter.openDebug();
ARouter.openLog();
ARouter.init(this);
ImageLoaderManager.getInstance().init(this, new FrescoInstance());
LogUtil.i("channel=====" + ChannelUtil.getChannel(this));
}

Expand Down
59 changes: 41 additions & 18 deletions app/src/main/java/com/sxu/simpleproject/SplashFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.alibaba.android.arouter.launcher.ARouter;

import com.sxu.basecomponent.activity.BaseActivity;
import com.sxu.basecomponent.fragment.BaseFragment;
import com.sxu.basecomponent.utils.PreferenceTag;
import com.sxu.baselibrary.commonutils.LaunchUtil;
import com.sxu.baselibrary.commonutils.SpannableStringUtil;
import com.sxu.baselibrary.datasource.preference.PreferencesManager;

import java.util.logging.Handler;
import com.sxu.imageloader.ImageLoaderListener;
import com.sxu.imageloader.ImageLoaderManager;
import com.sxu.imageloader.WrapImageView;

/**
* 启动页的主要逻辑包括:
Expand All @@ -36,7 +36,12 @@
*******************************************************************************/
public class SplashFragment extends BaseFragment {

private TextView descText;
private ImageView nameIcon;
private TextView rightText;
private View bottomLayout;
private WrapImageView adImage;

private Handler handler = new Handler();

@Override
protected int getLayoutResId() {
Expand All @@ -45,34 +50,52 @@ protected int getLayoutResId() {

@Override
protected void getViews() {
descText = contentView.findViewById(R.id.desc_text);
adImage = contentView.findViewById(R.id.ad_image);
nameIcon = contentView.findViewById(R.id.name_icon);
rightText = contentView.findViewById(R.id.right_text);
bottomLayout = contentView.findViewById(R.id.bottom_layout);
}

@Override
protected void initFragment() {
String desc = "将启动页的主题背景设置成和启动页相同的背景,即可解决黑白屏问题,具体可参考:";
String urlDesc = "Android开发细节";
SpannableStringUtil.setText(descText, desc + urlDesc, SpannableStringUtil.SPAN_TYPE_TEXT_COLOR,
Color.BLUE, desc.length(), urlDesc.length());
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() {
@Override
public void onStart() {

}

@Override
public void onProcess(int i, int i1) {

}

descText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LaunchUtil.openBrowse(context,
"https://juejin.im/post/5b3e14f8e51d45190570afae");
public void onCompleted(Bitmap bitmap) {
updateView();
}

@Override
public void onFailure(Exception e) {
updateView();
}
});

new android.os.Handler().postDelayed(new Runnable() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (PreferencesManager.getBoolean(PreferenceTag.KEY_IS_NEW_USER, true)) {
context.startActivity(new Intent(context, NewUserGuideActivity.class));
context.startActivity(new Intent(context, WelcomeActivity.class));
} else {
ARouter.getInstance().build("/main/home").navigation();
}
((Activity)context).finish();
}
}, 3000);
}

private void updateView() {
nameIcon.setImageResource(R.drawable.app_black_name_icon);
rightText.setTextColor(Color.GRAY);
bottomLayout.setBackgroundColor(Color.WHITE);
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
package com.sxu.simpleproject;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sxu.basecomponent.activity.BaseActivity;
import com.sxu.basecomponent.utils.PreferenceTag;
import com.sxu.baselibrary.commonutils.DisplayUtil;
import com.sxu.baselibrary.commonutils.LaunchUtil;
import com.sxu.baselibrary.commonutils.LogUtil;
import com.sxu.baselibrary.commonutils.SpannableStringUtil;
import com.sxu.baselibrary.datasource.preference.PreferencesManager;

import java.util.List;

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

private Button entryButton;
private ViewPager guidePager;

private static String[] items = new String[] {
"Page1", "Page2", "Page3", "Page4"
private static int[] items = new int[] {
R.drawable.guide_one_image,
R.drawable.guide_two_image,
R.drawable.guide_three_image,
R.drawable.guide_four_image,
};

@Override
Expand Down Expand Up @@ -87,16 +77,24 @@ public void onClick(View v) {
guidePager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

if (positionOffset > 0 && positionOffset < 1) {
entryButton.setVisibility(View.GONE);
} else {
if (position == items.length - 1) {
entryButton.setVisibility(View.VISIBLE);
} else {
entryButton.setVisibility(View.GONE);
}
}
}

@Override
public void onPageSelected(int position) {
if (position == items.length - 1) {
entryButton.setVisibility(View.VISIBLE);
} else {
entryButton.setVisibility(View.GONE);
}
// if (position == items.length - 1) {
// entryButton.setVisibility(View.VISIBLE);
// } else {
// entryButton.setVisibility(View.GONE);
// }
}

@Override
Expand All @@ -121,11 +119,10 @@ public int getCount() {
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
TextView textView = new TextView(container.getContext());
textView.setGravity(Gravity.CENTER);
textView.setText(items[position]);
container.addView(textView);
return textView;
ImageView imageView = new ImageView(container.getContext());
imageView.setImageResource(items[position]);
container.addView(imageView);
return imageView;
}

@Override
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/slogan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/splash_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/splash_bg_image"/>
<item android:top="180dp">
<bitmap android:src="@drawable/slogan"
android:gravity="center_horizontal|top"/>
</item>
</layer-list>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_new_user_guide_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
android:id="@+id/entry_button"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_marginBottom="48dp"
android:layout_marginBottom="24dp"
android:visibility="gone"
android:text="点击进入"
android:textSize="@dimen/fs_16"
android:layout_gravity="bottom|center_horizontal"
android:background="@android:color/transparent"/>
</FrameLayout>
50 changes: 30 additions & 20 deletions app/src/main/res/layout/fragment_splash_layout.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:gravity="center"
android:orientation="vertical">
android:layout_height="match_parent">
<com.sxu.imageloader.WrapImageView
android:id="@+id/ad_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="80dp"/>
<LinearLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center"
android:layout_gravity="center_horizontal|bottom"
android:orientation="vertical">
<ImageView
android:id="@+id/name_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:src="@drawable/app_white_name_icon"/>
<TextView
android:id="@+id/right_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:text="—— 网易公司版权所有 ©2018 ——"
android:textSize="10dp"
android:textColor="@color/white"/>
</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/fs_17"
android:text="这是启动页"
android:textStyle="bold"/>

<TextView
android:id="@+id/desc_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:text="将启动页的主题背景设置成和主题页相同的背景,即可解决黑白屏问题,具体可参考:"/>

</LinearLayout>
</FrameLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</style>

<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">@color/t1</item>
<item name="android:windowBackground">@drawable/splash_bg</item>
</style>

<style name="TransparentTheme" parent="AppTheme">
Expand Down
5 changes: 4 additions & 1 deletion library/basecomponent/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

<application>
<activity android:name=".activity.BaseWebViewActivity"
android:process=":web_process"/>
android:process=":web_process"/>
<activity android:name=".uiwidget.MagicDialog"
android:launchMode="singleTop"
android:theme="@style/TransparentTheme"/>
</application>
</manifest>
Loading

0 comments on commit 11f8ad3

Please sign in to comment.