tharak-android 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +1 -0
  2. package/build.gradle +45 -0
  3. package/consumer-rules.pro +0 -0
  4. package/libs/vital-sdk.aar +0 -0
  5. package/package.json +22 -0
  6. package/proguard-rules.pro +21 -0
  7. package/src/androidTest/androidTest.iml +11 -0
  8. package/src/androidTest/java/org/tharak/core/ExampleInstrumentedTest.java +27 -0
  9. package/src/androidTest/java/org/thiragatisoft/core/ExampleInstrumentedTest.java +26 -0
  10. package/src/main/AndroidManifest.xml +5 -0
  11. package/src/main/java/org/thiragatisoft/core/AppUtils.java +31 -0
  12. package/src/main/java/org/thiragatisoft/core/FileSelector.java +162 -0
  13. package/src/main/java/org/thiragatisoft/core/MainActivity.java +27 -0
  14. package/src/main/java/org/thiragatisoft/core/RestClient.java +298 -0
  15. package/src/main/java/org/thiragatisoft/core/VitalActivity.java +612 -0
  16. package/src/main/java/org/thiragatisoft/core/VitalsPlugin.java +15 -0
  17. package/src/main/java/org/thiragatisoft/core/VolleyMultipartRequest.java +218 -0
  18. package/src/main/java/org/thiragatisoft/core/http/CapacitorCookieManager.java +175 -0
  19. package/src/main/java/org/thiragatisoft/core/http/CapacitorHttpUrlConnection.java +408 -0
  20. package/src/main/java/org/thiragatisoft/core/http/FilesystemUtils.java +65 -0
  21. package/src/main/java/org/thiragatisoft/core/http/FormUploader.java +219 -0
  22. package/src/main/java/org/thiragatisoft/core/http/Http.java +275 -0
  23. package/src/main/java/org/thiragatisoft/core/http/HttpRequestHandler.java +515 -0
  24. package/src/main/java/org/thiragatisoft/core/http/ICapacitorHttpUrlConnection.java +15 -0
  25. package/src/main/java/org/thiragatisoft/core/http/JSValue.java +68 -0
  26. package/src/main/java/org/thiragatisoft/core/http/MimeType.java +17 -0
  27. package/src/main/main.iml +12 -0
  28. package/src/test/java/org/tharak/ExampleUnitTest.java +17 -0
  29. package/src/test/java/org/tharak/JSObjectTest.java +209 -0
  30. package/src/test/java/org/tharak/PluginMethodHandleTest.java +44 -0
  31. package/src/test/java/org/tharak/util/HostMaskTest.java +70 -0
  32. package/src/test/java/org/thiragatisoft/core/ExampleUnitTest.java +17 -0
  33. package/src/test/test.iml +11 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # tharak-android
