Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileSky committed Oct 9, 2024
2 parents d4d6aa9 + 43abd8a commit d7483bc
Show file tree
Hide file tree
Showing 14 changed files with 531 additions and 25 deletions.
1 change: 1 addition & 0 deletions .idea/droid-wrap.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ authors = ["mzdk100 <[email protected]>"]
description = "用于Rust的Android API的高级封装"
keywords = ["android", "api", "sdk", "jni", "java"]
license = "Apache-2.0"
version = "0.3.0"
version = "0.3.4"
edition = "2021"
readme = "README.md"
repository = "https://gitcode.net/mzdk100/droid-wrap.git"
[workspace.dependencies]
android-build = "0.1.0"

[package.metadata.docs.rs]
all-features = true
Expand All @@ -27,7 +29,7 @@ rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
[features]
android = ["java_lang"]
android_app = ["android", "android_view", "java_lang"]
android_content = ["android", "android_media", "java_lang", "java_io"]
android_content = ["android", "android_media", "android_os", "java_lang", "java_io"]
android_hardware = ["android"]
android_hardware_vibrator = ["android_hardware"]
android_media = ["android"]
Expand Down Expand Up @@ -65,13 +67,13 @@ test_java_nio = ["java_nio"]
[dependencies]

[dependencies.droid-wrap-utils]
version = "0.3.0"
version = "0.3.4"
path = "utils"

[dependencies.droid-wrap-derive]
version = "0.3.0"
version = "0.3.4"
path="derive"

[workspace]
members = ["derive", "example", "utils", "tests"]
members = ["derive", "example", "utils", "tests", "aapt2"]
resolver = "2"
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@

如需了解更多信息,请查看example目录中的代码示例。

### 关于构建工具

cargo-apk目前已经被标记为弃用状态,但不得不承认他在rust生态中是最好用的apk打包工具,因此我们尝试重新实现类似的工具[cargo-aapt2](aapt2/README.md)


## 分类

这些功能函数的分类使用条件编译的方式被链接到程序中。使用时,请将这个箱子作为可选依赖项,并指定相关的feature,这是防止编译不必要的代码从而让程序体积的不断膨胀。
Expand All @@ -67,6 +72,8 @@
1. android.content.Context;
2. android.content.ContextWrapper;
3. android.content.Intent。;
4. android.content.ComponentName;
5. android.content.ComponentName_WithComponentName;

### 安卓系统(android_os)

Expand Down Expand Up @@ -128,7 +135,10 @@ android.view.View的API等(包括点击监听器的实现)。

### javaIO操作(java_io)

实现了java.io.File。
实现了java.io.File等。

1. java.io.File;
2. java.io.Serializable;

### java语言内置(java_lang)

Expand Down
13 changes: 13 additions & 0 deletions aapt2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "cargo-aapt2"
authors.workspace = true
description.workspace = true
keywords.workspace = true
license.workspace = true
version.workspace = true
edition.workspace = true
readme = "README.md"
repository.workspace = true

[dependencies]
android-build.workspace = true
13 changes: 13 additions & 0 deletions aapt2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 安卓打包工具

## 简介

cargo-aapt2是用于生成apk的工具,和谷歌官方的[aapt2](https://developer.android.google.cn/tools/aapt2?hl=fi)的使用完全一致。
如果您不想花时间配置谷歌aapt2工具的环境,你可以简单的从rust生态系统中直接获取
```shell
cargo install cargo-aapt2
```
随后可以使用下面命令获取工具的帮助
```shell
cargo aapt2 -h
```
64 changes: 64 additions & 0 deletions aapt2/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2024. The RigelA open source project team and
* its contributors reserve all rights.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/

use android_build::{android_sdk, PathExt, ANDROID_BUILD_TOOLS_VERSION};
use std::{
env::{args, var},
path::PathBuf,
process::{exit, Command},
};

/// Returns the path to the `aapt2` executable for the given build tools version.
///
/// If the `ANDROID_AAPT2` environment variable is set and points to a file that exists,
/// that path is returned.
/// If `build_tools_version` is `None`, the value of the `ANDROID_BUILD_TOOLS_VERSION` environment variable is used
/// to find the `aapt2` executable from the Android SDK root directory.
pub fn android_aapt2_path(build_tools_version: Option<&str>) -> Option<PathBuf> {
const ANDROID_AAPT2: &str = "ANDROID_AAPT2";
const AAPT2: &str = if cfg!(windows) { "aapt2.exe" } else { "aapt2" };
// Check if ANDROID_AAPT2 environment variable is set and points to a valid file
var(ANDROID_AAPT2)
.ok()
.and_then(PathExt::path_if_exists)
.map(PathBuf::from)
.or_else(|| {
android_sdk().and_then(|sdk| {
sdk.join("build-tools")
.join(
build_tools_version
.map(ToString::to_string)
.unwrap_or_else(|| {
var(ANDROID_BUILD_TOOLS_VERSION)
.expect("either ANDROID_AAPT2 or ANDROID_BUILD_TOOLS_VERSION must be set")
}),
)
.join(AAPT2)
.path_if_exists()
})
})
}

fn main() {
let aapt2 = android_aapt2_path(None).unwrap();
exit(
Command::new(&aapt2)
.args(args().skip(1))
.spawn()
.unwrap()
.wait()
.unwrap()
.code()
.unwrap_or(1),
);
}
4 changes: 2 additions & 2 deletions derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ repository.workspace = true

[dependencies]
heck = "0.5.0"
proc-macro2 = "1.0.86"
proc-macro2 = "1.0.87"
quote = "1.0.37"

[dependencies.syn]
features = ["full"]
version = "2.0.76"
version = "2.0.79"

[lib]
proc-macro = true
30 changes: 29 additions & 1 deletion src/android/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use droid_wrap_derive::{java_class, java_method};
use droid_wrap_utils::{android_context, vm_attach};

use crate::{
android::view::{View, WindowManager},
android::view::{View, Window, WindowManager},
java::lang::{CharSequence, Runnable},
JObjNew, JObjRef, JType,
};
Expand Down Expand Up @@ -200,6 +200,34 @@ impl Activity {
Self::null()
}
}

/**
查询活动的当前窗口。这可用于直接访问无法通过 Activity/Screen 获得的窗口 API 部分。
返回:Window 当前窗口,如果活动不可见,则返回 null。
*/
#[java_method]
pub fn get_window(&self) -> Option<Window> {}

/**
调用此 Activity 的 Window 上的 Window.getCurrentFocus 来返回当前聚焦的视图。
返回:View 当前具有焦点的视图或 null。
*/
#[java_method]
pub fn get_current_focus(&self) -> Option<View> {}

/**
如果此活动的主窗口当前具有窗口焦点,则返回 true。请注意,这与视图本身具有焦点不同。
返回:如果此活动的主窗口当前具有窗口焦点,则返回 true。
*/
#[java_method]
pub fn has_window_focus(&self) -> bool {}

/**
检查自由格式窗口上的标题是否直接显示在内容上。
返回:如果标题显示在内容上,则返回 True;如果将内容向下推,则返回 false。
*/
#[java_method]
pub fn is_overlay_with_decor_caption_enabled(&self) -> bool {}
}

/// 测试android.app
Expand Down
Loading

0 comments on commit d7483bc

Please sign in to comment.