diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index a5527f2e9441906bb75dd8e0f5ba1459dbc482e8..0000000000000000000000000000000000000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,8 +0,0 @@ -# These are supported funding model platforms - -github: [UFreedom] -patreon: UFreedom -open_collective: Replace with a single Open Collective username -ko_fi: UFreedom -tidelift: UFreedom -custom: https://qr.alipay.com/paipai/personal.htm diff --git a/.gitignore b/.gitignore index 830ec381f85c773264a89148f18a8f97fd5dbcee..603b14077394cd2294ac6922fe619669630ef3ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,14 @@ *.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 -/upload_bintray.properties - +.cxx diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6dc0cf0066cecac7276fa74bd965bab6bdea7126..0000000000000000000000000000000000000000 --- a/.travis.yml +++ /dev/null @@ -1,49 +0,0 @@ -language: android -jdk: oraclejdk8 - -sudo: false - -android: - components: - # Uncomment the lines below if you want to - # use the latest revision of Android SDK Tools - # - platform-tools - - tools - - # The BuildTools version used by your project - - build-tools-24.0.0 - - # The SDK version used to compile your project - - android-24 - - # Additional components - - extra-google-google_play_services - - extra-google-m2repository - - extra-android-m2repository - # - addon-google_apis-google-19 - # - add-on - # - extra - - # Specify at least one system image, - # if you need to run emulator(s) during your tests - - sys-img-armeabi-v7a-android-21 - # - sys-img-x86-android-17 - - licenses: - - 'android-sdk-license-.+' - -env: - global: - # install timeout in minutes (2 minutes by default) - - ADB_INSTALL_TIMEOUT=8 - -# Emulator Management: Create, Start and Wait -before_script: - - echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a - - emulator -avd test -no-skin -no-audio -no-window & - - android-wait-for-emulator - - adb shell input keyevent 82 & - -script: - - android list target - - ./gradlew connectedAndroidTest \ No newline at end of file diff --git a/FloatingViewLib/bintrayUpload.gradle b/FloatingViewLib/bintrayUpload.gradle deleted file mode 100644 index 0e2303383f6ae1ddd217ccb3c2f50a1bd93133a8..0000000000000000000000000000000000000000 --- a/FloatingViewLib/bintrayUpload.gradle +++ /dev/null @@ -1,72 +0,0 @@ -apply plugin: 'com.github.dcendents.android-maven' -apply plugin: 'com.jfrog.bintray' - -def siteUrl = 'https://github.com/UFreedom/FloatingView' -def gitUrl = 'git@github.com:UFreedom/FloatingView.git' -group = "com.ufreedom.uikit" -version = "1.0.2" - - -install { - repositories.mavenInstaller { - - pom { - project { - packaging 'aar' - - name 'FloatingView can floating some view above anothor view with animation' - url siteUrl - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } - developers { - developer { - id 'FloatingViewLibrary' - name 'UFreedom' - email 'sunfreedomsun@gmail.com' - } - } - scm { - connection gitUrl - developerConnection gitUrl - url siteUrl - } - } - } - } -} - -task sourcesJar(type: Jar) { - from android.sourceSets.main.java.srcDirs - classifier = 'sources' -} -task javadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) -} -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} -artifacts { - archives javadocJar - archives sourcesJar -} -Properties properties = new Properties() -properties.load(project.rootProject.file('upload_bintray.properties').newDataInputStream()) -bintray { - user = properties.getProperty("bintray.user") - key = properties.getProperty("bintray.apikey") - configurations = ['archives'] - pkg { - repo = "maven" - name = "FloatingViewLibrary" - websiteUrl = siteUrl - vcsUrl = gitUrl - licenses = ["Apache-2.0"] - publish = true - } -} diff --git a/FloatingViewLib/build.gradle b/FloatingViewLib/build.gradle index b23c2bde1dfce076160d9d4628c7b0113667e8a3..2c09909f309bc5a09d180d6bc6e19359d06d5985 100644 --- a/FloatingViewLib/build.gradle +++ b/FloatingViewLib/build.gradle @@ -1,35 +1,37 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 24 - buildToolsVersion "24.0.0" +/* + * Copyright (C) 2021 The Chinese Software International 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 an 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. + */ +apply plugin: 'com.huawei.ohos.library' +ohos { + compileSdkVersion 5 defaultConfig { - minSdkVersion 14 - targetSdkVersion 24 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - + compatibleSdkVersion 5 } buildTypes { release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } } } + } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - compile 'com.android.support:appcompat-v7:24.2.1' + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.13' compile 'com.facebook.rebound:rebound:0.3.8' - testCompile 'junit:junit:4.12' } - -//apply from: "bintrayUpload.gradle" - diff --git a/FloatingViewLib/proguard-rules.pro b/FloatingViewLib/proguard-rules.pro index ff11ede7761c2d3d8e001ee02fdd3e0f3b45da78..f7666e47561d514b2a76d5a7dfbb43ede86da92a 100644 --- a/FloatingViewLib/proguard-rules.pro +++ b/FloatingViewLib/proguard-rules.pro @@ -1,17 +1 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/yummy/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/FloatingViewLib/src/androidTest/java/com/ufreedom/floatingview/ExampleInstrumentedTest.java b/FloatingViewLib/src/androidTest/java/com/ufreedom/floatingview/ExampleInstrumentedTest.java deleted file mode 100644 index ee18128b520e7d3174908d98ff45f2a901dd199f..0000000000000000000000000000000000000000 --- a/FloatingViewLib/src/androidTest/java/com/ufreedom/floatingview/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.ufreedom.floatingview; - -import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumentation test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() throws Exception { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("com.ufreedom.floatingview.test", appContext.getPackageName()); - } -} diff --git a/FloatingViewLib/src/main/AndroidManifest.xml b/FloatingViewLib/src/main/AndroidManifest.xml deleted file mode 100644 index 0b8b260db79b7c5fe7ff7e5e2cb09c6067a2f3f6..0000000000000000000000000000000000000000 --- a/FloatingViewLib/src/main/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - diff --git a/FloatingViewLib/src/main/config.json b/FloatingViewLib/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..037131941f509e5a2ed5858a6af4284f9735d0f0 --- /dev/null +++ b/FloatingViewLib/src/main/config.json @@ -0,0 +1,28 @@ +{ + "app": { + "bundleName": "com.ufreedom.demo", + "vendor": "ufreedom", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": { + }, + "module": { + "package": "com.ufreedom.floatingview", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "FloatingViewLib", + "moduleType": "har" + } + } +} \ No newline at end of file diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/Floating.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/Floating.java index ade15ec001bd26441f911151f970c0b02171dd89..0eb6406e7b0987c5f7a4b1657bf261d2d0cec350 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/Floating.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/Floating.java @@ -14,117 +14,141 @@ * limitations under the License. */ - package com.ufreedom.floatingview; -import android.app.Activity; -import android.content.Context; -import android.graphics.Rect; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.widget.FrameLayout; - import com.facebook.rebound.SpringSystem; import com.ufreedom.floatingview.transition.FloatingTransition; import com.ufreedom.floatingview.transition.YumFloating; - +import com.ufreedom.floatingview.util.LogUtil; +import ohos.aafwk.ability.AbilitySlice; +import ohos.agp.components.AttrSet; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.StackLayout; +import ohos.agp.utils.Rect; +import ohos.app.Context; /** - * Author UFreedom - * Date : 2016 十月 17 + * Floating + * + * @author xujianhong + * @since 2021-04-23 */ - public class Floating { - - - private FloatingDecorView mFloatingDecorView; + private StackLayout mFloatingDecorView; private SpringSystem mSpringSystem; - - public Floating(Activity activity){ + private AbilitySlice activity; - if (activity == null){ + /** + * Floating + * + * @param activity + * @param topComponent 传递顶层View + * @throws NullPointerException Activity should not be null + */ + public Floating(AbilitySlice activity, Component topComponent) { + this.activity = activity; + if (activity == null) { throw new NullPointerException("Activity should not be null"); } - - ViewGroup rootView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); - View decorView = rootView.findViewById(R.id.floating_decor); - if (decorView instanceof FloatingDecorView){ - mFloatingDecorView = (FloatingDecorView) decorView; - }else { - mFloatingDecorView = new FloatingDecorView(activity); - mFloatingDecorView.setId(R.id.floating_decor); - rootView.addView(mFloatingDecorView); - } - - if (mSpringSystem == null){ + mFloatingDecorView = new FloatingDecorView(activity); + + mFloatingDecorView.setLayoutConfig(new StackLayout.LayoutConfig(StackLayout.LayoutConfig.MATCH_PARENT, + StackLayout.LayoutConfig.MATCH_PARENT)); + + activity.setUIContent(ResourceTable.Layout_floating_fecor_view); + ComponentContainer rootView = (ComponentContainer) activity.findComponentById(ResourceTable.Id_root_view); + rootView.addComponent(topComponent); + rootView.addComponent(mFloatingDecorView); + if (mSpringSystem == null) { mSpringSystem = SpringSystem.create(); } - } - - - /*public void detach() { - - if (mFloatingDecorView == null) return; - - mFloatingDecorView.removeAllViews(); - ViewGroup rootView = (ViewGroup) mActivity.findViewById(Window.ID_ANDROID_CONTENT); - rootView.removeView(mFloatingDecorView); - mFloatingDecorView = null; - mActivity = null; - }*/ - - public void startFloating(FloatingElement floatingElement) { - - View anchorView = floatingElement.anchorView; - View targetView = floatingElement.targetView; - - if (targetView == null){ - targetView = LayoutInflater.from(anchorView.getContext()).inflate(floatingElement.targetViewLayoutResId,mFloatingDecorView,false); + + /** + * startFloating + * + * @param floatingElement + * @return Component + */ + public Component startFloating(FloatingElement floatingElement) { + + // 原始图 + Component anchorView = floatingElement.anchorView; + + // 悬浮的视图 + Component targetView = floatingElement.targetView; + if (targetView == null) { + targetView = LayoutScatter.getInstance(anchorView.getContext()).parse( + floatingElement.targetViewLayoutResId, mFloatingDecorView, false); } - - Rect rect = new Rect(); - anchorView.getGlobalVisibleRect(rect); - int[] location = new int[2]; - mFloatingDecorView.getLocationOnScreen(location); - rect.offset(-location[0], -location[1]); - - int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec((1 << 30) - 1, View.MeasureSpec.AT_MOST); - int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec((1 << 30) - 1, View.MeasureSpec.AT_MOST); - targetView.measure(widthMeasureSpec,heightMeasureSpec); - - int topMargin = rect.top + ((anchorView.getMeasuredHeight() - targetView.getMeasuredHeight()) / 2) + floatingElement.offsetY; - int leftMargin = rect.left + ((anchorView.getMeasuredWidth() - targetView.getMeasuredWidth()) / 2) + floatingElement.offsetX; - - FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - lp.topMargin = topMargin; - lp.leftMargin = leftMargin; - mFloatingDecorView.addView(targetView,lp); - + + Rect rect = anchorView.getComponentPosition(); + int[] location = anchorView.getLocationOnScreen(); + + rect.left = location[0]; + rect.top = location[1]; + + int widthMeasureSpec = Component.EstimateSpec.getSizeWithMode(targetView.getWidth(), Component.EstimateSpec.NOT_EXCEED); + int heightMeasureSpec = Component.EstimateSpec.getSizeWithMode(targetView.getHeight(), Component.EstimateSpec.NOT_EXCEED); + targetView.estimateSize(widthMeasureSpec, heightMeasureSpec); + + int topMargin = rect.top + ((anchorView.getHeight() - targetView.getHeight()) / 2) + floatingElement.offsetY; + int leftMargin = rect.left + ((anchorView.getWidth() - targetView.getWidth()) / 2) + floatingElement.offsetX; + + StackLayout.LayoutConfig lp = new StackLayout.LayoutConfig(StackLayout.LayoutConfig.MATCH_CONTENT, + StackLayout.LayoutConfig.MATCH_CONTENT); + + + // 减去的状态栏高度 + int titleHeight = mFloatingDecorView.getLocationOnScreen()[1]; + lp.setMarginTop(topMargin <= 0 ? 0 : topMargin - titleHeight); + lp.setMarginLeft(leftMargin); + LogUtil.error("startFloating topMargin", topMargin + " leftMargin" + leftMargin); + mFloatingDecorView.addComponent(targetView, lp); FloatingTransition floatingAnimator = floatingElement.floatingTransition; floatingAnimator.applyFloating(new YumFloating(targetView, mSpringSystem)); - + return mFloatingDecorView; } - - - - private class FloatingDecorView extends FrameLayout{ - + + /** + * FloatingDecorView + * + * @since 2021-04-23 + */ + public class FloatingDecorView extends StackLayout { + + /** + * FloatingDecorView + * + * @param context + */ public FloatingDecorView(Context context) { this(context, null); } - public FloatingDecorView(Context context, AttributeSet attrs) { - this(context, attrs, 0); + /** + * FloatingDecorView + * + * @param context + * @param attrs + */ + public FloatingDecorView(Context context, AttrSet attrs) { + this(context, attrs, null); } - public FloatingDecorView(Context context, AttributeSet attrs, int defStyle) { + /** + * FloatingDecorView + * + * @param context + * @param attrs + * @param defStyle + */ + public FloatingDecorView(Context context, AttrSet attrs, String defStyle) { super(context, attrs, defStyle); - } } - + } + diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingBuilder.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingBuilder.java index d84fd8d09cef8d3eabb27dfa74febb2d67aa8fa1..405922a5608c56882d028edef9d487f922ab3c5c 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingBuilder.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingBuilder.java @@ -14,71 +14,108 @@ * limitations under the License. */ - package com.ufreedom.floatingview; -import android.support.annotation.LayoutRes; -import android.view.View; - import com.ufreedom.floatingview.effect.ScaleFloatingTransition; import com.ufreedom.floatingview.transition.FloatingTransition; - +import ohos.agp.components.Component; /** - * - * Helped class for building {@link FloatingElement} - * - * Author UFreedom - * Date : 2016 十月 19 + * FloatingBuilder + * + * @author xujianhong + * @since 2021-04-23 */ public class FloatingBuilder { - private FloatingElement mFloatingElement; + /** + * FloatingBuilder + */ public FloatingBuilder() { mFloatingElement = new FloatingElement(); mFloatingElement.targetViewLayoutResId = -1; } - + + /** + * offsetX + * + * @param offsetX + * @return FloatingBuilder + */ public FloatingBuilder offsetX(int offsetX) { mFloatingElement.offsetX = offsetX; return this; } - + + /** + * offsetY + * + * @param offsetY + * @return FloatingBuilder + */ public FloatingBuilder offsetY(int offsetY) { mFloatingElement.offsetY = offsetY; return this; } - + /** + * floatingTransition + * + * @param floatingTransition + * @return FloatingBuilder + */ public FloatingBuilder floatingTransition(FloatingTransition floatingTransition) { mFloatingElement.floatingTransition = floatingTransition; - return this; + return this; } - - - public FloatingBuilder anchorView(View view){ + + /** + * anchorView + * + * @param view + * @return FloatingBuilder + */ + public FloatingBuilder anchorView(Component view) { mFloatingElement.anchorView = view; return this; } - - public FloatingBuilder targetView(View view) { + + /** + * targetView + * + * @param view + * @return FloatingBuilder + */ + public FloatingBuilder targetView(Component view) { mFloatingElement.targetView = view; return this; } - public FloatingBuilder targetView(@LayoutRes int layResId) { + /** + * targetView + * + * @param layResId + * @return FloatingBuilder + */ + public FloatingBuilder targetView(int layResId) { mFloatingElement.targetViewLayoutResId = layResId; return this; - } + } + /** + * build + * + * @return FloatingElement + * @throws NullPointerException TargetView should not be null + */ public FloatingElement build() { if (mFloatingElement.targetView == null && mFloatingElement.targetViewLayoutResId == -1) { throw new NullPointerException("TargetView should not be null"); } - - if (mFloatingElement.anchorView == null){ + + if (mFloatingElement.anchorView == null) { throw new NullPointerException("AnchorView should not be null"); } @@ -89,3 +126,4 @@ public class FloatingBuilder { } } + diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingElement.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingElement.java index 542fb0cee0f20200f5168b1850ea4d8db72414be..f74d7df4df509c4e0243cdf8e091e2e26d3fbae2 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingElement.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingElement.java @@ -14,25 +14,16 @@ * limitations under the License. */ - package com.ufreedom.floatingview; -import android.view.View; - import com.ufreedom.floatingview.transition.FloatingTransition; +import ohos.agp.components.Component; /** - * - * Data structure for a floating element. - * - * - * Author UFreedom - * Date : 2016 十月 19 + * @author xujianhong + * @since 2021-03-31 */ - public class FloatingElement { - - /** * Floating effect, the default is ScaleFloatingTransition */ @@ -53,7 +44,7 @@ public class FloatingElement { /** * The view which you want to float */ - public View targetView; + public Component targetView; /** @@ -64,8 +55,7 @@ public class FloatingElement { /** * The view that you want to float above */ - public View anchorView; - - + public Component anchorView; } + diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/CurveFloatingPathTransition.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/CurveFloatingPathTransition.java index 218cafe38b2d2dc8dfd6a5b49bf52ff960c8f4cd..3529a8280143a21bbf94b17295e8dbb93081a624 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/CurveFloatingPathTransition.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/CurveFloatingPathTransition.java @@ -14,42 +14,51 @@ * limitations under the License. */ - package com.ufreedom.floatingview.effect; -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; -import android.graphics.Path; - -import com.ufreedom.floatingview.transition.YumFloating; +import com.ufreedom.floatingview.spring.SimpleReboundListener; +import com.ufreedom.floatingview.spring.SpringHelper; import com.ufreedom.floatingview.transition.BaseFloatingPathTransition; import com.ufreedom.floatingview.transition.FloatingPath; import com.ufreedom.floatingview.transition.PathPosition; -import com.ufreedom.floatingview.spring.SpringHelper; -import com.ufreedom.floatingview.spring.SimpleReboundListener; +import com.ufreedom.floatingview.transition.YumFloating; +import ohos.agp.animation.Animator; +import ohos.agp.animation.AnimatorValue; +import ohos.agp.render.Path; /** - * Author UFreedom - * Date : 2016 十月 20 + * CurveFloatingPathTransition + * + * @author xujianhong + * @since 2021-03-31 */ - public class CurveFloatingPathTransition extends BaseFloatingPathTransition { private Path mPath; + /** + * CurveFloatingPathTransition + */ public CurveFloatingPathTransition() { - } + /** + * CurveFloatingPathTransition + * + * @param path + */ public CurveFloatingPathTransition(Path path) { this.mPath = path; } + /** + * getFloatingPath + * + * @return FloatingPath + */ @Override public FloatingPath getFloatingPath() { - if (mPath == null){ + if (mPath == null) { mPath = new Path(); mPath.moveTo(0, 0); mPath.quadTo(-100, -200, 0, -300); @@ -58,56 +67,86 @@ public class CurveFloatingPathTransition extends BaseFloatingPathTransition { return FloatingPath.create(mPath, false); } + /** + * applyFloating + * + * @param yumFloating + */ @Override public void applyFloating(final YumFloating yumFloating) { - ValueAnimator translateAnimator; - ValueAnimator alphaAnimator; + AnimatorValue translateAnimator; + AnimatorValue alphaAnimator; - - translateAnimator = ObjectAnimator.ofFloat(getStartPathPosition(), getEndPathPosition()); - translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + // 需要指定算法 translateAnimator = ObjectAnimator.ofFloat(getStartPathPosition(), getEndPathPosition()); + translateAnimator = new AnimatorValue(); + translateAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - float value = (float) valueAnimator.getAnimatedValue(); - PathPosition floatingPosition = getFloatingPosition(value); + public void onUpdate(AnimatorValue animatorValue, float v) { + PathPosition floatingPosition = getFloatingPosition(v * getEndPathPosition()); yumFloating.setTranslationX(floatingPosition.x); yumFloating.setTranslationY(floatingPosition.y); - } }); - translateAnimator.addListener(new AnimatorListenerAdapter() { + + translateAnimator.setStateChangedListener(new Animator.StateChangedListener() { + @Override + public void onStart(Animator animator) { + + } + + @Override + public void onStop(Animator animator) { + + } + + @Override + public void onCancel(Animator animator) { + + } + @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); + public void onEnd(Animator animator) { yumFloating.setTranslationX(0); yumFloating.setTranslationY(0); yumFloating.setAlpha(0f); } - }); + @Override + public void onPause(Animator animator) { - alphaAnimator = ObjectAnimator.ofFloat(1.0f, 0f); + } + + @Override + public void onResume(Animator animator) { + + } + }); + + alphaAnimator = new AnimatorValue(); alphaAnimator.setDuration(3000); - alphaAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + + alphaAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - yumFloating.setAlpha((Float) valueAnimator.getAnimatedValue()); + public void onUpdate(AnimatorValue animatorValue, float v) { + yumFloating.setAlpha(1 - v); } }); - - SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f,11, 15) - .reboundListener(new SimpleReboundListener(){ + + SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f, 11, 15) + .reboundListener(new SimpleReboundListener() { @Override public void onReboundUpdate(double currentValue) { yumFloating.setScaleX((float) currentValue); yumFloating.setScaleY((float) currentValue); } - }).start(yumFloating); - + }).start(yumFloating); + translateAnimator.setDuration(3000); - translateAnimator.setStartDelay(50); + + // 延迟 + translateAnimator.setDelay(50); translateAnimator.start(); alphaAnimator.start(); } - + } diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/ScaleFloatingTransition.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/ScaleFloatingTransition.java index 1ad5259f91c63006e17a944f2198fd9b4e1c7569..2b5e9e5c573175b9c85143ec7b4fc521c291caa0 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/ScaleFloatingTransition.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/ScaleFloatingTransition.java @@ -14,62 +14,76 @@ * limitations under the License. */ - package com.ufreedom.floatingview.effect; -import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; - -import com.ufreedom.floatingview.transition.YumFloating; -import com.ufreedom.floatingview.transition.FloatingTransition; import com.ufreedom.floatingview.spring.SimpleReboundListener; import com.ufreedom.floatingview.spring.SpringHelper; - +import com.ufreedom.floatingview.transition.FloatingTransition; +import com.ufreedom.floatingview.transition.YumFloating; +import ohos.agp.animation.AnimatorValue; /** - * Author UFreedom - * Date : 2016 十月 19 + * ScaleFloatingTransition + * + * @author xujianhong + * @since 2021-03-31 */ - public class ScaleFloatingTransition implements FloatingTransition { - private long mDuration; private double mBounciness; private double mSpeed; + /** + * ScaleFloatingTransition + */ public ScaleFloatingTransition() { mDuration = 1000; mBounciness = 10; mSpeed = 15; } + /** + * ScaleFloatingTransition + * + * @param duration + */ public ScaleFloatingTransition(long duration) { this.mDuration = duration; mBounciness = 10; mSpeed = 15; } + /** + * ScaleFloatingTransition + * + * @param duration + * @param bounciness + * @param speed + */ public ScaleFloatingTransition(long duration, double bounciness, double speed) { this.mDuration = duration; this.mBounciness = bounciness; this.mSpeed = speed; } + /** + * applyFloating + * + * @param yumFloating + */ @Override public void applyFloating(final YumFloating yumFloating) { - - ValueAnimator alphaAnimator = ObjectAnimator.ofFloat(1.0f, 0.0f); + AnimatorValue alphaAnimator = new AnimatorValue(); alphaAnimator.setDuration(mDuration); - alphaAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + alphaAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - yumFloating.setAlpha((Float) valueAnimator.getAnimatedValue()); + public void onUpdate(AnimatorValue animatorValue, float v) { + yumFloating.setAlpha(1 - v); } }); alphaAnimator.start(); - SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f, mBounciness, mSpeed) - .reboundListener(new SimpleReboundListener(){ + .reboundListener(new SimpleReboundListener() { @Override public void onReboundUpdate(double currentValue) { yumFloating.setScaleX((float) currentValue); @@ -77,5 +91,6 @@ public class ScaleFloatingTransition implements FloatingTransition { } }).start(yumFloating); } - + } + diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/TranslateFloatingTransition.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/TranslateFloatingTransition.java index 5b299a5d662d3f57322a5d8160ece097c15a0b0e..b544eb5573ae6d595ca2814771f787ea37016e66 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/TranslateFloatingTransition.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/TranslateFloatingTransition.java @@ -14,83 +14,119 @@ * limitations under the License. */ - package com.ufreedom.floatingview.effect; -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; - -import com.ufreedom.floatingview.transition.YumFloating; -import com.ufreedom.floatingview.transition.FloatingTransition; import com.ufreedom.floatingview.spring.SimpleReboundListener; import com.ufreedom.floatingview.spring.SpringHelper; - +import com.ufreedom.floatingview.transition.FloatingTransition; +import com.ufreedom.floatingview.transition.YumFloating; +import ohos.agp.animation.Animator; +import ohos.agp.animation.AnimatorValue; /** - * Author UFreedom - * Date : 2016 十月 19 + * TranslateFloatingTransition + * + * @author xujianhong + * @since 2021-03-31 */ - public class TranslateFloatingTransition implements FloatingTransition { private float mTranslateY; private long mDuration; + /** + * TranslateFloatingTransition + */ public TranslateFloatingTransition() { mTranslateY = -200f; mDuration = 1500; } - + /** + * TranslateFloatingTransition + * + * @param translateY + * @param duration + */ public TranslateFloatingTransition(float translateY, long duration) { this.mTranslateY = translateY; this.mDuration = duration; } + /** + * applyFloating + * + * @param yumFloating + */ @Override public void applyFloating(final YumFloating yumFloating) { - - ValueAnimator translateAnimator = ObjectAnimator.ofFloat(0, mTranslateY); + AnimatorValue translateAnimator = new AnimatorValue(); translateAnimator.setDuration(mDuration); - translateAnimator.setStartDelay(50); - translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + + // 启动延迟 + translateAnimator.setDelay(50); + translateAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - yumFloating.setTranslationY((Float) valueAnimator.getAnimatedValue()); + public void onUpdate(AnimatorValue animatorValue, float v) { + yumFloating.setTranslationY(v * mTranslateY); } }); - translateAnimator.addListener(new AnimatorListenerAdapter() { + + translateAnimator.setStateChangedListener(new Animator.StateChangedListener() { @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); + public void onStart(Animator animator) { + + } + + @Override + public void onStop(Animator animator) { + + } + + @Override + public void onCancel(Animator animator) { + + } + + @Override + public void onEnd(Animator animator) { yumFloating.setTranslationY(0); yumFloating.setAlpha(0f); + } + + @Override + public void onPause(Animator animator) { + + } + + @Override + public void onResume(Animator animator) { } }); - - ValueAnimator alphaAnimator = ObjectAnimator.ofFloat(1.0f, 0.0f); + AnimatorValue alphaAnimator = new AnimatorValue(); + + // 持续时长 alphaAnimator.setDuration(mDuration); - alphaAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + alphaAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - yumFloating.setAlpha((Float) valueAnimator.getAnimatedValue()); + public void onUpdate(AnimatorValue animatorValue, float v) { + yumFloating.setAlpha(1 - v); } }); - - SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f,10, 15) - .reboundListener(new SimpleReboundListener(){ + + SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f, 10, 15) + .reboundListener(new SimpleReboundListener() { @Override public void onReboundUpdate(double currentValue) { yumFloating.setScaleX((float) currentValue); yumFloating.setScaleY((float) currentValue); } }).start(yumFloating); - + alphaAnimator.start(); translateAnimator.start(); } } + diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/ReboundListener.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/ReboundListener.java index 52a76ffede76a3c2b40739da28a6825f625d1356..0ca1a23da6048d9d6673c568510d859f8e43b5e7 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/ReboundListener.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/ReboundListener.java @@ -14,18 +14,24 @@ * limitations under the License. */ - package com.ufreedom.floatingview.spring; /** - * Author UFreedom - * Date : 2016 十月 20 + * ReboundListener + * + * @author xujianhong + * @since 2021-03-31 */ - public interface ReboundListener { - - public void onReboundUpdate(double currentValue); + /** + * onReboundUpdate + * + * @param currentValue + */ + void onReboundUpdate(double currentValue); - public void onReboundEnd(); - + /** + * onReboundEnd + */ + void onReboundEnd(); } diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/SimpleReboundListener.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/SimpleReboundListener.java index 7a39b0bcde79b0eb0750497c2dab37af343800ba..ebc65bdc4aabea30f3776c04da6ee165899c34d2 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/SimpleReboundListener.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/SimpleReboundListener.java @@ -14,21 +14,29 @@ * limitations under the License. */ - package com.ufreedom.floatingview.spring; /** - * Author UFreedom - * Date : 2016 十月 20 + * SimpleReboundListener + * + * @author xujianhong + * @since 2021-03-31 */ +public class SimpleReboundListener implements ReboundListener { -public class SimpleReboundListener implements ReboundListener{ - + /** + * onReboundUpdate + * + * @param currentValue + */ @Override public void onReboundUpdate(double currentValue) { - + } + /** + * onReboundEnd + */ @Override public void onReboundEnd() { diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/SpringHelper.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/SpringHelper.java index d89b3d994c3fdbebaf85a407b6eb0f3b162b1336..f257c9139379d8d6937ceae964029073a651a485 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/SpringHelper.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/SpringHelper.java @@ -1,22 +1,6 @@ -/* - * Copyright (C) 2015 UFreedom - * - * 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.ufreedom.floatingview.spring; + import com.facebook.rebound.SimpleSpringListener; import com.facebook.rebound.Spring; import com.facebook.rebound.SpringConfig; @@ -26,15 +10,13 @@ import com.facebook.rebound.SpringUtil; import com.ufreedom.floatingview.transition.YumFloating; /** - * - * A help class for using Facebook Rebound - * - * Author UFreedom - * Date : 2016 十月 20 + * SpringHelper + * + * @author xujianhong + * @since 2021-03-31 */ - public class SpringHelper { - + private float mStartValue; private float mEndValue; private double mConfigValueOne; @@ -43,103 +25,180 @@ public class SpringHelper { private ReboundListener mReboundListener; private SpringListener mSpringListener; + /** + * SpringHelper + * + * @param startValue + * @param endValue + */ private SpringHelper(float startValue, float endValue) { this.mStartValue = startValue; this.mEndValue = endValue; } - public static SpringHelper create(float startValue, float endValue){ - return new SpringHelper(startValue,endValue); + /** + * create + * + * @param startValue + * @param endValue + * @return SpringHelper + */ + public static SpringHelper create(float startValue, float endValue) { + return new SpringHelper(startValue, endValue); } - public static SpringHelper createWithBouncinessAndSpeed(float startValue, float endValue, double bounciness, double speed){ - SpringHelper springHelper = new SpringHelper(startValue,endValue); - return springHelper.configBouncinessAndSpeed(bounciness,speed); + /** + * createWithBouncinessAndSpeed + * + * @param startValue + * @param endValue + * @param bounciness + * @param speed + * @return SpringHelper + */ + public static SpringHelper createWithBouncinessAndSpeed(float startValue, float endValue, double bounciness, double speed) { + SpringHelper springHelper = new SpringHelper(startValue, endValue); + return springHelper.configBouncinessAndSpeed(bounciness, speed); } - public static SpringHelper createWithTensionAndFriction(float startValue, float endValue, double tension, double friction){ - SpringHelper springHelper = new SpringHelper(startValue,endValue); - return springHelper.configTensionAndFriction(tension,friction); + /** + * createWithTensionAndFriction + * + * @param startValue + * @param endValue + * @param tension + * @param friction + * @return SpringHelper + */ + public static SpringHelper createWithTensionAndFriction(float startValue, float endValue, double tension, double friction) { + SpringHelper springHelper = new SpringHelper(startValue, endValue); + return springHelper.configTensionAndFriction(tension, friction); } - - - public SpringHelper configBouncinessAndSpeed(double bounciness, double speed){ + + /** + * configBouncinessAndSpeed + * + * @param bounciness + * @param speed + * @return SpringHelper + */ + public SpringHelper configBouncinessAndSpeed(double bounciness, double speed) { mConfigValueOne = bounciness; mConfigValueTwo = speed; mConfig = 0; return this; } - - public SpringHelper configTensionAndFriction(double tension, double friction){ + + /** + * configTensionAndFriction + * + * @param tension + * @param friction + * @return SpringHelper + */ + public SpringHelper configTensionAndFriction(double tension, double friction) { mConfigValueOne = tension; mConfigValueTwo = friction; mConfig = 1; return this; } - - public SpringHelper reboundListener(ReboundListener reboundListener){ + + /** + * reboundListener + * + * @param reboundListener + * @return SpringHelper + */ + public SpringHelper reboundListener(ReboundListener reboundListener) { this.mReboundListener = reboundListener; return this; } - - public SpringHelper springListener(SpringListener springListener){ + + /** + * springListener + * + * @param springListener + * @return SpringHelper + */ + public SpringHelper springListener(SpringListener springListener) { this.mSpringListener = springListener; return this; } - - public void start(){ + + /** + * start + */ + public void start() { SpringSystem springSystem = SpringSystem.create(); - Spring spring = springSystem.createSpring(); - if (mConfig == 0){ + Spring spring = springSystem.createSpring(); + if (mConfig == 0) { spring.setSpringConfig(SpringConfig.fromBouncinessAndSpeed(mConfigValueOne, mConfigValueTwo)); - }else if (mConfig == 1){ + } else if (mConfig == 1) { spring.setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(mConfigValueOne, mConfigValueTwo)); } start(spring); } - - private void start(Spring spring){ - if (spring != null){ - if (mSpringListener != null){ + /** + * start + * + * @param spring + */ + private void start(Spring spring) { + if (spring != null) { + + if (mSpringListener != null) { spring.addListener(mSpringListener); } - - spring.addListener(new SimpleSpringListener(){ + + spring.addListener(new SimpleSpringListener() { @Override public void onSpringUpdate(Spring spring) { - if (spring.getCurrentValue() == spring.getEndValue()){ - if (mReboundListener != null){ + if (spring.getCurrentValue() == spring.getEndValue()) { + if (mReboundListener != null) { mReboundListener.onReboundEnd(); } } - if (mReboundListener != null){ + if (mReboundListener != null) { mReboundListener.onReboundUpdate(transition(spring.getCurrentValue(), mStartValue, mEndValue)); } } }).setEndValue(mEndValue); - }else { + } else { throw new NullPointerException("Spring should not be null"); } } - - - public void start(final YumFloating yumFloating){ - if (mConfig == -1){ + + /** + * start + * + * @param yumFloating + */ + public void start(final YumFloating yumFloating) { + if (mConfig == -1) { throw new IllegalStateException("Hi , You must call one of the method configBouncinessAndSpeed and configTensionAndFriction to make mConfig"); } - + Spring spring = null; - if (mConfig == 0){ + if (mConfig == 0) { spring = yumFloating.createSpringByBouncinessAndSpeed(mConfigValueOne, mConfigValueTwo); - }else if (mConfig == 1){ + } else if (mConfig == 1) { spring = yumFloating.createSpringByTensionAndFriction(mConfigValueOne, mConfigValueTwo); } start(spring); } + /** + * transition + * + * @param progress + * @param startValue + * @param endValue + * @return float + */ public float transition(double progress, float startValue, float endValue) { return (float) SpringUtil.mapValueFromRangeToRange(progress, 0, 1, startValue, endValue); } - + } + diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/BaseFloatingPathTransition.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/BaseFloatingPathTransition.java index 831df8a45fc1157ac80b8a36c515455d3d6a2dd4..0684413064281e66b3334968ff81cbfbe6558cbf 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/BaseFloatingPathTransition.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/BaseFloatingPathTransition.java @@ -14,45 +14,59 @@ * limitations under the License. */ - package com.ufreedom.floatingview.transition; /** - * Author UFreedom - * Date : 2016 十月 19 + * BaseFloatingPathTransition + * + * @author xujianhong + * @since 2021-03-31 */ - -public abstract class BaseFloatingPathTransition implements FloatingPathTransition { +public abstract class BaseFloatingPathTransition implements FloatingPathTransition { private PathPosition mPathPosition; - private float [] mPathPositionGetter; - - public float getStartPathPosition(){ + private float[] mPathPositionGetter; + + /** + * getStartPathPosition + * + * @return float + */ + public float getStartPathPosition() { return 0; } - - public float getEndPathPosition(){ - if (getFloatingPath() != null){ + + /** + * getEndPathPosition + * + * @return float + */ + public float getEndPathPosition() { + if (getFloatingPath() != null) { return getFloatingPath().getPathMeasure().getLength(); } return 0; } - + + /** + * getFloatingPosition + * + * @param progress + * @return PathPosition + */ public PathPosition getFloatingPosition(float progress) { - if (mPathPosition == null){ + if (mPathPosition == null) { mPathPosition = new PathPosition(); } - if (mPathPositionGetter == null){ + if (mPathPositionGetter == null) { mPathPositionGetter = new float[2]; } - if (getFloatingPath() != null){ - getFloatingPath() .getPathMeasure().getPosTan(progress, mPathPositionGetter, null); + if (getFloatingPath() != null) { + float[] tangent = new float[2]; + getFloatingPath().getPathMeasure().getPosTan(progress, mPathPositionGetter, tangent); mPathPosition.x = mPathPositionGetter[0]; mPathPosition.y = mPathPositionGetter[1]; } return mPathPosition; } - - - } diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingPath.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingPath.java index ad03502d490abb9bfedbff8cb0d04a178d3ffa90..01f43fa79aacd7f245edaa4df3b0c7cf5dfc6836 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingPath.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingPath.java @@ -14,39 +14,64 @@ * limitations under the License. */ - package com.ufreedom.floatingview.transition; -import android.graphics.Path; -import android.graphics.PathMeasure; +import ohos.agp.render.Path; +import ohos.agp.render.PathMeasure; /** - * Author UFreedom - * + * FloatingPath + * + * @author xujianhong + * @since 2021-03-31 */ public class FloatingPath { - private Path mPath; private PathMeasure mPathMeasure; + /** + * FloatingPath + */ protected FloatingPath() { this.mPath = new Path(); } - + + /** + * FloatingPath + * + * @param path + */ protected FloatingPath(Path path) { this.mPath = path; } + /** + * create + * + * @param path + * @param forceClose + * @return FloatingPath + */ public static FloatingPath create(Path path, boolean forceClose) { FloatingPath floatingPath = new FloatingPath(path); floatingPath.mPathMeasure = new PathMeasure(path, forceClose); return floatingPath; } + /** + * getPath + * + * @return Path + */ public Path getPath() { return mPath; } + /** + * getPathMeasure + * + * @return PathMeasure + */ public PathMeasure getPathMeasure() { return mPathMeasure; } diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingPathTransition.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingPathTransition.java index 4f95a0677d5eb4819f04d667b084333a63332272..4a2306d7f47f6cc652988f4a71cd2b9d4b3b608d 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingPathTransition.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingPathTransition.java @@ -14,16 +14,19 @@ * limitations under the License. */ - package com.ufreedom.floatingview.transition; /** - * Author UFreedom - * Date : 2016 十月 19 + * FloatingPathTransition + * + * @author xujianhong + * @since 2021-03-31 */ - -public interface FloatingPathTransition extends FloatingTransition { - - public FloatingPath getFloatingPath(); - +public interface FloatingPathTransition extends FloatingTransition { + /** + * getFloatingPath + * + * @return FloatingPath + */ + FloatingPath getFloatingPath(); } diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingTransition.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingTransition.java index 6815904bd8b7badd9e6d3a16b1caec7edb778123..b0ccf87a47883b9cf5e81c1d279733b87c4425e1 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingTransition.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingTransition.java @@ -14,15 +14,19 @@ * limitations under the License. */ - package com.ufreedom.floatingview.transition; - /** - * Author UFreedom - * Date : 2016 十月 19 + * FloatingTransition + * + * @author xujianhong + * @since 2021-03-31 */ - public interface FloatingTransition { - public void applyFloating(YumFloating yumFloating); + /** + * applyFloating + * + * @param yumFloating + */ + void applyFloating(YumFloating yumFloating); } diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/ITransition.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/ITransition.java index 75290fc163b42f262aa3a7112f5ad7aec7e2c9fa..f3416316612e93c10ada832d34d498d05b5839ae 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/ITransition.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/ITransition.java @@ -14,38 +14,96 @@ * limitations under the License. */ - package com.ufreedom.floatingview.transition; /** - * Author UFreedom - * Date : 2016 十月 18 + * ITransition + * + * @author xujianhong + * @since 2021-03-31 */ - public interface ITransition { - - public void setAlpha(float alpha); - - public void setRotation(float rotation); - - public void setRotationX(float rotationX); + /** + * Alpha + * + * @param alpha + */ + void setAlpha(float alpha); + + /** + * Rotation + * + * @param rotation + */ + void setRotation(float rotation); + + /** + * RotationX + * + * @param rotationX + */ + void setRotationX(float rotationX); + + /** + * RotationY + * + * @param rotationY + */ + void setRotationY(float rotationY); + + /** + * ScaleX + * + * @param scaleX + */ + void setScaleX(float scaleX); + + /** + * ScaleY + * + * @param scaleY + */ + void setScaleY(float scaleY); - public void setRotationY(float rotationY); - - public void setScaleX(float scaleX); + /** + * ScrollX + * + * @param scrollX + */ + void setScrollX(int scrollX); - public void setScaleY(float scaleY); + /** + * scrollY + * + * @param scrollY + */ + void setScrollY(int scrollY); - public void setScrollX(int scrollX); + /** + * translationX + * + * @param translationX + */ + void setTranslationX(float translationX); - public void setScrollY(int scrollY); + /** + * translationY + * + * @param translationY + */ + void setTranslationY(float translationY); - public void setTranslationX(float translationX); - - public void setTranslationY(float translationY); + /** + * X + * + * @param x + */ + void setX(float x); - public void setX(float x); - - public void setY(float y); - + /** + * Y + * + * @param y + */ + void setY(float y); } diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/PathPosition.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/PathPosition.java index 390623e81bd12f043a26d237ec97e22083de747f..a2066f1d849f42afe55f306f42040f4014912128 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/PathPosition.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/PathPosition.java @@ -14,18 +14,23 @@ * limitations under the License. */ - package com.ufreedom.floatingview.transition; /** + * ITransition * - * Data structure for storing path position. - * - * Author UFreedom - * Date : 2016 十月 19 + * @author xujianhong + * @since 2021-03-31 */ +public class PathPosition { + + /** + * X + */ + public float x; -public class PathPosition { - public float x; - public float y; + /** + * Y + */ + public float y; } diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/Rebound.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/Rebound.java index 3f54d434d7977806a827f6ce9808d0ecfc668a52..5e6ff2628e874ad25cb390cf423a4a05e184bf1a 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/Rebound.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/Rebound.java @@ -14,22 +14,42 @@ * limitations under the License. */ - package com.ufreedom.floatingview.transition; import com.facebook.rebound.Spring; /** - * Author UFreedom - * Date : 2016 十月 19 + * Rebound + * + * @author xujianhong + * @since 2021-03-31 */ - public interface Rebound { - - public Spring createSpringByBouncinessAndSpeed(double bounciness, double speed); + /** + * createSpringByBouncinessAndSpeed + * + * @param bounciness + * @param speed + * @return Spring + */ + Spring createSpringByBouncinessAndSpeed(double bounciness, double speed); - public Spring createSpringByTensionAndFriction(double tension, double friction) ; + /** + * createSpringByTensionAndFriction + * + * @param tension + * @param friction + * @return Spring + */ + Spring createSpringByTensionAndFriction(double tension, double friction); - public float transition(double progress, float startValue, float endValue); - + /** + * transition + * + * @param progress + * @param startValue + * @param endValue + * @return float + */ + float transition(double progress, float startValue, float endValue); } diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/YumFloating.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/YumFloating.java index 955a2c687fe0373c8363b0ef41df9966da306c93..b10250b75ac08d365d0377f024bfd80353b61f9e 100644 --- a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/YumFloating.java +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/YumFloating.java @@ -14,171 +14,266 @@ * limitations under the License. */ - package com.ufreedom.floatingview.transition; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewParent; - import com.facebook.rebound.Spring; import com.facebook.rebound.SpringConfig; import com.facebook.rebound.SpringSystem; import com.facebook.rebound.SpringUtil; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; import java.lang.ref.WeakReference; /** - * Author UFreedom - * Date : 2016 十月 19 + * YumFloating + * + * @author xujianhong + * @since 2021-03-31 */ - public class YumFloating implements ITransition, Rebound { private SpringSystem mSpringSystem; - private WeakReference mTargetViewWeakReference; - - public YumFloating(View targetView, SpringSystem springSystem) { - mTargetViewWeakReference = new WeakReference(targetView); + private WeakReference mTargetViewWeakReference; + + /** + * YumFloating + * + * @param targetView + * @param springSystem + */ + public YumFloating(Component targetView, SpringSystem springSystem) { + mTargetViewWeakReference = new WeakReference(targetView); this.mSpringSystem = springSystem; } - - public YumFloating(View targetView) { - mTargetViewWeakReference = new WeakReference(targetView); - + /** + * YumFloating + * + * @param targetView + */ + public YumFloating(Component targetView) { + mTargetViewWeakReference = new WeakReference(targetView); } - public View getTargetView() { + /** + * getTargetView + * + * @return Component + */ + public Component getTargetView() { return mTargetViewWeakReference.get(); } + /** + * alpha + * + * @param alpha + */ @Override public void setAlpha(float alpha) { - View targetView; - if ((targetView = getTargetView()) != null){ + Component targetView; + if ((targetView = getTargetView()) != null) { targetView.setAlpha(alpha); } } + /** + * rotation + * + * @param rotation + */ @Override public void setRotation(float rotation) { - View targetView; - if ((targetView = getTargetView()) != null){ + Component targetView; + if ((targetView = getTargetView()) != null) { targetView.setRotation(rotation); } } + /** + * rotationX + * + * @param rotationX + */ @Override public void setRotationX(float rotationX) { - View targetView; - if ((targetView = getTargetView()) != null){ - targetView.setRotationX(rotationX); + Component targetView; + if ((targetView = getTargetView()) != null) { + targetView.setRotation(rotationX); } } + /** + * rotationY + * + * @param rotationY + */ @Override public void setRotationY(float rotationY) { - View targetView; - if ((targetView = getTargetView()) != null){ - targetView.setRotationY(rotationY); + Component targetView; + if ((targetView = getTargetView()) != null) { + targetView.setRotation(rotationY); } } + /** + * scaleX + * + * @param scaleX + */ @Override public void setScaleX(float scaleX) { - View targetView; - if ((targetView = getTargetView()) != null){ + Component targetView; + if ((targetView = getTargetView()) != null) { targetView.setScaleX(scaleX); } } + /** + * scaleY + * + * @param scaleY + */ @Override public void setScaleY(float scaleY) { - View targetView; - if ((targetView = getTargetView()) != null){ + Component targetView; + if ((targetView = getTargetView()) != null) { targetView.setScaleY(scaleY); } } + /** + * scrollX + * + * @param scrollX + */ @Override public void setScrollX(int scrollX) { - View targetView; - if ((targetView = getTargetView()) != null){ + Component targetView; + if ((targetView = getTargetView()) != null) { targetView.setScaleX(scrollX); } } + /** + * scrollY + * + * @param scrollY + */ @Override public void setScrollY(int scrollY) { - View targetView; - if ((targetView = getTargetView()) != null){ + Component targetView; + if ((targetView = getTargetView()) != null) { targetView.setScaleY(scrollY); } - + } + /** + * translationX + * + * @param translationX + */ @Override public void setTranslationX(float translationX) { - View targetView; - if ((targetView = getTargetView()) != null){ + Component targetView; + if ((targetView = getTargetView()) != null) { targetView.setTranslationX(translationX); } } + /** + * translationY + * + * @param translationY + */ @Override public void setTranslationY(float translationY) { - View targetView; - if ((targetView = getTargetView()) != null){ + Component targetView; + if ((targetView = getTargetView()) != null) { targetView.setTranslationY(translationY); } } + /** + * x + * + * @param x + */ @Override public void setX(float x) { - View targetView; - if ((targetView = getTargetView()) != null){ - targetView.setX(x); + Component targetView; + if ((targetView = getTargetView()) != null) { + targetView.setTranslationX(x); } } + /** + * y + * + * @param y + */ @Override public void setY(float y) { - View targetView; - if ((targetView = getTargetView()) != null){ - targetView.setY(y); + Component targetView; + if ((targetView = getTargetView()) != null) { + targetView.setTranslationY(y); } } - + /** + * createSpringByBouncinessAndSpeed + * + * @param bounciness + * @param speed + * @return Spring + */ @Override public Spring createSpringByBouncinessAndSpeed(double bounciness, double speed) { return mSpringSystem.createSpring() .setSpringConfig(SpringConfig.fromBouncinessAndSpeed(bounciness, speed)); } + /** + * createSpringByTensionAndFriction + * + * @param tension + * @param friction + * @return Spring + */ @Override public Spring createSpringByTensionAndFriction(double tension, double friction) { return mSpringSystem.createSpring() .setSpringConfig(SpringConfig.fromOrigamiTensionAndFriction(tension, friction)); } + /** + * transition + * + * @param progress + * @param startValue + * @param endValue + * @return float + */ @Override public float transition(double progress, float startValue, float endValue) { return (float) SpringUtil.mapValueFromRangeToRange(progress, 0, 1, startValue, endValue); } - - - public void clear(){ - View view = getTargetView(); - if (view != null){ - ViewParent viewParent = view.getParent(); - if (viewParent instanceof ViewGroup){ - ViewGroup parent = (ViewGroup) viewParent; - parent.removeView(view); + + /** + * clear + */ + public void clear() { + Component view = getTargetView(); + if (view != null) { + ComponentContainer viewParent = (ComponentContainer) view.getComponentParent(); + if (viewParent instanceof ComponentContainer) { + ComponentContainer parent = viewParent; + parent.removeComponent(view); mTargetViewWeakReference.clear(); } } } - + } diff --git a/FloatingViewLib/src/main/java/com/ufreedom/floatingview/util/LogUtil.java b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/util/LogUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..6cea79c31fe1e860425a55bf51101b5959e32525 --- /dev/null +++ b/FloatingViewLib/src/main/java/com/ufreedom/floatingview/util/LogUtil.java @@ -0,0 +1,88 @@ +/* + * 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 an 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.ufreedom.floatingview.util; + +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +/** + * LogUtil 工具类 + * + * @author xujianhong + * @since 2021-03-31 + */ +public final class LogUtil { + private static final int DOMAIN = 0x001; + + private LogUtil() { + throw new Error("请不要实例化!"); + } + + /** info日志打印 + * + * @param tag + * @param format + * @param objects + */ + public static void info(String tag, String format, Object... objects) { + HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, DOMAIN, tag); + HiLog.info(logLabel, format, objects); + } + + /** debug日志打印 + * + * @param tag + * @param format + * @param objects + */ + public static void debug(String tag, String format, Object... objects) { + HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, DOMAIN, tag); + HiLog.debug(logLabel, format, objects); + } + + /** error日志打印 + * + * @param tag + * @param format + * @param objects + */ + public static void error(String tag, String format, Object... objects) { + HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, DOMAIN, tag); + HiLog.error(logLabel, format, objects); + } + + /** warn日志打印 + * + * @param tag + * @param format + * @param objects + */ + public static void warn(String tag, String format, Object... objects) { + HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, DOMAIN, tag); + HiLog.warn(logLabel, format, objects); + } + + /** fatal日志打印 + * + * @param tag + * @param format + * @param objects + */ + public static void fatal(String tag, String format, Object... objects) { + HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, DOMAIN, tag); + HiLog.fatal(logLabel, format, objects); + } +} diff --git a/FloatingViewLib/src/main/res/values/ids.xml b/FloatingViewLib/src/main/res/values/ids.xml deleted file mode 100644 index 8fefcc523678f8a33acc0d1b19ccbc2d927f84c0..0000000000000000000000000000000000000000 --- a/FloatingViewLib/src/main/res/values/ids.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/FloatingViewLib/src/main/res/values/strings.xml b/FloatingViewLib/src/main/res/values/strings.xml deleted file mode 100644 index 86ebe52edcae2d4d6a82abf52171439ec9bab947..0000000000000000000000000000000000000000 --- a/FloatingViewLib/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - FloatingView - diff --git a/FloatingViewLib/src/main/resources/base/element/string.json b/FloatingViewLib/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..157e044df7c9626ba9485c4c8db36fada10c4fad --- /dev/null +++ b/FloatingViewLib/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "FloatingViewLib" + } + ] +} diff --git a/FloatingViewLib/src/main/resources/base/layout/floating_fecor_view.xml b/FloatingViewLib/src/main/resources/base/layout/floating_fecor_view.xml new file mode 100644 index 0000000000000000000000000000000000000000..5d495e88cfe04097f057abd4af2f645db14f6efb --- /dev/null +++ b/FloatingViewLib/src/main/resources/base/layout/floating_fecor_view.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/demo/src/main/res/drawable-xxhdpi/bike.png b/FloatingViewLib/src/main/resources/base/media/bike.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/bike.png rename to FloatingViewLib/src/main/resources/base/media/bike.png diff --git a/FloatingViewLib/src/test/java/com/ufreedom/floatingview/ExampleTest.java b/FloatingViewLib/src/test/java/com/ufreedom/floatingview/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..8e940a2923f709cb2f5b8dedfa4089d074989d82 --- /dev/null +++ b/FloatingViewLib/src/test/java/com/ufreedom/floatingview/ExampleTest.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2021 The Chinese Software International 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 an 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.ufreedom.floatingview; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/FloatingViewLib/src/test/java/com/ufreedom/floatingview/ExampleUnitTest.java b/FloatingViewLib/src/test/java/com/ufreedom/floatingview/ExampleUnitTest.java deleted file mode 100644 index 7a4ef401101f31594bcf040d8d94c0bd4a5f42bb..0000000000000000000000000000000000000000 --- a/FloatingViewLib/src/test/java/com/ufreedom/floatingview/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ufreedom.floatingview; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/README.md b/README.md index cb9f592678b2b198fba63cef14bb6d990c96d169..8f30c52e4bcecd367abe061f7a02771799876b5c 100644 --- a/README.md +++ b/README.md @@ -1,137 +1,97 @@ -

