diff --git a/.buildscript/deploy_snapshot.sh b/.buildscript/deploy_snapshot.sh deleted file mode 100755 index d2f49851791e8a733aab37cbe45ba41a46500b4b..0000000000000000000000000000000000000000 --- a/.buildscript/deploy_snapshot.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# -# Deploy a jar, source jar, and javadoc jar to Sonatype's snapshot repo. -# -# Adapted from https://coderwall.com/p/9b_lfq and -# http://benlimmer.com/2013/12/26/automatically-publish-javadoc-to-gh-pages-with-travis-ci/ and -# https://github.com/JakeWharton/RxBinding/blob/master/.buildscript/deploy_snapshot.sh - -SLUG="vanniktech/VNTNumberPickerPreference" -JDK="oraclejdk8" -BRANCH="master" - -set -e - -if [ "$TRAVIS_REPO_SLUG" != "$SLUG" ]; then - echo "Skipping snapshot deployment: wrong repository. Expected '$SLUG' but was '$TRAVIS_REPO_SLUG'." -elif [ "$TRAVIS_JDK_VERSION" != "$JDK" ]; then - echo "Skipping snapshot deployment: wrong JDK. Expected '$JDK' but was '$TRAVIS_JDK_VERSION'." -elif [ "$TRAVIS_PULL_REQUEST" != "false" ]; then - echo "Skipping snapshot deployment: was pull request." -elif [ "$TRAVIS_BRANCH" != "$BRANCH" ]; then - echo "Skipping snapshot deployment: wrong branch. Expected '$BRANCH' but was '$TRAVIS_BRANCH'." -else - echo "Deploying snapshot..." - ./gradlew clean build uploadArchives - echo "Snapshot deployed!" -fi \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8827cb305eea33a7f235ff2004cff2685177860e..0000000000000000000000000000000000000000 --- a/.travis.yml +++ /dev/null @@ -1,44 +0,0 @@ -language: android - -android: - components: - - platform-tools - - tools - - android-23 - - build-tools-23.0.2 - - extra-android-support - - extra-android-m2repository - -licenses: - - 'android-sdk-license-.+' - -jdk: - - oraclejdk8 - -before_install: - - pip install --user codecov - -install: true - -script: ./gradlew clean build - -after_success: - - .buildscript/deploy_snapshot.sh - - codecov - -env: - global: - - secure: "q4zX1iPp19XKbkbj3SHQVas+mHAHaowMWyJmVmbm4uPdTZI8Au/Q8+S4peVTp4IAgq0rFUvILDU6qWffl0+Cp4CGH9sIQALyzN1P3DUt9FGt2svCr0OjR2kcX6xdV//ncyTr5Z49uFwH7Fjmg9vXts/xNbwMnBed77Rn9RDpwJo=" - - secure: "zRgnhwOMHJEPNCKmIxp1ESl6kLKTwHmcIJV9EIkVBIArR+jp/n/lD32fJlPo9N2oaAmXKzMyVE2XSBGTWF17bmdwqQ6BgaTUcRJBnRwNAzDRGIwPYFMOS0KPPHKamezwv46y/vdA0bOA3t7Sax+L6xZbZzf2YrhJk0GMSDl+vy4=" - -branches: - except: - - gh-pages - -notifications: - email: false - -cache: - directories: - - $HOME/.gradle - - $HOME/.m2 diff --git a/1_overview.png b/1_overview.png deleted file mode 100755 index 2092bbf1b83a106312368ac1e396f55e0e5ffaed..0000000000000000000000000000000000000000 Binary files a/1_overview.png and /dev/null differ diff --git a/2_number_picker.png b/2_number_picker.png deleted file mode 100755 index 2d484c836d10044de4a2dd6591e31b64f62462d1..0000000000000000000000000000000000000000 Binary files a/2_number_picker.png and /dev/null differ diff --git a/3_start.png b/3_start.png deleted file mode 100755 index 23dfb1784ec7733d1cc844a731d537b4fe22698c..0000000000000000000000000000000000000000 Binary files a/3_start.png and /dev/null differ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..c846c5b6d46c7c53a03b41c5cbb65053c7528c80 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +0.0.1-SNAPSHOT +-------------- + +ohos 第一个版本,完整实现了原库的全部 api \ No newline at end of file diff --git a/README.OPENSOURCE.md b/README.OPENSOURCE.md new file mode 100644 index 0000000000000000000000000000000000000000..c221e080d6ba786d2829526d3cbc12e6e85ff3e6 --- /dev/null +++ b/README.OPENSOURCE.md @@ -0,0 +1,19 @@ +[ + + { + + "Name": "VNTNumberPickerPreference", + + "License": "Apache License", + + "License File": "LICENSE", + + "Version Number": "1.0.0", + + "Upstream URL": "https://github.com/vanniktech/VNTNumberPickerPreference", + + "Description": "这是一个易于使用的自定义首选项,它将打开一个带有数字选择器的对话框。该值将自动保存,您可以在XML中方便地设置default-,min-和maxValue。" + + } + +] \ No newline at end of file diff --git a/README.md b/README.md index c69ce90786e3eebf3014e3aef34f394011fb7264..0b977f417373328b2c3f7560e47870f639ea593e 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,103 @@ -VNTNumberPickerPreference -========================= - -This is an easy to use custom preference, which opens a dialog with a number picker. The value gets automatically saved and you can set the default-, min- and maxValue conveniently in the XML. - -```xml - -``` - -# Setup - -**build.gradle** - -```groovy -compile 'com.vanniktech:vntnumberpickerpreference:1.0.0' -compile 'com.vanniktech:vntnumberpickerpreference:1.0.1-SNAPSHOT' -``` - -Modules are located on [Maven Central](https://oss.sonatype.org/#nexus-search;quick~vntnumberpickerpreference). - -Go to your preference XML file and insert the above mentioned XML tag. Afterwards you are good to go and can run your project! - -# Get font size +# VNTNumberPickerPreference +#### 项目介绍 +- 项目名称:VNTNumberPickerPreference数字选择器 +- 所属系列:openharmony的第三方组件适配移植 +- 功能:实现VNTNumberPickerPreference数字选择器值自动保存 +- 项目移植状态:主功能完成 +- 调用差异:无 +- 基线版本: Release v1.0.0 +- 开发版本:sdk5,DevEco Studio2.1 Release + +#### 效果演示 + +#### 安装教程 +1.在项目根目录下的build.gradle文件中, + + ``` + allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } + } + ``` + +2.在entry模块的build.gradle文件中, + + ``` + dependencies { + implementation('com.gitee.chinasoft_ohos:vntNumber_PickerPre:0.0.1-SNAPSHOT') + ...... + } + ``` + +在sdk5,DevEco Studio2.1 Release下项目可直接运行 +如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, +并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 + +#### 使用说明 +在点击事件中初始化弹窗布局 + + parameterEntity.setKey(Constants.FONT_SIZE); + parameterEntity.setMinValue(8); + parameterEntity.setMaxValue(100); + parameterEntity.setWheelModeEnabled(true); + parameterEntity.setValue(fontContent.getText()); + parameterEntity.setTitle(fontTitle.getText()); + new XPopup.Builder(getContext()) + .popupAnimation(PopupAnimation.NoAnimation) + .setPopupCallback(new SimpleCallback() { + @Override + public void onDismiss(BasePopupView basePopupView) { + // 完全隐藏的时候执行 + fontContent.setText(PreferenceUtils.getString(getApplicationContext(), Constants.FONT_SIZE, "25")); + } + }) + .asCustom(new CustomPickerPopup(parameterEntity)) + .show(); + +ParameterEntity为实体类 +设置Preferences存储key + + parameterEntity.setKey(Constants.FONT_SIZE); +设置最小值 + + parameterEntity.setMinValue(8); +设置最大值 + + parameterEntity.setMaxValue(8); +设置是否可以循环滚动 + + parameterEntity.setWheelModeEnabled(true); +设置当前Value值 + + parameterEntity.setValue(fontContent.getText()); +设置Title值 + + parameterEntity.setTitle(fontTitle.getText()); +获取字体大小 + + PreferenceUtils.getString(getApplicationContext(), Constants.FONT_SIZE, "25") + +#### 测试信息 + +CodeCheck代码测试无异常 + +CloudTest代码测试无异常 + +火绒安全病毒安全检测通过 + +当前版本demo功能与原组件基本无差异 + +#### 版本迭代 + +- 0.0.1-SNAPSHOT +#### 版权和许可信息 -```java -SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); -int fonftSize = sharedPreferences.getInt("preference_font_size", getResources().getInteger(R.integer.font_size_default_value)); ``` - -# Proguard - -No configuration needed. - -# Preview - -Image of VNTNumberPickerPreference - -# License - Copyright (C) 2014-2016 Vanniktech - Niklas Baudy Licensed under the Apache License, Version 2.0 + +``` \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 491565aec234bdf5ad70c9c901dbb5dedfa5251e..0000000000000000000000000000000000000000 --- a/app/build.gradle +++ /dev/null @@ -1,65 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion rootProject.ext.compileSdkVersion as int - buildToolsVersion rootProject.ext.buildToolsVersion as String - - compileOptions { - sourceCompatibility rootProject.ext.javaVersion as JavaVersion - targetCompatibility rootProject.ext.javaVersion as JavaVersion - } - - defaultConfig { - applicationId "com.vanniktech.vntnumberpickerpreference.sample" - minSdkVersion rootProject.ext.minSdkVersion as int - targetSdkVersion rootProject.ext.targetSdkVersion as int - versionCode rootProject.ext.versionCode as int - versionName rootProject.ext.versionName as String - } - - def shouldSign = project.hasProperty('RELEASE_STORE_FILE') && project.hasProperty('RELEASE_STORE_PASSWORD') && project.hasProperty('RELEASE_KEY_ALIAS') && project.hasProperty('RELEASE_KEY_PASSWORD') - - if (shouldSign) { - signingConfigs { - release { - // http://stackoverflow.com/a/21020469/1979703 - storeFile file(RELEASE_STORE_FILE) - storePassword RELEASE_STORE_PASSWORD - keyAlias RELEASE_KEY_ALIAS - keyPassword RELEASE_KEY_PASSWORD - } - } - } - - applicationVariants.all { variant -> - variant.outputs.each { output -> - output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk")) - } - } - - buildTypes { - release { - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - shrinkResources true - zipAlignEnabled true - - if (shouldSign) { - signingConfig signingConfigs.release - } - } - - debug { - versionNameSuffix '-RC' - } - } -} - -dependencies { - compile project(':library') - - compile rootProject.ext.supportAppCompat - - debugCompile rootProject.ext.leakCanaryDebug - releaseCompile rootProject.ext.leakCanaryRelease -} \ No newline at end of file diff --git a/app/lint.xml b/app/lint.xml deleted file mode 100644 index 0a15a63bcbaf8168f091bfc59bcc98da18dcc190..0000000000000000000000000000000000000000 --- a/app/lint.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/proguard-rules.txt b/app/proguard-rules.txt deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml deleted file mode 100644 index 722ff1e51b9eaf78884122df594e7059f393fc93..0000000000000000000000000000000000000000 --- a/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/MainActivity.java b/app/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/MainActivity.java deleted file mode 100644 index b712dd679554f9aacc98981e9f57a07a06b716c1..0000000000000000000000000000000000000000 --- a/app/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/MainActivity.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.vanniktech.vntnumberpickerpreference.sample; - -import android.content.SharedPreferences; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.v7.app.AppCompatActivity; -import android.text.Html; -import android.text.method.LinkMovementMethod; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.TextView; - -public class MainActivity extends AppCompatActivity { - private static final int DEFAULT_BODY_SIZE = 180; - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - this.setContentView(R.layout.activity_main); - - final TextView checkItOutOnGitHubTextView = (TextView) this.findViewById(R.id.check_it_out_on_github); - checkItOutOnGitHubTextView.setMovementMethod(LinkMovementMethod.getInstance()); - checkItOutOnGitHubTextView.setText(Html.fromHtml(this.getString(R.string.check_it_out_on_github))); - - final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - final TextView bodySizeTextView = (TextView) this.findViewById(R.id.body_size); - bodySizeTextView.setTextSize(sharedPreferences.getInt("preference_font_size", this.getResources().getInteger(R.integer.font_size_default_value))); - bodySizeTextView.setText(this.getString(R.string.body_size).concat(" - " + sharedPreferences.getInt("preference_body_size", DEFAULT_BODY_SIZE))); - } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - this.getMenuInflater().inflate(R.menu.main, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - final int id = item.getItemId(); - - if (id == R.id.action_settings) { - this.startActivity(SettingsActivity.start(this)); - } else { - return super.onOptionsItemSelected(item); - } - - return true; - } -} diff --git a/app/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/SettingsActivity.java b/app/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/SettingsActivity.java deleted file mode 100644 index e7d81f8e42aca9b2b578b7dfaa09f914dd3aa2e4..0000000000000000000000000000000000000000 --- a/app/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/SettingsActivity.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.vanniktech.vntnumberpickerpreference.sample; - -import android.app.Activity; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceFragment; -import android.support.v7.app.AppCompatActivity; -import android.widget.Toast; - -public class SettingsActivity extends AppCompatActivity { - public static Intent start(final Activity activity) { - return new Intent(activity, SettingsActivity.class); - } - - @Override - public void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - this.setContentView(R.layout.frame_layout); - this.getFragmentManager().beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit(); - } - - public static class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener, SharedPreferences.OnSharedPreferenceChangeListener { - private Preference preferenceCallback; - private Preference preferenceCustomSummary; - - @Override - public void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - this.addPreferencesFromResource(R.xml.preferences); - - preferenceCallback = this.findPreference("preference_callback"); - preferenceCallback.setOnPreferenceChangeListener(this); - - preferenceCustomSummary = this.findPreference("preference_custom_summary"); - this.getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); - } - - @Override - public boolean onPreferenceChange(final Preference preference, final Object newValue) { - if (preference.equals(preferenceCallback)) { - final int value = (int) newValue; - Toast.makeText(getActivity(), "New value is " + value, Toast.LENGTH_SHORT).show(); - return true; - } - - return false; - } - - @Override - public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) { - if (preferenceCustomSummary != null && key.equals(preferenceCustomSummary.getKey())) { - final int value = sharedPreferences.getInt(key, 0); - preferenceCustomSummary.setSummary("My custom summary text. Value is " + value); - } - } - } -} diff --git a/app/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/VNTNumberPickerPreferenceApplication.java b/app/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/VNTNumberPickerPreferenceApplication.java deleted file mode 100644 index 54d5dcac2ed63368505d2bda14cb2a377e48e254..0000000000000000000000000000000000000000 --- a/app/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/VNTNumberPickerPreferenceApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.vanniktech.vntnumberpickerpreference.sample; - -import android.app.Application; - -import com.squareup.leakcanary.LeakCanary; - -public class VNTNumberPickerPreferenceApplication extends Application { - @Override - public void onCreate() { - super.onCreate(); - - LeakCanary.install(this); - } -} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index b9395e7be71927ce0ebd3c5ad8b490f18efb69ed..0000000000000000000000000000000000000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/frame_layout.xml b/app/src/main/res/layout/frame_layout.xml deleted file mode 100644 index de08336314407ef5a158dfa92c059b1a11e721e1..0000000000000000000000000000000000000000 --- a/app/src/main/res/layout/frame_layout.xml +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml deleted file mode 100644 index 4573dcbbb0075518248a3c0569b8d735f182af2a..0000000000000000000000000000000000000000 --- a/app/src/main/res/menu/main.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index cde69bcccec65160d92116f20ffce4fce0b5245c..0000000000000000000000000000000000000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index c133a0cbd379f5af6dbf1a899a0293ca5eccfad0..0000000000000000000000000000000000000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index bfa42f0e7b91d006d22352c9ff2f134e504e3c1d..0000000000000000000000000000000000000000 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index 324e72cdd7480cb983fa1bcc7ce686e51ef87fe7..0000000000000000000000000000000000000000 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml deleted file mode 100644 index 0ec1ffc2c430d296775031f3b1ec87022608177f..0000000000000000000000000000000000000000 --- a/app/src/main/res/values-w820dp/dimens.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - 64dp - - diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml deleted file mode 100644 index de8c31af68767ca90ea98a8ed3524c3856231751..0000000000000000000000000000000000000000 --- a/app/src/main/res/values/colors.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - #3F51B5 - #283593 - #E91E63 - - \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml deleted file mode 100644 index d9efc05229bafd2d5a0767e5448a7f32de94aa8b..0000000000000000000000000000000000000000 --- a/app/src/main/res/values/dimens.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - 16dp - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml deleted file mode 100644 index a094f30feb3181c522fcc8722180b5dd5064f299..0000000000000000000000000000000000000000 --- a/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - VNTNumberPickerPreference - Settings - Font size - Body size - Preview of VNTNumberPickerPreference - <a href="https://github.com/vanniktech/VNTNumberPickerPreference">Check it out on GitHub</a> - - 25 - 8 - 100 - - \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml deleted file mode 100644 index 64d60daa25ee10cf6f74d63dd5fa5e17aba3661f..0000000000000000000000000000000000000000 --- a/app/src/main/res/values/styles.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml deleted file mode 100644 index 0844c2089356377ce13dfcb2ab2877ca40fdaec7..0000000000000000000000000000000000000000 --- a/app/src/main/res/xml/preferences.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle index 04f28b35f03003a44a2f5abb38f72cba8547b2e2..78d567d3213cdfab2ccc9585e8ae4a61f09a532c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,63 +1,41 @@ -apply plugin: 'com.github.ben-manes.versions' -apply plugin: 'com.vanniktech.code.quality.tools' -apply plugin: 'com.vanniktech.android.junit.jacoco' +// 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 { - mavenCentral() + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } jcenter() - maven { url 'https://plugins.gradle.org/m2/' } } dependencies { - classpath 'com.vanniktech:gradle-code-quality-tools-plugin:0.4.0' - classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.4.0' - classpath 'com.vanniktech:gradle-maven-publish-plugin:0.1.0' - - classpath 'com.android.tools.build:gradle:2.1.0' - classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0' - classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.8' + classpath 'com.huawei.ohos:hap:2.4.4.2' + classpath 'com.huawei.ohos:decctest:1.0.0.7' } } -codeQualityTools { - lint { - textReport = true - } -} - -junitJacoco { - ignoreProjects = ['app'] // Don't care about sample -} - -subprojects { +allprojects { repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } jcenter() + mavenCentral() } - - plugins.apply('net.ltgt.errorprone') -} - -ext { - minSdkVersion = 14 - compileSdkVersion = 23 - targetSdkVersion = 23 - buildToolsVersion = '23.0.2' - - supportLibraryVersion = '23.2.1' - leakCanaryVersion = '1.3.1' - - versionCode = VERSION_CODE - versionName = VERSION_NAME - - supportAppCompat = "com.android.support:appcompat-v7:$supportLibraryVersion" - - leakCanaryDebug = "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion" - leakCanaryRelease = "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion" - - javaVersion = JavaVersion.VERSION_1_7 } - -task wrapper(type: Wrapper) { - gradleVersion = '2.13' - distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" -} \ No newline at end of file diff --git a/code_quality_tools/checkstyle.xml b/code_quality_tools/checkstyle.xml deleted file mode 100644 index 585bbb7e1a3ffddd99128ebdd034efa819ebe4c2..0000000000000000000000000000000000000000 --- a/code_quality_tools/checkstyle.xml +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/code_quality_tools/findbugs-filter.xml b/code_quality_tools/findbugs-filter.xml deleted file mode 100644 index 7b5656d846c183f12731a9d193f20acfffa3e8ee..0000000000000000000000000000000000000000 --- a/code_quality_tools/findbugs-filter.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/code_quality_tools/pmd.xml b/code_quality_tools/pmd.xml deleted file mode 100644 index f20e16e3b9966ea6150ff61abf6637c8e6df7e45..0000000000000000000000000000000000000000 --- a/code_quality_tools/pmd.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - Custom ruleset for Android application - - .*/R.java - .*/gen/.* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/entry/.gitignore b/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..796b96d1c402326528b4ba3c12ee9d92d0e212e9 --- /dev/null +++ b/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..72af0ff8a337fb5e1517c5d5deaf0bd8eb1c4e01 --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 4 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' + implementation 'io.openharmony.tpc.thirdlib:XPopup:1.0.3' + implementation('com.gitee.chinasoft_ohos:vntNumber_PickerPre:0.0.1-SNAPSHOT') + implementation 'io.openharmony.tpc.thirdlib:RippleEffect:1.0.1' +} +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..b185c0bf5566351595e7b933752b5f50f5133254 --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,67 @@ +{ + "app": { + "bundleName": "com.vanniktech.vntnumberpickerpreference.sample", + "vendor": "vanniktech", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.vanniktech.vntnumberpickerpreference.sample", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "metaData": { + "customizeData": [ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.NoTitleBar", + "extra": "" + } + ] + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.vanniktech.vntnumberpickerpreference.sample.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + }, + { + "orientation": "unspecified", + "name": "com.vanniktech.vntnumberpickerpreference.sample.SettingsAbility", + "icon": "$media:icon", + "description": "$string:settingsability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/MainAbility.java b/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..4f8434b34aa83e8d401d28695ae270062e90b287 --- /dev/null +++ b/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/MainAbility.java @@ -0,0 +1,17 @@ +package com.vanniktech.vntnumberpickerpreference.sample; + +import com.vanniktech.vntnumberpickerpreference.sample.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.agp.window.service.WindowManager; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + // 状态栏颜色 + WindowManager.getInstance().getTopWindow().get().setStatusBarColor(0xff283593); + } +} diff --git a/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/MyApplication.java b/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..b8c937a19425be186811137307eca9ac1d6746cf --- /dev/null +++ b/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/MyApplication.java @@ -0,0 +1,11 @@ +package com.vanniktech.vntnumberpickerpreference.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/vanniktech/vntnumberpickerpreference/sample/SettingsAbility.java b/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/SettingsAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..3c34f3300b527b1cf781f7823ed73f0a775f161c --- /dev/null +++ b/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/SettingsAbility.java @@ -0,0 +1,16 @@ +package com.vanniktech.vntnumberpickerpreference.sample; + +import com.vanniktech.vntnumberpickerpreference.sample.slice.SettingsAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.window.service.WindowManager; + +public class SettingsAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(SettingsAbilitySlice.class.getName()); + // 状态栏颜色 + WindowManager.getInstance().getTopWindow().get().setStatusBarColor(0xff283593); + } +} diff --git a/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/slice/MainAbilitySlice.java b/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..df1ea3989bf4ecef85a347f93158102b01001375 --- /dev/null +++ b/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/slice/MainAbilitySlice.java @@ -0,0 +1,120 @@ +package com.vanniktech.vntnumberpickerpreference.sample.slice; + +import com.vanniktech.vntnumberpickerpreference.Constants; +import com.vanniktech.vntnumberpickerpreference.PreferenceUtils; +import com.vanniktech.vntnumberpickerpreference.sample.ResourceTable; +import com.vanniktech.vntnumberpickerpreference.sample.SettingsAbility; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; +import ohos.agp.components.AttrHelper; +import ohos.agp.components.Component; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.Image; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.PopupDialog; +import ohos.agp.window.service.Display; +import ohos.agp.window.service.DisplayAttributes; +import ohos.agp.window.service.DisplayManager; +import ohos.utils.IntentConstants; +import ohos.utils.net.Uri; + +import java.util.Optional; + +public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener { + private Image settingImage; + private Text checkItOutOnGitHubTextView; + private Text bodySizeTextView; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + initComponent(); + initData(); + } + + public void initComponent() { + settingImage = (Image) findComponentById(ResourceTable.Id_settingImage);checkItOutOnGitHubTextView = (Text) findComponentById(ResourceTable.Id_check_it_out_on_github); + bodySizeTextView = (Text) findComponentById(ResourceTable.Id_body_size); + settingImage.setClickedListener(this::onClick); + checkItOutOnGitHubTextView.setClickedListener(this::onClick); + } + + public void initData() { + bodySizeTextView.setText("Body size - " + PreferenceUtils.getString(getApplicationContext(), Constants.BODY_SIZE, "180")); + bodySizeTextView.setTextSize(AttrHelper.vp2px(Integer.parseInt(PreferenceUtils.getString(getApplicationContext(), Constants.FONT_SIZE, "25")), getContext())); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } + + @Override + public void onClick(Component component) { + switch (component.getId()) { + case ResourceTable.Id_settingImage: + Optional + display = DisplayManager.getInstance().getDefaultDisplay(this); + DisplayAttributes displayAttributes = display.get().getAttributes(); + PopupDialog menuDialog = new PopupDialog(this, null); + DirectionalLayout menuComponent = (DirectionalLayout) LayoutScatter.getInstance(this) + .parse(ResourceTable.Layout_custom_setting_popup, null, false); + Text textSetting = (Text) menuComponent.findComponentById(ResourceTable.Id_text); + DirectionalLayout dl = (DirectionalLayout) menuComponent.findComponentById(ResourceTable.Id_dl); + textSetting.setWidth(getWindow().getLayoutConfig().get().width / 2); + ShapeElement element = new ShapeElement(); + element.setCornerRadius(10); + dl.setBackground(element); + textSetting.setBackground(element); + menuDialog.setCornerRadius(10); + + menuDialog.setCustomComponent(menuComponent); + menuDialog.showOnCertainPosition(1, displayAttributes.width / 4 - AttrHelper.vp2px(10, getContext()), -displayAttributes.width + 130); + menuDialog.setAutoClosable(true); + menuDialog.setAlignment(LayoutAlignment.RIGHT | LayoutAlignment.TOP); + menuDialog.show(); + textSetting.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + menuDialog.destroy(); + Intent intent = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(getAbilityPackageContext().getBundleName()) + .withAbilityName(SettingsAbility.class.getName()) + .build(); + intent.setOperation(operation); + startAbility(intent); + } + }); + break; + case ResourceTable.Id_check_it_out_on_github: + initWeb("https://github.com/vanniktech/VNTNumberPickerPreference"); + break; + default: + } + } + + /* + * 浏览器 + * */ + private void initWeb(String urlString) { + Intent intents = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withUri(Uri.parse(urlString)) + .withAction(IntentConstants.ACTION_SEARCH) + .build(); + intents.setOperation(operation); + startAbility(intents); + } +} diff --git a/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/slice/SettingsAbilitySlice.java b/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/slice/SettingsAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..96d05bdd1ad53382464948649a12f7dbe39314f9 --- /dev/null +++ b/entry/src/main/java/com/vanniktech/vntnumberpickerpreference/sample/slice/SettingsAbilitySlice.java @@ -0,0 +1,178 @@ +package com.vanniktech.vntnumberpickerpreference.sample.slice; + +import com.andexert.library.RippleView; +import com.lxj.xpopup.XPopup; +import com.lxj.xpopup.core.BasePopupView; +import com.lxj.xpopup.enums.PopupAnimation; +import com.lxj.xpopup.interfaces.SimpleCallback; +import com.vanniktech.vntnumberpickerpreference.Constants; +import com.vanniktech.vntnumberpickerpreference.CustomPickerPopup; +import com.vanniktech.vntnumberpickerpreference.ParameterEntity; +import com.vanniktech.vntnumberpickerpreference.PreferenceUtils; +import com.vanniktech.vntnumberpickerpreference.sample.MainAbility; +import com.vanniktech.vntnumberpickerpreference.sample.MyApplication; +import com.vanniktech.vntnumberpickerpreference.sample.ResourceTable; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; +import ohos.agp.components.Component; +import ohos.agp.components.Image; +import ohos.agp.components.Text; + +public class SettingsAbilitySlice extends AbilitySlice implements Component.ClickedListener { + private Image imageFinish; + private RippleView rvFont; + private RippleView rvBody; + private RippleView rvCallback; + private RippleView rvCustom; + private Text fontTitle; + private Text bodyTitle; + private Text callbackTitle; + private Text customTitle; + private Text fontContent; + private Text bodyContent; + private Text callbackContent; + private Text customContent; + private ParameterEntity parameterEntity = new ParameterEntity(); + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_settings); + initComponent(); + initData(); + } + + public void initComponent() { + imageFinish = (Image) findComponentById(ResourceTable.Id_image_finish); + rvFont = (RippleView) findComponentById(ResourceTable.Id_rv_font); + rvBody = (RippleView) findComponentById(ResourceTable.Id_rv_body); + rvCallback = (RippleView) findComponentById(ResourceTable.Id_rv_callback); + rvCustom = (RippleView) findComponentById(ResourceTable.Id_rv_custom); + fontTitle = (Text) findComponentById(ResourceTable.Id_font_title); + bodyTitle = (Text) findComponentById(ResourceTable.Id_body_title); + callbackTitle = (Text) findComponentById(ResourceTable.Id_callback_title); + customTitle = (Text) findComponentById(ResourceTable.Id_custom_title); + fontContent = (Text) findComponentById(ResourceTable.Id_font_content); + bodyContent = (Text) findComponentById(ResourceTable.Id_body_content); + callbackContent = (Text) findComponentById(ResourceTable.Id_callback_content); + customContent = (Text) findComponentById(ResourceTable.Id_custom_content); + imageFinish.setClickedListener(this::onClick); + rvFont.setClickedListener(this::onClick); + rvBody.setClickedListener(this::onClick); + rvCallback.setClickedListener(this::onClick); + rvCustom.setClickedListener(this::onClick); + } + + public void initData() { + fontContent.setText(PreferenceUtils.getString(getApplicationContext(), Constants.FONT_SIZE, "25")); + bodyContent.setText(PreferenceUtils.getString(getApplicationContext(), Constants.BODY_SIZE, "180")); + callbackContent.setText(PreferenceUtils.getString(getApplicationContext(), Constants.CALLBACK, "1")); + customContent.setText(PreferenceUtils.getString(getApplicationContext(), Constants.CUSTOM_SUMMARY, "10")); + parameterEntity.setContext(getContext()); + parameterEntity.setAbilitySlice(this); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } + + @Override + public void onClick(Component component) { + switch (component.getId()) { + case ResourceTable.Id_image_finish: + Intent intent = new Intent(); + Operation operation = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(getAbilityPackageContext().getBundleName()) + .withAbilityName(MainAbility.class.getName()) + .build(); + intent.setOperation(operation); + startAbility(intent); + terminateAbility(); + break; + case ResourceTable.Id_rv_font: + parameterEntity.setKey(Constants.FONT_SIZE); + parameterEntity.setMinValue(8); + parameterEntity.setMaxValue(100); + parameterEntity.setWheelModeEnabled(true); + parameterEntity.setValue(fontContent.getText()); + parameterEntity.setTitle(fontTitle.getText()); + new XPopup.Builder(getContext()) + .popupAnimation(PopupAnimation.NoAnimation) + .setPopupCallback(new SimpleCallback() { + @Override + public void onDismiss(BasePopupView basePopupView) { + // 完全隐藏的时候执行 + fontContent.setText(PreferenceUtils.getString(getApplicationContext(), Constants.FONT_SIZE, "25")); + } + }) + .asCustom(new CustomPickerPopup(parameterEntity)) + .show(); + break; + case ResourceTable.Id_rv_body: + parameterEntity.setKey(Constants.BODY_SIZE); + parameterEntity.setMinValue(40); + parameterEntity.setMaxValue(250); + parameterEntity.setWheelModeEnabled(false); + parameterEntity.setValue(bodyContent.getText()); + parameterEntity.setTitle(bodyTitle.getText()); + new XPopup.Builder(getContext()) + .popupAnimation(PopupAnimation.NoAnimation) + .setPopupCallback(new SimpleCallback() { + @Override + public void onDismiss(BasePopupView basePopupView) { + // 完全隐藏的时候执行 + bodyContent.setText(PreferenceUtils.getString(getApplicationContext(), Constants.BODY_SIZE, "180")); + } + }) + .asCustom(new CustomPickerPopup(parameterEntity)) + .show(); + break; + case ResourceTable.Id_rv_callback: + parameterEntity.setKey(Constants.CALLBACK); + parameterEntity.setMinValue(0); + parameterEntity.setMaxValue(10); + parameterEntity.setWheelModeEnabled(false); + parameterEntity.setValue(callbackContent.getText()); + parameterEntity.setTitle(callbackTitle.getText()); + new XPopup.Builder(getContext()) + .popupAnimation(PopupAnimation.NoAnimation) + .setPopupCallback(new SimpleCallback() { + @Override + public void onDismiss(BasePopupView basePopupView) { + // 完全隐藏的时候执行 + callbackContent.setText(PreferenceUtils.getString(getApplicationContext(), Constants.CALLBACK, "1")); + } + }) + .asCustom(new CustomPickerPopup(parameterEntity)) + .show(); + break; + case ResourceTable.Id_rv_custom: + parameterEntity.setKey(Constants.CUSTOM_SUMMARY); + parameterEntity.setMinValue(0); + parameterEntity.setMaxValue(100); + parameterEntity.setWheelModeEnabled(false); + parameterEntity.setValue(customContent.getText()); + parameterEntity.setTitle(customTitle.getText()); + new XPopup.Builder(getContext()) + .popupAnimation(PopupAnimation.NoAnimation) + .setPopupCallback(new SimpleCallback() { + @Override + public void onDismiss(BasePopupView basePopupView) { + // 完全隐藏的时候执行 + customContent.setText("My custom summary text. Value is " + PreferenceUtils.getString(getApplicationContext(), Constants.CUSTOM_SUMMARY, "10")); + } + }) + .asCustom(new CustomPickerPopup(parameterEntity)) + .show(); + break; + } + } +} 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..a1b7d42087dd759ad6095b80bd9321dddfbf1a32 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "app_name", + "value": "VNTNumberPickerPreference" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + }, + { + "name": "settingsability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "settingsability_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/graphic/background_ability_settings.xml b/entry/src/main/resources/base/graphic/background_ability_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..a002c2353e78af3a15235e00738328ff566bc085 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_settings.xml @@ -0,0 +1,8 @@ + + + + + \ 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..16b48349b18adfcea4c029d9b8623796276c641f --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_settings.xml b/entry/src/main/resources/base/layout/ability_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0ee91eee9bcec7b797ba766840d99e273d87881 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_settings.xml @@ -0,0 +1,176 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/custom_setting_popup.xml b/entry/src/main/resources/base/layout/custom_setting_popup.xml new file mode 100644 index 0000000000000000000000000000000000000000..ce4ce66a5a4e1cafb44bcaf42ee1c92233f38a31 --- /dev/null +++ b/entry/src/main/resources/base/layout/custom_setting_popup.xml @@ -0,0 +1,28 @@ + + + + + + + + + \ 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/app/src/main/res/drawable-nodpi/preview.png b/entry/src/main/resources/base/media/preview.png old mode 100755 new mode 100644 similarity index 100% rename from app/src/main/res/drawable-nodpi/preview.png rename to entry/src/main/resources/base/media/preview.png diff --git a/entry/src/main/resources/base/media/return_image.png b/entry/src/main/resources/base/media/return_image.png new file mode 100644 index 0000000000000000000000000000000000000000..0ea22f239a1b84e9f68f3542b2903913bd024162 Binary files /dev/null and b/entry/src/main/resources/base/media/return_image.png differ diff --git a/entry/src/main/resources/base/media/setting_image.png b/entry/src/main/resources/base/media/setting_image.png new file mode 100644 index 0000000000000000000000000000000000000000..4a69006b3f8e01100230217cfc29a07c36797ec1 Binary files /dev/null and b/entry/src/main/resources/base/media/setting_image.png differ diff --git a/entry/src/ohosTest/config.json b/entry/src/ohosTest/config.json new file mode 100644 index 0000000000000000000000000000000000000000..4e93dc2ca28d690fed8b02a58fe9c242b1513b6c --- /dev/null +++ b/entry/src/ohosTest/config.json @@ -0,0 +1,41 @@ +{ + "app": { + "bundleName": "com.vanniktech.vntnumberpickerpreference.sample", + "vendor": "vanniktech", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.vanniktech.vntnumberpickerpreference.sample", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "decc.testkit.runner.EntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ] + } +} \ No newline at end of file diff --git a/entry/src/ohosTest/java/com/vanniktech/vntnumberpickerpreference/sample/PreferenceUtilsTest.java b/entry/src/ohosTest/java/com/vanniktech/vntnumberpickerpreference/sample/PreferenceUtilsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d9b11d737e6c192291d80c56d6ff474b9169cf3e --- /dev/null +++ b/entry/src/ohosTest/java/com/vanniktech/vntnumberpickerpreference/sample/PreferenceUtilsTest.java @@ -0,0 +1,79 @@ +/* + * 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.vanniktech.vntnumberpickerpreference.sample; + +import com.vanniktech.vntnumberpickerpreference.Constants; +import com.vanniktech.vntnumberpickerpreference.PreferenceUtils; +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import ohos.app.Context; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * 文件描述 + * + * @since 2021-05-26 + */ +public class PreferenceUtilsTest { + private Context context; + + /** + * 开始 + * + */ + @Before + public void setUp() { + context = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility().getContext(); + } + + /** + * 结束 + * + */ + @After + public void tearDown() { + context = null; + } + + /** + * 存数据 + * + */ + @Test + public void putString() { + PreferenceUtils.putString(context, Constants.FONT_SIZE, "25"); + } + + /** + * 取数据 + * + */ + @Test + public void getString() { + String string = PreferenceUtils.getString(context, Constants.FONT_SIZE, "0"); + System.out.println("-----------" + string); + } + + /** + * 删除数据 + * + */ + @Test + public void deleteString() { + PreferenceUtils.deleteString(context, Constants.FONT_SIZE); + } +} diff --git a/entry/src/test/java/com/vanniktech/vntnumberpickerpreference/sample/ExampleTest.java b/entry/src/test/java/com/vanniktech/vntnumberpickerpreference/sample/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..dd38c2a3b4a4ae1d4c9050fd5dcd4250dd56dcb6 --- /dev/null +++ b/entry/src/test/java/com/vanniktech/vntnumberpickerpreference/sample/ExampleTest.java @@ -0,0 +1,9 @@ +package com.vanniktech.vntnumberpickerpreference.sample; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/gif/VNTNumberPickerPreference.gif b/gif/VNTNumberPickerPreference.gif new file mode 100644 index 0000000000000000000000000000000000000000..4aa41c020d0e6702d87c9836b28ff28da4376b41 Binary files /dev/null and b/gif/VNTNumberPickerPreference.gif differ diff --git a/gradle.properties b/gradle.properties index cdbdd30c7383cd781ae7f5deee9168408b45c2c8..0daf1830fbdef07e50a44d74210c8c82f1b66278 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,10 @@ -VERSION_NAME=1.0.1-SNAPSHOT -VERSION_CODE=8 -GROUP=com.vanniktech - -POM_DESCRIPTION=Custom preference, which opens a dialog with a number picker -POM_URL=https://github.com/vanniktech/VNTNumberPickerPreference -POM_SCM_URL=https://github.com/vanniktech/VNTNumberPickerPreference -POM_SCM_CONNECTION=scm:git@github.com:vanniktech/VNTNumberPickerPreference.git -POM_SCM_DEV_CONNECTION=scm:git@github.com:vanniktech/VNTNumberPickerPreference.git -POM_LICENCE_NAME=The Apache Software License, Version 2.0 -POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt -POM_LICENCE_DIST=repo -POM_DEVELOPER_ID=vanniktech -POM_DEVELOPER_NAME=Niklas Baudy \ No newline at end of file +# Project-wide Gradle settings. +# 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. +# 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 ca78035ef0501d802d4fc55381ef2d5c3ce0ec6e..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 0e53e2a2680846ae612231f9914e437806e09873..f59159e865d4b59feb1b8c44b001f62fc5d58df4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat May 14 17:56:58 CEST 2016 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.13-all.zip diff --git a/gradlew b/gradlew index 27309d92314c57d6e442529f1362bafc8376feae..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. +# ############################################################################## ## @@ -28,16 +44,16 @@ 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="" +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 @@ -109,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"` @@ -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 "$@"` -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# 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" "$@" diff --git a/gradlew.bat b/gradlew.bat index 832fdb6079b4b86ecdc08c2ccf68e6fcbb820852..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 @@ -13,8 +29,11 @@ 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= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -49,7 +68,6 @@ goto fail @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/library/build.gradle b/library/build.gradle index 97fb40fbdfc42cdeab46e10ae8b09266b110a0ff..da7649f79e06855d253231b925bc1caa4c398d24 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,30 +1,23 @@ -apply plugin: 'com.android.library' - -afterEvaluate { - generateReleaseBuildConfig.enabled = false -} - -android { - compileSdkVersion rootProject.ext.compileSdkVersion as int - buildToolsVersion rootProject.ext.buildToolsVersion as String - - compileOptions { - sourceCompatibility rootProject.ext.javaVersion as JavaVersion - targetCompatibility rootProject.ext.javaVersion as JavaVersion - } - +apply plugin: 'com.huawei.ohos.library' +ohos { + compileSdkVersion 5 defaultConfig { - minSdkVersion rootProject.ext.minSdkVersion as int + compatibleSdkVersion 4 } - buildTypes { release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } } } - - resourcePrefix 'vnt_' + } -apply plugin: "com.vanniktech.maven.publish" \ No newline at end of file +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.13' + implementation 'io.openharmony.tpc.thirdlib:XPopup:1.0.3' + implementation 'io.openharmony.tpc.thirdlib:RippleEffect:1.0.1' +} diff --git a/library/gradle.properties b/library/gradle.properties deleted file mode 100644 index c88e7d18547b972fcba3970438a48cca9a1262d7..0000000000000000000000000000000000000000 --- a/library/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_NAME=VNTNumberPickerPreference -POM_ARTIFACT_ID=vntnumberpickerpreference -POM_PACKAGING=aar \ No newline at end of file diff --git a/library/lint.xml b/library/lint.xml deleted file mode 100644 index d5eeb29b5ec643dcf99dfcf6f8e5d0a8f0e04dbd..0000000000000000000000000000000000000000 --- a/library/lint.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro index 1ce1525d30e3a0284400a0036e81929db6b47eea..f7666e47561d514b2a76d5a7dfbb43ede86da92a 100644 --- a/library/proguard-rules.pro +++ b/library/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 /home/nik/android/adt-bundle-linux-x86_64-20140702/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/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml deleted file mode 100644 index d571542359aa16609dc618b32622280bad6e0af4..0000000000000000000000000000000000000000 --- a/library/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/library/src/main/config.json b/library/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..51fcd417e31aa209f784f2c4955d230defe626b6 --- /dev/null +++ b/library/src/main/config.json @@ -0,0 +1,28 @@ +{ + "app": { + "bundleName": "com.vanniktech.vntnumberpickerpreference.sample", + "vendor": "vanniktech", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": { + }, + "module": { + "package": "com.vanniktech.vntnumberpickerpreference", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "library", + "moduleType": "har" + } + } +} \ No newline at end of file diff --git a/library/src/main/java/com/vanniktech/vntnumberpickerpreference/Constants.java b/library/src/main/java/com/vanniktech/vntnumberpickerpreference/Constants.java new file mode 100644 index 0000000000000000000000000000000000000000..62dfe46afb5af8c903dec0aadd7ad28aa9c03f92 --- /dev/null +++ b/library/src/main/java/com/vanniktech/vntnumberpickerpreference/Constants.java @@ -0,0 +1,48 @@ +/* + * 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.vanniktech.vntnumberpickerpreference; + +/** + * 常量类 + * + * @since 2021-05-25 + */ +public final class Constants { + /** + * SPKEYNAME + */ + public static final String SPKEYNAME = "SPKEYNAME"; + /** + * Font size + */ + public static final String FONT_SIZE = "font_size"; + /** + * Body size + */ + public static final String BODY_SIZE = "body_size"; + /** + * Callback + */ + public static final String CALLBACK = "callback"; + /** + * Custom summary + */ + public static final String CUSTOM_SUMMARY = "custom_summary"; + + private Constants() { + } +} + diff --git a/library/src/main/java/com/vanniktech/vntnumberpickerpreference/CustomPickerPopup.java b/library/src/main/java/com/vanniktech/vntnumberpickerpreference/CustomPickerPopup.java new file mode 100644 index 0000000000000000000000000000000000000000..d9d56c32aeeda5efe38beac8d3737a91ee09108c --- /dev/null +++ b/library/src/main/java/com/vanniktech/vntnumberpickerpreference/CustomPickerPopup.java @@ -0,0 +1,101 @@ +/* + * 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.vanniktech.vntnumberpickerpreference; + +import com.lxj.xpopup.animator.PopupAnimator; +import com.lxj.xpopup.core.CenterPopupView; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.DependentLayout; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.Picker; +import ohos.agp.components.Text; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.ToastDialog; + +/** + * 文件描述 + * + * @since 2021-05-21 + */ +public class CustomPickerPopup extends CenterPopupView { + private static final int FROMARGBINT = 0xffffffff; + private static final int CORNERRADIUS = 10; + private static final int WIDTH = 150; + private Picker picker; + private final ParameterEntity mParameterEntity; + + /** + * getIntFromAttr + * + * @param parameterEntity 实体类 + */ + public CustomPickerPopup(ParameterEntity parameterEntity) { + super(parameterEntity.getContext(), null); + this.mParameterEntity = parameterEntity; + } + + // 返回自定义弹窗的布局 + @Override + protected int getImplLayoutId() { + return ResourceTable.Layout_custom_picker_popup; + } + + // 执行初始化操作,比如:findComponentById,设置点击,或者任何你弹窗内的业务逻辑 + @Override + protected void onCreate() { + super.onCreate(); + picker = (Picker) findComponentById(ResourceTable.Id_picker); + DirectionalLayout dlDirectional = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_directional); + ShapeElement element = new ShapeElement(); + element.setRgbColor(RgbColor.fromArgbInt(FROMARGBINT)); + element.setCornerRadius(CORNERRADIUS); + dlDirectional.setBackground(element); + DependentLayout dlDependent = (DependentLayout) findComponentById(ResourceTable.Id_dl_dependent); + dlDependent.setBackground(element); + Text titleText = (Text) findComponentById(ResourceTable.Id_titleText); + titleText.setText(mParameterEntity.getTitle()); + picker.setWheelModeEnabled(mParameterEntity.isWheelModeEnabled()); + picker.setMaxValue(mParameterEntity.getMaxValue()); + picker.setMinValue(mParameterEntity.getMinValue()); + picker.setValue(Integer.parseInt(PreferenceUtils.getString(getContext().getApplicationContext(), + mParameterEntity.getKey(), mParameterEntity.getValue()))); + findComponentById(ResourceTable.Id_cancelText).setClickedListener(component -> { + dismiss(); // 关闭弹窗 + }); + findComponentById(ResourceTable.Id_determineText).setClickedListener(component -> { + PreferenceUtils.putString(getContext().getApplicationContext(), + mParameterEntity.getKey(), String.valueOf(picker.getValue())); + new ToastDialog(getContext()) + .setText("New value is " + picker.getValue()) + // Toast显示在界面中间 + .setAlignment(LayoutAlignment.BOTTOM) + .show(); + dismiss(); // 关闭弹窗 + }); + } + + // 设置自定义动画器,看需要而定 + @Override + protected PopupAnimator getPopupAnimator() { + return super.getPopupAnimator(); + } + + @Override + protected int getMaxWidth() { + return mParameterEntity.getAbilitySlice().getWindow().getLayoutConfig().get().width - WIDTH; + } +} \ No newline at end of file diff --git a/library/src/main/java/com/vanniktech/vntnumberpickerpreference/ParameterEntity.java b/library/src/main/java/com/vanniktech/vntnumberpickerpreference/ParameterEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..3376e6755de161a667716548f42848f919ddc1c3 --- /dev/null +++ b/library/src/main/java/com/vanniktech/vntnumberpickerpreference/ParameterEntity.java @@ -0,0 +1,99 @@ +/* + * 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.vanniktech.vntnumberpickerpreference; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.app.Context; + +/** + * 实体类 + * + * @since 2021-05-25 + */ +public class ParameterEntity { + Context context; + AbilitySlice abilitySlice; + String key; + int minValue; + int maxValue; + boolean isWheelModeEnabled; + String value; + String title; + + public Context getContext() { + return context; + } + + public void setContext(Context context) { + this.context = context; + } + + public AbilitySlice getAbilitySlice() { + return abilitySlice; + } + + public void setAbilitySlice(AbilitySlice abilitySlice) { + this.abilitySlice = abilitySlice; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public int getMinValue() { + return minValue; + } + + public void setMinValue(int minValue) { + this.minValue = minValue; + } + + public int getMaxValue() { + return maxValue; + } + + public void setMaxValue(int maxValue) { + this.maxValue = maxValue; + } + + public boolean isWheelModeEnabled() { + return isWheelModeEnabled; + } + + public void setWheelModeEnabled(boolean isModeEnabled) { + isWheelModeEnabled = isModeEnabled; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/library/src/main/java/com/vanniktech/vntnumberpickerpreference/PreferenceUtils.java b/library/src/main/java/com/vanniktech/vntnumberpickerpreference/PreferenceUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..73c648d302f6dee7fbd1c2bcf4b52911c337fef3 --- /dev/null +++ b/library/src/main/java/com/vanniktech/vntnumberpickerpreference/PreferenceUtils.java @@ -0,0 +1,84 @@ +/* + * 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.vanniktech.vntnumberpickerpreference; + +import ohos.app.Context; +import ohos.data.DatabaseHelper; +import ohos.data.preferences.Preferences; + +/** + * Preference工具类 + * + * @since 2021-05-24 + */ +public class PreferenceUtils { + private static PreferenceUtils instance = null; + + private PreferenceUtils() { + } + + /** + * 静态锁对象 + * + * @return Utils + */ + public static synchronized PreferenceUtils getInstance() { + if (instance == null) { + instance = new PreferenceUtils(); + } + return instance; + } + + /** + * 存放key和value + * + * @param context 上下文 + * @param key key值 + * @param value value值 + */ + public static void putString(Context context, String key, String value) { + DatabaseHelper databaseHelper = new DatabaseHelper(context); + Preferences preferences = databaseHelper.getPreferences(Constants.SPKEYNAME); + preferences.putString(key, value); + preferences.flushSync(); + } + + /** + * 根据key获取value + * + * @param context 上下文 + * @param key key值 + * @param value value值 + * @return String获取的String + */ + public static String getString(Context context, String key, String value) { + DatabaseHelper databaseHelper = new DatabaseHelper(context); + Preferences preferences = databaseHelper.getPreferences(Constants.SPKEYNAME); + return preferences.getString(key, value); + } + + /** + * 根据key获取value + * + * @param context 上下文 + * @param key key值 + */ + public static void deleteString(Context context, String key) { + DatabaseHelper databaseHelper = new DatabaseHelper(context); + Preferences preferences = databaseHelper.getPreferences(Constants.SPKEYNAME); + preferences.delete(key); + } +} diff --git a/library/src/main/java/com/vanniktech/vntnumberpickerpreference/VNTNumberPickerPreference.java b/library/src/main/java/com/vanniktech/vntnumberpickerpreference/VNTNumberPickerPreference.java deleted file mode 100644 index 0e5cddd44533e8af0e39c9bb4e9542babb77882f..0000000000000000000000000000000000000000 --- a/library/src/main/java/com/vanniktech/vntnumberpickerpreference/VNTNumberPickerPreference.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.vanniktech.vntnumberpickerpreference; - -import android.app.AlertDialog.Builder; -import android.content.Context; -import android.content.res.TypedArray; -import android.preference.DialogPreference; -import android.util.AttributeSet; -import android.view.Gravity; -import android.view.ViewGroup.LayoutParams; -import android.widget.LinearLayout; -import android.widget.NumberPicker; - -public class VNTNumberPickerPreference extends DialogPreference { - private static final int MIN_VALUE = 0; - private static final int MAX_VALUE = 100; - private static final boolean WRAP_SELECTOR_WHEEL = false; - - private int selectedValue; - private final int minValue; - private final int maxValue; - private final boolean wrapSelectorWheel; - private NumberPicker numberPicker; - - public VNTNumberPickerPreference(final Context context, final AttributeSet attrs) { - super(context, attrs); - - final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.vnt_NumberPickerPreference); - - minValue = a.getInt(R.styleable.vnt_NumberPickerPreference_vnt_minValue, MIN_VALUE); - maxValue = a.getInt(R.styleable.vnt_NumberPickerPreference_vnt_maxValue, MAX_VALUE); - wrapSelectorWheel = a.getBoolean(R.styleable.vnt_NumberPickerPreference_vnt_setWrapSelectorWheel, WRAP_SELECTOR_WHEEL); - - a.recycle(); - } - - @Override - protected void onSetInitialValue(final boolean restoreValue, final Object defaultValue) { - final int intDefaultValue = defaultValue instanceof Integer ? (int) defaultValue : minValue; - selectedValue = restoreValue ? this.getPersistedInt(intDefaultValue) : intDefaultValue; - this.updateSummary(); - } - - @Override - protected Object onGetDefaultValue(final TypedArray a, final int index) { - return a.getInteger(index, 0); - } - - @Override - protected void onPrepareDialogBuilder(final Builder builder) { - super.onPrepareDialogBuilder(builder); - - numberPicker = new NumberPicker(this.getContext()); - numberPicker.setMinValue(minValue); - numberPicker.setMaxValue(maxValue); - numberPicker.setValue(selectedValue); - numberPicker.setWrapSelectorWheel(wrapSelectorWheel); - numberPicker.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); - - final LinearLayout linearLayout = new LinearLayout(this.getContext()); - linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); - linearLayout.setGravity(Gravity.CENTER); - linearLayout.addView(numberPicker); - - builder.setView(linearLayout); - } - - @Override - protected void onDialogClosed(final boolean positiveResult) { - super.onDialogClosed(positiveResult); - - if (positiveResult && numberPicker != null) { - final int newValue = numberPicker.getValue(); - - if (this.callChangeListener(newValue)) { - this.selectedValue = newValue; - - this.updateSummary(); - this.persistInt(this.selectedValue); - } - } - } - - private void updateSummary() { - this.setSummary(String.valueOf(selectedValue)); - } -} diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml deleted file mode 100644 index 6f720d77dcc084d5a8863f4d834a56562bea4935..0000000000000000000000000000000000000000 --- a/library/src/main/res/values/attrs.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/library/src/main/res/values/library_vntnumberpickerpreference_strings.xml b/library/src/main/res/values/library_vntnumberpickerpreference_strings.xml deleted file mode 100644 index e0ba810ecbbaa57cb707126f7aadece9f2321cfa..0000000000000000000000000000000000000000 --- a/library/src/main/res/values/library_vntnumberpickerpreference_strings.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - year;owner - Niklas Baudy - VNTNumberPickerPreference - This is an easy to use custom preference, which opens a dialog with a number picker. The value gets automatically saved and you can set the default-, min- and maxValue conveniently in the XML. - 0.1.5 - https://github.com/vanniktech/VNTNumberPickerPreference - apache_2_0 - true - https://github.com/vanniktech/VNTNumberPickerPreference - - Niklas Baudy - 2015 - \ No newline at end of file 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..7128059822f0dc00ca2a7cfbe73428f6e9e607c2 --- /dev/null +++ b/library/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "library" + }, + { + "name": "github", + "value": "Check it out on GitHub" + } + ] +} \ No newline at end of file diff --git a/library/src/main/resources/base/layout/custom_picker_popup.xml b/library/src/main/resources/base/layout/custom_picker_popup.xml new file mode 100644 index 0000000000000000000000000000000000000000..36e69901f61a702d2811aa5c359a38ec38545610 --- /dev/null +++ b/library/src/main/resources/base/layout/custom_picker_popup.xml @@ -0,0 +1,62 @@ + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/resources/base/layout/menu_main.xml b/library/src/main/resources/base/layout/menu_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..8b9154d5100b378e92d90a33b7285fb0a795eb05 --- /dev/null +++ b/library/src/main/resources/base/layout/menu_main.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/test/java/com/vanniktech/vntnumberpickerpreference/ExampleTest.java b/library/src/test/java/com/vanniktech/vntnumberpickerpreference/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..54133585291cf2c4e825b0b41e17dc55409c2ae3 --- /dev/null +++ b/library/src/test/java/com/vanniktech/vntnumberpickerpreference/ExampleTest.java @@ -0,0 +1,9 @@ +package com.vanniktech.vntnumberpickerpreference; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/settings.gradle b/settings.gradle index ef1bbc736460937ffe010258cfb0b84b66fecc9f..d0c7ee8440156d4a9324ac5357770747425fef57 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1 @@ -include ':app' -include ':library' \ No newline at end of file +include ':entry', ':library'