Skip to content

Commit

Permalink
完善代码
Browse files Browse the repository at this point in the history
  • Loading branch information
duweiwang committed Jun 20, 2022
1 parent c03bc66 commit 8e1a26e
Show file tree
Hide file tree
Showing 15 changed files with 459 additions and 51 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ hexo s
```script
hexo d
```



##### 建站记录


数学公式的支持:
需要手动安装pandoc程序
https://github.com/theme-next/hexo-theme-next/blob/master/docs/zh-CN/MATH.md
63 changes: 63 additions & 0 deletions source/_drafts/android-aosp-binder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: Android Binder
tags: Android
-------------

一、Binder是什么

<center>
<img src="../images/android-binder-what.svg" width="50%"/>
</center>

+ An IPC/component system for developing object-oriented OS services
- Not yet another object-oriented kernel
- Instead an object-oriented operating system environment that works on traditional kernels, like Linux!

+ Essential to Android!
+ Comes from OpenBinder
- Started at Be, Inc. as a key part of the "next generation BeOS" (~ 2001)
- Acquired by PalmSource
- First implementation used in Palm Cobalt (micro-kernel based OS)
- Palm switched to Linux, so Binder ported to Linux, open-sourced (~ 2005)
- Google hired Dianne Hackborn, a key OpenBinder engineer, to join the Android team
- Used as-is for the initial bring-up of Android, but then completely rewritten (~ 2008)
- OpenBinder no longer maintained - long live Binder!

+ Focused on scalability, stability, flexibility, low-latency/overhead, easy programming model

二、IPC

+ Inter-process communication (IPC) is a framework for the exchange of signals and data across multiple processes
+ Used for message passing, synchronization, shared memory, and remote procedure calls (RPC)
+ Enables information sharing, computational speedup, modularity, convenience, privilege separation, data isolation, stability
- Each process has its own (sandboxed) address space, typically running under a unique system ID
+ Many IPC options
- Files (including memory mapped)
- Signals
- Sockets (UNIX domain, TCP/IP)
- Pipes (including named pipes)
- Semaphores
- Shared memory
- Message passing (including queues, message bus)
- Intents, ContentProviders, Messenger
- Binder!


三、为什么使用Binder














<center>
<img src="../images/android-basic-aidl-overview.png" width="50%"/>
</center>
18 changes: 0 additions & 18 deletions source/_drafts/android-aosp-event-loop.md

This file was deleted.

132 changes: 123 additions & 9 deletions source/_drafts/android-basic-app-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ tags:
1.4 设计指引
+ 小部件内容
小部件是吸引用户进入app的绝佳机制。


+ 小部件导航
将用户导航到常用功能,快速完成用户的意图。

+ 小部件的尺寸
长按并放手进入大小调节模式。通过尺寸变化,控制信息的展示量。

+ 布局注意事项
根据设备网格的分辨率来摆放布局。记住以下几点:

Expand All @@ -56,24 +52,23 @@ tags:

#### 二、创建简单的小部件

2.1 小部件元器件
##### 2.1 涉及的类
+ `AppWidgetProviderInfo`
描述小部件元信息,布局、更新频率等
+ `AppWidgetProvider`
定义交互的编程接口。


<center>
<img src="../images/android-appwidget-overview.jpeg" width="100%"/>
<img src="../images/android-appwidget-overview.jpeg" width="50%"/>
</center>

除了基本的元器件,如果你的小部件需要用户配置信息,你需要提供配置修改界面让用户修改配置,如钟表小部件的时区修改。
+ Android-12起,提供默认配置,之后用户再修改。
+ Android-11及以前,每次添加小部件都启动配置页。


2.2 声明`AppWidgetProviderInfo`

##### 2.2 声明`AppWidgetProviderInfo`
在res/xml/声明:
```xml
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
Expand All @@ -95,10 +90,129 @@ tags:
```