- - - -

+# FloatingView -

FloatingView

+**本项目基于开源项目FloatingView进行openharmony化的移植和开发,可以通过项目标签以及github地址( https://github.com/UFreedom/FloatingView )追踪到原安卓项目版本** -

- FloatingView can make the target view floating above the anchor view with cool animation -

+#### 项目介绍 +- 项目名称:FloatingView +- 所属系列:openharmony的第三方组件适配移植 +- 功能:可以让Component在别的Component上执行的漂浮动画。 +- 项目移植状态:主功能完成 +- 调用差异:有 +- 基线版本:release 1.0.2 +- 开发版本:sdk5,DevEco Studio2.1 beta3 +- 项目作者和维护人:许建宏 +- 联系方式:xujianhong050@chinasoftinc.com +- 原项目Doc地址:https://github.com/UFreedom/FloatingView -

- - - - - +#### 效果演示 -

+ -

- -

- -

- -Links ------ -- [中文版 README](https://github.com/UFreedom/FloatingView/blob/master/README_CN.md) -- [Blog about FloatingView](http://www.jianshu.com/p/6aaa258d77f1) -- [demo.apk](http://oeapkptbn.bkt.clouddn.com/FloatingView-demo-v1.0.1.apk) - - -Usage ------ - -### Step 1 +#### 调用差异说明 +```java + 由于openharmony无对应API Window.ID_ANDROID_CONTENT所以需要传递当前的顶层Component在其上面进行操作 + 所以在初始化Floating的时候需要传递当前的Component +``` +#### 安装教程 -Add dependencies in build.gradle. -```groovy - dependencies { - compile 'com.ufreedom.uikit:FloatingViewLib:1.0.2' +1.在项目根目录下的build.gradle文件中, +```java + allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } } - + } +``` +2.在entry模块的build.gradle文件中, +```java + dependencies { + implementation('com.gitee.chinasoft_ohos:FloatingViewLib:0.0.1-SNAPSHOT') + ...... + } ``` +在sdk5,DevEco Studio2.1 beta3下项目可直接运行 +如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, +并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 +#### 使用说明 -### Step 2 - -Use FloatingBuilder to create a FloatingElement - +初始化 ```java - - FloatingElement builder = new FloatingBuilder() - .anchorView(View) - .targetView(View) + FloatingElement builder = new FloatingBuilder() + .anchorView(Component) + .targetView(Component) .offsetX(int) .offsetY(int) .floatingTransition(FloatingTransition) .build(); - ``` - -The use of FloatingBuilder can be configured to have: - -* anchorView :Anchor, is you want to float animation in which View above -* target:Target, The view which you want to float -* offsetX:X direction of offset, unit PX -* offsetY: Y direction of offset, unit PX -* floatingTransition : Floating effect, the default is ScaleFloatingTransition - - -### Step 3 - -Create a Floating as a FloatingElement container, and then let your View fly up - +创建一个 `Floating` 作为 `FloatingElement` 的容器,然后让你的 `Component` 飞起来 ```java - Floating floating = new Floating(getActivity()); + Floating floating = new Floating(AbilitySlice activity, Component topComponent); floating.startFloating(builder); ``` - - -Customisation -------------- - - -####1.Coordinates - - - - -####2.Class Diagram - - - -####3.Floating Animation - -Implementation of floating animation is very simple, you only need to implement the [FloatingTransition][4] interface. - +实现漂浮动画很简单,你只需要实现 `FloatingTransition` 接口就可以 ```java - public interface FloatingTransition { - public void applyFloating(YumFloating yumFloating); + void applyFloating(YumFloating yumFloating); } - ``` +在 `applyFloating` 方法,你可以使用 `Animation` 创建动画,然后使用 `YumFloating` 进行 `Alpha`,`Scale`,`Translate`,`Rotate` 等变换 - -In the `applyFloating` method, you can use Android Animation to do the animation, and then use the [YumFloating][6] to do Alpha , Scale, Translate, Rotate and other transformations. -If you want to add the [Facebook Rebound][5] animation effect, you can use the [SpringHelper][7], for example, [ScaleFloatingTransition][8]: - +如果你想加入 Facebook Rebound 回弹动画效果,你可以使用 SpringHelper,例如 ScaleFloatingTransition: ```java - public class ScaleFloatingTransition implements FloatingTransition { +public class ScaleFloatingTransition implements FloatingTransition { ... - - @Override + + @Override public void applyFloating(final YumFloating yumFloating) { - - ValueAnimator alphaAnimator = ObjectAnimator.ofFloat(1.0f, 0.0f); - alphaAnimator.setDuration(duration); - alphaAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + AnimatorValue alphaAnimator = new AnimatorValue(); + alphaAnimator.setDuration(mDuration); + alphaAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - yumFloating.setAlpha((Float) valueAnimator.getAnimatedValue()); + public void onUpdate(AnimatorValue animatorValue, float v) { + yumFloating.setAlpha(1 - v); } }); alphaAnimator.start(); - - SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f,bounciness, speed) - .reboundListener(new SimpleReboundListener(){ + SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f, mBounciness, mSpeed) + .reboundListener(new SimpleReboundListener() { @Override public void onReboundUpdate(double currentValue) { yumFloating.setScaleX((float) currentValue); @@ -139,85 +99,103 @@ If you want to add the [Facebook Rebound][5] animation effect, you can use the } }).start(yumFloating); } - -} - +} ``` +如果 `SpringHelper` 无法满足你的需求,你可以直接使用 `YumFloating `的 +`createSpringByBouncinessAndSpeed(double bounciness, double speed)` 或者 `createSpringByTensionAndFriction(double tension, double friction)` 创建 `Spring`, 然后使用 `transition(double progress, float startValue, float endValue)` 进行数值转换 -If [SpringHelper][7] can not meet your needs, you can directly use the `createSpringByBouncinessAndSpeed(double bounciness, double speed)` or -`createSpringByTensionAndFriction(double tension, double friction)` to create the Spring, and then use `transition (Progress double, startValue float, endValue float)` for numerical conversion - -####4.Floating Path Animation -The floating path animation is also very simple, such as [CurveFloatingPathTransition][9], first you need to inherit from the [BaseFloatingPathTransition][10] class ,The difference is, you need to implement a `getFloatingPath (`) method. -Use `Path` in the `getFloatingPath () `method to create the path you want to float, and then call `FloatingPath.create (path, false)` to return. For example, [CurveFloatingPathTransition][9] implementation: +路径漂浮动画 实现路径漂浮同样很简单,例如 `CurveFloatingPathTransition` ,首先你需要继承 `BaseFloatingPathTransition` 类.和继承 `FloatingTransition` 类不同的是,你需要再实现一个 `getFloatingPath()` 方法. 在 `getFloatingPath()` 方法内使用 Path 创建你想漂浮的路径,然后调用 `FloatingPath.create(path, false)` 进行返回. 例如 `CurveFloatingPathTransition` 实现: ```java - public class CurveFloatingPathTransition extends BaseFloatingPathTransition { +public class CurveFloatingPathTransition extends BaseFloatingPathTransition { ... - + @Override public FloatingPath getFloatingPath() { - if (path == null){ - path = new Path(); - path.moveTo(0, 0); - path.quadTo(-100, -200, 0, -300); - path.quadTo(200, -400, 0, -500); + if (mPath == null) { + mPath = new Path(); + mPath.moveTo(0, 0); + mPath.quadTo(-100, -200, 0, -300); + mPath.quadTo(200, -400, 0, -500); } - return FloatingPath.create(path, false); + return FloatingPath.create(mPath, false); } @Override public void applyFloating(final YumFloating yumFloating) { - ValueAnimator translateAnimator; - ValueAnimator alphaAnimator; - - - translateAnimator = ObjectAnimator.ofFloat(getStartPathPosition(), getEndPathPosition()); - translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - float value = (float) valueAnimator.getAnimatedValue(); - PathPosition floatingPosition = getFloatingPosition(value); - yumFloating.setTranslationX(floatingPosition.x); - yumFloating.setTranslationY(floatingPosition.y); - - } - }); - - ... - } - + AnimatorValue translateAnimator; + AnimatorValue alphaAnimator; + + // 需要指定算法 translateAnimator = ObjectAnimator.ofFloat(getStartPathPosition(), getEndPathPosition()); + translateAnimator = new AnimatorValue(); + translateAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + PathPosition floatingPosition = getFloatingPosition(v * getEndPathPosition()); + yumFloating.setTranslationX(floatingPosition.x); + yumFloating.setTranslationY(floatingPosition.y); + } + }); + } + ... } ``` +使用 `Path`将你想要漂浮的路径的描绘出来,然后在 `applyFloating(final YumFloating yumFloating)` 方法中: +使用 `getStartPathPosition()` 方法获取路径的开始位置 +使用 `getEndPathPosition()`方法获取路径的结束位置 +使用 `getFloatingPosition(float progress)` 获取当前进度的位置 +`getFloatingPosition(float progress)` 方法会返回一个 `PathPosition` 对象,其属性 `x`,`y` 分别代表当前路径动画的` x `坐标,和 `y `坐标. -Use Path to describe the path you want to float, and then in `applyFloating (YumFloating yumFloating)`: -* Use `getStartPathPosition () ` method to obtain the starting position of the path -* Use `getEndPathPosition () ` method to obtain the end position of the path -* Use `getFloatingPosition(float progress)` to get the position of the current progress - -`getFloatingPosition(float progress)`method will return a `PathPosition` object, its properties x an y representing the current path animation x coordinates and Y coordinates. +3.接口说明: +```java +/** + * 锚点,也就是你想在哪个 Component 上面进行漂浮动画 + */ +FloatingBuilder anchorView(Component view) + +/** + * 目标,你想漂浮的 Component + */ +FloatingBuilder targetView(Component view) + +/** + * x 方向的偏移量,单位 px + */ +FloatingBuilder offsetX(int offsetX) + +/** + * y 方向的偏移量,单位 px + */ +FloatingBuilder offsetY(int offsetY) + +/** + * 漂浮效果,默认是 ScaleFloatingTransition,也可以自己实现漂浮效果 + */ +FloatingBuilder floatingTransition(FloatingTransition floatingTransition) +``` -Release Log ------------ +#### 测试信息 +CodeCheck代码测试无异常 -#### v1.0.2 -[Fix bug](https://github.com/UFreedom/FloatingView/pull/6) +CloudTest代码测试无异常 +火绒安全病毒安全检测通过 -#### v1.0.1 -First Version +当前版本demo功能与原组件基本无差异 +测试员:常小俊 +#### 版本迭代 +- 0.0.1-SNAPSHOT -License --------- +## License Copyright 2015 UFreedom @@ -232,15 +210,3 @@ License 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. - - -[1]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingBuilder.java -[2]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingElement.java -[3]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/Floating.java -[4]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingTransition.java -[5]:http://facebook.github.io/rebound/ -[6]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/YumFloating.java -[7]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/SpringHelper.java -[8]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/ScaleFloatingTransition.java -[9]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/CurveFloatingPathTransition.java -[10]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/BaseFloatingPathTransition.java \ No newline at end of file diff --git a/README_CN.md b/README_CN.md deleted file mode 100644 index d6853cd03cea0b4a52efd8e2191403f942e735d4..0000000000000000000000000000000000000000 --- a/README_CN.md +++ /dev/null @@ -1,241 +0,0 @@ -

- - - -

- -

FloatingView

- -

- FloatingView can make the target view floating above the anchor view with cool animation -

- -

- - - - - -

- -

-

- -

- -Links ------ -- [FloatingView 介绍博客](http://www.jianshu.com/p/6aaa258d77f1) -- [演示程序 apk](http://oeapkptbn.bkt.clouddn.com/FloatingView-demo-v1.0.1.apk) - - -Usage ------ - -### Step 1 - -在 build.gradle 文件中添加库依赖 - -```groovy - dependencies { - compile 'com.ufreedom.uikit:FloatingViewLib:1.0.2' - } - -``` - - - -### Step 2 - -使用 [FloatingBuilder][1] 创建一个 [FloatingElement][2] - -```java - - FloatingElement builder = new FloatingBuilder() - .anchorView(View) - .targetView(View) - .offsetX(int) - .offsetY(int) - .floatingTransition(FloatingTransition) - .build(); - -``` - -使用 FloatingBuilder 可以设置的有 -* anchorView :锚点,也就是你想在哪个 View 上面进行漂浮动画 -* target:目标,你想漂浮的 View -* offsetX:x 方向的偏移量,单位 px -* offsetY: y 方向的偏移量,单位 px -* floatingTransition : 漂浮效果,默认是 ScaleFloatingTransition,也可以自己实现漂浮效果 - -### Step 3 - -创建一个 [Floating][3] 作为 [FloatingElement][2] 的容器,然后让你的 View 飞起来 - -```java - Floating floating = new Floating(getActivity()); - floating.startFloating(builder); -``` - - -自定义 ------ - - -####1.坐标系 - - - - -####2.类图 - - - - - -####3.漂浮动画 - -实现漂浮动画很简单,你只需要实现 [FloatingTransition][4] 接口就可以: - -```java - - public interface FloatingTransition { - public void applyFloating(YumFloating yumFloating); - } - -``` - -在 `applyFloating` 方法,你可以使用 Android Animation 创建动画,然后使用 [YumFloating][6] 进行 Alpha,Scale,Translate,Rotate 等变换 - -如果你想加入 [Facebook Rebound][5] 回弹动画效果,你可以使用 [SpringHelper][7],例如 [ScaleFloatingTransition][8]: - -```java - public class ScaleFloatingTransition implements FloatingTransition { - - ... - - @Override - public void applyFloating(final YumFloating yumFloating) { - - ValueAnimator alphaAnimator = ObjectAnimator.ofFloat(1.0f, 0.0f); - alphaAnimator.setDuration(duration); - alphaAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - yumFloating.setAlpha((Float) valueAnimator.getAnimatedValue()); - } - }); - alphaAnimator.start(); - - SpringHelper.createWidthBouncinessAndSpeed(0.0f, 1.0f,bounciness, speed) - .reboundListener(new SimpleReboundListener(){ - @Override - public void onReboundUpdate(double currentValue) { - yumFloating.setScaleX((float) currentValue); - yumFloating.setScaleY((float) currentValue); - } - }).start(yumFloating); - } - -} - - -``` - -如果 [SpringHelper][7] 无法满足你的需求,你可以直接使用 [YumFloating][6] 的 `createSpringByBouncinessAndSpeed(double bounciness, double speed)` 或者 - `createSpringByTensionAndFriction(double tension, double friction)` 创建 Spring, 然后使用 `transition(double progress, float startValue, float endValue)` 进行数值转换 - - -####4.路径漂浮动画 -实现路径漂浮同样很简单,例如 [CurveFloatingPathTransition][9] ,首先你需要继承 [BaseFloatingPathTransition][10] 类.和继承 [FloatingTransition][4] 类不同的是,你需要再实现一个 `getFloatingPath()` 方法. -在 `getFloatingPath()` 方法内使用 `Path` 创建你想漂浮的路径,然后调用 `FloatingPath.create(path, false)` 进行返回. 例如 [CurveFloatingPathTransition][9] 实现: - -```java - public class CurveFloatingPathTransition extends BaseFloatingPathTransition { - - ... - - @Override - public FloatingPath getFloatingPath() { - if (path == null){ - path = new Path(); - path.moveTo(0, 0); - path.quadTo(-100, -200, 0, -300); - path.quadTo(200, -400, 0, -500); - } - return FloatingPath.create(path, false); - } - - @Override - public void applyFloating(final YumFloating yumFloating) { - ValueAnimator translateAnimator; - ValueAnimator alphaAnimator; - - - translateAnimator = ObjectAnimator.ofFloat(getStartPathPosition(), getEndPathPosition()); - translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - float value = (float) valueAnimator.getAnimatedValue(); - PathPosition floatingPosition = getFloatingPosition(value); - yumFloating.setTranslationX(floatingPosition.x); - yumFloating.setTranslationY(floatingPosition.y); - - } - }); - - ... - } - -} -``` - -使用 Path 将你想要漂浮的路径的描绘出来,然后在 `applyFloating(final YumFloating yumFloating)` 方法中: - -* 使用 `getStartPathPosition()` 方法获取路径的开始位置 -* 使用 `getEndPathPosition()`方法获取路径的结束位置 -* 使用 `getFloatingPosition(float progress)` 获取当前进度的位置 - -`getFloatingPosition(float progress)` 方法会返回一个 `PathPosition` 对象,其属性 x,y 分别代表当前路径动画的 x 坐标,和 y 坐标. - - - Release Log ------------ - - - #### v1.0.2 - [修复 bug](https://github.com/UFreedom/FloatingView/pull/6) - - - #### v1.0.1 - 初始版本 - - - -License --------- - - Copyright 2015 UFreedom - - 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. - -[1]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingBuilder.java -[2]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/FloatingElement.java -[3]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/Floating.java -[4]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/FloatingTransition.java -[5]:http://facebook.github.io/rebound/ -[6]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/YumFloating.java -[7]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/spring/SpringHelper.java -[8]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/ScaleFloatingTransition.java -[9]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/effect/CurveFloatingPathTransition.java -[10]:https://github.com/UFreedom/FloatingView/blob/master/FloatingViewLib/src/main/java/com/ufreedom/floatingview/transition/BaseFloatingPathTransition.java \ No newline at end of file diff --git a/build.gradle b/build.gradle index a96dcf3e5d5c81376134eeb2552b518a7d5904f4..9097118df06bf21081277518b0bbb0f5c1a2d129 100644 --- a/build.gradle +++ b/build.gradle @@ -1,26 +1,40 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 4 + } +} buildscript { repositories { + maven { + url 'https://mirrors.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' + classpath 'com.huawei.ohos:hap:2.4.2.7' + classpath 'com.huawei.ohos:decctest:1.0.0.6' } } allprojects { repositories { + maven { + url 'https://mirrors.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } jcenter() } } - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/changeLog.md b/changeLog.md new file mode 100644 index 0000000000000000000000000000000000000000..4b5290ce1d4b7458f2718358f723929c223d9f29 --- /dev/null +++ b/changeLog.md @@ -0,0 +1,7 @@ +# 基本功能:Component在别的Component上执行的漂浮动画 + +# 修改点: + 由于openharmony不支持Window.ID_ANDROID_CONTENT所以需要传递当前的Component在其上面进行操作 + +# 遗留问题(暂不支持的功能): + 无 \ No newline at end of file diff --git a/demo/build.gradle b/demo/build.gradle deleted file mode 100644 index 795ae3873ecc158fae215151ca5d610040c99477..0000000000000000000000000000000000000000 --- a/demo/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 24 - buildToolsVersion "24.0.0" - defaultConfig { - applicationId "com.ufreedom.demo" - minSdkVersion 14 - targetSdkVersion 24 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - compile 'com.android.support:appcompat-v7:24.2.1' - testCompile 'junit:junit:4.12' - compile project(':FloatingViewLib') - compile 'com.android.support:recyclerview-v7:24.2.1' - compile 'com.android.support:design:24.2.1' -} diff --git a/demo/proguard-rules.pro b/demo/proguard-rules.pro deleted file mode 100644 index ff11ede7761c2d3d8e001ee02fdd3e0f3b45da78..0000000000000000000000000000000000000000 --- a/demo/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/yummy/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/demo/src/androidTest/java/com/ufreedom/floatingview/ExampleInstrumentedTest.java b/demo/src/androidTest/java/com/ufreedom/floatingview/ExampleInstrumentedTest.java deleted file mode 100644 index 2d5e1ddb194b5702a40153118001cec25ef27c66..0000000000000000000000000000000000000000 --- a/demo/src/androidTest/java/com/ufreedom/floatingview/ExampleInstrumentedTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.ufreedom.floatingview; - -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Instrumentation test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() throws Exception { - // Context of the app under test. - /*Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("com.ufreedom.floatingview", appContext.getPackageName());*/ - } -} diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml deleted file mode 100644 index 53ad268d5d6377e7928254b97683f83e7cff726f..0000000000000000000000000000000000000000 --- a/demo/src/main/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/demo/src/main/java/com/ufreedom/demo/MainActivity.java b/demo/src/main/java/com/ufreedom/demo/MainActivity.java deleted file mode 100644 index 5ee400a97d56a41435ed102ba60b73f193077c4f..0000000000000000000000000000000000000000 --- a/demo/src/main/java/com/ufreedom/demo/MainActivity.java +++ /dev/null @@ -1,339 +0,0 @@ -package com.ufreedom.demo; - -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; -import android.graphics.Path; -import android.os.Build; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.widget.ImageView; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import com.ufreedom.floatingview.Floating; -import com.ufreedom.floatingview.FloatingBuilder; -import com.ufreedom.floatingview.FloatingElement; -import com.ufreedom.floatingview.effect.ScaleFloatingTransition; -import com.ufreedom.floatingview.effect.TranslateFloatingTransition; -import com.ufreedom.floatingview.spring.ReboundListener; -import com.ufreedom.floatingview.spring.SimpleReboundListener; -import com.ufreedom.floatingview.spring.SpringHelper; -import com.ufreedom.floatingview.transition.BaseFloatingPathTransition; -import com.ufreedom.floatingview.transition.FloatingPath; -import com.ufreedom.floatingview.transition.FloatingTransition; -import com.ufreedom.floatingview.transition.PathPosition; -import com.ufreedom.floatingview.transition.YumFloating; - -public class MainActivity extends AppCompatActivity { - - private Floating mFloating; - private View mIcPlaneView; - private View mIcPaperAirPlaneView; - private int mScreenWidth; - private int mScreenHeight; - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - mFloating = new Floating(this); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes(); - localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags); - } - - mScreenWidth = UIUtils.getScreenWidth(this); - mScreenHeight = UIUtils.getScreenWidth(this); - initLayout(); - } - - private void initLayout() { - - int margin = UIUtils.dip2px(this,15); - int w = mScreenWidth - margin * 2; - int h = (int) (w * 0.53f); - - RelativeLayout bikeRootView = (RelativeLayout) findViewById(R.id.itemBikeContainerView); - RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) bikeRootView.getLayoutParams(); - layoutParams.width = w; - layoutParams.height = h; - - RelativeLayout clockRootView = (RelativeLayout) findViewById(R.id.itemClockContainerView); - RelativeLayout.LayoutParams clockRootViewLayoutParams = (RelativeLayout.LayoutParams) clockRootView.getLayoutParams(); - clockRootViewLayoutParams.width = w; - clockRootViewLayoutParams.height = h; - - mIcPlaneView = findViewById(R.id.icPlane); - mIcPlaneView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - ImageView imageView = new ImageView(MainActivity.this); - imageView.setLayoutParams(new ViewGroup.LayoutParams(mIcPlaneView.getMeasuredWidth(), mIcPlaneView.getMeasuredHeight())); - imageView.setImageResource(R.drawable.floating_plane); - - FloatingElement floatingElement = new FloatingBuilder() - .anchorView(v) - .targetView(imageView) - .floatingTransition(new PlaneFloating()) - .build(); - mFloating.startFloating(floatingElement); - } - }); - - mIcPaperAirPlaneView = findViewById(R.id.icPaperAirPlane); - mIcPaperAirPlaneView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - ImageView imageView = new ImageView(MainActivity.this); - imageView.setLayoutParams(new ViewGroup.LayoutParams(mIcPaperAirPlaneView.getMeasuredWidth(), mIcPaperAirPlaneView.getMeasuredHeight())); - imageView.setImageResource(R.drawable.paper_airplane); - - FloatingElement floatingElement = new FloatingBuilder() - .anchorView(v) - .targetView(imageView) - .floatingTransition(new TranslateFloatingTransition()) - .build(); - mFloating.startFloating(floatingElement); - } - }); - - View icCommandLineView = findViewById(R.id.icCommandLine); - icCommandLineView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - TextView textView = new TextView(MainActivity.this); - textView.setText("Hello FloatingView"); - - FloatingElement floatingElement = new FloatingBuilder() - .anchorView(v) - .targetView(textView) - .offsetY(-v.getMeasuredHeight()) - .floatingTransition(new ScaleFloatingTransition()) - .build(); - mFloating.startFloating(floatingElement); - } - }); - - View icLikeView = findViewById(R.id.icLike); - icLikeView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - FloatingElement floatingElement = new FloatingBuilder() - .anchorView(v) - .targetView(R.layout.ic_like) - .floatingTransition(new TranslateFloatingTransition()) - .build(); - mFloating.startFloating(floatingElement); - - } - }); - - - final View icStarView = findViewById(R.id.icStar); - icStarView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View v) { - - ImageView imageView = new ImageView(MainActivity.this); - imageView.setLayoutParams(new ViewGroup.LayoutParams(icStarView.getMeasuredWidth(), icStarView.getMeasuredHeight())); - imageView.setImageResource(R.drawable.star_floating); - - final FloatingElement floatingElement = new FloatingBuilder() - .anchorView(v) - .targetView(imageView) - .floatingTransition(new StarFloating()) - .build(); - - SpringHelper.createWithBouncinessAndSpeed(0f,1f,11,15).reboundListener(new ReboundListener() { - @Override - public void onReboundUpdate(double currentValue) { - v.setScaleX((float) currentValue); - v.setScaleY((float) currentValue); - } - - @Override - public void onReboundEnd() { - mFloating.startFloating(floatingElement); - } - }).start(); - - - - } - }); - - - final View icBeerView = findViewById(R.id.icBeer); - icBeerView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - ImageView imageView = new ImageView(MainActivity.this); - imageView.setLayoutParams(new ViewGroup.LayoutParams(icBeerView.getMeasuredWidth(), icBeerView.getMeasuredHeight())); - imageView.setImageResource(R.drawable.beer); - - FloatingElement floatingElement = new FloatingBuilder() - .anchorView(v) - .targetView(imageView) - .floatingTransition(new BeerFloating()) - .build(); - mFloating.startFloating(floatingElement); - } - }); - } - - class PlaneFloating extends BaseFloatingPathTransition { - - @Override - public FloatingPath getFloatingPath() { - Path path = new Path(); - path.moveTo(0, 0); - path.quadTo(100, -300, 0, -600); - path.rLineTo(0, -mScreenHeight - 300); - return FloatingPath.create(path, false); - } - - @Override - public void applyFloating(final YumFloating yumFloating) { - - ValueAnimator translateAnimator = ObjectAnimator.ofFloat(getStartPathPosition(), getEndPathPosition()); - translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - float value = (float) valueAnimator.getAnimatedValue(); - PathPosition floatingPosition = getFloatingPosition(value); - yumFloating.setTranslationX(floatingPosition.x); - yumFloating.setTranslationY(floatingPosition.y); - - } - }); - translateAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - yumFloating.setTranslationX(0); - yumFloating.setTranslationY(0); - yumFloating.setAlpha(0f); - yumFloating.clear(); - } - }); - - - SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f, 14, 15) - .reboundListener(new SimpleReboundListener() { - @Override - public void onReboundUpdate(double currentValue) { - yumFloating.setScaleX((float) currentValue); - yumFloating.setScaleY((float) currentValue); - } - }).start(yumFloating); - - translateAnimator.setDuration(3000); - translateAnimator.start(); - } - } - - class StarFloating implements FloatingTransition { - - @Override - public void applyFloating(final YumFloating yumFloating) { - SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f,10, 15) - .reboundListener(new SimpleReboundListener(){ - @Override - public void onReboundUpdate(double currentValue) { - yumFloating.setScaleX((float) currentValue); - yumFloating.setScaleY((float) currentValue); - } - }).start(yumFloating); - - - ValueAnimator rotateAnimator = ObjectAnimator.ofFloat(0, 360); - rotateAnimator.setDuration(500); - rotateAnimator.setRepeatCount(ValueAnimator.INFINITE); - rotateAnimator.setRepeatMode(ValueAnimator.RESTART); - rotateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - yumFloating.setRotation((float) valueAnimator.getAnimatedValue()); - } - }); - - ValueAnimator translateAnimator = ObjectAnimator.ofFloat(0, 500); - translateAnimator.setDuration(600); - translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - yumFloating.setTranslationY(-(Float) valueAnimator.getAnimatedValue()); - } - }); - translateAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - yumFloating.setAlpha(0f); - yumFloating.clear(); - } - }); - rotateAnimator.start(); - translateAnimator.start(); - } - } - - - class BeerFloating extends BaseFloatingPathTransition{ - - - @Override - public FloatingPath getFloatingPath() { - Path path = new Path(); - path.rLineTo(-100,0); - path.quadTo(0,-200,100,0); - path.quadTo(0,200,-100,0); - return FloatingPath.create(path, false); - } - - @Override - public void applyFloating(final YumFloating yumFloating) { - ValueAnimator translateAnimator = ObjectAnimator.ofFloat(0, 500); - translateAnimator.setDuration(600); - translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator valueAnimator) { - float value = (float) valueAnimator.getAnimatedValue(); - PathPosition floatingPosition = getFloatingPosition(value); - yumFloating.setTranslationX(floatingPosition.x); - yumFloating.setTranslationY(floatingPosition.y); - - } - }); - - - ValueAnimator alphaAnimation = ObjectAnimator.ofFloat(1f,0f); - alphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - yumFloating.setAlpha((Float) animation.getAnimatedValue()); - } - }); - alphaAnimation.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - yumFloating.clear(); - } - }); - alphaAnimation.setStartDelay(550); - alphaAnimation.setDuration(300); - translateAnimator.start(); - alphaAnimation.start(); - } - } - -} diff --git a/demo/src/main/java/com/ufreedom/demo/UIUtils.java b/demo/src/main/java/com/ufreedom/demo/UIUtils.java deleted file mode 100644 index 43ffcc3a6c581ee16cf7b24a2fe37f91c08578bc..0000000000000000000000000000000000000000 --- a/demo/src/main/java/com/ufreedom/demo/UIUtils.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.ufreedom.demo; - -import android.content.Context; -import android.content.res.Resources; -import android.util.DisplayMetrics; -import android.util.TypedValue; -import android.view.WindowManager; - -/** - * Utils for UI - * Author UFreedom - * Date : 2016 十月 28 - */ - -public class UIUtils { - - public static int dip2px(Context context, float dp) { - Resources r = context.getResources(); - float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); - return Math.round(px); - } - - public static int getScreenWidth(Context context){ - DisplayMetrics dm = new DisplayMetrics(); - WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); - wm.getDefaultDisplay().getMetrics(dm); - return dm.widthPixels; - - } - public static int getScreenHeight(Context context){ - DisplayMetrics dm = new DisplayMetrics(); - WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); - wm.getDefaultDisplay().getMetrics(dm); - return dm.heightPixels; - } -} diff --git a/demo/src/main/res/drawable-xxhdpi/bg_item.9.png b/demo/src/main/res/drawable-xxhdpi/bg_item.9.png deleted file mode 100644 index 7704c70eccbbc3c75ab3b79ad505010575b46590..0000000000000000000000000000000000000000 Binary files a/demo/src/main/res/drawable-xxhdpi/bg_item.9.png and /dev/null differ diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml deleted file mode 100644 index 602a1993df9af66cfaf91e95879dd82a1c059c45..0000000000000000000000000000000000000000 --- a/demo/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,168 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/demo/src/main/res/layout/fragment_rv.xml b/demo/src/main/res/layout/fragment_rv.xml deleted file mode 100644 index 9bb297b58143633598ab8baaaeb597dd9e23e5a2..0000000000000000000000000000000000000000 --- a/demo/src/main/res/layout/fragment_rv.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/demo/src/main/res/layout/fragment_simple.xml b/demo/src/main/res/layout/fragment_simple.xml deleted file mode 100644 index 1f31ddd90b6104aba1bbdc8cd6c395750188cfb9..0000000000000000000000000000000000000000 --- a/demo/src/main/res/layout/fragment_simple.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/demo/src/main/res/layout/ic_like.xml b/demo/src/main/res/layout/ic_like.xml deleted file mode 100644 index 8c0981de8bd6658e6e56cad0766b41dbaac510f9..0000000000000000000000000000000000000000 --- a/demo/src/main/res/layout/ic_like.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/demo/src/main/res/layout/rv_item.xml b/demo/src/main/res/layout/rv_item.xml deleted file mode 100644 index 9328f242ae973b99253b0f95c5a3acd9e823e1d1..0000000000000000000000000000000000000000 --- a/demo/src/main/res/layout/rv_item.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/demo/src/main/res/menu/menu.xml b/demo/src/main/res/menu/menu.xml deleted file mode 100644 index 52469792ecc79f3064cad99d6fb47d90838e32fa..0000000000000000000000000000000000000000 --- a/demo/src/main/res/menu/menu.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/demo/src/main/res/mipmap-hdpi/ic_launcher.png b/demo/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index 14dd0e04ff494fbdf70aed73cb4aea38cc37a902..0000000000000000000000000000000000000000 Binary files a/demo/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/demo/src/main/res/mipmap-mdpi/ic_launcher.png b/demo/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index 1603b79a260385de33361abbbe8bff4ec31af715..0000000000000000000000000000000000000000 Binary files a/demo/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/demo/src/main/res/mipmap-xhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index adb4a389daedd4f44b464b3b0614733036baf735..0000000000000000000000000000000000000000 Binary files a/demo/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index f505df2e14823017b4606487906151eb7b5228da..0000000000000000000000000000000000000000 Binary files a/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png deleted file mode 100644 index 0b587d93b8f3dac0d6b4ae1f3ca52e5988418cf6..0000000000000000000000000000000000000000 Binary files a/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ diff --git a/demo/src/main/res/values-v19/dimens.xml b/demo/src/main/res/values-v19/dimens.xml deleted file mode 100644 index dcbc3d50bdd8278919613c2a10b35435cc8ea751..0000000000000000000000000000000000000000 --- a/demo/src/main/res/values-v19/dimens.xml +++ /dev/null @@ -1,4 +0,0 @@ - - 24dp - 80dp - diff --git a/demo/src/main/res/values-v19/styles.xml b/demo/src/main/res/values-v19/styles.xml deleted file mode 100644 index 1a90d1f50b98893edd4da579343400b0342b7001..0000000000000000000000000000000000000000 --- a/demo/src/main/res/values-v19/styles.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/demo/src/main/res/values-v21/dimens.xml b/demo/src/main/res/values-v21/dimens.xml deleted file mode 100644 index f7cecae96a5e3627b3635436d5b37ee957707afb..0000000000000000000000000000000000000000 --- a/demo/src/main/res/values-v21/dimens.xml +++ /dev/null @@ -1,3 +0,0 @@ - - 24dp - diff --git a/demo/src/main/res/values-v21/styles.xml b/demo/src/main/res/values-v21/styles.xml deleted file mode 100644 index 005ce9916fa5f72222fcf4e59e0344d528c0d9df..0000000000000000000000000000000000000000 --- a/demo/src/main/res/values-v21/styles.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/demo/src/main/res/values-w820dp/dimens.xml b/demo/src/main/res/values-w820dp/dimens.xml deleted file mode 100644 index 63fc816444614bd64f68a372d1f93211628ee51d..0000000000000000000000000000000000000000 --- a/demo/src/main/res/values-w820dp/dimens.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - 64dp - diff --git a/demo/src/main/res/values/colors.xml b/demo/src/main/res/values/colors.xml deleted file mode 100644 index 207098f7449f09e7870e08800bcca5474f7d0a57..0000000000000000000000000000000000000000 --- a/demo/src/main/res/values/colors.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - #6d5f88 - #6d5f88 - #6d5f88 - #6d5f88 - diff --git a/demo/src/main/res/values/dimens.xml b/demo/src/main/res/values/dimens.xml deleted file mode 100644 index 6ea94ab346724de17dc220218175d7ea2ed48ea1..0000000000000000000000000000000000000000 --- a/demo/src/main/res/values/dimens.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - 16dp - 16dp - 0dp - 48dp - 28dp - 28dp - - - diff --git a/demo/src/main/res/values/strings.xml b/demo/src/main/res/values/strings.xml deleted file mode 100644 index 86ebe52edcae2d4d6a82abf52171439ec9bab947..0000000000000000000000000000000000000000 --- a/demo/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - FloatingView - diff --git a/demo/src/main/res/values/styles.xml b/demo/src/main/res/values/styles.xml deleted file mode 100644 index be71ed5f000b00e6106bbbf555dd07b3ba0abe5e..0000000000000000000000000000000000000000 --- a/demo/src/main/res/values/styles.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/demo/src/test/java/com/ufreedom/floatingview/ExampleUnitTest.java b/demo/src/test/java/com/ufreedom/floatingview/ExampleUnitTest.java deleted file mode 100644 index 7a4ef401101f31594bcf040d8d94c0bd4a5f42bb..0000000000000000000000000000000000000000 --- a/demo/src/test/java/com/ufreedom/floatingview/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ufreedom.floatingview; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/demo/.gitignore b/entry/.gitignore similarity index 100% rename from demo/.gitignore rename to entry/.gitignore diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..e55c852ec53092596cb6fcdaae44e003fa3a9a1b --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,13 @@ +apply plugin: 'com.huawei.ohos.hap' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 4 + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testCompile 'junit:junit:4.12' + implementation project(":FloatingViewLib") +} diff --git a/entry/src/main/config.json b/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..13e88a428c12de8610689fca3613180ff63a9164 --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,57 @@ +{ + "app": { + "bundleName": "com.ufreedom.demo", + "vendor": "ufreedom", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.ufreedom.demo", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.ufreedom.demo.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/ufreedom/demo/MainAbility.java b/entry/src/main/java/com/ufreedom/demo/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..2f67c892387ff4769d0dbef400885f2b4c214035 --- /dev/null +++ b/entry/src/main/java/com/ufreedom/demo/MainAbility.java @@ -0,0 +1,39 @@ +/* + * 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 an 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.ufreedom.demo; + +import com.ufreedom.demo.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + * + * @author xujianhong + * @since 2021-03-31 + */ +public class MainAbility extends Ability { + /** + * onStart + * + * @param intent + */ + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/entry/src/main/java/com/ufreedom/demo/MyApplication.java b/entry/src/main/java/com/ufreedom/demo/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..a3134654c583c3ddb8a62a224451f87eb97daa69 --- /dev/null +++ b/entry/src/main/java/com/ufreedom/demo/MyApplication.java @@ -0,0 +1,34 @@ +/* + * 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 an 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.ufreedom.demo; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + * + * @author xujianhong + * @since 2021-03-31 + */ +public class MyApplication extends AbilityPackage { + /** + * onInitialize + */ + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/entry/src/main/java/com/ufreedom/demo/UiUtils.java b/entry/src/main/java/com/ufreedom/demo/UiUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..9fce7eb2e92fc2342fed568b553ec1e42c3a3a00 --- /dev/null +++ b/entry/src/main/java/com/ufreedom/demo/UiUtils.java @@ -0,0 +1,57 @@ +/* + * 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 an 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.ufreedom.demo; + +import ohos.agp.window.service.Display; +import ohos.agp.window.service.DisplayAttributes; +import ohos.agp.window.service.DisplayManager; +import ohos.app.Context; + +import java.util.Optional; + +/** + * 尺寸转换 + * + * @author xujianhong + * @since 2021-03-31 + */ +public final class UiUtils { + private UiUtils() { + } + + /** px转换成dip + * + * @param context + * @param dp + * @return 转换后的数据 + */ + public static int dip2px(Context context, float dp) { + Optional display = DisplayManager.getInstance().getDefaultDisplay(context); + DisplayAttributes displayAttributes = display.get().getAttributes(); + return Math.round(displayAttributes.scalDensity * dp); + } + + /** 获取屏幕宽度 + * + * @param context + * @return 屏幕宽度 + */ + public static int getScreenWidth(Context context) { + Optional display = DisplayManager.getInstance().getDefaultDisplay(context); + DisplayAttributes displayAttributes = display.get().getAttributes(); + return displayAttributes.width; + } +} diff --git a/entry/src/main/java/com/ufreedom/demo/slice/MainAbilitySlice.java b/entry/src/main/java/com/ufreedom/demo/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..736bd709c0cd3ebc477936eb44d6cab8e4019475 --- /dev/null +++ b/entry/src/main/java/com/ufreedom/demo/slice/MainAbilitySlice.java @@ -0,0 +1,235 @@ +/* + * 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 an 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.ufreedom.demo.slice; + +import com.ufreedom.demo.ResourceTable; +import com.ufreedom.demo.UiUtils; +import com.ufreedom.demo.transition.BeerFloating; +import com.ufreedom.demo.transition.PlaneFloating; +import com.ufreedom.demo.transition.StarFloating; +import com.ufreedom.floatingview.Floating; +import com.ufreedom.floatingview.FloatingBuilder; +import com.ufreedom.floatingview.FloatingElement; +import com.ufreedom.floatingview.effect.ScaleFloatingTransition; +import com.ufreedom.floatingview.effect.TranslateFloatingTransition; +import com.ufreedom.floatingview.spring.ReboundListener; +import com.ufreedom.floatingview.spring.SpringHelper; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.Image; +import ohos.agp.components.Text; +import ohos.agp.utils.Color; + +/** + * MainAbilitySlice + * + * @author xujianhong + * @since 2021-03-31 + */ +public class MainAbilitySlice extends AbilitySlice { + private Floating mFloating; + private Component mIcPlaneView; + private Component mIcPaperPlane; + private int mScreenHeight; + private Component dependentLayout; + private final int marginAll = 15; + private final int two = 2; + private final float heightUtil = 0.53f; + private final double bounciness = 11; + private final double speed = 15; + private final int starOffsetX = -80; + + /** + * onStart + * + * @param intent + */ + @Override + public void onStart(Intent intent) { + super.onStart(intent); + getWindow().setStatusBarColor(Color.getIntColor("#6d5f88")); + super.setUIContent(ResourceTable.Layout_ability_main); + dependentLayout = findComponentById(ResourceTable.Id_dependent_layout); + mFloating = new Floating(this, dependentLayout); + mScreenHeight = UiUtils.getScreenWidth(this); + initLayout(); + } + + /** + * 初始化动画 + */ + private void initLayout() { + // 底部大飞机 + setIcPlaneView(); + + // 纸飞机 + setIcPaperAirPlaneView(); + + // C代码 + setIcCommandLineView(); + + // 点赞 + setIcLikeView(); + + // 旋转星星 + setIcStarView(); + + // 啤酒 + setIcBeerView(); + } + + /** + * 底部飞机 + */ + private void setIcPlaneView() { + mIcPlaneView = findComponentById(ResourceTable.Id_icPlane); + mIcPlaneView.setClickedListener(view -> { + Image iv = new Image(this); + iv.setLayoutConfig(new ComponentContainer.LayoutConfig(mIcPlaneView.getWidth(), mIcPlaneView.getHeight())); + iv.setPixelMap(ResourceTable.Media_floating_plane); + FloatingElement floatingElement = new FloatingBuilder() + .anchorView(mIcPlaneView) + .targetView(iv) + .floatingTransition(new PlaneFloating(this)) + .build(); + mFloating.startFloating(floatingElement); + }); + } + + /** + * 纸飞机 + */ + private void setIcPaperAirPlaneView() { + mIcPaperPlane = findComponentById(ResourceTable.Id_icPaperAirPlane); + mIcPaperPlane.setClickedListener(view -> { + Image iv = new Image(this); + iv.setLayoutConfig(new ComponentContainer.LayoutConfig(mIcPaperPlane.getWidth(), + mIcPaperPlane.getHeight())); + iv.setPixelMap(ResourceTable.Media_paper_airplane); + FloatingElement floatingElement = new FloatingBuilder() + .anchorView(mIcPaperPlane) + .targetView(iv) + .floatingTransition(new TranslateFloatingTransition()) + .build(); + mFloating.startFloating(floatingElement); + }); + } + + /** + * C代码 + */ + private void setIcCommandLineView() { + Component icCommandLineView = findComponentById(ResourceTable.Id_icCommandLine); + icCommandLineView.setClickedListener(view -> { + Text textView = new Text(this); + textView.setText("Hello FloatingView"); + FloatingElement floatingElement = new FloatingBuilder() + .anchorView(view) + .targetView(textView) + .offsetY(-view.getHeight()) + .offsetX(-view.getWidth()) + .floatingTransition(new ScaleFloatingTransition()) + .build(); + mFloating.startFloating(floatingElement); + }); + } + + /** + * 点赞 + */ + private void setIcLikeView() { + Image icLikeView = (Image) findComponentById(ResourceTable.Id_icLike); + icLikeView.setClickedListener(view -> { + FloatingElement floatingElement = new FloatingBuilder() + .anchorView(icLikeView) + .targetView(ResourceTable.Layout_ic_like) + .offsetX(-icLikeView.getWidth()) + .offsetY(-icLikeView.getHeight()) + .floatingTransition(new TranslateFloatingTransition()) + .build(); + mFloating.startFloating(floatingElement); + }); + } + + /** + * 旋转星星 + */ + private void setIcStarView() { + final Component icStarView = findComponentById(ResourceTable.Id_icStar); + icStarView.setClickedListener(view -> { + Image iv = new Image(this); + iv.setLayoutConfig(new ComponentContainer.LayoutConfig(icStarView.getWidth(), icStarView.getHeight())); + iv.setPixelMap(ResourceTable.Media_star_floating); + final FloatingElement floatingElement = new FloatingBuilder() + .anchorView(view) + .targetView(iv) + .offsetX(starOffsetX) + .floatingTransition(new StarFloating()) + .build(); + SpringHelper.createWithBouncinessAndSpeed(0f, 1f, bounciness, speed).reboundListener(new ReboundListener() { + @Override + public void onReboundUpdate(double currentValue) { + view.setScaleX((float) currentValue); + view.setScaleY((float) currentValue); + } + + @Override + public void onReboundEnd() { + mFloating.startFloating(floatingElement); + } + }).start(); + }); + } + + /** + * 啤酒 + */ + private void setIcBeerView() { + final Component icBeerView = findComponentById(ResourceTable.Id_icBeer); + icBeerView.setClickedListener(view -> { + Image iv = new Image(this); + iv.setLayoutConfig(new ComponentContainer.LayoutConfig(icBeerView.getWidth(), icBeerView.getHeight())); + iv.setPixelMap(ResourceTable.Media_beer); + + FloatingElement floatingElement = new FloatingBuilder() + .anchorView(view) + .targetView(iv) + .floatingTransition(new BeerFloating()) + .build(); + mFloating.startFloating(floatingElement); + }); + } + + /** + * onActive + */ + @Override + public void onActive() { + super.onActive(); + } + + /** + * onForeground + * + * @param intent + */ + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/entry/src/main/java/com/ufreedom/demo/transition/BeerFloating.java b/entry/src/main/java/com/ufreedom/demo/transition/BeerFloating.java new file mode 100644 index 0000000000000000000000000000000000000000..33bce918838c0d3fca501f6843826d906016b2ab --- /dev/null +++ b/entry/src/main/java/com/ufreedom/demo/transition/BeerFloating.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2015 UFreedom + * + * 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.ufreedom.demo.transition; + +import com.ufreedom.demo.util.AnimatorStateChangedListener; +import com.ufreedom.floatingview.transition.BaseFloatingPathTransition; +import com.ufreedom.floatingview.transition.FloatingPath; +import com.ufreedom.floatingview.transition.PathPosition; +import com.ufreedom.floatingview.transition.YumFloating; +import ohos.agp.animation.Animator; +import ohos.agp.animation.AnimatorValue; +import ohos.agp.render.Path; + +/** + * BeerFloating + * + * @author xujianhong + * @since 2021-03-31 + */ +public class BeerFloating extends BaseFloatingPathTransition { + private static final float MXCOOR0 = -100; + private static final float MYCOOR1 = -200; + private static final float MXCOOR1 = 100; + + private static final float MYCOOR2 = 200; + private static final float MXCOOR2 = -100; + + private static final int MANIMATORVALUE = 500; + private static final long MTRANSLATEDURATION = 600L; + + private static final long MALPHASTARTDELAY = 550L; + private static final long MALPHADURATION = 300L; + + /** + * getFloatingPath + * + * @return FloatingPath + */ + @Override + public FloatingPath getFloatingPath() { + Path path = new Path(); + path.rLineTo(MXCOOR0, 0); + path.quadTo(0, MYCOOR1, MXCOOR1, 0); + path.quadTo(0, MYCOOR2, MXCOOR2, 0); + return FloatingPath.create(path, false); + } + + /** + * applyFloating + * + * @param yumFloating + */ + @Override + public void applyFloating(final YumFloating yumFloating) { + AnimatorValue translateAnimator = new AnimatorValue(); + translateAnimator.setDuration(MTRANSLATEDURATION); + translateAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float value) { + PathPosition floatingPosition = getFloatingPosition(value * MANIMATORVALUE); + yumFloating.setTranslationX(floatingPosition.x); + yumFloating.setTranslationY(floatingPosition.y); + } + }); + AnimatorValue alphaAnimation = new AnimatorValue(); + alphaAnimation.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + yumFloating.setAlpha(1 - v); + } + }); + + alphaAnimation.setStateChangedListener(new AnimatorStateChangedListener() { + @Override + public void onEnd(Animator animator) { + yumFloating.clear(); + } + }); + alphaAnimation.setDelay(MALPHASTARTDELAY); + alphaAnimation.setDuration(MALPHADURATION); + translateAnimator.start(); + alphaAnimation.start(); + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/ufreedom/demo/transition/PlaneFloating.java b/entry/src/main/java/com/ufreedom/demo/transition/PlaneFloating.java new file mode 100644 index 0000000000000000000000000000000000000000..8167e62f702dcf67fca46da7e665de506fdb860c --- /dev/null +++ b/entry/src/main/java/com/ufreedom/demo/transition/PlaneFloating.java @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2015 UFreedom + * + * 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.ufreedom.demo.transition; + +import com.ufreedom.demo.UiUtils; +import com.ufreedom.demo.util.AnimatorStateChangedListener; +import com.ufreedom.floatingview.spring.SimpleReboundListener; +import com.ufreedom.floatingview.spring.SpringHelper; +import com.ufreedom.floatingview.transition.BaseFloatingPathTransition; +import com.ufreedom.floatingview.transition.FloatingPath; +import com.ufreedom.floatingview.transition.PathPosition; +import com.ufreedom.floatingview.transition.YumFloating; +import com.ufreedom.floatingview.util.LogUtil; +import ohos.agp.animation.Animator; +import ohos.agp.animation.AnimatorValue; +import ohos.agp.render.Path; +import ohos.app.Context; + +/** + * PlaneFloating + * + * @author xujianhong + * @since 2021-03-31 + */ +public class PlaneFloating extends BaseFloatingPathTransition { + private static final float MXCOOR0 = 100; + private static final float MYCOOR0 = -300; + private static final float MYCOOR1 = -600; + private static final float MLINETOYCOOR1 = -100; + private static final float MPROGRESS = 2110; + private static final long MDURATION = 3000L; + private static final double MBOUNCINESS = 14; + private static final double MSPEED = 15; + private int mScreenHeight; + + /** + * PlaneFloating + * + * @param context + */ + public PlaneFloating(Context context) { + mScreenHeight = UiUtils.getScreenWidth(context); + } + + /** + * getFloatingPath + * + * @return FloatingPath + */ + @Override + public FloatingPath getFloatingPath() { + Path path = new Path(); + path.moveTo(0, 0); + path.quadTo(MXCOOR0, MYCOOR0, 0, MYCOOR1); + path.rLineTo(0, -mScreenHeight + MLINETOYCOOR1); + return FloatingPath.create(path, false); + } + + /** + * applyFloating + * + * @param yumFloating + */ + @Override + public void applyFloating(final YumFloating yumFloating) { + AnimatorValue translateAnimator = new AnimatorValue(); + translateAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + PathPosition floatingPosition = getFloatingPosition(v * MPROGRESS); + yumFloating.setTranslationX(floatingPosition.x); + yumFloating.setTranslationY(floatingPosition.y); + LogUtil.error("animatorValue", "x" + floatingPosition.x + " y" + floatingPosition.y); + } + }); + + translateAnimator.setStateChangedListener(new AnimatorStateChangedListener() { + @Override + public void onEnd(Animator animator) { + yumFloating.setTranslationX(0); + yumFloating.setTranslationY(0); + yumFloating.setAlpha(0f); + yumFloating.clear(); + } + }); + SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f, MBOUNCINESS, MSPEED) + .reboundListener(new SimpleReboundListener() { + @Override + public void onReboundUpdate(double currentValue) { + yumFloating.setScaleX((float) currentValue); + yumFloating.setScaleY((float) currentValue); + } + }).start(yumFloating); + + translateAnimator.setDuration(MDURATION); + translateAnimator.start(); + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/ufreedom/demo/transition/StarFloating.java b/entry/src/main/java/com/ufreedom/demo/transition/StarFloating.java new file mode 100644 index 0000000000000000000000000000000000000000..205ca5cdd4c22c8fd9be692c9063258caf526f71 --- /dev/null +++ b/entry/src/main/java/com/ufreedom/demo/transition/StarFloating.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2015 UFreedom + * + * 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.ufreedom.demo.transition; + +import com.ufreedom.demo.util.AnimatorStateChangedListener; +import com.ufreedom.floatingview.spring.SimpleReboundListener; +import com.ufreedom.floatingview.spring.SpringHelper; +import com.ufreedom.floatingview.transition.FloatingTransition; +import com.ufreedom.floatingview.transition.YumFloating; +import ohos.agp.animation.Animator; +import ohos.agp.animation.AnimatorValue; + +/** + * StarFloating + * + * @author xujianhong + * @since 2021-03-31 + */ +public class StarFloating implements FloatingTransition { + private static final double MBOUNCINESS = 10; + private static final double MSPEED = 15; + private static final long MROTATEDURATION = 500L; + private static final int MROTATEANIMATORVALUE = 360; + private static final long MTRANSLATEDURATION = 600L; + private static final long MTRANSLATEANIMATORVALUE = 500L; + + /** + * applyFloating + * + * @param yumFloating + */ + @Override + public void applyFloating(final YumFloating yumFloating) { + SpringHelper.createWithBouncinessAndSpeed(0.0f, 1.0f, MBOUNCINESS, MSPEED) + .reboundListener(new SimpleReboundListener() { + @Override + public void onReboundUpdate(double currentValue) { + yumFloating.setScaleX((float) currentValue); + yumFloating.setScaleY((float) currentValue); + } + }).start(yumFloating); + AnimatorValue translateAnimator = new AnimatorValue(); + translateAnimator.setDuration(MTRANSLATEDURATION); + translateAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + yumFloating.setTranslationY(-v * MTRANSLATEANIMATORVALUE); + } + }); + + translateAnimator.setStateChangedListener(new AnimatorStateChangedListener() { + @Override + public void onEnd(Animator animator) { + yumFloating.setAlpha(0f); + yumFloating.clear(); + } + }); + setRotateAnimator(yumFloating).start(); + translateAnimator.start(); + } + + /** + * setRotateAnimator + * + * @param yumFloating + * @return AnimatorValue + */ + private AnimatorValue setRotateAnimator(YumFloating yumFloating) { + AnimatorValue rotateAnimator = new AnimatorValue(); + + // 持续时长 + rotateAnimator.setDuration(MROTATEDURATION); + + // 循环次数 + rotateAnimator.setLoopedCount(AnimatorValue.INFINITE); + rotateAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() { + @Override + public void onUpdate(AnimatorValue animatorValue, float v) { + yumFloating.setRotation(v * MROTATEANIMATORVALUE); + } + }); + return rotateAnimator; + } +} diff --git a/entry/src/main/java/com/ufreedom/demo/util/AnimatorStateChangedListener.java b/entry/src/main/java/com/ufreedom/demo/util/AnimatorStateChangedListener.java new file mode 100644 index 0000000000000000000000000000000000000000..9c61af788ca35fb8acc8d9051122cea480bcb838 --- /dev/null +++ b/entry/src/main/java/com/ufreedom/demo/util/AnimatorStateChangedListener.java @@ -0,0 +1,80 @@ +/* + * 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 an 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.ufreedom.demo.util; + +import ohos.agp.animation.Animator; + +/** + * AnimatorStateChanged + * + * @author xujianhong + * @since 2021-04-23 + */ +public class AnimatorStateChangedListener implements Animator.StateChangedListener { + /** + * 开始动画 + * + * @param animator + */ + @Override + public void onStart(Animator animator) { + } + + /** + * 停止动画 + * + * @param animator + */ + @Override + public void onStop(Animator animator) { + } + + /** + * 取消动画 + * + * @param animator + */ + @Override + public void onCancel(Animator animator) { + } + + /** + * 结束动画 + * + * @param animator + */ + @Override + public void onEnd(Animator animator) { + } + + /** + * Pause + * + * @param animator + */ + @Override + public void onPause(Animator animator) { + } + + /** + * Resume + * + * @param animator + */ + @Override + public void onResume(Animator animator) { + } +} diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..11ae65be6152d082c98a860d8dba9c5b351e82e7 --- /dev/null +++ b/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "color_them", + "value": "#6d5f88" + } + ] +} \ 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..211064a859ef63a15007cc7bbc5b7ae72c3f6bb3 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "app_name", + "value": "FloatingView" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "HelloWorld", + "value": "Hello World" + } + ] +} \ 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/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..707cf5bd9c6ce0cf1bbe77871e9eb4fcba2784ff --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/entry/src/main/resources/base/layout/ic_like.xml b/entry/src/main/resources/base/layout/ic_like.xml new file mode 100644 index 0000000000000000000000000000000000000000..34f22a7b4b735069f16a0a256b26bd1454336a64 --- /dev/null +++ b/entry/src/main/resources/base/layout/ic_like.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/demo/src/main/res/drawable-xxhdpi/beer.png b/entry/src/main/resources/base/media/beer.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/beer.png rename to entry/src/main/resources/base/media/beer.png diff --git a/entry/src/main/resources/base/media/bike.png b/entry/src/main/resources/base/media/bike.png new file mode 100644 index 0000000000000000000000000000000000000000..169504c8d0e69fa6cf08cfb0e19557fa7c8579d9 Binary files /dev/null and b/entry/src/main/resources/base/media/bike.png differ diff --git a/demo/src/main/res/drawable-xxhdpi/clock.png b/entry/src/main/resources/base/media/clock.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/clock.png rename to entry/src/main/resources/base/media/clock.png diff --git a/demo/src/main/res/drawable-xxhdpi/command_line.png b/entry/src/main/resources/base/media/command_line.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/command_line.png rename to entry/src/main/resources/base/media/command_line.png diff --git a/demo/src/main/res/drawable-xxhdpi/floating_plane.png b/entry/src/main/resources/base/media/floating_plane.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/floating_plane.png rename to entry/src/main/resources/base/media/floating_plane.png diff --git a/demo/src/main/res/drawable-xxhdpi/floating_view_title.png b/entry/src/main/resources/base/media/floating_view_title.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/floating_view_title.png rename to entry/src/main/resources/base/media/floating_view_title.png diff --git a/demo/src/main/res/drawable-xxhdpi/ice_cream.png b/entry/src/main/resources/base/media/ice_cream.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/ice_cream.png rename to entry/src/main/resources/base/media/ice_cream.png diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/entry/src/main/resources/base/media/icon.png differ diff --git a/demo/src/main/res/drawable-xxhdpi/like.png b/entry/src/main/resources/base/media/like.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/like.png rename to entry/src/main/resources/base/media/like.png diff --git a/demo/src/main/res/drawable-xxhdpi/milk.png b/entry/src/main/resources/base/media/milk.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/milk.png rename to entry/src/main/resources/base/media/milk.png diff --git a/demo/src/main/res/drawable-xxhdpi/paper_airplane.png b/entry/src/main/resources/base/media/paper_airplane.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/paper_airplane.png rename to entry/src/main/resources/base/media/paper_airplane.png diff --git a/demo/src/main/res/drawable-xxhdpi/soda.png b/entry/src/main/resources/base/media/soda.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/soda.png rename to entry/src/main/resources/base/media/soda.png diff --git a/demo/src/main/res/drawable-xxhdpi/star.png b/entry/src/main/resources/base/media/star.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/star.png rename to entry/src/main/resources/base/media/star.png diff --git a/demo/src/main/res/drawable-xxhdpi/star_floating.png b/entry/src/main/resources/base/media/star_floating.png similarity index 100% rename from demo/src/main/res/drawable-xxhdpi/star_floating.png rename to entry/src/main/resources/base/media/star_floating.png diff --git a/entry/src/test/java/com/ufreedom/demo/ExampleTest.java b/entry/src/test/java/com/ufreedom/demo/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ef0261b5aecdabef479f98eb4af432dfdaf7c7e7 --- /dev/null +++ b/entry/src/test/java/com/ufreedom/demo/ExampleTest.java @@ -0,0 +1,9 @@ +package com.ufreedom.demo; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/gif/floatView.gif b/gif/floatView.gif new file mode 100644 index 0000000000000000000000000000000000000000..37f3c438164d31901171d2b4cdec6b96a85666f5 Binary files /dev/null and b/gif/floatView.gif differ diff --git a/gradle.properties b/gradle.properties index aac7c9b4614ccfde6c721f24994cf30885a791d0..0daf1830fbdef07e50a44d74210c8c82f1b66278 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,10 @@ # Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: +# IDE (e.g. DevEco Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. - # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html - # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx1536m - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 13372aef5e24af05341d49695ee84e5f9b594659..490fda8577df6c95960ba7077c43220e5bb2c0d9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04e285f34080d98841a9fac832466aec720aecec..f59159e865d4b59feb1b8c44b001f62fc5d58df4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Mon Dec 28 10:00:20 PST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip diff --git a/gradlew b/gradlew index 9d82f78915133e1c35a6ea51252590fb38efac2f..2fe81a7d95e4f9ad2c9b2a046707d36ceb3980b3 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# 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 +# +# https://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. +# ############################################################################## ## @@ -6,20 +22,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +64,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,26 +75,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -85,7 +105,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -105,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` @@ -134,27 +154,30 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 8a0b282aa6885fb573c106b3551f7275c5f17e8e..62bd9b9ccefea2b65ae41e5d9a545e2021b90a1d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -8,14 +24,17 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +65,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +78,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/images/classdiagram.png b/images/classdiagram.png deleted file mode 100644 index feffb1d536c5c86d2e9f344927dede8ca96588f0..0000000000000000000000000000000000000000 Binary files a/images/classdiagram.png and /dev/null differ diff --git a/images/coordinate.png b/images/coordinate.png deleted file mode 100644 index d1a828122f06468fa01420a0e80a07424787b2c8..0000000000000000000000000000000000000000 Binary files a/images/coordinate.png and /dev/null differ diff --git a/images/demo.gif b/images/demo.gif deleted file mode 100644 index 9cab5eacaeb611b94eb07a5e7c96cfdb3453b22a..0000000000000000000000000000000000000000 Binary files a/images/demo.gif and /dev/null differ diff --git a/images/floating_anim.gif b/images/floating_anim.gif deleted file mode 100644 index 224b579edea69d9d15d16113999ee20c13f60878..0000000000000000000000000000000000000000 Binary files a/images/floating_anim.gif and /dev/null differ diff --git a/settings.gradle b/settings.gradle index a75c18be2a5dfe6dd9015f53ef9487748b5affae..8517c3f4e9f2e6222c0dccee292fd75d1cac5748 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':demo', ':FloatingViewLib' +include ':entry', ':FloatingViewLib'