Skip to content

Commit d50c71f

Browse files
author
Ryan
committed
Add sample app in Java. Provide progress interface and optimize ECrypt implementations.
1 parent 2db055e commit d50c71f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1222
-132
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/pvryan/easycryptsample/FragmentFile.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import android.view.ViewGroup
2626
import com.pvryan.easycrypt.ECrypt
2727
import kotlinx.android.synthetic.main.fragment_file.*
2828
import org.jetbrains.anko.AnkoLogger
29-
import org.jetbrains.anko.support.v4.indeterminateProgressDialog
3029
import org.jetbrains.anko.support.v4.onUiThread
3130
import org.jetbrains.anko.support.v4.progressDialog
3231
import org.jetbrains.anko.support.v4.toast
@@ -93,8 +92,8 @@ class FragmentFile : Fragment(), AnkoLogger {
9392
eCrypt.hash(fis, ECrypt.HashAlgorithms.SHA_256,
9493
object : ECrypt.ECryptResultListener {
9594

96-
override fun onProgress(progressBy: Int) {
97-
pDialog.incrementProgressBy(progressBy / 1024)
95+
override fun onProgress(newBytes: Int, bytesProcessed: Long) {
96+
pDialog.progress = (bytesProcessed / 1024).toInt()
9897
}
9998

10099
override fun <T> onSuccess(result: T) {
@@ -134,8 +133,8 @@ class FragmentFile : Fragment(), AnkoLogger {
134133
eCrypt.encrypt(fis, edPassword.text.toString(),
135134
object : ECrypt.ECryptResultListener {
136135

137-
override fun onProgress(progressBy: Int) {
138-
pDialog.incrementProgressBy(progressBy / 1024)
136+
override fun onProgress(newBytes: Int, bytesProcessed: Long) {
137+
pDialog.progress = (bytesProcessed / 1024).toInt()
139138
}
140139

141140
override fun <T> onSuccess(result: T) {
@@ -165,10 +164,22 @@ class FragmentFile : Fragment(), AnkoLogger {
165164
try {
166165

167166
val fis = context.contentResolver.openInputStream(data?.data)
168-
val pDialog = indeterminateProgressDialog("Decrypting file...")
167+
168+
val pDialog = progressDialog("Decrypting file...")
169+
pDialog.max = fis.available() / 1024
170+
pDialog.setProgressNumberFormat(null)
171+
pDialog.setOnCancelListener {
172+
fis.close()
173+
toast("Canceled by user.")
174+
}
169175

170176
eCrypt.decrypt(fis, edPassword.text.toString(),
171177
object : ECrypt.ECryptResultListener {
178+
179+
override fun onProgress(newBytes: Int, bytesProcessed: Long) {
180+
pDialog.progress = (bytesProcessed / 1024).toInt()
181+
}
182+
172183
override fun <T> onSuccess(result: T) {
173184
onUiThread {
174185
pDialog.dismiss()

app/src/main/java/com/pvryan/easycryptsample/FragmentString.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package com.pvryan.easycryptsample
1717

1818
import android.os.Bundle
19-
import android.os.Environment
2019
import android.support.annotation.Nullable
2120
import android.support.v4.app.Fragment
2221
import android.view.LayoutInflater
@@ -108,12 +107,9 @@ class FragmentString : Fragment() {
108107
e.printStackTrace()
109108
onUiThread { toast("Error: $message") }
110109
}
111-
},
112-
outputFile = File(Environment.getExternalStorageDirectory().absolutePath +
113-
File.separator + "Hash.txt")
110+
}
114111
)
115112
}
116-
117113
}
118114

119115
companion object {

app/src/main/res/layout/activity_main.xml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
<?xml version="1.0" encoding="utf-8"?><!--
2-
Copyright 2017 Priyank Vasa
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
1+
<?xml version="1.0" encoding="utf-8"?><!-- Copyright 2017 Priyank Vasa
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
65
7-
http://www.apache.org/licenses/LICENSE-2.0
6+
http://www.apache.org/licenses/LICENSE-2.0
87
9-
Unless required by applicable law or agreed to in writing, software
10-
distributed under the License is distributed on an "AS IS" BASIS,
11-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
See the License for the specific language governing permissions and
13-
limitations under the License.
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
1413
-->
1514

1615
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"

app/src/main/res/layout/fragment_file.xml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
<?xml version="1.0" encoding="utf-8"?><!--
2-
Copyright 2017 Priyank Vasa
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
1+
<?xml version="1.0" encoding="utf-8"?><!-- Copyright 2017 Priyank Vasa
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
65
7-
http://www.apache.org/licenses/LICENSE-2.0
6+
http://www.apache.org/licenses/LICENSE-2.0
87
9-
Unless required by applicable law or agreed to in writing, software
10-
distributed under the License is distributed on an "AS IS" BASIS,
11-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
See the License for the specific language governing permissions and
13-
limitations under the License.
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
1413
-->
1514

1615
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

app/src/main/res/layout/fragment_string.xml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
<?xml version="1.0" encoding="utf-8"?><!--
2-
Copyright 2017 Priyank Vasa
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
1+
<?xml version="1.0" encoding="utf-8"?><!-- Copyright 2017 Priyank Vasa
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
65
7-
http://www.apache.org/licenses/LICENSE-2.0
6+
http://www.apache.org/licenses/LICENSE-2.0
87
9-
Unless required by applicable law or agreed to in writing, software
10-
distributed under the License is distributed on an "AS IS" BASIS,
11-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
See the License for the specific language governing permissions and
13-
limitations under the License.
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
1413
-->
1514

1615
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

appJava/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

appJava/build.gradle

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 26
5+
buildToolsVersion "26.0.0"
6+
7+
8+
defaultConfig {
9+
applicationId "com.pvryan.easycryptsample"
10+
minSdkVersion 19
11+
targetSdkVersion 26
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16+
17+
}
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
dexOptions {
25+
}
26+
compileOptions {
27+
sourceCompatibility JavaVersion.VERSION_1_8
28+
targetCompatibility JavaVersion.VERSION_1_8
29+
}
30+
}
31+
32+
dependencies {
33+
implementation fileTree(include: ['*.jar'], dir: 'libs')
34+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
35+
exclude group: 'com.android.support', module: 'support-annotations'
36+
})
37+
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
38+
testImplementation 'junit:junit:4.12'
39+
implementation 'com.android.support:design:26.0.0-beta2'
40+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
41+
implementation project(path: ':easycrypt')
42+
}

appJava/proguard-rules.pro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/ryan/Android/Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile

0 commit comments

Comments
 (0)