尺寸属性:
2.2.1 尺寸属性:
+ `targetCellWidth` & `targetCellHeight`(Android-12)
+ `minWidth` & `minHeight`
+ `minResizeWidth` & `minResizeHeight`
+ `resizeMode`

2.2.2 其他属性:
+ updatePeriodMillis
+ initialLayout
+ configure
+ description
+ previewLayout(Android-12) & previewImage(Android11-↓)
+ autoAdvanceViewId
+ widgetCategory
+ widgetFeatures


##### 2.3 使用`AppWidgetProvider`类处理广播

2.3.1 在`AndroidManifest`声明

```xml
<receiver android:name="ExampleAppWidgetProvider"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/example_appwidget_info" />
</receiver>
```

2.3.2 实现`AppWidgetProvider`类
+ onUpdate()
+ onAppWidgetOptionsChanged()
+ onDeleted(Context, int[])
+ onEnabled(Context)
+ onDisabled(Context)
+ onReceive(Context, Intent)

其中`onUpdate()`回调尤为重要。


2.3.3 接收小部件广播意图
+ ACTION_APPWIDGET_UPDATE
+ ACTION_APPWIDGET_DELETED
+ ACTION_APPWIDGET_ENABLED
+ ACTION_APPWIDGET_DISABLED
+ ACTION_APPWIDGET_OPTIONS_CHANGED



##### 2.4 创建布局
布局基于RemoteViews实现,不能使用自定义view。也不能使用RemoteViews支持的类的子类。但它支持ViewStub。

2.4.1 对状态行为的支持
Android-12支持以下包含状态的View,但是需要保存状态并注册状态变更事件。
+ CheckBox
+ Switch
+ RadioButton

```kotlin
// Check the view.
remoteView.setCompoundButtonChecked(R.id.my_checkbox, true)
// Check a radio group.
remoteView.setRadioGroupChecked(R.id.my_radio_group, R.id.radio_button_2)
// Listen for check changes. The intent will have an extra with the key
// EXTRA_CHECKED that specifies the current checked state of the view.
remoteView.setOnCheckedChangeResponse(
R.id.my_checkbox,
RemoteViews.RemoteResponse.fromPendingIntent(onCheckedChangePendingIntent)
)
```

##### 2.5 实现圆角
Android-12新增的参数:
+ system_app_widget_background_radius 不能大于28dp
+ system_app_widget_inner_radius

<center>
<img src="../images/android-appwidget-corner.png" width="50%"/>
</center>


#### 三、增强你的小部件
这里讨论一些可选项,Android-12中的体验增强。

##### 3.1 添加设备主题
3.1.1 使用动态颜色向后兼容

##### 3.2 声音支持

##### 3.3 优化选择小部件时的体验
Android-12增加动态预览和小部件描述。


##### 3.4 添加小部件描述
```xml
<appwidget-provider
android:description="@string/my_widget_description">
</appwidget-provider>
```
##### 3.5 平滑转场效果
Android-12起当用户从小部件拉起应用时,使用`@android:id/background` or `android.R.id.background`优化拉起效果:
```xml
// Top level layout of the widget.
<LinearLayout
android:id="@android:id/background">
</LinearLayout>
```

##### 3.6 运行时修改`RemoteViews`
Android-12新增一些方法
```xml
// Set the colors of a progress bar at runtime.
remoteView.setColorStateList(R.id.progress, "setProgressTintList", createProgressColorStateList())
// Specify exact sizes for margins.
remoteView.setViewLayoutMargin(R.id.text, RemoteViews.MARGIN_END, 8f, TypedValue.COMPLEX_UNIT_DP)
```




Expand Down
4 changes: 2 additions & 2 deletions source/_drafts/android-source-retrofit.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Retrofit源码阅读
tags:
---
tags: Android
-------------

一、基本原理概述

Expand Down
Loading

0 comments on commit 8e1a26e

Please sign in to comment.