Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
set thread priority high and help setting
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhamTyagi committed Nov 15, 2019
1 parent df23e59 commit f8731f8
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 235 deletions.
1 change: 1 addition & 0 deletions HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Help
7 changes: 3 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -73,6 +72,7 @@ android {
pseudoLocalesEnabled true
}
debug {
versionNameSuffix "-debug"
debuggable true
jniDebuggable true
renderscriptDebuggable true
Expand All @@ -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'
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@
android:name="ai.loko.hk.ui.activities.CropActivity"
android:label="@string/title_activity_crop"
android:theme="@style/NoActionBar" />


<service android:name="com.ixuea.android.downloader.DownloadService">
<intent-filter>
<action android:name="com.ixuea.android.downloader.DOWNLOAD_SERVICE" />
</intent-filter>
</service>

</application>

</manifest>
14 changes: 5 additions & 9 deletions app/src/main/java/ai/loko/hk/ui/Accessibility.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
*/
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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());
Expand All @@ -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();
Expand All @@ -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();
}

Expand Down
18 changes: 2 additions & 16 deletions app/src/main/java/ai/loko/hk/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down
62 changes: 13 additions & 49 deletions app/src/main/java/ai/loko/hk/ui/ocr/Screenshotter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;

}

/**
Expand All @@ -126,30 +107,19 @@ 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();
int rowStride = planes[0].getRowStride();
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);
Expand All @@ -166,12 +136,6 @@ private void tearDown() {
* The interface Screenshot callback.
*/
public interface ScreenshotCallback {
/**
* On screenshot.
*
* @param bitmap the bitmap
*/
void onScreenshot(Bitmap bitmap);

}
}
28 changes: 7 additions & 21 deletions app/src/main/java/ai/loko/hk/ui/services/Floating.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit f8731f8

Please sign in to comment.