From f8731f8a9131305c7ae54b72f59dc0ba42e253ae Mon Sep 17 00:00:00 2001 From: SubhamTyagi Date: Fri, 15 Nov 2019 20:41:49 +0530 Subject: [PATCH] set thread priority high and help setting --- HELP.md | 1 + app/build.gradle | 7 +- app/src/main/AndroidManifest.xml | 8 -- .../java/ai/loko/hk/ui/Accessibility.java | 14 ++-- .../main/java/ai/loko/hk/ui/MainActivity.java | 18 +---- .../java/ai/loko/hk/ui/ocr/Screenshotter.java | 62 +++----------- .../java/ai/loko/hk/ui/services/Floating.java | 28 ++----- .../ai/loko/hk/ui/services/OCRFloating.java | 81 +++++-------------- .../hk/ui/services/option4/OCRFloating4.java | 76 +++++------------ .../main/java/ai/loko/hk/ui/utils/Utils.java | 40 +++++++++ .../main/res/drawable/ic_apps_black_24dp.xml | 5 -- .../main/res/drawable/ic_help_white_24dp.xml | 5 ++ update-changelog.json | 16 ++-- 13 files changed, 126 insertions(+), 235 deletions(-) create mode 100644 HELP.md delete mode 100644 app/src/main/res/drawable/ic_apps_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_help_white_24dp.xml diff --git a/HELP.md b/HELP.md new file mode 100644 index 0000000..7581886 --- /dev/null +++ b/HELP.md @@ -0,0 +1 @@ +# Help \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 6a24e8b..cab9d25 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,15 +30,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 defaultConfig { applicationId "ai.loko.hk.ui" minSdkVersion 19 targetSdkVersion 28 - versionCode 31 - versionName '2.5' + versionCode 32 + versionName '2.5.1' multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" versionNameSuffix '-Coral' @@ -73,6 +72,7 @@ android { pseudoLocalesEnabled true } debug { + versionNameSuffix "-debug" debuggable true jniDebuggable true renderscriptDebuggable true @@ -86,7 +86,6 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - //Multidex support for older version than lollipop implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.recyclerview:recyclerview:1.1.0-rc01' implementation 'com.google.android.material:material:1.2.0-alpha01' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5374cf3..56c7ef0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -101,14 +101,6 @@ android:name="ai.loko.hk.ui.activities.CropActivity" android:label="@string/title_activity_crop" android:theme="@style/NoActionBar" /> - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/ai/loko/hk/ui/Accessibility.java b/app/src/main/java/ai/loko/hk/ui/Accessibility.java index 9dc8433..72f9583 100644 --- a/app/src/main/java/ai/loko/hk/ui/Accessibility.java +++ b/app/src/main/java/ai/loko/hk/ui/Accessibility.java @@ -43,6 +43,9 @@ import ai.loko.hk.ui.services.Floating; import ai.loko.hk.ui.utils.CustomToast; +import static android.os.Process.THREAD_PRIORITY_BACKGROUND; +import static android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE; + /** * This accessibility may be discontinue in future; */ @@ -393,7 +396,7 @@ void getQuestionAndOptionFromScreen(AccessibilityNodeInfo source) { synchronized private void findAnswer(String question, String option1, String option2, String option3) { synchronized (this) { - new Update().execute(question, option1, option2, option3); + new Update().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,question, option1, option2, option3); } } @@ -420,10 +423,6 @@ protected void onPostExecute(String s) { super.onPostExecute(s); Intent i = new Intent(getApplicationContext(), Floating.class); - /*i.putExtra("option1", obj.getAcount()); - i.putExtra("option2", obj.getBcount()); - i.putExtra("option3", obj.getCcount()); - */ i.putExtra("option1", engine.getA1()); i.putExtra("option2", engine.getB2()); i.putExtra("option3", engine.getC3()); @@ -439,9 +438,7 @@ protected void onProgressUpdate(Void... values) { @Override protected String doInBackground(String... strings) { - - //obj = new FindAnswers(strings[0], strings[1], strings[2], strings[3]); - //obj.search(); + android.os.Process.setThreadPriority(THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY_MORE_FAVORABLE); engine = new Engine(new Question(strings[0], strings[1], strings[2], strings[3])); engine.search(); @@ -450,7 +447,6 @@ protected String doInBackground(String... strings) { return engine.getAnswer(); } else { engine = new Engine(new Question(strings[0], strings[1], strings[2], strings[3])); - // obj = new FindAnswers(strings[0], strings[1], strings[2], strings[3]); return engine.search(); } diff --git a/app/src/main/java/ai/loko/hk/ui/MainActivity.java b/app/src/main/java/ai/loko/hk/ui/MainActivity.java index ccf3def..23e2fe3 100644 --- a/app/src/main/java/ai/loko/hk/ui/MainActivity.java +++ b/app/src/main/java/ai/loko/hk/ui/MainActivity.java @@ -253,10 +253,10 @@ public void onBoomButtonClick(int index) { } })); - rightBmb.addBuilder(new HamButton.Builder().normalImageRes(R.drawable.ic_apps_black_24dp).subNormalText("Supported App that are currently working").normalText("Supported Apps").listener(new OnBMClickListener() { + rightBmb.addBuilder(new HamButton.Builder().normalImageRes(R.drawable.ic_help_white_24dp).subNormalText("If you are getting any error than get online help").normalText("Help Me").listener(new OnBMClickListener() { @Override public void onBoomButtonClick(int index) { - supportedApps(); + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/SubhamTyagi/loco-answers/HELP.md"))); } })); rightBmb.addBuilder(new HamButton.Builder().normalImageRes(R.drawable.ic_info_white_24dp).normalText("About").subNormalText("About me").listener(new OnBMClickListener() { @@ -421,20 +421,6 @@ public void onClick(SweetAlertDialog sweetAlertDialog) { } - private void supportedApps() { - new SweetAlertDialog(this, SweetAlertDialog.NORMAL_TYPE) - .setTitleText("Supported Apps") - .setContentText(getResources().getString(R.string.supported_apps)) - .setConfirmText("Ok") - .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { - @Override - public void onClick(SweetAlertDialog sweetAlertDialog) { - //startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/SubhamTyagi/loco-answers/releases/"))); - sweetAlertDialog.dismissWithAnimation(); - } - }).show(); - } - private boolean isNetworkAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); diff --git a/app/src/main/java/ai/loko/hk/ui/ocr/Screenshotter.java b/app/src/main/java/ai/loko/hk/ui/ocr/Screenshotter.java index 432dbc7..366837f 100644 --- a/app/src/main/java/ai/loko/hk/ui/ocr/Screenshotter.java +++ b/app/src/main/java/ai/loko/hk/ui/ocr/Screenshotter.java @@ -45,41 +45,23 @@ import ai.loko.hk.ui.utils.Logger; -/** - * The type Screenshotter. - */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class Screenshotter implements ImageReader.OnImageAvailableListener { private static final String TAG = "Screenshotter"; - private static Screenshotter mInstance; - private static Context context; + private Screenshotter mInstance; + private Context context; private VirtualDisplay virtualDisplay; private int width; private int height; private ScreenshotCallback cb; private ImageReader mImageReader; private MediaProjection mMediaProjection; - private volatile int imageAvailable = 0; - private Screenshotter() { + public Screenshotter(Context context) { + this.context = context; } - /** - * Get the single instance of the Screenshotter class. - * - * @param context1 the context 1 - * @return the instance - */ - public static Screenshotter getInstance(Context context1) { - context = context1; - if (mInstance == null) { - mInstance = new Screenshotter(); - } - return mInstance; - } - - /** * Take screenshot. * @@ -95,20 +77,19 @@ public void takeScreenshot(final ScreenshotCallback cb) { } } try { - virtualDisplay = mMediaProjection.createVirtualDisplay("Screenshotter", width, height, 50, + virtualDisplay = mMediaProjection.createVirtualDisplay( + "Screenshotter", + width, height, 50, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, - mImageReader.getSurface(), null, null); - + mImageReader.getSurface(), + null, + null); mImageReader.setOnImageAvailableListener(Screenshotter.this, null); - - } catch (Exception e) { e.printStackTrace(); Logger.logException(e); - - } - // return this; + } /** @@ -126,22 +107,12 @@ public Screenshotter setSize(int width, int height) { @Override public void onImageAvailable(ImageReader reader) { - Image image; - // Log.d(TAG, "onImageAvailable: start"); - /*synchronized (this) { - ++imageAvailable; - if (imageAvailable != 2) { - image = reader.acquireLatestImage(); - if (image == null) return; - image.close(); - return; - } - }*/ - image = reader.acquireLatestImage(); + Image image = reader.acquireLatestImage(); if (image == null) { Log.d(TAG, "onImageAvailable: image is null"); return; } + final Image.Plane[] planes = image.getPlanes(); final Buffer buffer = planes[0].getBuffer().rewind(); int pixelStride = planes[0].getPixelStride(); @@ -149,7 +120,6 @@ public void onImageAvailable(ImageReader reader) { int rowPadding = rowStride - pixelStride * width; Bitmap bitmap = Bitmap.createBitmap(width + rowPadding / pixelStride, height, Bitmap.Config.ARGB_8888); bitmap.copyPixelsFromBuffer(buffer); - tearDown(); image.close(); cb.onScreenshot(bitmap); @@ -166,12 +136,6 @@ private void tearDown() { * The interface Screenshot callback. */ public interface ScreenshotCallback { - /** - * On screenshot. - * - * @param bitmap the bitmap - */ void onScreenshot(Bitmap bitmap); - } } diff --git a/app/src/main/java/ai/loko/hk/ui/services/Floating.java b/app/src/main/java/ai/loko/hk/ui/services/Floating.java index 535abad..447651f 100644 --- a/app/src/main/java/ai/loko/hk/ui/services/Floating.java +++ b/app/src/main/java/ai/loko/hk/ui/services/Floating.java @@ -53,6 +53,9 @@ import ai.loko.hk.ui.activities.ForegroundActivity; import ui.R; +import static android.os.Process.THREAD_PRIORITY_BACKGROUND; +import static android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE; + public class Floating extends Service { @@ -75,6 +78,8 @@ public IBinder onBind(Intent intent) { @Override public void onCreate() { super.onCreate(); + android.os.Process.setThreadPriority(THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY_MORE_FAVORABLE); + LinearLayout linearLayout = new LinearLayout(this); mFloatingView = LayoutInflater.from(this).inflate(R.layout.floating, linearLayout); @@ -102,15 +107,6 @@ public void onCreate() { params.x = 0; params.y = 100; - //if (Build.VERSION.SDK_INT>=22) - // params.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; - //else - // params.type=WindowManager.LayoutParams.TYPE_PHONE; - //params.format = PixelFormat.TRANSLUCENT; - // params.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; - // params.width = WindowManager.LayoutParams.WRAP_CONTENT; - //params.height = WindowManager.LayoutParams.WRAP_CONTENT; - //Add the view to the window mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); if (mWindowManager != null) { @@ -171,24 +167,14 @@ public void onClick(View v) { } }); - /*wiki.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Which.itIsGoogle = false; - setAnswers(); - wiki.setProgress(1); - } - });*/ - } - //GENERATE + private void setAnswers() { Intent i = new Intent(getApplicationContext(), ForegroundActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); - //getApplicationContext().startActivity(new Intent(getApplicationContext(),ForegroundActivity.class)); - } + } @Override public int onStartCommand(Intent intent, int flags, int startId) { diff --git a/app/src/main/java/ai/loko/hk/ui/services/OCRFloating.java b/app/src/main/java/ai/loko/hk/ui/services/OCRFloating.java index 4286d02..ba34c66 100644 --- a/app/src/main/java/ai/loko/hk/ui/services/OCRFloating.java +++ b/app/src/main/java/ai/loko/hk/ui/services/OCRFloating.java @@ -56,11 +56,6 @@ import com.dd.processbutton.iml.ActionProcessButton; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - import ai.loko.hk.ui.MainActivity; import ai.loko.hk.ui.answers.Engine; import ai.loko.hk.ui.constants.Constant; @@ -70,10 +65,12 @@ import ai.loko.hk.ui.ocr.Points; import ai.loko.hk.ui.ocr.Screenshotter; import ai.loko.hk.ui.ocr.TesseractImageTextReader; -import ai.loko.hk.ui.utils.Logger; import ai.loko.hk.ui.utils.Utils; import ui.R; +import static android.os.Process.THREAD_PRIORITY_BACKGROUND; +import static android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE; + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public class OCRFloating extends Service { @@ -100,12 +97,10 @@ public OCRFloating() { @Override public void onCreate() { super.onCreate(); - + android.os.Process.setThreadPriority(THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY_MORE_FAVORABLE); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); - mFloatingView = LayoutInflater.from(this).inflate(R.layout.floating, new LinearLayout(this)); - notification(); int LAYOUT_FLAG; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -127,7 +122,6 @@ public void onCreate() { if (mWindowManager != null) { mWindowManager.addView(mFloatingView, params); - // } mFloatingView.findViewById(R.id.head).setOnTouchListener(new View.OnTouchListener() { @@ -188,65 +182,32 @@ public boolean onTouch(View v, MotionEvent event) { width = size.x; height = size.y; + final Screenshotter screenshotter = new Screenshotter(getApplicationContext()); + screenshotter.setSize(width, height); + + getAnswer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { OCRFloating.isGoogle = true; getAnswer.setProgress(10); - synchronized (OCRFloating.this) { - Screenshotter.getInstance(getApplicationContext()).setSize(width, height).takeScreenshot(new Screenshotter.ScreenshotCallback() { - @Override - public void onScreenshot(final Bitmap bitmap) { - getAnswer.setProgress(25); - new TakeScreenShot().execute(bitmap); - } - }); - } + screenshotter.takeScreenshot(new Screenshotter.ScreenshotCallback() { + @Override + public void onScreenshot(Bitmap bitmap) { + getAnswer.setProgress(25); + + new ProcessImageAndSearch().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bitmap); + } + }); } }); + coordinate[0] = (int) Math.ceil((double) Points.X1); coordinate[1] = (int) Math.ceil((double) Points.Y1); coordinate[2] = (int) Math.ceil((double) Points.X2); coordinate[3] = (int) Math.ceil((double) Points.Y2); } - private void writeToStorage(Bitmap bmp) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - File picFile = new File(Constant.PATH, "SCR_" + Long.toString(System.currentTimeMillis()) + ".jpg"); - bmp.compress(Bitmap.CompressFormat.JPEG, 60, bytes); - try { - Log.d(TAG, "Writing images"); - picFile.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(picFile); - outputStream.write(bytes.toByteArray()); - outputStream.close(); - } catch (IOException e) { - Logger.logException(e); - } - } - - private void writeToStorage(String[] questionAndOption) { - File picFile = new File(Constant.PATH, "QaOption_" + Long.toString(System.currentTimeMillis()) + ".txt"); - StringBuilder value = new StringBuilder(); - if (questionAndOption.length == 5) { - value.append(questionAndOption[4]); - } else { - value.append("ERROR: "); - for (String s : questionAndOption) { - value.append(s).append("\n"); - } - } - try { - picFile.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(picFile); - outputStream.write(value.toString().getBytes()); - outputStream.close(); - } catch (IOException e) { - Logger.logException(e); - } - - } - @Override public int onStartCommand(Intent intent, int flags, int startId) { String action = ""; @@ -293,7 +254,7 @@ public IBinder onBind(Intent intent) { return null; } - private class TakeScreenShot extends AsyncTask { + private class ProcessImageAndSearch extends AsyncTask { private String[] questionAndOption; private Bitmap croppedGrayscaleImage; private Engine engine; @@ -331,8 +292,8 @@ protected void onPostExecute(final String s) { new Thread() { @Override public void run() { - writeToStorage(croppedGrayscaleImage); - writeToStorage(questionAndOption); + Utils.writeToStorage(croppedGrayscaleImage); + Utils.writeToStorage(questionAndOption); } }.start(); } @@ -340,6 +301,8 @@ public void run() { @Override protected String doInBackground(Bitmap... bitmaps) { + Log.d(TAG, "doInBackground: "); + android.os.Process.setThreadPriority(THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY_MORE_FAVORABLE); if (coordinate[2] == 0 || coordinate[3] == 0) { coordinate[2] = width; coordinate[3] = height; diff --git a/app/src/main/java/ai/loko/hk/ui/services/option4/OCRFloating4.java b/app/src/main/java/ai/loko/hk/ui/services/option4/OCRFloating4.java index afc2f05..b123431 100644 --- a/app/src/main/java/ai/loko/hk/ui/services/option4/OCRFloating4.java +++ b/app/src/main/java/ai/loko/hk/ui/services/option4/OCRFloating4.java @@ -58,11 +58,6 @@ import com.dd.processbutton.iml.ActionProcessButton; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - import ai.loko.hk.ui.MainActivity; import ai.loko.hk.ui.answers.option4.Engine4; import ai.loko.hk.ui.constants.Constant; @@ -72,10 +67,12 @@ import ai.loko.hk.ui.ocr.Screenshotter; import ai.loko.hk.ui.ocr.option4.ImageTextReader4; import ai.loko.hk.ui.ocr.option4.TesseractImageTextReader4; -import ai.loko.hk.ui.utils.Logger; import ai.loko.hk.ui.utils.Utils; import ui.R; +import static android.os.Process.THREAD_PRIORITY_BACKGROUND; +import static android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE; + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public class OCRFloating4 extends Service { @@ -100,6 +97,7 @@ public OCRFloating4() { @Override public void onCreate() { super.onCreate(); + android.os.Process.setThreadPriority(THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY_MORE_FAVORABLE); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); @@ -187,21 +185,23 @@ public boolean onTouch(View v, MotionEvent event) { display.getSize(size); width = size.x; height = size.y; + final Screenshotter screenshotter = new Screenshotter(getApplicationContext()); + screenshotter.setSize(width, height); getAnswer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { OCRFloating4.isGoogle = true; getAnswer.setProgress(10); - synchronized (OCRFloating4.this) { - Screenshotter.getInstance(getApplicationContext()).setSize(width, height).takeScreenshot(new Screenshotter.ScreenshotCallback() { - @Override - public void onScreenshot(final Bitmap bitmap) { - getAnswer.setProgress(25); - new TakeScreenShot().execute(bitmap); - } - }); - } + screenshotter.takeScreenshot(new Screenshotter.ScreenshotCallback() { + @Override + public void onScreenshot(Bitmap bitmap) { + getAnswer.setProgress(25); + Log.d(TAG, "onScreenshot: one time screenshot taken"); + new ProcessImageAndSearch().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, bitmap); + + } + }); } }); coordinate[0] = (int) Math.ceil((double) Points.X1); @@ -211,44 +211,6 @@ public void onScreenshot(final Bitmap bitmap) { } - private void writeToStorage(Bitmap bmp) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - File picFile = new File(Constant.PATH, "SCR_" + Long.toString(System.currentTimeMillis()) + ".jpg"); - bmp.compress(Bitmap.CompressFormat.JPEG, 60, bytes); - try { - Log.d(TAG, "Writing images"); - picFile.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(picFile); - outputStream.write(bytes.toByteArray()); - outputStream.close(); - } catch (IOException e) { - Logger.logException(e); - } - } - - private void writeToStorage(String[] questionAndOption) { - File picFile = new File(Constant.PATH, "QaOption_" + Long.toString(System.currentTimeMillis()) + ".txt"); - StringBuilder value = new StringBuilder(); - if (questionAndOption.length == 5) { - value.append(questionAndOption[4]); - } else { - value.append("ERROR: "); - for (String s : questionAndOption) { - value.append(s).append("\n"); - } - } - try { - picFile.createNewFile(); - FileOutputStream outputStream = new FileOutputStream(picFile); - outputStream.write(value.toString().getBytes()); - outputStream.close(); - } catch (IOException e) { - Logger.logException(e); - } - - } - - @Override public int onStartCommand(Intent intent, int flags, int startId) { String action = ""; @@ -295,7 +257,7 @@ public IBinder onBind(Intent intent) { return null; } - private class TakeScreenShot extends AsyncTask { + private class ProcessImageAndSearch extends AsyncTask { private String[] questionAndOption; private Bitmap croppedGrayscaleImage; private Engine4 engine; @@ -343,8 +305,8 @@ protected void onPostExecute(final String s) { new Thread() { @Override public void run() { - writeToStorage(croppedGrayscaleImage); - writeToStorage(questionAndOption); + Utils.writeToStorage(croppedGrayscaleImage); + Utils.writeToStorage(questionAndOption); } }.start(); } @@ -352,6 +314,8 @@ public void run() { @Override protected String doInBackground(Bitmap... bitmaps) { + android.os.Process.setThreadPriority(THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY_MORE_FAVORABLE); + if (coordinate[2] == 0 || coordinate[3] == 0) { coordinate[2] = width; coordinate[3] = height; diff --git a/app/src/main/java/ai/loko/hk/ui/utils/Utils.java b/app/src/main/java/ai/loko/hk/ui/utils/Utils.java index 8f5bf50..44766b1 100644 --- a/app/src/main/java/ai/loko/hk/ui/utils/Utils.java +++ b/app/src/main/java/ai/loko/hk/ui/utils/Utils.java @@ -33,14 +33,20 @@ import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; +import android.util.Log; import androidx.annotation.Nullable; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; +import ai.loko.hk.ui.constants.Constant; import ai.loko.hk.ui.data.Data; public class Utils { @@ -120,6 +126,40 @@ public static Bitmap convertToGrayscale(Bitmap bmpOriginal) { return bmpGrayscale; } + public static void writeToStorage(Bitmap bmp) { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + File picFile = new File(Constant.PATH, "SCR_" + Long.toString(System.currentTimeMillis()) + ".jpg"); + bmp.compress(Bitmap.CompressFormat.JPEG, 60, bytes); + try { + picFile.createNewFile(); + FileOutputStream outputStream = new FileOutputStream(picFile); + outputStream.write(bytes.toByteArray()); + outputStream.close(); + } catch (IOException e) { + Logger.logException(e); + } + } + + public static void writeToStorage(String[] questionAndOption) { + File picFile = new File(Constant.PATH, "QaOption_" + Long.toString(System.currentTimeMillis()) + ".txt"); + StringBuilder value = new StringBuilder(); + if (questionAndOption.length == 5) { + value.append(questionAndOption[4]); + } else { + value.append("ERROR: "); + for (String s : questionAndOption) { + value.append(s).append("\n"); + } + } + try { + picFile.createNewFile(); + FileOutputStream outputStream = new FileOutputStream(picFile); + outputStream.write(value.toString().getBytes()); + outputStream.close(); + } catch (IOException e) { + Logger.logException(e); + } + } //public static String getDataUrl() } diff --git a/app/src/main/res/drawable/ic_apps_black_24dp.xml b/app/src/main/res/drawable/ic_apps_black_24dp.xml deleted file mode 100644 index 373f775..0000000 --- a/app/src/main/res/drawable/ic_apps_black_24dp.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_help_white_24dp.xml b/app/src/main/res/drawable/ic_help_white_24dp.xml new file mode 100644 index 0000000..5ec2577 --- /dev/null +++ b/app/src/main/res/drawable/ic_help_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/update-changelog.json b/update-changelog.json index d7453da..67db505 100644 --- a/update-changelog.json +++ b/update-changelog.json @@ -1,13 +1,13 @@ { - "latestVersion": "2.5", - "latestVersionCode": "31", + "latestVersion": "2.5.1", + "latestVersionCode": "32", "url": "https://github.com/SubhamTyagi/loco-answers/releases", "releaseNotes": [ - "- See App Settings for WhatsNew + "- Blank screen bug fix", "- Tesseract all types data(fast,best,standard) for accuracy and performance", - "- Grayscale image control" - "- Enlarge Image" - "- Android 10 crash fix" - "- other bug fixes and performance improvements" - ] + "- Grayscale image control setting", + "- Enlarge Image Setting", + "- Android 10 crash fix", + "- other bug fixes and performance improvements" + ] } \ No newline at end of file