积跬步

Just do IT Now.


  • Home

  • Tags

  • Categories

  • Archives

  • Search

Jetpack-Navigation

Posted on 2019-12-24 | In Android

Navigation

“导航” 页面切换(处理导航图所需的一切,包括页面的跳转、参数的传递、动画效果的设置,以及Appbar的设置等)

NavHost是个容器,也是个控制器

Read more »

Jetpack-WorkManager

Posted on 2019-12-24 | In Android

WorkManager

Android为后台执行任务提供了多种解决方案:JobScheduler、Loader、Service等。但它们可能会消耗大量的电量。Android在耗电问题上又做了各种尝试,从Doze到App Standby。

WorkManager为应用程序中那些不需要及时完成的任务(如后台执行任务)提供统一的解决方案,以便在设备电量和用户体验之间达到一个较好的平衡。

Read more »

Jetpack-生命周期感知型组件

Posted on 2019-12-24 | In Android

生命周期感知型组件

解耦很大程度上表现为系统组件的生命周期与普通组件之间的解耦。普通组件在使用过程中通常需要依赖于系统组件的生命周期。因为普通组件无法主动获知系统组件的生命周期事件。

生命周期感知型组件可执行响应另一个组件(如Activity和Fragment)的生命周期状态的变化。

Read more »

Jetpack

Posted on 2019-12-24 | In Android

初识Jetpack

摘要:初识Jetpack

  • Jetpack架构
  • 如何使用
  • jetpack的介绍
Read more »

安卓-存储相关

Posted on 2019-12-23 | In Android

数据存储

存储方式 说明
SharedPreferences 在键值对中存储私有原始数据
内部存储 在设备内存中存储私有数据
外部存储 在共享的外部存储中存储公共数据
SQLite 数据库 在私有数据库中存储结构化数据

SharedPreferences

Read more »

工具-Intent相关

Posted on 2019-12-23 | In Android代码片段

跳转到指定应用的首页

1
2
3
4
5
6
7
/**
* 跳转到指定应用的首页
*/
private void showActivity(@NonNull String packageName){
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
startActivity(intent);
}

跳转到指定应用的指定页面

Read more »

工具-下载并安装Apk

Posted on 2019-12-19 | In Android代码片段

下载并安装apk

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
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
52
53
54
55
56
57
58
59
/**
* 1.从服务器下载apk
*
* @param path
* @param pd
*/
public static File getFileFromServer(String path, @NonNull ProgressDialog pd) throws Exception{
// 如果相等的话表示当前的sdcard挂载在手机上并且是可用的
HttpURLConnection conn;

if(path.indexOf("https") != -1){//独立打包的地址为https,因此需要用Https方式下载
int lastIndex = path.lastIndexOf("/");
if(lastIndex == -1){
File file = new File(pd.getContext().getExternalCacheDir(), "updata.apk");
return file;
}

String preScheme = path.substring(0, lastIndex);
String name = path.substring(lastIndex, path.length());
URL url = new URL(preScheme + URLEncoder.encode(name,"UTF-8"));//独立打包的包名时utf-8的

TrustHttpsHostHelper.trustAllHosts();
conn = (HttpsURLConnection)url.openConnection();
TrustHttpsHostHelper.setHostVerifier((HttpsURLConnection) conn);
conn.connect();
}else{
URL url = new URL(path);
conn = (HttpURLConnection) url.openConnection();
}

conn.setConnectTimeout(5000);

// 获取到文件的大小
int fileSize = conn.getContentLength();
int newFileSize = FormetFileSize(fileSize);
pd.setMax(newFileSize);

InputStream is = conn.getInputStream();

File file = new File(pd.getContext().getExternalCacheDir(), "updata.apk");

FileOutputStream fos = new FileOutputStream(file);
BufferedInputStream bis = new BufferedInputStream(is);
byte[] buffer = new byte[1024];
int len;
int total = 0;
while ((len = bis.read(buffer)) != -1){
fos.write(buffer, 0, len);
total += len;
// 获取当前已下载量
int newTotal = FormetFileSize(total);
pd.setProgress(newTotal);
pd.setProgressNumberFormat(newTotal + " kb/" + newFileSize + " kb");
}
fos.close();
bis.close();
is.close();
return file;
}

