From 4275dbfff036b170eaaf75b234a5f28a7dfde1a9 Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Mon, 10 Mar 2025 09:26:15 +0800 Subject: [PATCH] =?UTF-8?q?version:1.4.8=20fix:=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E9=94=AE=E6=8B=A8=E5=8F=B7=20update:=E5=A2=9E=E5=8A=A0sim?= =?UTF-8?q?=E5=8D=A1=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +- .../activity/contact/ContactListActivity.java | 30 ----- .../os/activity/setting/SettingActivity.java | 32 ++++- .../com/xxpatx/os/base/rx/BaseRxService.java | 6 +- .../com/xxpatx/os/config/CommonConfig.java | 2 + .../xxpatx/os/service/main/MainService.java | 114 ++++++++++++++---- .../com/xxpatx/os/utils/ContactsUtils.java | 31 +++++ 7 files changed, 156 insertions(+), 63 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7c029f4..598b8ea 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,8 +15,8 @@ android { applicationId "com.xxpatx.os" minSdkVersion 24 targetSdkVersion 29 - versionCode 1048 - versionName "1.4.8" + versionCode 1049 + versionName "1.4.9" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/xxpatx/os/activity/contact/ContactListActivity.java b/app/src/main/java/com/xxpatx/os/activity/contact/ContactListActivity.java index 83a046d..9a354c6 100644 --- a/app/src/main/java/com/xxpatx/os/activity/contact/ContactListActivity.java +++ b/app/src/main/java/com/xxpatx/os/activity/contact/ContactListActivity.java @@ -25,7 +25,6 @@ import com.xxpatx.os.databinding.ActivityContactListBinding; import com.xxpatx.os.dialog.EditContactDialog; import com.zackratos.ultimatebarx.ultimatebarx.java.UltimateBarX; -import java.util.ArrayList; import java.util.List; public class ContactListActivity extends BaseMvvmActivity { @@ -115,35 +114,6 @@ public class ContactListActivity extends BaseMvvmActivity getSIMContacts() { - getAll(); - List contactList = new ArrayList<>(); - ContentResolver resolver = getContentResolver(); - // 获取Sims卡联系人 - Uri uri = Uri.parse("content://icc/adn"); - Cursor phoneCursor = resolver.query(uri, null, null, null, null); - if (phoneCursor != null) { - int colName = phoneCursor.getColumnIndex(NAME); - int colNumber = phoneCursor.getColumnIndex(NUMBER); - while (phoneCursor.moveToNext()) { - String number = phoneCursor.getString(colNumber); - // 当手机号码为空的或者为空字段 跳过当前循环 - String username = phoneCursor.getString(colName); - long id = phoneCursor.getLong(phoneCursor.getColumnIndex("_id")); - Log.e(TAG, "getSIMContacts: number = " + number + " username = " + username + " _id = " + id); - Contact contact = new Contact(username, number, true); - contact.setId(id); - contactList.add(contact); - } - phoneCursor.close(); - } - return contactList; - } - private void getAll() { ContentResolver resolver = getContentResolver(); Cursor adnCursor = resolver.query(Uri.parse("content://icc/adn/subId/0"), null, null, null, null); diff --git a/app/src/main/java/com/xxpatx/os/activity/setting/SettingActivity.java b/app/src/main/java/com/xxpatx/os/activity/setting/SettingActivity.java index 50a313a..7d6b8aa 100644 --- a/app/src/main/java/com/xxpatx/os/activity/setting/SettingActivity.java +++ b/app/src/main/java/com/xxpatx/os/activity/setting/SettingActivity.java @@ -30,6 +30,7 @@ import com.xxpatx.os.bean.AppInfo; import com.xxpatx.os.bean.SystemSettings; import com.xxpatx.os.config.CommonConfig; import com.xxpatx.os.databinding.ActivitySettingBinding; +import com.xxpatx.os.dialog.CustomDialog; import com.xxpatx.os.service.WeAccessibilityService; import com.xxpatx.os.service.main.MainService; import com.xxpatx.os.utils.AccessibilityUtils; @@ -301,13 +302,34 @@ public class SettingActivity extends BaseMvvmActivity() { @@ -244,8 +253,13 @@ public class MainService extends BaseRxService implements MainSContact.MainSView @Override public void onNext(@NonNull Integer hour) { - Log.e("mTimeSignalCallback", "onNext: "); - mSoundPool.play(soundMap.get(hour), 1, 1, 0, 0, 1); + Log.e("mTimeSignalCallback", "onNext: " + hour); + if (hour > 6 && hour < 22) { + mSoundPool.play(soundMap.get(hour), 1, 1, 0, 0, 1); + } else { + /*10点到86点不报时*/ + Log.e("mTimeSignalCallback", "onNext: "); + } } @Override @@ -260,6 +274,34 @@ public class MainService extends BaseRxService implements MainSContact.MainSView }); } + private void setAlarmTime() { + /*Android 10 及以后息屏收不到time_tick广播*/ + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { + AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); + Intent intent = new Intent(XXOS_ACTION_TIME_TICK); + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, TIME_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); + long triggerAtTime = getIntervalMillis(); + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAtTime, pendingIntent); + } + } + + /** + * @return 获取下个整点的时间戳 + */ + private long getIntervalMillis() { + Calendar calendar = Calendar.getInstance(); + int hour = calendar.get(Calendar.HOUR_OF_DAY); + Log.e(TAG, "getIntervalMillis: hour = " + hour); + int min = calendar.get(Calendar.MINUTE); + Log.e(TAG, "getIntervalMillis: min = " + min); + calendar.set(Calendar.HOUR_OF_DAY, hour + 1); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + long time = calendar.getTimeInMillis(); + Log.e(TAG, "getIntervalMillis: time = " + TimeUtils.transferLongToDate(time)); + return time; + } + @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.e(TAG, "onStartCommand: "); @@ -398,7 +440,7 @@ public class MainService extends BaseRxService implements MainSContact.MainSView } // 监听时间和日期变化 - public void registerTimeReceiver() { + public void registerTimeChangedReceiver() { mTimeChangedReceiver = new TimeChangedReceiver(); IntentFilter filter = new IntentFilter(); filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); @@ -406,6 +448,8 @@ public class MainService extends BaseRxService implements MainSContact.MainSView filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); filter.addAction(Intent.ACTION_TIME_TICK); + filter.addAction(XXOS_ACTION_TIME_TICK); + filter.addAction(XXOS_ACTION_TIME_CHANGED); registerReceiver(mTimeChangedReceiver, filter); } @@ -415,15 +459,22 @@ public class MainService extends BaseRxService implements MainSContact.MainSView @Override public void onReceive(Context context, Intent intent) { - if (Intent.ACTION_DATE_CHANGED.equals(intent.getAction())) { - Log.e(TAG, "TimeChangedReceiver:" + "data changed"); - } else if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) { - Log.e(TAG, "TimeChangedReceiver:" + "time changed"); - } else if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) { - Log.e(TAG, "TimeChangedReceiver:" + "timezone changed"); - } else if (Intent.ACTION_TIME_TICK.equals(intent.getAction())) { - Log.e(TAG, "TimeChangedReceiver:" + "time tick"); - hourlyTimeSignal(); + String action = intent.getAction(); + Log.e("TimeChangedReceiver", "onReceive: " + action); + switch (action) { + case Intent.ACTION_DATE_CHANGED: + case Intent.ACTION_TIME_CHANGED: + case Intent.ACTION_TIMEZONE_CHANGED: + case XXOS_ACTION_TIME_CHANGED: + setAlarmTime(); + break; + case Intent.ACTION_TIME_TICK: + hourlyTimeSignal(); + break; + case XXOS_ACTION_TIME_TICK: + alarmWakeup(); + break; + default: } } } @@ -450,7 +501,20 @@ public class MainService extends BaseRxService implements MainSContact.MainSView } } - private void registFastCallReceive() { + private void alarmWakeup() { + boolean hourly_time = mMMKV.decodeBool(CommonConfig.HOURLY_TIME_SIGNAL_KEY, false); + if (hourly_time) { + Calendar calendar = Calendar.getInstance(); + int hour = calendar.get(Calendar.HOUR_OF_DAY); + Log.e(TAG, "hourlyTimeSignal: hour = " + hour); + mTimeSignalCallback.timeTick(hour); + setAlarmTime(); + } else { + Log.e(TAG, "hourlyTimeSignal: not enable hourly time signal"); + } + } + + private void registerFastCallReceive() { if (null == mTimeSignalReceiver) { mTimeSignalReceiver = new TimeSignalReceiver(); } @@ -728,8 +792,8 @@ public class MainService extends BaseRxService implements MainSContact.MainSView if (mBallView.isAttachedToWindow()) { mWindowManager.removeView(mBallView); } - mMMKV.encode(Float_Window_X, mBallParams.x); - mMMKV.encode(Float_Window_Y, mBallParams.y); + mMMKV.encode(FLOAT_WINDOW_X, mBallParams.x); + mMMKV.encode(FLOAT_WINDOW_Y, mBallParams.y); } isBallShown = false; break; @@ -789,8 +853,8 @@ public class MainService extends BaseRxService implements MainSContact.MainSView mBallParams.width = WindowManager.LayoutParams.WRAP_CONTENT; mBallParams.height = WindowManager.LayoutParams.WRAP_CONTENT; // mBallParams.gravity = Gravity.TOP; - int x = mMMKV.decodeInt(Float_Window_X, 360); - int y = mMMKV.decodeInt(Float_Window_Y, -783); + int x = mMMKV.decodeInt(FLOAT_WINDOW_X, 360); + int y = mMMKV.decodeInt(FLOAT_WINDOW_Y, -783); mBallParams.x = x; mBallParams.y = y; mWindowManager.addView(mBallView, mBallParams); @@ -879,8 +943,8 @@ public class MainService extends BaseRxService implements MainSContact.MainSView mBallParams.y += tranY; // 更新悬浮窗位置 mWindowManager.updateViewLayout(mBallView, mBallParams); - mMMKV.encode(Float_Window_X, mBallParams.x); - mMMKV.encode(Float_Window_Y, mBallParams.y); + mMMKV.encode(FLOAT_WINDOW_X, mBallParams.x); + mMMKV.encode(FLOAT_WINDOW_Y, mBallParams.y); // 记录当前坐标作为下一次计算的上一次移动的位置坐标 lastX = nowX; lastY = nowY; diff --git a/app/src/main/java/com/xxpatx/os/utils/ContactsUtils.java b/app/src/main/java/com/xxpatx/os/utils/ContactsUtils.java index bd0315a..6d82d58 100644 --- a/app/src/main/java/com/xxpatx/os/utils/ContactsUtils.java +++ b/app/src/main/java/com/xxpatx/os/utils/ContactsUtils.java @@ -15,9 +15,11 @@ import android.text.TextUtils; import android.util.Log; import com.bumptech.glide.Glide; +import com.tencent.mmkv.MMKV; import com.xxpatx.os.R; import com.xxpatx.os.bean.Contact; import com.xxpatx.os.bean.ContactId; +import com.xxpatx.os.config.CommonConfig; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -640,5 +642,34 @@ public class ContactsUtils { return -1; } + public static final String NAME = "name"; + public static final String NUMBER = "number"; + public static List getSIMContacts(Context context) { + List contactList = new ArrayList<>(); + MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE); + boolean show_sim = mmkv.decodeInt(CommonConfig.SHOW_SIM_CARD_CONTACT, 0) == 1; + if (!show_sim) { + return contactList; + } + ContentResolver resolver = context.getContentResolver(); + // 获取Sims卡联系人 + Uri uri = Uri.parse("content://icc/adn"); + Cursor phoneCursor = resolver.query(uri, null, null, null, null); + if (phoneCursor != null) { + final int colName = phoneCursor.getColumnIndex(NAME); + final int colNumber = phoneCursor.getColumnIndex(NUMBER); + while (phoneCursor.moveToNext()) { + String number = phoneCursor.getString(colNumber); + // 当手机号码为空的或者为空字段 跳过当前循环 + String username = phoneCursor.getString(colName); + Log.e(TAG, "getSIMContacts: number = " + number + " username = " + username); + Contact contact = new Contact(username, number, true); + contactList.add(contact); + } + phoneCursor.close(); + } + return contactList; + } } +