parent
59f9ce7768
commit
e435a31697
@ -1,15 +1,15 @@ |
|||||||
package com.novel.read.event |
package com.novel.read.event |
||||||
|
|
||||||
import com.mango.mangolib.event.BaseEvent |
import com.mango.mangolib.event.BaseEvent |
||||||
import com.novel.read.model.protocol.RankByUpadateResp |
import com.novel.read.model.protocol.RankByUpdateResp |
||||||
|
|
||||||
/** |
/** |
||||||
* create by 赵利君 on 2019/6/18 |
* create by 赵利君 on 2019/6/18 |
||||||
* describe: |
* describe: |
||||||
*/ |
*/ |
||||||
class RankByUpdateEvent : BaseEvent<RankByUpadateResp> { |
class RankByUpdateEvent : BaseEvent<RankByUpdateResp> { |
||||||
|
|
||||||
constructor(result: RankByUpadateResp) : super(result) {} |
constructor(result: RankByUpdateResp) : super(result) {} |
||||||
|
|
||||||
constructor() {} |
constructor() {} |
||||||
} |
} |
||||||
|
@ -1,57 +0,0 @@ |
|||||||
package com.novel.read.model.protocol; |
|
||||||
|
|
||||||
import com.novel.read.base.MyApp; |
|
||||||
import com.novel.read.utlis.StringUtils; |
|
||||||
|
|
||||||
import java.io.Serializable; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
public class CategoryTypeResp implements Serializable { |
|
||||||
|
|
||||||
|
|
||||||
private List<CategoryBean> category; |
|
||||||
|
|
||||||
public List<CategoryBean> getCategory() { |
|
||||||
return category; |
|
||||||
} |
|
||||||
|
|
||||||
public void setCategory(List<CategoryBean> category) { |
|
||||||
this.category = category; |
|
||||||
} |
|
||||||
|
|
||||||
public static class CategoryBean { |
|
||||||
/** |
|
||||||
* id : 1 |
|
||||||
* title : 玄幻奇幻 |
|
||||||
* cover : |
|
||||||
*/ |
|
||||||
|
|
||||||
private int id; |
|
||||||
private String title; |
|
||||||
private String cover; |
|
||||||
|
|
||||||
public int getId() { |
|
||||||
return id; |
|
||||||
} |
|
||||||
|
|
||||||
public void setId(int id) { |
|
||||||
this.id = id; |
|
||||||
} |
|
||||||
|
|
||||||
public String getTitle() { |
|
||||||
return StringUtils.convertCC(title == null ? "" : title); |
|
||||||
} |
|
||||||
|
|
||||||
public void setTitle(String title) { |
|
||||||
this.title = title; |
|
||||||
} |
|
||||||
|
|
||||||
public String getCover() { |
|
||||||
return cover; |
|
||||||
} |
|
||||||
|
|
||||||
public void setCover(String cover) { |
|
||||||
this.cover = cover; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,25 @@ |
|||||||
|
package com.novel.read.model.protocol |
||||||
|
|
||||||
|
import com.novel.read.base.MyApp |
||||||
|
import com.novel.read.utlis.StringUtils |
||||||
|
|
||||||
|
import java.io.Serializable |
||||||
|
|
||||||
|
class CategoryTypeResp : Serializable { |
||||||
|
|
||||||
|
|
||||||
|
var category: List<CategoryBean> = arrayListOf() |
||||||
|
|
||||||
|
class CategoryBean { |
||||||
|
/** |
||||||
|
* id : 1 |
||||||
|
* title : 玄幻奇幻 |
||||||
|
* cover : |
||||||
|
*/ |
||||||
|
|
||||||
|
var id: Int = 0 |
||||||
|
var title: String = "" |
||||||
|
get() = StringUtils.convertCC(field) |
||||||
|
var cover: String? = null |
||||||
|
} |
||||||
|
} |
@ -1,21 +0,0 @@ |
|||||||
package com.novel.read.model.protocol; |
|
||||||
|
|
||||||
import com.novel.read.model.db.ChapterInfoBean; |
|
||||||
|
|
||||||
import java.io.Serializable; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
public class ChapterInfoPackage implements Serializable { |
|
||||||
|
|
||||||
private List<ChapterInfoBean> article; |
|
||||||
|
|
||||||
public List<ChapterInfoBean> getArticle() { |
|
||||||
return article; |
|
||||||
} |
|
||||||
|
|
||||||
public void setArticle(List<ChapterInfoBean> article) { |
|
||||||
this.article = article; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,12 @@ |
|||||||
|
package com.novel.read.model.protocol |
||||||
|
|
||||||
|
import com.novel.read.model.db.ChapterInfoBean |
||||||
|
|
||||||
|
import java.io.Serializable |
||||||
|
|
||||||
|
class ChapterInfoPackage : Serializable { |
||||||
|
|
||||||
|
var article: List<ChapterInfoBean>? = null |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,18 +0,0 @@ |
|||||||
package com.novel.read.model.protocol; |
|
||||||
|
|
||||||
import java.io.Serializable; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
public class HotSearchResp implements Serializable { |
|
||||||
|
|
||||||
|
|
||||||
private List<String> key; |
|
||||||
|
|
||||||
public List<String> getKey() { |
|
||||||
return key; |
|
||||||
} |
|
||||||
|
|
||||||
public void setKey(List<String> key) { |
|
||||||
this.key = key; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,10 @@ |
|||||||
|
package com.novel.read.model.protocol |
||||||
|
|
||||||
|
import java.io.Serializable |
||||||
|
import java.util.ArrayList |
||||||
|
|
||||||
|
class HotSearchResp : Serializable { |
||||||
|
|
||||||
|
|
||||||
|
var key: List<String> = arrayListOf() |
||||||
|
} |
@ -1,120 +0,0 @@ |
|||||||
package com.novel.read.model.protocol; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
public class MarkResp { |
|
||||||
|
|
||||||
private List<SignBean> sign; |
|
||||||
|
|
||||||
public List<SignBean> getSign() { |
|
||||||
return sign; |
|
||||||
} |
|
||||||
|
|
||||||
public void setSign(List<SignBean> sign) { |
|
||||||
this.sign = sign; |
|
||||||
} |
|
||||||
|
|
||||||
public static class SignBean { |
|
||||||
/** |
|
||||||
* id : 8 |
|
||||||
* uid : 1 |
|
||||||
* book_id : 1 |
|
||||||
* article_id : 1 |
|
||||||
* words : 0 |
|
||||||
* create_time : 1561450031 |
|
||||||
* update_time : 1561450031 |
|
||||||
* delete_time : null |
|
||||||
*/ |
|
||||||
|
|
||||||
private int id; |
|
||||||
private int uid; |
|
||||||
private int book_id; |
|
||||||
private int article_id; |
|
||||||
private int words; |
|
||||||
private int create_time; |
|
||||||
private int update_time; |
|
||||||
private Object delete_time; |
|
||||||
private String content; |
|
||||||
private boolean edit; |
|
||||||
|
|
||||||
public int getId() { |
|
||||||
return id; |
|
||||||
} |
|
||||||
|
|
||||||
public void setId(int id) { |
|
||||||
this.id = id; |
|
||||||
} |
|
||||||
|
|
||||||
public int getUid() { |
|
||||||
return uid; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUid(int uid) { |
|
||||||
this.uid = uid; |
|
||||||
} |
|
||||||
|
|
||||||
public int getBook_id() { |
|
||||||
return book_id; |
|
||||||
} |
|
||||||
|
|
||||||
public void setBook_id(int book_id) { |
|
||||||
this.book_id = book_id; |
|
||||||
} |
|
||||||
|
|
||||||
public int getArticle_id() { |
|
||||||
return article_id; |
|
||||||
} |
|
||||||
|
|
||||||
public void setArticle_id(int article_id) { |
|
||||||
this.article_id = article_id; |
|
||||||
} |
|
||||||
|
|
||||||
public int getWords() { |
|
||||||
return words; |
|
||||||
} |
|
||||||
|
|
||||||
public void setWords(int words) { |
|
||||||
this.words = words; |
|
||||||
} |
|
||||||
|
|
||||||
public int getCreate_time() { |
|
||||||
return create_time; |
|
||||||
} |
|
||||||
|
|
||||||
public void setCreate_time(int create_time) { |
|
||||||
this.create_time = create_time; |
|
||||||
} |
|
||||||
|
|
||||||
public int getUpdate_time() { |
|
||||||
return update_time; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUpdate_time(int update_time) { |
|
||||||
this.update_time = update_time; |
|
||||||
} |
|
||||||
|
|
||||||
public Object getDelete_time() { |
|
||||||
return delete_time; |
|
||||||
} |
|
||||||
|
|
||||||
public void setDelete_time(Object delete_time) { |
|
||||||
this.delete_time = delete_time; |
|
||||||
} |
|
||||||
|
|
||||||
public String getContent() { |
|
||||||
return content == null ? "" : content; |
|
||||||
} |
|
||||||
|
|
||||||
public void setContent(String content) { |
|
||||||
this.content = content; |
|
||||||
} |
|
||||||
|
|
||||||
public boolean isEdit() { |
|
||||||
return edit; |
|
||||||
} |
|
||||||
|
|
||||||
public void setEdit(boolean edit) { |
|
||||||
this.edit = edit; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,31 @@ |
|||||||
|
package com.novel.read.model.protocol |
||||||
|
|
||||||
|
class MarkResp { |
||||||
|
|
||||||
|
var sign: List<SignBean>? = null |
||||||
|
|
||||||
|
class SignBean { |
||||||
|
/** |
||||||
|
* id : 8 |
||||||
|
* uid : 1 |
||||||
|
* book_id : 1 |
||||||
|
* article_id : 1 |
||||||
|
* words : 0 |
||||||
|
* create_time : 1561450031 |
||||||
|
* update_time : 1561450031 |
||||||
|
* delete_time : null |
||||||
|
*/ |
||||||
|
|
||||||
|
var id: Int = 0 |
||||||
|
var uid: Int = 0 |
||||||
|
var book_id: Int = 0 |
||||||
|
var article_id: Int = 0 |
||||||
|
var words: Int = 0 |
||||||
|
var create_time: Int = 0 |
||||||
|
var update_time: Int = 0 |
||||||
|
var delete_time: Any? = null |
||||||
|
var content: String? = null |
||||||
|
get() = if (field == null) "" else field |
||||||
|
var isEdit: Boolean = false |
||||||
|
} |
||||||
|
} |
@ -1,18 +0,0 @@ |
|||||||
package com.novel.read.model.protocol; |
|
||||||
|
|
||||||
public class UidResp { |
|
||||||
|
|
||||||
/** |
|
||||||
* uid : 3 |
|
||||||
*/ |
|
||||||
|
|
||||||
private int uid; |
|
||||||
|
|
||||||
public int getUid() { |
|
||||||
return uid; |
|
||||||
} |
|
||||||
|
|
||||||
public void setUid(int uid) { |
|
||||||
this.uid = uid; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,10 @@ |
|||||||
|
package com.novel.read.model.protocol |
||||||
|
|
||||||
|
class UidResp { |
||||||
|
|
||||||
|
/** |
||||||
|
* uid : 3 |
||||||
|
*/ |
||||||
|
|
||||||
|
var uid: Int = 0 |
||||||
|
} |
@ -1,99 +0,0 @@ |
|||||||
package com.novel.read.utlis; |
|
||||||
|
|
||||||
import android.os.Build; |
|
||||||
import android.view.View; |
|
||||||
import android.view.WindowManager; |
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity; |
|
||||||
|
|
||||||
import java.lang.reflect.Field; |
|
||||||
import java.lang.reflect.Method; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author: LiJun 390057892@qq.com |
|
||||||
* @date: 2018/3/7 15:07 |
|
||||||
*/ |
|
||||||
|
|
||||||
public class StatusBarUtil { |
|
||||||
public static void setBarsStyle(AppCompatActivity activity, int color, boolean dark) { |
|
||||||
MIUISetStatusBarLightMode(activity, dark); |
|
||||||
FlymeSetStatusBarLightMode(activity, dark); |
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上
|
|
||||||
View decorView = activity.getWindow().getDecorView(); |
|
||||||
if (dark) { |
|
||||||
int option = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
|
||||||
decorView.setSystemUiVisibility(option); |
|
||||||
activity.getWindow().setStatusBarColor(activity.getResources().getColor(color)); |
|
||||||
} else { |
|
||||||
int option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE; |
|
||||||
decorView.setSystemUiVisibility(option); |
|
||||||
activity.getWindow().setStatusBarColor(activity.getResources().getColor(color)); |
|
||||||
} |
|
||||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0
|
|
||||||
WindowManager.LayoutParams localLayoutParams = activity.getWindow().getAttributes(); |
|
||||||
localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags); |
|
||||||
} |
|
||||||
|
|
||||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//android6.0以后可以对状态栏文字颜色和图标进行修改
|
|
||||||
// if (dark){
|
|
||||||
// activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
|
||||||
// }else {
|
|
||||||
// activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
} |
|
||||||
|
|
||||||
public static boolean MIUISetStatusBarLightMode(AppCompatActivity activity, boolean dark) { |
|
||||||
boolean result = false; |
|
||||||
if (activity.getWindow() != null) { |
|
||||||
Class clazz = activity.getWindow().getClass(); |
|
||||||
try { |
|
||||||
int darkModeFlag = 0; |
|
||||||
Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); |
|
||||||
Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); |
|
||||||
darkModeFlag = field.getInt(layoutParams); |
|
||||||
Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); |
|
||||||
if (dark) { |
|
||||||
extraFlagField.invoke(activity.getWindow(), darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
|
|
||||||
} else { |
|
||||||
extraFlagField.invoke(activity.getWindow(), 0, darkModeFlag);//清除黑色字体
|
|
||||||
} |
|
||||||
result = true; |
|
||||||
} catch (Exception e) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
private static boolean FlymeSetStatusBarLightMode(AppCompatActivity activity, boolean dark) { |
|
||||||
boolean result = false; |
|
||||||
if (activity.getWindow() != null) { |
|
||||||
try { |
|
||||||
WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); |
|
||||||
Field darkFlag = WindowManager.LayoutParams.class |
|
||||||
.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); |
|
||||||
Field meizuFlags = WindowManager.LayoutParams.class |
|
||||||
.getDeclaredField("meizuFlags"); |
|
||||||
darkFlag.setAccessible(true); |
|
||||||
meizuFlags.setAccessible(true); |
|
||||||
int bit = darkFlag.getInt(null); |
|
||||||
int value = meizuFlags.getInt(lp); |
|
||||||
if (dark) { |
|
||||||
value |= bit; |
|
||||||
} else { |
|
||||||
value &= ~bit; |
|
||||||
} |
|
||||||
meizuFlags.setInt(lp, value); |
|
||||||
activity.getWindow().setAttributes(lp); |
|
||||||
result = true; |
|
||||||
} catch (Exception e) { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,106 @@ |
|||||||
|
package com.novel.read.utlis |
||||||
|
|
||||||
|
import android.os.Build |
||||||
|
import android.view.View |
||||||
|
import android.view.WindowManager |
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity |
||||||
|
|
||||||
|
import java.lang.reflect.Field |
||||||
|
import java.lang.reflect.Method |
||||||
|
|
||||||
|
/** |
||||||
|
* @author: LiJun 390057892@qq.com |
||||||
|
* @date: 2018/3/7 15:07 |
||||||
|
*/ |
||||||
|
|
||||||
|
object StatusBarUtil { |
||||||
|
fun setBarsStyle(activity: AppCompatActivity, color: Int, dark: Boolean) { |
||||||
|
MIUISetStatusBarLightMode(activity, dark) |
||||||
|
FlymeSetStatusBarLightMode(activity, dark) |
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上 |
||||||
|
val decorView = activity.window.decorView |
||||||
|
if (dark) { |
||||||
|
val option = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR |
||||||
|
decorView.systemUiVisibility = option |
||||||
|
activity.window.statusBarColor = activity.resources.getColor(color) |
||||||
|
} else { |
||||||
|
val option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
||||||
|
decorView.systemUiVisibility = option |
||||||
|
activity.window.statusBarColor = activity.resources.getColor(color) |
||||||
|
} |
||||||
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0 |
||||||
|
val localLayoutParams = activity.window.attributes |
||||||
|
localLayoutParams.flags = |
||||||
|
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or localLayoutParams.flags |
||||||
|
} |
||||||
|
|
||||||
|
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//android6.0以后可以对状态栏文字颜色和图标进行修改 |
||||||
|
// if (dark){ |
||||||
|
// activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
||||||
|
// }else { |
||||||
|
// activity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE); |
||||||
|
// } |
||||||
|
// |
||||||
|
// } |
||||||
|
} |
||||||
|
|
||||||
|
fun MIUISetStatusBarLightMode(activity: AppCompatActivity, dark: Boolean): Boolean { |
||||||
|
var result = false |
||||||
|
if (activity.window != null) { |
||||||
|
val clazz = activity.window.javaClass |
||||||
|
try { |
||||||
|
var darkModeFlag = 0 |
||||||
|
val layoutParams = Class.forName("android.view.MiuiWindowManager\$LayoutParams") |
||||||
|
val field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE") |
||||||
|
darkModeFlag = field.getInt(layoutParams) |
||||||
|
val extraFlagField = clazz.getMethod( |
||||||
|
"setExtraFlags", |
||||||
|
Int::class.javaPrimitiveType, |
||||||
|
Int::class.javaPrimitiveType |
||||||
|
) |
||||||
|
if (dark) { |
||||||
|
extraFlagField.invoke(activity.window, darkModeFlag, darkModeFlag)//状态栏透明且黑色字体 |
||||||
|
} else { |
||||||
|
extraFlagField.invoke(activity.window, 0, darkModeFlag)//清除黑色字体 |
||||||
|
} |
||||||
|
result = true |
||||||
|
} catch (e: Exception) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
return result |
||||||
|
} |
||||||
|
|
||||||
|
private fun FlymeSetStatusBarLightMode(activity: AppCompatActivity, dark: Boolean): Boolean { |
||||||
|
var result = false |
||||||
|
if (activity.window != null) { |
||||||
|
try { |
||||||
|
val lp = activity.window.attributes |
||||||
|
val darkFlag = WindowManager.LayoutParams::class.java |
||||||
|
.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON") |
||||||
|
val meizuFlags = WindowManager.LayoutParams::class.java |
||||||
|
.getDeclaredField("meizuFlags") |
||||||
|
darkFlag.isAccessible = true |
||||||
|
meizuFlags.isAccessible = true |
||||||
|
val bit = darkFlag.getInt(null) |
||||||
|
var value = meizuFlags.getInt(lp) |
||||||
|
if (dark) { |
||||||
|
value = value or bit |
||||||
|
} else { |
||||||
|
value = value and bit.inv() |
||||||
|
} |
||||||
|
meizuFlags.setInt(lp, value) |
||||||
|
activity.window.attributes = lp |
||||||
|
result = true |
||||||
|
} catch (e: Exception) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
return result |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,162 +0,0 @@ |
|||||||
package com.novel.read.utlis; |
|
||||||
|
|
||||||
import android.app.Activity; |
|
||||||
import android.os.Build; |
|
||||||
import android.view.View; |
|
||||||
import android.view.WindowManager; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by newbiechen on 17-5-16. |
|
||||||
* 基于 Android 4.4 |
|
||||||
* |
|
||||||
* 主要参数说明: |
|
||||||
* |
|
||||||
* SYSTEM_UI_FLAG_FULLSCREEN : 隐藏StatusBar |
|
||||||
* SYSTEM_UI_FLAG_HIDE_NAVIGATION : 隐藏NavigationBar |
|
||||||
* SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN: 视图扩展到StatusBar的位置,并且StatusBar不消失。 |
|
||||||
* 这里需要一些处理,一般是将StatusBar设置为全透明或者半透明。之后还需要使用fitSystemWindows=防止视图扩展到Status |
|
||||||
* Bar上面(会在StatusBar上加一层View,该View可被移动) |
|
||||||
* SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION: 视图扩展到NavigationBar的位置 |
|
||||||
* SYSTEM_UI_FLAG_LAYOUT_STABLE:稳定效果 |
|
||||||
* SYSTEM_UI_FLAG_IMMERSIVE_STICKY:保证点击任意位置不会退出 |
|
||||||
* |
|
||||||
* 可设置特效说明: |
|
||||||
* 1. 全屏特效 |
|
||||||
* 2. 全屏点击不退出特效 |
|
||||||
* 3. 注意在19 <=sdk <=21 时候,必须通过Window设置透明栏 |
|
||||||
*/ |
|
||||||
|
|
||||||
public class SystemBarUtils { |
|
||||||
|
|
||||||
private static final int UNSTABLE_STATUS = View.SYSTEM_UI_FLAG_FULLSCREEN; |
|
||||||
private static final int UNSTABLE_NAV = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
|
||||||
private static final int STABLE_STATUS = View.SYSTEM_UI_FLAG_FULLSCREEN | |
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | |
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | |
|
||||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
|
||||||
private static final int STABLE_NAV = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | |
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | |
|
||||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
|
||||||
private static final int EXPAND_STATUS = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE; |
|
||||||
private static final int EXPAND_NAV = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE; |
|
||||||
|
|
||||||
|
|
||||||
//设置隐藏StatusBar(点击任意地方会恢复)
|
|
||||||
public static void hideUnStableStatusBar(Activity activity){ |
|
||||||
//App全屏,隐藏StatusBar
|
|
||||||
setFlag(activity,UNSTABLE_STATUS); |
|
||||||
} |
|
||||||
|
|
||||||
public static void showUnStableStatusBar(Activity activity){ |
|
||||||
clearFlag(activity,UNSTABLE_STATUS); |
|
||||||
} |
|
||||||
|
|
||||||
//隐藏NavigationBar(点击任意地方会恢复)
|
|
||||||
public static void hideUnStableNavBar(Activity activity){ |
|
||||||
setFlag(activity,UNSTABLE_NAV); |
|
||||||
} |
|
||||||
|
|
||||||
public static void showUnStableNavBar(Activity activity){ |
|
||||||
clearFlag(activity,UNSTABLE_NAV); |
|
||||||
} |
|
||||||
|
|
||||||
public static void hideStableStatusBar(Activity activity){ |
|
||||||
//App全屏,隐藏StatusBar
|
|
||||||
setFlag(activity,STABLE_STATUS); |
|
||||||
} |
|
||||||
|
|
||||||
public static void showStableStatusBar(Activity activity){ |
|
||||||
clearFlag(activity,STABLE_STATUS); |
|
||||||
} |
|
||||||
|
|
||||||
public static void hideStableNavBar(Activity activity){ |
|
||||||
//App全屏,隐藏StatusBar
|
|
||||||
setFlag(activity,STABLE_NAV); |
|
||||||
} |
|
||||||
|
|
||||||
public static void showStableNavBar(Activity activity){ |
|
||||||
clearFlag(activity,STABLE_NAV); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 视图扩充到StatusBar |
|
||||||
*/ |
|
||||||
public static void expandStatusBar(Activity activity){ |
|
||||||
setFlag(activity, EXPAND_STATUS); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 视图扩充到NavBar |
|
||||||
* @param activity |
|
||||||
*/ |
|
||||||
public static void expandNavBar(Activity activity){ |
|
||||||
setFlag(activity, EXPAND_NAV); |
|
||||||
} |
|
||||||
|
|
||||||
public static void transparentStatusBar(Activity activity){ |
|
||||||
if (Build.VERSION.SDK_INT >= 21){ |
|
||||||
expandStatusBar(activity); |
|
||||||
activity.getWindow() |
|
||||||
.setStatusBarColor(activity.getResources().getColor(android.R.color.transparent)); |
|
||||||
} |
|
||||||
else if (Build.VERSION.SDK_INT >= 19){ |
|
||||||
WindowManager.LayoutParams attrs = activity.getWindow().getAttributes(); |
|
||||||
attrs.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | attrs.flags); |
|
||||||
activity.getWindow().setAttributes(attrs); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static void transparentNavBar(Activity activity){ |
|
||||||
if (Build.VERSION.SDK_INT >= 21){ |
|
||||||
expandNavBar(activity); |
|
||||||
//下面这个方法在sdk:21以上才有
|
|
||||||
activity.getWindow() |
|
||||||
.setNavigationBarColor(activity.getResources().getColor(android.R.color.transparent)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static void setFlag(Activity activity, int flag){ |
|
||||||
if (Build.VERSION.SDK_INT >= 19){ |
|
||||||
View decorView = activity.getWindow().getDecorView(); |
|
||||||
int option = decorView.getSystemUiVisibility() | flag; |
|
||||||
decorView.setSystemUiVisibility(option); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//取消flag
|
|
||||||
public static void clearFlag(Activity activity, int flag){ |
|
||||||
if (Build.VERSION.SDK_INT >= 19){ |
|
||||||
View decorView = activity.getWindow().getDecorView(); |
|
||||||
int option = decorView.getSystemUiVisibility() & (~flag); |
|
||||||
decorView.setSystemUiVisibility(option); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static void setToggleFlag(Activity activity, int option){ |
|
||||||
if (Build.VERSION.SDK_INT >= 19){ |
|
||||||
if (isFlagUsed(activity,option)){ |
|
||||||
clearFlag(activity,option); |
|
||||||
} |
|
||||||
else { |
|
||||||
setFlag(activity,option); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @param activity |
|
||||||
* @return flag是否已被使用 |
|
||||||
*/ |
|
||||||
public static boolean isFlagUsed(Activity activity, int flag) { |
|
||||||
int currentFlag = activity.getWindow().getDecorView().getSystemUiVisibility(); |
|
||||||
if((currentFlag & flag) |
|
||||||
== flag) { |
|
||||||
return true; |
|
||||||
}else { |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,155 @@ |
|||||||
|
package com.novel.read.utlis |
||||||
|
|
||||||
|
import android.app.Activity |
||||||
|
import android.os.Build |
||||||
|
import android.view.View |
||||||
|
import android.view.WindowManager |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by newbiechen on 17-5-16. |
||||||
|
* 基于 Android 4.4 |
||||||
|
* |
||||||
|
* 主要参数说明: |
||||||
|
* |
||||||
|
* SYSTEM_UI_FLAG_FULLSCREEN : 隐藏StatusBar |
||||||
|
* SYSTEM_UI_FLAG_HIDE_NAVIGATION : 隐藏NavigationBar |
||||||
|
* SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN: 视图扩展到StatusBar的位置,并且StatusBar不消失。 |
||||||
|
* 这里需要一些处理,一般是将StatusBar设置为全透明或者半透明。之后还需要使用fitSystemWindows=防止视图扩展到Status |
||||||
|
* Bar上面(会在StatusBar上加一层View,该View可被移动) |
||||||
|
* SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION: 视图扩展到NavigationBar的位置 |
||||||
|
* SYSTEM_UI_FLAG_LAYOUT_STABLE:稳定效果 |
||||||
|
* SYSTEM_UI_FLAG_IMMERSIVE_STICKY:保证点击任意位置不会退出 |
||||||
|
* |
||||||
|
* 可设置特效说明: |
||||||
|
* 1. 全屏特效 |
||||||
|
* 2. 全屏点击不退出特效 |
||||||
|
* 3. 注意在19 <=sdk <=21 时候,必须通过Window设置透明栏 |
||||||
|
*/ |
||||||
|
|
||||||
|
object SystemBarUtils { |
||||||
|
|
||||||
|
private val UNSTABLE_STATUS = View.SYSTEM_UI_FLAG_FULLSCREEN |
||||||
|
private val UNSTABLE_NAV = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
||||||
|
private val STABLE_STATUS = View.SYSTEM_UI_FLAG_FULLSCREEN or |
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or |
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or |
||||||
|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
||||||
|
private val STABLE_NAV = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or |
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or |
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or |
||||||
|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
||||||
|
private val EXPAND_STATUS = |
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
||||||
|
private val EXPAND_NAV = |
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
||||||
|
|
||||||
|
|
||||||
|
//设置隐藏StatusBar(点击任意地方会恢复) |
||||||
|
fun hideUnStableStatusBar(activity: Activity) { |
||||||
|
//App全屏,隐藏StatusBar |
||||||
|
setFlag(activity, UNSTABLE_STATUS) |
||||||
|
} |
||||||
|
|
||||||
|
fun showUnStableStatusBar(activity: Activity) { |
||||||
|
clearFlag(activity, UNSTABLE_STATUS) |
||||||
|
} |
||||||
|
|
||||||
|
//隐藏NavigationBar(点击任意地方会恢复) |
||||||
|
fun hideUnStableNavBar(activity: Activity) { |
||||||
|
setFlag(activity, UNSTABLE_NAV) |
||||||
|
} |
||||||
|
|
||||||
|
fun showUnStableNavBar(activity: Activity) { |
||||||
|
clearFlag(activity, UNSTABLE_NAV) |
||||||
|
} |
||||||
|
|
||||||
|
fun hideStableStatusBar(activity: Activity) { |
||||||
|
//App全屏,隐藏StatusBar |
||||||
|
setFlag(activity, STABLE_STATUS) |
||||||
|
} |
||||||
|
|
||||||
|
fun showStableStatusBar(activity: Activity) { |
||||||
|
clearFlag(activity, STABLE_STATUS) |
||||||
|
} |
||||||
|
|
||||||
|
fun hideStableNavBar(activity: Activity) { |
||||||
|
//App全屏,隐藏StatusBar |
||||||
|
setFlag(activity, STABLE_NAV) |
||||||
|
} |
||||||
|
|
||||||
|
fun showStableNavBar(activity: Activity) { |
||||||
|
clearFlag(activity, STABLE_NAV) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 视图扩充到StatusBar |
||||||
|
*/ |
||||||
|
fun expandStatusBar(activity: Activity) { |
||||||
|
setFlag(activity, EXPAND_STATUS) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 视图扩充到NavBar |
||||||
|
* @param activity |
||||||
|
*/ |
||||||
|
fun expandNavBar(activity: Activity) { |
||||||
|
setFlag(activity, EXPAND_NAV) |
||||||
|
} |
||||||
|
|
||||||
|
fun transparentStatusBar(activity: Activity) { |
||||||
|
if (Build.VERSION.SDK_INT >= 21) { |
||||||
|
expandStatusBar(activity) |
||||||
|
activity.window.statusBarColor = |
||||||
|
activity.resources.getColor(android.R.color.transparent) |
||||||
|
} else if (Build.VERSION.SDK_INT >= 19) { |
||||||
|
val attrs = activity.window.attributes |
||||||
|
attrs.flags = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or attrs.flags |
||||||
|
activity.window.attributes = attrs |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fun transparentNavBar(activity: Activity) { |
||||||
|
if (Build.VERSION.SDK_INT >= 21) { |
||||||
|
expandNavBar(activity) |
||||||
|
//下面这个方法在sdk:21以上才有 |
||||||
|
activity.window.navigationBarColor = |
||||||
|
activity.resources.getColor(android.R.color.transparent) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fun setFlag(activity: Activity, flag: Int) { |
||||||
|
if (Build.VERSION.SDK_INT >= 19) { |
||||||
|
val decorView = activity.window.decorView |
||||||
|
val option = decorView.systemUiVisibility or flag |
||||||
|
decorView.systemUiVisibility = option |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//取消flag |
||||||
|
fun clearFlag(activity: Activity, flag: Int) { |
||||||
|
if (Build.VERSION.SDK_INT >= 19) { |
||||||
|
val decorView = activity.window.decorView |
||||||
|
val option = decorView.systemUiVisibility and flag.inv() |
||||||
|
decorView.systemUiVisibility = option |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fun setToggleFlag(activity: Activity, option: Int) { |
||||||
|
if (Build.VERSION.SDK_INT >= 19) { |
||||||
|
if (isFlagUsed(activity, option)) { |
||||||
|
clearFlag(activity, option) |
||||||
|
} else { |
||||||
|
setFlag(activity, option) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param activity |
||||||
|
* @return flag是否已被使用 |
||||||
|
*/ |
||||||
|
fun isFlagUsed(activity: Activity, flag: Int): Boolean { |
||||||
|
val currentFlag = activity.window.decorView.systemUiVisibility |
||||||
|
return currentFlag and flag == flag |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"> |
||||||
|
<corners android:radius="20dp"/> |
||||||
|
<stroke android:color="@color/colorDesTitle" android:width="1dp"/> |
||||||
|
</shape> |
@ -1,5 +1,6 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||||
<item android:state_selected="true" android:drawable="@drawable/listen_select"/> |
<item android:state_selected="true" android:drawable="@drawable/listen_select"/> |
||||||
|
<item android:state_checked="true" android:drawable="@drawable/listen_select"/> |
||||||
<item android:state_selected="false" android:drawable="@color/read_menu_color"/> |
<item android:state_selected="false" android:drawable="@color/read_menu_color"/> |
||||||
</selector> |
</selector> |
@ -1,6 +1,8 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||||
|
|
||||||
<item android:state_selected="true" android:color="@color/white"/> |
<item android:state_selected="true" android:color="@color/white"/> |
||||||
|
<item android:state_checked="true" android:color="@color/white"/> |
||||||
<item android:state_selected="false" android:color="@color/smallColor"/> |
<item android:state_selected="false" android:color="@color/smallColor"/> |
||||||
|
|
||||||
</selector> |
</selector> |
@ -0,0 +1,8 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||||
|
|
||||||
|
<item android:state_selected="true" android:color="@color/light_yellow"/> |
||||||
|
<item android:state_checked="true" android:color="@color/light_yellow"/> |
||||||
|
<item android:state_selected="false" android:color="@color/smallColor"/> |
||||||
|
|
||||||
|
</selector> |
@ -1,20 +1,23 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
android:orientation="vertical" |
android:orientation="vertical" |
||||||
android:layout_width="wrap_content" |
android:layout_width="match_parent" |
||||||
android:layout_height="wrap_content"> |
android:layout_height="match_parent" |
||||||
|
android:layout_gravity="center"> |
||||||
|
|
||||||
<View |
<View |
||||||
android:id="@+id/read_bg_view" |
android:id="@+id/read_bg_view" |
||||||
android:layout_width="30dp" |
android:layout_width="30dp" |
||||||
android:layout_height="40dp" |
android:layout_height="40dp" |
||||||
android:background="@color/nb.read.bg_1"/> |
android:layout_gravity="center" |
||||||
|
android:background="@color/read_bg_one"/> |
||||||
|
|
||||||
<ImageView |
<ImageView |
||||||
android:id="@+id/read_bg_iv_checked" |
android:id="@+id/read_bg_iv_checked" |
||||||
android:layout_width="30dp" |
android:layout_width="30dp" |
||||||
android:layout_height="40dp" |
android:layout_height="40dp" |
||||||
android:src="@drawable/ic_checked" |
android:src="@drawable/ic_checked" |
||||||
|
android:layout_gravity="center" |
||||||
android:scaleType="center" |
android:scaleType="center" |
||||||
android:visibility="gone"/> |
android:visibility="gone"/> |
||||||
</FrameLayout> |
</FrameLayout> |
@ -1,78 +0,0 @@ |
|||||||
package com.common_lib.base.utils; |
|
||||||
|
|
||||||
import android.content.Context; |
|
||||||
import android.os.Build; |
|
||||||
import android.provider.Settings; |
|
||||||
import android.telephony.TelephonyManager; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
import java.io.InputStreamReader; |
|
||||||
import java.io.LineNumberReader; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by alex on 2017/2/8. |
|
||||||
*/ |
|
||||||
|
|
||||||
public class DeviceInfoUtil { |
|
||||||
public static String getDeviceInfo(Context context){ |
|
||||||
String A_ID = Settings.System.getString(context.getContentResolver(), Settings.System.ANDROID_ID); |
|
||||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); |
|
||||||
StringBuilder sb = new StringBuilder(); |
|
||||||
sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId()); |
|
||||||
sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion()); |
|
||||||
sb.append("\nLine1Number = " + tm.getLine1Number()); |
|
||||||
sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso()); |
|
||||||
sb.append("\nNetworkOperator = " + tm.getNetworkOperator()); |
|
||||||
sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName()); |
|
||||||
sb.append("\nNetworkType = " + tm.getNetworkType()); |
|
||||||
sb.append("\nPhoneType = " + tm.getPhoneType()); |
|
||||||
sb.append("\nSimCountryIso = " + tm.getSimCountryIso()); |
|
||||||
sb.append("\nSimOperator = " + tm.getSimOperator()); |
|
||||||
sb.append("\nSimOperatorName = " + tm.getSimOperatorName()); |
|
||||||
sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber()); |
|
||||||
sb.append("\nSimState = " + tm.getSimState()); |
|
||||||
sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId()); |
|
||||||
sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber()); |
|
||||||
sb.append("\nSoftwareVersion=" + tm.getDeviceSoftwareVersion()); |
|
||||||
sb.append("\nCPU="+getCPUSerial()); |
|
||||||
sb.append("\nBoard="+ Build.BOARD); |
|
||||||
sb.append("\nCPU1="+ Build.CPU_ABI); |
|
||||||
sb.append("\nDEVICE="+ Build.DEVICE); |
|
||||||
sb.append("\nHARDWARE="+ Build.HARDWARE); |
|
||||||
sb.append("\nANDROID_ID = " + A_ID); |
|
||||||
return sb.toString(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 获取CPU序列号 |
|
||||||
* |
|
||||||
* @return CPU序列号(16位) |
|
||||||
* 读取失败为"0000000000000000" |
|
||||||
*/ |
|
||||||
private static String getCPUSerial() { |
|
||||||
String str = "", strCPU = "", cpuAddress = "0000000000000000"; |
|
||||||
try { |
|
||||||
//读取CPU信息
|
|
||||||
Process pp = Runtime.getRuntime().exec("cat /proc/cpuinfo"); |
|
||||||
InputStreamReader ir = new InputStreamReader(pp.getInputStream()); |
|
||||||
LineNumberReader input = new LineNumberReader(ir); |
|
||||||
//查找CPU序列号
|
|
||||||
str = input.readLine(); |
|
||||||
if (str != null) { |
|
||||||
//查找到序列号所在行
|
|
||||||
if (str.indexOf("Serial") > -1) { |
|
||||||
//提取序列号
|
|
||||||
strCPU = str.substring(str.indexOf(":") + 1, |
|
||||||
str.length()); |
|
||||||
//去空格
|
|
||||||
cpuAddress = strCPU.trim(); |
|
||||||
} |
|
||||||
} else { |
|
||||||
} |
|
||||||
} catch (IOException ex) { |
|
||||||
//赋予默认值
|
|
||||||
ex.printStackTrace(); |
|
||||||
} |
|
||||||
return cpuAddress; |
|
||||||
} |
|
||||||
} |
|
@ -1,55 +0,0 @@ |
|||||||
package com.common_lib.base.utils; |
|
||||||
|
|
||||||
import android.annotation.TargetApi; |
|
||||||
import android.content.Context; |
|
||||||
import android.net.ConnectivityManager; |
|
||||||
import android.net.NetworkInfo; |
|
||||||
import android.os.Build; |
|
||||||
import android.provider.Settings; |
|
||||||
|
|
||||||
import com.common_lib.base.BaseConstants; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Created by alex on 2016/3/2. |
|
||||||
*/ |
|
||||||
public class NetworkUtils { |
|
||||||
public static final int TYPE_UNKNOWN = -1; |
|
||||||
|
|
||||||
private static NetworkInfo getActiveNetworkInfo(Context context) { |
|
||||||
if (context == null) { |
|
||||||
return null; |
|
||||||
} else { |
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
|
||||||
return cm == null ? null : cm.getActiveNetworkInfo(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private static int getActiveNetworkType(Context context) { |
|
||||||
NetworkInfo info = getActiveNetworkInfo(context); |
|
||||||
return info != null && info.isConnected() ? info.getType() : -1; |
|
||||||
} |
|
||||||
|
|
||||||
public static boolean isNetworkAvailable(Context context) { |
|
||||||
NetworkInfo info = getActiveNetworkInfo(context); |
|
||||||
return info != null && info.isConnected(); |
|
||||||
} |
|
||||||
|
|
||||||
public static boolean isWiFiConnected(Context context) { |
|
||||||
return getActiveNetworkType(context) == 1; |
|
||||||
} |
|
||||||
|
|
||||||
@TargetApi(17) |
|
||||||
public static boolean isAirplaneModeOn(Context context) { |
|
||||||
return Build.VERSION.SDK_INT < 17 ? Settings.System.getInt(context.getContentResolver(), "airplane_mode_on", 0) != 0 : Settings.Global.getInt(context.getContentResolver(), "airplane_mode_on", 0) != 0; |
|
||||||
} |
|
||||||
|
|
||||||
public static boolean checkConnection(Context context) { |
|
||||||
if (isNetworkAvailable(context)) { |
|
||||||
return true; |
|
||||||
} else { |
|
||||||
ToastUtils.showNormalToast(context, BaseConstants.No_Internet); |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,94 +0,0 @@ |
|||||||
package com.common_lib.base.utils; |
|
||||||
|
|
||||||
import com.common_lib.base.BaseConstants; |
|
||||||
import com.common_lib.base.GsonManager; |
|
||||||
import com.google.gson.Gson; |
|
||||||
import com.google.gson.reflect.TypeToken; |
|
||||||
|
|
||||||
import java.lang.reflect.Type; |
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
/** |
|
||||||
* 用于处理一些奇奇怪怪的String类型转换的工具类 |
|
||||||
* Created by alex on 16/7/20. |
|
||||||
*/ |
|
||||||
public class StringUtils { |
|
||||||
//这个方法是用来处理服务端返回的url列表的
|
|
||||||
public static List<String> formatStringUrl(String imageContent) { |
|
||||||
List<String> res = null; |
|
||||||
if (imageContent == null || imageContent.isEmpty()) { |
|
||||||
return res; |
|
||||||
} |
|
||||||
Gson gson = GsonManager.Companion.getInstance().getGson(); |
|
||||||
Type listType = new TypeToken<ArrayList<String>>() { |
|
||||||
}.getType(); |
|
||||||
res = gson.fromJson(imageContent, listType); |
|
||||||
return res; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
//这个方法是获取url列表的方法,这个方法就是
|
|
||||||
public static List<String> formatStringUrl(String imageContent, boolean addHead, int maxLength) { |
|
||||||
List<String> res; |
|
||||||
if (imageContent == null || imageContent.isEmpty()) { |
|
||||||
res = new ArrayList<>(); |
|
||||||
res.add(null); |
|
||||||
return res; |
|
||||||
} |
|
||||||
Gson gson = GsonManager.Companion.getInstance().getGson(); |
|
||||||
Type listType = new TypeToken<ArrayList<String>>() { |
|
||||||
}.getType(); |
|
||||||
res = gson.fromJson(imageContent, listType); |
|
||||||
if (res.size() > 0 && res.size() < maxLength) { |
|
||||||
if (addHead && res.get(res.size()-1) != null) { |
|
||||||
res.add(res.size(), null); |
|
||||||
} |
|
||||||
} else if(res.size()==maxLength){ |
|
||||||
return res; |
|
||||||
}else{ |
|
||||||
res = new ArrayList<>(); |
|
||||||
res.add(null); |
|
||||||
} |
|
||||||
return res; |
|
||||||
} |
|
||||||
|
|
||||||
//这是将一个字符串的长度增大
|
|
||||||
public static String increaseGroupMessage(String msg) { |
|
||||||
StringBuilder builder = new StringBuilder(); |
|
||||||
builder.append(msg); |
|
||||||
while (builder.length() < 100) { |
|
||||||
builder.append(BaseConstants.EMPTY_STRING); |
|
||||||
} |
|
||||||
return builder.toString(); |
|
||||||
} |
|
||||||
|
|
||||||
public static String formatList(List<String> info) { |
|
||||||
String res = null; |
|
||||||
List<String> infoList = new ArrayList<>(); |
|
||||||
for (int i = 0; i < info.size(); i++) { |
|
||||||
if (info.get(i) != null) { |
|
||||||
infoList.add(info.get(i)); |
|
||||||
} |
|
||||||
} |
|
||||||
if (infoList.size() > -1) { |
|
||||||
Gson gson = GsonManager.Companion.getInstance().getGson(); |
|
||||||
res = gson.toJson(infoList); |
|
||||||
} |
|
||||||
return res; |
|
||||||
} |
|
||||||
|
|
||||||
//从图片的路径当中获取图片的名称
|
|
||||||
public static String getFileNameFromPath(String path) { |
|
||||||
String res; |
|
||||||
String[] s = path.split("/"); |
|
||||||
res = s[s.length - 1]; |
|
||||||
return res; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,48 +0,0 @@ |
|||||||
package com.common_lib.base.utils; |
|
||||||
|
|
||||||
import android.content.Context; |
|
||||||
import android.widget.Toast; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Created by alex on 2016/3/2. |
|
||||||
*/ |
|
||||||
public class ToastUtils { |
|
||||||
public enum Duration {SHORT, LONG} |
|
||||||
|
|
||||||
private ToastUtils() { |
|
||||||
throw new AssertionError(); |
|
||||||
} |
|
||||||
|
|
||||||
public static void showNormalToast(Context context, int stringResId) { |
|
||||||
showToast(context, stringResId, Duration.SHORT); |
|
||||||
} |
|
||||||
|
|
||||||
public static void showNormalToast(Context context, String text) { |
|
||||||
showToast(context, text, Duration.SHORT); |
|
||||||
} |
|
||||||
|
|
||||||
public static void showLongDurationToast(Context context, int stringResId) { |
|
||||||
showToast(context, stringResId, Duration.LONG); |
|
||||||
} |
|
||||||
|
|
||||||
public static void showLongDurationToast(Context context, String text) { |
|
||||||
showToast(context, text, Duration.LONG); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private static void showToast(Context context, int text, Duration duration) { |
|
||||||
Toast toast = Toast.makeText(context, text, |
|
||||||
(duration == Duration.SHORT ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG)); |
|
||||||
// toast.setGravity(Gravity.CENTER, 0, 0);
|
|
||||||
toast.show(); |
|
||||||
} |
|
||||||
|
|
||||||
private static void showToast(Context context, String text, Duration duration) { |
|
||||||
Toast toast = Toast.makeText(context, text, |
|
||||||
(duration == Duration.SHORT ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG)); |
|
||||||
// toast.setGravity(Gravity.BOTTOM, 0, 0);
|
|
||||||
toast.show(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
Loading…
Reference in new issue