注意:这一段中URL url = new URL(preScheme + URLEncoder.encode(name,"UTF-8"));//独立打包的包名时utf-8的(其中 name 是带一个斜杆的,比如”/byldy_1.1.2.apk”)会把最后一个”/“转成”%2F”,而这会有个问题:七牛的链接比如https://qiniudownload.byjxj.com%2Fbyldy_1.1.2.apk放到浏览器上也无法下载;而https://qiniudownload.byjxj.com/20191219%2Fbyldy_1.1.3.apk就可以下载;目前还无法确定是不是七牛的问题。

Read more »

工具-多个控件添加监听

Posted on 2019-12-19 | In Android代码片段

多个控件添加监听

1
2
3
4
5
6
7
8
9
10
11
12
//多个控件添加监听
private void addOnClickListeners(@IdRes int... ids) {
if (ids != null) {
View view;
for (int id : ids) {
view = findViewById(id);
if (view != null) {
view.setOnClickListener(this);
}
}
}
}
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
//调用: 
addOnClickListeners(R.id.btn_open_log
, R.id.btn_disable_log
, R.id.btn_pre_load_before_page
, R.id.btn_pre_load_inside_page
, R.id.btn_pre_load_before_button_click
, R.id.btn_pre_load_group_before_page
);

private SparseArray viewSparseArray = new SparseArray<>();
private void addOnClickListeners(@IdRes int... ids) {
if (viewSparseArray == null) {
viewSparseArray = new SparseArray<>();
}
if (ids != null) {
for (int id : ids) {
if (viewSparseArray.get(id) == null) {
viewSparseArray.put(id, findViewById(id));
}
if (viewSparseArray.get(id) != null) {
viewSparseArray.get(id).setOnClickListener(this);
}
}
}
}
Read more »

工具-尺寸、大小

Posted on 2019-12-19 | In Android代码片段
将设计在苹果的宽高转换成Android的宽高1234567891011121314151617181920212223242526272829303132333435public class IOSDisplayTransfer { /** * 将设计在苹果的高度转换成and ...
Read more »

字符串相关

Posted on 2019-12-19 | In Java代码片段

java_判断是否中文字符

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class IsChineseOrEnglish{
//GENERAL_PUNCTUATION 判断中文的“号
//CJK_SYMBOLS_and_punctuation 判断中文的。号
//HALFWIDTH_AND_FULLWIDTH_FORMS 判断中中文的,号

public static boolean isChinese(Char c){
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if(ub == Character.UnicodeBlock.CJK_SYMBOLS_and_punctuation
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_and_punctuation
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS){
return true;
}
return false;
}

public static void isChiese(String strName){
char[] ch = strName.toCharArray();
for(int i = 0; i < ch.length; i++){
char c = ch[i];
if(isChinese(c) == true){
System.out.println(isChiese(c));
return;
} else {
System.out.println(isChiese(c));
return;
}
}
}

public static void main(String[] args){
Random r = new Random();
for(int i = 0; i < 20; i++){
System.out.println(r.nextInt(10) + 1);
isChinese("き");
isChinese("中国");
}
}
}
Read more »

方法反射实例

Posted on 2019-12-19 | In Java代码片段

方法反射实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class ReflectCase {

public static void main(String[] args) throws Exception {
Proxy target = new Proxy();
Method method = Proxy.class.getDeclaredMethod("run");
method.invoke(target);
}

static class Proxy {
public void run() {
System.out.println("run");
}
}
}
Read more »

获取本地IP

Posted on 2019-12-19 | In Java代码片段

获取本地IP

1
2
3
4
5
6
7
8
9
10
InetAddress ia = null;
try{
ia = ia.getLocalHost();
String localName = ia.getHostName();
String localIP = ia.getHostAddress();
Systemt.out.println("本机名称是:" + localName);
Systemt.out.println("本机的IP是:" + localIP);
} catch(Exception e){
e.printStackTrace();
}
Read more »
<1…222324>

285 posts
21 categories
44 tags
E-Mail CSDN
0%
© 2018 — 2025 阿炳
Powered by Hexo
|
Theme — NexT.Gemini v5.1.4