Skip to content

Commit

Permalink
去掉testOnly=true
Browse files Browse the repository at this point in the history
添加解锁
添加夜间模式
目前版本支持直接安装
  • Loading branch information
tignioj committed Jun 2, 2020
1 parent 196aa8b commit 9d8512f
Show file tree
Hide file tree
Showing 33 changed files with 678 additions and 121 deletions.
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tignioj.freezeapp">


<application
android:name=".InitApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:testOnly="true"
android:theme="@style/AppTheme">
<activity
android:name="com.tignioj.freezeapp.MainActivity"
Expand Down
43 changes: 43 additions & 0 deletions app/src/main/java/com/tignioj/freezeapp/InitApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.tignioj.freezeapp;

import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import androidx.appcompat.app.AppCompatDelegate;

import com.tignioj.freezeapp.config.MyConfig;

public class InitApplication extends Application {
private boolean isNightModeEnabled = false;

private static InitApplication singleton = null;

public static InitApplication getInstance() {
if (singleton == null) {
singleton = new InitApplication();
}
return singleton;
}

@Override
public void onCreate() {
super.onCreate();
singleton = this;
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
this.isNightModeEnabled = mPrefs.getBoolean(MyConfig.PERSONAL_SHP_CONFIG_KEY_IS_NIGHT_MODE, true);
}

public boolean isNightModeEnabled() {
return isNightModeEnabled;
}

public void setIsNightModeEnabled(boolean isNightModeEnabled) {
this.isNightModeEnabled = isNightModeEnabled;

SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(MyConfig.PERSONAL_SHP_CONFIG_KEY_IS_NIGHT_MODE, isNightModeEnabled);
editor.apply();
}
}
39 changes: 23 additions & 16 deletions app/src/main/java/com/tignioj/freezeapp/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
package com.tignioj.freezeapp;

import androidx.appcompat.app.AlertDialog;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import android.content.DialogInterface;
import android.app.Application;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import com.google.android.material.navigation.NavigationView;
import com.tignioj.freezeapp.backend.viewmodel.HomeViewModel;
import com.tignioj.freezeapp.config.MyConfig;
import com.tignioj.freezeapp.service.FreezeService;
import com.tignioj.freezeapp.ui.setting.SettingFragment;
import com.tignioj.freezeapp.utils.DeviceMethod;
import com.tignioj.freezeapp.utils.Inform;

public class MainActivity extends AppCompatActivity {

private AppBarConfiguration mAppBarConfiguration;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (InitApplication.getInstance().isNightModeEnabled()) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
setContentView(R.layout.activity_main);

// DeviceMethod.getInstance(getApplicationContext()).onRemoveActivate();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

Inform.setMainActivity(MainActivity.this);

Log.d(MyConfig.MY_TAG, "reload");

// NavigationUI.setupActionBarWithNavController(this, navController);

//判断是否可使用
Expand All @@ -45,8 +60,8 @@ protected void onCreate(Bundle savedInstanceState) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Inform.alert("请先激活", "请先激活, 先退出账号,再设置该应用为device owner, 激活方法请看https://github.com/tignioj/AutoFreezeApp",
"查看链接", "退出",
Inform.alert(R.string.please_activate_alert_title, R.string.activate_tips,
R.string.check_link_buton_text, R.string.exit_text,
new Inform.Callback() {
@Override
public void ok() {
Expand All @@ -68,8 +83,9 @@ public void dismiss() {
});
}
}, 0);
} else {
startService(new Intent(getApplicationContext(), FreezeService.class));
}
startService(new Intent(getApplicationContext(), FreezeService.class));


