diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..767459aec91b3a0e191e29beeeacbd4ad377b245 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx +/.idea/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..a9c8a2aa1d26e1ff3e0fdf32f623df4262be66f6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## 0.0.1-SNAPSHOT + +ohos 第一个版本,完整实现了原库的全部 api +由于模拟器卡顿,建议使用用真机安装测试效果。 +由于系统原因,图片上下滑动会偶发的卡顿,暂时无法解决。 \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..2470daca7a0a1d6e3bb33dea6aca7a1f0561c527 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 yayandroid + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.OPENSOURCE b/README.OPENSOURCE new file mode 100644 index 0000000000000000000000000000000000000000..78bf360580f22a630beff9769a2cd563c7340a2a --- /dev/null +++ b/README.OPENSOURCE @@ -0,0 +1,18 @@ +[ + + { + + "Name": "ParallaxRecyclerView", + + "License": "The MIT License", + + "License File": "LICENSE", + + "Version Number": "master", + + "Upstream URL": "https://github.com/yayaa/ParallaxRecyclerView", + + "Description": "一个视差效果的RecyclerView控件" + } + +] \ No newline at end of file diff --git a/README.md b/README.md index ac6b3c190488ab975c54fdc824cf6e9ee915a001..4c30417dc98299773fd97f529942ad20b7f780b6 100644 --- a/README.md +++ b/README.md @@ -1,76 +1,95 @@ # ParallaxRecyclerView -This library will provide you to have Parallax effect on every item of your RecyclerView. -Sample shows with static images but it can be used with async loading images as well. -Tested with [Picasso][1] -![](http://yayandroid.com/data/github_library/parallax_recyclerview/parallax_recyclerview.gif) +#### 项目介绍 +- 项目名称:ParallaxRecyclerView +- 所属系列:openharmony的第三方组件适配移植 +- 功能:一个视差效果的RecyclerView控件。 +- 项目移植状态:主功能完成 +- 调用差异:无 +- 开发版本:sdk6,DevEco Studio2.2 Beta1 +- 基线版本: master -Compatibility -------------- -This library works on 2.2+ probably earlier as well, but i didn't even bother to test because i believe at some point we have to stop supporting every version ;) -Usage ------ -Get your ParallaxRecyclerView instance, and set its adapter as shown in sample. You need to provide a ParallaxImageView, which will handle parallax effect, on your recyclerView's item. +#### 效果演示 +

+ +

