Skip to content

Latest commit

 

History

History
82 lines (66 loc) · 15.8 KB

Android-Examples.md

File metadata and controls

82 lines (66 loc) · 15.8 KB

Android 版 PAG、GIF、Rive 示例 / The Android PAG, GIF and Rive examples

中文 English
本文档不绑定代码类。 This document is not bound to a code class.
中文 English
Example-PAG、Example-GIF、Example-Rive 三个 iOS 示例在 Example-Android 中各有一个 Android 版本:example-pag、example-gif、example-rive(Gradle application 模块,Kotlin)。它们使用 Android 库 cyltabbar,Tab、PlusButton、页面与 iOS 示例相同,资源优先直接取自 iOS 示例:图片、颜色、字体与动画文件都读取 iOS 示例自己的文件(Assets.xcassets、字体目录、动画目录、库的资源 bundle),不复制;demokit 的 DemoAssets 按 Xcode 的方式读取资源目录(@2x / @3x 按屏幕密度选择、深色外观、PDF 由 PdfRenderer 渲染、颜色集)。三个 App 与 app 共用 demokit 模块:iOS CYLSettingsDemoTableViewController 对应的设置列表、PlusButton 角标演示(iOS Example-Shared)、样式切换。 Each of the three iOS examples Example-PAG, Example-GIF and Example-Rive has an Android version in Example-Android: example-pag, example-gif, example-rive (Gradle application modules, Kotlin). They use the Android library cyltabbar, with the iOS examples' tabs, plus buttons and pages, and take their resources from the iOS examples first: images, colors, fonts and animation files are the iOS examples' own files (Assets.xcassets, the font folder, the animation folders, the library's resource bundle), not copies; DemoAssets in demokit reads an asset catalog the way Xcode does (@2x / @3x by screen density, the dark appearance, PDFs rendered with PdfRenderer, color sets). The three apps share the demokit module with app: the settings list of iOS CYLSettingsDemoTableViewController, the plus button badge demo (iOS Example-Shared), the style switch.
ObjC Example 的图片例外:app 与 demokit 不读取 Example/Images.xcassets(21 MB,其中 AppIcon.appiconset 不能作为资源打包),因此把用到的图片复制了一份:demokit/src/main/assets/objc-example/TabBarIcon 中的 Tab 图片(home、message、fishpond、account 的普通与选中图片)、PlusButton 的 post_normal / post_highlight、videoback,以及首页封面 home_select_cover 与 home_select_cover_dark;角标示例行的图标是库资源 bundle 中的 cyl_badge_sample_icon(即 App 图标),复制为 cyltabbar 的 res/drawable-nodpi/cyl_badge_sample_icon.png,由 cyl_badgeIcon 以 6 dp 圆角显示,与 iOS 相同。DemoAssets 找不到图片时记录 CYLDemoAssets 日志。 An exception for the ObjC Example's images: app and demokit do not read Example/Images.xcassets (21 MB, and its AppIcon.appiconset cannot be packaged as assets), so the images they use are copied: the tab images in demokit/src/main/assets/objc-example/TabBarIcon (home, message, fishpond, account, normal and selected), the plus button's post_normal / post_highlight, videoback, and the first tab's cover, home_select_cover and home_select_cover_dark; the badge rows' icon is the library bundle's cyl_badge_sample_icon (the app icon), copied to cyltabbar's res/drawable-nodpi/cyl_badge_sample_icon.png and shown by cyl_badgeIcon with 6 dp corners, as on iOS. DemoAssets logs a missing image under CYLDemoAssets.

[CN]目录

[EN]Contents

中文 English
模块 Modules
示例对照 The examples side by side
运行与验证 Running and checking
差异与限制 Differences and limits

[CN]模块

[EN]Modules

模块 Module 内容 Contents
example-gif 对应 Example-GIF;不需要第三方库(GIF 由系统解码);GIF 文件来自 Example-GIF/GIFApp/Resources Example-GIF; no third-party library (the platform decodes GIF); the GIF files come from Example-GIF/GIFApp/Resources
example-pag 对应 Example-PAG;依赖 libpag(com.tencent.tav:libpag);PAG 文件来自 Example-Shared/PAGResources/tab-icons,首次构建前由 scripts/fetch-animation-resources.py 下载(与 iOS 的 pod install 相同) Example-PAG; depends on libpag (com.tencent.tav:libpag); the PAG files come from Example-Shared/PAGResources/tab-icons, downloaded before the first build by scripts/fetch-animation-resources.py (as pod install does on iOS)
example-rive 对应 Example-Rive;依赖 rive-android(app.rive:rive-android 10.3.0);.riv 文件来自 Example-SwiftUI-Rive/AnimatedApp/RiveAssets Example-Rive; depends on rive-android (app.rive:rive-android 10.3.0); the .riv files come from Example-SwiftUI-Rive/AnimatedApp/RiveAssets
demokit 共享的演示代码(Android library):DemoAssets(读取 iOS 资源目录)、演示列表与设置行(DemoCatalog.SETTINGS)、DemoTabBarActivity、DemoTabBarStyle、DemoPlusButtonBadge、DemoPublishPlusButton、展示页与配置用例 The shared demo code (an Android library): DemoAssets (reads the iOS asset catalogs), the demo lists and the settings rows (DemoCatalog.SETTINGS), DemoTabBarActivity, DemoTabBarStyle, DemoPlusButtonBadge, DemoPublishPlusButton, the gallery and the configuration cases

[CN]示例对照

[EN]The examples side by side

示例 Example iOS 功能 Android 实现 Status iOS feature Android implementation
GIF 第 1 个 Tab:GIF key(CYLTabBarGIFFilePath),选中时播放一次 相同的 key,tab_rocket.gif done Tab 1: a GIF key (CYLTabBarGIFFilePath), plays once when selected The same key, tab_rocket.gif
GIF 第 2 个 Tab:通用 key(CYLTabBarAnimationFilePath) 相同的 key,tab_star.gif done Tab 2: the generic key (CYLTabBarAnimationFilePath) The same key, tab_star.gif
GIF 第 3 个 Tab:作为图片传入的 GIF(CYLTabBarItemImageURL)循环播放 库新增 CYLGIFDrawable:作为图片传入的 GIF 循环播放(对应 +cyl_animatedImageWithGIFData:) done Tab 3: a GIF given as an image (CYLTabBarItemImageURL) loops New in the library: CYLGIFDrawable, a GIF given as an image loops (the twin of +cyl_animatedImageWithGIFData:)
GIF 首页为设置列表;没有子页面的 "发布" PlusButton;1.5 倍速;橙色强调色 DemoCatalog.SETTINGS、DemoPublishPlusButton、tabBarItemAnimationSpeed、setTintColor done Home is the settings list; a "Publish" plus button without a page; 1.5x speed; orange tint DemoCatalog.SETTINGS, DemoPublishPlusButton, tabBarItemAnimationSpeed, setTintColor
PAG 四个 PAG Tab 图标(33 pt,1.5 倍速),文件不存在时显示图片 相同的文件与 key;文件不存在时不加 key 并输出提示 done Four PAG tab icons (33 pt, 1.5x), the image when a file is missing The same files and keys; without a file, no key and a log hint
PAG PlusButton:标题 "菜单" 画在 tabbar_database 背景图上,第 3 项,页面为 "菜单" MenuPlusButton done Plus button: the title "Menu" on the tabbar_database background, the third item, its page "Menu" MenuPlusButton
PAG 首页:角标帮助列表、"全屏" 按钮上抖动的随机颜色红点,push 子页面("next" 按钮)、下一页,点击重新创建 TabBar;3A57ED 导航栏、白色标题;push 的页面隐藏 TabBar HomePage、ChildPage、NextPage、NavigationPage(ActionBar 标题、返回按钮、setTabBarHidden) done Home: the badge helper table, a shaking dot of a random color on the "Full screen" item, pushes a child page ("next" item) and a next page, taps create the tab bar again; the 3A57ED navigation bar with white titles; pushed pages hide the tab bar HomePage, ChildPage, NextPage, NavigationPage (action bar title, back button, setTabBarHidden)
PAG 首次启动的引导页(3 张图、5 秒跳过) GuideActivity done The guide on first launch (3 images, a 5 s skip) GuideActivity
PAG 西柚皮肤原地互换两个 Tab 的动画(#216);"我的" 为设置列表 CYLThemeManager 监听 + updateTabBarItemAtIndex;DemoCatalog.SETTINGS done The Grapefruit skin swaps two tabs' animations in place (#216); "Me" is the settings list A CYLThemeManager listener + updateTabBarItemAtIndex; DemoCatalog.SETTINGS
Rive Tab 图标为 icons.riv 的画板(状态机 + "active" 输入,CYLTabBarRiveURL) CourseTab.animationAttributes,同样的选项 done Tab icons are icons.riv artboards (state machine + "active" input, CYLTabBarRiveURL) CourseTab.animationAttributes, the same options
Rive "Start" PlusButton,标题与 Tab 标题对齐(#636),页面为课程引导页 StartPlusButton(alignsTitleWithTabBarItemTitles)、OnboardingPage(shapes.riv、button.riv) done The "Start" plus button, its title aligned with the tab titles (#636), its page the course onboarding StartPlusButton (alignsTitleWithTabBarItemTitles), OnboardingPage (shapes.riv, button.riv)
Rive Chat:HomeView(VCard、HCard);Search:SideMenu,图标为 icons.riv 画板,选中项为蓝色背景,"Dark Mode" 开关播放 / 停止图标 CoursesPage、SideMenuPage:逐项翻译 SwiftUI 视图,使用课程自己的字体(Poppins、Inter)、图片(主题、头像、Spline、图标、标志)与颜色 done Chat: HomeView (VCard, HCard); Search: SideMenu, icons from icons.riv, the selected item on blue, the "Dark Mode" switch plays / stops its icon CoursesPage, SideMenuPage: the SwiftUI views translated item by item, with the course's own fonts (Poppins, Inter), images (topics, avatars, Spline, icons, logos) and colors
Rive Bell:设置列表上方的 menu_button.riv 与 "播放 / 停止" BellPage done Bell: menu_button.riv with "Play / Stop" above the settings list BellPage
Rive User:登录,check.riv(Check / Error 触发)与 confetti.riv SignInPage done User: sign in, check.riv (Check / Error triggers) and confetti.riv SignInPage
Rive 深色 TabBar、白色强调色;西柚皮肤互换 Chat 与 User 的图标 TabBar 颜色;CYLThemeManager 监听 done A dark tab bar with white tints; the Grapefruit skin swaps the icons of Chat and User Bar colors; a CYLThemeManager listener
全部 / All PlusButton 角标(启动后为 1,每次点击加 1)、弹性点击动画、长按、滑动切换;导航栏的样式切换 DemoPlusButtonBadge、DemoTabBarStyle(ActionBar 按钮) done The plus button badge (1 after launch, +1 per tap), bounce taps, long press, swipe; the style switch in the navigation bar DemoPlusButtonBadge, DemoTabBarStyle (an action bar button)

[CN]运行与验证

[EN]Running and checking

中文 English
构建需要 UTF-8 区域设置(macOS 与常见桌面系统的默认值):Example-PAG 的资源目录中有中文名称的图片集(屏幕全屏),在 POSIX 区域设置下 Gradle 无法读取该文件名;CI 中请设置 LC_ALL=C.UTF-8。 Building needs a UTF-8 locale (the default on macOS and common desktop systems): Example-PAG's asset catalog has an image set with a Chinese name (屏幕全屏), which Gradle cannot read under a POSIX locale; set LC_ALL=C.UTF-8 on CI.
在 Android Studio 中打开 Example-Android,运行 example-gif、example-pag 或 example-rive。example-pag 首次构建时下载 PAG 文件(需要 python3 与网络);没有时构建继续,Tab 显示图片,也可以手动执行 python3 scripts/fetch-animation-resources.py PAGResources。 Open Example-Android in Android Studio and run example-gif, example-pag or example-rive. example-pag downloads the PAG files on its first build (python3 and the network); without them the build goes on and the tabs show their images, or run python3 scripts/fetch-animation-resources.py PAGResources yourself.
gradle :example-gif:testDebugUnitTest :example-pag:testDebugUnitTest :example-rive:testDebugUnitTest(Robolectric)检查 Tab、key、PlusButton、页面、引导页、皮肤互换与 PlusButton 角标;三个模块与 demokit 的 lint 没有问题。 gradle :example-gif:testDebugUnitTest :example-pag:testDebugUnitTest :example-rive:testDebugUnitTest (Robolectric) checks the tabs, keys, plus buttons, pages, the guide, the skin swaps and the plus button badge; lint reports no issues in the three modules and demokit.

[CN]差异与限制

[EN]Differences and limits

中文 English
库通过反射调用 libpag 与 rive-android,方法名与参数按两个库的真实类核对(PAGView、RiveAnimationView),并由测试检查;rive-android 的 Kotlin 默认参数通过其 $default 方法传递(如 Fit.CONTAIN、Loop.AUTO),按官方示例在加载时传入画板与状态机。 The library calls libpag and rive-android by reflection; the method names and parameters were checked against both libraries' real classes (PAGView, RiveAnimationView) and a test checks them; rive-android's Kotlin default parameters go through its $default methods (e.g. Fit.CONTAIN, Loop.AUTO), and the artboard and state machine are given at load, as the official sample does.
libpag 与 rive-android 带原生代码,JVM 上无法加载:测试只检查 key、页面与回退,未在设备或模拟器上运行;GIF 循环在 JVM 上无法解码(Movie),该测试只在能解码的环境中运行。 libpag and rive-android load native code, which the JVM cannot: the tests check the keys, pages and fallbacks, and nothing was run on a device or an emulator; Movie decodes no GIF on the JVM, so the looping test runs only where it can.
rive-android 固定为 10.3.0:更新的版本需要 compileSdk 36(androidx.core 1.17)或 Compose。lifecycle 2.9 的 lint 检查(NullSafeMutableLiveData)会让本项目的 lint 崩溃,example-rive 中关闭了该检查(App 不使用 LiveData)。 rive-android is pinned to 10.3.0: newer versions need compileSdk 36 (androidx.core 1.17) or Compose. The lint check of lifecycle 2.9 (NullSafeMutableLiveData) crashes this project's lint, so example-rive turns it off (the app has no LiveData).
示例按 iOS 源码直接翻译(文字、字体、尺寸、颜色、时序),遇到问题时参考官方示例(pag-android、pag-enterprise-android、rive-android)。SwiftUI 的 blur 只在 Android 12 及以后生效(RenderEffect),.regularMaterial 以半透明白色表示。iOS 示例的 Liquid Glass 效果在 Android 上不存在,样式切换只改变 tabBarStyleType。 The examples are translated directly from the iOS sources (texts, fonts, sizes, colors, timing), with the official samples (pag-android, pag-enterprise-android, rive-android) as the reference when a question comes up. SwiftUI's blur applies on Android 12 and later only (RenderEffect), and .regularMaterial is a translucent white. The iOS examples' Liquid Glass does not exist on Android; the style switch only changes tabBarStyleType.