//侧边栏
Expand All @@ -82,22 +98,13 @@ public void dismiss() {
.setDrawerLayout(drawer)
.build();


//添加返回按钮到导航栏
NavController navController = Navigation.findNavController(this, R.id.fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.fragment);
Expand Down
30 changes: 6 additions & 24 deletions app/src/main/java/com/tignioj/freezeapp/MyDeviceAdminReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public void onDisabled(final Context context, Intent intent) {
// 设备管理:不可用
Toast.makeText(context, "设备管理:不可用", Toast.LENGTH_SHORT).show();
//如果取消了激活就再次提示激活
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
DeviceMethod.getInstance(context.getApplicationContext()).onActivate();
}
}, 3000);
// new Handler().postDelayed(new Runnable() {
// @Override
// public void run() {
// DeviceMethod.getInstance(context.getApplicationContext()).onActivate();
// }
// }, 3000);
}

@Override
Expand All @@ -37,25 +37,7 @@ public CharSequence onDisableRequested(Context context, Intent intent) {
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
context.stopService(intent);// 是否可以停止*/

return "这是一个可选的消息,警告有关禁止用户的请求";
}

@Override
public void onPasswordChanged(Context context, Intent intent) {
// 设备管理:密码己经改变
// Toast.makeText(context, "设备管理:密码己经改变", Toast.LENGTH_SHORT).show();
}

@Override
public void onPasswordFailed(Context context, Intent intent) {
// 设备管理:改变密码失败
// Toast.makeText(context, "设备管理:改变密码失败", Toast.LENGTH_SHORT).show();
}

