This commit is contained in:
wangcongtao
2020-10-20 10:03:11 +08:00
parent 7cc699e251
commit 2ecf7d2a48
16 changed files with 184 additions and 116 deletions

View File

@@ -1,12 +1,11 @@
package com.mogo.module.apps;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.text.TextUtils;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.module.common.utils.CarSeries;
import com.mogo.utils.FileUtils;
import java.io.BufferedReader;
import java.io.File;
@@ -22,34 +21,28 @@ import java.util.List;
* <p>
* 过滤 app
*/
public class AppFilterImpl implements AppFilter {
public class AppFilterImpl {
private final Context mContext;
private List< String > mFilterPackages;
private static List< String > mFilterPackages;
private static String sExternalPath = "/system/etc/packagesFilterList.txt";
private static List< String > sExternalConfigPackages = new ArrayList<>();
public AppFilterImpl( Context context ) {
mContext = context;
static {
if ( CarSeries.getSeries() != CarSeries.CAR_SERIES_F80X ) {
final String[] values = context.getResources().getStringArray( R.array.module_apps_array_filter_packages );
final String[] values = AbsMogoApplication.getApp().getResources().getStringArray( R.array.module_apps_array_filter_packages );
if ( values != null ) {
mFilterPackages = new ArrayList( Arrays.asList( values ) );
}
} else {
final String[] values = context.getResources().getStringArray( R.array.module_apps_array_filter_packages_f );
final String[] values = AbsMogoApplication.getApp().getResources().getStringArray( R.array.module_apps_array_filter_packages_f );
if ( values != null ) {
mFilterPackages = new ArrayList( Arrays.asList( values ) );
}
}
}
@Override
public boolean filter( PackageInfo packageInfo ) {
// if ( isSystemApp( packageInfo ) ) {
// return true;
// }
public static boolean sFilter( PackageInfo packageInfo ) {
if ( isInExternalFilter( packageInfo ) ) {
return true;
}
@@ -62,19 +55,19 @@ public class AppFilterImpl implements AppFilter {
return false;
}
private boolean isSystemApp( PackageInfo packageInfo ) {
private static boolean isSystemApp( PackageInfo packageInfo ) {
return ( packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM ) != 0;
}
private boolean isFilterPackages( PackageInfo packageInfo ) {
private static boolean isFilterPackages( PackageInfo packageInfo ) {
return mFilterPackages.contains( packageInfo.packageName );
}
private boolean noLaunchIntent( PackageInfo packageInfo ) {
return mContext.getPackageManager().getLaunchIntentForPackage( packageInfo.packageName ) == null;
private static boolean noLaunchIntent( PackageInfo packageInfo ) {
return AbsMogoApplication.getApp().getPackageManager().getLaunchIntentForPackage( packageInfo.packageName ) == null;
}
private boolean isInExternalFilter( PackageInfo packageInfo ) {
private static boolean isInExternalFilter( PackageInfo packageInfo ) {
return sExternalConfigPackages.contains( packageInfo.packageName );
}

View File

@@ -2,19 +2,17 @@ package com.mogo.module.apps;
import android.os.Bundle;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.commons.utils.ViewPagerSpeedScroller;
import com.mogo.module.apps.model.AppInfo;
import com.mogo.module.apps.view.GridViewPagerScroller;
import com.mogo.module.apps.view.PagerSlidingTabStripV2;
import com.mogo.utils.logger.Logger;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
@@ -36,8 +34,6 @@ public class AppsFragment extends MvpFragment< AppsView, AppsPresenter > impleme
private View mLoadingView;
private PagerSlidingTabStripV2 mIndicator;
private GridViewPagerScroller mScroller;
@Override
protected int getLayoutId() {
return R.layout.module_apps_fragment_apps;
@@ -58,19 +54,7 @@ public class AppsFragment extends MvpFragment< AppsView, AppsPresenter > impleme
mIndicator = findViewById( R.id.module_apps_id_indicator );
mIndicator.setOpenPadding( true );
try {
Field mField = ViewPager.class.getDeclaredField("mScroller");
mField.setAccessible(true);
mScroller = new GridViewPagerScroller(getContext(), new DecelerateInterpolator());
mField.set(mAppsPager, mScroller);
mScroller.setDuration(160);
Field field = ViewPager.class.getDeclaredField("mTouchSlop");
field.setAccessible(true);
field.setInt(mAppsPager, 4);
} catch (Exception e) {
e.printStackTrace();
}
ViewPagerSpeedScroller.attach(getContext(), mAppsPager, 1000);
}
@NonNull
@@ -109,34 +93,6 @@ public class AppsFragment extends MvpFragment< AppsView, AppsPresenter > impleme
}
}
// @Override
// public Animation onCreateAnimation( int transit, boolean enter, int nextAnim ) {
// TranslateAnimation animation = null;
// if ( transit == FragmentTransaction.TRANSIT_FRAGMENT_OPEN ) {
// if ( enter ) {
// animation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
// Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0 );
// } else {
// animation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1,
// Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0 );
// }
// } else if ( FragmentTransaction.TRANSIT_FRAGMENT_CLOSE == transit ) {
// if ( enter ) {
// animation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 0,
// Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0 );
// } else {
// animation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1,
// Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0 );
// }
// }
// if ( animation == null ) {
// animation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
// Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1 );
// }
// animation.setDuration( 300 );
// return animation;
// }
@Override
public void onDestroyView() {
super.onDestroyView();

View File

@@ -6,7 +6,6 @@ import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import com.mogo.module.apps.AppFilter;
import com.mogo.module.apps.AppFilterImpl;
import com.mogo.module.apps.AppsConst;
import com.mogo.module.apps.AppsListChangedLiveData;
@@ -31,8 +30,6 @@ public class AppsModel {
private static volatile AppsModel sInstance;
private Context mContext;
private AppFilter mAppFilter;
private Map< Integer, List< AppInfo > > mPagedApps = new HashMap<>();
private AppsModel( Context context ) {
@@ -58,7 +55,6 @@ public class AppsModel {
mPagedApps.clear();
}
mContext = null;
mAppFilter = null;
sInstance = null;
}
@@ -69,9 +65,6 @@ public class AppsModel {
}
return;
}
if ( mAppFilter == null ) {
mAppFilter = new AppFilterImpl( mContext );
}
try {
AppFilterImpl.loadExternalFilterPackagesList();
} catch ( Exception e ) {
@@ -83,7 +76,7 @@ public class AppsModel {
int counter = 0;
for ( int i = 0; i < packages.size(); ++i ) {
PackageInfo packageInfo = packages.get( i );
if ( mAppFilter.filter( packageInfo ) ) {
if ( AppFilterImpl.sFilter( packageInfo ) ) {
continue;
}
int page = counter++ / AppsConst.TOTAL_SIZE_EACH_PAGE;
@@ -118,13 +111,10 @@ public class AppsModel {
if ( mPagedApps == null || mPagedApps.isEmpty() ) {
return;
}
if ( mAppFilter == null ) {
mAppFilter = new AppFilterImpl( mContext );
}
try {
final PackageManager packageManager = mContext.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageInfo( packageName, 0 );
if ( !mAppFilter.filter( packageInfo ) ) {
if ( !AppFilterImpl.sFilter( packageInfo ) ) {
String appName = getApplicationName( packageManager, packageInfo );
String versionName = packageInfo.versionName;
int versionCode = packageInfo.versionCode;
@@ -157,7 +147,7 @@ public class AppsModel {
return 0;
} else {
if ( mPagedApps.get( totalPages - 1 ) == null
|| mPagedApps.get( totalPages - 1 ).size() == AppsConst.TOTAL_SIZE_EACH_PAGE ) {
|| mPagedApps.get( totalPages - 1 ).size() == AppsConst.TOTAL_SIZE_EACH_PAGE ) {
return totalPages;
} else {
return totalPages - 1;