技术标签: 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。
文章浏览阅读7.8k次,点赞3次,收藏9次。如何配置filezilla服务端和客户端百度‘filezilla server’下载最新版。注意点:下载的版本如果是32位的适用xp和win2003,百度首页的是适用于win7或更高的win系统。32和64内容无异。安装过程也是一样的。一、这里的filezilla包括服务端和客户端。我们先来用filezilla server 架设ftp服务端。看步骤。1选择标准版的就可以了。 _filezilla server for windows (32bit x86)
文章浏览阅读724次,点赞18次,收藏8次。深度学习作为一种强大的机器学习技术,已经成为图像处理领域的核心技术之一。通过模拟人脑处理信息的方式,深度学习能够从图像数据中学习到复杂的模式和特征,从而实现从简单的图像分类到复杂的场景理解等多种功能。要充分发挥深度学习在图像处理中的潜力,我们首先需要理解图像的本质。本文旨在深入探讨深度学习图像处理的基础概念,为初学者铺平通往高级理解的道路。我们将从最基础的问题开始:图像是什么?我们如何通过计算机来理解和处理图像?
文章浏览阅读62次。在收集到初步的样本数据之后,接下来该考虑的问题有:(1)样本数据集的数量和质量是否满足模型构建的要求。(2)是否出现从未设想过的数据状态。(3)是否有明显的规律和趋势。(4)各因素之间有什么样的关联性。解决方案:检验数据集的数据质量、绘制图表、计算某些特征量等,对样本数据集的结构和规律进行分析。从数据质量分析和数据特征分析两个角度出发。_数据分析 规律集
文章浏览阅读8.9k次。关于桌面上图标都不见了这类问题的解决方法1、在桌面空白处右击鼠标-->排列图标-->勾选显示桌面图标。2、如果问题还没解决,那么打开任务管理器(同时按“Ctrl+Alt+Del”即可打开),点击“文件”→“新建任务”,在打开的“创建新任务”对话框中输入“explorer”,单击“确定”按钮后,稍等一下就可以见到桌面图标了。3、问题还没解决,按Windows键+R(或者点开始-->..._上传文件时候怎么找不到桌面图标
文章浏览阅读1.5k次。参考:http://blog.csdn.net/zahuopuboss/article/details/9259283 #include #include #include #include #include #include #include #include #include #include #include #include _怎么设置tun的接收缓冲
文章浏览阅读741次。创建一个inputView继承于UIView- (instancetype)initWithFrame:(CGRect)frame{ self = [superinitWithFrame:frame]; if (self) { self.backgroundColor = [UIColorcolorWithRed:0.13gre
文章浏览阅读594次。字符串面试题(2022)_java字符串相关面试题
文章浏览阅读1.4w次,点赞12次,收藏21次。VSCODE 实现远程GUI,显示plt.plot, 设置x11端口转发问题服务器 linux ubuntu16.04本地 windows 10很多小伙伴发现VSCode不能显示figure,只有用自带的jupyter才能勉强个截图、或者转战远程桌面,这对数据分析极为不方便。在命令行键入xeyes(一个显示图像的命令)会failed,而桌面下会出现:但是Xshell能实现X11转发图像,有交互功能,但只能用Xshell输入命令plot,实在不方便。其实VScode有X11转发插件!!方法_vscode远程ssh连接服务器 python 显示plt
文章浏览阅读529次。网络编程_javase套接字socket
文章浏览阅读3.3k次,点赞2次,收藏2次。element switch开关文字显示element中switch开关把on-text 和 off-text 属性改为 active-text 和 inactive-text 属性.怎么把文字描述显示在开关上?下面就是实现方法: 1 <el-table-column label="状态"> 2 <template slot-scope="scope">..._el-switch 不同状态显示不同字
文章浏览阅读785次。java后台发起请求使用的工具类package com.cennavi.utils;import org.apache.http.Header;import org.apache.http.HttpResponse;import org.apache.http.HttpStatus;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpPost;import org.apach_httprequestutil.httpget
文章浏览阅读137次。在前两节我们部署了App-V Server并且序列化了相应的软件,现在可谓是万事俱备,只欠东风。在这篇博客里面主要介绍一下如何部署客户端并实现应用程序的虚拟化。在这里先简要的说一下应用虚拟化的工作原理吧!App-V Streaming 就是利用templateServer序列化出一个软件运行的虚拟环境,然后上传到app-v Server上,最后客户..._app-v 客户端