@Override
public void onPasswordSucceeded(Context context, Intent intent) {
// 设备管理:改变密码成功
// Toast.makeText(context, "设备管理:改变密码成功", Toast.LENGTH_SHORT).show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import com.tignioj.freezeapp.backend.viewmodel.repo.FreezeAppRepository;
import com.tignioj.freezeapp.backend.viewmodel.repo.FreezeTaskerRepository;
import com.tignioj.freezeapp.backend.viewmodel.repo.HomeRepository;
import com.tignioj.freezeapp.entity.AppInfo;
import com.tignioj.freezeapp.uientity.AppInfo;
import com.tignioj.freezeapp.utils.DeviceMethod;

import java.util.List;

public class HomeViewModel extends AndroidViewModel {
Context context;

HomeRepository homeRepository;
AppsCategoryRepository appsCategoryRepository;
FreezeAppRepository freezeAppRepository;
Expand All @@ -32,6 +32,7 @@ public MutableLiveData<Integer> getSelectedReadyToFreezeCount() {
return homeRepository.getSelectedReadyToFreezeCount();
}


public HomeViewModel(@NonNull Application application) {
super(application);
this.context = application;
Expand Down Expand Up @@ -178,7 +179,6 @@ public MutableLiveData<List<AppInfo>> findUnFreezeAppsListWithPattern(String pat
}



public void setSelectedReadyToFreezeCount(int i) {
homeRepository.setSelectedReadyToFreezeCount(i);
}
Expand All @@ -203,8 +203,22 @@ public void deleteFreezeAppByPackageName(String appName) {
}
}

public List<String > getFonzenAppListPackageName() {
return homeRepository.getFrozenAppListPackageName();
public List<String> getFonzenAppListPackageName() {
return homeRepository.getFrozenAppListPackageNameFromPM();
}

/**
* 返回解冻数量
* @return
*/
public int unFreezeAllApp() {
List<AppInfo> frozenAppList = homeRepository.getFrozenAppList();
int i = 0;
for (AppInfo a : frozenAppList) {
i++;
DeviceMethod.getInstance(context).freeze(a.getPackageName(), false);
}
freezeAppRepository.unFreezeAllApp();
return i;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public List<FreezeApp> getFreezeAppByCategoryId(long id) {
return freezeAppDao.getAllAppsByCategoryId(id);
}

public void insertFreezeApp(FreezeApp[] freezeApps) {
public void insertFreezeApp(FreezeApp ...freezeApps) {
new FreezeAppRepository.InsertAsyncTask(freezeAppDao).execute(freezeApps);
}

public void deleteFreezeApp(FreezeApp[] freezeApps) {
public void deleteFreezeApp(FreezeApp ...freezeApps) {
new FreezeAppRepository.DeleteAsyncTask(freezeAppDao).execute(freezeApps);
}

public void updateFreezeApp(FreezeApp[] freezeApps) {
public void updateFreezeApp(FreezeApp ...freezeApps) {
new FreezeAppRepository.UpdateAsyncTask(freezeAppDao).execute(freezeApps);
}

Expand All @@ -70,6 +70,17 @@ public FreezeApp getFreezeAppByPackageName(String packageName) {
return freezeAppDao.getFreezeAppByPackageName(packageName);
}

/**
* 把数据库中所有冻结的改为未冻结
*/
public void unFreezeAllApp() {
List<FreezeApp> allFrozenApps = getAllFrozenApps();
for (FreezeApp f : allFrozenApps) {
f.setFrozen(false);
updateFreezeApp(f);
}
}


public static class InsertAsyncTask extends AsyncTask<FreezeApp, Void, Void> {
private FreezeAppDao freezeAppDao;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.tignioj.freezeapp.backend.viewmodel.repo;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;

import androidx.lifecycle.MutableLiveData;

import com.tignioj.freezeapp.backend.entitys.FreezeApp;
import com.tignioj.freezeapp.entity.AppInfo;
import com.tignioj.freezeapp.config.MyConfig;
import com.tignioj.freezeapp.uientity.AppInfo;
import com.tignioj.freezeapp.utils.DeviceMethod;

import java.util.ArrayList;
Expand All @@ -23,6 +26,8 @@ public class HomeRepository {
private MutableLiveData<List<AppInfo>> mutableLiveDataAllAppList;
private MutableLiveData<Integer> selectedReadyToFreezeCount;



public synchronized static HomeRepository getInstance(Context context) {
if (homeRepository == null) {
homeRepository = new HomeRepository(context);
Expand All @@ -37,6 +42,7 @@ public synchronized static HomeRepository getInstance(Context context) {
private HomeRepository(Context context) {
this.context = context;


mutableLiveDataAllAppList = new MutableLiveData<>();
this.allApps = getAllAppList();
mutableLiveDataAllAppList.setValue(this.allApps);
Expand Down Expand Up @@ -65,13 +71,12 @@ public MutableLiveData<List<AppInfo>> getMutableLiveDataAllAppList() {
*/
public List<AppInfo> getFrozenAppList() {
List<AppInfo> appInfos = new ArrayList<>();
for (AppInfo a : appInfos) {
for (AppInfo a : this.allApps) {
if (a.isHidden()) {
appInfos.add(a);
}
}
return appInfos;

}


Expand Down Expand Up @@ -271,7 +276,7 @@ public MutableLiveData<List<AppInfo>> getMutableLiveDataUnFreezeAppListLiveNotIn
return newAppInfosLive;
}

public List<String> getFrozenAppListPackageName() {
public List<String> getFrozenAppListPackageNameFromPM() {
List<String> appInfos = new ArrayList<>();

PackageManager pm = context.getPackageManager();
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/com/tignioj/freezeapp/config/MyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
public class MyConfig {

//SHP文件Start=======================================================
public static final String SHP_FREEZE_APP_LIST_FOR_TIMER = "shp_freeze_app_list_for_timer";
//冻结列表的key
public static final String FREEZE_APP_LIST_FOR_TIMER = "freeze_app_list_for_timer";
public static final String PERSONAL_SHP_CONFIG_DB = "personal_shp_config_db";

//key
public static final String PERSONAL_SHP_CONFIG_KEY_IS_NIGHT_MODE = "personal_shp_config_key_is_night_mode";


//Shp文件End=============================================================
Expand All @@ -16,4 +17,6 @@ public class MyConfig {
public static final String BROADCAST_RECEIVER = "broadcast_receiver";
public static final String TAG_ERR = "tag_err";
//调试End=============================================


}
Loading

0 comments on commit 9d8512f

Please sign in to comment.