package/build.gradle ADDED
@@ -0,0 +1,45 @@
1
+ plugins {
2
+ id 'com.android.library'
3
+ }
4
+
5
+ android {
6
+ compileSdkVersion rootProject.ext.compileSdkVersion
7
+
8
+ defaultConfig {
9
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
10
+ targetSdkVersion targetSdkVersion = project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 29
11
+ versionCode 1
12
+ versionName "1.0"
13
+
14
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15
+ consumerProguardFiles "consumer-rules.pro"
16
+ }
17
+
18
+ buildTypes {
19
+ release {
20
+ minifyEnabled false
21
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22
+ }
23
+ }
24
+ compileOptions {
25
+ sourceCompatibility JavaVersion.VERSION_1_8
26
+ targetCompatibility JavaVersion.VERSION_1_8
27
+ }
28
+ }
29
+ repositories {
30
+ google()
31
+ jcenter()
32
+ mavenCentral()
33
+ flatDir{
34
+ dirs 'src/main/libs', 'libs'
35
+ }
36
+ }
37
+ dependencies {
38
+ implementation fileTree(dir: 'src/main/libs', include: ['*.jar'])
39
+ implementation 'androidx.appcompat:appcompat:1.4.1'
40
+ implementation 'com.google.android.material:material:1.4.0'
41
+ testImplementation 'junit:junit:4.+'
42
+ androidTestImplementation 'androidx.test.ext:junit:1.1.3'
43
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
44
+ implementation project(':capacitor-android')
45
+ }
File without changes
Binary file
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "tharak-android",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/thiragati-soft/tharak-android.git"
12
+ },
13
+ "author": "tharak",
14
+ "license": "ISC",
15
+ "bugs": {
16
+ "url": "https://github.com/thiragati-soft/tharak-android/issues"
17
+ },
18
+ "homepage": "https://github.com/thiragati-soft/tharak-android#readme",
19
+ "dependencies": {
20
+ "@capacitor/android": "^2.5.0"
21
+ }
22
+ }
@@ -0,0 +1,21 @@
1
+ # Add project specific ProGuard rules here.
2
+ # You can control the set of applied configuration files using the
3
+ # proguardFiles setting in build.gradle.
4
+ #
5
+ # For more details, see
6
+ # http://developer.android.com/guide/developing/tools/proguard.html
7
+
8
+ # If your project uses WebView with JS, uncomment the following
9
+ # and specify the fully qualified class name to the JavaScript interface
10
+ # class:
11
+ #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12
+ # public *;
13
+ #}
14
+
15
+ # Uncomment this to preserve the line number information for
16
+ # debugging stack traces.
17
+ #-keepattributes SourceFile,LineNumberTable
18
+
19
+ # If you keep the line number information, uncomment this to
20
+ # hide the original source file name.
21
+ #-renamesourcefileattribute SourceFile
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/java/org/tharak/core" isTestSource="false" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
@@ -0,0 +1,27 @@
1
+ package com.getcapacitor.android;
2
+
3
+ import android.content.Context;
4
+
5
+ import androidx.test.platform.app.InstrumentationRegistry;
6
+ import androidx.test.ext.junit.runners.AndroidJUnit4;
7
+
8
+ import org.junit.Test;
9
+ import org.junit.runner.RunWith;
10
+
11
+ import static org.junit.Assert.*;
12
+
13
+ /**
14
+ * Instrumented test, which will execute on an Android device.
15
+ *
16
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17
+ */
18
+ @RunWith(AndroidJUnit4.class)
19
+ public class ExampleInstrumentedTest {
20
+ @Test
21
+ public void useAppContext() throws Exception {
22
+ // Context of the app under test.
23
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24
+
25
+ assertEquals("com.getcapacitor.android.test", appContext.getPackageName());
26
+ }
27
+ }
@@ -0,0 +1,26 @@
1
+ package org.thiragatisoft.core;
2
+
3
+ import android.content.Context;
4
+
5
+ import androidx.test.platform.app.InstrumentationRegistry;
6
+ import androidx.test.ext.junit.runners.AndroidJUnit4;
7
+
8
+ import org.junit.Test;
9
+ import org.junit.runner.RunWith;
10
+
11
+ import static org.junit.Assert.*;
12
+
13
+ /**
14
+ * Instrumented test, which will execute on an Android device.
15
+ *
16
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17
+ */
18
+ @RunWith(AndroidJUnit4.class)
19
+ public class ExampleInstrumentedTest {
20
+ @Test
21
+ public void useAppContext() {
22
+ // Context of the app under test.
23
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24
+ assertEquals("org.thiragatisoft.core.test", appContext.getPackageName());
25
+ }
26
+ }
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+ package="org.thiragatisoft.core">
4
+
5
+ </manifest>
@@ -0,0 +1,31 @@
1
+ package org.thiragatisoft.core;
2
+
3
+ import com.getcapacitor.CapConfig;
4
+ import com.getcapacitor.JSObject;
5
+ import com.getcapacitor.NativePlugin;
6
+ import com.getcapacitor.Plugin;
7
+ import com.getcapacitor.PluginCall;
8
+ import com.getcapacitor.PluginMethod;
9
+
10
+ @NativePlugin()
11
+ public class AppUtils extends Plugin {
12
+ @PluginMethod()
13
+ public void getConfigProperty(PluginCall call) {
14
+ try {
15
+ String key = call.getString("key");
16
+ String defaultValue = call.getString("defaultValue");
17
+ CapConfig capConfig = this.getBridge().getConfig();
18
+ String value = capConfig.getString(key, defaultValue);
19
+ JSObject result = new JSObject();
20
+ result.put("value", value);
21
+ call.success(result);
22
+ }catch (Exception ex){
23
+ ex.printStackTrace();
24
+ call.error("Error", String.valueOf(500), ex);
25
+ }
26
+ }
27
+ @PluginMethod()
28
+ public boolean isSimulator(){
29
+ return false;
30
+ }
31
+ }
@@ -0,0 +1,162 @@
1
+ package org.thiragatisoft.core;
2
+
3
+ import android.app.Activity;
4
+ import android.content.Context;
5
+ import android.content.Intent;
6
+ import android.database.Cursor;
7
+ import android.net.Uri;
8
+ import android.provider.OpenableColumns;
9
+ import android.util.Log;
10
+ import android.webkit.MimeTypeMap;
11
+
12
+ import com.getcapacitor.JSArray;
13
+ import com.getcapacitor.JSObject;
14
+ import com.getcapacitor.NativePlugin;
15
+ import com.getcapacitor.Plugin;
16
+ import com.getcapacitor.PluginCall;
17
+ import com.getcapacitor.PluginMethod;
18
+
19
+ import org.json.JSONArray;
20
+ import org.json.JSONException;
21
+
22
+ import java.io.File;
23
+ import java.io.FileOutputStream;
24
+ import java.io.InputStream;
25
+ @NativePlugin()
26
+ public class FileSelector extends Plugin {
27
+ static final int PICKFILE_RESULT_CODE = 5;
28
+ PluginCall call;
29
+
30
+ @PluginMethod()
31
+ public void fileSelector(PluginCall call) {
32
+ this.call = call;
33
+ Boolean value = call.getBoolean("multiple_selection");
34
+ JSArray extensions = call.getArray("ext");
35
+ Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT); // Intent.ACTION_OPEN_DOCUMENT, Intent.ACTION_OPEN_DOCUMENT_TREE
36
+
37
+ String[] supportedMimeTypes = new String[extensions.length()];
38
+ String type;
39
+ for(int i = 0; i < extensions.length(); i++)
40
+ {
41
+ try {
42
+ if(extensions.getString(i) == "images")
43
+ {
44
+ supportedMimeTypes[i] = "image/*";
45
+ }
46
+ else if(extensions.getString(i) == "videos")
47
+ {
48
+ supportedMimeTypes[i] = "videos/*";
49
+ }
50
+ else if(extensions.getString(i) == "audios")
51
+ {
52
+ supportedMimeTypes[i] = "audios/*";
53
+ }
54
+ else if(extensions.getString(i) == "*")
55
+ {
56
+ supportedMimeTypes[i] = "*/*";
57
+ break;
58
+ }
59
+ else
60
+ {
61
+ supportedMimeTypes[i] = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extensions.getString(i));
62
+ }
63
+ } catch (JSONException e) {
64
+ Log.i("capacitor",e.getMessage());
65
+ }
66
+ }
67
+ chooseFile.putExtra(Intent.EXTRA_MIME_TYPES,supportedMimeTypes);
68
+ chooseFile.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, value);
69
+ chooseFile.setType("*/*");
70
+ chooseFile.addCategory(Intent.CATEGORY_OPENABLE);
71
+ chooseFile = Intent.createChooser(chooseFile, "Choose file(s)");
72
+ startActivityForResult(call, chooseFile, PICKFILE_RESULT_CODE);
73
+ }
74
+
75
+ @Override
76
+ protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
77
+ super.handleOnActivityResult(requestCode, resultCode, data);
78
+ Log.i("capacitor","handling result");
79
+ if (requestCode == PICKFILE_RESULT_CODE && resultCode == Activity.RESULT_OK) {
80
+ if (data != null) {
81
+ JSONArray pathArray = new JSONArray();
82
+ JSONArray extensionArray = new JSONArray();
83
+ JSONArray org_name_Array = new JSONArray();
84
+ Context context = getBridge().getActivity().getApplicationContext();
85
+ // https://stackoverflow.com/questions/19513556/select-multiple-files-with-intent-action-get-content/48824844
86
+ if (data.getClipData() != null) {
87
+ for (int i = 0; i < data.getClipData().getItemCount(); i++) {
88
+ Uri uri = data.getClipData().getItemAt(i).getUri();
89
+ String[] fileInfo = getCopyFilePath(uri, context);
90
+ pathArray.put(fileInfo[0]);
91
+ org_name_Array.put(fileInfo[1]);
92
+ extensionArray.put(fileInfo[2]);
93
+ }
94
+ } else {
95
+ Uri uri = data.getData();
96
+ String[] fileInfo = getCopyFilePath(uri, context);
97
+ pathArray.put(fileInfo[0]);
98
+ org_name_Array.put(fileInfo[1]);
99
+ extensionArray.put(fileInfo[2]);
100
+ }
101
+
102
+ if (pathArray.length() != 0){
103
+ JSObject ret = new JSObject();
104
+ ret.put("paths", pathArray.toString());
105
+ ret.put("original_names", org_name_Array.toString());
106
+ ret.put("extensions", extensionArray.toString());
107
+ call.success(ret);
108
+ } else {
109
+ call.error("No paths found...");
110
+ }
111
+ }
112
+ }
113
+ }
114
+
115
+ private static String[] getCopyFilePath(Uri uri, Context context) {
116
+ Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
117
+ if(cursor == null)
118
+ {
119
+ return null;
120
+ }
121
+ int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
122
+ if (!cursor.moveToFirst())
123
+ {
124
+ return null;
125
+ }
126
+ String name = (cursor.getString(nameIndex));
127
+ File file = new File(context.getCacheDir(), name);
128
+ try {
129
+ InputStream inputStream = context.getContentResolver().openInputStream(uri);
130
+ FileOutputStream outputStream = new FileOutputStream(file);
131
+ int read = 0;
132
+ int maxBufferSize = 1024 * 1024;
133
+ int bufferSize = Math.min(inputStream.available(), maxBufferSize);
134
+ final byte[] buffers = new byte[bufferSize];
135
+ while ((read = inputStream.read(buffers)) != -1) {
136
+ outputStream.write(buffers, 0, read);
137
+ }
138
+ inputStream.close();
139
+ outputStream.close();
140
+ } catch (Exception e) {
141
+ // Log.i("myfile",e.toString());
142
+ return null;
143
+ } finally {
144
+ if (cursor != null)
145
+ cursor.close();
146
+ }
147
+ /*
148
+ * Path returned by Camera API : http://localhost/_capacitor_file_/data/user/0/io.ionic.starter/cache/12315.1594373585807.jpeg
149
+ * Path returned by file.getPath(): /data/user/0/io.ionic.starter/cache/IMG-20200708-WA0004.jpg
150
+ * So we need to make some corrections here for the fetch API on the web layer to be able to fetch a blob from this file
151
+ * https://github.com/ionic-team/capacitor/blob/cdd317f82828c319e4249716a5fa4a9e6bdf6201/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java
152
+ */
153
+ String fileInfo[] = new String[3];
154
+ String modifiedPath = "_capacitor_file_" + file.getPath();
155
+ fileInfo[0] = modifiedPath;
156
+ Log.i("capacitor",fileInfo[0]);
157
+ fileInfo[1] = name.substring(0,name.indexOf('.'));
158
+ fileInfo[2] = name.substring(name.indexOf('.'));
159
+ return fileInfo;
160
+ }
161
+
162
+ }
@@ -0,0 +1,27 @@
1
+ package org.thiragatisoft.core;
2
+
3
+
4
+ import android.os.Bundle;
5
+ import com.getcapacitor.Plugin;
6
+ import org.thiragatisoft.core.http.Http;
7
+ import java.util.ArrayList;
8
+ import java.util.HashMap;
9
+
10
+ public class MainActivity extends VitalActivity {
11
+ private static final String TAG = "MainActivity";
12
+ private static final HashMap<String, String> callbacks = new HashMap<>();
13
+ @Override
14
+ public void onCreate(Bundle savedInstanceState) {
15
+ super.onCreate(savedInstanceState);
16
+
17
+ // Initializes the Bridge
18
+ this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
19
+ // Additional plugins you've installed go here
20
+ // Ex: add(TotallyAwesomePlugin.class);
21
+ add(AppUtils.class);
22
+ add(RestClient.class);
23
+ add(Http.class);
24
+ add(FileSelector.class);
25
+ }});
26
+ }
27
+ }