x1ongzhu 1 سال پیش
والد
کامیت
13ec4a0765

+ 2 - 1
app/build.gradle

@@ -31,7 +31,7 @@ android {
 
     buildTypes {
         release {
-            minifyEnabled false
+            minifyEnabled true
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
             signingConfig signingConfigs.release
         }
@@ -70,4 +70,5 @@ dependencies {
         exclude group: 'org.json', module: 'json'
     }
     implementation 'com.android.volley:volley:1.2.1'
+    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01"
 }

BIN
app/release/app-release.apk


BIN
app/release/baselineProfiles/0/app-release.dm


BIN
app/release/baselineProfiles/1/app-release.dm


+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -4,6 +4,7 @@
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
 
     <application
         android:name=".MyApplication"

+ 42 - 0
app/src/main/java/com/example/modifier/Backup.java

@@ -0,0 +1,42 @@
+package com.example.modifier;
+
+import java.util.Date;
+
+public class Backup {
+
+    private Config config;
+
+    private Date date;
+
+    private String path;
+
+    public Backup(Config config, Date date, String path) {
+        this.config = config;
+        this.date = date;
+        this.path = path;
+    }
+
+    public Config getConfig() {
+        return config;
+    }
+
+    public void setConfig(Config config) {
+        this.config = config;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+}

+ 72 - 0
app/src/main/java/com/example/modifier/BackupAdapter.java

@@ -0,0 +1,72 @@
+package com.example.modifier;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.core.view.LayoutInflaterCompat;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.example.modifier.databinding.ItemBackupBinding;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Locale;
+
+public class BackupAdapter extends RecyclerView.Adapter<BackupAdapter.BackupViewHolder> {
+
+    public interface OnRestoreListener {
+        void onRestore(Backup backup);
+    }
+
+    private Context context;
+    private List<Backup> backups;
+    private OnRestoreListener onRestoreListener;
+
+    public BackupAdapter(Context context, List<Backup> backups) {
+        this.context = context;
+        this.backups = backups;
+    }
+
+    public void setOnRestoreListener(OnRestoreListener onRestoreListener) {
+        this.onRestoreListener = onRestoreListener;
+    }
+
+    @NonNull
+    @Override
+    public BackupAdapter.BackupViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+        ItemBackupBinding binding = ItemBackupBinding.inflate(LayoutInflater.from(context), parent, false);
+        return new BackupViewHolder(binding.getRoot());
+    }
+
+    @SuppressLint("DefaultLocale")
+    @Override
+    public void onBindViewHolder(@NonNull BackupAdapter.BackupViewHolder holder, int position) {
+        ItemBackupBinding binding = ItemBackupBinding.bind(holder.itemView);
+        Backup backup = backups.get(position);
+        binding.tvNumber.setText(backup.getConfig().getNumber());
+        binding.tvTime.setText(SimpleDateFormat.getDateTimeInstance().format(backup.getDate()));
+        binding.tvInfo.setText(String.format("MCC: %s, MNC: %s, Country: %s",
+                backup.getConfig().getMcc(), backup.getConfig().getMnc(), backup.getConfig().getCountry()));
+        binding.btnRestore.setOnClickListener(v -> {
+            if (onRestoreListener != null) {
+                onRestoreListener.onRestore(backup);
+            }
+        });
+    }
+
+    @Override
+    public int getItemCount() {
+        return backups.size();
+    }
+
+    public class BackupViewHolder extends RecyclerView.ViewHolder {
+        public BackupViewHolder(@NonNull ViewGroup parent) {
+            super(parent);
+        }
+    }
+}

+ 6 - 0
app/src/main/java/com/example/modifier/ModifierService.java

@@ -9,6 +9,7 @@ import android.content.pm.PackageManager;
 import android.graphics.PixelFormat;
 import android.net.Uri;
 import android.os.Build;
+import android.os.PowerManager;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.Gravity;
@@ -273,6 +274,7 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
         layoutParams.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
         layoutParams.format = PixelFormat.TRANSLUCENT;
         layoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
+        layoutParams.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
         layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
         layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
         layoutParams.x = 0;
@@ -325,6 +327,10 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
 
             updateDevice("canSend", canSend);
         });
+
+//        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+//        PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "RCS:MyWakelockTag");
+//        wakeLock.acquire();
     }
 
     private void updateDevice(String key, Object value) {

+ 26 - 13
app/src/main/java/com/example/modifier/fragments/BackupFragment.java

@@ -1,12 +1,6 @@
 package com.example.modifier.fragments;
 
 import android.os.Bundle;
-
-import androidx.annotation.NonNull;
-import androidx.core.content.ContextCompat;
-import androidx.fragment.app.Fragment;
-
-import android.os.FileUtils;
 import android.os.Handler;
 import android.os.Looper;
 import android.util.Log;
@@ -14,19 +8,25 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
+import androidx.annotation.NonNull;
+import androidx.core.content.ContextCompat;
+import androidx.fragment.app.Fragment;
+import androidx.recyclerview.widget.LinearLayoutManager;
+
+import com.example.modifier.Backup;
+import com.example.modifier.BackupAdapter;
+import com.example.modifier.Config;
 import com.example.modifier.R;
 import com.example.modifier.Utils;
 import com.example.modifier.databinding.FragmentBackupBinding;
-import com.google.android.material.dialog.MaterialAlertDialogBuilder;
-import com.google.gson.Gson;
 
 import org.apache.commons.io.IOUtils;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
 import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -34,7 +34,10 @@ public class BackupFragment extends Fragment {
 
     FragmentBackupBinding binding;
     Handler handler = new Handler(Looper.getMainLooper());
-    ExecutorService executor = Executors.newFixedThreadPool(4);
+    ExecutorService executor = Executors.newFixedThreadPool(8);
+
+    BackupAdapter adapter;
+    List<Backup> backups;
 
     public BackupFragment() {
         // Required empty public constructor
@@ -44,7 +47,14 @@ public class BackupFragment extends Fragment {
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        backups = new ArrayList<>();
+        adapter = new BackupAdapter(getContext(), backups);
 
+        for (int i = 0; i < 10; i++) {
+            Backup backup = new Backup(new Config("123000", "310", "240", "", "", "", "us"), new Date(), "/");
+            backups.add(backup);
+        }
+        adapter.notifyDataSetChanged();
     }
 
     @Override
@@ -69,8 +79,11 @@ public class BackupFragment extends Fragment {
                     }, 1500);
                 });
             });
