Skip to content

Commit

Permalink
添加splash页面
Browse files Browse the repository at this point in the history
  • Loading branch information
TongmingWu committed Aug 26, 2016
1 parent 0ea73e5 commit 36212a1
Show file tree
Hide file tree
Showing 13 changed files with 463 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".mvp.view.activity.HomeActivity"
android:screenOrientation="portrait">
android:name=".mvp.view.activity.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".mvp.view.activity.HomeActivity"
android:screenOrientation="portrait" />
<activity
android:name=".mvp.view.activity.SearchActivity"
android:screenOrientation="portrait" />
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/com/tongming/manga/mvp/api/ApiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.tongming.manga.mvp.bean.ComicPage;
import com.tongming.manga.mvp.bean.Hot;
import com.tongming.manga.mvp.bean.Search;
import com.tongming.manga.mvp.bean.Sms;
import com.tongming.manga.mvp.bean.User;
import com.tongming.manga.mvp.bean.UserInfo;
import com.tongming.manga.util.CommonUtil;

import java.io.File;
Expand All @@ -16,6 +19,7 @@
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
Expand All @@ -31,6 +35,9 @@ public class ApiManager {
// private static final String BASE_URL = "http://45.78.25.201";
private static final String BASE_URL = "http://119.29.57.187";

public static final String APP_ID = "Rp2mOsDSVkDoN5E4hbJEhlig-gzGzoHsz";
public static final String APP_KEY = "ri3VwT0ULLOqxtdjMPkhkgla";

//短缓存有效期为1秒钟
public static final int CACHE_STALE_SHORT = 1;
//长缓存有效期为7天
Expand Down Expand Up @@ -129,4 +136,24 @@ public Observable<Search> doSearch(String word, int page) {
return apiService.doSearch(word, page);
}

public Observable<Sms> requestSms(RequestBody body) {
return apiService.requestSms(body);
}

public Observable<Sms> verifySms(RequestBody body) {
return apiService.verifySms(body);
}

public Observable<User> login(RequestBody body) {
return apiService.login(body);
}

public Observable<User> logon(RequestBody body) {
return apiService.logon(body);
}

public Observable<UserInfo> getUserInfo(String token) {
return apiService.getUserInfo(token);
}

}
30 changes: 30 additions & 0 deletions app/src/main/java/com/tongming/manga/mvp/api/ApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
import com.tongming.manga.mvp.bean.ComicPage;
import com.tongming.manga.mvp.bean.Hot;
import com.tongming.manga.mvp.bean.Search;
import com.tongming.manga.mvp.bean.Sms;
import com.tongming.manga.mvp.bean.User;
import com.tongming.manga.mvp.bean.UserInfo;

import okhttp3.RequestBody;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;
import rx.Observable;

Expand All @@ -29,4 +36,27 @@ public interface ApiService {
Observable<Search> doSearch(@Query("word") String word, @Query("page") int page);


//@Query("appId") String appId, @Query("appKey") String appKey, @Query("phone") String phone
@Headers("Content-Type:application/json")
@POST("/requestSms")
Observable<Sms> requestSms(@Body RequestBody body);

//@Query("appId") String appId, @Query("appKey") String appKey, @Query("phone") String phone, @Query("code") String code
@Headers("Content-Type:application/json")
@POST("/verifySms")
Observable<Sms> verifySms(@Body RequestBody body);

//@Query("phone") String phone, @Query("password") String password
@Headers("Content-Type:application/json")
@POST("/login")
Observable<User> login(@Body RequestBody body);

//@Query("phone") String phone, @Query("password") String password, @Query("name") String name
@Headers("Content-Type:application/json")
@POST("/logon")
Observable<User> logon(@Body RequestBody body);

@GET("/user")
Observable<UserInfo> getUserInfo(@Query("token") String token);

}
27 changes: 27 additions & 0 deletions app/src/main/java/com/tongming/manga/mvp/bean/Sms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.tongming.manga.mvp.bean;

