hxMac 1 month ago
parent
commit
c020131491

+ 8 - 0
UtilsApplication/app/app/src/main/AndroidManifest.xml

@@ -14,7 +14,15 @@
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     <uses-permission android:name="android.permission.VIBRATE" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
+    <uses-permission android:name="android.permission.INSTALL_PACKAGES" />
+    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
+    <queries>
+        <intent>
+            <action android:name="android.provider.Telephony.SMS_DELIVER"/>
+        </intent>
 
+    </queries>
     <application
         android:allowBackup="true"
         android:dataExtractionRules="@xml/data_extraction_rules"

+ 48 - 22
UtilsApplication/app/app/src/main/java/com/hx/utils/application/ui/sms/SmsFragment.kt

@@ -1,5 +1,6 @@
 package com.hx.utils.application.ui.sms
 
+import android.Manifest.permission.READ_PHONE_STATE
 import android.Manifest.permission.READ_SMS
 import android.Manifest.permission.RECEIVE_SMS
 import android.Manifest.permission.SEND_SMS
@@ -10,13 +11,16 @@ import android.content.ContentValues
 import android.content.Intent
 import android.os.Build
 import android.provider.Telephony
+import android.util.Log
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import androidx.appcompat.app.AppCompatActivity
+import androidx.core.widget.doOnTextChanged
 import androidx.lifecycle.ViewModelProvider
 import com.blankj.utilcode.util.AppUtils
 import com.blankj.utilcode.util.PermissionUtils
+import com.blankj.utilcode.util.StringUtils
 import com.blankj.utilcode.util.TimeUtils
 import com.blankj.utilcode.util.ToastUtils
 import com.hx.utils.application.R
