diff --git a/.gitignore b/.gitignore
index f21a1dd505a839ab6b0c3a6da3c1816da43aba56..5dfaa310cb4dcfb5ccce8fbfb8a3d8a3963b19e5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1,16 @@
-.gradle/
+*.iml
+.gradle
/local.properties
-.idea/
+/.idea
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
.DS_Store
-build/
-captures/
-
-*.class
-*.iml
-*.pyc
-gradle/local.properties
+/build
+/captures
+.externalNativeBuild
+.cxx
+upload.gradle
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000000000000000000000000000000000000..51dc8503e395fadf517aebf8e28612c5837d16ad
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,2 @@
+## 0.0.1-SNAPSHOT
+* ohos 第一个版本,实现了原库的功能
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..8009fc706a8b720b843e923e57b313aa66980aa2
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+Copyright 2015 jungly
+
+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.
\ No newline at end of file
diff --git a/README.OpenSource b/README.OpenSource
new file mode 100644
index 0000000000000000000000000000000000000000..01b2c95fe03dc32ccd00d3d6ea895b2e836567d5
--- /dev/null
+++ b/README.OpenSource
@@ -0,0 +1,10 @@
+[
+ {
+ "Name": " GridPasswordView ",
+ "License": " Apache License ",
+ "License File": " LICENSE ",
+ "Version Number": " 0.3 ",
+ "Upstream URL": " https://github.com/Jungerr/GridPasswordView ",
+ "Description": " A password view that looks like the pay password view in wechat app and alipay app. "
+ }
+]
\ No newline at end of file
diff --git a/README.md b/README.md
index db866034df9bcf10cd7b2ba301a83126e1d402ee..fb52fa4da976401424d1f88555ce48cfd483306a 100644
--- a/README.md
+++ b/README.md
@@ -1,83 +1,110 @@
# GridPasswordView
-[  ](https://bintray.com/jungerr/maven/gridPasswordView/_latestVersion)
-An android password view that looks like the pay password view in wechat app and alipay app.
-Apache License 2.0.
+#### 项目介绍
-##Quick Overview
+- 项目名称:GridPasswordView
+- 所属系列:OpenHarmony的第三方组件适配移植
+- 功能:密码输入功能
+- 项目移植状态:主功能完成
+- 调用差异:无
+- 开发版本:sdk5,DevEco Studio2.1 beta4
+- 基线版本:GridPasswordView组件 Releases V0.3
- - Download [demo-0.3.apk][2]
- - Screenshots
+#### 项目演示
-![demo][1]
+
+#### 安装教程
-##Getting Started
+ 1.在项目根目录下的build.gradle文件中,
- - Add the dependency to your build.gradle.
-```
-dependencies {
- compile 'com.jungly:gridPasswordView:0.3'
-}
-```
-or Maven:
-```
-
- com.jungly
- gridPasswordView
- 0.3
- aar
-
-```
- - Add the GridPasswordView to your layout.
+ ```
+
+ allprojects {
+ repositories {
+ maven {
+ url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
+ }
+ }
+ }
+ ```
+ 2.在entry模块的build.gradle文件中,
+
+ ```
+ dependencies {
+ implementation('com.gitee.chinasoft_ohos:GridPasswordView:0.0.1-SNAPSHOT')
+ ......
+ }
+ ```
+ 在sdk5,DevEco Studio2.1 beta4下项目可直接运行
+ 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件,
+ 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
+
+#### 使用说明
+1. GridPasswordView是一个密码输入功能的界面。
```xml
-
+
```
+2.使用方法
+```xml
+ 设置边框的颜色
+ app:gpv_grid_color="#ff0000"
+ 设置边框宽度
+ app:gpv_line_width="6"
+ 设置密码的个数
+ app:gpv_password_length="6"
+ 设置密码显示样式
+ app:gpv_password_transformation="$"
+ 设置密码明文密文显示
+ app:gpv_show_password="true"
+ 设置字体大小
+ app:gpv_text_size="30"
+ getPassWord() 获取GridPasswordView输入的密码
+ clearPassword() 清理GridPasswordView控件中的密码
+ togglePasswordVisibility()设置GridPasswordView控件中密码是否明文显示
+ setPasswordType()设置GridPasswordView控件输入类型
+ setOnPasswordChangedListener(OnPasswordChangedListener listener)监听GridPasswordView控件密码的输入变化
+```
+#### 测试信息
+```
+ CodeCheck代码测试无异常
-##How to use
-`getPassWord()` get the text the PasswordView is displaying
-`clearPassword()`: clear password in the view
-`setPassword(String password)` just like the setText(String s) method of textview
-`togglePasswordVisibility()` Toggle the visibility state of this view.
-`setPasswordVisibility(boolean visible)` Set the visibility state of this view.
-`setOnPasswordChangedListener(OnPasswordChangedListener listener)` Register a callback to be invoked when password changed.
-`setPasswordType(PasswordType passwordType)` one of numberPassword 、textPassword 、TEXtextVisiblePassword、textWebPassword
-
-##Other
-If you use this library in your app, please let me know : jungly.ik@gmail.com
-##Contributing
+ CloudTest代码测试无异常
-Yes:) If you found a bug, have an idea how to improve library or have a question, please create new issue or comment existing one. If you would like to contribute code fork the repository and send a pull request.
+ 火绒安全病毒安全检测通过
+```
+#### 版本迭代
+- 0.0.1-SNAPSHOT
-License
----
+#### 版权和许可信息
- Copyright 2015 jungly
- 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
+```
+Copyright 2015 jungly
- http://www.apache.org/licenses/LICENSE-2.0
+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
- 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.
+ http://www.apache.org/licenses/LICENSE-2.0
- [1]: http://jungerr.qiniudn.com/gridpasswordview_0.2.gif
- [2]: https://github.com/Jungerr/GridPasswordView/blob/master/demo/demo-0.3.apk
+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.
+```
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 4b6ddcd6d6e08d15655a4120186d72e4187e34dc..2368e1d63380a3fe53798b21625a9e8dc5b1f91a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,17 +1,37 @@
// 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 5
+ }
+}
+
buildscript {
repositories {
+ maven {
+ url 'https://mirrors.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.0.0'
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
+ classpath 'com.huawei.ohos:hap:2.4.2.7'
+ classpath 'com.huawei.ohos:decctest:1.0.0.6'
}
}
allprojects {
repositories {
+ maven {
+ url 'https://mirrors.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
jcenter()
}
}
diff --git a/demo/build.gradle b/demo/build.gradle
deleted file mode 100644
index d3b35f60956fa7ea38232d839fe16d68e62a9188..0000000000000000000000000000000000000000
--- a/demo/build.gradle
+++ /dev/null
@@ -1,27 +0,0 @@
-apply plugin: 'com.android.application'
-
-android {
- compileSdkVersion 23
- buildToolsVersion "23.0.2"
-
- defaultConfig {
- applicationId "com.jungly.gridpasswordview.demo"
- minSdkVersion 14
- targetSdkVersion 23
- versionCode 2
- versionName "1.2"
- }
- 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:23.1.1'
- compile 'com.jakewharton:butterknife:6.0.0'
- compile 'com.jungly:gridPasswordView:0.3'
-}
diff --git a/demo/demo-0.3.apk b/demo/demo-0.3.apk
deleted file mode 100644
index 51ede07370d57337536384bc4ff9c86011014f76..0000000000000000000000000000000000000000
Binary files a/demo/demo-0.3.apk and /dev/null differ
diff --git a/demo/proguard-rules.pro b/demo/proguard-rules.pro
deleted file mode 100644
index 52757475d953fc200740c4809493efe9251618cb..0000000000000000000000000000000000000000
--- a/demo/proguard-rules.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in /Users/jungly/Develop/Program Files/android-sdk/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the proguardFiles
-# directive in build.gradle.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
diff --git a/demo/src/androidTest/java/com/jungly/gridpasswordview/demo/ApplicationTest.java b/demo/src/androidTest/java/com/jungly/gridpasswordview/demo/ApplicationTest.java
deleted file mode 100644
index 71eabbeb37532032c45095c2fe6335f14f57968b..0000000000000000000000000000000000000000
--- a/demo/src/androidTest/java/com/jungly/gridpasswordview/demo/ApplicationTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.jungly.gridpasswordview.demo;
-
-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/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml
deleted file mode 100644
index 4076b2c109afdf0064710131c2ad965cbc15e9f5..0000000000000000000000000000000000000000
--- a/demo/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/demo/src/main/java/com/jungly/gridpasswordview/demo/MainActivity.java b/demo/src/main/java/com/jungly/gridpasswordview/demo/MainActivity.java
deleted file mode 100644
index 46d14121c55c6389fa982422a71f858ffd8a0a53..0000000000000000000000000000000000000000
--- a/demo/src/main/java/com/jungly/gridpasswordview/demo/MainActivity.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package com.jungly.gridpasswordview.demo;
-
-import android.os.Bundle;
-import android.support.v7.app.ActionBarActivity;
-import android.support.v7.widget.Toolbar;
-import android.util.Log;
-import android.widget.Spinner;
-
-import com.jungly.gridpasswordview.GridPasswordView;
-import com.jungly.gridpasswordview.PasswordType;
-
-import butterknife.ButterKnife;
-import butterknife.InjectView;
-import butterknife.OnCheckedChanged;
-import butterknife.OnItemSelected;
-
-
-public class MainActivity extends ActionBarActivity {
-
- @InjectView(R.id.gpv_normal)
- GridPasswordView gpvNormal;
- @InjectView(R.id.gpv_length)
- GridPasswordView gpvLength;
- @InjectView(R.id.gpv_transformation)
- GridPasswordView gpvTransformation;
- @InjectView(R.id.gpv_passwordType)
- GridPasswordView gpvPasswordType;
- @InjectView(R.id.gpv_customUi)
- GridPasswordView gpvCustomUi;
- @InjectView(R.id.gpv_normail_twice)
- GridPasswordView gpvNormalTwice;
- @InjectView(R.id.toolbar)
- Toolbar toolbar;
- @InjectView(R.id.pswtype_sp)
- Spinner pswtypeSp;
-
- boolean isFirst = true;
- String firstPwd;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ButterKnife.inject(this);
- setSupportActionBar(toolbar);
- toolbar.setTitle(R.string.app_name);
-
- onPwdChangedTest();
- }
-
- @OnCheckedChanged(R.id.psw_visibility_switcher)
- void onCheckedChanged(boolean isChecked) {
- gpvPasswordType.togglePasswordVisibility();
- }
-
- @OnItemSelected(R.id.pswtype_sp)
- void onTypeSelected(int position) {
- switch (position) {
- case 0:
- gpvPasswordType.setPasswordType(PasswordType.NUMBER);
- break;
-
- case 1:
- gpvPasswordType.setPasswordType(PasswordType.TEXT);
- break;
-
- case 2:
- gpvPasswordType.setPasswordType(PasswordType.TEXTVISIBLE);
- break;
-
- case 3:
- gpvPasswordType.setPasswordType(PasswordType.TEXTWEB);
- break;
- }
-
- }
-
- // Test GridPasswordView.clearPassword() in OnPasswordChangedListener.
- // Need enter the password twice and then check the password , like Alipay
- void onPwdChangedTest(){
- gpvNormalTwice.setOnPasswordChangedListener(new GridPasswordView.OnPasswordChangedListener() {
- @Override
- public void onTextChanged(String psw) {
- if (psw.length() == 6 && isFirst){
- gpvNormalTwice.clearPassword();
- isFirst = false;
- firstPwd = psw;
- }else if (psw.length() == 6 && !isFirst){
- if (psw.equals(firstPwd)){
- Log.d("MainActivity", "The password is: " + psw);
- }else {
- Log.d("MainActivity", "password doesn't match the previous one, try again!");
- gpvNormalTwice.clearPassword();
- isFirst = true;
- }
- }
- }
-
- @Override
- public void onInputFinish(String psw) { }
- });
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- ButterKnife.reset(this);
- }
-}
diff --git a/demo/src/main/res/drawable/gridpassword_bg.xml b/demo/src/main/res/drawable/gridpassword_bg.xml
deleted file mode 100644
index 35021f1e0f38db8c8b97e261095c11a366245033..0000000000000000000000000000000000000000
--- a/demo/src/main/res/drawable/gridpassword_bg.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/demo/src/main/res/layout/actionbar_common.xml b/demo/src/main/res/layout/actionbar_common.xml
deleted file mode 100644
index 513dd933d8af90f9aaefa297fa7e35bda3ba10b5..0000000000000000000000000000000000000000
--- a/demo/src/main/res/layout/actionbar_common.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
\ No newline at end of file
diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml
deleted file mode 100644
index 009ba4708f6a16cd7b4101290377e1509c6c5f09..0000000000000000000000000000000000000000
--- a/demo/src/main/res/layout/activity_main.xml
+++ /dev/null
@@ -1,132 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/demo/src/main/res/menu/menu_main.xml b/demo/src/main/res/menu/menu_main.xml
deleted file mode 100644
index 9dee83a1d3f61b72e0f6db8550cb9b66ed5dfe1f..0000000000000000000000000000000000000000
--- a/demo/src/main/res/menu/menu_main.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
diff --git a/demo/src/main/res/mipmap-hdpi/ic_launcher.png b/demo/src/main/res/mipmap-hdpi/ic_launcher.png
deleted file mode 100644
index cde69bcccec65160d92116f20ffce4fce0b5245c..0000000000000000000000000000000000000000
Binary files a/demo/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ
diff --git a/demo/src/main/res/mipmap-mdpi/ic_launcher.png b/demo/src/main/res/mipmap-mdpi/ic_launcher.png
deleted file mode 100644
index c133a0cbd379f5af6dbf1a899a0293ca5eccfad0..0000000000000000000000000000000000000000
Binary files a/demo/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ
diff --git a/demo/src/main/res/mipmap-xhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xhdpi/ic_launcher.png
deleted file mode 100644
index bfa42f0e7b91d006d22352c9ff2f134e504e3c1d..0000000000000000000000000000000000000000
Binary files a/demo/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ
diff --git a/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png b/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png
deleted file mode 100644
index 324e72cdd7480cb983fa1bcc7ce686e51ef87fe7..0000000000000000000000000000000000000000
Binary files a/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ
diff --git a/demo/src/main/res/values-w820dp/dimens.xml b/demo/src/main/res/values-w820dp/dimens.xml
deleted file mode 100644
index 63fc816444614bd64f68a372d1f93211628ee51d..0000000000000000000000000000000000000000
--- a/demo/src/main/res/values-w820dp/dimens.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- 64dp
-
diff --git a/demo/src/main/res/values/color.xml b/demo/src/main/res/values/color.xml
deleted file mode 100644
index c307009debdeff87146efc681322989fdea005e4..0000000000000000000000000000000000000000
--- a/demo/src/main/res/values/color.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
- #2196F3
- #1976D2
- #BBDEFB
- #4CAF50
- #212121
- #727272
- #FFFFFF
- #B6B6B6
-
\ No newline at end of file
diff --git a/demo/src/main/res/values/dimens.xml b/demo/src/main/res/values/dimens.xml
deleted file mode 100644
index 47c82246738c4d056e8030d3a259206f42e8e15d..0000000000000000000000000000000000000000
--- a/demo/src/main/res/values/dimens.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
- 16dp
- 16dp
-
diff --git a/demo/src/main/res/values/strings.xml b/demo/src/main/res/values/strings.xml
deleted file mode 100644
index c8fe7a787564e760a4e955121148efa5f5632b98..0000000000000000000000000000000000000000
--- a/demo/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
- GridPassWordViewDemo
- MainActivity
-
- Hello world!
- Settings
-
-
- - numberPassword
- - textPassword
- - textVisiblePassword
- - textWebPassword
-
-
diff --git a/demo/src/main/res/values/styles.xml b/demo/src/main/res/values/styles.xml
deleted file mode 100644
index 510d76a6e6a1e683ebd32bedf4498455e4703913..0000000000000000000000000000000000000000
--- a/demo/src/main/res/values/styles.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
diff --git a/demo/.gitignore b/entry/.gitignore
similarity index 100%
rename from demo/.gitignore
rename to entry/.gitignore
diff --git a/entry/build.gradle b/entry/build.gradle
new file mode 100644
index 0000000000000000000000000000000000000000..c0ff8e880e916c04f4300223e6ad6986addffb4f
--- /dev/null
+++ b/entry/build.gradle
@@ -0,0 +1,17 @@
+apply plugin: 'com.huawei.ohos.hap'
+ohos {
+ signingConfigs {
+
+ }
+ compileSdkVersion 5
+ defaultConfig {
+ compatibleSdkVersion 5
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
+ testCompile 'junit:junit:4.12'
+ compile project(path: ':library')
+
+}
diff --git a/entry/src/main/config.json b/entry/src/main/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..da8d5a2077168f6ffb4cb9e3e0682c4af24b7380
--- /dev/null
+++ b/entry/src/main/config.json
@@ -0,0 +1,49 @@
+{
+ "app": {
+ "bundleName": "com.jungly.gridpasswordview",
+ "vendor": "jungly",
+ "version": {
+ "code": 1,
+ "name": "1.0"
+ },
+ "apiVersion": {
+ "compatible": 5,
+ "target": 5,
+ "releaseType": "Release"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "com.jungly.gridpasswordview",
+ "name": ".MyApplication",
+ "deviceType": [
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "entry",
+ "moduleType": "entry"
+ },
+ "abilities": [
+ {
+ "skills": [
+ {
+ "entities": [
+ "entity.system.home"
+ ],
+ "actions": [
+ "action.system.home"
+ ]
+ }
+ ],
+ "orientation": "unspecified",
+ "name": "com.jungly.gridpasswordview.MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:mainability_description",
+ "label": "GridPasswordView",
+ "type": "page",
+ "launchType": "standard"
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/entry/src/main/java/com/jungly/gridpasswordview/MainAbility.java b/entry/src/main/java/com/jungly/gridpasswordview/MainAbility.java
new file mode 100644
index 0000000000000000000000000000000000000000..c349b392aba4551a16414d2008b52b73979c2ec5
--- /dev/null
+++ b/entry/src/main/java/com/jungly/gridpasswordview/MainAbility.java
@@ -0,0 +1,13 @@
+package com.jungly.gridpasswordview;
+
+import com.jungly.gridpasswordview.slice.MainAbilitySlice;
+import ohos.aafwk.ability.Ability;
+import ohos.aafwk.content.Intent;
+
+public class MainAbility extends Ability {
+ @Override
+ public void onStart(Intent intent) {
+ super.onStart(intent);
+ super.setMainRoute(MainAbilitySlice.class.getName());
+ }
+}
diff --git a/entry/src/main/java/com/jungly/gridpasswordview/MyApplication.java b/entry/src/main/java/com/jungly/gridpasswordview/MyApplication.java
new file mode 100644
index 0000000000000000000000000000000000000000..03bb6ebdc9e28b070d69d574b2632218eb7f8bbf
--- /dev/null
+++ b/entry/src/main/java/com/jungly/gridpasswordview/MyApplication.java
@@ -0,0 +1,10 @@
+package com.jungly.gridpasswordview;
+
+import ohos.aafwk.ability.AbilityPackage;
+
+public class MyApplication extends AbilityPackage {
+ @Override
+ public void onInitialize() {
+ super.onInitialize();
+ }
+}
diff --git a/entry/src/main/java/com/jungly/gridpasswordview/ToolbarAdapter.java b/entry/src/main/java/com/jungly/gridpasswordview/ToolbarAdapter.java
new file mode 100644
index 0000000000000000000000000000000000000000..0cc9e2a9c9515fd35dd0cf72ad12b85a64313d77
--- /dev/null
+++ b/entry/src/main/java/com/jungly/gridpasswordview/ToolbarAdapter.java
@@ -0,0 +1,65 @@
+/*
+ * 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.jungly.gridpasswordview;
+
+import ohos.agp.components.*;
+import ohos.app.Context;
+
+import java.util.List;
+
+public class ToolbarAdapter extends BaseItemProvider {
+ private List mColorList;
+ private Context context;
+
+ public ToolbarAdapter(Context context, List list) {
+ this.mColorList = list;
+ this.context = context;
+ }
+
+ @Override
+ public int getCount() {
+ return mColorList == null ? 0 : mColorList.size();
+ }
+
+ @Override
+ public Object getItem(int i) {
+ if (mColorList != null && i >= 0 && i < mColorList.size()) {
+ return mColorList.get(i);
+ }
+ return null;
+ }
+
+ @Override
+ public long getItemId(int i) {
+ return i;
+ }
+
+ @Override
+ public Component getComponent(int position, Component convertComponent, ComponentContainer componentContainer) {
+ final Component cpt;
+ if (convertComponent == null) {
+ cpt = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_item_menu_list, null, false);
+ } else {
+ cpt = convertComponent;
+ }
+ String color = mColorList.get(position);
+
+ Text text = (Text) cpt.findComponentById(ResourceTable.Id_text_item);
+ text.setText(color);
+
+ return cpt;
+ }
+}
diff --git a/entry/src/main/java/com/jungly/gridpasswordview/slice/MainAbilitySlice.java b/entry/src/main/java/com/jungly/gridpasswordview/slice/MainAbilitySlice.java
new file mode 100644
index 0000000000000000000000000000000000000000..1044a8fd03de847c16f1978b60d186f1ba9b4572
--- /dev/null
+++ b/entry/src/main/java/com/jungly/gridpasswordview/slice/MainAbilitySlice.java
@@ -0,0 +1,201 @@
+package com.jungly.gridpasswordview.slice;
+
+import com.jungly.gridpasswordview.GridPasswordView;
+import com.jungly.gridpasswordview.PasswordType;
+import com.jungly.gridpasswordview.ResourceTable;
+import com.jungly.gridpasswordview.ToolbarAdapter;
+
+import ohos.aafwk.ability.AbilitySlice;
+import ohos.aafwk.content.Intent;
+import ohos.agp.colors.RgbColor;
+import ohos.agp.components.*;
+import ohos.agp.components.element.ShapeElement;
+import ohos.agp.components.element.StateElement;
+import ohos.agp.utils.Color;
+import ohos.agp.window.dialog.*;
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+
+import java.time.format.TextStyle;
+import java.util.ArrayList;
+import java.util.List;
+
+public class MainAbilitySlice extends AbilitySlice {
+ static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MainAbilitySlice");
+ private static final int SWITCH_CORNER_RADIUS = 50;
+ private GridPasswordView mGridPasswordView;
+ private GridPasswordView mGridPasswordView2;
+ private GridPasswordView mGridPasswordView3;
+ private GridPasswordView mGridPasswordView8;
+ private Text mText;
+ private Text mTextStyle;
+ private boolean isChangePSW = true;
+ private boolean isFirst = true;
+ private String firstPwd;
+ private boolean password_type_number = true;
+ private Switch mSwitch;
+ private PopupDialog mPopupWindow;
+
+ @Override
+ public void onStart(Intent intent) {
+ super.onStart(intent);
+ super.setUIContent(ResourceTable.Layout_ability_main);
+
+ mGridPasswordView = (GridPasswordView) findComponentById(ResourceTable.Id_gridviewpassword);
+ mGridPasswordView2 = (GridPasswordView) findComponentById(ResourceTable.Id_gridviewpassword_2);
+ mGridPasswordView3 = (GridPasswordView) findComponentById(ResourceTable.Id_gridviewpassword_3);
+
+ mSwitch = (Switch) findComponentById(ResourceTable.Id_switch_pass);
+ setSwitchStyle(mSwitch);
+ mGridPasswordView8 = (GridPasswordView) findComponentById(ResourceTable.Id_gridviewpassword8);
+ mText = (Text) findComponentById(ResourceTable.Id_change_psw);
+
+ mTextStyle = (Text) findComponentById(ResourceTable.Id_change_psw_style);
+ mGridPasswordView8.setOnPasswordChangedListener(
+ new GridPasswordView.OnPasswordChangedListener() {
+ @Override
+ public void onTextChanged(String psw) {
+ if (psw.length() == mGridPasswordView8.DEFAULT_PASSWORD_LENGTH && isFirst) {
+ mGridPasswordView8.clearPassword();
+ isFirst = false;
+ firstPwd = psw;
+ } else if (psw.length() == 6 && !isFirst) {
+ if (psw.equals(firstPwd)) {
+ isFirst = true;
+ } else {
+ mGridPasswordView8.clearPassword();
+ firstPwd = psw;
+ }
+ }
+ }
+
+ @Override
+ public void onInputFinish(String psw) {
+ }
+ });
+
+ mText.setClickedListener(new Component.ClickedListener() {
+ @Override
+ public void onClick(Component component) {
+ showListPop();
+ }
+ });
+
+ mTextStyle.setClickedListener(new Component.ClickedListener() {
+ @Override
+ public void onClick(Component component) {
+ if (password_type_number) {
+ password_type_number = false;
+ mTextStyle.setText("数字");
+ mGridPasswordView3.setPasswordType(PasswordType.NUMBER);
+ } else {
+ password_type_number = true;
+ mTextStyle.setText("字母");
+ mGridPasswordView3.setPasswordType(PasswordType.TEXT);
+ }
+ }
+ });
+
+ mSwitch.setCheckedStateChangedListener(new AbsButton.CheckedStateChangedListener() {
+ @Override
+ public void onCheckedChanged(AbsButton absButton, boolean b) {
+ if (b) {
+ mGridPasswordView3.setShowPassword(false);
+ } else {
+ mGridPasswordView3.setShowPassword(true);
+ }
+ }
+ });
+ }
+
+ private StateElement trackElementInit(ShapeElement on, ShapeElement off) {
+ StateElement trackElement = new StateElement();
+ trackElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, on);
+ trackElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, off);
+ return trackElement;
+ }
+
+ private StateElement thumbElementInit(ShapeElement on, ShapeElement off) {
+ StateElement thumbElement = new StateElement();
+ thumbElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, on);
+ thumbElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, off);
+ return thumbElement;
+ }
+
+ private void setSwitchStyle(Switch switchStyle) {
+ ShapeElement elementThumbOn = new ShapeElement();
+ elementThumbOn.setShape(ShapeElement.OVAL);
+ elementThumbOn.setRgbColor(RgbColor.fromArgbInt(0xFF4aac4e));
+ elementThumbOn.setCornerRadius(SWITCH_CORNER_RADIUS);
+ // 关闭状态下滑块的样式
+ ShapeElement elementThumbOff = new ShapeElement();
+ elementThumbOff.setShape(ShapeElement.OVAL);
+ elementThumbOff.setRgbColor(RgbColor.fromArgbInt(0xFFFFFFFF));
+ elementThumbOff.setCornerRadius(SWITCH_CORNER_RADIUS);
+ // 开启状态下轨迹样式
+ ShapeElement elementTrackOn = new ShapeElement();
+ elementTrackOn.setShape(ShapeElement.RECTANGLE);
+ elementTrackOn.setRgbColor(RgbColor.fromArgbInt(0xffcde6ce));
+ elementTrackOn.setCornerRadius(SWITCH_CORNER_RADIUS);
+ // 关闭状态下轨迹样式
+ ShapeElement elementTrackOff = new ShapeElement();
+ elementTrackOff.setShape(ShapeElement.RECTANGLE);
+ elementTrackOff.setRgbColor(RgbColor.fromArgbInt(0xFF808080));
+ elementTrackOff.setCornerRadius(SWITCH_CORNER_RADIUS);
+ switchStyle.setTrackElement(trackElementInit(elementTrackOn, elementTrackOff));
+ switchStyle.setThumbElement(thumbElementInit(elementThumbOn, elementThumbOff));
+ }
+
+ private void showListPop() {
+ ListContainer spinnerListView = new ListContainer(getContext());
+ ToolbarAdapter spinnerAdapter = new ToolbarAdapter(getContext(), getPassTypeData());
+ spinnerListView.setItemProvider(spinnerAdapter);
+ spinnerListView.setItemClickedListener((parent, view, position, id) -> {
+ if (mPopupWindow != null) {
+ mPopupWindow.destroy();
+ mPopupWindow = null;
+ }
+ mText.setText(getPassTypeData().get(position));
+ if (mText.getText().equals("pattern_number")) {
+ mGridPasswordView3.setPasswordType(PasswordType.NUMBER);
+ } else if (mText.getText().equals("pattern_password")) {
+ mGridPasswordView3.setPasswordType(PasswordType.PASSWORD);
+ } else if (mText.getText().equals("pattern_text")) {
+ mGridPasswordView3.setPasswordType(PasswordType.TEXT);
+ }
+ });
+ mPopupWindow = new PopupDialog(getContext(), mText);
+ mPopupWindow.setCustomComponent(spinnerListView);
+ mPopupWindow.show();
+ mPopupWindow.setDialogListener(() -> {
+ if (mPopupWindow != null) {
+ mPopupWindow.destroy();
+ mPopupWindow = null;
+ }
+ return false;
+ });
+ }
+
+ /**
+ * 获取密码类型数据
+ *
+ * @return Spinner数据
+ */
+ private List getPassTypeData() {
+ ArrayList menuList = new ArrayList<>();
+ menuList.add("pattern_number");
+ menuList.add("pattern_password");
+ menuList.add("pattern_text");
+ return menuList;
+ }
+
+ @Override
+ public void onActive() {
+ super.onActive();
+ }
+
+ @Override
+ public void onForeground(Intent intent) {
+ super.onForeground(intent);
+ }
+}
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..67313ef672caf2ed8097a470cc4280361b15a676
--- /dev/null
+++ b/entry/src/main/resources/base/element/string.json
@@ -0,0 +1,12 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "GridPasswordView"
+ },
+ {
+ "name": "mainability_description",
+ "value": "Java_Phone_Empty Feature Ability"
+ }
+ ]
+}
\ 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/icon_sanjiao.xml b/entry/src/main/resources/base/graphic/icon_sanjiao.xml
new file mode 100644
index 0000000000000000000000000000000000000000..669c949b227d50ecc4f08e02fe54b23c91def428
--- /dev/null
+++ b/entry/src/main/resources/base/graphic/icon_sanjiao.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
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..d080c77d430d36a105f23b02823a8b966be71a5a
--- /dev/null
+++ b/entry/src/main/resources/base/layout/ability_main.xml
@@ -0,0 +1,224 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/entry/src/main/resources/base/layout/item_menu_list.xml b/entry/src/main/resources/base/layout/item_menu_list.xml
new file mode 100644
index 0000000000000000000000000000000000000000..e0a7fe6411e10c614bbbe4446602aa326721428d
--- /dev/null
+++ b/entry/src/main/resources/base/layout/item_menu_list.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/entry/src/main/resources/base/media/ic_arrow.png b/entry/src/main/resources/base/media/ic_arrow.png
new file mode 100644
index 0000000000000000000000000000000000000000..0a3f75de4f99d151e26f699398227db81c27e7bd
Binary files /dev/null and b/entry/src/main/resources/base/media/ic_arrow.png differ
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/entry/src/test/java/com/jungly/gridpasswordview/ExampleTest.java b/entry/src/test/java/com/jungly/gridpasswordview/ExampleTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..d36867ea803d9823dbf6e502dec13825b9d247c2
--- /dev/null
+++ b/entry/src/test/java/com/jungly/gridpasswordview/ExampleTest.java
@@ -0,0 +1,9 @@
+package com.jungly.gridpasswordview;
+
+import org.junit.Test;
+
+public class ExampleTest {
+ @Test
+ public void onStart() {
+ }
+}
diff --git a/gradle.properties b/gradle.properties
deleted file mode 100644
index 1d3591c8a4c9c29578c36c87f80c05a6aea3ee3f..0000000000000000000000000000000000000000
--- a/gradle.properties
+++ /dev/null
@@ -1,18 +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
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 8c0fb64a8698b08ecc4158d828ca593c4928e9dd..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 d57051703e32b305b0071fed7cef094fd0504f39..6623300bebd011bc5f7991f4f9c389e2f67b14ac 100644
--- a/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\://services.gradle.org/distributions/gradle-6.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
diff --git a/gradlew b/gradlew
deleted file mode 100755
index 91a7e269e19dfc62e27137a0b57ef3e430cee4fd..0000000000000000000000000000000000000000
--- a/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/gradlew.bat b/gradlew.bat
deleted file mode 100644
index aec99730b4e8fcd90b57a0e8e01544fea7c31a89..0000000000000000000000000000000000000000
--- a/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/gridpasswordview.gif b/gridpasswordview.gif
new file mode 100644
index 0000000000000000000000000000000000000000..4150f3f19fa9f5bb542a19c0bbadb64364df3f15
Binary files /dev/null and b/gridpasswordview.gif differ
diff --git a/library/.gitignore b/library/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..796b96d1c402326528b4ba3c12ee9d92d0e212e9
--- /dev/null
+++ b/library/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/library/build.gradle b/library/build.gradle
index c570052d2b55312b310c800bd23296722f7b584e..276eacf16b1058c5f85a69a0839b1ec585d19770 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -1,24 +1,14 @@
-apply plugin: 'com.android.library'
-
-android {
- compileSdkVersion 23
- buildToolsVersion "23.0.2"
+apply plugin: 'com.huawei.ohos.library'
+ohos {
+ compileSdkVersion 5
defaultConfig {
- minSdkVersion 11
- targetSdkVersion 23
- versionCode 4
- versionName "0.3"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
+ compatibleSdkVersion 5
}
+
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:23.1.1'
-}
\ No newline at end of file
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ testCompile'junit:junit:4.12'
+}
diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml
deleted file mode 100644
index 5f0f9bac88d562dd11820fafe5a94441b33e1861..0000000000000000000000000000000000000000
--- a/library/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/library/src/main/config.json b/library/src/main/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..f7f563f0071d31583c7fdbf8ba81841edc5f7f8f
--- /dev/null
+++ b/library/src/main/config.json
@@ -0,0 +1,27 @@
+{
+ "app": {
+ "bundleName": "com.jungly.gridpasswordview",
+ "vendor": "jungly",
+ "version": {
+ "code": 1,
+ "name": "1.0"
+ },
+ "apiVersion": {
+ "compatible": 5,
+ "target": 5,
+ "releaseType": "Release"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "com.jungly.gridpasswordview",
+ "deviceType": [
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "library",
+ "moduleType": "har"
+ }
+ }
+}
\ No newline at end of file
diff --git a/library/src/main/java/com/jungly/gridpasswordview/CustomPasswordTransformationMethod.java b/library/src/main/java/com/jungly/gridpasswordview/CustomPasswordTransformationMethod.java
index e355512c7053bd4cd45e4843fe6f0fb9ba80a315..a95c0380bcb4ae9b7d04a3bbc0b0875241436f1c 100644
--- a/library/src/main/java/com/jungly/gridpasswordview/CustomPasswordTransformationMethod.java
+++ b/library/src/main/java/com/jungly/gridpasswordview/CustomPasswordTransformationMethod.java
@@ -1,29 +1,21 @@
package com.jungly.gridpasswordview;
-import android.text.method.PasswordTransformationMethod;
-import android.view.View;
-
/**
* 默认'●'
*
* @author Jungly
- * mail: jungly.ik@gmail.com
+ * mail: jungly.ik@gmail.com
*/
-public class CustomPasswordTransformationMethod extends PasswordTransformationMethod {
- String transformation;
+public class CustomPasswordTransformationMethod {
+ private final String transformation;
public CustomPasswordTransformationMethod(String transformation) {
this.transformation = transformation;
}
- @Override
- public CharSequence getTransformation(CharSequence source, View view) {
- return new PasswordCharSequence(source);
- }
-
private class PasswordCharSequence implements CharSequence {
- private CharSequence mSource;
+ private final CharSequence mSource;
public PasswordCharSequence(CharSequence source) {
mSource = source;
@@ -44,5 +36,4 @@ public class CustomPasswordTransformationMethod extends PasswordTransformationMe
return mSource.subSequence(start, end);
}
}
-
}
\ No newline at end of file
diff --git a/library/src/main/java/com/jungly/gridpasswordview/GridPasswordView.java b/library/src/main/java/com/jungly/gridpasswordview/GridPasswordView.java
index f2cd3727f8fdf664cbc72790f7e251e944cce643..307c39104cb3070d6beace5bcbe0fb308908c26a 100644
--- a/library/src/main/java/com/jungly/gridpasswordview/GridPasswordView.java
+++ b/library/src/main/java/com/jungly/gridpasswordview/GridPasswordView.java
@@ -1,31 +1,19 @@
package com.jungly.gridpasswordview;
-import android.annotation.TargetApi;
-import android.content.Context;
-import android.content.res.ColorStateList;
-import android.content.res.TypedArray;
-import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.GradientDrawable;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Parcelable;
-import android.text.Editable;
-import android.text.InputType;
-import android.text.TextUtils;
-import android.text.TextWatcher;
-import android.text.method.PasswordTransformationMethod;
-import android.util.AttributeSet;
-import android.view.KeyEvent;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.EditText;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
import com.jungly.gridpasswordview.imebugfixer.ImeDelBugFixedEditText;
+import ohos.agp.colors.RgbColor;
+import ohos.agp.components.*;
+import ohos.agp.components.element.ShapeElement;
+import ohos.agp.render.Canvas;
+import ohos.agp.utils.Color;
+import ohos.agp.utils.TextAlignment;
+import ohos.agp.window.service.Display;
+import ohos.agp.window.service.DisplayManager;
+import ohos.app.Context;
+
+import ohos.multimodalinput.event.KeyEvent;
+
/**
* ●
*
@@ -33,179 +21,186 @@ import com.jungly.gridpasswordview.imebugfixer.ImeDelBugFixedEditText;
* jungly.ik@gmail.com
* 15/3/5 21:30
*/
-public class GridPasswordView extends LinearLayout implements PasswordView {
- private static final int DEFAULT_PASSWORDLENGTH = 6;
+public class GridPasswordView extends DirectionalLayout implements PasswordView, Component.DrawTask {
+ public static final int DEFAULT_PASSWORD_LENGTH = 6;
+ private static final int DEFAULT_LINE_WIDTH = 5;
+ private static final int DEFAULT_MAX_PASSWORDLENGTH = 8;
private static final int DEFAULT_TEXTSIZE = 16;
private static final String DEFAULT_TRANSFORMATION = "●";
- private static final int DEFAULT_LINECOLOR = 0xaa888888;
- private static final int DEFAULT_GRIDCOLOR = 0xffffffff;
+ private static final int DEFAULT_OUTER_LINE_COLOR = 0xaa888888;
+ private static final int DEFAULT_TEXT_COLOR = Color.getIntColor("#ff000000");
- private ColorStateList mTextColor;
+ private Context mContext;
+ private Color mTextColor;
private int mTextSize = DEFAULT_TEXTSIZE;
- private int mLineWidth;
- private int mLineColor;
- private int mGridColor;
- private Drawable mLineDrawable;
- private Drawable mOuterLineDrawable;
+ private int mLineWidth = DEFAULT_LINE_WIDTH;
+ private Color mGridColor;
+ private ShapeElement mOuterLineDrawable;
+ private Color mOutLineColor;
private int mPasswordLength;
private String mPasswordTransformation;
private int mPasswordType;
-
private String[] mPasswordArr;
- private TextView[] mViewArr;
-
+ private Text[] mViewArr;
+ private TextField[] mViewFiledArr;
+ private boolean showPassword = true;
private ImeDelBugFixedEditText mInputView;
private OnPasswordChangedListener mListener;
- private PasswordTransformationMethod mTransformationMethod;
+ private int mScreenWidth;
+ private boolean isFirst = true;
+ private boolean isDelInput = false;
public GridPasswordView(Context context) {
super(context);
- initViews(context);
- init(context, null, 0);
+ init(context, null, "");
}
- public GridPasswordView(Context context, AttributeSet attrs) {
+ public GridPasswordView(Context context, AttrSet attrs) {
super(context, attrs);
- init(context, attrs, 0);
+ init(context, attrs, "");
}
- public GridPasswordView(Context context, AttributeSet attrs, int defStyleAttr) {
+ public GridPasswordView(Context context, AttrSet attrs, String defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr);
}
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
- public GridPasswordView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- init(context, attrs, defStyleAttr);
- }
+ private void init(Context context, AttrSet attrs, String defStyleAttr) {
+ Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();
+ mScreenWidth = display.getAttributes().width;
+
+ mContext = context;
- private void init(Context context, AttributeSet attrs, int defStyleAttr) {
initAttrs(context, attrs, defStyleAttr);
initViews(context);
}
- private void initAttrs(Context context, AttributeSet attrs, int defStyleAttr) {
- TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.gridPasswordView, defStyleAttr, 0);
+ private void initAttrs(Context context, AttrSet attrSet, String defStyleAttr) {
+ mGridColor = TypedAttrUtils.getColor(attrSet, "gpv_grid_color", Color.BLACK);
+ mTextColor = TypedAttrUtils.getColor(attrSet, "gpv_text_color", new Color(DEFAULT_TEXT_COLOR));
+ if (mTextColor == null) {
+ mTextColor = new Color(DEFAULT_TEXT_COLOR);
+ }
+ showPassword = TypedAttrUtils.getBoolean(attrSet, "gpv_show_password", true);
+ mOutLineColor = TypedAttrUtils.getColor(attrSet, "gpv_outer_line_color", new Color(DEFAULT_OUTER_LINE_COLOR));
+ mPasswordType = TypedAttrUtils.getInteger(attrSet, "gpv_password_type", InputAttribute.PATTERN_NUMBER);
- mTextColor = ta.getColorStateList(R.styleable.gridPasswordView_gpvTextColor);
- if (mTextColor == null)
- mTextColor = ColorStateList.valueOf(getResources().getColor(android.R.color.primary_text_light));
- int textSize = ta.getDimensionPixelSize(R.styleable.gridPasswordView_gpvTextSize, -1);
+ int textSize = TypedAttrUtils.getDimensionPixelSize(attrSet, "gpv_text_size",
+ AttrHelper.fp2px(DEFAULT_TEXTSIZE, context));
if (textSize != -1) {
- this.mTextSize = Util.px2sp(context, textSize);
+ this.mTextSize = AttrHelper.fp2px(DEFAULT_TEXTSIZE, context);
+ }
+ mLineWidth = TypedAttrUtils.getInteger(attrSet, "gpv_line_width", DEFAULT_LINE_WIDTH);
+ if (mLineWidth < 1) {
+ mLineWidth = DEFAULT_LINE_WIDTH;
}
-
- mLineWidth = (int) ta.getDimension(R.styleable.gridPasswordView_gpvLineWidth, Util.dp2px(getContext(), 1));
- mLineColor = ta.getColor(R.styleable.gridPasswordView_gpvLineColor, DEFAULT_LINECOLOR);
- mGridColor = ta.getColor(R.styleable.gridPasswordView_gpvGridColor, DEFAULT_GRIDCOLOR);
- mLineDrawable = ta.getDrawable(R.styleable.gridPasswordView_gpvLineColor);
- if (mLineDrawable == null)
- mLineDrawable = new ColorDrawable(mLineColor);
mOuterLineDrawable = generateBackgroundDrawable();
+ mPasswordLength = TypedAttrUtils.getInteger(attrSet, "gpv_line_width", DEFAULT_PASSWORD_LENGTH);
+ mPasswordLength = attrSet.getAttr("gpv_password_length").get().getIntegerValue();
+ if (mPasswordLength < 1) {
+ mPasswordLength = DEFAULT_PASSWORD_LENGTH;
+ }
+ if (mPasswordLength > DEFAULT_MAX_PASSWORDLENGTH) {
+ mPasswordLength = DEFAULT_MAX_PASSWORDLENGTH;
+ }
- mPasswordLength = ta.getInt(R.styleable.gridPasswordView_gpvPasswordLength, DEFAULT_PASSWORDLENGTH);
- mPasswordTransformation = ta.getString(R.styleable.gridPasswordView_gpvPasswordTransformation);
- if (TextUtils.isEmpty(mPasswordTransformation))
- mPasswordTransformation = DEFAULT_TRANSFORMATION;
-
-
- mPasswordType = ta.getInt(R.styleable.gridPasswordView_gpvPasswordType, 0);
-
- ta.recycle();
+ mPasswordTransformation = TypedAttrUtils.getString(attrSet,
+ "gpv_password_transformation", DEFAULT_TRANSFORMATION);
mPasswordArr = new String[mPasswordLength];
- mViewArr = new TextView[mPasswordLength];
+ mViewArr = new Text[mPasswordLength];
+ mViewFiledArr = new TextField[mPasswordLength];
}
private void initViews(Context context) {
- super.setBackgroundDrawable(mOuterLineDrawable);
- setShowDividers(SHOW_DIVIDER_NONE);
+ super.setBackground(mOuterLineDrawable);
setOrientation(HORIZONTAL);
- mTransformationMethod = new CustomPasswordTransformationMethod(mPasswordTransformation);
- inflaterViews(context);
+ addDrawTask(this::onDraw);
}
- private void inflaterViews(Context context) {
- LayoutInflater inflater = LayoutInflater.from(context);
- inflater.inflate(R.layout.gridpasswordview, this);
-
- mInputView = (ImeDelBugFixedEditText) findViewById(R.id.inputView);
- mInputView.setMaxEms(mPasswordLength);
- mInputView.addTextChangedListener(textWatcher);
- mInputView.setDelKeyEventListener(onDelKeyEventListener);
- setCustomAttr(mInputView);
-
- mViewArr[0] = mInputView;
+ @Override
+ public void onDraw(Component component, Canvas canvas) {
+ if (isFirst) {
+ inflaterViews(mContext);
+ isFirst = false;
+ }
+ }
- int index = 1;
+ private void inflaterViews(Context context) {
+ int compantWidth = (mScreenWidth - getMarginLeft() - getMarginRight()
+ - getPaddingRight() - getPaddingLeft()) - mLineWidth * mPasswordLength;
+ int singleCompantWidth = compantWidth / mPasswordLength;
+ int index = 0;
while (index < mPasswordLength) {
- View dividerView = inflater.inflate(R.layout.divider, null);
- LayoutParams dividerParams = new LayoutParams(mLineWidth, LayoutParams.MATCH_PARENT);
- dividerView.setBackgroundDrawable(mLineDrawable);
- addView(dividerView, dividerParams);
-
- TextView textView = (TextView) inflater.inflate(R.layout.textview, null);
- setCustomAttr(textView);
- LayoutParams textViewParams = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1f);
- addView(textView, textViewParams);
-
- mViewArr[index] = textView;
+ if (index != 0) {
+ Component line = new Component(context);
+ line.setWidth(mLineWidth);
+ line.setHeight(ComponentContainer.LayoutConfig.MATCH_PARENT);
+ line.setBackground(generateDividerBackgroundColor());
+ addComponent(line);
+ }
+ mInputView = (ImeDelBugFixedEditText) LayoutScatter.getInstance(context)
+ .parse(ResourceTable.Layout_gridpasswordview, null, false);
+ mInputView.addTextObserver(textWatcher);
+ mInputView.setKeyEventListener(KeyEventListener);
+ mInputView.setTextInputType(mPasswordType);
+ mInputView.setTruncationMode(Text.TruncationMode.AUTO_SCROLLING);
+
+ mViewFiledArr[index] = mInputView;
+ StackLayout stackLayout = new StackLayout(getContext());
+ stackLayout.setWidth(singleCompantWidth);
+ stackLayout.setHeight(110);
+ stackLayout.addComponent(mInputView);
+ Text text = new Text(context);
+ text.setWidth(singleCompantWidth);
+ text.setHeight(110);
+ text.setTextColor(mTextColor);
+ text.setTextAlignment(TextAlignment.CENTER);
+ text.setTextSize(50);
+ text.setTextAlignment(TextAlignment.HORIZONTAL_CENTER | TextAlignment.VERTICAL_CENTER);
+ mViewArr[index] = text;
+ stackLayout.addComponent(text);
+ addComponent(stackLayout);
index++;
}
-
- setOnClickListener(mOnClickListener);
+ setClickedListener(mOnClickListener);
}
- private void setCustomAttr(TextView view) {
- if (mTextColor != null)
+ private void setCustomAttr(Text view) {
+ if (mTextColor != null) {
view.setTextColor(mTextColor);
- view.setTextSize(mTextSize);
-
- int inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
- switch (mPasswordType) {
-
- case 1:
- inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
- break;
-
- case 2:
- inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
- break;
-
- case 3:
- inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
- break;
}
- view.setInputType(inputType);
- view.setTransformationMethod(mTransformationMethod);
+ view.setTextSize(mTextSize);
}
- private OnClickListener mOnClickListener = new OnClickListener() {
+ private Component.ClickedListener mOnClickListener = new Component.ClickedListener() {
@Override
- public void onClick(View v) {
+ public void onClick(Component component) {
forceInputViewGetFocus();
}
};
- private GradientDrawable generateBackgroundDrawable() {
- GradientDrawable drawable = new GradientDrawable();
- drawable.setColor(mGridColor);
- drawable.setStroke(mLineWidth, mLineColor);
- return drawable;
+ private ShapeElement generateDividerBackgroundColor() {
+ ShapeElement elementLine = new ShapeElement();
+ elementLine.setRgbColor(RgbColor.fromArgbInt(mOutLineColor.getValue()));
+ return elementLine;
+ }
+
+ private ShapeElement generateBackgroundDrawable() {
+ ShapeElement element = new ShapeElement();
+ element.setStroke(mLineWidth, RgbColor.fromArgbInt(mOutLineColor.getValue()));
+ return element;
}
private void forceInputViewGetFocus() {
- mInputView.setFocusable(true);
- mInputView.setFocusableInTouchMode(true);
+ mInputView.setFocusable(FOCUS_ENABLE);
+ mInputView.setClickable(true);
+ mInputView.setTouchFocusable(true);
mInputView.requestFocus();
- InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(mInputView, InputMethodManager.SHOW_IMPLICIT);
}
private ImeDelBugFixedEditText.OnDelKeyEventListener onDelKeyEventListener = new ImeDelBugFixedEditText.OnDelKeyEventListener() {
-
@Override
public void onDeleteClick() {
for (int i = mPasswordArr.length - 1; i >= 0; i--) {
@@ -221,110 +216,96 @@ public class GridPasswordView extends LinearLayout implements PasswordView {
}
};
- private TextWatcher textWatcher = new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-
- }
-
+ /**
+ * TextFiled 的文本输入监听
+ */
+ ohos.agp.components.Text.TextObserver textWatcher = new ohos.agp.components.Text.TextObserver() {
@Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- if (s == null) {
+ public void onTextUpdated(String s, int index, int i1, int i2) {
+ String newStr = s.toString();
+ if (newStr == null || newStr.equals("") || newStr.length() > mPasswordLength) {
return;
}
- String newStr = s.toString();
- if (newStr.length() == 1) {
- mPasswordArr[0] = newStr;
- notifyTextChanged();
- } else if (newStr.length() == 2) {
- String newNum = newStr.substring(1);
- for (int i = 0; i < mPasswordArr.length; i++) {
- if (mPasswordArr[i] == null) {
- mPasswordArr[i] = newNum;
- mViewArr[i].setText(newNum);
- notifyTextChanged();
+ for (int i = 0; i < mPasswordArr.length; i++) {
+ String newNum = newStr.substring(newStr.length() - 1);
+ if (mPasswordArr[i] == null) {
+ if (isDelInput) {
+ isDelInput = false;
break;
}
+ mPasswordArr[i] = newNum;
+ if (showPassword) {
+ mViewArr[i].setText(mPasswordTransformation);
+ } else {
+ mViewArr[i].setText(newNum);
+ }
+ notifyTextChanged();
+ break;
}
- mInputView.removeTextChangedListener(this);
- mInputView.setText(mPasswordArr[0]);
- if (mInputView.getText().length() >= 1) {
- mInputView.setSelection(1);
- }
- mInputView.addTextChangedListener(this);
}
}
-
- @Override
- public void afterTextChanged(Editable s) {
-
- }
};
- @Deprecated
- private OnKeyListener onKeyListener = new OnKeyListener() {
+ Component.KeyEventListener KeyEventListener = new Component.KeyEventListener() {
@Override
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
- onDelKeyEventListener.onDeleteClick();
+ public boolean onKeyEvent(Component component, KeyEvent keyEvent) {
+ if (keyEvent.getKeyCode() == KeyEvent.KEY_SPACE) {
return true;
}
- return false;
- }
- };
-
- private void notifyTextChanged() {
- if (mListener == null)
- return;
-
- String currentPsw = getPassWord();
- mListener.onTextChanged(currentPsw);
-
- if (currentPsw.length() == mPasswordLength)
- mListener.onInputFinish(currentPsw);
- }
+ if (keyEvent.isKeyDown() && keyEvent.getKeyCode() == KeyEvent.KEY_DEL) {
+ for (int i = mPasswordArr.length - 1; i >= 0; i--) {
+ if (mPasswordArr[i] != null) {
+ mPasswordArr[i] = null;
- @Override
- protected Parcelable onSaveInstanceState() {
- Bundle bundle = new Bundle();
- bundle.putParcelable("instanceState", super.onSaveInstanceState());
- bundle.putStringArray("passwordArr", mPasswordArr);
- return bundle;
- }
+ mViewArr[i].setText(null);
+ notifyTextChanged();
- @Override
- protected void onRestoreInstanceState(Parcelable state) {
- if (state instanceof Bundle) {
- Bundle bundle = (Bundle) state;
- mPasswordArr = bundle.getStringArray("passwordArr");
- state = bundle.getParcelable("instanceState");
- mInputView.removeTextChangedListener(textWatcher);
- setPassword(getPassWord());
- mInputView.addTextChangedListener(textWatcher);
+ isDelInput = true;
+ if (i == 0) {
+ isDelInput = false;
+ for (int j = mViewFiledArr.length - 1; j >= 0; j--) {
+ mViewFiledArr[j].setText(null);
+ }
+ }
+ break;
+ } else {
+ mViewArr[i].setText(null);
+ }
+ }
+ }
+ return false;
}
- super.onRestoreInstanceState(state);
- }
-
- //TODO
- //@Override
- private void setError(String error) {
- mInputView.setError(error);
- }
+ };
/**
- * Return the text the PasswordView is displaying.
+ * 获取密码
+ *
+ * @return the text the PasswordView is displaying.
*/
@Override
public String getPassWord() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mPasswordArr.length; i++) {
- if (mPasswordArr[i] != null)
+ if (mPasswordArr[i] != null) {
sb.append(mPasswordArr[i]);
+ }
}
return sb.toString();
}
+ private void notifyTextChanged() {
+ if (mListener == null) {
+ return;
+ }
+ String currentPsw = getPassWord();
+ mListener.onTextChanged(currentPsw);
+
+ if (currentPsw.length() == mPasswordLength) {
+ mListener.onInputFinish(currentPsw);
+ }
+ }
+
/**
* Clear the passwrod the PasswordView is displaying.
*/
@@ -333,45 +314,47 @@ public class GridPasswordView extends LinearLayout implements PasswordView {
for (int i = 0; i < mPasswordArr.length; i++) {
mPasswordArr[i] = null;
mViewArr[i].setText(null);
+ mViewFiledArr[i].setText(null);
}
}
/**
- * Sets the string value of the PasswordView.
+ * 设置密码
+ *
+ * @param password Sets the string value of the PasswordView.
*/
@Override
public void setPassword(String password) {
clearPassword();
- if (TextUtils.isEmpty(password))
+ if (null == password || password.length() == 0) {
return;
+ }
char[] pswArr = password.toCharArray();
for (int i = 0; i < pswArr.length; i++) {
if (i < mPasswordArr.length) {
mPasswordArr[i] = pswArr[i] + "";
- mViewArr[i].setText(mPasswordArr[i]);
+ if (isShowPassword()) {
+ mViewArr[i].setText(mPasswordTransformation);
+ } else {
+ mViewArr[i].setText(mPasswordArr[i]);
+ }
}
}
}
/**
- * Set the enabled state of this view.
+ * 设置密码明文密文
+ *
+ * @param visible Set the enabled state of this view.
*/
@Override
public void setPasswordVisibility(boolean visible) {
- for (TextView textView : mViewArr) {
- textView.setTransformationMethod(visible ? null : mTransformationMethod);
- if (textView instanceof EditText) {
- EditText et = (EditText) textView;
- et.setSelection(et.getText().length());
- }
- }
+ this.showPassword = visible;
+ setPassword(getPassWord());
}
- /**
- * Toggle the enabled state of this view.
- */
@Override
public void togglePasswordVisibility() {
boolean currentVisible = getPassWordVisibility();
@@ -379,78 +362,88 @@ public class GridPasswordView extends LinearLayout implements PasswordView {
}
/**
- * Get the visibility of this view.
+ * 密码是否显示
+ *
+ * @return Get the visibility of this view.
*/
private boolean getPassWordVisibility() {
- return mViewArr[0].getTransformationMethod() == null;
+ return showPassword;
}
/**
- * Register a callback to be invoked when password changed.
+ * 密码改变监听
+ *
+ * @param listener Register a callback to be invoked when password changed.
*/
@Override
public void setOnPasswordChangedListener(OnPasswordChangedListener listener) {
this.mListener = listener;
}
+ /**
+ * 密码展示类型
+ *
+ * @param passwordType set password show type
+ */
@Override
public void setPasswordType(PasswordType passwordType) {
- boolean visible = getPassWordVisibility();
- int inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
+ int inputType = InputAttribute.PATTERN_NUMBER;
switch (passwordType) {
-
case TEXT:
- inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
+ inputType = InputAttribute.PATTERN_TEXT;
break;
- case TEXTVISIBLE:
- inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
+ case NUMBER:
+ inputType = InputAttribute.PATTERN_NUMBER;
break;
- case TEXTWEB:
- inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
+ case PASSWORD:
+ inputType = InputAttribute.PATTERN_PASSWORD;
break;
- }
-
- for (TextView textView : mViewArr)
- textView.setInputType(inputType);
- setPasswordVisibility(visible);
- }
+ case PATTERN_NULL:
+ inputType = InputAttribute.PATTERN_NULL;
+ break;
- @Override
- public void setBackground(Drawable background) {
+ default:
+ inputType = InputAttribute.PATTERN_NUMBER;
+ }
+ for (TextField textView : mViewFiledArr) {
+ textView.setTextInputType(inputType);
+ }
}
- @Override
- public void setBackgroundColor(int color) {
+ public boolean isShowPassword() {
+ return showPassword;
}
- @Override
- public void setBackgroundResource(int resid) {
- }
-
- @Override
- public void setBackgroundDrawable(Drawable background) {
+ /**
+ * 密码是否显示
+ *
+ * @param showPassword 是否显示密码
+ */
+ public void setShowPassword(boolean showPassword) {
+ this.showPassword = showPassword;
+ setPassword(getPassWord());
}
-
/**
- * Interface definition for a callback to be invoked when the password changed or is at the maximum length.
+ * Interface definition for a callback to be invoked when
+ * the password changed or is at the maximum length.
*/
public interface OnPasswordChangedListener {
-
/**
* Invoked when the password changed.
+ *
* @param psw new text
*/
void onTextChanged(String psw);
/**
* Invoked when the password is at the maximum length.
+ *
* @param psw complete text
*/
void onInputFinish(String psw);
-
}
}
diff --git a/library/src/main/java/com/jungly/gridpasswordview/PasswordType.java b/library/src/main/java/com/jungly/gridpasswordview/PasswordType.java
index 18b7e67f3134b2c70355000dd79397e070fe19df..2884b79a9ef5f064f3026715d3f790725cd19ae2 100644
--- a/library/src/main/java/com/jungly/gridpasswordview/PasswordType.java
+++ b/library/src/main/java/com/jungly/gridpasswordview/PasswordType.java
@@ -6,7 +6,5 @@ package com.jungly.gridpasswordview;
* 5/3/21 16:47
*/
public enum PasswordType {
-
- NUMBER, TEXT, TEXTVISIBLE, TEXTWEB;
-
-}
+ NUMBER, TEXT, TEXTVISIBLE, PATTERN_NULL, PASSWORD
+}
\ No newline at end of file
diff --git a/library/src/main/java/com/jungly/gridpasswordview/PasswordView.java b/library/src/main/java/com/jungly/gridpasswordview/PasswordView.java
index 2ca0837d4c04e492b00580465419761b15d84aad..cf110fe3d5b5ac8d3691416c601b0260cd97a191 100644
--- a/library/src/main/java/com/jungly/gridpasswordview/PasswordView.java
+++ b/library/src/main/java/com/jungly/gridpasswordview/PasswordView.java
@@ -7,8 +7,6 @@ package com.jungly.gridpasswordview;
*/
interface PasswordView {
- //void setError(String error);
-
String getPassWord();
void clearPassword();
diff --git a/library/src/main/java/com/jungly/gridpasswordview/TypedAttrUtils.java b/library/src/main/java/com/jungly/gridpasswordview/TypedAttrUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..627631b4f00acb1a30b32ba9d88c254f9a73f7c8
--- /dev/null
+++ b/library/src/main/java/com/jungly/gridpasswordview/TypedAttrUtils.java
@@ -0,0 +1,122 @@
+/*
+ * 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.jungly.gridpasswordview;
+
+import ohos.agp.components.AttrSet;
+import ohos.agp.utils.Color;
+
+/**
+ * AttrSet的util工具类
+ *
+ * @since 2021-03-24
+ */
+public class TypedAttrUtils {
+ /**
+ * 返回自定义int类型的颜色值
+ *
+ * @param attrs AttrSet类
+ * @param attrName 自定义属性名
+ * @param defValue 默认值
+ * @return 自定义int类型的颜色值
+ */
+ public static int getIntColor(AttrSet attrs, String attrName, int defValue) {
+ if (attrs.getAttr(attrName) != null && attrs.getAttr(attrName).isPresent()) {
+ return attrs.getAttr(attrName).get().getColorValue().getValue();
+ } else {
+ return defValue;
+ }
+ }
+
+ /**
+ * 返回自定义Color类型的颜色值
+ *
+ * @param attrs AttrSet类
+ * @param attrName 自定义属性名
+ * @param defValue 默认值
+ * @return 自定义Color类型的颜色值
+ */
+ public static Color getColor(AttrSet attrs, String attrName, Color defValue) {
+ if (attrs.getAttr(attrName) != null && attrs.getAttr(attrName).isPresent()) {
+ return attrs.getAttr(attrName).get().getColorValue();
+ } else {
+ return defValue;
+ }
+ }
+
+ /**
+ * 返回自定义布尔值
+ *
+ * @param attrs AttrSet类
+ * @param attrName 自定义属性名
+ * @param defValue 默认值
+ * @return 自定义布尔值
+ */
+ public static boolean getBoolean(AttrSet attrs, String attrName, boolean defValue) {
+ if (attrs.getAttr(attrName) != null && attrs.getAttr(attrName).isPresent()) {
+ return attrs.getAttr(attrName).get().getBoolValue();
+ } else {
+ return defValue;
+ }
+ }
+
+ /**
+ * 返回自定义字符串值
+ *
+ * @param attrs AttrSet类
+ * @param attrName 自定义属性名
+ * @param defValue 默认值
+ * @return 自定义字符串值
+ */
+ public static String getString(AttrSet attrs, String attrName, String defValue) {
+ if (attrs.getAttr(attrName) != null && attrs.getAttr(attrName).isPresent()) {
+ return attrs.getAttr(attrName).get().getStringValue();
+ } else {
+ return defValue;
+ }
+ }
+
+ /**
+ * 返回自定义value值
+ *
+ * @param attrs AttrSet类
+ * @param attrName 自定义属性名
+ * @param defValue 默认值
+ * @return 自定义value值
+ */
+ public static int getDimensionPixelSize(AttrSet attrs, String attrName, int defValue) {
+ if (attrs.getAttr(attrName) != null && attrs.getAttr(attrName).isPresent()) {
+ return attrs.getAttr(attrName).get().getDimensionValue();
+ } else {
+ return defValue;
+ }
+ }
+
+ /**
+ * 返回自定义Integer值
+ *
+ * @param attrs AttrSet类
+ * @param attrName 自定义属性名
+ * @param defValue 默认值
+ * @return 自定义Integer值
+ */
+ public static int getInteger(AttrSet attrs, String attrName, int defValue) {
+ if (attrs.getAttr(attrName) != null && attrs.getAttr(attrName).isPresent()) {
+ return attrs.getAttr(attrName).get().getIntegerValue();
+ } else {
+ return defValue;
+ }
+ }
+}
diff --git a/library/src/main/java/com/jungly/gridpasswordview/Util.java b/library/src/main/java/com/jungly/gridpasswordview/Util.java
index 8168bfcb587b40673d795a9bdf19d41ab7f99bc2..ac509956c48f37ad5d06bd9b1c3adf7229b6da26 100644
--- a/library/src/main/java/com/jungly/gridpasswordview/Util.java
+++ b/library/src/main/java/com/jungly/gridpasswordview/Util.java
@@ -1,7 +1,7 @@
package com.jungly.gridpasswordview;
-import android.content.Context;
-import android.util.DisplayMetrics;
+
+import ohos.app.Context;
/**
* @author Jungly
@@ -9,15 +9,11 @@ import android.util.DisplayMetrics;
* 15/3/8 10:07
*/
public class Util {
-
public static int px2sp(Context context, float pxValue) {
- final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
- return (int) (pxValue / fontScale + 0.5f);
+ return 1;
}
public static int dp2px(Context context, int dp) {
- DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
- return (int) ((dp * displayMetrics.density) + 0.5);
+ return 1;
}
-
}
diff --git a/library/src/main/java/com/jungly/gridpasswordview/imebugfixer/ImeDelBugFixedEditText.java b/library/src/main/java/com/jungly/gridpasswordview/imebugfixer/ImeDelBugFixedEditText.java
index 5c994a3ca85f4148a5f15a6e51700056a3350b4d..b9a985b6382bdc75b9669a2582fe20e4765f98ea 100644
--- a/library/src/main/java/com/jungly/gridpasswordview/imebugfixer/ImeDelBugFixedEditText.java
+++ b/library/src/main/java/com/jungly/gridpasswordview/imebugfixer/ImeDelBugFixedEditText.java
@@ -1,74 +1,29 @@
package com.jungly.gridpasswordview.imebugfixer;
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.KeyEvent;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputConnection;
-import android.view.inputmethod.InputConnectionWrapper;
-import android.widget.EditText;
-
-/**
- * @see Stack
- * Overflow
- */
-public class ImeDelBugFixedEditText extends EditText {
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.TextField;
+import ohos.app.Context;
+public class ImeDelBugFixedEditText extends TextField {
private OnDelKeyEventListener delKeyEventListener;
public ImeDelBugFixedEditText(Context context) {
super(context);
}
- public ImeDelBugFixedEditText(Context context, AttributeSet attrs) {
+ public ImeDelBugFixedEditText(Context context, AttrSet attrs) {
super(context, attrs);
}
- public ImeDelBugFixedEditText(Context context, AttributeSet attrs, int defStyle) {
+ public ImeDelBugFixedEditText(Context context, AttrSet attrs, String defStyle) {
super(context, attrs, defStyle);
}
- @Override
- public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
- return new ZanyInputConnection(super.onCreateInputConnection(outAttrs), true);
- }
-
- private class ZanyInputConnection extends InputConnectionWrapper {
-
- public ZanyInputConnection(InputConnection target, boolean mutable) {
- super(target, mutable);
- }
-
- @Override
- public boolean sendKeyEvent(KeyEvent event) {
- if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
- if (delKeyEventListener != null) {
- delKeyEventListener.onDeleteClick();
- return true;
- }
- }
- return super.sendKeyEvent(event);
- }
-
-
- @Override
- public boolean deleteSurroundingText(int beforeLength, int afterLength) {
- if (beforeLength == 1 && afterLength == 0) {
- return sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)) && sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
- }
-
- return super.deleteSurroundingText(beforeLength, afterLength);
- }
- }
-
public void setDelKeyEventListener(OnDelKeyEventListener delKeyEventListener) {
this.delKeyEventListener = delKeyEventListener;
}
public interface OnDelKeyEventListener {
-
void onDeleteClick();
-
}
-
}
\ No newline at end of file
diff --git a/library/src/main/res/layout/divider.xml b/library/src/main/res/layout/divider.xml
deleted file mode 100644
index 7e249fc49e2ff3174bc7b7f8c7493406f4d8c6b7..0000000000000000000000000000000000000000
--- a/library/src/main/res/layout/divider.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
\ No newline at end of file
diff --git a/library/src/main/res/layout/gridpasswordview.xml b/library/src/main/res/layout/gridpasswordview.xml
deleted file mode 100644
index 99b60c4db7d880b27c798455757e11bb0dbfebd9..0000000000000000000000000000000000000000
--- a/library/src/main/res/layout/gridpasswordview.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/library/src/main/res/layout/textview.xml b/library/src/main/res/layout/textview.xml
deleted file mode 100644
index b83614dc1e87a274d2259cf83b83222a2ebe0e3e..0000000000000000000000000000000000000000
--- a/library/src/main/res/layout/textview.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
\ No newline at end of file
diff --git a/library/src/main/res/values/attr.xml b/library/src/main/res/values/attr.xml
deleted file mode 100644
index 568131daec1f4f6c639d50cd426f2e43efca3f79..0000000000000000000000000000000000000000
--- a/library/src/main/res/values/attr.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml
deleted file mode 100644
index 91c1df15c60f750e1e68e5f74b5b7b7a5006bcea..0000000000000000000000000000000000000000
--- a/library/src/main/res/values/styles.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
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..6c298286373e6266fd910aac81429792f08df437
--- /dev/null
+++ b/library/src/main/resources/base/element/string.json
@@ -0,0 +1,8 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "Library"
+ }
+ ]
+}
diff --git a/library/src/main/resources/base/layout/gridpasswordview.xml b/library/src/main/resources/base/layout/gridpasswordview.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b81e3b8cd09c5eef2a86196a1d16152b46584e45
--- /dev/null
+++ b/library/src/main/resources/base/layout/gridpasswordview.xml
@@ -0,0 +1,12 @@
+
+
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 462ba77a79b5b42e643189698928223924adb4be..d0c7ee8440156d4a9324ac5357770747425fef57 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1 @@
-include ':demo', ':library'
+include ':entry', ':library'