-In your adapter create a ViewHolder which extends ParallaxViewHolder. This will make you implement below method that you need to return your ParallaxImageView's id on item. -```java -@Override -public int getParallaxImageId() { - return R.id.backgroundImage; +#### 安装教程 + +1.在项目根目录下的build.gradle文件中, + ```gradle +allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } } -``` + ``` +2.在entry模块的build.gradle文件中, +```xml + dependencies { + implementation('com.gitee.chinasoft_ohos:ParallaxRecyclerView:0.0.1-SNAPSHOT') + + } +``` +在sdk6,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 + +#### 使用说明 -And this method needs to be called onBindViewHolder method to notify ParallaxImageView that will be displayed once again, so it will re-center itselfs. +RecyclerView xml引用方式: -```java -viewHolder.getBackgroundImage().reuse(); +```xml + +``` +ParallaxImageView xml引用方式: +```xml + + ``` -If you wish to change Parallax effects ratio, you can simple call `setParallaxRatio` on code, or you can set it by xml with `parallax_ratio` attribute. +ParallaxViewHolder Java调用: -## Download -Add library dependency to your `build.gradle` file: +```java + public static class ViewHolder extends ParallaxViewHolder { -[![Maven Central](https://img.shields.io/maven-central/v/com.yayandroid/ParallaxRecyclerView.svg)](http://search.maven.org/#search%7Cga%7C1%7CParallaxRecyclerView) -```groovy -dependencies { - compile 'com.yayandroid:ParallaxRecyclerView:1.1' -} + private final Text textView; + public ViewHolder(Component v) { + super(v); + textView = (Text) v.findComponentById(ResourceTable.Id_title); + } + + @Override + public int getParallaxImageId() { + return ResourceTable.Id_backgroundImage; + } + + public Text getTextView() { + return textView; + } + } ``` +#### 测试信息 +CodeCheck代码测试无异常 -References ----------- +CloudTest代码测试无异常 -This library has been built by our designer's insistence. She's seen [JBParallaxCell library on IOS][2] and want it to have in Android as well. Researches lead me to [this repository][3] but it wasn't quite affective as it is on IOS, so here ParallaxRecyclerView. +病毒安全检测通过 -## License +当前版本demo功能与原组件基本无差异 -``` -The MIT License (MIT) - -Copyright (c) 2015 yayandroid - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -``` +#### 版本迭代 + +- 0.0.1-SNAPSHOT -[1]: https://github.com/square/picasso -[2]: https://github.com/jberlana/JBParallaxCell -[3]: https://github.com/bopbi/Android-Parallax-ListView-Item diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..c90352f34c1dd312747bd6b193d4d6aaf685d2bc --- /dev/null +++ b/build.gradle @@ -0,0 +1,39 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.5.0' + classpath 'com.huawei.ohos:decctest:1.2.4.1' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/library/app/.gitignore b/entry/.gitignore similarity index 100% rename from library/app/.gitignore rename to entry/.gitignore diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..daa90b07a221021717f6656ab70867e010f4d13d --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + + compileSdkVersion 6 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + implementation project(path: ':library') + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html','xml'] +} diff --git a/entry/proguard-rules.pro b/entry/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/entry/src/main/config.json b/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..644828180f83e12ef79acb07cd3f14df7fe3a83d --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,54 @@ +{ + "app": { + "bundleName": "com.yayhos.parallaxrecyclerview.sample", + "vendor": "yayhos", + "version": { + "code": 1000000, + "name": "1.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.yayhos.parallaxrecyclerview.sample", + "name": ".MyApplication", + "mainAbility": "com.yayhos.parallaxrecyclerview.sample.MainAbility", + "deviceType": [ + "phone","tablet" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.yayhos.parallaxrecyclerview.sample.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard", + "metaData": { + "customizeData": [ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.NoTitleBar" + } + ] + } + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/yayhos/parallaxrecyclerview/sample/MainAbility.java b/entry/src/main/java/com/yayhos/parallaxrecyclerview/sample/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..7445e37ed1020d2c704f8e567c3b2b3cbd8deffd --- /dev/null +++ b/entry/src/main/java/com/yayhos/parallaxrecyclerview/sample/MainAbility.java @@ -0,0 +1,21 @@ +package com.yayhos.parallaxrecyclerview.sample; + +import com.yayhos.parallaxrecyclerview.RecyclerView; +import com.yayhos.parallaxrecyclerview.sample.slice.RecyclerAdapter; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.colors.RgbColor; +import ohos.agp.window.service.WindowManager; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + WindowManager.getInstance().getTopWindow().get().setStatusBarColor(new RgbColor(48, 63, 159).asArgbInt()); + super.setUIContent(ResourceTable.Layout_ability_main); + RecyclerView listContainer = (RecyclerView) findComponentById(ResourceTable.Id_list); + RecyclerAdapter testRecyclerAdapter = new RecyclerAdapter(this); + listContainer.setItemProvider(testRecyclerAdapter); + + } +} diff --git a/entry/src/main/java/com/yayhos/parallaxrecyclerview/sample/MyApplication.java b/entry/src/main/java/com/yayhos/parallaxrecyclerview/sample/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..ee86a6450a462753c8e6ec2cab841940dfd98ae8 --- /dev/null +++ b/entry/src/main/java/com/yayhos/parallaxrecyclerview/sample/MyApplication.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.yayhos.parallaxrecyclerview.sample; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/entry/src/main/java/com/yayhos/parallaxrecyclerview/sample/slice/RecyclerAdapter.java b/entry/src/main/java/com/yayhos/parallaxrecyclerview/sample/slice/RecyclerAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..12cf328b3d02ea86181662dcf10872bc35f697cc --- /dev/null +++ b/entry/src/main/java/com/yayhos/parallaxrecyclerview/sample/slice/RecyclerAdapter.java @@ -0,0 +1,111 @@ +package com.yayhos.parallaxrecyclerview.sample.slice; + +import com.yayhos.parallaxrecyclerview.ParallaxViewHolder; +import com.yayhos.parallaxrecyclerview.sample.ResourceTable; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.*; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import ohos.app.Context; +import ohos.global.resource.NotExistException; +import ohos.media.image.ImageSource; +import ohos.media.image.PixelMap; + +import java.io.IOException; +import java.io.InputStream; + +public class RecyclerAdapter extends BaseItemProvider { + private Context mContext; + private final int[] imageIds = new int[]{ResourceTable.Media_test_image_1, + ResourceTable.Media_test_image_2, ResourceTable.Media_test_image_3, + ResourceTable.Media_test_image_4, ResourceTable.Media_test_image_5}; + private static final String FORMAT = "image/jpg"; + + private PixelMap[] pixelMaps; + + + private PixelMap getPixelMapFromResource(Context context, int resId, ImageSource.DecodingOptions decodingOptions) { + PixelMap pixelmap; + try (InputStream drawableInputStream = context.getResourceManager().getResource(resId)) { + ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions(); + sourceOptions.formatHint = FORMAT; + ImageSource imageSource = ImageSource.create(drawableInputStream, sourceOptions); + pixelmap = imageSource.createPixelmap(decodingOptions); + return pixelmap; + } catch (IOException | NotExistException e) { + e.getMessage(); + } + return null; + } + + public RecyclerAdapter(Context context) { + + this.mContext = context; + + pixelMaps = new PixelMap[imageIds.length]; + + for (int i = 0; i < imageIds.length; i++) { + + pixelMaps[i] = getPixelMapFromResource(context, imageIds[i], new ImageSource.DecodingOptions()); + + } + + } + + @Override + public int getCount() { + return 50; + } + + @Override + public Object getItem(int i) { + return i; + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public Component getComponent(int position, Component component, ComponentContainer componentContainer) { + final Component cpt; + ViewHolder holder; + + if (component == null) { + cpt = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_ability_item, null, false); + holder = new ViewHolder(cpt); + cpt.setTag(holder); + + + } else { + cpt = component; + holder = (ViewHolder) cpt.getTag(); + } + holder.getTextView().setText("ROW " + position); + ShapeElement background = new ShapeElement(); + background.setRgbColor(new RgbColor(Color.WHITE.getValue())); + holder.getBackgroundImage().setBackground(background); + holder.getBackgroundImage().setMyPixelMap(pixelMaps[position % imageIds.length]); + return cpt; + } + + public static class ViewHolder extends ParallaxViewHolder { + + private final Text textView; + public ViewHolder(Component v) { + super(v); + textView = (Text) v.findComponentById(ResourceTable.Id_title); + } + + @Override + public int getParallaxImageId() { + return ResourceTable.Id_backgroundImage; + } + + public Text getTextView() { + return textView; + } + } + +} 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..c67d9044ef366609015973849011499174c2c0e9 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "parallaxrecyclerview" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_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_item.xml b/entry/src/main/resources/base/layout/ability_item.xml new file mode 100644 index 0000000000000000000000000000000000000000..f01d55e468e6015ff197be087b2fed6362b8a591 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_item.xml @@ -0,0 +1,23 @@ + + + + + + + \ 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..fe2be45989e8aa925b6c6d1402cd45ad000e6137 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file 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/sample/app/src/main/res/mipmap-xxhdpi/test_image_1.jpg b/entry/src/main/resources/base/media/test_image_1.jpg similarity index 100% rename from sample/app/src/main/res/mipmap-xxhdpi/test_image_1.jpg rename to entry/src/main/resources/base/media/test_image_1.jpg diff --git a/sample/app/src/main/res/mipmap-xxhdpi/test_image_2.jpg b/entry/src/main/resources/base/media/test_image_2.jpg similarity index 100% rename from sample/app/src/main/res/mipmap-xxhdpi/test_image_2.jpg rename to entry/src/main/resources/base/media/test_image_2.jpg diff --git a/sample/app/src/main/res/mipmap-xxhdpi/test_image_3.png b/entry/src/main/resources/base/media/test_image_3.png similarity index 100% rename from sample/app/src/main/res/mipmap-xxhdpi/test_image_3.png rename to entry/src/main/resources/base/media/test_image_3.png diff --git a/sample/app/src/main/res/mipmap-xxhdpi/test_image_4.jpg b/entry/src/main/resources/base/media/test_image_4.jpg similarity index 100% rename from sample/app/src/main/res/mipmap-xxhdpi/test_image_4.jpg rename to entry/src/main/resources/base/media/test_image_4.jpg diff --git a/sample/app/src/main/res/mipmap-xxhdpi/test_image_5.png b/entry/src/main/resources/base/media/test_image_5.png similarity index 100% rename from sample/app/src/main/res/mipmap-xxhdpi/test_image_5.png rename to entry/src/main/resources/base/media/test_image_5.png diff --git a/entry/src/main/resources/en/element/string.json b/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9a65826c45bd78608542e9aa000897a6a99e12d8 --- /dev/null +++ b/entry/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "parallaxrecyclerview" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/entry/src/main/resources/zh/element/string.json b/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cceb47ef7fe45b78bf79a69417b803439cb9b1e6 --- /dev/null +++ b/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "parallaxrecyclerview" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/entry/src/ohosTest/java/com/yayhos/parallaxrecyclerview/sample/ExampleOhosTest.java b/entry/src/ohosTest/java/com/yayhos/parallaxrecyclerview/sample/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..95572f69c14a10338eb059b86309ef893cb8666c --- /dev/null +++ b/entry/src/ohosTest/java/com/yayhos/parallaxrecyclerview/sample/ExampleOhosTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.yayhos.parallaxrecyclerview.sample; + +import com.yayhos.parallaxrecyclerview.ParallaxImageView; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.Image; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +/** + * 测试 + * + * @author wz + * @since 2021-06-25 + */ +public class ExampleOhosTest { + static ParallaxImageView imageView; + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.yayhos.parallaxrecyclerview.sample", actualBundleName); + } + @BeforeClass + public static void set() { + Ability ability = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility(); + imageView =new ParallaxImageView(ability); + + } + @Test + public void testSetId() { + imageView.setId(100); + assertEquals(100, imageView.getId()); + } + @Test + public void testSetBackground() { + ShapeElement background = new ShapeElement(); + background.setRgbColor(new RgbColor(Color.WHITE.getValue())); + imageView.setBackground(background); + assertEquals(background, imageView.getBackgroundElement()); + } + +} \ No newline at end of file diff --git a/entry/src/test/java/com/yayhos/parallaxrecyclerview/sample/ExampleTest.java b/entry/src/test/java/com/yayhos/parallaxrecyclerview/sample/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d5782eb97848b275a59e05943bf6601f72b08c51 --- /dev/null +++ b/entry/src/test/java/com/yayhos/parallaxrecyclerview/sample/ExampleTest.java @@ -0,0 +1,9 @@ +package com.yayhos.parallaxrecyclerview.sample; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/sample/gradle.properties b/gradle.properties similarity index 46% rename from sample/gradle.properties rename to gradle.properties index 1d3591c8a4c9c29578c36c87f80c05a6aea3ee3f..be492496f9a20ac2d980ef4fc30061f4184c1c40 100644 --- a/sample/gradle.properties +++ b/gradle.properties @@ -1,18 +1,13 @@ # 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. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# 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 \ No newline at end of file +# If the Chinese output is garbled, please configure the following parameter. +# This function is enabled by default when the DevEco Studio builds the hap/app,if you need disable gradle parallel,you should set org.gradle.parallel false. +# more information see https://docs.gradle.org/current/userguide/performance.html +# org.gradle.parallel=false +# org.gradle.jvmargs=-Dfile.encoding=GBK \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..490fda8577df6c95960ba7077c43220e5bb2c0d9 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/library/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties similarity index 52% rename from library/gradle/wrapper/gradle-wrapper.properties rename to gradle/wrapper/gradle-wrapper.properties index 0c71e760dc93830dd3411fe50d6f5c86bf0a8f4d..f59159e865d4b59feb1b8c44b001f62fc5d58df4 100644 --- a/library/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Apr 10 15:27:10 PDT 2013 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.2.1-all.zip diff --git a/sample/gradlew b/gradlew old mode 100755 new mode 100644 similarity index 63% rename from sample/gradlew rename to gradlew index 91a7e269e19dfc62e27137a0b57ef3e430cee4fd..2fe81a7d95e4f9ad2c9b2a046707d36ceb3980b3 --- a/sample/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,31 +75,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# 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\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -90,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 @@ -110,10 +125,11 @@ 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"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -138,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/sample/gradlew.bat b/gradlew.bat similarity index 70% rename from sample/gradlew.bat rename to gradlew.bat index 8a0b282aa6885fb573c106b3551f7275c5f17e8e..62bd9b9ccefea2b65ae41e5d9a545e2021b90a1d 100644 --- a/sample/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/image/demo.gif b/image/demo.gif new file mode 100644 index 0000000000000000000000000000000000000000..6d04f2f2a9b40a957c79d37d8b8f686dfa9c2ff9 Binary files /dev/null and b/image/demo.gif differ diff --git a/library/.gitignore b/library/.gitignore index 5a95c3c0754d10eca785deb425b554894467ce48..796b96d1c402326528b4ba3c12ee9d92d0e212e9 100644 --- a/library/.gitignore +++ b/library/.gitignore @@ -1,6 +1 @@ -.gradle -.idea -.DS_Store -/local.properties /build -/captures diff --git a/library/app/app.iml b/library/app/app.iml deleted file mode 100644 index b8adcec939483930eb4a4fb9fa23e31cbcd4ef95..0000000000000000000000000000000000000000 --- a/library/app/app.iml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/library/app/build.gradle b/library/app/build.gradle deleted file mode 100644 index 8bc7f24637c5b603552f49d08e676fec3dae903a..0000000000000000000000000000000000000000 --- a/library/app/build.gradle +++ /dev/null @@ -1,28 +0,0 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 22 - buildToolsVersion "21.1.2" - - defaultConfig { - minSdkVersion 8 - targetSdkVersion 22 - versionCode 2 - versionName "1.1" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - - compile 'com.android.support:appcompat-v7:22.0.0' - compile 'com.android.support:recyclerview-v7:22.0.0' -} - -apply from: '../maven_push.gradle' \ No newline at end of file diff --git a/library/app/proguard-rules.pro b/library/app/proguard-rules.pro deleted file mode 100644 index f6218e850b7d47e765e40457d7177533f798d06d..0000000000000000000000000000000000000000 --- a/library/app/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/yahyabayramoglu/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/library/app/src/androidTest/java/com/yayandroid/parallaxrecyclerview/ApplicationTest.java b/library/app/src/androidTest/java/com/yayandroid/parallaxrecyclerview/ApplicationTest.java deleted file mode 100644 index 68e52af43047a520e16872486a7a9d14338dc99f..0000000000000000000000000000000000000000 --- a/library/app/src/androidTest/java/com/yayandroid/parallaxrecyclerview/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.yayandroid.parallaxrecyclerview; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/library/app/src/main/AndroidManifest.xml b/library/app/src/main/AndroidManifest.xml deleted file mode 100644 index 8de215d90e3a1c381f0cf1d8082dbf6e978f87f2..0000000000000000000000000000000000000000 --- a/library/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/library/app/src/main/java/com/yayandroid/parallaxrecyclerview/ParallaxImageView.java b/library/app/src/main/java/com/yayandroid/parallaxrecyclerview/ParallaxImageView.java deleted file mode 100644 index 4ecddf8511a9d7ef3da0d4021e8687c82b99c990..0000000000000000000000000000000000000000 --- a/library/app/src/main/java/com/yayandroid/parallaxrecyclerview/ParallaxImageView.java +++ /dev/null @@ -1,207 +0,0 @@ -package com.yayandroid.parallaxrecyclerview; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Bitmap; -import android.graphics.Matrix; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.util.AttributeSet; -import android.widget.ImageView; - -/** - * Created by yahyabayramoglu on 15/04/15. - */ -public class ParallaxImageView extends ImageView { - - private final float DEFAULT_PARALLAX_RATIO = 1.2f; - private float parallaxRatio = DEFAULT_PARALLAX_RATIO; - - private boolean DEFAULT_CENTER_CROP = true; - private boolean shouldCenterCrop = DEFAULT_CENTER_CROP; - - private boolean needToTranslate = true; - private ParallaxImageListener listener; - - private int rowYPos = -1; - private int recyclerViewHeight = -1; - private int recyclerViewYPos = -1; - - public interface ParallaxImageListener { - int[] requireValuesForTranslate(); - } - - public ParallaxImageView(Context context) { - super(context); - init(context, null); - } - - public ParallaxImageView(Context context, AttributeSet attrs) { - super(context, attrs); - init(context, attrs); - } - - public ParallaxImageView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(context, attrs); - } - - private void init(Context context, AttributeSet attrs) { - setScaleType(ImageView.ScaleType.MATRIX); - - if (attrs != null) { - TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ParallaxImageView, 0, 0); - this.parallaxRatio = ta.getFloat(R.styleable.ParallaxImageView_parallax_ratio, DEFAULT_PARALLAX_RATIO); - this.shouldCenterCrop = ta.getBoolean(R.styleable.ParallaxImageView_center_crop, DEFAULT_CENTER_CROP); - ta.recycle(); - } - } - - /** - * This trick was needed because there is no way to detect when image is displayed, - * we need to translate image for very first time as well. This will be needed only - * if you are using async image loading... - *

