Skip to content

Commit

Permalink
添加未接来电未读短信计数器,修正部分逻辑
Browse files Browse the repository at this point in the history
添加了一个未接来电未读短信计数器,修正授权逻辑,修正应用界面菜单逻辑,以及把菜单添加了个exported的flag可以在设置进入,补全了一些文本资源。
  • Loading branch information
Yuyuko1024 committed Jun 25, 2023
1 parent 859be5f commit 665d633
Show file tree
Hide file tree
Showing 19 changed files with 1,476 additions and 57 deletions.
17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

1,130 changes: 1,130 additions & 0 deletions .idea/stat.log

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions .idea/statistic.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
implementation 'org.jetbrains:annotations:23.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.preference:preference:1.2.0'
implementation 'pub.devrel:easypermissions:3.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
Expand All @@ -20,6 +22,9 @@
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />

<application
android:allowBackup="true"
Expand All @@ -29,6 +34,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MicroLauncher">

<service
android:process=":restart"
android:name=".service.KillSelfSrv"
Expand Down Expand Up @@ -59,11 +65,16 @@
<activity
android:name=".activity.MenuActivity"
android:excludeFromRecents="true"
android:exported="false"
android:exported="true"
android:icon="@drawable/launcher_option"
android:label="@string/menu_title"
android:launchMode="singleInstance"
android:theme="@style/Theme.MicroLauncher" />
android:theme="@style/Theme.MicroLauncher">
<intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activity.AppListActivity"
android:excludeFromRecents="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,36 +205,42 @@ private void showMenu(View view){
PopupMenu popupMenu = new PopupMenu(this,view);
popupMenu.getMenuInflater().inflate(R.menu.app_option,popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(item -> {
Intent ia = new Intent();
switch (item.getItemId()){
case R.id.menu_app_manage:
ia.setClassName("com.android.settings",
Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setClassName("com.android.settings",
"com.android.settings.applications.ManageApplications");
startActivity(ia);
startActivity(i);
break;
case R.id.menu_about_phone:
Log.e("Device Info","Device SDK="+Build.VERSION.SDK_INT);
if (Build.VERSION.SDK_INT >= 28){
Log.e("Device Info","Device SDK="+Build.VERSION.SDK_INT);
Intent ia = new Intent();
ia.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ia.setClassName("com.android.settings",
"com.android.settings.Settings$MyDeviceInfoActivity");
startActivity(ia);
}else{
Log.e("Device Info","Device SDK="+Build.VERSION.SDK_INT);
Intent ia = new Intent();
ia.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ia.setClassName("com.android.settings",
"com.android.settings.Settings$DeviceInfoSettingsActivity");
startActivity(ia);}
break;
case R.id.menu_launcher_option:
Intent menu = new Intent(AppList3rdActivity.this, MenuActivity.class);
menu.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(menu);
finish();
break;
case R.id.menu_volume_changer:
Intent vol_it = new Intent(AppList3rdActivity.this, VolumeChanger.class);
vol_it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(vol_it);
break;
}
return false;
return true;
});
popupMenu.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ private void loadApp() {
pkgName = activityInfo.packageName;
application = new Application(appIcon, appLabel, isSystemApp, appIntent, pkgName);
if(isSimpleList) {
if(appLabel != getString(R.string.app_name) && isSystemApp ){
mApplicationList.add(application);
}
if(appLabel == getString(R.string.trd_apps)){
if(appLabel != getString(R.string.app_name) && isSystemApp || appLabel == getString(R.string.trd_apps)){
mApplicationList.add(application);
}
}else{
Expand Down Expand Up @@ -164,31 +161,35 @@ private void showMenu(View view){
switch (item.getItemId()){
case R.id.menu_app_manage:
Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setClassName("com.android.settings",
"com.android.settings.applications.ManageApplications");
startActivity(i);
break;
case R.id.menu_about_phone:
Log.e("Device Info","Device SDK="+Build.VERSION.SDK_INT);
if (Build.VERSION.SDK_INT >= 28){
Log.e("Device Info","Device SDK="+Build.VERSION.SDK_INT);
Intent ia = new Intent();
ia.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ia.setClassName("com.android.settings",
"com.android.settings.Settings$MyDeviceInfoActivity");
startActivity(ia);
}else{
Log.e("Device Info","Device SDK="+Build.VERSION.SDK_INT);
Intent ia = new Intent();
ia.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ia.setClassName("com.android.settings",
"com.android.settings.Settings$DeviceInfoSettingsActivity");
startActivity(ia);}
break;
case R.id.menu_launcher_option:
Intent menu = new Intent(AppListActivity.this, MenuActivity.class);
menu.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(menu);
finish();
break;
case R.id.menu_volume_changer:
Intent vol_it = new Intent(AppListActivity.this, VolumeChanger.class);
vol_it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(vol_it);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.CallLog;
import android.provider.Telephony;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
Expand All @@ -26,6 +30,7 @@
import org.exthmui.microlauncher.duoqin.BuildConfig;
import org.exthmui.microlauncher.duoqin.R;
import org.exthmui.microlauncher.duoqin.databinding.ActivityMainBinding;
import org.exthmui.microlauncher.duoqin.widgets.CallSmsCounter;
import org.exthmui.microlauncher.duoqin.widgets.CarrierTextView;
import org.exthmui.microlauncher.duoqin.widgets.ClockViewManager;
import org.exthmui.microlauncher.duoqin.widgets.DateTextView;
Expand All @@ -36,18 +41,25 @@
import java.util.TimerTask;

import es.dmoral.toasty.Toasty;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;

public class MainActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
private final static String TAG = "ML_MainActivity";
private static final int grant_int=1;
private boolean carrier_enable = true;
private boolean xiaoai_enable = true;
private boolean dialpad_enable = true;
private boolean carrier_enable;
private boolean xiaoai_enable;
private boolean dialpad_enable;
private boolean callsms_counter;
private boolean torch = false;
private String clock_locate;
private CameraManager manager;
private ContentObserver mMissedPhoneContentObserver;
private ContentObserver mMissedMsgContentObserver;
private ActivityMainBinding mainBinding;
private ClockViewManager clockViewManager;
private DateTextView date;
private CallSmsCounter callSmsCounter;
private LunarDateTextView lunarDate;
private CarrierTextView carrier;
String pound_func;
Expand All @@ -67,14 +79,74 @@ protected void onCreate(Bundle savedInstanceState) {
date = new DateTextView(this);
lunarDate = new LunarDateTextView(this);
carrier = new CarrierTextView(this);
callSmsCounter = new CallSmsCounter(this);
clockViewManager.insertOrUpdateView(1, date);
loadSettings();
initCallSmsObserver();
}

private void GrantPermissions(){
if(PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(this,android.Manifest.permission.CAMERA)){
String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
ActivityCompat.requestPermissions(this, perms,grant_int);
String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA,
Manifest.permission.READ_CALL_LOG, Manifest.permission.READ_SMS};
if (!EasyPermissions.hasPermissions(this, perms)) {
EasyPermissions.requestPermissions(this, getString(R.string.permission_required_title),
grant_int, perms);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions.onRequestPermissionsResult(requestCode,permissions,grantResults,this);
}

@AfterPermissionGranted(grant_int)
private void initCallSmsObserver() {
mMissedPhoneContentObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange);
runOnUiThread(() -> {
callSmsCounter = null;
callSmsCounter = new CallSmsCounter(MainActivity.this);
clockViewManager.insertOrUpdateView(4, callSmsCounter);
setClockLocate(clock_locate);
});
}
};
mMissedMsgContentObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange);
runOnUiThread(() -> {
callSmsCounter = null;
callSmsCounter = new CallSmsCounter(MainActivity.this);
clockViewManager.insertOrUpdateView(4, callSmsCounter);
setClockLocate(clock_locate);
});
}
};
unregisterObserver();
getContentResolver().registerContentObserver(CallLog.Calls.CONTENT_URI,
true, mMissedPhoneContentObserver);
getContentResolver().registerContentObserver(Uri.parse("content://sms"),
true, mMissedMsgContentObserver);
getContentResolver().registerContentObserver(Telephony.MmsSms.CONTENT_URI,
true, mMissedMsgContentObserver);
}

private synchronized void unregisterObserver() {
try {
if (mMissedPhoneContentObserver != null) {
getContentResolver().unregisterContentObserver(mMissedPhoneContentObserver);
}
if (mMissedMsgContentObserver != null) {
getContentResolver().unregisterContentObserver(mMissedMsgContentObserver);
}
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "unregisterObserver failed: " + e.getMessage());
}
}

Expand All @@ -97,7 +169,15 @@ private void loadSettings(){
Log.d(TAG, "Disable carrier name");
clockViewManager.removeView(3);
}
String clock_locate = (sharedPreferences.getString("list_preference_clock_locate","reimu"));
callsms_counter = sharedPreferences.getBoolean("switch_preference_callsms_counter",false);
if(callsms_counter){
Log.d(TAG, "Enable call/sms counter");
clockViewManager.insertOrUpdateView(4, callSmsCounter);
}else{
Log.d(TAG, "Disable call/sms counter");
clockViewManager.removeView(4);
}
clock_locate = (sharedPreferences.getString("list_preference_clock_locate","left"));
setClockLocate(clock_locate);
pound_func = (sharedPreferences.getString("preference_pound_func","volume"));
String clock_size = (sharedPreferences.getString("list_preference_clock_size","58"));
Expand All @@ -117,7 +197,7 @@ private void setClockLocate(String clockLocate) {
break;
}
mainBinding.clock.textClock.setLayoutParams(params);
for (int i = 1; i < 4; i++) {
for (int i = 1; i < clockViewManager.getViewCount()+1; i++) {
Log.d(TAG, "setClockLocate: "+i);
clockViewManager.setLayoutParams(i, params);
}
Expand All @@ -126,7 +206,7 @@ private void setClockLocate(String clockLocate) {
private void checkDevice(){
Log.d(TAG, "checkDevice: "+Build.BOARD);
if(!Build.BOARD.equals("k61v1_64_bsp")){
Toasty.info(this,"非多亲设备,部分功能可能无法使用。",Toasty.LENGTH_SHORT).show();
Toasty.info(this,R.string.not_qin_device,Toasty.LENGTH_SHORT).show();
}
}

Expand All @@ -144,7 +224,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
break;
case "list_preference_clock_locate":
String clock_locate = (sharedPreferences.getString("list_preference_clock_locate", "reimu"));
clock_locate = (sharedPreferences.getString("list_preference_clock_locate", "left"));
setClockLocate(clock_locate);
break;
case "list_preference_clock_size":
Expand All @@ -170,6 +250,9 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
case "preference_pound_func":
pound_func = sharedPreferences.getString("preference_pound_func","volume");
break;
case "switch_preference_callsms_counter":
callsms_counter = sharedPreferences.getBoolean("switch_preference_callsms_counter",false);
break;
}
}

Expand All @@ -193,6 +276,7 @@ public void onClick(View v) {
protected void onDestroy() {
super.onDestroy();
finish();
unregisterObserver();
}

@Override
Expand Down Expand Up @@ -230,7 +314,6 @@ else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
it.addCategory("android.intent.category.APP_BROWSER");
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(it);
Log.d(TAG,"5,4,3,2,1,三倍ice cream!!!!!");
}catch (Exception e){
Log.d(TAG,"没有找到系统浏览器或者系统浏览器被禁用");
}
Expand Down
Loading

0 comments on commit 665d633

Please sign in to comment.