android wear-Addressing Common Issues,Optimizing Performance and Battery Life
> Addressing Common Issues
Creating a custom watch face for Android Wear is substantially different from creating notifications and wearable-specific activities.
Android Wear lets your watch face determine the screen shape at runtime. To detect whether the screen is square or round, override the onApplyWindowInsets()
method
in the CanvasWatchFaceService.Engine
class as
follows:
private class Engine extends CanvasWatchFaceService.Engine { boolean mIsRound; int mChinSize; @Override public void onApplyWindowInsets(WindowInsets insets) { super.onApplyWindowInsets(insets); mIsRound = insets.isRound(); mChinSize = insets.getSystemWindowInsetBottom(); } ... }
To ensure that the system indicators remain visible, you can configure their position on the screen and whether they need background protection when you create a WatchFaceStyle
instance:
- To set the position of the status bar, use the
setStatusBarGravity()
method. - To set the position of the hotword, use the
setHotwordIndicatorGravity()
method. - To protect the status bar and hotword with a semi-transparent gray background, use the
setViewProtection()
method. This is usually necessary if your watch face has a light background, since the system indicators are white.
Canvas.getWidth()
andCanvas.getHeight()
methods
and set the positions of your graphic elements using values that are some fraction of the detected screen size. If you resize the elements of your watch face in response to a peek card, use values that are some fraction of the remaining space above the card
to redraw your watch face.In addition to accommodating notification cards and system indicators, you need to ensure that the animations in your watch face run smoothly and that your service does not perform
unnecessary computations.
>Optimizing Performance and Battery Life
In addition to accommodating notification cards and system indicators, you need to ensure that the animations in your watch face run smoothly and that your service does not perform
unnecessary computations. Watch faces in Android Wear run continuously on the device, so it is critical that your watch face uses power efficiently.
>To improve the performance of your watch face:
- Do not use graphic elements that are larger than you need.
- Remove extra transparent pixels around the edges.
Canvas
object
using the Canvas.drawBitmap()
method,
you can provide a Paint
instance
to configure several options. To improve performance, disable anti-aliasing using thesetAntiAlias()
method,
since this option does not have any effect on bitmaps.
》When possible, avoid performing these operations inside the Engine.onDraw()
method:
- Loading images and other resources.
- Resizing images.
- Allocating objects.
- Performing computations whose result does not change between frames.
Animations and small changes to the contents of the watch face wake up the CPU. Your watch face should let the CPU sleep in between animations. To maximize battery life, use animations sparingly. Even a blinking colon wakes up the CPU with every blink and hurts battery life.
The Android Wear companion app lets developers and users see how much battery different processes on the wearable device are consuming under Settings > Watch battery.
For more information about new features in Android 5.0 that help you improve battery life, see Project Volta.
相關文章
- Oracle -- Common Performance Tuning IssuesOracleORM
- Metlink:Performance issues with enq: US - contentionORMENQ
- Top 5 Database and/or Instance Performance Issues in RAC EnvironmentDatabaseORM
- N-channel MOSFET to extend battery life in portable devicesBATdev
- Database and/or Instance Performance Issues in RAC Environment_1373500.1DatabaseORM
- Android Jetpack 之 LifecycleAndroidJetpack
- MySQL 8.0 Reference Manual(讀書筆記60節--Optimizing the MySQL Server 和 Measuring Performance)MySql筆記ServerORM
- 播布客視訊-Performance Tuning筆記(三)Database Configuration and IO IssuesORM筆記Database
- 淺談Android中LifecycleAndroid
- MySQL 8.0 Reference Manual(讀書筆記51節--Optimizing Subqueries, Derived Tables, View References, and Common Table Expressions(1))MySql筆記ViewExpress
- MySQL 8.0 Reference Manual(讀書筆記52節--Optimizing Subqueries, Derived Tables, View References, and Common Table Expressions(2))MySql筆記ViewExpress
- Android耗電分析之Battery Historian工具使用AndroidBAT
- Performance and Memory Improvements in ART(Android O)ORMAndroid
- Android新元件架構——LifecylceAndroid元件架構
- Android程式生命週期ProcessLifecycleAndroid
- Flutter仿Android生命週期LifecycleStateFlutterAndroid
- Android 官方架構元件(一)——LifecycleAndroid架構元件
- Android 官方架構元件之 LifecycleAndroid架構元件
- Android 程式生命週期 Process LifecycleAndroid
- 初學 Android 架構元件之 LifecycleAndroid架構元件
- Android Jetpack元件之Lifecycles庫詳解AndroidJetpack元件
- 通過 Battery Historian 工具分析 Android APP 耗電情況BATAndroidAPP
- Master Note for Tablespace IssuesAST
- android-Optimizing Content for the Assistant,Handling App LinksAndroidAPP
- Android生命週期元件Lifecycle使用詳解Android元件
- what is life?
- Life on the Farm
- MySQL:COUNT(*) profile optimizing階段慢MySql
- Android技能樹 — Rxjava取消訂閱小結(2):RxLifeCycleAndroidRxJava
- com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException:AndroidUIAPIORMExceptionIDE
- Battery Indicator 電池指示燈工具BATIndicator
- performance of the databaseORMDatabase
- Activitylifecyclecallbacks使用
- It's my life
- It s my life
- Two extremes in lifeREM
- 7.life
- How to Troubleshoot Grid Infrastructure Startup IssuesASTStruct