- * # If only there was another way to get notified when image has displayed. - */ - // region EnsureTranslate - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - ensureTranslate(); - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - super.onLayout(changed, left, top, right, bottom); - ensureTranslate(); - } - - @Override - public void setImageDrawable(Drawable drawable) { - super.setImageDrawable(drawable); - ensureTranslate(); - } - - @Override - public void setImageBitmap(Bitmap bm) { - super.setImageBitmap(bm); - ensureTranslate(); - } - - @Override - public void setImageResource(int resId) { - super.setImageResource(resId); - ensureTranslate(); - } - - @Override - public void setImageURI(Uri uri) { - super.setImageURI(uri); - ensureTranslate(); - } - // endregion - - /** - * Notify this view when it is back on recyclerView, so we can reset. - */ - public void reuse() { - this.needToTranslate = true; - } - - public void centerCrop(boolean enable) { - this.shouldCenterCrop = enable; - } - - public void setParallaxRatio(float parallaxRatio) { - this.parallaxRatio = parallaxRatio; - } - - public void setListener(ParallaxImageListener listener) { - this.listener = listener; - } - - public ParallaxImageListener getListener() { - return listener; - } - - public synchronized boolean doTranslate() { - if (getDrawable() == null) { - return false; - } - - if (getListener() != null && getValues()) { - calculateAndMove(); - return true; - } else { - return false; - } - } - - private boolean ensureTranslate() { - if (needToTranslate) { - needToTranslate = !doTranslate(); - } - return !needToTranslate; - } - - private boolean getValues() { - int[] values = getListener().requireValuesForTranslate(); - if (values == null) - return false; - - this.rowYPos = values[0]; - this.recyclerViewHeight = values[1]; - this.recyclerViewYPos = values[2]; - return true; - } - - private void calculateAndMove() { - float distanceFromCenter = (recyclerViewYPos + recyclerViewHeight) / 2 - rowYPos; - - int drawableHeight = getDrawable().getIntrinsicHeight(); - int imageViewHeight = getMeasuredHeight(); - float scale = 1; - if (shouldCenterCrop) { - scale = recomputeImageMatrix(); - drawableHeight *= scale; - } - - float difference = drawableHeight - imageViewHeight; - float move = (distanceFromCenter / recyclerViewHeight) * difference * parallaxRatio; - - moveTo((move / 2) - (difference / 2), scale); - } - - private float recomputeImageMatrix() { - float scale; - final int viewWidth = getWidth() - getPaddingLeft() - getPaddingRight(); - final int viewHeight = getHeight() - getPaddingTop() - getPaddingBottom(); - final int drawableWidth = getDrawable().getIntrinsicWidth(); - final int drawableHeight = getDrawable().getIntrinsicHeight(); - - if (drawableWidth * viewHeight > drawableHeight * viewWidth) { - scale = (float) viewHeight / (float) drawableHeight; - } else { - scale = (float) viewWidth / (float) drawableWidth; - } - - return scale; - } - - private void moveTo(float move, float scale) { - Matrix imageMatrix = getImageMatrix(); - if (scale != 1) { - imageMatrix.setScale(scale, scale); - } - - float[] matrixValues = new float[9]; - imageMatrix.getValues(matrixValues); - float current = matrixValues[Matrix.MTRANS_Y]; - imageMatrix.postTranslate(0, move - current); - - setImageMatrix(imageMatrix); - invalidate(); - } - -} \ No newline at end of file diff --git a/library/app/src/main/java/com/yayandroid/parallaxrecyclerview/ParallaxRecyclerView.java b/library/app/src/main/java/com/yayandroid/parallaxrecyclerview/ParallaxRecyclerView.java deleted file mode 100644 index 390b88734723934616c0e61f56bb001cbd2c5df6..0000000000000000000000000000000000000000 --- a/library/app/src/main/java/com/yayandroid/parallaxrecyclerview/ParallaxRecyclerView.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.yayandroid.parallaxrecyclerview; - -import android.content.Context; -import android.support.v7.widget.RecyclerView; -import android.util.AttributeSet; - -/** - * Created by yahyabayramoglu on 26/04/15. - */ -public class ParallaxRecyclerView extends RecyclerView { - - private OnScrollListener scrollListener; - - public ParallaxRecyclerView(Context context) { - super(context); - init(); - } - - public ParallaxRecyclerView(Context context, AttributeSet attrs) { - super(context, attrs); - init(); - } - - public ParallaxRecyclerView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - init(); - } - - private void init() { - setOnScrollListener(defaultListener); - } - - private OnScrollListener defaultListener = new OnScrollListener() { - @Override - public void onScrollStateChanged(RecyclerView recyclerView, int newState) { - super.onScrollStateChanged(recyclerView, newState); - - if (scrollListener != null) - scrollListener.onScrollStateChanged(recyclerView, newState); - } - - @Override - public void onScrolled(RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - - for (int i = 0; i < recyclerView.getChildCount(); i++) { - ViewHolder viewHolder = recyclerView.getChildViewHolder(recyclerView.getChildAt(i)); - if (viewHolder instanceof ParallaxViewHolder) { - ((ParallaxViewHolder) viewHolder).animateImage(); - } - } - - if (scrollListener != null) - scrollListener.onScrolled(recyclerView, dx, dy); - } - }; - - @Override - public void setOnScrollListener(OnScrollListener listener) { - if (listener != defaultListener) - this.scrollListener = listener; - else - super.setOnScrollListener(listener); - } - -} diff --git a/library/app/src/main/java/com/yayandroid/parallaxrecyclerview/ParallaxViewHolder.java b/library/app/src/main/java/com/yayandroid/parallaxrecyclerview/ParallaxViewHolder.java deleted file mode 100644 index 6cd5a4c8dce1f58e02f558a23512df220774ec75..0000000000000000000000000000000000000000 --- a/library/app/src/main/java/com/yayandroid/parallaxrecyclerview/ParallaxViewHolder.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.yayandroid.parallaxrecyclerview; - -import android.support.v7.widget.RecyclerView; -import android.view.View; - -/** - * Created by yahyabayramoglu on 15/04/15. - */ -public abstract class ParallaxViewHolder extends RecyclerView.ViewHolder implements ParallaxImageView.ParallaxImageListener { - - private ParallaxImageView backgroundImage; - - public abstract int getParallaxImageId(); - - public ParallaxViewHolder(View itemView) { - super(itemView); - - backgroundImage = (ParallaxImageView) itemView.findViewById(getParallaxImageId()); - backgroundImage.setListener(this); - } - - @Override - public int[] requireValuesForTranslate() { - if (itemView.getParent() == null) { - // Not added to parent yet! - return null; - } else { - int[] itemPosition = new int[2]; - itemView.getLocationOnScreen(itemPosition); - - int[] recyclerPosition = new int[2]; - ((RecyclerView) itemView.getParent()).getLocationOnScreen(recyclerPosition); - - return new int[]{itemPosition[1], ((RecyclerView) itemView.getParent()).getMeasuredHeight(), recyclerPosition[1]}; - } - } - - public void animateImage() { - getBackgroundImage().doTranslate(); - } - - public ParallaxImageView getBackgroundImage() { - return backgroundImage; - } -} diff --git a/library/app/src/main/res/values/parallax_attrs.xml b/library/app/src/main/res/values/parallax_attrs.xml deleted file mode 100644 index 193037ab4700f167c1dec586145578c84421fa2c..0000000000000000000000000000000000000000 --- a/library/app/src/main/res/values/parallax_attrs.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index d3ff69d6e7f91950ff157ce7e6b7ab81f0a49d2d..6008a4b01ccc04b47dbe676b73b765e4ed4bfe23 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,19 +1,24 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.library' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { -buildscript { - repositories { - jcenter() + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 4 } - dependencies { - classpath 'com.android.tools.build:gradle:1.1.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } } + } -allprojects { - repositories { - jcenter() - } +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.13' + } diff --git a/library/consumer-rules.pro b/library/consumer-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..9dccc613bc71b04b83531f550bdab2fb667ecfc9 --- /dev/null +++ b/library/consumer-rules.pro @@ -0,0 +1 @@ +# Add har specific ProGuard rules for consumer here. \ No newline at end of file diff --git a/library/gradle.properties b/library/gradle.properties deleted file mode 100644 index 79832fcbaacfc98b9d7111f39dedbb30455d9988..0000000000000000000000000000000000000000 --- a/library/gradle.properties +++ /dev/null @@ -1,39 +0,0 @@ -# Project-wide Gradle settings. - -# IDE (e.g. Android 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. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# 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 - -POM_NAME=ParallaxRecyclerView Library -POM_ARTIFACT_ID=ParallaxRecyclerView -POM_PACKAGING=aar -VERSION_NAME=1.1 -VERSION_CODE=2 -GROUP=com.yayandroid - -POM_DESCRIPTION=ParallaxRecyclerView Library -POM_URL=https://github.com/yayaa/ParallaxRecyclerView -POM_SCM_URL=https://github.com/yayaa/ParallaxRecyclerView -POM_SCM_CONNECTION=scm:https://github.com/yayaa/ParallaxRecyclerView.git -POM_SCM_DEV_CONNECTION=scm:https://github.com/yayaa/ParallaxRecyclerView.git -POM_LICENCE_NAME=MIT License -POM_LICENCE_URL=http://www.opensource.org/licenses/mit-license.php -POM_LICENCE_DIST=repo -POM_DEVELOPER_ID=yayaa -POM_DEVELOPER_NAME=Yahya BAYRAMOGLU - -SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots -RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2 \ No newline at end of file diff --git a/library/gradle/wrapper/gradle-wrapper.jar b/library/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 8c0fb64a8698b08ecc4158d828ca593c4928e9dd..0000000000000000000000000000000000000000 Binary files a/library/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/library/gradlew b/library/gradlew deleted file mode 100755 index 91a7e269e19dfc62e27137a0b57ef3e430cee4fd..0000000000000000000000000000000000000000 --- a/library/gradlew +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# 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\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -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 - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((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" ;; - 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=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/library/gradlew.bat b/library/gradlew.bat deleted file mode 100644 index 8a0b282aa6885fb573c106b3551f7275c5f17e8e..0000000000000000000000000000000000000000 --- a/library/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@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 Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz 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. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -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 - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/library/library.iml b/library/library.iml deleted file mode 100644 index 0264ccf180465acd84c9016fbbfc7aaa7a21364d..0000000000000000000000000000000000000000 --- a/library/library.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/library/maven_push.gradle b/library/maven_push.gradle deleted file mode 100644 index 2f96fe1230acf50270dc8ffe14d00b611ede9cd4..0000000000000000000000000000000000000000 --- a/library/maven_push.gradle +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2013 Chris Banes - * - * 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. - */ - -apply plugin: 'maven' -apply plugin: 'signing' - -def isReleaseBuild() { - return VERSION_NAME.contains("SNAPSHOT") == false -} - -def getReleaseRepositoryUrl() { - return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL - : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -} - -def getSnapshotRepositoryUrl() { - return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL - : "https://oss.sonatype.org/content/repositories/snapshots/" -} - -def getRepositoryUsername() { - return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" -} - -def getRepositoryPassword() { - return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" -} - -afterEvaluate { project -> - uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - pom.groupId = GROUP - pom.artifactId = POM_ARTIFACT_ID - pom.version = VERSION_NAME - - repository(url: getReleaseRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) - } - snapshotRepository(url: getSnapshotRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) - } - - pom.project { - name POM_NAME - packaging POM_PACKAGING - description POM_DESCRIPTION - url POM_URL - - scm { - url POM_SCM_URL - connection POM_SCM_CONNECTION - developerConnection POM_SCM_DEV_CONNECTION - } - - licenses { - license { - name POM_LICENCE_NAME - url POM_LICENCE_URL - distribution POM_LICENCE_DIST - } - } - - developers { - developer { - id POM_DEVELOPER_ID - name POM_DEVELOPER_NAME - } - } - } - } - } - } - - signing { - required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } - sign configurations.archives - } - - //task androidJavadocs(type: Javadoc) { - //source = android.sourceSets.main.allJava - //} - - //task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { - //classifier = 'javadoc' - //from androidJavadocs.destinationDir - //} - - task androidSourcesJar(type: Jar) { - classifier = 'sources' - from android.sourceSets.main.java.sourceFiles - } - - artifacts { - archives androidSourcesJar - } -} \ No newline at end of file diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/library/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/library/settings.gradle b/library/settings.gradle deleted file mode 100644 index e7b4def49cb53d9aa04228dd3edb14c9e635e003..0000000000000000000000000000000000000000 --- a/library/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -include ':app' diff --git a/library/src/main/config.json b/library/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..91f688956303b6bda72c898d7f137ec49b069ccf --- /dev/null +++ b/library/src/main/config.json @@ -0,0 +1,23 @@ +{ + "app": { + "bundleName": "com.yayhos.parallaxrecyclerview.sample", + "vendor": "yayhos", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": { + }, + "module": { + "package": "com.yayhos.parallaxrecyclerview", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "library", + "moduleType": "har" + } + } +} \ No newline at end of file diff --git a/library/src/main/java/com/yayhos/parallaxrecyclerview/ParallaxImageView.java b/library/src/main/java/com/yayhos/parallaxrecyclerview/ParallaxImageView.java new file mode 100644 index 0000000000000000000000000000000000000000..f2ef7a4d63483d874500e119a4e46326b5734fee --- /dev/null +++ b/library/src/main/java/com/yayhos/parallaxrecyclerview/ParallaxImageView.java @@ -0,0 +1,167 @@ +package com.yayhos.parallaxrecyclerview; + +import ohos.agp.components.AttrSet; +import ohos.agp.components.Image; +import ohos.agp.render.Paint; +import ohos.agp.render.PixelMapHolder; +import ohos.agp.utils.Matrix; +import ohos.agp.utils.Point; +import ohos.agp.window.service.Display; +import ohos.agp.window.service.DisplayManager; +import ohos.app.Context; +import ohos.media.image.PixelMap; + +import java.math.BigDecimal; +import java.util.Optional; + +/** + * Created by yahyabayramoglu on 15/04/15. + */ +public class ParallaxImageView extends Image { + + + private static final float DEFAULT_PARALLAX_RATIO = 1.5f; + private float parallaxRatio = DEFAULT_PARALLAX_RATIO; + private ParallaxImageListener listener; + + private int rowYPos = -1; + private int recyclerViewHeight = -1; + private int recyclerViewYPos = -1; + private Context context; + private int index = -1; + private PixelMap myPixelMap; + + public PixelMap getMyPixelMap() { + return myPixelMap; + } + + public void setMyPixelMap(PixelMap myPixelMap) { + this.myPixelMap = myPixelMap; + } + + public interface ParallaxImageListener { + int[] requireValuesForTranslate(); + } + + public ParallaxImageView(Context context) { + super(context); + this.context = context; + init(); + } + + public ParallaxImageView(Context context, AttrSet attrs) { + super(context, attrs); + this.context = context; + init(); + } + + public ParallaxImageView(Context context, AttrSet attrs, String defStyleAttr) { + super(context, attrs, defStyleAttr); + this.context = context; + init(); + } + + private void init() { + + if (getScreenWidth(context) < getScreenHeight(context)) { + imageMatrix.setScale(recomputeImageMatrix(), recomputeImageMatrix()); + + this.addDrawTask((component, canvas) -> { + canvas.save(); + canvas.concat(imageMatrix); + if (index == -1) { + canvas.drawPixelMapHolder(new PixelMapHolder(getMyPixelMap()), 0, -330, new Paint()); + } else { + canvas.drawPixelMapHolder(new PixelMapHolder(getMyPixelMap()), 0, -200, new Paint()); + + } + + canvas.restore(); + }); + } else { + imageMatrix.setScale(recomputeImageMatrix(), recomputeImageMatrix()); + + this.addDrawTask((component, canvas) -> { + canvas.save(); + canvas.concat(imageMatrix); + if (index == -1) { + canvas.drawPixelMapHolder(new PixelMapHolder(getMyPixelMap()), 0, -270, new Paint()); + + } else { + canvas.drawPixelMapHolder(new PixelMapHolder(getMyPixelMap()), 0, -200, new Paint()); + } + canvas.restore(); + }); + } + + } + + + public void setListener(ParallaxImageListener listener) { + this.listener = listener; + } + + public ParallaxImageListener getListener() { + return listener; + } + + public synchronized boolean doTranslate() { + if (getListener() != null && getValues()) { + calculateAndMove(); + return true; + } else { + return false; + } + } + + private boolean getValues() { + int[] values = getListener().requireValuesForTranslate(); + if (values == null){ + return false; + } + this.rowYPos = values[0]; + this.recyclerViewHeight = getScreenHeight(context); + this.recyclerViewYPos = 70; + return true; + } + + private void calculateAndMove() { + float distanceFromCenter = (recyclerViewYPos + recyclerViewHeight) / 2 - rowYPos; + float difference = 1269f; + float move = (distanceFromCenter / recyclerViewHeight) * difference * parallaxRatio; + moveTo((new BigDecimal(move).divide(new BigDecimal(2)) ).subtract (new BigDecimal(difference).divide(new BigDecimal(2)) ).floatValue(), recomputeImageMatrix()); + } + + private float recomputeImageMatrix() { + float Width = getScreenWidth(context); + + BigDecimal num1= new BigDecimal(Width); + BigDecimal num2=num1.divide(new BigDecimal(100)); + BigDecimal num3=num2.multiply(new BigDecimal(0.12f)); + return num3.floatValue(); + } + + Matrix imageMatrix = new Matrix(); + + private void moveTo(float move, float scale) { + imageMatrix = new Matrix(); + imageMatrix.setScale(scale, scale); + imageMatrix.postTranslate(0, move); + index = 0; + invalidate(); + } + + private int getScreenHeight(Context context) { + Optional display = DisplayManager.getInstance().getDefaultDisplay(context); + Point size = new Point(); + display.get().getSize(size); + return (int) size.getPointY(); + } + + private float getScreenWidth(Context context) { + Optional display = DisplayManager.getInstance().getDefaultDisplay(context); + Point size = new Point(); + display.get().getSize(size); + return size.getPointX(); + } +} \ No newline at end of file diff --git a/library/src/main/java/com/yayhos/parallaxrecyclerview/ParallaxViewHolder.java b/library/src/main/java/com/yayhos/parallaxrecyclerview/ParallaxViewHolder.java new file mode 100644 index 0000000000000000000000000000000000000000..a0278bb7ad00a5e83c250773dcc41bac02c8ab08 --- /dev/null +++ b/library/src/main/java/com/yayhos/parallaxrecyclerview/ParallaxViewHolder.java @@ -0,0 +1,33 @@ +package com.yayhos.parallaxrecyclerview; + +import ohos.agp.components.Component; + +public abstract class ParallaxViewHolder implements ParallaxImageView.ParallaxImageListener { + private ParallaxImageView backgroundImage; + Component component; + + public ParallaxViewHolder(Component component) { + this.component = component; + backgroundImage = (ParallaxImageView) component.findComponentById(getParallaxImageId()); + backgroundImage.setListener(this); + } + + public abstract int getParallaxImageId(); + + @Override + public int[] requireValuesForTranslate() { + int[] itemPosition; + itemPosition = component.getLocationOnScreen(); + int[] recyclerPosition = new int[2]; + return new int[]{itemPosition[1], 2499, recyclerPosition[1]}; + + } + + public void animateImage() { + getBackgroundImage().doTranslate(); + } + + public ParallaxImageView getBackgroundImage() { + return backgroundImage; + } +} diff --git a/library/src/main/java/com/yayhos/parallaxrecyclerview/RecyclerView.java b/library/src/main/java/com/yayhos/parallaxrecyclerview/RecyclerView.java new file mode 100644 index 0000000000000000000000000000000000000000..d2f13bc2e2dc0d8ee5b607cfe1f820a8c6c1ded6 --- /dev/null +++ b/library/src/main/java/com/yayhos/parallaxrecyclerview/RecyclerView.java @@ -0,0 +1,47 @@ +package com.yayhos.parallaxrecyclerview; + +import ohos.agp.components.AttrSet; +import ohos.agp.components.Component; +import ohos.agp.components.ListContainer; +import ohos.app.Context; +import ohos.multimodalinput.event.TouchEvent; + + +public class RecyclerView extends ListContainer implements ListContainer.ScrolledListener { + + public RecyclerView(Context context) { + super(context); + init(); + } + + public RecyclerView(Context context, AttrSet attrSet) { + super(context, attrSet); + init(); + } + + public RecyclerView(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + init(); + + + } + + private void init() { + this.setScrolledListener(this); + this.setLongClickable(false); + } + + @Override + public void onContentScrolled(Component component, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { + ListContainer listContainer = (ListContainer) component; + int size = listContainer.getVisibleIndexCount(); + for (int i = 0; i < size; i++) { + Component image = listContainer.getComponentAt(listContainer.getItemPosByVisibleIndex(i)); + if(image.getTag() instanceof ParallaxViewHolder){ + ((ParallaxViewHolder) image.getTag()).animateImage(); + } + + } + } + +} diff --git a/library/src/main/resources/base/element/string.json b/library/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..211a936b6a562815c346636393376e8f1a72a08e --- /dev/null +++ b/library/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "library_library", + "value": "library_library" + } + ] +} diff --git a/library/src/test/java/com/yayhos/parallaxrecyclerview/ExampleTest.java b/library/src/test/java/com/yayhos/parallaxrecyclerview/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6ebf3d438465ed5702544cb728dd8be6472190f5 --- /dev/null +++ b/library/src/test/java/com/yayhos/parallaxrecyclerview/ExampleTest.java @@ -0,0 +1,9 @@ +package com.yayhos.parallaxrecyclerview; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/sample/.gitignore b/sample/.gitignore deleted file mode 100644 index 5a95c3c0754d10eca785deb425b554894467ce48..0000000000000000000000000000000000000000 --- a/sample/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -.gradle -.idea -.DS_Store -/local.properties -/build -/captures diff --git a/sample/.idea/misc.xml b/sample/.idea/misc.xml deleted file mode 100644 index 6b8fbd72bcb6cdbd296b26ed5221ee57b07dfd28..0000000000000000000000000000000000000000 --- a/sample/.idea/misc.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sample/app/.gitignore b/sample/app/.gitignore deleted file mode 100644 index 796b96d1c402326528b4ba3c12ee9d92d0e212e9..0000000000000000000000000000000000000000 --- a/sample/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/sample/app/app.iml b/sample/app/app.iml deleted file mode 100644 index 97852eada51a99a48b9978d97f7d148baee1a563..0000000000000000000000000000000000000000 --- a/sample/app/app.iml +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sample/app/build.gradle b/sample/app/build.gradle deleted file mode 100644 index 4db2f3720c533474bd5c81bda2282cf19201aec5..0000000000000000000000000000000000000000 --- a/sample/app/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 22 - buildToolsVersion "21.1.2" - - defaultConfig { - applicationId "com.yayandroid.parallaxrecyclerview.sample" - minSdkVersion 8 - targetSdkVersion 22 - versionCode 2 - versionName "1.1" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - - compile 'com.android.support:appcompat-v7:22.0.0' - - compile 'com.yayandroid:ParallaxRecyclerView:1.1' - compile 'com.squareup.picasso:picasso:2.5.2' - -} diff --git a/sample/app/proguard-rules.pro b/sample/app/proguard-rules.pro deleted file mode 100644 index f6218e850b7d47e765e40457d7177533f798d06d..0000000000000000000000000000000000000000 --- a/sample/app/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/yahyabayramoglu/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/sample/app/src/androidTest/java/com/yayandroid/parallaxrecyclerview/sample/ApplicationTest.java b/sample/app/src/androidTest/java/com/yayandroid/parallaxrecyclerview/sample/ApplicationTest.java deleted file mode 100644 index f1c2c8dae61d884b100a60f9f5a847f86cdbf3bb..0000000000000000000000000000000000000000 --- a/sample/app/src/androidTest/java/com/yayandroid/parallaxrecyclerview/sample/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.yayandroid.parallaxrecyclerview.sample; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/sample/app/src/main/AndroidManifest.xml b/sample/app/src/main/AndroidManifest.xml deleted file mode 100644 index d15c424154872ebc20226cd9fdf6f966c829ba2f..0000000000000000000000000000000000000000 --- a/sample/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/sample/app/src/main/java/com/yayandroid/parallaxrecyclerview/sample/MainActivity.java b/sample/app/src/main/java/com/yayandroid/parallaxrecyclerview/sample/MainActivity.java deleted file mode 100644 index 81f00a3b1aef4d8b222059376db4196b34a769f9..0000000000000000000000000000000000000000 --- a/sample/app/src/main/java/com/yayandroid/parallaxrecyclerview/sample/MainActivity.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.yayandroid.parallaxrecyclerview.sample; - -import android.support.v7.app.ActionBarActivity; -import android.os.Bundle; -import android.support.v7.widget.LinearLayoutManager; - -import com.yayandroid.parallaxrecyclerview.ParallaxRecyclerView; - -/** - * Created by yahyabayramoglu on 14/04/15. - */ -public class MainActivity extends ActionBarActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - ParallaxRecyclerView recyclerView = (ParallaxRecyclerView) findViewById(R.id.recyclerView); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setHasFixedSize(true); - recyclerView.setAdapter(new TestRecyclerAdapter(this)); - } - -} diff --git a/sample/app/src/main/java/com/yayandroid/parallaxrecyclerview/sample/TestRecyclerAdapter.java b/sample/app/src/main/java/com/yayandroid/parallaxrecyclerview/sample/TestRecyclerAdapter.java deleted file mode 100644 index 6a0fb4370a7f633a6b32a9070b2d89ee035c47a4..0000000000000000000000000000000000000000 --- a/sample/app/src/main/java/com/yayandroid/parallaxrecyclerview/sample/TestRecyclerAdapter.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.yayandroid.parallaxrecyclerview.sample; - -import android.content.Context; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.squareup.picasso.Picasso; -import com.yayandroid.parallaxrecyclerview.ParallaxViewHolder; - -/** - * Created by yahyabayramoglu on 14/04/15. - */ -public class TestRecyclerAdapter extends RecyclerView.Adapter { - - private Context context; - private LayoutInflater inflater; - - /* - private int[] imageIds = new int[]{R.mipmap.test_image_1, - R.mipmap.test_image_2, R.mipmap.test_image_3, - R.mipmap.test_image_4, R.mipmap.test_image_5}; - */ - - private String[] imageUrls = new String[]{ - "http://yayandroid.com/data/github_library/parallax_listview/test_image_1.jpg", - "http://yayandroid.com/data/github_library/parallax_listview/test_image_2.jpg", - "http://yayandroid.com/data/github_library/parallax_listview/test_image_3.png", - "http://yayandroid.com/data/github_library/parallax_listview/test_image_4.jpg", - "http://yayandroid.com/data/github_library/parallax_listview/test_image_5.png", - }; - - public TestRecyclerAdapter(Context context) { - this.context = context; - this.inflater = LayoutInflater.from(context); - } - - @Override - public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) { - return new ViewHolder(inflater.inflate(R.layout.item, viewGroup, false)); - } - - @Override - public void onBindViewHolder(ViewHolder viewHolder, int position) { - // viewHolder.getBackgroundImage().setImageResource(imageIds[position % imageIds.length]); - Picasso.with(context).load(imageUrls[position % imageUrls.length]).into(viewHolder.getBackgroundImage()); - viewHolder.getTextView().setText("Row " + position); - - // # CAUTION: - // Important to call this method - viewHolder.getBackgroundImage().reuse(); - } - - @Override - public int getItemCount() { - return 50; - } - - /** - * # CAUTION: - * ViewHolder must extend from ParallaxViewHolder - */ - public static class ViewHolder extends ParallaxViewHolder { - - private final TextView textView; - - public ViewHolder(View v) { - super(v); - - textView = (TextView) v.findViewById(R.id.label); - } - - @Override - public int getParallaxImageId() { - return R.id.backgroundImage; - } - - public TextView getTextView() { - return textView; - } - } - - -} diff --git a/sample/app/src/main/res/layout/activity_main.xml b/sample/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 8d3d26f185f2556312c797c7d181faa46811ad0c..0000000000000000000000000000000000000000 --- a/sample/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/sample/app/src/main/res/layout/item.xml b/sample/app/src/main/res/layout/item.xml deleted file mode 100644 index 6fabfc6320c4ab3b72a623c7e55cb94731f10857..0000000000000000000000000000000000000000 --- a/sample/app/src/main/res/layout/item.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - diff --git a/sample/app/src/main/res/mipmap-hdpi/ic_launcher.png b/sample/app/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index cde69bcccec65160d92116f20ffce4fce0b5245c..0000000000000000000000000000000000000000 Binary files a/sample/app/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/sample/app/src/main/res/mipmap-mdpi/ic_launcher.png b/sample/app/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index c133a0cbd379f5af6dbf1a899a0293ca5eccfad0..0000000000000000000000000000000000000000 Binary files a/sample/app/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/sample/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/sample/app/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index bfa42f0e7b91d006d22352c9ff2f134e504e3c1d..0000000000000000000000000000000000000000 Binary files a/sample/app/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index 324e72cdd7480cb983fa1bcc7ce686e51ef87fe7..0000000000000000000000000000000000000000 Binary files a/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/sample/app/src/main/res/values/dimens.xml b/sample/app/src/main/res/values/dimens.xml deleted file mode 100644 index 47c82246738c4d056e8030d3a259206f42e8e15d..0000000000000000000000000000000000000000 --- a/sample/app/src/main/res/values/dimens.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - 16dp - 16dp - diff --git a/sample/app/src/main/res/values/strings.xml b/sample/app/src/main/res/values/strings.xml deleted file mode 100644 index 18bcaa9ec4b742487f5656b4e2090733437544da..0000000000000000000000000000000000000000 --- a/sample/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - ParallaxRecyclerView - - Hello world! - Settings - diff --git a/sample/app/src/main/res/values/styles.xml b/sample/app/src/main/res/values/styles.xml deleted file mode 100644 index 766ab9930487aebdf634594950b22d39b44d8125..0000000000000000000000000000000000000000 --- a/sample/app/src/main/res/values/styles.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/sample/build.gradle b/sample/build.gradle deleted file mode 100644 index f6e9073125b2693ab199e4b8fc06d204fdc8a13e..0000000000000000000000000000000000000000 --- a/sample/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - jcenter() - } -} diff --git a/sample/gradle/wrapper/gradle-wrapper.jar b/sample/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 8c0fb64a8698b08ecc4158d828ca593c4928e9dd..0000000000000000000000000000000000000000 Binary files a/sample/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/sample/gradle/wrapper/gradle-wrapper.properties b/sample/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index a84b007783b3fd5da1514cce2acd2f40ec646f74..0000000000000000000000000000000000000000 --- a/sample/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,6 +0,0 @@ -#Thu May 26 15:12:32 EEST 2016 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip diff --git a/sample/sample.iml b/sample/sample.iml deleted file mode 100644 index 23c601e48a1883852977bfb321f1406958123a1f..0000000000000000000000000000000000000000 --- a/sample/sample.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sample/settings.gradle b/sample/settings.gradle deleted file mode 100644 index 9d495b34f861c6ed05009b95cf15aaf24f76ebc0..0000000000000000000000000000000000000000 --- a/sample/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -include ':app' \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..d0c7ee8440156d4a9324ac5357770747425fef57 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':entry', ':library'