Android Weekly Notes #478

Android Weekly Issue #478

Introducing Navigation-Material

Bottom Sheet的navigation.

详情见:
https://google.github.io/accompanist/navigation-material/

Integrating detekt in the Workflow

在workflow中加入detekt.

关于规则集的介绍及使用.

如何定义自己的规则.

Finite State Machine as a ViewModel for Jetpack Compose Screens

无限状态机.

文末有一些比较好的参考链接.

Loading images for Jetpack Compose using Glide, Coil, and Fresco

Jetpack Compose加载图像的几种选择:

使用https://github.com/skydoves/landscapist, 有三种选择:

  • GlideImage
  • CoilImage
  • FrescoImage

Camera2 - Everything You Wanted To Know

Camera2的API使用.

Large-screen UI in the Google I/O App

大屏UI.

Animations in Navigation Compose with Accompanist

Navigation的动画.

navigation(
  startDestination = "ask_username"
  route = "login"
  enterTransition = { initial, _ ->
    // Check to see if the previous screen is in the login graph
    if (initial.destination.hierarchy.any { it.route == "login" }) {
      slideInHorizontally(initialOffsetX = { 1000 }
    } else
      null // use the defaults
  }
  exitTransition = { _, target ->
    // Check to see if the new screen is in the login graph
    if (target.destination.hierarchy.any { it.route == "login" }) {
      slideOutHorizontally(targetOffsetX = { -1000 }
    } else
      null // use the defaults
  }
  popEnterTransition = { initial, _ ->
    // Check to see if the previous screen is in the login graph
    if (initial.destination.hierarchy.any { it.route == "login" }) {
      // Note how we animate from the opposite direction on a pop
      slideInHorizontally(initialOffsetX = { -1000 }
    } else
      null // use the defaults
  }
  popExitTransition = { _, target ->
    // Check to see if the new screen is in the login graph
    if (target.destination.hierarchy.any { it.route == "login" }) {
      // Note how we animate from the opposite direction on a pop
      slideOutHorizontally(targetOffsetX = { 1000 }
    } else
      null // use the defaults
  }
) {
  composable("ask_username") {
    // Add content
  }
  composable("ask_password") {
    // Add content
  }
  composable("register") {
    // Add content
  }
}

Auto Unlock Android Device on App Deploy

设备解锁脚本:

#!/bin/bash
# When a device is attached there will be atleast 3 lines -> heading, device details, an empty new line
if adb devices | wc -l | grep "3"; then 
  # Check if device locked, this may differ on some OEMs
  if adb shell dumpsys window | grep  "mInputRestricted=true"; then 
      echo "Device is Locked"
      adb shell input keyevent KEYCODE_WAKEUP # wakeup device
      adb shell input touchscreen swipe 530 1420 530 1120 # swipe up gesture
      adb shell input text "000000" # <- Change to the your device PIN/Password
      #adb shell input keyevent 66 # simulate press enter, if your keyguard requires it
  else
      echo "Device already unLocked"
  fi
  # 2 = Stay awake on USB, 0 = reset
  adb shell settings put global stay_on_while_plugged_in 2
  #adb shell settings put system screen_brightness 700
  adb shell input keyevent KEYCODE_WAKEUP
  adb shell input touchscreen tap 0 0 # this will wake up the screen and won't have any unwanted touches
else
  echo "There should be only one device connected at a time"
fi

exit 0

可以配置到IDE的run configuration里.

Best practice to build accessible apps with Jetpack Compose

Accessibility的最佳实践:

    1. Add content description to images
    1. Hide decorative images
    1. Improve element’s description
    1. Group elements together
Row (modifier = Modifier.semantics(mergeDescendants = true){}){
   Column {
       Icon(painter = painterResource(R.drawable.ic_pets),
           contentDescription = null)
       Text(text = stringResource(R.string.no_pet))
   }
   Column {
       Icon(painter = painterResource(R.drawable.ic_car),
           contentDescription = null)
       Text(text = stringResource(R.string.car_owner))
   }
   Column(/*...*/)
}
    1. Change reading order
    1. Facilitate navigation with headings
    1. Disable element and describe element state
var checked by remember { mutableStateOf(true) }

Row(modifier = Modifier
        .toggleable(checked) { checked = !checked }
        .semantics {  stateDescription = 
                       if(checked) "ON" else "OFF" }
){
   Text(text = "Profile details")
   Switch(checked = checked,
          onCheckedChange = { checked = !checked },
          modifier = Modifier.clearAndSetSemantics {  }

   )
}

Code

  • https://github.com/akshay2211/NYTimes-Compose

你可能感兴趣的:(Android Weekly Notes #478)