Skip to content

Commit

Permalink
Add loading animation while processing to avoid confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdurazaaqMohammed committed Aug 22, 2024
1 parent 13201b8 commit 06b11b1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdk = 4
targetSdk = 35
versionCode = 29
versionName = "1.6.5.6"
versionName = "1.6.5.7"
multiDexEnabled = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
Expand Down Expand Up @@ -126,6 +128,8 @@ private void setColor(int color, boolean isTextColor, ScrollView settingsMenu) {
d.setTint(textColor);
settingsButton.setBackgroundDrawable(d);
} else settingsButton.setText("⚙️");
ImageView loadingImage = findViewById(R.id.loadingImage);
loadingImage.setColorFilter(new LightingColorFilter(0xFF000000, textColor));
if(fromSettingsMenu) {
setButtonBorder(settingsMenu.findViewById(R.id.langPicker));
setButtonBorder(settingsMenu.findViewById(R.id.changeTextColor));
Expand Down Expand Up @@ -501,6 +505,7 @@ private static class ProcessTask extends AsyncTask<Uri, Void, Void> {
ProcessTask(MainActivity context, com.abdurazaaqmohammed.AntiSplit.main.DeviceSpecsUtil deviceSpecsUtil) {
activityReference = new WeakReference<>(context);
DeviceSpecsUtil = deviceSpecsUtil;
toggleAnimation(context, true);
}

@Override
Expand Down Expand Up @@ -595,6 +600,7 @@ protected Void doInBackground(Uri... uris) {
@Override
protected void onPostExecute(Void result) {
MainActivity activity = activityReference.get();
toggleAnimation(activity, false);
if(activity.urisAreSplitApks) activity.getHandler().post(() -> {
try {
activity.uris.remove(0);
Expand All @@ -610,6 +616,20 @@ protected void onPostExecute(Void result) {
}
}

public static void toggleAnimation(MainActivity context, boolean on) {
ImageView loadingImage = context.findViewById(R.id.loadingImage);
context.runOnUiThread(() -> {
if(on) {
loadingImage.setVisibility(View.VISIBLE);
loadingImage.startAnimation(AnimationUtils.loadAnimation(context, R.anim.loading));
}
else {
loadingImage.setVisibility(View.GONE);
loadingImage.clearAnimation();
}
});
}

private void processOneSplitApkUri(Uri uri) {
splitAPKUri = uri;
if (showDialog) showApkSelectionDialog();
Expand Down Expand Up @@ -875,6 +895,7 @@ private void showSuccess() {
private void showError(Exception e) {
final String mainErr = e.toString();
errorOccurred = !mainErr.equals(rss.getString(R.string.sign_failed));
toggleAnimation(this, false);
StringBuilder stackTrace = new StringBuilder().append(mainErr).append('\n');
for(StackTraceElement line : e.getStackTrace()) stackTrace.append(line).append('\n');
runOnUiThread(() -> {
Expand All @@ -886,6 +907,7 @@ private void showError(Exception e) {
}

private void showError(String err) {
toggleAnimation(this, false);
runOnUiThread(() -> {
TextView errorBox = findViewById(R.id.errorField);
errorBox.setVisibility(View.VISIBLE);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/reandroid/apkeditor/merge/Merger.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.reandroid.apkeditor.merge;

import static com.abdurazaaqmohammed.AntiSplit.main.MainActivity.toggleAnimation;
import static com.reandroid.apkeditor.merge.LogUtil.logMessage;

import android.content.Context;
Expand Down Expand Up @@ -62,6 +63,7 @@ public interface LogListener {
void onLog(int resID);
}

/** @noinspection ResultOfMethodCallIgnored*/
private static void extractAndLoad(Uri in, File cacheDir, Context context, List<String> splits, ApkBundle bundle) throws IOException, MismatchedSplitsException, InterruptedException {
logMessage(in.getPath());
boolean checkSplits = splits != null && !splits.isEmpty();
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/anim/loading.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite" />
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/reload.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="1000"
android:viewportHeight="1000">
<path
android:fillColor="#FF000000"
android:pathData="M586.9,373.6l95.6,-84.4c-49.6,-39.2 -129.4,-79.1 -198.2,-79.1c-134.9,0 -248.2,90.5 -280.2,212.8L10.6,374.5C64.4,168.3 255.2,15.8 482.5,15.8c126.7,0 258.8,63.7 345.4,141.4l90.8,-80.1L990,479.6L586.9,373.6zM317.5,710.8c49.6,39.2 129.4,79.1 198.2,79.1c134.9,0 248.2,-90.5 280.2,-212.8l193.5,48.5c-53.7,206.2 -244.6,358.7 -471.9,358.7c-126.7,0 -258.8,-63.7 -345.4,-141.4l-90.8,80.1L10,520.4l403.1,106L317.5,710.8z"/>
</vector>
15 changes: 13 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
android:id="@+id/settingsButton"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"/>
tools:ignore="SpeakableTextPresentCheck" />

</LinearLayout>

Expand All @@ -46,6 +47,15 @@
android:orientation="vertical"
android:padding="8dp">

<ImageView
android:id="@+id/loadingImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:importantForAccessibility="no"
android:src="@drawable/reload"
android:layout_gravity="center"
android:visibility="gone" />

<TextView
android:id="@+id/errorField"
android:layout_width="match_parent"
Expand All @@ -58,8 +68,9 @@
android:id="@+id/logField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="20sp"
android:textIsSelectable="true"/>
tools:ignore="SpeakableTextPresentCheck" />

</LinearLayout>
</ScrollView>
Expand Down

0 comments on commit 06b11b1

Please sign in to comment.