技术标签: java android android studio
2021年作者开始学习Android开发,一直以来对于谷歌手表及其他可穿戴只能设备非常热衷,偶然接触到一款作用于可穿戴设备上的全新操作系统,本着对于其技术水平的好奇,作者会带大家一起来认识与学习Wear OS。
在开发移动应用程序时,我们通常只关注两种类型的设备:平板电脑和智能手机。每次我们开始新的 Android Studio 项目时,当我们遇到全新的其他设备时,我们通常都会去寻找它已经存在的模板,在此模板的基础上进行代码构建。
既然如此,那你有没有考虑过为可穿戴设备构建一款属于它们的应用程序?
Wear OS(前称为Android Wear、Wear OS ByGoogle),是Android操作系统的一个分支版本,专为智能手表等可穿戴式电脑设备所设计,由Google主导开发。初始原型于2014年3月19日公布。
智能手表在设计和交互性方面与智能手机不同,因为不同的使用环境和较小的屏幕。布局更简单,更依赖于滑动操作来操作。
在本文中,我将教大家如何为 Wear OS 可穿戴设备创建简易的应用程序。
要读懂此教程,你至少应该具备:
Wear OS是专为可穿戴设备设计的新平台。尽管它以Android为基础,但它是一种全新的模式并拥有一组独特的功能。
如果你已经比较熟悉Android移动应用程序开发,Wear OS也应该有迹可循。
建立 Android Wear 应用时,请根据项目要求选择"Wear OS"选项卡、空的活动或任何其他可用选项。
你的应用程序包中会出现两个模块:用于智能手表的佩戴模块,以及用于平板电脑和手机的应用程序模块。
如果你希望将智能手表功能添加到现有应用程序中,打开它,然后从菜单中选择 Wear OS 模块,进行设置。之后会出现一个文件夹,其中包含所需模块的文件名。File -> New -> New Module
从两个模块创建两个不同的文件。但是,它们必须具有相同的包名称,并在发布时使用相同的认证进行验证。.apk.aab
这一点很重要,因为 Google 服务允许应用相互通信。当然你也可以在不使用智能手机平台的情况下制作Wear OS应用程序。
第一步是为应用程序设计布局。
布局是对应用程序用户界面的直观描述。它是向用户显示的应用的图形插图。
Android应用程序开发中的主要问题之一是设备种类繁多。它们拥有各种不同的尺寸、形状和配置。即使是Wear OS,也有各种屏幕样式需要考虑,包括圆形,方形和带有切碎边缘的圆形。
Wear OS和Android OS具有相似的UI模式。所以你可以使用Google的Wear UI工具包,该工具包具有满足智能手表样式要求所需的一套全面功能。
如此,实施过程简化了,开发资源也减少了。
为此,我们应在应用级文件中包含以下依赖项。build.gradle
dependencies {
// 对于Wear UI工具包
implementation 'com.google.android.support:wearable:2.5.0'
implementation 'com.android.support:percent:28.0.0'
implementation 'com.android.support:wear:28.0.0'
implementation 'androidx.wear:wear:1.0.0'
compileOnly 'com.google.android.wearable:wearable:2.7.0'
// 对于谷歌服务
implementation 'com.google.android.gms:play-services-wearable:16.0.1'
implementation 'com.android.support:support-v4:28.0.0'
}
Wear OS Apps的清单与Android智能手机的清单略有不同。
在Wear OS中,必须定义它的功能与操作系统库以及其他元数据。
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="com.demo.wear">
<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault">
<uses-library
android:name="com.google.android.wearable"
android:required="true" />
<!-- If your software is Standalone, it means it doesn't need to be run on a mobile device. -->
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
工具包中有四个主要的 UI 元件值得特别注意,因为它们在 Wear OS 开发中很有用:
<androidx.wear.widget.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:padding="8dp"
tools:deviceIds="wear"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
app:layout_boxedEdges="all">
<ImageButton
android:background="@android:color/transparent"
android:layout_height="60dp"
android:layout_width="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:src="@drawable/ic_ok" />
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="some text"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!--In this example, this ImageButton requires an icon named ic_cancel-->
<ImageButton
android:background="@android:color/transparent"
android:layout_height="60dp"
android:layout_width="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:src="@drawable/ic_cancel" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.wear.widget.BoxInsetLayout>
结果:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout
xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
tools:context=".MainActivity"
tools:deviceIds="wear">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
app:boxedEdges="none">
<android.support.wear.widget.SwipeDismissFrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_dismiss_root" >
<TextView
android:id="@+id/test_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:text="Swipe to dismiss"/>
</android.support.wear.widget.SwipeDismissFrameLayout>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Hello world" />
</FrameLayout>
</android.support.wear.widget.BoxInsetLayout>
结果:
导航是指允许用户在应用程序中的不同屏幕或目标中实现进入和返回的交互界面。
手表应用程序通常没有设置标题栏,来节省大量的显示空间。使用 ViewPager 时,不会显示 TabLayout,因此,我们可能无法确定我们所在的页面。
让我们来看看导航栏的效果,它可以解决这个问题。WearableNavigationDrawerView
当你从屏幕顶部向下滑动时,它将显示一个导航栏,显示当前页面的图标和标题。如果有多个页面,请左右滑动页面以进行更改。
让我们看看它是如何使用的。我们更改布局文件并创建根布局,并添加导航栏控件。WearableDrawerLayout
<android.support.wear.widget.drawer.WearableNavigationDrawerView
android:id="@+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navigationStyle="multiPage"/>
设置导航抽屉的适配器,以及每个页面的图标和标题,如下所示:
class DrawerAdapter(context: Context) : WearableNavigationDrawerView.WearableNavigationDrawerAdapter() {
private val context = context
override fun getItemText(pos: Int): CharSequence {
return when (pos) {
0 -> "First page"
else -> "The second page"
}
}
override fun getItemDrawable(pos: Int): Drawable {
// 创建两个图标并命名它们
return when (pos) {
0 -> ContextCompat.getDrawable(context, R.drawable.icon_one)!!
else -> ContextCompat.getDrawable(context, R.drawable.icon_two)!!
}
}
override fun getCount(): Int {
return 2
}
}
在*.MainActivity*中设置抽屉。
navigation_drawer.apply{
setAdapter(DrawerAdapter(this))
controller.peekDrawer()
addOnItemSelectedListener {
pos ->
// 切换页面
}
}
结果:
在此教程中,我们学习了如何使用 ConstraintLayout、SwipeDismissFrameLayout 和 WearableNavigationDrawerView 创建基于 Android 的 Wear OS 应用程序。
但这只是基本的构建,希望大家能在这个教程的基础上能加入自己的想象,从而完成一个功能更全面更加优化的Wear OS app。
文章浏览阅读3.3k次,点赞7次,收藏39次。CPU 执行现行程序的过程中,出现某些急需处理的异常情况或特殊请求,CPU暂时中止现行程序,而转去对异常情况或特殊请求进行处理,处理完毕后再返回现行程序断点处,继续执行原程序。void 函数名(void) interrupt n using m {中断函数内容 //尽量精简 }编译器会把该函数转化为中断函数,表示中断源编号为n,中断源对应一个中断入口地址,而中断入口地址的内容为跳转指令,转入本函数。using m用于指定本函数内部使用的工作寄存器组,m取值为0~3。该修饰符可省略,由编译器自动分配。_51单片机中断篇
文章浏览阅读396次。项目经验(案例一)项目时间:2009-10 - 2009-12项目名称:中驰别克信息化管理整改完善项目描述:项目介绍一,建立中驰别克硬件档案(PC,服务器,网络设备,办公设备等)二,建立中驰别克软件档案(每台PC安装的软件,财务,HR,OA,专用系统等)三,能过建立的档案对中驰别克信息化办公环境优化(合理使用ADSL宽带资源,对域进行调整,对文件服务器进行优化,对共享打印机进行调整)四,优化完成后..._网络工程师项目经历
文章浏览阅读1k次,点赞31次,收藏30次。LVS:Linux Virtual Server,负载调度器,内核集成, 阿里的四层SLB(Server Load Balance)是基于LVS+keepalived实现。NATTUNDR优点端口转换WAN性能最好缺点性能瓶颈服务器支持隧道模式不支持跨网段真实服务器要求anyTunneling支持网络private(私网)LAN/WAN(私网/公网)LAN(私网)真实服务器数量High (100)High (100)真实服务器网关lvs内网地址。
文章浏览阅读899次。https://www.toutiao.com/a6713171323893318151/作者 | 黄小邪/言有三编辑 | 黄小邪/言有三图像预处理算法的好坏直接关系到后续图像处理的效果,如图像分割、目标识别、边缘提取等,为了获取高质量的数字图像,很多时候都需要对图像进行降噪处理,尽可能的保持原始信息完整性(即主要特征)的同时,又能够去除信号中无用的信息。并且,降噪还引出了一..._噪声很大的图片可以降噪吗
文章浏览阅读152次。目录谨慎地覆盖cloneCloneable接口并没有包含任何方法,那么它到底有什么作用呢?Object类中的clone()方法如何重写好一个clone()方法1.对于数组类型我可以采用clone()方法的递归2.如果对象是非数组,建议提供拷贝构造器(copy constructor)或者拷贝工厂(copy factory)3.如果为线程安全的类重写clone()方法4.如果为需要被继承的类重写clone()方法总结谨慎地覆盖cloneCloneable接口地目的是作为对象的一个mixin接口(详见第20_为继承设计类有两种选择,但无论选择其中的
文章浏览阅读958次,点赞21次,收藏24次。今天学长向大家分享一个毕业设计项目基于协同过滤的电影推荐系统项目运行效果:项目获取:https://gitee.com/assistant-a/project-sharing21世纪是信息化时代,随着信息技术和网络技术的发展,信息化已经渗透到人们日常生活的各个方面,人们可以随时随地浏览到海量信息,但是这些大量信息千差万别,需要费事费力的筛选、甄别自己喜欢或者感兴趣的数据。对网络电影服务来说,需要用到优秀的协同过滤推荐功能去辅助整个系统。系统基于Python技术,使用UML建模,采用Django框架组合进行设
文章浏览阅读614次。10G SFP+光模块被广泛应用于10G以太网中,在下一代移动网络、固定接入网、城域网、以及数据中心等领域非常常见。下面易天光通信(ETU-LINK)就为大家一一盘点下10G SFP+光模块都有哪些吧。一、10G SFP+双纤光模块10G SFP+双纤光模块是一种常规的光模块,有两个LC光纤接口,传输距离最远可达100公里,常用的10G SFP+双纤光模块有10G SFP+ SR、10G SFP+ LR,其中10G SFP+ SR的传输距离为300米,10G SFP+ LR的传输距离为10公里。_10g sfp+
文章浏览阅读239次。该项目含有源码、文档、程序、数据库、配套开发软件、软件安装教程。欢迎交流项目运行环境配置:项目技术:Express框架 + Node.js+ Vue 等等组成,B/S模式 +Vscode管理+前后端分离等等。环境需要1.运行环境:最好是Nodejs最新版,我们在这个版本上开发的。其他版本理论上也可以。2.开发环境:Vscode或HbuilderX都可以。推荐HbuilderX;3.mysql环境:建议是用5.7版本均可4.硬件环境:windows 7/8/10 1G内存以上;_基于vue美食网站源码
文章浏览阅读62次。oldwain随便写@hexun链接:http://oldwain.blog.hexun.com/ ...
文章浏览阅读843次,点赞16次,收藏22次。用这个工具扫描其它网站时,要注意法律问题,同时也比较慢,所以我们以之前写的登录页面为例子扫描。_sqlmap拖库
文章浏览阅读1.5w次,点赞5次,收藏38次。Origin也能玩转图片的拼接组合排版谭编(华南师范大学学报编辑部,广州 510631)通常,我们利用Origin软件能非常快捷地绘制出一张单独的绘图。但是,我们在论文的撰写过程中,经常需要将多种科学实验图片(电镜图、示意图、曲线图等)组合在一张图片中。大多数人都是采用PPT、Adobe Illustrator、CorelDraw等软件对多种不同类型的图进行拼接的。那么,利用Origin软件能否实..._origin怎么把三个图做到一张图上
文章浏览阅读4.2k次,点赞4次,收藏51次。51单片机智能电风扇控制系统仿真设计( proteus仿真+程序+原理图+报告+讲解视频)仿真图proteus7.8及以上 程序编译器:keil 4/keil 5 编程语言:C语言 设计编号:S0042。_电风扇模拟控制系统设计