diff --git a/.gitignore b/.gitignore index c6cbe562a42726ab875d51cb513723b234787300..37a4eb8b43d978ea05b2c6e3fb934f9b40dddd4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,15 @@ *.iml .gradle /local.properties -/.idea/workspace.xml +/.idea/caches /.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml .DS_Store /build /captures +.externalNativeBuild +/entry/.preview +.cxx diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000000000000000000000000000000000000..9d45f4369697246b4bb01e1cb33f15a0252f36ba --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 734b74319c64c454d22cd9b6987d62614ce89247..61a9130cd9669c3843e6445dfe1fee2d493869bc 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,23 +1,6 @@ - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3377d40335424fd605124d4761390218bb..0000000000000000000000000000000000000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 49a6be07e4322f09fa29f4bbd86f1f0ed573625d..cd4ae4464d47b01a068a8d42f4b8271a7008e76b 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -3,16 +3,19 @@ diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000000000000000000000000000000000000..19e238eaa31f512cfc1e8641964227098d1eb8bb --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9ddc1ea681e50c02395b47cb1453edb03a1f4265..8a14290d011eafeb38e9abc5abac47df163a6d4f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,84 +1,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1.8 - - - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 6b18980960f43350ef67ec72c640ed5ed3f9a51a..f80b4058dae01383d0cec635c161f2590039bb12 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,9 +2,9 @@ - - - + + + \ No newline at end of file diff --git a/.idea/qaplug_profiles.xml b/.idea/qaplug_profiles.xml new file mode 100644 index 0000000000000000000000000000000000000000..3dfd21f3217524e575f32113c93bdd238a03c1bc --- /dev/null +++ b/.idea/qaplug_profiles.xml @@ -0,0 +1,465 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460d8b38ac04e3a3224d7c79ef719b1991a9..0000000000000000000000000000000000000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..ff7f412774ce68c1d8cd79c3c69cf891bf31f9af --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## 0.0.1-SNAPSHOT +ohos 第一个版本 + * 实现了原库的大部分 api + *Window.setBoundRect(Rect boundRect)设置移动窗口的边界。因为鸿蒙没有提供 获取底部导航栏高度, + 底部导航栏是否显示等API导致计算Rect的时候有点偏差,所以导致window窗口在滑动的时候不能紧贴上下边界 \ No newline at end of file diff --git a/README.OPENSOURCE b/README.OPENSOURCE new file mode 100644 index 0000000000000000000000000000000000000000..e66d772019761dd8ad0026d6b6b5238dca484241 --- /dev/null +++ b/README.OPENSOURCE @@ -0,0 +1,19 @@ +[ + + { + + "Name": "FloatUtil", + + "License": "MIT License", + + "License File": "LICENSE", + + "Version Number": "1.0", + + "Upstream URL": "https://github.com/liuguangli/FloatUtil", + + "Description": "一个简单的浮窗工具,封装了浮窗的使用方法" + + } + +] \ No newline at end of file diff --git a/README.md b/README.md index 800fe8f16a6faa0fd7b176b200fc77dc9f234913..e6d359cf848cf405b312c34bae9165a2fd2ba028 100644 --- a/README.md +++ b/README.md @@ -1,95 +1,135 @@ -## FloatUtil -[![](https://jitpack.io/v/liuguangli/FloatUtil.svg)](https://jitpack.io/#liuguangli/FloatUtil) +# FloatUtil -一个简单的浮窗工具。封装了浮窗的使用方法,并做了系统、版本的兼容处理,帮你绕过权限的限制。 +#### 项目介绍 +- 项目名称:FloatUtil +- 所属系列:openharmony的第三方组件适配移植 +- 功能:一个简单的浮窗工具。封装了浮窗的使用方法。 +- 项目移植状态:主功能完成 +- 调用差异:无 +- 开发版本:sdk6,DevEco Studio 2.2 Beta1 +- 基线版本:Release 1.0 -![浮窗](https://github.com/liuguangli/FloatUtil/blob/master/files/float_drag.gif) -## 开始 -项目使用 [jitpack](https://jitpack.io) 做开源库的托管,你需要在 .gradle 中添加  [jitpack](https://jitpack.io) -的仓库。 +#### 效果演示 - allprojects { - repositories { - jcenter() - maven { url "https://jitpack.io" } + + +#### 安装教程 + + +1.在项目根目录下的build.gradle文件中, +```java + allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } } - -在添加 FloatUtil 的依赖引用: - - - dependencies { - compile 'com.github.liuguangli:FloatUtil:-SNAPSHOT' - } + } +``` +2.在entry模块的build.gradle文件中, +```java + dependencies { + implementation('com.gitee.chinasoft_ohos:FloatUtil:0.0.1-SNAPSHOT') + ...... + } +``` + +在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行 +如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, +并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 + +#### 使用说明 + +1.初始化: + +```java + SimpleView floatView = new SimpleView(this); + FloatUtil builder = new FloatUtil.Builder() + .Component(floatView) + .build(this); +``` +SimpleView 是你自定义的 Component,就这么简单,浮窗显示出来了 + +2.关闭浮窗 +```java +builder.hideFloatView(floatView); +``` +同一个 Component 类,同时只能显示一个实例, 关闭的时候指定一个 Component 对象便能知道关闭哪个浮窗实例 + +3.向浮窗传递参数,在当前窗口的自定义Component定义函数onParamReceive(IntentParams args)通过 +IntentParams args进行传递参数 +```java +IntentParams params = new IntentParams(); +floatView.onParamReceive(params); +``` +4.指定层级和对其方式 +```java +new FloatUtil.Builder() + .setComponent(smartFloatView) //window 窗口布局 + .setGravity(LayoutAlignment.CENTER) //对其方式 + .setTypeFlag(TypeFlag.MOD_APPLICATION_MEDIA) //指定层级 + .build(this); + +//应用内窗体 TypeFlag.MOD_APPLICATION_MEDIA +//应用外窗体 TypeFlag.MOD_APP_OVERLAY +``` +5.接口说明: -### 创建一个简单的浮窗 +```java +/** + * view 自定义布局 + */ +setComponent(Component view) - SimpleView floatView = new SimpleView(this); - FloatUtil.showFloatView(floatView, null); - -SimpleView 是你自定义的 View,就这么简单,浮窗显示出来了。 +/** + * gravity 对其方式 + */ +setGravity(int gravity) -![浮窗](https://github.com/liuguangli/FloatUtil/blob/master/files/simple_float.gif) - -### 关闭浮窗 +/** + * height 自定义窗体高度 + */ +setHeight(int height) - FloatUtil.hideFloatView(context, SimpleView.class, false); -同一个 View 类,同时只能显示一个实例, 关闭的时候指定一个 class 对象便能知道关闭哪个浮窗实例。 最后一个参数 -决定要不要将当前实例缓存,以便下次快速显示并维持状态,false 代表不缓存,true 表示要缓存。 +/** + * width 自定义窗体高度 + */ +setWidth(int width) -### 向浮窗传递参数 +/** + * isMovable 是否可以拖动 + */ +setIsMovable(boolean isMovable) -FloatUtil 提供了一个接口:ParamReceiver。你自定义的 View 实现这个接口便能接收参数。 +/** + * typeFlag 窗口层级 + */ +setTypeFlag(TypeFlag typeFlag) - public class SimpleViewWitchParam extends FrameLayout implements ParamReceiver { - public static final java.lang.String PARAM = "PARAM"; - public static final String CONTENT = "content"; - @Override - public void onParamReceive(Bundle bundle) { - // 在这个回调方法中接收参数并解析 - if (bundle != null) { - String param = bundle.getString(PARAM); - - } - } - } - -然后在添加这个 SimpleViewWitchParam 到浮窗。 - - SimpleViewWitchParam floatView = new SimpleViewWitchParam(this); - Bundle bundle = new Bundle(); - bundle.putString(SimpleViewWitchParam.PARAM, "我是传过来的参数"); - FloatUtil.showFloatView(floatView, bundle); - -![浮窗](https://github.com/liuguangli/FloatUtil/blob/master/files/float_param.gif) - -### 指定层级和对齐方式 - - SimpleViewWitchParam floatView = new SimpleViewWitchParam(this); - // 居中对齐,浮窗层级为 WindowManager.LayoutParams.TYPE_TOAST - FloatUtil.showFloatView(floatView, Gravity.CENTER,WindowManager.LayoutParams.TYPE_TOAST , null); - -![浮窗](https://github.com/liuguangli/FloatUtil/blob/master/files/float_center.gif) - -浮窗类型 type 决定了浮窗的层级,关于浮窗层级的详细理解可以参考我的博客:[《浮窗开发之窗口层级》](http://www.liuguangli.win/archives/476), -Android 系统对窗体的某些层级有权限限制,例如 WindowManager.LayoutParams.TYPE_PHONE 类型的窗体需要授权。 +/** + * point 指定x,y位置 + */ +point(Point point) +``` + +## 测试信息 + +CodeCheck代码测试无异常 + +CloudTest代码测试无异常 -### 智能浮窗(突破授权) +病毒安全检测通过 -FloatUtil 提供智能方式添加浮窗,针对特定的系统版本、机型为你选择合适的浮窗 type ,越过授权(详细参考我的博客:[越过用户授权使用浮窗](http://www.liuguangli.win/archives/484)),你不需要再去关注复杂的处理过程。 - - SimpleViewWitchParam floatView = new SimpleViewWitchParam(this); - Bundle bundle = new Bundle(); - bundle.putString(SimpleViewWitchParam.PARAM, "智能浮窗"); - // 指定浮窗显示的位置 - Point point = new Point(); - point.x = 0; - point.y = 0; - FloatUtil.showSmartFloat(floatView, Gravity.CENTER, point, bundle); - +当前版本demo功能与原组件基本无差异 -## MIT License +## 版本迭代 + +- 0.0.1-SNAPSHOT + +## 版权和许可信息 +``` +MIT License Copyright (c) 2016 刘光利 @@ -110,5 +150,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - +``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index f6abf0a7979324f3fd71626fd812c4c29b5ce89f..49bd550bd2daf5240e23681f66bd1c5b835cc430 100644 --- a/build.gradle +++ b/build.gradle @@ -1,24 +1,36 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 +ohos { + compileSdkVersion 6 + defaultConfig { + compatibleSdkVersion 5 + } +} buildscript { repositories { - jcenter() + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' - classpath "com.github.dcendents:android-maven-gradle-plugin:1.5" - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.huawei.ohos:hap:2.4.5.0' + classpath 'com.huawei.ohos:decctest:1.2.4.1' } } allprojects { repositories { - jcenter() - maven { url "https://jitpack.io" } + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } } } - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/simple/.gitignore b/entry/.gitignore similarity index 100% rename from simple/.gitignore rename to entry/.gitignore diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..455f27a7822959f8289e1f4d280e5a6e0d57bc97 --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 +ohos { + compileSdkVersion 6 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.200' + implementation project(':library') +} +decc { + supportType = ['html', 'xml'] +} diff --git a/entry/proguard-rules.pro b/entry/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/entry/src/main/config.json b/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..db1cd6ff76f9754e9ea1349e44543a28985dc839 --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,61 @@ +{ + "app": { + "bundleName": "com.dalimao.floateutil", + "vendor": "dalimao", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "reqPermissions": [ + { + "name": "ohos.permission.SYSTEM_FLOAT_WINDOW" + } + ], + "package": "com.dalimao.floateutil", + "name": ".MyApplication", + "mainAbility": "com.dalimao.floateutil.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "portrait", + "name": "com.dalimao.floateutil.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "metaData":{ + "customizeData":[ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.NoTitleBar", + "extra":"" + } + ] + } + + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/dalimao/floateutil/FloatBallView.java b/entry/src/main/java/com/dalimao/floateutil/FloatBallView.java new file mode 100644 index 0000000000000000000000000000000000000000..f430ac0be66823a782b96bf229c34cc99b4e5282 --- /dev/null +++ b/entry/src/main/java/com/dalimao/floateutil/FloatBallView.java @@ -0,0 +1,30 @@ +package com.dalimao.floateutil; + +import ohos.agp.components.Component; +import ohos.agp.components.Image; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.StackLayout; +import ohos.app.Context; + +/** + * FloatBallView + * + * @since 2021-07-01 + */ +public class FloatBallView extends StackLayout { + private static final float RADIUSNUM = 100f; + + /** + * FloatBallView + * + * @param context + */ + public FloatBallView(Context context) { + super(context); + Component rootView = LayoutScatter.getInstance(context). + parse(ResourceTable.Layout_float_small_drag_ball, + this, true); + Image imageView = (Image) rootView.findComponentById(ResourceTable.Id_imageView); + imageView.setCornerRadius(RADIUSNUM); + } +} diff --git a/entry/src/main/java/com/dalimao/floateutil/MainAbility.java b/entry/src/main/java/com/dalimao/floateutil/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..f6a548bbb6bccb454f63bc9118d167ee502c8fe5 --- /dev/null +++ b/entry/src/main/java/com/dalimao/floateutil/MainAbility.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dalimao.floateutil; + +import com.dalimao.floateutil.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.utils.PacMap; + +/** + * MyApplication + * + * @since 2021-06-29 + */ +public class MainAbility extends Ability { + /** + * onStart + * + * @param intent + */ + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } + + @Override + public void onSaveAbilityState(PacMap outState) { + super.onSaveAbilityState(outState); + } + + @Override + protected void onActive() { + super.onActive(); + } +} diff --git a/entry/src/main/java/com/dalimao/floateutil/MyApplication.java b/entry/src/main/java/com/dalimao/floateutil/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..da2cdd7bb162508d5525979049b40bd1d9fdf02a --- /dev/null +++ b/entry/src/main/java/com/dalimao/floateutil/MyApplication.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dalimao.floateutil; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + * + * @since 2021-06-29 + */ +public class MyApplication extends AbilityPackage { + /** + * onInitialize + */ + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/entry/src/main/java/com/dalimao/floateutil/SimpleView.java b/entry/src/main/java/com/dalimao/floateutil/SimpleView.java new file mode 100644 index 0000000000000000000000000000000000000000..43f1d58d5ca2ba30f52ebd7be5b661636d60ec13 --- /dev/null +++ b/entry/src/main/java/com/dalimao/floateutil/SimpleView.java @@ -0,0 +1,23 @@ +package com.dalimao.floateutil; + +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.StackLayout; +import ohos.app.Context; + +/** + * SimpleView + * + * @since 2021-06-28 + */ +public class SimpleView extends StackLayout { + /** + * SimpleView + * + * @param context + */ + public SimpleView(Context context) { + super(context); + LayoutScatter.getInstance(context).parse(ResourceTable.Layout_float_simple, + this, true); + } +} diff --git a/entry/src/main/java/com/dalimao/floateutil/SimpleViewWitchParam.java b/entry/src/main/java/com/dalimao/floateutil/SimpleViewWitchParam.java new file mode 100644 index 0000000000000000000000000000000000000000..1c315a0fe07a3b9c0c5148d0e2e50475f69bfb3c --- /dev/null +++ b/entry/src/main/java/com/dalimao/floateutil/SimpleViewWitchParam.java @@ -0,0 +1,53 @@ +package com.dalimao.floateutil; + +import ohos.aafwk.content.IntentParams; +import ohos.agp.components.Component; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.StackLayout; +import ohos.agp.components.Text; +import ohos.app.Context; + +/** + * SimpleViewWitchParam + * + * @since 2021-06-29 + */ +public class SimpleViewWitchParam extends StackLayout { + /** + * PARAM + */ + public static final String PARAM = "PARAM"; + /** + * CONTENT + */ + public static final String CONTENT = "content"; + Component rootView; + + /** + * SimpleViewWitchParam + * + * @param context + */ + public SimpleViewWitchParam(Context context) { + super(context); + rootView = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_float_simple_witch_param, this, true); + } + + /** + * onParamReceive + * + * @param args + */ + public void onParamReceive(IntentParams args) { + if (args != null) { + String param = (String) args.getParam(PARAM); + Text textView = (Text) rootView.findComponentById(ResourceTable.Id_tv_param); + textView.setText(param); + String content = (String) args.getParam(CONTENT); + if (content != null && content.length() > 0) { + Text tvContent = (Text) rootView.findComponentById(ResourceTable.Id_tv_content); + tvContent.setText(content); + } + } + } +} diff --git a/entry/src/main/java/com/dalimao/floateutil/slice/MainAbilitySlice.java b/entry/src/main/java/com/dalimao/floateutil/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..d214884d135700bd1e5b25e3eead4c3b06d6429f --- /dev/null +++ b/entry/src/main/java/com/dalimao/floateutil/slice/MainAbilitySlice.java @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dalimao.floateutil.slice; + +import com.dalimao.library.FloatUtil; +import com.dalimao.floateutil.ResourceTable; +import com.dalimao.floateutil.SimpleView; +import com.dalimao.floateutil.FloatBallView; +import com.dalimao.floateutil.SimpleViewWitchParam; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.IntentParams; +import ohos.agp.components.Button; +import ohos.agp.components.Component; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.utils.Point; +import ohos.sysappcomponents.settings.AppSettings; +import ohos.utils.net.Uri; + +/** + * SimpleViewWitchParam + * + * @since 2021-06-29 + */ +public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener { + private static final int FLOATBALLVIEWSIZE = 45; + private static final int POINTX = 100; + private static final int POINTY = 300; + private static final int REQUESTCODE = 1000; + private static final String PARAMVALUE = "我是传过来的参数"; + Button mAddSimpleView; + Button mAddSimpleViewWithParam; + Button mAddSimpleViewWithGravity; + Button mAddSimpleViewWithType; + Button mAddSimpleViewWithPoint; + Button mAddSimpleSmartFloatView; + Button mAddDragView; + IntentParams params; + SimpleViewWitchParam smartFloatView; + Point point; + FloatUtil builder; + + /** + * onStart + * + * @param intent + */ + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + mAddSimpleView = (Button) findComponentById(ResourceTable.Id_addSimpleView); + mAddSimpleViewWithParam = (Button) findComponentById(ResourceTable.Id_addSimpleViewWithParam); + mAddSimpleViewWithGravity = (Button) findComponentById(ResourceTable.Id_addSimpleViewWithGravity); + mAddSimpleViewWithType = (Button) findComponentById(ResourceTable.Id_addSimpleViewWithType); + mAddSimpleViewWithPoint = (Button) findComponentById(ResourceTable.Id_addSimpleViewWithPoint); + mAddSimpleSmartFloatView = (Button) findComponentById(ResourceTable.Id_addSimpleSmartFloatView); + mAddDragView = (Button) findComponentById(ResourceTable.Id_addDragView); + mAddSimpleView.setClickedListener(this); + mAddSimpleViewWithParam.setClickedListener(this); + mAddSimpleViewWithGravity.setClickedListener(this); + mAddSimpleViewWithType.setClickedListener(this); + mAddSimpleViewWithPoint.setClickedListener(this); + mAddSimpleSmartFloatView.setClickedListener(this); + mAddDragView.setClickedListener(this); + } + + /** + * onActive + */ + @Override + public void onActive() { + super.onActive(); + } + + /** + * onForeground + * + * @param intent + */ + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } + + /** + * onClick + * + * @param component + */ + @Override + public void onClick(Component component) { + params = new IntentParams(); + smartFloatView = new SimpleViewWitchParam(this); + point = new Point(); + boolean isAuthority = AppSettings.canShowFloating(this); + if (!isAuthority) { + Intent intent = new Intent(); + intent.setAction("android.settings.action.MANAGE_OVERLAY_PERMISSION"); + Uri parse = Uri.parse("package:" + getBundleName()); + intent.setUri(parse); + startAbilityForResult(intent, REQUESTCODE); + return; + } + switch (component.getId()) { + case ResourceTable.Id_addSimpleView: + setIdAddSimpleView(); + break; + + case ResourceTable.Id_addSimpleViewWithParam: + setIdAddSimpleViewWithParam(); + break; + + case ResourceTable.Id_addSimpleViewWithGravity: + setIdAddSimpleViewWithGravity(); + break; + + case ResourceTable.Id_addSimpleViewWithType: + setIdAddSimpleViewWithType(); + break; + + case ResourceTable.Id_addSimpleViewWithPoint: + setIdAddSimpleViewWithPoint(); + break; + + case ResourceTable.Id_addSimpleSmartFloatView: + setIdAddSimpleSmartFloatView(); + break; + + case ResourceTable.Id_addDragView: + setIdAddDragView(); + break; + default: + break; + } + } + + private void setIdAddSimpleView() { + SimpleView floatView = new SimpleView(this); + + builder = new FloatUtil.Builder() + .setComponent(floatView) + .showFloatView(this); + floatView.findComponentById(ResourceTable.Id_close) + .setClickedListener(view -> { + builder.hideFloatView(floatView); + }); + } + + private void setIdAddSimpleViewWithParam() { + params.setParam(SimpleViewWitchParam.PARAM, PARAMVALUE); + smartFloatView.onParamReceive(params); + builder = new FloatUtil.Builder() + .setComponent(smartFloatView) + .showFloatView(this); + smartFloatView.findComponentById(ResourceTable.Id_close) + .setClickedListener(view -> { + builder.hideFloatView(smartFloatView); + }); + } + + private void setIdAddSimpleViewWithGravity() { + params.setParam(SimpleViewWitchParam.PARAM, PARAMVALUE); + params.setParam(SimpleViewWitchParam.CONTENT, getString(ResourceTable.String_add_simple_view_with_gravity)); + smartFloatView.onParamReceive(params); + builder = new FloatUtil.Builder() + .setComponent(smartFloatView) + .setGravity(LayoutAlignment.CENTER) + .showFloatView(this); + smartFloatView.findComponentById(ResourceTable.Id_close) + .setClickedListener(view -> { + builder.hideFloatView(smartFloatView); + }); + } + + private void setIdAddSimpleViewWithType() { + params.setParam(SimpleViewWitchParam.PARAM, PARAMVALUE); + params.setParam(SimpleViewWitchParam.CONTENT, getString(ResourceTable.String_add_simple_view_with_type)); + smartFloatView.onParamReceive(params); + builder = new FloatUtil.Builder() + .setComponent(smartFloatView) + .setGravity(LayoutAlignment.CENTER) + .showFloatView(this); + smartFloatView.findComponentById(ResourceTable.Id_close) + .setClickedListener(view -> { + builder.hideFloatView(smartFloatView); + }); + } + + private void setIdAddSimpleViewWithPoint() { + params.setParam(SimpleViewWitchParam.PARAM, PARAMVALUE); + params.setParam(SimpleViewWitchParam.CONTENT, getString(ResourceTable.String_add_simple_view_with_point)); + point = new Point(POINTX, POINTY); + + smartFloatView.onParamReceive(params); + builder = new FloatUtil.Builder() + .setComponent(smartFloatView) + .setGravity(LayoutAlignment.TOP) + .point(point) + .showFloatView(this); + smartFloatView.findComponentById(ResourceTable.Id_close) + .setClickedListener(view -> { + builder.hideFloatView(smartFloatView); + }); + } + + private void setIdAddSimpleSmartFloatView() { + params.setParam(SimpleViewWitchParam.PARAM, "智能浮窗"); + params.setParam(SimpleViewWitchParam.CONTENT, getString(ResourceTable.String_add_simple_view_with_smart)); + smartFloatView.onParamReceive(params); + + builder = new FloatUtil.Builder() + .setComponent(smartFloatView) + .setGravity(LayoutAlignment.CENTER) + .point(point) + .showFloatView(this); + smartFloatView.findComponentById(ResourceTable.Id_close) + .setClickedListener(view -> { + builder.hideFloatView(smartFloatView); + }); + } + + private void setIdAddDragView() { + SimpleViewWitchParam simpleView = new SimpleViewWitchParam(this); + FloatBallView floatBallView = new FloatBallView(this); + + new FloatUtil.Builder() + .setComponent(floatBallView) + .setWidth(FLOATBALLVIEWSIZE) + .setHeight(FLOATBALLVIEWSIZE) + .setIsMovable(false) + .showFloatView(this); + builder = new FloatUtil.Builder() + .setComponent(simpleView) + .setIsMovable(true) + .showFloatView(this); + + simpleView.findComponentById(ResourceTable.Id_close) + .setClickedListener(view -> { + builder.hideFloatView(simpleView); + }); + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..baa5cfcfb2c0a9b0886a5584366e36b41a72ace8 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,56 @@ +{ + "string": [ + { + "name": "app_name", + "value": "FloateUtil" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + }, + { + "name": "add_simple_view", + "value": "显示一个简单的浮窗,默认使用 TYPE_PHONE 类型浮窗,showFloatView(View view, null)。" + }, + { + "name": "btn_show", + "value": "显示" + }, + { + "name": "add_simple_view_with_param", + "value": "显示一个简单的浮窗,默认使用 TYPE_PHONE 类型浮窗,传递一个 Bundle 参数 ,showFloatView(View view,Bundle bundle)。" + }, + { + "name": "add_simple_view_with_gravity", + "value": "显示一个简单的浮窗,默认使用 TYPE_PHONE 类型浮窗,传递一个 Bundle 参数 ,指定对齐方式为居中对齐,FloatUtil.showFloatView(floatView, Gravity.CENTER, bundle);。" + }, + { + "name": "add_simple_view_with_type", + "value": "显示一个简单的浮窗,默认使用 TYPE_PHONE 类型浮窗,传递一个 Bundle 参数 ,指定对齐方式为居中对齐,指定浮窗层级为 WindowManager.LayoutParams.TYPE_TOAST,\n FloatUtil.showFloatView(floatView, Gravity.CENTER, WindowManager.LayoutParams.TYPE_PHONE, bundle);。" + }, + { + "name": "add_simple_view_with_point", + "value": "显示一个简单的浮窗,默认使用 TYPE_PHONE 类型浮窗,传递一个 Bundle 参数 ,指定对齐方式为居中对齐,指定浮窗层级为 WindowManager.LayoutParams.TYPE_TOAST,指定坐标 point(x,y) FloatUtil.showFloatView(floatView, Gravity.CENTER, WindowManager.LayoutParams.TYPE_TOAST, point, bundle);。" + }, + { + "name": "add_simple_view_with_smart", + "value": "添加智能浮窗,智能的意思是自动根据当前系统版本和机型选择何时的 type ,绕过系统权限限制使用浮窗" + }, + { + "name": "add_simple_view_with_drag", + "value": "添加一个可拖动的浮窗,拖动的方法在自定义的 View 中实现" + }, + { + "name": "title", + "value": "标题" + }, + { + "name": "param", + "value": "参数:" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_main.xml b/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_btn.xml b/entry/src/main/resources/base/graphic/background_btn.xml new file mode 100644 index 0000000000000000000000000000000000000000..f13bd4b0381bf289b7b77e7f030e3781d3d19dc7 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_btn.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/shape1.xml b/entry/src/main/resources/base/graphic/shape1.xml new file mode 100644 index 0000000000000000000000000000000000000000..23700217ea88646d67a6fae4dd4f0be81e795a84 --- /dev/null +++ b/entry/src/main/resources/base/graphic/shape1.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..c12ba9646aa8c98439df2fbb7f7785dd120bc0bf --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,199 @@ + + + + + + + + +