-
         });
+
+        binding.rvBackup.setLayoutManager(new LinearLayoutManager(getContext()));
+        binding.rvBackup.setAdapter(adapter);
+
         return binding.getRoot();
     }
 

+ 15 - 3
app/src/main/res/layout/floating_window.xml

@@ -16,22 +16,34 @@
             android:layout_width="match_parent"
             android:layout_height="match_parent">
 
+            <com.google.android.material.textview.MaterialTextView
+                android:id="@+id/tv_device_name"
+                android:layout_width="match_parent"
+                android:layout_height="24dp"
+                android:ellipsize="end"
+                android:gravity="center"
+                android:lines="1"
+                android:text="01-001"
+                android:textColor="?attr/colorPrimary"
+                android:textSize="14sp"
+                app:layout_constraintTop_toTopOf="parent" />
+
             <com.google.android.material.checkbox.MaterialCheckBox
                 android:id="@+id/sw_connect"
                 style="@style/Widget.Material3.CompoundButton.CheckBox"
                 android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
+                android:layout_height="36dp"
                 android:checked="true"
                 android:text="Connect"
                 android:textSize="14sp"
                 app:layout_constraintStart_toStartOf="parent"
-                app:layout_constraintTop_toTopOf="parent" />
+                app:layout_constraintTop_toBottomOf="@id/tv_device_name" />
 
             <com.google.android.material.checkbox.MaterialCheckBox
                 android:id="@+id/sw_send"
                 style="@style/Widget.Material3.CompoundButton.CheckBox"
                 android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
+                android:layout_height="36dp"
                 android:checked="true"
                 android:text="Send"
                 android:textSize="14sp"

+ 11 - 10
app/src/main/res/layout/fragment_backup.xml

@@ -6,20 +6,21 @@
     android:layout_height="match_parent"
     tools:context=".fragments.BackupFragment">
 
-    <ScrollView
+    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+        android:id="@+id/refresh"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:clipToPadding="false"
-        android:fitsSystemWindows="true">
+        android:layout_height="match_parent">
 
-        <LinearLayout
+        <androidx.recyclerview.widget.RecyclerView
+            android:id="@+id/rv_backup"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="vertical"
-            android:padding="20dp">
+            android:layout_height="match_parent"
+            android:clipToPadding="false"
+            android:fitsSystemWindows="true">
+
+        </androidx.recyclerview.widget.RecyclerView>
+    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
 
-        </LinearLayout>
-    </ScrollView>
 
     <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
         android:id="@+id/fab_backup"

+ 74 - 0
app/src/main/res/layout/item_backup.xml

@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <com.google.android.material.card.MaterialCardView
+        style="?attr/materialCardViewFilledStyle"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="16dp"
+        android:layout_marginTop="16dp"
+        android:layout_marginRight="16dp">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical"
+            android:padding="16dp">
+
+            <com.google.android.material.textview.MaterialTextView
+                android:id="@+id/tv_number"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="123456789"
+                android:textColor="?attr/colorPrimary"
+                android:textSize="16sp"
+                android:textStyle="bold" />
+
+            <com.google.android.material.textview.MaterialTextView
+                android:id="@+id/tv_info"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="8dp"
+                android:text="mcc: 310    mnc: 240   coutry: us"
+                android:textColor="?attr/colorOnSurfaceVariant"
+                android:textSize="14sp" />
+
+            <androidx.constraintlayout.widget.ConstraintLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="8dp"
+                android:orientation="horizontal">
+
+                <com.google.android.material.textview.MaterialTextView
+                    android:id="@+id/tv_time"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="2024-05-13 18:00:00"
+                    android:textColor="?attr/colorOnSurfaceVariant"
+                    android:textSize="14sp"
+                    app:layout_constraintBottom_toBottomOf="parent"
+                    app:layout_constraintStart_toStartOf="parent"
+                    app:layout_constraintTop_toTopOf="parent" />
+
+                <com.google.android.material.button.MaterialButton
+                    android:id="@+id/btn_restore"
+                    style="@style/Widget.Material3.Button.TextButton"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center_vertical"
+                    android:minHeight="0dp"
+                    android:padding="0dp"
+                    android:text="Restore"
+                    app:icon="@drawable/ic_settings_backup_restore"
+                    app:iconPadding="0dp"
+                    app:layout_constraintBaseline_toBaselineOf="@id/tv_time"
+                    app:layout_constraintEnd_toEndOf="parent" />
+            </androidx.constraintlayout.widget.ConstraintLayout>
+
+        </LinearLayout>
+
+    </com.google.android.material.card.MaterialCardView>
+</LinearLayout>