@@ -37,28 +41,26 @@ class SmsFragment : BaseFragment<FragmentSmsBinding, SmsViewModel>() {
 
     override fun setupView() {
         binding.loading.visibility = View.GONE
-        viewModel.showTime.observe(viewLifecycleOwner) {
-            binding.time.setText(it)
-        }
         binding.insertMms.setOnClickListener {
             val smsPackageName = Telephony.Sms.getDefaultSmsPackage(context)
             val currentPackageName = context?.packageName
-            if (smsPackageName != currentPackageName) {
-                val intent: Intent?
-                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
-                    intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
-                    intent.putExtra(
-                        Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
-                        requireContext().packageName
-                    )
-                    requireContext().startActivity(intent)
-                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
-                    openSMSappChooser()
+            if (!smsPackageName.isNullOrBlank()) {
+                if (smsPackageName != currentPackageName) {
+                    val intent: Intent?
+                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
+                        intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
+                        intent.putExtra(
+                            Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
+                            requireContext().packageName
+                        )
+                        requireContext().startActivity(intent)
+                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+                        openSMSappChooser()
+                    }
+                    return@setOnClickListener
                 }
-                return@setOnClickListener
             }
 
-
             val name = binding.name.text?.toString().orEmpty()
             val message = binding.message.text?.toString().orEmpty()
             if (name.isBlank()) {
@@ -89,9 +91,33 @@ class SmsFragment : BaseFragment<FragmentSmsBinding, SmsViewModel>() {
             )
             datePickerDialog.show()
         }
+        binding.read.setOnCheckedChangeListener { _, b ->
+            viewModel.read.postValue(b)
+        }
+
+        binding.name.doOnTextChanged { text, _, _, _ ->
+            viewModel.name.postValue(text.toString())
+        }
+
+        binding.message.doOnTextChanged { text, _, _, _ ->
+            viewModel.message.postValue(text.toString())
+        }
+
+        viewModel.message.observe(viewLifecycleOwner) {
+            binding.showMsg.text = it
+        }
+
+        viewModel.name.observe(viewLifecycleOwner) {
+            binding.materialTextView.text = StringUtils.getString(R.string.from_S, it)
+        }
 
-        binding.radioGroup.setOnCheckedChangeListener { _, checkedId ->
-            viewModel.read.value = binding.radioButton1.id == checkedId
+        viewModel.read.observe(viewLifecycleOwner) {
+            binding.materialTextView3.setText(if (it) R.string.read else R.string.unread)
+        }
+
+        viewModel.showTime.observe(viewLifecycleOwner) {
+            binding.selectTime.text = it
+            binding.materialTextView2.text = it
         }
 
         (activity as? AppCompatActivity)?.supportActionBar?.title = arguments?.getString("data")
@@ -109,7 +135,7 @@ class SmsFragment : BaseFragment<FragmentSmsBinding, SmsViewModel>() {
 
 
     fun getPermissions() {
-        val permissions = listOf(SEND_SMS, RECEIVE_SMS, READ_SMS).toTypedArray()
+        val permissions = listOf(SEND_SMS, RECEIVE_SMS, READ_SMS, READ_PHONE_STATE).toTypedArray()
         PermissionUtils.permission(*permissions)
             .rationale { _, shouldRequest ->
                 run {
@@ -117,7 +143,7 @@ class SmsFragment : BaseFragment<FragmentSmsBinding, SmsViewModel>() {
                 }
             }.callback(object : PermissionUtils.FullCallback {
                 override fun onGranted(permissionsGranted: MutableList<String>) {
-
+                    Log.d("hzshkj", "onGranted: $permissionsGranted")
                 }
 
                 override fun onDenied(forever: MutableList<String>, denied: MutableList<String>) {
@@ -145,8 +171,8 @@ class SmsFragment : BaseFragment<FragmentSmsBinding, SmsViewModel>() {
             }
             context?.contentResolver?.insert(Telephony.Sms.CONTENT_URI, values)
 
-            binding.name.text.clear()
-            binding.message.text.clear()
+            binding.name.text?.clear()
+            binding.message.text?.clear()
             viewModel.time.postValue(0)
             viewModel.showTime.postValue("")
 

+ 3 - 2
UtilsApplication/app/app/src/main/java/com/hx/utils/application/ui/sms/SmsViewModel.kt

@@ -9,8 +9,9 @@ class SmsViewModel : ViewModel() {
     }
     val time: MutableLiveData<Long> = _time
 
-    val read: MutableLiveData<Boolean>
-        get() = MutableLiveData(false)
+    val read = MutableLiveData(false)
+    val name = MutableLiveData("")
+    val message = MutableLiveData("")
 
     val showTime: MutableLiveData<String> = MutableLiveData()
 }

+ 7 - 0
UtilsApplication/app/app/src/main/res/drawable/twotone_contact_phone_24.xml

@@ -0,0 +1,7 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
+      
+    <path android:fillAlpha="0.3" android:fillColor="@android:color/white" android:pathData="M22,5L2,5v14h20L22,5zM9,6c1.65,0 3,1.35 3,3s-1.35,3 -3,3 -3,-1.35 -3,-3 1.35,-3 3,-3zM15,18L3,18v-1.41C3,14.08 6.97,13 9,13s6,1.08 6,3.58L15,18zM17.85,14h1.64L21,16l-1.99,1.99c-1.31,-0.98 -2.28,-2.38 -2.73,-3.99 -0.18,-0.64 -0.28,-1.31 -0.28,-2s0.1,-1.36 0.28,-2c0.45,-1.62 1.42,-3.01 2.73,-3.99L21,8l-1.51,2h-1.64c-0.22,0.63 -0.35,1.3 -0.35,2s0.13,1.37 0.35,2z" android:strokeAlpha="0.3"/>
+      
+    <path android:fillColor="@android:color/white" android:pathData="M2,21h20c1.1,0 1.99,-0.9 1.99,-2L24,5c0,-1.1 -0.9,-2 -2,-2L2,3C0.9,3 0,3.9 0,5v14c0,1.1 0.9,2 2,2zM2,5h20v14L2,19L2,5zM19.49,10L21,8l-1.99,-1.99c-1.31,0.98 -2.28,2.37 -2.73,3.99 -0.18,0.64 -0.28,1.31 -0.28,2s0.1,1.36 0.28,2c0.45,1.61 1.42,3.01 2.73,3.99L21,16l-1.51,-2h-1.64c-0.22,-0.63 -0.35,-1.3 -0.35,-2s0.13,-1.37 0.35,-2h1.64zM9,12c1.65,0 3,-1.35 3,-3s-1.35,-3 -3,-3 -3,1.35 -3,3 1.35,3 3,3zM9,8c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM9,13c-2.03,0 -6,1.08 -6,3.58L3,18h12v-1.41C15,14.08 11.03,13 9,13zM5.48,16c0.74,-0.5 2.22,-1 3.52,-1s2.77,0.49 3.52,1L5.48,16z"/>
+    
+</vector>

+ 11 - 0
UtilsApplication/app/app/src/main/res/drawable/twotone_timer_24.xml

@@ -0,0 +1,11 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
+      
+    <path android:fillAlpha="0.3" android:fillColor="@android:color/white" android:pathData="M12,6c-3.87,0 -7,3.13 -7,7s3.13,7 7,7s7,-3.13 7,-7S15.87,6 12,6zM13,14h-2V8h2V14z" android:strokeAlpha="0.3"/>
+      
+    <path android:fillColor="@android:color/white" android:pathData="M9,1h6v2h-6z"/>
+      
+    <path android:fillColor="@android:color/white" android:pathData="M19.03,7.39l1.42,-1.42c-0.43,-0.51 -0.9,-0.99 -1.41,-1.41l-1.42,1.42C16.07,4.74 14.12,4 12,4c-4.97,0 -9,4.03 -9,9c0,4.97 4.02,9 9,9s9,-4.03 9,-9C21,10.88 20.26,8.93 19.03,7.39zM12,20c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7s7,3.13 7,7S15.87,20 12,20z"/>
+      
+    <path android:fillColor="@android:color/white" android:pathData="M11,8h2v6h-2z"/>
+    
+</vector>

+ 106 - 70
UtilsApplication/app/app/src/main/res/layout/fragment_sms.xml

@@ -4,11 +4,13 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:background="@color/white"
     tools:context=".ui.dashboard.DashboardFragment">
 
     <androidx.constraintlayout.widget.ConstraintLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:layout_marginTop="15dp"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
@@ -19,101 +21,134 @@
             android:layout_height="match_parent"
             android:orientation="vertical">
 
-
-            <EditText
-                android:id="@+id/name"
+            <com.google.android.material.textfield.TextInputLayout
+                style="@style/ThemeOverlay.Material3.AutoCompleteTextView.OutlinedBox"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginStart="15dp"
-                android:layout_marginTop="10dp"
                 android:layout_marginEnd="15dp"
                 android:hint="@string/sender_s_name_or_number"
-                android:lines="2" />
+                app:endIconMode="clear_text">
+
+                <com.google.android.material.textfield.TextInputEditText
+                    android:id="@+id/name"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content" />
+            </com.google.android.material.textfield.TextInputLayout>
 
-            <EditText
-                android:id="@+id/message"
+            <com.google.android.material.textfield.TextInputLayout
+                style="@style/ThemeOverlay.Material3.AutoCompleteTextView.OutlinedBox"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginStart="15dp"
+                android:layout_marginTop="15dp"
                 android:layout_marginEnd="15dp"
-                android:gravity="top|start"
                 android:hint="@string/sms_content"
-                android:inputType="textMultiLine"
-                android:maxLines="20"
-                android:minLines="10"
-                android:scrollbars="vertical" />
+                app:endIconMode="clear_text">
 
-            <TextView
+                <com.google.android.material.textfield.TextInputEditText
+                    android:id="@+id/message"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:gravity="center|start"
+                    android:inputType="textMultiLine"
+                    android:maxLines="20"
+                    android:minLines="10"
+                    android:scrollbars="vertical" />
+            </com.google.android.material.textfield.TextInputLayout>
+
+            <com.google.android.material.materialswitch.MaterialSwitch
+                android:id="@+id/read"
                 android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
+                android:layout_height="match_parent"
                 android:layout_marginStart="15dp"
+                android:layout_marginTop="15dp"
                 android:layout_marginEnd="15dp"
-                android:text="@string/has_the_message_been_read"
-                android:textColor="#000000"
-                android:textSize="13sp" />
+                android:text="@string/has_the_message_been_read" />
 
-            <RadioGroup
-                android:id="@+id/radioGroup"
+            <com.google.android.material.button.MaterialSplitButton
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginStart="15dp"
-                android:layout_marginTop="10dp"
-                android:layout_marginEnd="15dp"
-                android:orientation="horizontal">
+                android:layout_marginTop="15dp"
+                android:layout_marginEnd="15dp">
 
-                <RadioButton
-                    android:id="@+id/radioButton1"
-                    android:layout_width="wrap_content"
+                <Button
+                    android:id="@+id/selectTime"
+                    android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:checked="true"
-                    android:tag="1"
-                    android:text="@string/read"
-                    android:textColor="#000000" />
+                    android:gravity="start|center"
+                    android:text="@string/sms_sending_time"
+                    app:icon="@drawable/twotone_timer_24" />
 
 
-                <RadioButton
-                    android:id="@+id/radioButton2"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:layout_marginStart="20dp"
-                    android:tag="0"
-                    android:text="@string/unread"
-                    android:textColor="#000000" />
-            </RadioGroup>
+            </com.google.android.material.button.MaterialSplitButton>
+
 
-            <androidx.constraintlayout.widget.ConstraintLayout
+            <com.google.android.material.card.MaterialCardView
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:layout_marginTop="10dp"
-                android:orientation="horizontal">
-
-                <EditText
-                    android:id="@+id/time"
-                    android:layout_width="0dp"
-                    android:layout_height="wrap_content"
-                    android:layout_marginStart="15dp"
-                    android:layout_marginEnd="10dp"
-                    android:enabled="false"
-                    android:focusable="false"
-                    android:hint="@string/sms_sending_time"
-                    app:layout_constraintBottom_toBottomOf="parent"
-                    app:layout_constraintEnd_toStartOf="@+id/selectTime"
-                    app:layout_constraintStart_toStartOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
-                <Button
-                    android:id="@+id/selectTime"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:layout_marginEnd="15dp"
-                    android:layout_marginBottom="10dp"
-                    android:text="@string/select_time"
-                    android:textColor="#ffffff"
-                    android:textSize="13sp"
-                    app:layout_constraintBottom_toBottomOf="parent"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-            </androidx.constraintlayout.widget.ConstraintLayout>
+                android:layout_margin="15dp"
+
+                android:orientation="vertical">
+
+                <androidx.constraintlayout.widget.ConstraintLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="100dp"
+                    android:layout_margin="15dp">
+
+                    <com.google.android.material.textview.MaterialTextView
+                        android:id="@+id/materialTextView"
+                        android:layout_width="0dp"
+                        android:layout_height="wrap_content"
+                        android:drawableStart="@drawable/twotone_email_24"
+                        android:drawablePadding="5dp"
+                        android:gravity="center|start"
+                        android:textStyle="bold"
+                        app:layout_constraintEnd_toStartOf="@+id/materialTextView2"
+                        app:layout_constraintHorizontal_bias="0.5"
+                        app:layout_constraintHorizontal_chainStyle="packed"
+                        app:layout_constraintStart_toStartOf="parent"
+                        app:layout_constraintTop_toTopOf="parent"
+                        tools:text="Sender" />
+
+                    <com.google.android.material.textview.MaterialTextView
+                        android:id="@+id/materialTextView2"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        app:layout_constraintBottom_toBottomOf="@+id/materialTextView"
+                        app:layout_constraintEnd_toEndOf="parent"
+                        app:layout_constraintHorizontal_bias="0.5"
+                        app:layout_constraintStart_toEndOf="@+id/materialTextView"
+                        app:layout_constraintTop_toTopOf="parent"
+                        tools:text="Time" />
+
+                    <com.google.android.material.textview.MaterialTextView
+
+                        android:id="@+id/show_msg"
+                        android:layout_width="0dp"
+                        android:layout_height="0dp"
+                        android:layout_marginTop="4dp"
+                        android:layout_marginBottom="4dp"
+                        android:textStyle="italic"
+                        app:layout_constraintBottom_toTopOf="@+id/materialTextView3"
+                        app:layout_constraintEnd_toEndOf="parent"
+                        app:layout_constraintHorizontal_bias="0.153"
+                        app:layout_constraintStart_toStartOf="parent"
+                        app:layout_constraintTop_toBottomOf="@+id/materialTextView"
+                        tools:text="Message" />
+
+                    <com.google.android.material.textview.MaterialTextView
+                        android:id="@+id/materialTextView3"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:textStyle="bold"
+                        android:visibility="gone"
+                        app:layout_constraintBottom_toBottomOf="parent"
+                        app:layout_constraintEnd_toEndOf="parent"
+                        tools:text="Read" />
+                </androidx.constraintlayout.widget.ConstraintLayout>
+            </com.google.android.material.card.MaterialCardView>
 
             <Button
                 android:id="@+id/insert_mms"
@@ -137,7 +172,8 @@
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="parent" />
+            app:layout_constraintTop_toTopOf="parent"
+            tools:visibility="gone" />
     </androidx.constraintlayout.widget.ConstraintLayout>
 
 </androidx.core.widget.NestedScrollView>

+ 1 - 0
UtilsApplication/app/app/src/main/res/values/strings.xml

@@ -27,6 +27,7 @@
     <string name="sms_sending_time">SMS sending time</string>
     <string name="select_time">Select time</string>
     <string name="submit">Submit</string>
+    <string name="from_S">From: %s</string>
 
 
 </resources>