From ba24d922a67907428bdf7e2e6490eeeb1eb84af0 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Fri, 24 Jun 2022 16:13:29 +0200 Subject: [PATCH] Update the examples --- check.sh | 3 --- examples/property_foreach.rs | 7 +++++-- examples/property_get.rs | 11 +++++++---- examples/property_refresh.rs | 13 ++++++++----- examples/property_set.rs | 5 ++++- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/check.sh b/check.sh index 421fb0f..739143e 100755 --- a/check.sh +++ b/check.sh @@ -3,9 +3,6 @@ set -e adb shell reboot cargo check --target=aarch64-linux-android -cargo check --target=aarch64-linux-android -cargo check --target=aarch64-linux-android --features "bionic-deprecated" -cargo check --target=aarch64-linux-android --examples --features "bionic-deprecated" cargo build --target=aarch64-linux-android --examples cargo doc cargo test diff --git a/examples/property_foreach.rs b/examples/property_foreach.rs index 1616abb..efab010 100644 --- a/examples/property_foreach.rs +++ b/examples/property_foreach.rs @@ -1,5 +1,8 @@ +use android_properties::AndroidProperties; + fn main() { - for property in android_properties::prop_values() { - println!("{}", property); + let properties = AndroidProperties::new(); + for property in properties.property_values() { + println!("{:?}", properties.get(&property)); } } diff --git a/examples/property_get.rs b/examples/property_get.rs index d1991eb..9637ec3 100644 --- a/examples/property_get.rs +++ b/examples/property_get.rs @@ -1,11 +1,14 @@ -use android_properties::AndroidProperty; +use android_properties::{AndroidProperties, AndroidProperty}; const HELLO_WORLD_PROPERTY: &str = "hello.world"; fn main() { - let mut hello_world = AndroidProperty::new(HELLO_WORLD_PROPERTY); - match hello_world.value() { - Some(_value) => println!("{}", hello_world), + let properties = AndroidProperties::new(); + let hello_world = AndroidProperty::new(HELLO_WORLD_PROPERTY); + properties.set(&hello_world, "bonjour").unwrap(); + + match properties.get(&hello_world) { + Some(value) => println!("{:?}", value), None => println!("Property {} not found", hello_world.name()), }; } diff --git a/examples/property_refresh.rs b/examples/property_refresh.rs index f172f30..ac509d8 100644 --- a/examples/property_refresh.rs +++ b/examples/property_refresh.rs @@ -1,12 +1,15 @@ -use android_properties::{setprop, AndroidProperty}; +use android_properties::{AndroidProperties, AndroidProperty}; const HELLO_WORLD_PROPERTY: &str = "hello.world"; fn main() { - setprop(HELLO_WORLD_PROPERTY, "initial value").expect("Cannot set android property"); + let properties = AndroidProperties::new(); + + properties.set_property(HELLO_WORLD_PROPERTY, "initial value").expect("Cannot set android property"); + let hello_world = AndroidProperty::new(HELLO_WORLD_PROPERTY); - println!("Initial property: {}", hello_world); + println!("Initial property: {:?}", properties.get(&hello_world)); - setprop(HELLO_WORLD_PROPERTY, "refreshed value").expect("Cannot set android property"); - println!("Refreshed property: {}", hello_world); + properties.set_property(HELLO_WORLD_PROPERTY, "refreshed value").expect("Cannot set android property"); + println!("Refreshed property: {:?}", properties.get(&hello_world)); } diff --git a/examples/property_set.rs b/examples/property_set.rs index c9f843e..f326f66 100644 --- a/examples/property_set.rs +++ b/examples/property_set.rs @@ -1,3 +1,6 @@ +use android_properties::AndroidProperties; + fn main() { - android_properties::setprop("hello.world", "hello").expect("Cannot set android property"); + let properties = AndroidProperties::new(); + properties.set_property("hello.world", "hello").expect("Cannot set android property"); }