1.补充上次提交Launcher实现方法abstract setFragmentsDisableRefreshDataFlag
2.sharepreference config.xml存储是否刷新数据标识 3.推荐页禁止数据刷新代码补充 4.二级菜单按Home键和返回键更新刷新数据变量,home键重置FragmentManager
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.GET_TASKS"/>
|
||||
<uses-permission
|
||||
android:name="android.permission.INSTALL_PACKAGES"/>
|
||||
<uses-permission android:name="permission.REQUEST_DELETE_PACKAGES" />
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.view.View;
|
||||
import com.android.device.MediaStateChangeObserver;
|
||||
import com.android.eventbaus.MessageEvent;
|
||||
import com.android.util.LogUtils;
|
||||
import com.android.util.SharedPreferencesUtil;
|
||||
import com.ik.mboxlauncher.R;
|
||||
import com.ik.mboxlauncher.ui.base.FragmentActivity;
|
||||
import com.ik.mboxlauncher.ui.fragment.AppsFragment;
|
||||
@@ -73,6 +74,11 @@ public class CategoryActivity extends FragmentActivity {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFragmentsDisableRefreshDataFlag() {
|
||||
FragmentManager.getInstance().pressBackUpdateAllFragmentDisableRefreshDataFlag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void popBackStackFragment() {
|
||||
|
||||
@@ -94,9 +100,24 @@ public class CategoryActivity extends FragmentActivity {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
onResumeResetDisableFreshDataFlag();
|
||||
}
|
||||
|
||||
private void onResumeResetDisableFreshDataFlag() {
|
||||
if(SharedPreferencesUtil.getSharePrefrencesBoolean(this,SharedPreferencesUtil.CONFIG_RESET_DISABLE_FRESHDATA_FLAG)){
|
||||
SharedPreferencesUtil.setSharePrefrencesBoolean(this,SharedPreferencesUtil.CONFIG_RESET_DISABLE_FRESHDATA_FLAG,false);
|
||||
FragmentManager.getInstance().pressBackUpdateAllFragmentDisableRefreshDataFlag();
|
||||
if(currentFragment!=null){
|
||||
currentFragment.onResumeFragment(new MessageEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public void setPopWindow(int top, int bottom){
|
||||
// public void setPopWindow(int top, int bottom){
|
||||
// View view = this.getWindow().getDecorView();
|
||||
// view.layout(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
// view.setDrawingCacheEnabled(true);
|
||||
@@ -122,6 +143,7 @@ public class CategoryActivity extends FragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
FragmentManager.getInstance().destory();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@@ -135,10 +157,16 @@ public class CategoryActivity extends FragmentActivity {
|
||||
if(currentFragment.onKeyDown(keyCode,event)){
|
||||
return true;
|
||||
}else {
|
||||
currentFragment.resetDisableRefreshDataFlag();
|
||||
//currentFragment.resetDisableRefreshDataFlag();
|
||||
FragmentManager.getInstance().pressBackUpdateAllFragmentDisableRefreshDataFlag();
|
||||
return super.onKeyDown(keyCode,event);
|
||||
}
|
||||
}
|
||||
if(keyCode==KeyEvent.KEYCODE_HOME){
|
||||
LogUtils.loge("onKeyDown===>KEYCODE_HOME");
|
||||
currentFragment.onDetach();
|
||||
FragmentManager.getInstance().pressBackUpdateAllFragmentDisableRefreshDataFlag();
|
||||
}
|
||||
return super.onKeyDown(keyCode,event);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ik.mboxlauncher.ui;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.util.LogUtils;
|
||||
import com.ik.mboxlauncher.ui.base.BaseFragment;
|
||||
import com.ik.mboxlauncher.ui.base.NotifyInterface;
|
||||
import com.ik.mboxlauncher.ui.fragment.AppsFragment;
|
||||
@@ -55,9 +56,10 @@ public class FragmentManager {
|
||||
|
||||
public static void init(Context context, NotifyInterface notifyInterface){
|
||||
if(mInstance==null){
|
||||
LogUtils.loge("FragmentManager init null");
|
||||
mInstance = new FragmentManager(context,notifyInterface);
|
||||
}
|
||||
|
||||
LogUtils.loge("FragmentManager init end");
|
||||
}
|
||||
|
||||
public static FragmentManager getInstance(){
|
||||
@@ -82,6 +84,25 @@ public class FragmentManager {
|
||||
return null;
|
||||
}
|
||||
public void destory(){
|
||||
// 清空所有 Fragment 引用
|
||||
if(mAppsFragment != null) {
|
||||
mAppsFragment = null;
|
||||
}
|
||||
if(mLocalFragment != null) {
|
||||
mLocalFragment = null;
|
||||
}
|
||||
if(mMainFragment != null) {
|
||||
mMainFragment = null;
|
||||
}
|
||||
if(mMusicFragment != null) {
|
||||
mMusicFragment = null;
|
||||
}
|
||||
if(mRecommendFragment != null) {
|
||||
mRecommendFragment = null;
|
||||
}
|
||||
if(mVideoFragment != null) {
|
||||
mVideoFragment = null;
|
||||
}
|
||||
mInstance = null;
|
||||
}
|
||||
|
||||
@@ -91,4 +112,34 @@ public class FragmentManager {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
//按返回键 home键 等必须恢复 刷新数据处理
|
||||
public void pressBackUpdateAllFragmentDisableRefreshDataFlag(){
|
||||
if(mAppsFragment!=null){
|
||||
mAppsFragment.resetDisableRefreshDataFlag();
|
||||
}else {
|
||||
LogUtils.loge("mAppsFragment==null");
|
||||
}
|
||||
if(mLocalFragment!=null){
|
||||
mLocalFragment.resetDisableRefreshDataFlag();
|
||||
}else {
|
||||
LogUtils.loge("mLocalFragment==null");
|
||||
}
|
||||
if(mVideoFragment!=null){
|
||||
mVideoFragment.resetDisableRefreshDataFlag();
|
||||
}else {
|
||||
LogUtils.loge("mVideoFragment==null");
|
||||
}
|
||||
if(mMusicFragment!=null){
|
||||
mMusicFragment.resetDisableRefreshDataFlag();
|
||||
}else {
|
||||
LogUtils.loge("mMusicFragment==null");
|
||||
}
|
||||
if(mRecommendFragment!=null){
|
||||
mRecommendFragment.resetDisableRefreshDataFlag();
|
||||
}else {
|
||||
LogUtils.loge("mRecommendFragment==null");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.ik.mboxlauncher.ui;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
@@ -18,6 +20,7 @@ import com.android.nebulasdk.AppManager;
|
||||
import com.android.util.EventBusType;
|
||||
import com.android.util.LogManager;
|
||||
import com.android.util.LogUtils;
|
||||
import com.android.util.SharedPreferencesUtil;
|
||||
import com.ik.mboxlauncher.SystemService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -102,10 +105,39 @@ public class StartupBroadcast extends BroadcastReceiver {
|
||||
break;
|
||||
}
|
||||
EventBusUtils.postMsg(messageEvent);
|
||||
|
||||
if(!isTopAppPackage(context)){
|
||||
LogUtils.loge("three app activity on top of layer");
|
||||
boolean sharePrefrencesBoolean = SharedPreferencesUtil.getSharePrefrencesBoolean(context, SharedPreferencesUtil.CONFIG_RESET_DISABLE_FRESHDATA_FLAG);
|
||||
if(!sharePrefrencesBoolean){
|
||||
SharedPreferencesUtil.setSharePrefrencesBoolean(context,SharedPreferencesUtil.CONFIG_RESET_DISABLE_FRESHDATA_FLAG,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取顶层应用的包名
|
||||
* @param context 上下文
|
||||
* @return 顶层应用包名,如果获取失败返回 null
|
||||
*/
|
||||
public static boolean isTopAppPackage(Context context) {
|
||||
try {
|
||||
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
if (activityManager != null) {
|
||||
List<ActivityManager.RunningTaskInfo> runningTasks = activityManager.getRunningTasks(1);
|
||||
if (runningTasks != null && !runningTasks.isEmpty()) {
|
||||
ActivityManager.RunningTaskInfo taskInfo = runningTasks.get(0);
|
||||
ComponentName topActivity = taskInfo.topActivity;
|
||||
LogUtils.loge("topActivity packagename: " + topActivity.getPackageName());
|
||||
return topActivity.getPackageName().equalsIgnoreCase(context.getPackageName());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.loge("Error getting top app package name: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定包名应用的Launcher Activity信息
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.eventbaus.MessageEvent;
|
||||
import com.android.util.LogUtils;
|
||||
|
||||
/** A fragment which slides when it is entering/exiting. */
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
@@ -38,6 +39,8 @@ public abstract class BaseFragment extends Fragment {
|
||||
protected static final int MODEL_NORMAL = 0x00;
|
||||
protected static final int MODEL_CUSTOM = 0x01;
|
||||
protected int cuttentModel=MODEL_NORMAL;
|
||||
private View view;
|
||||
|
||||
public NotifyInterface getNotifyInterface() {
|
||||
return notifyInterface;
|
||||
}
|
||||
@@ -110,7 +113,12 @@ public abstract class BaseFragment extends Fragment {
|
||||
@Override
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(getLayoutResourceId(), container, false);
|
||||
if(view==null){
|
||||
view = inflater.inflate(getLayoutResourceId(), container, false);
|
||||
LogUtils.loge("onCreateView()==>view=null"+getClass().getSimpleName());
|
||||
}else {
|
||||
LogUtils.loge("onCreateView()==>view!=null"+getClass().getSimpleName());
|
||||
}
|
||||
initView( view);
|
||||
handler.post(inidataRunnable);
|
||||
return view;
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.app.FragmentTransaction;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.eventbaus.MessageEvent;
|
||||
import com.android.util.LogUtils;
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,16 +43,19 @@ public abstract class FragmentActivity extends BaseActivity implements NotifyInt
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getlayoutId());
|
||||
if (savedInstanceState == null) {
|
||||
LogUtils.loge("savedInstanceState===>null");
|
||||
showInitialFragment();
|
||||
} else {
|
||||
mShowInitialFragment = false;
|
||||
LogUtils.loge("savedInstanceState===>not null");
|
||||
}
|
||||
mFragmentManager = getFragmentManager();
|
||||
initView();
|
||||
initData();
|
||||
// Show initial fragment only when the saved state is not restored, because the last
|
||||
// fragment is restored if savesInstanceState is not null.
|
||||
if (savedInstanceState == null) {
|
||||
showInitialFragment();
|
||||
} else {
|
||||
mShowInitialFragment = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -95,10 +99,11 @@ public abstract class FragmentActivity extends BaseActivity implements NotifyInt
|
||||
protected FragmentTransaction showFragment(Fragment fragment, boolean addToBackStack) {
|
||||
currentFragment = (BaseFragment) fragment;
|
||||
currentFragment.setNotifyInterface(this);
|
||||
LogUtils.loge("showFragment===>mFragmentManager1");
|
||||
if (mFragmentManager == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LogUtils.loge("showFragment===>mFragmentManager2");
|
||||
FragmentTransaction ft = mFragmentManager.beginTransaction();
|
||||
// ft.setCustomAnimations(
|
||||
// R.anim.slide_left_in,
|
||||
@@ -128,6 +133,7 @@ public abstract class FragmentActivity extends BaseActivity implements NotifyInt
|
||||
}
|
||||
if (!fragment.isAdded()) {
|
||||
ft.replace(getFramlayoutId(), fragment, tag).commit();
|
||||
LogUtils.loge("showFragment===>replace");
|
||||
} else {
|
||||
ft.show(fragment).commit();
|
||||
}
|
||||
@@ -139,7 +145,9 @@ public abstract class FragmentActivity extends BaseActivity implements NotifyInt
|
||||
@Override
|
||||
public void onMessageEvent(MessageEvent event) {
|
||||
super.onMessageEvent(event);
|
||||
// if(MessageEvent.ACTION_UPADATE_DATA_SOURCE.equals(event.action)){
|
||||
if(MessageEvent.ACTION_UPADATE_APPS_SOURCE.equals(event.action)){
|
||||
setFragmentsDisableRefreshDataFlag();
|
||||
}
|
||||
// 更新UI
|
||||
if(currentFragment!=null){
|
||||
currentFragment.onResumeFragment(event);
|
||||
@@ -147,7 +155,7 @@ public abstract class FragmentActivity extends BaseActivity implements NotifyInt
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public abstract void setFragmentsDisableRefreshDataFlag();
|
||||
protected boolean isShowDisplay() {
|
||||
int count = mFragmentManager.getBackStackEntryCount();
|
||||
if (count > 0) {
|
||||
|
||||
@@ -161,6 +161,7 @@ public class RecommendFragment extends CategoryFragment {
|
||||
@Override
|
||||
public void onResumeFragment(MessageEvent event) {
|
||||
super.onResumeFragment(event);
|
||||
disableFreshData=false;
|
||||
loadAppInfoByCategory(AppManager.CATEGORY_RECOMMEND);//重新加载数据
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,7 @@ public class VideoFragment extends CategoryFragment {
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
LogUtils.loge("VideoFragment===>initData()");
|
||||
loadAppInfoByCategory(AppManager.CATEGORY_VIDEO);
|
||||
}
|
||||
|
||||
@@ -160,6 +161,7 @@ public class VideoFragment extends CategoryFragment {
|
||||
@Override
|
||||
public void onResumeFragment(MessageEvent event) {
|
||||
super.onResumeFragment(event);
|
||||
LogUtils.loge("VideoFragment===>onResumeFragment()");
|
||||
disableFreshData=false;
|
||||
loadAppInfoByCategory(AppManager.CATEGORY_VIDEO);//重新加载数据
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class SharedPreferencesUtil {
|
||||
|
||||
public static final String CONFIG_LOCAL_BOOKMARK_APP="config_local_bookmark_app";//本地配置 收藏夹
|
||||
public static final String CONFIG_NET_DEFEND_BOOKMARK_APP="config_net_defend_bookmark_app";//网络隔离 收藏夹
|
||||
|
||||
public static final String CONFIG_RESET_DISABLE_FRESHDATA_FLAG="config_reset_disable_freshdata_flag";//重置设备禁止刷新数据为true可刷新
|
||||
public static String getSharePrefrencesString(Context context,String key){
|
||||
SharedPreferences sharedPreferences=context.getSharedPreferences(SHARE_NAME,0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user