From 954cb5cc5fe436b5f84da706c5949fc6dd8f3af9 Mon Sep 17 00:00:00 2001 From: Baya Innovation <86925273+BayaInnovation@users.noreply.github.com> Date: Tue, 25 Apr 2023 02:54:03 +0300 Subject: [PATCH] =?UTF-8?q?=E1=88=80=E1=8C=88=E1=88=AD=20=E1=89=A0?= =?UTF-8?q?=E1=89=80=E1=88=8D=20=E1=8A=A5=E1=8B=8D=E1=89=80=E1=89=B5=20?= =?UTF-8?q?=E1=8B=AD=E1=88=88=E1=88=9D=E1=88=8D=E1=88=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 30 + app/src/main/AndroidManifest.xml | 45 ++ .../com/my/newproject23/BluetoothConnect.java | 111 ++++ .../my/newproject23/BluetoothController.java | 354 ++++++++++ .../java/com/my/newproject23/FileUtil.java | 604 ++++++++++++++++++ .../com/my/newproject23/MainActivity.java | 249 ++++++++ .../com/my/newproject23/RequestNetwork.java | 52 ++ .../RequestNetworkController.java | 185 ++++++ .../com/my/newproject23/SketchwareUtil.java | 209 ++++++ .../com/mychapa/pay/BluetoothConnect.java | 111 ++++ .../com/mychapa/pay/BluetoothController.java | 354 ++++++++++ .../main/java/com/mychapa/pay/FileUtil.java | 604 ++++++++++++++++++ .../java/com/mychapa/pay/MainActivity.java | 250 ++++++++ .../java/com/mychapa/pay/RequestNetwork.java | 52 ++ .../mychapa/pay/RequestNetworkController.java | 185 ++++++ .../java/com/mychapa/pay/SketchwareUtil.java | 209 ++++++ app/src/main/res/drawable-xhdpi/app_icon.png | Bin 0 -> 7211 bytes .../main/res/drawable-xhdpi/default_image.png | Bin 0 -> 981 bytes app/src/main/res/layout/main.xml | 57 ++ app/src/main/res/values/colors.xml | 7 + app/src/main/res/values/secrets.xml | 8 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 15 + build.gradle | 21 + settings.gradle | 1 + 25 files changed, 3716 insertions(+) create mode 100644 app/build.gradle create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/my/newproject23/BluetoothConnect.java create mode 100644 app/src/main/java/com/my/newproject23/BluetoothController.java create mode 100644 app/src/main/java/com/my/newproject23/FileUtil.java create mode 100644 app/src/main/java/com/my/newproject23/MainActivity.java create mode 100644 app/src/main/java/com/my/newproject23/RequestNetwork.java create mode 100644 app/src/main/java/com/my/newproject23/RequestNetworkController.java create mode 100644 app/src/main/java/com/my/newproject23/SketchwareUtil.java create mode 100644 app/src/main/java/com/mychapa/pay/BluetoothConnect.java create mode 100644 app/src/main/java/com/mychapa/pay/BluetoothController.java create mode 100644 app/src/main/java/com/mychapa/pay/FileUtil.java create mode 100644 app/src/main/java/com/mychapa/pay/MainActivity.java create mode 100644 app/src/main/java/com/mychapa/pay/RequestNetwork.java create mode 100644 app/src/main/java/com/mychapa/pay/RequestNetworkController.java create mode 100644 app/src/main/java/com/mychapa/pay/SketchwareUtil.java create mode 100644 app/src/main/res/drawable-xhdpi/app_icon.png create mode 100644 app/src/main/res/drawable-xhdpi/default_image.png create mode 100644 app/src/main/res/layout/main.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/secrets.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 build.gradle create mode 100644 settings.gradle diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..2449b06 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,30 @@ +apply plugin: 'com.android.application' + +android { + useLibrary 'org.apache.http.legacy' + compileSdkVersion 28 + + defaultConfig { + applicationId "com.mychapa.pay" + minSdkVersion 21 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'com.google.android.material:material:1.0.0' + implementation 'com.google.firebase:firebase-database:19.0.0' + implementation 'com.github.bumptech.glide:glide:3.7.0' + implementation 'com.google.code.gson:gson:2.8.0' + implementation 'com.squareup.okhttp3:okhttp:3.9.1' +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d521975 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/my/newproject23/BluetoothConnect.java b/app/src/main/java/com/my/newproject23/BluetoothConnect.java new file mode 100644 index 0000000..422afe8 --- /dev/null +++ b/app/src/main/java/com/my/newproject23/BluetoothConnect.java @@ -0,0 +1,111 @@ +package com.my.newproject23; + +import android.app.Activity; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.content.Intent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Set; +import java.util.UUID; + +public class BluetoothConnect { +private static final String DEFAULT_UUID = "00001101-0000-1000-8000-00805F9B34FB"; + +private Activity activity; + +private BluetoothAdapter bluetoothAdapter; + +public BluetoothConnect(Activity activity) { +this.activity = activity; +this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); +} + +public boolean isBluetoothEnabled() { +if(bluetoothAdapter != null) return true; + +return false; +} + +public boolean isBluetoothActivated() { +if(bluetoothAdapter == null) return false; + +return bluetoothAdapter.isEnabled(); +} + +public void activateBluetooth() { +Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); +activity.startActivity(intent); +} + +public String getRandomUUID() { +return String.valueOf(UUID.randomUUID()); +} + +public void getPairedDevices(ArrayList> results) { +Set pairedDevices = bluetoothAdapter.getBondedDevices(); + +if(pairedDevices.size() > 0) { +for(BluetoothDevice device : pairedDevices) { +HashMap result = new HashMap<>(); +result.put("name", device.getName()); +result.put("address", device.getAddress()); + +results.add(result); +} +} +} + +public void readyConnection(BluetoothConnectionListener listener, String tag) { +if(BluetoothController.getInstance().getState().equals(BluetoothController.STATE_NONE)) { +BluetoothController.getInstance().start(this, listener, tag, UUID.fromString(DEFAULT_UUID), bluetoothAdapter); +} +} + +public void readyConnection(BluetoothConnectionListener listener, String uuid, String tag) { +if(BluetoothController.getInstance().getState().equals(BluetoothController.STATE_NONE)) { +BluetoothController.getInstance().start(this, listener, tag, UUID.fromString(uuid), bluetoothAdapter); +} +} + + +public void startConnection(BluetoothConnectionListener listener, String address, String tag) { +BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address); + +BluetoothController.getInstance().connect(device, this, listener, tag, UUID.fromString(DEFAULT_UUID), bluetoothAdapter); +} + +public void startConnection(BluetoothConnectionListener listener, String uuid, String address, String tag) { +BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address); + +BluetoothController.getInstance().connect(device, this, listener, tag, UUID.fromString(uuid), bluetoothAdapter); +} + +public void stopConnection(BluetoothConnectionListener listener, String tag) { +BluetoothController.getInstance().stop(this, listener, tag); +} + +public void sendData(BluetoothConnectionListener listener, String data, String tag) { +String state = BluetoothController.getInstance().getState(); + +if(!state.equals(BluetoothController.STATE_CONNECTED)) { +listener.onConnectionError(tag, state, "Bluetooth is not connected yet"); +return; +} + +BluetoothController.getInstance().write(data.getBytes()); +} + +public Activity getActivity() { +return activity; +} + +public interface BluetoothConnectionListener { +void onConnected(String tag, HashMap deviceData); +void onDataReceived(String tag, byte[] data, int bytes); +void onDataSent(String tag, byte[] data); +void onConnectionError(String tag, String connectionState, String message); +void onConnectionStopped(String tag); +} +} \ No newline at end of file diff --git a/app/src/main/java/com/my/newproject23/BluetoothController.java b/app/src/main/java/com/my/newproject23/BluetoothController.java new file mode 100644 index 0000000..e7f2245 --- /dev/null +++ b/app/src/main/java/com/my/newproject23/BluetoothController.java @@ -0,0 +1,354 @@ +package com.my.newproject23; + +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothServerSocket; +import android.bluetooth.BluetoothSocket; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.HashMap; +import java.util.UUID; + +public class BluetoothController { +public static final String STATE_NONE = "none"; +public static final String STATE_LISTEN = "listen"; +public static final String STATE_CONNECTING = "connecting"; +public static final String STATE_CONNECTED = "connected"; + +private AcceptThread acceptThread; +private ConnectThread connectThread; +private ConnectedThread connectedThread; + +private String state = STATE_NONE; + +private static BluetoothController instance; + +public static synchronized BluetoothController getInstance() { +if(instance == null) { +instance = new BluetoothController(); +} + +return instance; +} + +public synchronized void start(BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) { +if (connectThread != null) { +connectThread.cancel(); +connectThread = null; +} + +if (connectedThread != null) { +connectedThread.cancel(); +connectedThread = null; +} + +if (acceptThread != null) { +acceptThread.cancel(); +acceptThread = null; +} + +acceptThread = new AcceptThread(bluetoothConnect, listener, tag, uuid, bluetoothAdapter); +acceptThread.start();} + +public synchronized void connect(BluetoothDevice device, BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) { +if (state.equals(STATE_CONNECTING)) { +if (connectThread != null) { +connectThread.cancel(); +connectThread = null; +} +} + +if (connectedThread != null) { +connectedThread.cancel(); +connectedThread = null; +} + +connectThread = new ConnectThread(device, bluetoothConnect, listener, tag, uuid, bluetoothAdapter); +connectThread.start(); +} + +public synchronized void connected(BluetoothSocket socket, final BluetoothDevice device, BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag) { +if (connectThread != null) { +connectThread.cancel(); +connectThread = null; +} + +if (connectedThread != null) { +connectedThread.cancel(); +connectedThread = null; +} + +if (acceptThread != null) { +acceptThread.cancel(); +acceptThread = null; +} + +connectedThread = new ConnectedThread(socket, bluetoothConnect, listener, tag); +connectedThread.start(); + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +HashMap deviceMap = new HashMap<>(); +deviceMap.put("name", device.getName()); +deviceMap.put("address", device.getAddress()); + +listener.onConnected(tag, deviceMap); +} +}); +} + +public synchronized void stop(BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag) { +if (connectThread != null) { +connectThread.cancel(); +connectThread = null; +} + +if (connectedThread != null) { +connectedThread.cancel(); +connectedThread = null; +} + +if (acceptThread != null) { +acceptThread.cancel(); +acceptThread = null; +} + +state = STATE_NONE; + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +listener.onConnectionStopped(tag); +} +}); +} + +public void write(byte[] out) { +ConnectedThread r; + +synchronized (this) { +if (!state.equals(STATE_CONNECTED)) return; +r = connectedThread; +} + +r.write(out); +} + +public void connectionFailed(BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag, final String message) { +state = STATE_NONE; + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +listener.onConnectionError(tag, state, message); +} +}); +} + +public void connectionLost(BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag) { +state = STATE_NONE; + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +listener.onConnectionError(tag, state, "Bluetooth connection is disconnected"); +} +}); +} + +public String getState() { +return state; +} + +private class AcceptThread extends Thread { +private BluetoothServerSocket serverSocket; + +private BluetoothConnect bluetoothConnect; +private BluetoothConnect.BluetoothConnectionListener listener; +private String tag; + +public AcceptThread(BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) { +this.bluetoothConnect = bluetoothConnect; +this.listener = listener; +this.tag = tag; + +try { +serverSocket = bluetoothAdapter.listenUsingRfcommWithServiceRecord(tag, uuid); +} catch (Exception e) { +e.printStackTrace(); +} + +state = STATE_LISTEN; +} + +@Override +public void run() { +BluetoothSocket bluetoothSocket; + +while (!state.equals(STATE_CONNECTED)) { +try { +bluetoothSocket = serverSocket.accept(); +} catch (Exception e) { +e.printStackTrace(); +break; +} + +if (bluetoothSocket != null) { +synchronized (BluetoothController.this) { +switch (state) { +case STATE_LISTEN: +case STATE_CONNECTING: +connected(bluetoothSocket, bluetoothSocket.getRemoteDevice(), bluetoothConnect, listener, tag); +break; +case STATE_NONE: +case STATE_CONNECTED: +try { +bluetoothSocket.close(); +} catch (Exception e) { +e.printStackTrace(); +} +break; +} +} +} +} +} + +public void cancel() { +try { +serverSocket.close(); +} catch (Exception e) { +e.printStackTrace(); +} +} +} + +private class ConnectThread extends Thread { +private BluetoothDevice device; +private BluetoothSocket socket; + +private BluetoothConnect bluetoothConnect; +private BluetoothConnect.BluetoothConnectionListener listener; +private String tag; +private BluetoothAdapter bluetoothAdapter; + +public ConnectThread(BluetoothDevice device, BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) { +this.device = device; +this.bluetoothConnect = bluetoothConnect; +this.listener = listener; +this.tag = tag; +this.bluetoothAdapter = bluetoothAdapter; + +try { +socket = device.createRfcommSocketToServiceRecord(uuid); +} catch (Exception e) { +e.printStackTrace(); +} + +state = STATE_CONNECTING; +} + +@Override +public void run() { +bluetoothAdapter.cancelDiscovery(); + +try { +socket.connect(); +} catch (Exception e) { +try { +socket.close(); +} catch (Exception e2) { +e2.printStackTrace(); +} +connectionFailed(bluetoothConnect, listener, tag, e.getMessage()); +return; +} + +synchronized (BluetoothController.this) { +connectThread = null; +} + +connected(socket, device, bluetoothConnect, listener, tag); +} + +public void cancel() { +try { +socket.close(); +} catch (Exception e) { +e.printStackTrace(); +} +} +} + +private class ConnectedThread extends Thread { +private BluetoothSocket socket; +private InputStream inputStream; +private OutputStream outputStream; + +private BluetoothConnect bluetoothConnect; +private BluetoothConnect.BluetoothConnectionListener listener; +private String tag; + +public ConnectedThread(BluetoothSocket socket, BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag) { +this.bluetoothConnect = bluetoothConnect; +this.listener = listener; +this.tag = tag; + +this.socket = socket; + +try { +inputStream = socket.getInputStream(); +outputStream = socket.getOutputStream(); +} catch (Exception e) { +e.printStackTrace(); +} + +state = STATE_CONNECTED; +} + +public void run() { +while (state.equals(STATE_CONNECTED)) { +try { +final byte[] buffer = new byte[1024]; +final int bytes = inputStream.read(buffer); + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +listener.onDataReceived(tag, buffer, bytes); +} +}); +} catch (Exception e) { +e.printStackTrace(); +connectionLost(bluetoothConnect, listener, tag); +break; +} +} +} + +public void write(final byte[] buffer) { +try { +outputStream.write(buffer); + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +listener.onDataSent(tag, buffer); +} +}); +} catch (Exception e) { +e.printStackTrace(); +} +} + +public void cancel() { +try { +socket.close(); +} catch (Exception e) { +e.printStackTrace(); +} +} +} +} \ No newline at end of file diff --git a/app/src/main/java/com/my/newproject23/FileUtil.java b/app/src/main/java/com/my/newproject23/FileUtil.java new file mode 100644 index 0000000..f97da04 --- /dev/null +++ b/app/src/main/java/com/my/newproject23/FileUtil.java @@ -0,0 +1,604 @@ +package com.my.newproject23; + +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.Context; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.ColorMatrix; +import android.graphics.ColorMatrixColorFilter; +import android.graphics.LightingColorFilter; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; +import android.graphics.Rect; +import android.graphics.RectF; +import android.media.ExifInterface; +import android.net.Uri; +import android.os.Environment; +import android.provider.DocumentsContract; +import android.provider.MediaStore; +import android.text.TextUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.net.URLDecoder; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + +public class FileUtil { + +private static void createNewFile(String path) { +int lastSep = path.lastIndexOf(File.separator); +if (lastSep > 0) { +String dirPath = path.substring(0, lastSep); +makeDir(dirPath); +} + +File file = new File(path); + +try { +if (!file.exists()) +file.createNewFile(); +} catch (IOException e) { +e.printStackTrace(); +} +} + +public static String readFile(String path) { +createNewFile(path); + +StringBuilder sb = new StringBuilder(); +FileReader fr = null; +try { +fr = new FileReader(new File(path)); + +char[] buff = new char[1024]; +int length = 0; + +while ((length = fr.read(buff)) > 0) { +sb.append(new String(buff, 0, length)); +} +} catch (IOException e) { +e.printStackTrace(); +} finally { +if (fr != null) { +try { +fr.close(); +} catch (Exception e) { +e.printStackTrace(); +} +} +} + +return sb.toString(); +} + +public static void writeFile(String path, String str) { +createNewFile(path); +FileWriter fileWriter = null; + +try { +fileWriter = new FileWriter(new File(path), false); +fileWriter.write(str); +fileWriter.flush(); +} catch (IOException e) { +e.printStackTrace(); +} finally { +try { +if (fileWriter != null) +fileWriter.close(); +} catch (IOException e) { +e.printStackTrace(); +} +} +} + +public static void copyFile(String sourcePath, String destPath) { +if (!isExistFile(sourcePath)) return; +createNewFile(destPath); + +FileInputStream fis = null; +FileOutputStream fos = null; + +try { +fis = new FileInputStream(sourcePath); +fos = new FileOutputStream(destPath, false); + +byte[] buff = new byte[1024]; +int length = 0; + +while ((length = fis.read(buff)) > 0) { +fos.write(buff, 0, length); +} +} catch (IOException e) { +e.printStackTrace(); +} finally { +if (fis != null) { +try { +fis.close(); +} catch (IOException e) { +e.printStackTrace(); +} +} +if (fos != null) { +try { +fos.close(); +} catch (IOException e) { +e.printStackTrace(); +} +} +} +} + +public static void moveFile(String sourcePath, String destPath) { +copyFile(sourcePath, destPath); +deleteFile(sourcePath); +} + +public static void deleteFile(String path) { +File file = new File(path); + +if (!file.exists()) return; + +if (file.isFile()) { +file.delete(); +return; +} + +File[] fileArr = file.listFiles(); + +if (fileArr != null) { +for (File subFile : fileArr) { +if (subFile.isDirectory()) { +deleteFile(subFile.getAbsolutePath()); +} + +if (subFile.isFile()) { +subFile.delete(); +} +} +} + +file.delete(); +} + +public static boolean isExistFile(String path) { +File file = new File(path); +return file.exists(); +} + +public static void makeDir(String path) { +if (!isExistFile(path)) { +File file = new File(path); +file.mkdirs(); +} +} + +public static void listDir(String path, ArrayList list) { +File dir = new File(path); +if (!dir.exists() || dir.isFile()) return; + +File[] listFiles = dir.listFiles(); +if (listFiles == null || listFiles.length <= 0) return; + +if (list == null) return; +list.clear(); +for (File file : listFiles) { +list.add(file.getAbsolutePath()); +} +} + +public static boolean isDirectory(String path) { +if (!isExistFile(path)) return false; +return new File(path).isDirectory(); +} + +public static boolean isFile(String path) { +if (!isExistFile(path)) return false; +return new File(path).isFile(); +} + +public static long getFileLength(String path) { +if (!isExistFile(path)) return 0; +return new File(path).length(); +} + +public static String getExternalStorageDir() { +return Environment.getExternalStorageDirectory().getAbsolutePath(); +} + +public static String getPackageDataDir(Context context) { +return context.getExternalFilesDir(null).getAbsolutePath(); +} + +public static String getPublicDir(String type) { +return Environment.getExternalStoragePublicDirectory(type).getAbsolutePath(); +} + +public static String convertUriToFilePath(final Context context, final Uri uri) { +String path = null; +if (DocumentsContract.isDocumentUri(context, uri)) { +if (isExternalStorageDocument(uri)) { +final String docId = DocumentsContract.getDocumentId(uri); +final String[] split = docId.split(":"); +final String type = split[0]; + +if ("primary".equalsIgnoreCase(type)) { +path = Environment.getExternalStorageDirectory() + "/" + split[1]; +} +} else if (isDownloadsDocument(uri)) { +final String id = DocumentsContract.getDocumentId(uri); + +if (!TextUtils.isEmpty(id)) { +if (id.startsWith("raw:")) { +return id.replaceFirst("raw:", ""); +} +} + +final Uri contentUri = ContentUris +.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); + +path = getDataColumn(context, contentUri, null, null); +} else if (isMediaDocument(uri)) { +final String docId = DocumentsContract.getDocumentId(uri); +final String[] split = docId.split(":"); +final String type = split[0]; + +Uri contentUri = null; +if ("image".equals(type)) { +contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; +} else if ("video".equals(type)) { +contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; +} else if ("audio".equals(type)) { +contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; +} + +final String selection = MediaStore.Audio.Media._ID + "=?"; +final String[] selectionArgs = new String[]{ +split[1] +}; + +path = getDataColumn(context, contentUri, selection, selectionArgs); +} +} else if (ContentResolver.SCHEME_CONTENT.equalsIgnoreCase(uri.getScheme())) { +path = getDataColumn(context, uri, null, null); +} else if (ContentResolver.SCHEME_FILE.equalsIgnoreCase(uri.getScheme())) { +path = uri.getPath(); +} + +if (path != null) { +try { +return URLDecoder.decode(path, "UTF-8"); +}catch(Exception e){ +return null; +} +} +return null; +} + +private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { +Cursor cursor = null; + +final String column = MediaStore.Images.Media.DATA; +final String[] projection = { +column +}; + +try { +cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); +if (cursor != null && cursor.moveToFirst()) { +final int column_index = cursor.getColumnIndexOrThrow(column); +return cursor.getString(column_index); +} +} catch (Exception e) { + +} finally { +if (cursor != null) { +cursor.close(); +} +} +return null; +} + + +private static boolean isExternalStorageDocument(Uri uri) { +return "com.android.externalstorage.documents".equals(uri.getAuthority()); +} + +private static boolean isDownloadsDocument(Uri uri) { +return "com.android.providers.downloads.documents".equals(uri.getAuthority()); +} + +private static boolean isMediaDocument(Uri uri) { +return "com.android.providers.media.documents".equals(uri.getAuthority()); +} + +private static void saveBitmap(Bitmap bitmap, String destPath) { +FileOutputStream out = null; +FileUtil.createNewFile(destPath); +try { +out = new FileOutputStream(new File(destPath)); +bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); +} catch (Exception e) { +e.printStackTrace(); +} finally { +try { +if (out != null) { +out.close(); +} +} catch (IOException e) { +e.printStackTrace(); +} +} +} + +public static Bitmap getScaledBitmap(String path, int max) { +Bitmap src = BitmapFactory.decodeFile(path); + +int width = src.getWidth(); +int height = src.getHeight(); +float rate = 0.0f; + +if (width > height) { +rate = max / (float) width; +height = (int) (height * rate); +width = max; +} else { +rate = max / (float) height; +width = (int) (width * rate); +height = max; +} + +return Bitmap.createScaledBitmap(src, width, height, true); +} + +public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { +final int width = options.outWidth; +final int height = options.outHeight; +int inSampleSize = 1; + +if (height > reqHeight || width > reqWidth) { +final int halfHeight = height / 2; +final int halfWidth = width / 2; + +while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) { +inSampleSize *= 2; +} +} + +return inSampleSize; +} + +public static Bitmap decodeSampleBitmapFromPath(String path, int reqWidth, int reqHeight) { +final BitmapFactory.Options options = new BitmapFactory.Options(); +options.inJustDecodeBounds = true; +BitmapFactory.decodeFile(path, options); + +options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); + +options.inJustDecodeBounds = false; +return BitmapFactory.decodeFile(path, options); +} + +public static void resizeBitmapFileRetainRatio(String fromPath, String destPath, int max) { +if (!isExistFile(fromPath)) return; +Bitmap bitmap = getScaledBitmap(fromPath, max); +saveBitmap(bitmap, destPath); +} + +public static void resizeBitmapFileToSquare(String fromPath, String destPath, int max) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Bitmap bitmap = Bitmap.createScaledBitmap(src, max, max, true); +saveBitmap(bitmap, destPath); +} + +public static void resizeBitmapFileToCircle(String fromPath, String destPath) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), +src.getHeight(), Bitmap.Config.ARGB_8888); +Canvas canvas = new Canvas(bitmap); + +final int color = 0xff424242; +final Paint paint = new Paint(); +final Rect rect = new Rect(0, 0, src.getWidth(), src.getHeight()); + +paint.setAntiAlias(true); +canvas.drawARGB(0, 0, 0, 0); +paint.setColor(color); +canvas.drawCircle(src.getWidth() / 2, src.getHeight() / 2, +src.getWidth() / 2, paint); +paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); +canvas.drawBitmap(src, rect, rect, paint); + +saveBitmap(bitmap, destPath); +} + +public static void resizeBitmapFileWithRoundedBorder(String fromPath, String destPath, int pixels) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src +.getHeight(), Bitmap.Config.ARGB_8888); +Canvas canvas = new Canvas(bitmap); + +final int color = 0xff424242; +final Paint paint = new Paint(); +final Rect rect = new Rect(0, 0, src.getWidth(), src.getHeight()); +final RectF rectF = new RectF(rect); +final float roundPx = pixels; + +paint.setAntiAlias(true); +canvas.drawARGB(0, 0, 0, 0); +paint.setColor(color); +canvas.drawRoundRect(rectF, roundPx, roundPx, paint); + +paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); +canvas.drawBitmap(src, rect, rect, paint); + +saveBitmap(bitmap, destPath); +} + +public static void cropBitmapFileFromCenter(String fromPath, String destPath, int w, int h) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); + +int width = src.getWidth(); +int height = src.getHeight(); + +if (width < w && height < h) +return; + +int x = 0; +int y = 0; + +if (width > w) +x = (width - w) / 2; + +if (height > h) +y = (height - h) / 2; + +int cw = w; +int ch = h; + +if (w > width) +cw = width; + +if (h > height) +ch = height; + +Bitmap bitmap = Bitmap.createBitmap(src, x, y, cw, ch); +saveBitmap(bitmap, destPath); +} + +public static void rotateBitmapFile(String fromPath, String destPath, float angle) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Matrix matrix = new Matrix(); +matrix.postRotate(angle); +Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); +saveBitmap(bitmap, destPath); +} + +public static void scaleBitmapFile(String fromPath, String destPath, float x, float y) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Matrix matrix = new Matrix(); +matrix.postScale(x, y); + +int w = src.getWidth(); +int h = src.getHeight(); + +Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, w, h, matrix, true); +saveBitmap(bitmap, destPath); +} + +public static void skewBitmapFile(String fromPath, String destPath, float x, float y) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Matrix matrix = new Matrix(); +matrix.postSkew(x, y); + +int w = src.getWidth(); +int h = src.getHeight(); + +Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, w, h, matrix, true); +saveBitmap(bitmap, destPath); +} + +public static void setBitmapFileColorFilter(String fromPath, String destPath, int color) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, +src.getWidth() - 1, src.getHeight() - 1); +Paint p = new Paint(); +ColorFilter filter = new LightingColorFilter(color, 1); +p.setColorFilter(filter); +Canvas canvas = new Canvas(bitmap); +canvas.drawBitmap(bitmap, 0, 0, p); +saveBitmap(bitmap, destPath); +} + +public static void setBitmapFileBrightness(String fromPath, String destPath, float brightness) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +ColorMatrix cm = new ColorMatrix(new float[] +{ +1, 0, 0, 0, brightness, +0, 1, 0, 0, brightness, +0, 0, 1, 0, brightness, +0, 0, 0, 1, 0 +}); + +Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); +Canvas canvas = new Canvas(bitmap); +Paint paint = new Paint(); +paint.setColorFilter(new ColorMatrixColorFilter(cm)); +canvas.drawBitmap(src, 0, 0, paint); +saveBitmap(bitmap, destPath); +} + +public static void setBitmapFileContrast(String fromPath, String destPath, float contrast) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +ColorMatrix cm = new ColorMatrix(new float[] +{ +contrast, 0, 0, 0, 0, +0, contrast, 0, 0, 0, +0, 0, contrast, 0, 0, +0, 0, 0, 1, 0 +}); + +Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); +Canvas canvas = new Canvas(bitmap); +Paint paint = new Paint(); +paint.setColorFilter(new ColorMatrixColorFilter(cm)); +canvas.drawBitmap(src, 0, 0, paint); + +saveBitmap(bitmap, destPath); +} + +public static int getJpegRotate(String filePath) { +int rotate = 0; +try { +ExifInterface exif = new ExifInterface(filePath); +int iOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); + +switch (iOrientation) { +case ExifInterface.ORIENTATION_ROTATE_90: +rotate = 90; +break; +case ExifInterface.ORIENTATION_ROTATE_180: +rotate = 180; +break; +case ExifInterface.ORIENTATION_ROTATE_270: +rotate = 270; +break; +default: +rotate = 0; +break; +} +} +catch (IOException e) { +return 0; +} + +return rotate; +} +public static File createNewPictureFile(Context context) { +SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss"); +String fileName = date.format(new Date()) + ".jpg"; +File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_DCIM).getAbsolutePath() + File.separator + fileName); +return file; +} +} \ No newline at end of file diff --git a/app/src/main/java/com/my/newproject23/MainActivity.java b/app/src/main/java/com/my/newproject23/MainActivity.java new file mode 100644 index 0000000..98bd999 --- /dev/null +++ b/app/src/main/java/com/my/newproject23/MainActivity.java @@ -0,0 +1,249 @@ +package com.my.newproject23; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.annotation.*; +import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import com.google.android.material.appbar.AppBarLayout; +import android.app.*; +import android.os.*; +import android.view.*; +import android.view.View.*; +import android.widget.*; +import android.content.*; +import android.content.res.*; +import android.graphics.*; +import android.graphics.drawable.*; +import android.media.*; +import android.net.*; +import android.text.*; +import android.text.style.*; +import android.util.*; +import android.webkit.*; +import android.animation.*; +import android.view.animation.*; +import java.util.*; +import java.util.regex.*; +import java.text.*; +import org.json.*; +import java.util.HashMap; +import android.widget.LinearLayout; +import android.widget.Button; +import android.widget.EditText; +import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.ValueEventListener; +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.DatabaseError; +import com.google.firebase.database.GenericTypeIndicator; +import com.google.firebase.database.ChildEventListener; +import android.view.View; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.DialogFragment; + + +public class MainActivity extends AppCompatActivity { + + private FirebaseDatabase _firebase = FirebaseDatabase.getInstance(); + + private Toolbar _toolbar; + private AppBarLayout _app_bar; + private CoordinatorLayout _coordinator; + private HashMap header = new HashMap<>(); + private HashMap chapa = new HashMap<>(); + private HashMap response = new HashMap<>(); + private String handler = ""; + private HashMap msl = new HashMap<>(); + + private LinearLayout linear1; + private Button button1; + private EditText edittext1; + private LinearLayout linear2; + + private RequestNetwork cnet; + private RequestNetwork.RequestListener _cnet_request_listener; + private DatabaseReference hh = _firebase.getReference("hh"); + private ChildEventListener _hh_child_listener; + @Override + protected void onCreate(Bundle _savedInstanceState) { + super.onCreate(_savedInstanceState); + setContentView(R.layout.main); + initialize(_savedInstanceState); + com.google.firebase.FirebaseApp.initializeApp(this); + initializeLogic(); + } + + private void initialize(Bundle _savedInstanceState) { + + _app_bar = (AppBarLayout) findViewById(R.id._app_bar); + _coordinator = (CoordinatorLayout) findViewById(R.id._coordinator); + _toolbar = (Toolbar) findViewById(R.id._toolbar); + setSupportActionBar(_toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + _toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View _v) { + onBackPressed(); + } + }); + linear1 = (LinearLayout) findViewById(R.id.linear1); + button1 = (Button) findViewById(R.id.button1); + edittext1 = (EditText) findViewById(R.id.edittext1); + linear2 = (LinearLayout) findViewById(R.id.linear2); + cnet = new RequestNetwork(this); + + button1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View _view) { + header = new HashMap<>(); + header.put("Authorization", "Bearer CHASECK_TEST-GOu5EEWv11fsJexRDhpq6HTpEQYCCPb3"); + cnet.setHeaders(header); + chapa = new HashMap<>(); + chapa.put("amount", "100"); + chapa.put("currency", "ETB"); + chapa.put("email", "baya@gmail.com"); + chapa.put("first_name", "lij"); + chapa.put("last_name", "baya"); + chapa.put("phone_number", "0900000000"); + chapa.put("tx_ref", hh.push().getKey()); + chapa.put("callback_url", "https://webhook.site/077164d6-29cb-40df-ba29-8a00e59a7e60"); + chapa.put("return_url", "https://www.google.com/"); + chapa.put("customization[title]", "ambesa baus ticket"); + chapa.put("customization[description]", "for travel"); + cnet.setParams(chapa, RequestNetworkController.REQUEST_BODY); + cnet.startRequestNetwork(RequestNetworkController.POST, "https://api.chapa.co/v1/transaction/mobile-initialize", "", _cnet_request_listener); + } + }); + + _cnet_request_listener = new RequestNetwork.RequestListener() { + @Override + public void onResponse(String _param1, String _param2, HashMap _param3) { + final String _tag = _param1; + final String _response = _param2; + final HashMap _responseHeaders = _param3; + response = new Gson().fromJson(_response, new TypeToken>(){}.getType()); + handler = (new Gson()).toJson(response.get("data"), new TypeToken>(){}.getType()); + + msl = new Gson().fromJson(handler, new TypeToken>(){}.getType()); + edittext1.setText(msl.get("checkout_url").toString()); + } + + @Override + public void onErrorResponse(String _param1, String _param2) { + final String _tag = _param1; + final String _message = _param2; + + } + }; + + _hh_child_listener = new ChildEventListener() { + @Override + public void onChildAdded(DataSnapshot _param1, String _param2) { + GenericTypeIndicator> _ind = new GenericTypeIndicator>() {}; + final String _childKey = _param1.getKey(); + final HashMap _childValue = _param1.getValue(_ind); + + } + + @Override + public void onChildChanged(DataSnapshot _param1, String _param2) { + GenericTypeIndicator> _ind = new GenericTypeIndicator>() {}; + final String _childKey = _param1.getKey(); + final HashMap _childValue = _param1.getValue(_ind); + + } + + @Override + public void onChildMoved(DataSnapshot _param1, String _param2) { + + } + + @Override + public void onChildRemoved(DataSnapshot _param1) { + GenericTypeIndicator> _ind = new GenericTypeIndicator>() {}; + final String _childKey = _param1.getKey(); + final HashMap _childValue = _param1.getValue(_ind); + + } + + @Override + public void onCancelled(DatabaseError _param1) { + final int _errorCode = _param1.getCode(); + final String _errorMessage = _param1.getMessage(); + + } + }; + hh.addChildEventListener(_hh_child_listener); + } + + private void initializeLogic() { + } + + @Override + protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) { + + super.onActivityResult(_requestCode, _resultCode, _data); + + switch (_requestCode) { + + default: + break; + } + } + + @Deprecated + public void showMessage(String _s) { + Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show(); + } + + @Deprecated + public int getLocationX(View _v) { + int _location[] = new int[2]; + _v.getLocationInWindow(_location); + return _location[0]; + } + + @Deprecated + public int getLocationY(View _v) { + int _location[] = new int[2]; + _v.getLocationInWindow(_location); + return _location[1]; + } + + @Deprecated + public int getRandom(int _min, int _max) { + Random random = new Random(); + return random.nextInt(_max - _min + 1) + _min; + } + + @Deprecated + public ArrayList getCheckedItemPositionsToArray(ListView _list) { + ArrayList _result = new ArrayList(); + SparseBooleanArray _arr = _list.getCheckedItemPositions(); + for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) { + if (_arr.valueAt(_iIdx)) + _result.add((double)_arr.keyAt(_iIdx)); + } + return _result; + } + + @Deprecated + public float getDip(int _input){ + return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics()); + } + + @Deprecated + public int getDisplayWidthPixels(){ + return getResources().getDisplayMetrics().widthPixels; + } + + @Deprecated + public int getDisplayHeightPixels(){ + return getResources().getDisplayMetrics().heightPixels; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/my/newproject23/RequestNetwork.java b/app/src/main/java/com/my/newproject23/RequestNetwork.java new file mode 100644 index 0000000..dd276c4 --- /dev/null +++ b/app/src/main/java/com/my/newproject23/RequestNetwork.java @@ -0,0 +1,52 @@ +package com.my.newproject23; + +import android.app.Activity; + +import java.util.HashMap; + +public class RequestNetwork { +private HashMap params = new HashMap<>(); +private HashMap headers = new HashMap<>(); + +private Activity activity; + +private int requestType = 0; + +public RequestNetwork(Activity activity) { +this.activity = activity; +} + +public void setHeaders(HashMap headers) { +this.headers = headers; +} + +public void setParams(HashMap params, int requestType) { +this.params = params; +this.requestType = requestType; +} + +public HashMap getParams() { +return params; +} + +public HashMap getHeaders() { +return headers; +} + +public Activity getActivity() { +return activity; +} + +public int getRequestType() { +return requestType; +} + +public void startRequestNetwork(String method, String url, String tag, RequestListener requestListener) { +RequestNetworkController.getInstance().execute(this, method, url, tag, requestListener); +} + +public interface RequestListener { +public void onResponse(String tag, String response, HashMap responseHeaders); +public void onErrorResponse(String tag, String message); +} +} diff --git a/app/src/main/java/com/my/newproject23/RequestNetworkController.java b/app/src/main/java/com/my/newproject23/RequestNetworkController.java new file mode 100644 index 0000000..5b621c1 --- /dev/null +++ b/app/src/main/java/com/my/newproject23/RequestNetworkController.java @@ -0,0 +1,185 @@ +package com.my.newproject23; + +import com.google.gson.Gson; + +import java.io.IOException; +import java.security.cert.CertificateException; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.FormBody; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class RequestNetworkController { +public static final String GET = "GET"; +public static final String POST = "POST"; +public static final String PUT = "PUT"; +public static final String DELETE = "DELETE"; + +public static final int REQUEST_PARAM = 0; +public static final int REQUEST_BODY = 1; + +private static final int SOCKET_TIMEOUT = 15000; +private static final int READ_TIMEOUT = 25000; + +protected OkHttpClient client; + +private static RequestNetworkController mInstance; + +public static synchronized RequestNetworkController getInstance() { +if(mInstance == null) { +mInstance = new RequestNetworkController(); +} +return mInstance; +} + +private OkHttpClient getClient() { +if (client == null) { +OkHttpClient.Builder builder = new OkHttpClient.Builder(); + +try { +final TrustManager[] trustAllCerts = new TrustManager[]{ +new X509TrustManager() { +@Override +public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) +throws CertificateException { +} + +@Override +public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) +throws CertificateException { +} + +@Override +public java.security.cert.X509Certificate[] getAcceptedIssuers() { +return new java.security.cert.X509Certificate[]{}; +} +} +}; + +final SSLContext sslContext = SSLContext.getInstance("TLS"); +sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); +final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); +builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]); +builder.connectTimeout(SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); +builder.readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS); +builder.writeTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS); +builder.hostnameVerifier(new HostnameVerifier() { +@Override +public boolean verify(String hostname, SSLSession session) { +return true; +} +}); +} catch (Exception e) { +} + +client = builder.build(); +} + +return client; +} + +public void execute(final RequestNetwork requestNetwork, String method, String url, final String tag, final RequestNetwork.RequestListener requestListener) { +Request.Builder reqBuilder = new Request.Builder(); +Headers.Builder headerBuilder = new Headers.Builder(); + +if(requestNetwork.getHeaders().size() > 0) { +HashMap headers = requestNetwork.getHeaders(); + +for(HashMap.Entry header : headers.entrySet()) { +headerBuilder.add(header.getKey(), String.valueOf(header.getValue())); +} +} + +try { +if (requestNetwork.getRequestType() == REQUEST_PARAM) { +if (method.equals(GET)) { +HttpUrl.Builder httpBuilder; + +try { +httpBuilder = HttpUrl.parse(url).newBuilder(); +} catch (NullPointerException ne) { +throw new NullPointerException("unexpected url: " + url); +} + +if (requestNetwork.getParams().size() > 0) { +HashMap params = requestNetwork.getParams(); + +for (HashMap.Entry param : params.entrySet()) { +httpBuilder.addQueryParameter(param.getKey(), String.valueOf(param.getValue())); +} +} + +reqBuilder.url(httpBuilder.build()).headers(headerBuilder.build()).get(); +} else { +FormBody.Builder formBuilder = new FormBody.Builder(); +if (requestNetwork.getParams().size() > 0) { +HashMap params = requestNetwork.getParams(); + +for (HashMap.Entry param : params.entrySet()) { +formBuilder.add(param.getKey(), String.valueOf(param.getValue())); +} +} + +RequestBody reqBody = formBuilder.build(); + +reqBuilder.url(url).headers(headerBuilder.build()).method(method, reqBody); +} +} else { +RequestBody reqBody = RequestBody.create(okhttp3.MediaType.parse("application/json"), new Gson().toJson(requestNetwork.getParams())); + +if (method.equals(GET)) { +reqBuilder.url(url).headers(headerBuilder.build()).get(); +} else { +reqBuilder.url(url).headers(headerBuilder.build()).method(method, reqBody); +} +} + +Request req = reqBuilder.build(); + +getClient().newCall(req).enqueue(new Callback() { +@Override +public void onFailure(Call call, final IOException e) { +requestNetwork.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +requestListener.onErrorResponse(tag, e.getMessage()); +} +}); +} + +@Override +public void onResponse(Call call, final Response response) throws IOException { +final String responseBody = response.body().string().trim(); +requestNetwork.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +Headers b = response.headers(); +HashMap map = new HashMap<>(); +for(String s : b.names()) { +map.put(s, b.get(s) != null ? b.get(s) : "null"); +} +requestListener.onResponse(tag, responseBody, map); +} +}); +} +}); +} catch (Exception e) { +requestListener.onErrorResponse(tag, e.getMessage()); +} +} +} \ No newline at end of file diff --git a/app/src/main/java/com/my/newproject23/SketchwareUtil.java b/app/src/main/java/com/my/newproject23/SketchwareUtil.java new file mode 100644 index 0000000..d383211 --- /dev/null +++ b/app/src/main/java/com/my/newproject23/SketchwareUtil.java @@ -0,0 +1,209 @@ +package com.my.newproject23; +import android.content.*; +import android.view.*; +import android.widget.*; +import android.util.*; +import java.util.*; +import android.app.*; +import android.content.*; +import android.net.*; +import java.io.*; +import android.graphics.drawable.*; +import android.view.inputmethod.*; + +public class SketchwareUtil { + public static int TOP = 1; + public static int CENTER = 2; + public static int BOTTOM = 3; + + public static void CustomToast(Context context, String message, int textColor, int textSize, int bgColor, int radius, int gravity) { + Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); + View view = toast.getView(); + TextView msg = view.findViewById(android.R.id.message); + msg.setTextSize(textSize); + msg.setTextColor(textColor); + msg.setGravity(Gravity.CENTER); + GradientDrawable shape = new GradientDrawable(); + shape.setColor(bgColor); + shape.setCornerRadius(radius); + view.setBackgroundDrawable(shape); + view.setPadding(15,10,15,10); + view.setElevation(10); + switch(gravity){ + case 1: + toast.setGravity(Gravity.TOP, 0,150); + break; + case 2: + toast.setGravity(Gravity.CENTER, 0,0); + break; + case 3: + toast.setGravity(Gravity.BOTTOM, 0,150); + break; + } + toast.show(); + } + + public static void CustomToastWithIcon(Context context, String message, int textColor, int textSize, int bgColor, int radius, int gravity, int icon) { + Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); + View view = toast.getView(); + TextView msg = (TextView) view.findViewById(android.R.id.message); + msg.setTextSize(textSize); + msg.setTextColor(textColor); + msg.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0); + msg.setGravity(Gravity.CENTER); + msg.setCompoundDrawablePadding(10); + GradientDrawable shape = new GradientDrawable(); + shape.setColor(bgColor); + shape.setCornerRadius(radius); + view.setBackgroundDrawable(shape); + view.setPadding(10,10,10,10); + view.setElevation(10); + switch(gravity){ + case 1: + toast.setGravity(Gravity.TOP, 0,150); + break; + case 2: + toast.setGravity(Gravity.CENTER, 0,0); + break; + case 3: + toast.setGravity(Gravity.BOTTOM, 0,150); + break; + } + toast.show(); + } + + public static void sortListMap(final ArrayList> listMap, final String key, final boolean isNumber, final boolean ascending) { + Collections.sort(listMap, new Comparator>(){ + public int compare(HashMap _compareMap1, HashMap _compareMap2){ + if (isNumber) { + int _count1 = Integer.valueOf(_compareMap1.get(key).toString()); + int _count2 = Integer.valueOf(_compareMap2.get(key).toString()); + if (ascending) { + return _count1 < _count2 ? -1 : _count1 < _count2 ? 1 : 0; + } + else { + return _count1 > _count2 ? -1 : _count1 > _count2 ? 1 : 0; + } + } + else { + if (ascending) { + return (_compareMap1.get(key).toString()).compareTo(_compareMap2.get(key).toString()); + } + else { + return (_compareMap2.get(key).toString()).compareTo(_compareMap1.get(key).toString()); + } + } + }}); + } + + public static void CropImage(Activity a, String s, int i){ + try { + Intent cropIntent = new Intent("com.android.camera.action.CROP"); + File f = new File(s); + Uri contentUri = Uri.fromFile(f); + cropIntent.setDataAndType(contentUri, "image/*"); + cropIntent.putExtra("crop", "true"); + cropIntent.putExtra("aspectX", 1); + cropIntent.putExtra("aspectY", 1); + cropIntent.putExtra("outputX", 280); + cropIntent.putExtra("outputY", 280); + cropIntent.putExtra("return-data", false); + a.startActivityForResult(cropIntent, i); + } catch (ActivityNotFoundException anfe) { + String errorMessage = "Your device doesn't support the crop action!"; + Toast toast = Toast.makeText(a, errorMessage, Toast.LENGTH_SHORT); + toast.show(); + } + } + + public static boolean isConnected(Context a) { + ConnectivityManager connectivityManager = (android.net.ConnectivityManager) + a.getSystemService(Activity.CONNECTIVITY_SERVICE); + NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); + return activeNetworkInfo != null && activeNetworkInfo.isConnected(); + } + + public static String copyFromInputStream(InputStream inputStream) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + byte buf[] = new byte[1024]; + int i; + try { + while ((i = inputStream.read(buf)) != -1){ + outputStream.write(buf, 0, i); + } + outputStream.close(); + inputStream.close(); + } catch (IOException e) { + + } + return outputStream.toString(); + } + + public static void hideKeyboard(Context c){ + InputMethodManager imm = (InputMethodManager) + c.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); + } + + public static void showKeyboard(Context c){ + InputMethodManager imm = (InputMethodManager) + c.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + + public static void showMessage(Context _context, String _s) { + Toast.makeText(_context, _s, Toast.LENGTH_SHORT).show(); + } + + public static int getLocationX(View _view) { + int _location[] = new int[2]; + _view.getLocationInWindow(_location); + return _location[0]; + } + + public static int getLocationY(View _view) { + int _location[] = new int[2]; + _view.getLocationInWindow(_location); + return _location[1]; + } + + public static int getRandom(int _min, int _max) { + Random random = new Random(); + return random.nextInt(_max - _min + 1) + _min; + } + + public static ArrayList getCheckedItemPositionsToArray(ListView _list) { + ArrayList _result = new ArrayList(); + SparseBooleanArray _arr = _list.getCheckedItemPositions(); + for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) { + if (_arr.valueAt(_iIdx)) + _result.add((double) _arr.keyAt(_iIdx)); + } + return _result; + } + + public static float getDip(Context _context, int _input) { + return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, _context.getResources().getDisplayMetrics()); + } + + public static int getDisplayWidthPixels(Context _context) { + return _context.getResources().getDisplayMetrics().widthPixels; + } + + public static int getDisplayHeightPixels(Context _context) { + return _context.getResources().getDisplayMetrics().heightPixels; + } + + public static void getAllKeysFromMap(Map map, ArrayList output) { + if (output == null) return; + output.clear(); + + if (map == null || map.size() <= 0) return; + + Iterator itr = map.entrySet().iterator(); + while (itr.hasNext()) { + Map.Entry entry = (Map.Entry) itr.next(); + output.add(entry.getKey()); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/mychapa/pay/BluetoothConnect.java b/app/src/main/java/com/mychapa/pay/BluetoothConnect.java new file mode 100644 index 0000000..7128fde --- /dev/null +++ b/app/src/main/java/com/mychapa/pay/BluetoothConnect.java @@ -0,0 +1,111 @@ +package com.mychapa.pay; + +import android.app.Activity; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.content.Intent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Set; +import java.util.UUID; + +public class BluetoothConnect { +private static final String DEFAULT_UUID = "00001101-0000-1000-8000-00805F9B34FB"; + +private Activity activity; + +private BluetoothAdapter bluetoothAdapter; + +public BluetoothConnect(Activity activity) { +this.activity = activity; +this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); +} + +public boolean isBluetoothEnabled() { +if(bluetoothAdapter != null) return true; + +return false; +} + +public boolean isBluetoothActivated() { +if(bluetoothAdapter == null) return false; + +return bluetoothAdapter.isEnabled(); +} + +public void activateBluetooth() { +Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); +activity.startActivity(intent); +} + +public String getRandomUUID() { +return String.valueOf(UUID.randomUUID()); +} + +public void getPairedDevices(ArrayList> results) { +Set pairedDevices = bluetoothAdapter.getBondedDevices(); + +if(pairedDevices.size() > 0) { +for(BluetoothDevice device : pairedDevices) { +HashMap result = new HashMap<>(); +result.put("name", device.getName()); +result.put("address", device.getAddress()); + +results.add(result); +} +} +} + +public void readyConnection(BluetoothConnectionListener listener, String tag) { +if(BluetoothController.getInstance().getState().equals(BluetoothController.STATE_NONE)) { +BluetoothController.getInstance().start(this, listener, tag, UUID.fromString(DEFAULT_UUID), bluetoothAdapter); +} +} + +public void readyConnection(BluetoothConnectionListener listener, String uuid, String tag) { +if(BluetoothController.getInstance().getState().equals(BluetoothController.STATE_NONE)) { +BluetoothController.getInstance().start(this, listener, tag, UUID.fromString(uuid), bluetoothAdapter); +} +} + + +public void startConnection(BluetoothConnectionListener listener, String address, String tag) { +BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address); + +BluetoothController.getInstance().connect(device, this, listener, tag, UUID.fromString(DEFAULT_UUID), bluetoothAdapter); +} + +public void startConnection(BluetoothConnectionListener listener, String uuid, String address, String tag) { +BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address); + +BluetoothController.getInstance().connect(device, this, listener, tag, UUID.fromString(uuid), bluetoothAdapter); +} + +public void stopConnection(BluetoothConnectionListener listener, String tag) { +BluetoothController.getInstance().stop(this, listener, tag); +} + +public void sendData(BluetoothConnectionListener listener, String data, String tag) { +String state = BluetoothController.getInstance().getState(); + +if(!state.equals(BluetoothController.STATE_CONNECTED)) { +listener.onConnectionError(tag, state, "Bluetooth is not connected yet"); +return; +} + +BluetoothController.getInstance().write(data.getBytes()); +} + +public Activity getActivity() { +return activity; +} + +public interface BluetoothConnectionListener { +void onConnected(String tag, HashMap deviceData); +void onDataReceived(String tag, byte[] data, int bytes); +void onDataSent(String tag, byte[] data); +void onConnectionError(String tag, String connectionState, String message); +void onConnectionStopped(String tag); +} +} \ No newline at end of file diff --git a/app/src/main/java/com/mychapa/pay/BluetoothController.java b/app/src/main/java/com/mychapa/pay/BluetoothController.java new file mode 100644 index 0000000..8b2a7d2 --- /dev/null +++ b/app/src/main/java/com/mychapa/pay/BluetoothController.java @@ -0,0 +1,354 @@ +package com.mychapa.pay; + +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.bluetooth.BluetoothServerSocket; +import android.bluetooth.BluetoothSocket; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.HashMap; +import java.util.UUID; + +public class BluetoothController { +public static final String STATE_NONE = "none"; +public static final String STATE_LISTEN = "listen"; +public static final String STATE_CONNECTING = "connecting"; +public static final String STATE_CONNECTED = "connected"; + +private AcceptThread acceptThread; +private ConnectThread connectThread; +private ConnectedThread connectedThread; + +private String state = STATE_NONE; + +private static BluetoothController instance; + +public static synchronized BluetoothController getInstance() { +if(instance == null) { +instance = new BluetoothController(); +} + +return instance; +} + +public synchronized void start(BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) { +if (connectThread != null) { +connectThread.cancel(); +connectThread = null; +} + +if (connectedThread != null) { +connectedThread.cancel(); +connectedThread = null; +} + +if (acceptThread != null) { +acceptThread.cancel(); +acceptThread = null; +} + +acceptThread = new AcceptThread(bluetoothConnect, listener, tag, uuid, bluetoothAdapter); +acceptThread.start();} + +public synchronized void connect(BluetoothDevice device, BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) { +if (state.equals(STATE_CONNECTING)) { +if (connectThread != null) { +connectThread.cancel(); +connectThread = null; +} +} + +if (connectedThread != null) { +connectedThread.cancel(); +connectedThread = null; +} + +connectThread = new ConnectThread(device, bluetoothConnect, listener, tag, uuid, bluetoothAdapter); +connectThread.start(); +} + +public synchronized void connected(BluetoothSocket socket, final BluetoothDevice device, BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag) { +if (connectThread != null) { +connectThread.cancel(); +connectThread = null; +} + +if (connectedThread != null) { +connectedThread.cancel(); +connectedThread = null; +} + +if (acceptThread != null) { +acceptThread.cancel(); +acceptThread = null; +} + +connectedThread = new ConnectedThread(socket, bluetoothConnect, listener, tag); +connectedThread.start(); + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +HashMap deviceMap = new HashMap<>(); +deviceMap.put("name", device.getName()); +deviceMap.put("address", device.getAddress()); + +listener.onConnected(tag, deviceMap); +} +}); +} + +public synchronized void stop(BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag) { +if (connectThread != null) { +connectThread.cancel(); +connectThread = null; +} + +if (connectedThread != null) { +connectedThread.cancel(); +connectedThread = null; +} + +if (acceptThread != null) { +acceptThread.cancel(); +acceptThread = null; +} + +state = STATE_NONE; + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +listener.onConnectionStopped(tag); +} +}); +} + +public void write(byte[] out) { +ConnectedThread r; + +synchronized (this) { +if (!state.equals(STATE_CONNECTED)) return; +r = connectedThread; +} + +r.write(out); +} + +public void connectionFailed(BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag, final String message) { +state = STATE_NONE; + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +listener.onConnectionError(tag, state, message); +} +}); +} + +public void connectionLost(BluetoothConnect bluetoothConnect, final BluetoothConnect.BluetoothConnectionListener listener, final String tag) { +state = STATE_NONE; + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +listener.onConnectionError(tag, state, "Bluetooth connection is disconnected"); +} +}); +} + +public String getState() { +return state; +} + +private class AcceptThread extends Thread { +private BluetoothServerSocket serverSocket; + +private BluetoothConnect bluetoothConnect; +private BluetoothConnect.BluetoothConnectionListener listener; +private String tag; + +public AcceptThread(BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) { +this.bluetoothConnect = bluetoothConnect; +this.listener = listener; +this.tag = tag; + +try { +serverSocket = bluetoothAdapter.listenUsingRfcommWithServiceRecord(tag, uuid); +} catch (Exception e) { +e.printStackTrace(); +} + +state = STATE_LISTEN; +} + +@Override +public void run() { +BluetoothSocket bluetoothSocket; + +while (!state.equals(STATE_CONNECTED)) { +try { +bluetoothSocket = serverSocket.accept(); +} catch (Exception e) { +e.printStackTrace(); +break; +} + +if (bluetoothSocket != null) { +synchronized (BluetoothController.this) { +switch (state) { +case STATE_LISTEN: +case STATE_CONNECTING: +connected(bluetoothSocket, bluetoothSocket.getRemoteDevice(), bluetoothConnect, listener, tag); +break; +case STATE_NONE: +case STATE_CONNECTED: +try { +bluetoothSocket.close(); +} catch (Exception e) { +e.printStackTrace(); +} +break; +} +} +} +} +} + +public void cancel() { +try { +serverSocket.close(); +} catch (Exception e) { +e.printStackTrace(); +} +} +} + +private class ConnectThread extends Thread { +private BluetoothDevice device; +private BluetoothSocket socket; + +private BluetoothConnect bluetoothConnect; +private BluetoothConnect.BluetoothConnectionListener listener; +private String tag; +private BluetoothAdapter bluetoothAdapter; + +public ConnectThread(BluetoothDevice device, BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag, UUID uuid, BluetoothAdapter bluetoothAdapter) { +this.device = device; +this.bluetoothConnect = bluetoothConnect; +this.listener = listener; +this.tag = tag; +this.bluetoothAdapter = bluetoothAdapter; + +try { +socket = device.createRfcommSocketToServiceRecord(uuid); +} catch (Exception e) { +e.printStackTrace(); +} + +state = STATE_CONNECTING; +} + +@Override +public void run() { +bluetoothAdapter.cancelDiscovery(); + +try { +socket.connect(); +} catch (Exception e) { +try { +socket.close(); +} catch (Exception e2) { +e2.printStackTrace(); +} +connectionFailed(bluetoothConnect, listener, tag, e.getMessage()); +return; +} + +synchronized (BluetoothController.this) { +connectThread = null; +} + +connected(socket, device, bluetoothConnect, listener, tag); +} + +public void cancel() { +try { +socket.close(); +} catch (Exception e) { +e.printStackTrace(); +} +} +} + +private class ConnectedThread extends Thread { +private BluetoothSocket socket; +private InputStream inputStream; +private OutputStream outputStream; + +private BluetoothConnect bluetoothConnect; +private BluetoothConnect.BluetoothConnectionListener listener; +private String tag; + +public ConnectedThread(BluetoothSocket socket, BluetoothConnect bluetoothConnect, BluetoothConnect.BluetoothConnectionListener listener, String tag) { +this.bluetoothConnect = bluetoothConnect; +this.listener = listener; +this.tag = tag; + +this.socket = socket; + +try { +inputStream = socket.getInputStream(); +outputStream = socket.getOutputStream(); +} catch (Exception e) { +e.printStackTrace(); +} + +state = STATE_CONNECTED; +} + +public void run() { +while (state.equals(STATE_CONNECTED)) { +try { +final byte[] buffer = new byte[1024]; +final int bytes = inputStream.read(buffer); + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +listener.onDataReceived(tag, buffer, bytes); +} +}); +} catch (Exception e) { +e.printStackTrace(); +connectionLost(bluetoothConnect, listener, tag); +break; +} +} +} + +public void write(final byte[] buffer) { +try { +outputStream.write(buffer); + +bluetoothConnect.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +listener.onDataSent(tag, buffer); +} +}); +} catch (Exception e) { +e.printStackTrace(); +} +} + +public void cancel() { +try { +socket.close(); +} catch (Exception e) { +e.printStackTrace(); +} +} +} +} \ No newline at end of file diff --git a/app/src/main/java/com/mychapa/pay/FileUtil.java b/app/src/main/java/com/mychapa/pay/FileUtil.java new file mode 100644 index 0000000..5cd832e --- /dev/null +++ b/app/src/main/java/com/mychapa/pay/FileUtil.java @@ -0,0 +1,604 @@ +package com.mychapa.pay; + +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.Context; +import android.database.Cursor; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.ColorMatrix; +import android.graphics.ColorMatrixColorFilter; +import android.graphics.LightingColorFilter; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; +import android.graphics.Rect; +import android.graphics.RectF; +import android.media.ExifInterface; +import android.net.Uri; +import android.os.Environment; +import android.provider.DocumentsContract; +import android.provider.MediaStore; +import android.text.TextUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.net.URLDecoder; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + +public class FileUtil { + +private static void createNewFile(String path) { +int lastSep = path.lastIndexOf(File.separator); +if (lastSep > 0) { +String dirPath = path.substring(0, lastSep); +makeDir(dirPath); +} + +File file = new File(path); + +try { +if (!file.exists()) +file.createNewFile(); +} catch (IOException e) { +e.printStackTrace(); +} +} + +public static String readFile(String path) { +createNewFile(path); + +StringBuilder sb = new StringBuilder(); +FileReader fr = null; +try { +fr = new FileReader(new File(path)); + +char[] buff = new char[1024]; +int length = 0; + +while ((length = fr.read(buff)) > 0) { +sb.append(new String(buff, 0, length)); +} +} catch (IOException e) { +e.printStackTrace(); +} finally { +if (fr != null) { +try { +fr.close(); +} catch (Exception e) { +e.printStackTrace(); +} +} +} + +return sb.toString(); +} + +public static void writeFile(String path, String str) { +createNewFile(path); +FileWriter fileWriter = null; + +try { +fileWriter = new FileWriter(new File(path), false); +fileWriter.write(str); +fileWriter.flush(); +} catch (IOException e) { +e.printStackTrace(); +} finally { +try { +if (fileWriter != null) +fileWriter.close(); +} catch (IOException e) { +e.printStackTrace(); +} +} +} + +public static void copyFile(String sourcePath, String destPath) { +if (!isExistFile(sourcePath)) return; +createNewFile(destPath); + +FileInputStream fis = null; +FileOutputStream fos = null; + +try { +fis = new FileInputStream(sourcePath); +fos = new FileOutputStream(destPath, false); + +byte[] buff = new byte[1024]; +int length = 0; + +while ((length = fis.read(buff)) > 0) { +fos.write(buff, 0, length); +} +} catch (IOException e) { +e.printStackTrace(); +} finally { +if (fis != null) { +try { +fis.close(); +} catch (IOException e) { +e.printStackTrace(); +} +} +if (fos != null) { +try { +fos.close(); +} catch (IOException e) { +e.printStackTrace(); +} +} +} +} + +public static void moveFile(String sourcePath, String destPath) { +copyFile(sourcePath, destPath); +deleteFile(sourcePath); +} + +public static void deleteFile(String path) { +File file = new File(path); + +if (!file.exists()) return; + +if (file.isFile()) { +file.delete(); +return; +} + +File[] fileArr = file.listFiles(); + +if (fileArr != null) { +for (File subFile : fileArr) { +if (subFile.isDirectory()) { +deleteFile(subFile.getAbsolutePath()); +} + +if (subFile.isFile()) { +subFile.delete(); +} +} +} + +file.delete(); +} + +public static boolean isExistFile(String path) { +File file = new File(path); +return file.exists(); +} + +public static void makeDir(String path) { +if (!isExistFile(path)) { +File file = new File(path); +file.mkdirs(); +} +} + +public static void listDir(String path, ArrayList list) { +File dir = new File(path); +if (!dir.exists() || dir.isFile()) return; + +File[] listFiles = dir.listFiles(); +if (listFiles == null || listFiles.length <= 0) return; + +if (list == null) return; +list.clear(); +for (File file : listFiles) { +list.add(file.getAbsolutePath()); +} +} + +public static boolean isDirectory(String path) { +if (!isExistFile(path)) return false; +return new File(path).isDirectory(); +} + +public static boolean isFile(String path) { +if (!isExistFile(path)) return false; +return new File(path).isFile(); +} + +public static long getFileLength(String path) { +if (!isExistFile(path)) return 0; +return new File(path).length(); +} + +public static String getExternalStorageDir() { +return Environment.getExternalStorageDirectory().getAbsolutePath(); +} + +public static String getPackageDataDir(Context context) { +return context.getExternalFilesDir(null).getAbsolutePath(); +} + +public static String getPublicDir(String type) { +return Environment.getExternalStoragePublicDirectory(type).getAbsolutePath(); +} + +public static String convertUriToFilePath(final Context context, final Uri uri) { +String path = null; +if (DocumentsContract.isDocumentUri(context, uri)) { +if (isExternalStorageDocument(uri)) { +final String docId = DocumentsContract.getDocumentId(uri); +final String[] split = docId.split(":"); +final String type = split[0]; + +if ("primary".equalsIgnoreCase(type)) { +path = Environment.getExternalStorageDirectory() + "/" + split[1]; +} +} else if (isDownloadsDocument(uri)) { +final String id = DocumentsContract.getDocumentId(uri); + +if (!TextUtils.isEmpty(id)) { +if (id.startsWith("raw:")) { +return id.replaceFirst("raw:", ""); +} +} + +final Uri contentUri = ContentUris +.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); + +path = getDataColumn(context, contentUri, null, null); +} else if (isMediaDocument(uri)) { +final String docId = DocumentsContract.getDocumentId(uri); +final String[] split = docId.split(":"); +final String type = split[0]; + +Uri contentUri = null; +if ("image".equals(type)) { +contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; +} else if ("video".equals(type)) { +contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; +} else if ("audio".equals(type)) { +contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; +} + +final String selection = MediaStore.Audio.Media._ID + "=?"; +final String[] selectionArgs = new String[]{ +split[1] +}; + +path = getDataColumn(context, contentUri, selection, selectionArgs); +} +} else if (ContentResolver.SCHEME_CONTENT.equalsIgnoreCase(uri.getScheme())) { +path = getDataColumn(context, uri, null, null); +} else if (ContentResolver.SCHEME_FILE.equalsIgnoreCase(uri.getScheme())) { +path = uri.getPath(); +} + +if (path != null) { +try { +return URLDecoder.decode(path, "UTF-8"); +}catch(Exception e){ +return null; +} +} +return null; +} + +private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { +Cursor cursor = null; + +final String column = MediaStore.Images.Media.DATA; +final String[] projection = { +column +}; + +try { +cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); +if (cursor != null && cursor.moveToFirst()) { +final int column_index = cursor.getColumnIndexOrThrow(column); +return cursor.getString(column_index); +} +} catch (Exception e) { + +} finally { +if (cursor != null) { +cursor.close(); +} +} +return null; +} + + +private static boolean isExternalStorageDocument(Uri uri) { +return "com.android.externalstorage.documents".equals(uri.getAuthority()); +} + +private static boolean isDownloadsDocument(Uri uri) { +return "com.android.providers.downloads.documents".equals(uri.getAuthority()); +} + +private static boolean isMediaDocument(Uri uri) { +return "com.android.providers.media.documents".equals(uri.getAuthority()); +} + +private static void saveBitmap(Bitmap bitmap, String destPath) { +FileOutputStream out = null; +FileUtil.createNewFile(destPath); +try { +out = new FileOutputStream(new File(destPath)); +bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); +} catch (Exception e) { +e.printStackTrace(); +} finally { +try { +if (out != null) { +out.close(); +} +} catch (IOException e) { +e.printStackTrace(); +} +} +} + +public static Bitmap getScaledBitmap(String path, int max) { +Bitmap src = BitmapFactory.decodeFile(path); + +int width = src.getWidth(); +int height = src.getHeight(); +float rate = 0.0f; + +if (width > height) { +rate = max / (float) width; +height = (int) (height * rate); +width = max; +} else { +rate = max / (float) height; +width = (int) (width * rate); +height = max; +} + +return Bitmap.createScaledBitmap(src, width, height, true); +} + +public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { +final int width = options.outWidth; +final int height = options.outHeight; +int inSampleSize = 1; + +if (height > reqHeight || width > reqWidth) { +final int halfHeight = height / 2; +final int halfWidth = width / 2; + +while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) { +inSampleSize *= 2; +} +} + +return inSampleSize; +} + +public static Bitmap decodeSampleBitmapFromPath(String path, int reqWidth, int reqHeight) { +final BitmapFactory.Options options = new BitmapFactory.Options(); +options.inJustDecodeBounds = true; +BitmapFactory.decodeFile(path, options); + +options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); + +options.inJustDecodeBounds = false; +return BitmapFactory.decodeFile(path, options); +} + +public static void resizeBitmapFileRetainRatio(String fromPath, String destPath, int max) { +if (!isExistFile(fromPath)) return; +Bitmap bitmap = getScaledBitmap(fromPath, max); +saveBitmap(bitmap, destPath); +} + +public static void resizeBitmapFileToSquare(String fromPath, String destPath, int max) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Bitmap bitmap = Bitmap.createScaledBitmap(src, max, max, true); +saveBitmap(bitmap, destPath); +} + +public static void resizeBitmapFileToCircle(String fromPath, String destPath) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), +src.getHeight(), Bitmap.Config.ARGB_8888); +Canvas canvas = new Canvas(bitmap); + +final int color = 0xff424242; +final Paint paint = new Paint(); +final Rect rect = new Rect(0, 0, src.getWidth(), src.getHeight()); + +paint.setAntiAlias(true); +canvas.drawARGB(0, 0, 0, 0); +paint.setColor(color); +canvas.drawCircle(src.getWidth() / 2, src.getHeight() / 2, +src.getWidth() / 2, paint); +paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); +canvas.drawBitmap(src, rect, rect, paint); + +saveBitmap(bitmap, destPath); +} + +public static void resizeBitmapFileWithRoundedBorder(String fromPath, String destPath, int pixels) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src +.getHeight(), Bitmap.Config.ARGB_8888); +Canvas canvas = new Canvas(bitmap); + +final int color = 0xff424242; +final Paint paint = new Paint(); +final Rect rect = new Rect(0, 0, src.getWidth(), src.getHeight()); +final RectF rectF = new RectF(rect); +final float roundPx = pixels; + +paint.setAntiAlias(true); +canvas.drawARGB(0, 0, 0, 0); +paint.setColor(color); +canvas.drawRoundRect(rectF, roundPx, roundPx, paint); + +paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); +canvas.drawBitmap(src, rect, rect, paint); + +saveBitmap(bitmap, destPath); +} + +public static void cropBitmapFileFromCenter(String fromPath, String destPath, int w, int h) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); + +int width = src.getWidth(); +int height = src.getHeight(); + +if (width < w && height < h) +return; + +int x = 0; +int y = 0; + +if (width > w) +x = (width - w) / 2; + +if (height > h) +y = (height - h) / 2; + +int cw = w; +int ch = h; + +if (w > width) +cw = width; + +if (h > height) +ch = height; + +Bitmap bitmap = Bitmap.createBitmap(src, x, y, cw, ch); +saveBitmap(bitmap, destPath); +} + +public static void rotateBitmapFile(String fromPath, String destPath, float angle) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Matrix matrix = new Matrix(); +matrix.postRotate(angle); +Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); +saveBitmap(bitmap, destPath); +} + +public static void scaleBitmapFile(String fromPath, String destPath, float x, float y) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Matrix matrix = new Matrix(); +matrix.postScale(x, y); + +int w = src.getWidth(); +int h = src.getHeight(); + +Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, w, h, matrix, true); +saveBitmap(bitmap, destPath); +} + +public static void skewBitmapFile(String fromPath, String destPath, float x, float y) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Matrix matrix = new Matrix(); +matrix.postSkew(x, y); + +int w = src.getWidth(); +int h = src.getHeight(); + +Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, w, h, matrix, true); +saveBitmap(bitmap, destPath); +} + +public static void setBitmapFileColorFilter(String fromPath, String destPath, int color) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, +src.getWidth() - 1, src.getHeight() - 1); +Paint p = new Paint(); +ColorFilter filter = new LightingColorFilter(color, 1); +p.setColorFilter(filter); +Canvas canvas = new Canvas(bitmap); +canvas.drawBitmap(bitmap, 0, 0, p); +saveBitmap(bitmap, destPath); +} + +public static void setBitmapFileBrightness(String fromPath, String destPath, float brightness) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +ColorMatrix cm = new ColorMatrix(new float[] +{ +1, 0, 0, 0, brightness, +0, 1, 0, 0, brightness, +0, 0, 1, 0, brightness, +0, 0, 0, 1, 0 +}); + +Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); +Canvas canvas = new Canvas(bitmap); +Paint paint = new Paint(); +paint.setColorFilter(new ColorMatrixColorFilter(cm)); +canvas.drawBitmap(src, 0, 0, paint); +saveBitmap(bitmap, destPath); +} + +public static void setBitmapFileContrast(String fromPath, String destPath, float contrast) { +if (!isExistFile(fromPath)) return; +Bitmap src = BitmapFactory.decodeFile(fromPath); +ColorMatrix cm = new ColorMatrix(new float[] +{ +contrast, 0, 0, 0, 0, +0, contrast, 0, 0, 0, +0, 0, contrast, 0, 0, +0, 0, 0, 1, 0 +}); + +Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); +Canvas canvas = new Canvas(bitmap); +Paint paint = new Paint(); +paint.setColorFilter(new ColorMatrixColorFilter(cm)); +canvas.drawBitmap(src, 0, 0, paint); + +saveBitmap(bitmap, destPath); +} + +public static int getJpegRotate(String filePath) { +int rotate = 0; +try { +ExifInterface exif = new ExifInterface(filePath); +int iOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); + +switch (iOrientation) { +case ExifInterface.ORIENTATION_ROTATE_90: +rotate = 90; +break; +case ExifInterface.ORIENTATION_ROTATE_180: +rotate = 180; +break; +case ExifInterface.ORIENTATION_ROTATE_270: +rotate = 270; +break; +default: +rotate = 0; +break; +} +} +catch (IOException e) { +return 0; +} + +return rotate; +} +public static File createNewPictureFile(Context context) { +SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss"); +String fileName = date.format(new Date()) + ".jpg"; +File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_DCIM).getAbsolutePath() + File.separator + fileName); +return file; +} +} \ No newline at end of file diff --git a/app/src/main/java/com/mychapa/pay/MainActivity.java b/app/src/main/java/com/mychapa/pay/MainActivity.java new file mode 100644 index 0000000..ef0cf92 --- /dev/null +++ b/app/src/main/java/com/mychapa/pay/MainActivity.java @@ -0,0 +1,250 @@ +package com.mychapa.pay; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.annotation.*; +import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import com.google.android.material.appbar.AppBarLayout; +import android.app.*; +import android.os.*; +import android.view.*; +import android.view.View.*; +import android.widget.*; +import android.content.*; +import android.content.res.*; +import android.graphics.*; +import android.graphics.drawable.*; +import android.media.*; +import android.net.*; +import android.text.*; +import android.text.style.*; +import android.util.*; +import android.webkit.*; +import android.animation.*; +import android.view.animation.*; +import java.util.*; +import java.util.regex.*; +import java.text.*; +import org.json.*; +import java.util.HashMap; +import android.widget.LinearLayout; +import android.widget.Button; +import android.widget.EditText; +import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.ValueEventListener; +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.DatabaseError; +import com.google.firebase.database.GenericTypeIndicator; +import com.google.firebase.database.ChildEventListener; +import android.view.View; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.DialogFragment; + + +public class MainActivity extends AppCompatActivity { + + private FirebaseDatabase _firebase = FirebaseDatabase.getInstance(); + + private Toolbar _toolbar; + private AppBarLayout _app_bar; + private CoordinatorLayout _coordinator; + private HashMap header = new HashMap<>(); + private HashMap chapa = new HashMap<>(); + private HashMap response = new HashMap<>(); + private String handler = ""; + private HashMap msl = new HashMap<>(); + + private LinearLayout linear1; + private Button button1; + private LinearLayout linear2; + private EditText edittext1; + + private RequestNetwork cnet; + private RequestNetwork.RequestListener _cnet_request_listener; + private DatabaseReference hh = _firebase.getReference("hh"); + private ChildEventListener _hh_child_listener; + @Override + protected void onCreate(Bundle _savedInstanceState) { + super.onCreate(_savedInstanceState); + setContentView(R.layout.main); + initialize(_savedInstanceState); + com.google.firebase.FirebaseApp.initializeApp(this); + initializeLogic(); + } + + private void initialize(Bundle _savedInstanceState) { + + _app_bar = (AppBarLayout) findViewById(R.id._app_bar); + _coordinator = (CoordinatorLayout) findViewById(R.id._coordinator); + _toolbar = (Toolbar) findViewById(R.id._toolbar); + setSupportActionBar(_toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + _toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View _v) { + onBackPressed(); + } + }); + linear1 = (LinearLayout) findViewById(R.id.linear1); + button1 = (Button) findViewById(R.id.button1); + linear2 = (LinearLayout) findViewById(R.id.linear2); + edittext1 = (EditText) findViewById(R.id.edittext1); + cnet = new RequestNetwork(this); + + button1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View _view) { + header = new HashMap<>(); + header.put("Authorization", "Bearer CHASECK_TEST-GOu5EEWv11fsJexRDhpq6HTpEQYCCPb3"); + cnet.setHeaders(header); + chapa = new HashMap<>(); + chapa.put("amount", "100"); + chapa.put("currency", "ETB"); + chapa.put("email", "baya@gmail.com"); + chapa.put("first_name", "lij"); + chapa.put("last_name", "baya"); + chapa.put("phone_number", "0900000000"); + chapa.put("tx_ref", hh.push().getKey()); + chapa.put("callback_url", "https://webhook.site/077164d6-29cb-40df-ba29-8a00e59a7e60"); + chapa.put("return_url", "https://www.google.com/"); + chapa.put("customization[title]", "ambesa baus ticket"); + chapa.put("customization[description]", "for travel"); + cnet.setParams(chapa, RequestNetworkController.REQUEST_BODY); + cnet.startRequestNetwork(RequestNetworkController.POST, "https://api.chapa.co/v1/transaction/mobile-initialize", "", _cnet_request_listener); + } + }); + + _cnet_request_listener = new RequestNetwork.RequestListener() { + @Override + public void onResponse(String _param1, String _param2, HashMap _param3) { + final String _tag = _param1; + final String _response = _param2; + final HashMap _responseHeaders = _param3; + response = new Gson().fromJson(_response, new TypeToken>(){}.getType()); + handler = (new Gson()).toJson(response.get("data"), new TypeToken>(){}.getType()); + + msl = new Gson().fromJson(handler, new TypeToken>(){}.getType()); + edittext1.setText(msl.get("checkout_url").toString()); + } + + @Override + public void onErrorResponse(String _param1, String _param2) { + final String _tag = _param1; + final String _message = _param2; + + } + }; + + _hh_child_listener = new ChildEventListener() { + @Override + public void onChildAdded(DataSnapshot _param1, String _param2) { + GenericTypeIndicator> _ind = new GenericTypeIndicator>() {}; + final String _childKey = _param1.getKey(); + final HashMap _childValue = _param1.getValue(_ind); + + } + + @Override + public void onChildChanged(DataSnapshot _param1, String _param2) { + GenericTypeIndicator> _ind = new GenericTypeIndicator>() {}; + final String _childKey = _param1.getKey(); + final HashMap _childValue = _param1.getValue(_ind); + + } + + @Override + public void onChildMoved(DataSnapshot _param1, String _param2) { + + } + + @Override + public void onChildRemoved(DataSnapshot _param1) { + GenericTypeIndicator> _ind = new GenericTypeIndicator>() {}; + final String _childKey = _param1.getKey(); + final HashMap _childValue = _param1.getValue(_ind); + + } + + @Override + public void onCancelled(DatabaseError _param1) { + final int _errorCode = _param1.getCode(); + final String _errorMessage = _param1.getMessage(); + + } + }; + hh.addChildEventListener(_hh_child_listener); + } + + private void initializeLogic() { + //android 12 + } + + @Override + protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) { + + super.onActivityResult(_requestCode, _resultCode, _data); + + switch (_requestCode) { + + default: + break; + } + } + + @Deprecated + public void showMessage(String _s) { + Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show(); + } + + @Deprecated + public int getLocationX(View _v) { + int _location[] = new int[2]; + _v.getLocationInWindow(_location); + return _location[0]; + } + + @Deprecated + public int getLocationY(View _v) { + int _location[] = new int[2]; + _v.getLocationInWindow(_location); + return _location[1]; + } + + @Deprecated + public int getRandom(int _min, int _max) { + Random random = new Random(); + return random.nextInt(_max - _min + 1) + _min; + } + + @Deprecated + public ArrayList getCheckedItemPositionsToArray(ListView _list) { + ArrayList _result = new ArrayList(); + SparseBooleanArray _arr = _list.getCheckedItemPositions(); + for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) { + if (_arr.valueAt(_iIdx)) + _result.add((double)_arr.keyAt(_iIdx)); + } + return _result; + } + + @Deprecated + public float getDip(int _input){ + return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics()); + } + + @Deprecated + public int getDisplayWidthPixels(){ + return getResources().getDisplayMetrics().widthPixels; + } + + @Deprecated + public int getDisplayHeightPixels(){ + return getResources().getDisplayMetrics().heightPixels; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/mychapa/pay/RequestNetwork.java b/app/src/main/java/com/mychapa/pay/RequestNetwork.java new file mode 100644 index 0000000..b360219 --- /dev/null +++ b/app/src/main/java/com/mychapa/pay/RequestNetwork.java @@ -0,0 +1,52 @@ +package com.mychapa.pay; + +import android.app.Activity; + +import java.util.HashMap; + +public class RequestNetwork { +private HashMap params = new HashMap<>(); +private HashMap headers = new HashMap<>(); + +private Activity activity; + +private int requestType = 0; + +public RequestNetwork(Activity activity) { +this.activity = activity; +} + +public void setHeaders(HashMap headers) { +this.headers = headers; +} + +public void setParams(HashMap params, int requestType) { +this.params = params; +this.requestType = requestType; +} + +public HashMap getParams() { +return params; +} + +public HashMap getHeaders() { +return headers; +} + +public Activity getActivity() { +return activity; +} + +public int getRequestType() { +return requestType; +} + +public void startRequestNetwork(String method, String url, String tag, RequestListener requestListener) { +RequestNetworkController.getInstance().execute(this, method, url, tag, requestListener); +} + +public interface RequestListener { +public void onResponse(String tag, String response, HashMap responseHeaders); +public void onErrorResponse(String tag, String message); +} +} diff --git a/app/src/main/java/com/mychapa/pay/RequestNetworkController.java b/app/src/main/java/com/mychapa/pay/RequestNetworkController.java new file mode 100644 index 0000000..59bb663 --- /dev/null +++ b/app/src/main/java/com/mychapa/pay/RequestNetworkController.java @@ -0,0 +1,185 @@ +package com.mychapa.pay; + +import com.google.gson.Gson; + +import java.io.IOException; +import java.security.cert.CertificateException; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.FormBody; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class RequestNetworkController { +public static final String GET = "GET"; +public static final String POST = "POST"; +public static final String PUT = "PUT"; +public static final String DELETE = "DELETE"; + +public static final int REQUEST_PARAM = 0; +public static final int REQUEST_BODY = 1; + +private static final int SOCKET_TIMEOUT = 15000; +private static final int READ_TIMEOUT = 25000; + +protected OkHttpClient client; + +private static RequestNetworkController mInstance; + +public static synchronized RequestNetworkController getInstance() { +if(mInstance == null) { +mInstance = new RequestNetworkController(); +} +return mInstance; +} + +private OkHttpClient getClient() { +if (client == null) { +OkHttpClient.Builder builder = new OkHttpClient.Builder(); + +try { +final TrustManager[] trustAllCerts = new TrustManager[]{ +new X509TrustManager() { +@Override +public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) +throws CertificateException { +} + +@Override +public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) +throws CertificateException { +} + +@Override +public java.security.cert.X509Certificate[] getAcceptedIssuers() { +return new java.security.cert.X509Certificate[]{}; +} +} +}; + +final SSLContext sslContext = SSLContext.getInstance("TLS"); +sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); +final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); +builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]); +builder.connectTimeout(SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); +builder.readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS); +builder.writeTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS); +builder.hostnameVerifier(new HostnameVerifier() { +@Override +public boolean verify(String hostname, SSLSession session) { +return true; +} +}); +} catch (Exception e) { +} + +client = builder.build(); +} + +return client; +} + +public void execute(final RequestNetwork requestNetwork, String method, String url, final String tag, final RequestNetwork.RequestListener requestListener) { +Request.Builder reqBuilder = new Request.Builder(); +Headers.Builder headerBuilder = new Headers.Builder(); + +if(requestNetwork.getHeaders().size() > 0) { +HashMap headers = requestNetwork.getHeaders(); + +for(HashMap.Entry header : headers.entrySet()) { +headerBuilder.add(header.getKey(), String.valueOf(header.getValue())); +} +} + +try { +if (requestNetwork.getRequestType() == REQUEST_PARAM) { +if (method.equals(GET)) { +HttpUrl.Builder httpBuilder; + +try { +httpBuilder = HttpUrl.parse(url).newBuilder(); +} catch (NullPointerException ne) { +throw new NullPointerException("unexpected url: " + url); +} + +if (requestNetwork.getParams().size() > 0) { +HashMap params = requestNetwork.getParams(); + +for (HashMap.Entry param : params.entrySet()) { +httpBuilder.addQueryParameter(param.getKey(), String.valueOf(param.getValue())); +} +} + +reqBuilder.url(httpBuilder.build()).headers(headerBuilder.build()).get(); +} else { +FormBody.Builder formBuilder = new FormBody.Builder(); +if (requestNetwork.getParams().size() > 0) { +HashMap params = requestNetwork.getParams(); + +for (HashMap.Entry param : params.entrySet()) { +formBuilder.add(param.getKey(), String.valueOf(param.getValue())); +} +} + +RequestBody reqBody = formBuilder.build(); + +reqBuilder.url(url).headers(headerBuilder.build()).method(method, reqBody); +} +} else { +RequestBody reqBody = RequestBody.create(okhttp3.MediaType.parse("application/json"), new Gson().toJson(requestNetwork.getParams())); + +if (method.equals(GET)) { +reqBuilder.url(url).headers(headerBuilder.build()).get(); +} else { +reqBuilder.url(url).headers(headerBuilder.build()).method(method, reqBody); +} +} + +Request req = reqBuilder.build(); + +getClient().newCall(req).enqueue(new Callback() { +@Override +public void onFailure(Call call, final IOException e) { +requestNetwork.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +requestListener.onErrorResponse(tag, e.getMessage()); +} +}); +} + +@Override +public void onResponse(Call call, final Response response) throws IOException { +final String responseBody = response.body().string().trim(); +requestNetwork.getActivity().runOnUiThread(new Runnable() { +@Override +public void run() { +Headers b = response.headers(); +HashMap map = new HashMap<>(); +for(String s : b.names()) { +map.put(s, b.get(s) != null ? b.get(s) : "null"); +} +requestListener.onResponse(tag, responseBody, map); +} +}); +} +}); +} catch (Exception e) { +requestListener.onErrorResponse(tag, e.getMessage()); +} +} +} \ No newline at end of file diff --git a/app/src/main/java/com/mychapa/pay/SketchwareUtil.java b/app/src/main/java/com/mychapa/pay/SketchwareUtil.java new file mode 100644 index 0000000..fadce80 --- /dev/null +++ b/app/src/main/java/com/mychapa/pay/SketchwareUtil.java @@ -0,0 +1,209 @@ +package com.mychapa.pay; +import android.content.*; +import android.view.*; +import android.widget.*; +import android.util.*; +import java.util.*; +import android.app.*; +import android.content.*; +import android.net.*; +import java.io.*; +import android.graphics.drawable.*; +import android.view.inputmethod.*; + +public class SketchwareUtil { + public static int TOP = 1; + public static int CENTER = 2; + public static int BOTTOM = 3; + + public static void CustomToast(Context context, String message, int textColor, int textSize, int bgColor, int radius, int gravity) { + Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); + View view = toast.getView(); + TextView msg = view.findViewById(android.R.id.message); + msg.setTextSize(textSize); + msg.setTextColor(textColor); + msg.setGravity(Gravity.CENTER); + GradientDrawable shape = new GradientDrawable(); + shape.setColor(bgColor); + shape.setCornerRadius(radius); + view.setBackgroundDrawable(shape); + view.setPadding(15,10,15,10); + view.setElevation(10); + switch(gravity){ + case 1: + toast.setGravity(Gravity.TOP, 0,150); + break; + case 2: + toast.setGravity(Gravity.CENTER, 0,0); + break; + case 3: + toast.setGravity(Gravity.BOTTOM, 0,150); + break; + } + toast.show(); + } + + public static void CustomToastWithIcon(Context context, String message, int textColor, int textSize, int bgColor, int radius, int gravity, int icon) { + Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT); + View view = toast.getView(); + TextView msg = (TextView) view.findViewById(android.R.id.message); + msg.setTextSize(textSize); + msg.setTextColor(textColor); + msg.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0); + msg.setGravity(Gravity.CENTER); + msg.setCompoundDrawablePadding(10); + GradientDrawable shape = new GradientDrawable(); + shape.setColor(bgColor); + shape.setCornerRadius(radius); + view.setBackgroundDrawable(shape); + view.setPadding(10,10,10,10); + view.setElevation(10); + switch(gravity){ + case 1: + toast.setGravity(Gravity.TOP, 0,150); + break; + case 2: + toast.setGravity(Gravity.CENTER, 0,0); + break; + case 3: + toast.setGravity(Gravity.BOTTOM, 0,150); + break; + } + toast.show(); + } + + public static void sortListMap(final ArrayList> listMap, final String key, final boolean isNumber, final boolean ascending) { + Collections.sort(listMap, new Comparator>(){ + public int compare(HashMap _compareMap1, HashMap _compareMap2){ + if (isNumber) { + int _count1 = Integer.valueOf(_compareMap1.get(key).toString()); + int _count2 = Integer.valueOf(_compareMap2.get(key).toString()); + if (ascending) { + return _count1 < _count2 ? -1 : _count1 < _count2 ? 1 : 0; + } + else { + return _count1 > _count2 ? -1 : _count1 > _count2 ? 1 : 0; + } + } + else { + if (ascending) { + return (_compareMap1.get(key).toString()).compareTo(_compareMap2.get(key).toString()); + } + else { + return (_compareMap2.get(key).toString()).compareTo(_compareMap1.get(key).toString()); + } + } + }}); + } + + public static void CropImage(Activity a, String s, int i){ + try { + Intent cropIntent = new Intent("com.android.camera.action.CROP"); + File f = new File(s); + Uri contentUri = Uri.fromFile(f); + cropIntent.setDataAndType(contentUri, "image/*"); + cropIntent.putExtra("crop", "true"); + cropIntent.putExtra("aspectX", 1); + cropIntent.putExtra("aspectY", 1); + cropIntent.putExtra("outputX", 280); + cropIntent.putExtra("outputY", 280); + cropIntent.putExtra("return-data", false); + a.startActivityForResult(cropIntent, i); + } catch (ActivityNotFoundException anfe) { + String errorMessage = "Your device doesn't support the crop action!"; + Toast toast = Toast.makeText(a, errorMessage, Toast.LENGTH_SHORT); + toast.show(); + } + } + + public static boolean isConnected(Context a) { + ConnectivityManager connectivityManager = (android.net.ConnectivityManager) + a.getSystemService(Activity.CONNECTIVITY_SERVICE); + NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); + return activeNetworkInfo != null && activeNetworkInfo.isConnected(); + } + + public static String copyFromInputStream(InputStream inputStream) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + byte buf[] = new byte[1024]; + int i; + try { + while ((i = inputStream.read(buf)) != -1){ + outputStream.write(buf, 0, i); + } + outputStream.close(); + inputStream.close(); + } catch (IOException e) { + + } + return outputStream.toString(); + } + + public static void hideKeyboard(Context c){ + InputMethodManager imm = (InputMethodManager) + c.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); + } + + public static void showKeyboard(Context c){ + InputMethodManager imm = (InputMethodManager) + c.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + + public static void showMessage(Context _context, String _s) { + Toast.makeText(_context, _s, Toast.LENGTH_SHORT).show(); + } + + public static int getLocationX(View _view) { + int _location[] = new int[2]; + _view.getLocationInWindow(_location); + return _location[0]; + } + + public static int getLocationY(View _view) { + int _location[] = new int[2]; + _view.getLocationInWindow(_location); + return _location[1]; + } + + public static int getRandom(int _min, int _max) { + Random random = new Random(); + return random.nextInt(_max - _min + 1) + _min; + } + + public static ArrayList getCheckedItemPositionsToArray(ListView _list) { + ArrayList _result = new ArrayList(); + SparseBooleanArray _arr = _list.getCheckedItemPositions(); + for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) { + if (_arr.valueAt(_iIdx)) + _result.add((double) _arr.keyAt(_iIdx)); + } + return _result; + } + + public static float getDip(Context _context, int _input) { + return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, _context.getResources().getDisplayMetrics()); + } + + public static int getDisplayWidthPixels(Context _context) { + return _context.getResources().getDisplayMetrics().widthPixels; + } + + public static int getDisplayHeightPixels(Context _context) { + return _context.getResources().getDisplayMetrics().heightPixels; + } + + public static void getAllKeysFromMap(Map map, ArrayList output) { + if (output == null) return; + output.clear(); + + if (map == null || map.size() <= 0) return; + + Iterator itr = map.entrySet().iterator(); + while (itr.hasNext()) { + Map.Entry entry = (Map.Entry) itr.next(); + output.add(entry.getKey()); + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-xhdpi/app_icon.png b/app/src/main/res/drawable-xhdpi/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ab98421307ce19763868ff3d16f9f02dd3dcb261 GIT binary patch literal 7211 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 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/default_image.png b/app/src/main/res/drawable-xhdpi/default_image.png new file mode 100644 index 0000000000000000000000000000000000000000..49bb21199ec0bba8e4d360cd813dbd7e6696a95d GIT binary patch literal 981 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%xcg6p}rHd>I(3)EF2VS{N990fib~ zFff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9;eUJonf*W>XMsm#F#`j)FbFd;%$g&? zz`*S5>EaktaqI1z^WGtWBFF8G`F?UAH0qvkVv(=+KaB4s2|?F&=@t6?hNvELzaIZQ_Z#lNvt0-0_BItBs5A?=4=>_S{-}YW2I{ zb@wda@3T(7Ct=yX?3Uys^}Rhw%ktPF7tBttdMKFN;D3cd)2bpNVSjtJOM_G7CJm=b0!OLtCOPg5?`5SwjZuxK* zmIe9iEZ5-v$#9?%{k$ZO^NRe z&U>y)xgmdjdji`B{X-nNAsRh;}-+(op0|J zFVj*yXm*_;+athpW5`)suRBaUFW$)&YpmNXeQEc^+(&!!-~J5td)Z_vZ}ZOj_RQj` zjofVB>3X4s_d?mSW-Rsjd1h6A^n$+idPWyS6ZT82da`4-&?}xl*|(}igZ359)nj<| z>D~9USI)ToX865vIfw2y#z!|oHrF<=t!C)`#`tP2Q_fcYfNar(=Gq3X)eH;M`Tw`6 z9a|MN<$ny*1}nx>mZ!bNB2y;)TeCL$)+g_)?(^P$5j%Ec;>X`6YtN)G+z55K=zfl8 zN_wlKa`F_b^}Md~bq)L0Y1%etU<^zOE8o zSNS4kVFpG4T&Q6YgAQw-w^jMF7l-)`WF;)#$~atXmw%9#@L)qRgRA_%^CwQt_+VRP z=z977lwH4i)=cQ1BN?&8R68(O=2YNBv!ySTGel=4^8fXjq;iraJtL{iRZK!v{^9(n zKY>To%bL^HZ>p8A$oaaa{hytCMFZo$h|Tu${~lidz>t6Qv~yjA#=O8sd${*zNY-;| z#3oqsSo?i*Vp3p0paptY?Ita)n{3&TC4Vw#|4A8#t^Fx0@2C80bK6+I*yda%TgY#Z zX}^4*{h!9Tudw<2nsi;wI71Kq&u)*MUYhGkGp$&idVD=Fw=sCS`njxgN@xNA)4rVv literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml new file mode 100644 index 0000000..9197b7e --- /dev/null +++ b/app/src/main/res/layout/main.xml @@ -0,0 +1,57 @@ + + + + + + +