/**
* Created by Tongming on 2016/8/20.
*/
public class Sms {

private int code;
private String message;

public void setCode(int code) {
this.code = code;
}

public void setMessage(String message) {
this.message = message;
}

public int getCode() {

return code;
}

public String getMessage() {
return message;
}
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/tongming/manga/mvp/bean/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tongming.manga.mvp.bean;

/**
* Created by Tongming on 2016/8/20.
*/
public class User {
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/tongming/manga/mvp/bean/UserInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tongming.manga.mvp.bean;

/**
* Created by Tongming on 2016/8/20.
*/
public class UserInfo {
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ protected void initView() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkPermission();
}
/*byte[] bytes = RSA.encryptData("哈哈".getBytes());
if (bytes != null) {
String strRead = Base64Utils.encode(bytes);
Logger.d(strRead);
}*/
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) rlBar.getLayoutParams();
params.setMargins(0, 80, 0, 0);
final List<BaseFragment> fragments = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -134,6 +135,23 @@ protected int getLayoutId() {
return R.layout.activity_page;
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus && Build.VERSION.SDK_INT >= 19) {
View decorView = getWindow().getDecorView();
//沉浸
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}

@Override
protected void initView() {
handler.postDelayed(runnable, 1000 * 60); //时间定时器
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.tongming.manga.mvp.view.activity;

import android.content.Intent;

import com.tongming.manga.R;
import com.tongming.manga.mvp.base.BaseActivity;

/**
* Created by Tongming on 2016/8/26.
*/
public class SplashActivity extends BaseActivity {

@Override
protected int getLayoutId() {
return R.layout.activity_splash;
}

@Override
protected void initView() {
getWindow().getDecorView().post(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this, HomeActivity.class));
finish();
}
});
}
}
133 changes: 133 additions & 0 deletions app/src/main/java/com/tongming/manga/util/Base64Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.tongming.manga.util;

/**
* Created by Tongming on 2016/4/5.
*/
import java.io.UnsupportedEncodingException;

public class Base64Utils
{
private static final char[] base64EncodeChars = new char[]
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', '+', '/' };
private static final byte[] base64DecodeChars = new byte[]
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 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, -1, -1, -1, -1, -1, -1, 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, -1, -1,
-1, -1, -1 };

/**
* 加密
*
* @param data
* @return
*/
public static String encode(byte[] data)
{
StringBuffer sb = new StringBuffer();
int len = data.length;
int i = 0;
int b1, b2, b3;
while (i < len)
{
b1 = data[i++] & 0xff;
if (i == len)
{
sb.append(base64EncodeChars[b1 >>> 2]);
sb.append(base64EncodeChars[(b1 & 0x3) << 4]);
sb.append("==");
break;
}
b2 = data[i++] & 0xff;
if (i == len)
{
sb.append(base64EncodeChars[b1 >>> 2]);
sb.append(base64EncodeChars[((b1 & 0x03) << 4) | ((b2 & 0xf0) >>> 4)]);
sb.append(base64EncodeChars[(b2 & 0x0f) << 2]);
sb.append("=");
break;
}
b3 = data[i++] & 0xff;
sb.append(base64EncodeChars[b1 >>> 2]);
sb.append(base64EncodeChars[((b1 & 0x03) << 4) | ((b2 & 0xf0) >>> 4)]);
sb.append(base64EncodeChars[((b2 & 0x0f) << 2) | ((b3 & 0xc0) >>> 6)]);
sb.append(base64EncodeChars[b3 & 0x3f]);
}
return sb.toString();
}

/**
* 解密
*
* @param str
* @return
*/
public static byte[] decode(String str)
{
try
{
return decodePrivate(str);
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
return new byte[]
{};
}

private static byte[] decodePrivate(String str) throws UnsupportedEncodingException
{
StringBuffer sb = new StringBuffer();
byte[] data = null;
data = str.getBytes("US-ASCII");
int len = data.length;
int i = 0;
int b1, b2, b3, b4;
while (i < len)
{

do
{
b1 = base64DecodeChars[data[i++]];
} while (i < len && b1 == -1);
if (b1 == -1)
break;

do
{
b2 = base64DecodeChars[data[i++]];
} while (i < len && b2 == -1);
if (b2 == -1)
break;
sb.append((char) ((b1 << 2) | ((b2 & 0x30) >>> 4)));

do
{
b3 = data[i++];
if (b3 == 61)
return sb.toString().getBytes("iso8859-1");
b3 = base64DecodeChars[b3];
} while (i < len && b3 == -1);
if (b3 == -1)
break;
sb.append((char) (((b2 & 0x0f) << 4) | ((b3 & 0x3c) >>> 2)));

do
{
b4 = data[i++];
if (b4 == 61)
return sb.toString().getBytes("iso8859-1");
b4 = base64DecodeChars[b4];
} while (i < len && b4 == -1);
if (b4 == -1)
break;
sb.append((char) (((b3 & 0x03) << 6) | b4));
}
return sb.toString().getBytes("iso8859-1");
}

}
Loading

0 comments on commit 36212a1

Please sign in to comment.