管控功能移植

This commit is contained in:
2019-12-30 17:30:05 +08:00
parent ce9ca54dcb
commit 0f23821d20
331 changed files with 1747 additions and 35782 deletions

View File

@@ -8,7 +8,6 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import com.mjsheng.myappstore.bean.AppUpdateInfo;
import com.mjsheng.myappstore.bean.LocalAppInfo;

View File

@@ -0,0 +1,132 @@
package com.mjsheng.myappstore.utils;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Looper;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import cn.jpush.android.api.JPushInterface;
public class ExampleUtil {
public static final String PREFS_NAME = "JPUSH_EXAMPLE";
public static final String PREFS_DAYS = "JPUSH_EXAMPLE_DAYS";
public static final String PREFS_START_TIME = "PREFS_START_TIME";
public static final String PREFS_END_TIME = "PREFS_END_TIME";
public static final String KEY_APP_KEY = "JPUSH_APPKEY";
public static boolean isEmpty(String s) {
if (null == s)
return true;
if (s.length() == 0)
return true;
if (s.trim().length() == 0)
return true;
return false;
}
/**
* 只能以 “+” 或者 数字开头;后面的内容只能包含 “-” 和 数字。
* */
private final static String MOBILE_NUMBER_CHARS = "^[+0-9][-0-9]{1,}$";
public static boolean isValidMobileNumber(String s) {
if(TextUtils.isEmpty(s)) return true;
Pattern p = Pattern.compile(MOBILE_NUMBER_CHARS);
Matcher m = p.matcher(s);
return m.matches();
}
// 校验Tag Alias 只能是数字,英文字母和中文
public static boolean isValidTagAndAlias(String s) {
Pattern p = Pattern.compile("^[\u4E00-\u9FA50-9a-zA-Z_!@#$&*+=.|]+$");
Matcher m = p.matcher(s);
return m.matches();
}
// 取得AppKey
public static String getAppKey(Context context) {
Bundle metaData = null;
String appKey = null;
try {
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
context.getPackageName(), PackageManager.GET_META_DATA);
if (null != ai)
metaData = ai.metaData;
if (null != metaData) {
appKey = metaData.getString(KEY_APP_KEY);
if ((null == appKey) || appKey.length() != 24) {
appKey = null;
}
}
} catch (NameNotFoundException e) {
}
return appKey;
}
// 取得版本号
public static String GetVersion(Context context) {
try {
PackageInfo manager = context.getPackageManager().getPackageInfo(
context.getPackageName(), 0);
return manager.versionName;
} catch (NameNotFoundException e) {
return "Unknown";
}
}
public static void showToast(final String toast, final Context context)
{
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
// Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
Looper.loop();
}
}).start();
}
public static boolean isConnected(Context context) {
ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = conn.getActiveNetworkInfo();
return (info != null && info.isConnected());
}
public static String getImei(Context context, String imei) {
String ret = null;
try {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
ret = telephonyManager.getDeviceId();
} catch (Exception e) {
Logger.e(ExampleUtil.class.getSimpleName(), e.getMessage());
}
if (isReadableASCII(ret)){
return ret;
} else {
return imei;
}
}
private static boolean isReadableASCII(CharSequence string){
if (TextUtils.isEmpty(string)) return false;
try {
Pattern p = Pattern.compile("[\\x20-\\x7E]+");
return p.matcher(string).matches();
} catch (Throwable e){
return true;
}
}
public static String getDeviceId(Context context) {
return JPushInterface.getUdid(context);
}
}

View File

@@ -0,0 +1,40 @@
package com.mjsheng.myappstore.utils;
import android.util.Log;
/**
* Created by efan on 2017/4/13.
*/
public class Logger {
//设为false关闭日志
private static final boolean LOG_ENABLE = true;
public static void i(String tag, String msg){
if (LOG_ENABLE){
Log.i(tag, msg);
}
}
public static void v(String tag, String msg){
if (LOG_ENABLE){
Log.v(tag, msg);
}
}
public static void d(String tag, String msg){
if (LOG_ENABLE){
Log.d(tag, msg);
}
}
public static void w(String tag, String msg){
if (LOG_ENABLE){
Log.w(tag, msg);
}
}
public static void e(String tag, String msg){
if (LOG_ENABLE){
Log.e(tag, msg);
}
}
}

View File

@@ -1,90 +0,0 @@
package com.mjsheng.myappstore.utils;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.LinearInterpolator;
import android.view.animation.ScaleAnimation;
import com.mjsheng.myappstore.callback.GalleryItemClickAnimationListener;
public class ScaleAnimEffect {
private static ScaleAnimEffect mInstance;
private float fromXScale;
private float toXScale;
private float fromYScale;
private float toYScale;
private long duration;
public static ScaleAnimEffect getInstance() {
if (null == mInstance) {
mInstance = new ScaleAnimEffect();
}
return mInstance;
}
/**
* 设置缩放参数
*
* @param fromXScale 初始X轴缩放比
* @param toXScale 目标X轴缩放比
* @param fromYScale 初始Y轴缩放比
* @param toYScale 目标Y轴缩放比
* @param duration 动画持续时间
*/
public void setAttributs(float fromXScale, float toXScale,
float fromYScale, float toYScale, long duration) {
this.fromXScale = fromXScale;
this.fromYScale = fromYScale;
this.toXScale = toXScale;
this.toYScale = toYScale;
this.duration = duration;
}
public Animation createAnimation() {
ScaleAnimation anim = new ScaleAnimation(fromXScale, toXScale,
fromYScale, toYScale, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
anim.setInterpolator(new LinearInterpolator());
anim.setDuration(duration);
return anim;
}
public Animation alphaAnimation(float fromAlpha, float toAlpha,
long duration, long offsetDuration) {
AlphaAnimation anim = new AlphaAnimation(fromAlpha, toAlpha);
anim.setDuration(duration);
anim.setStartOffset(offsetDuration);
anim.setInterpolator(new AccelerateInterpolator());
return anim;
}
public void startAnimation(Animation animation, View view,
final GalleryItemClickAnimationListener callback) {
if (view != null) {
if (callback != null) {
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
}
@Override
public void onAnimationEnd(Animation arg0) {
if (callback != null) {
callback.onAnimationEnd();
}
}
});
}
view.startAnimation(animation);
}
}
}

View File

@@ -3,7 +3,7 @@ package com.mjsheng.myappstore.utils;
import android.app.ActivityManager;
import android.content.Context;
import com.mjsheng.myappstore.base.MyApplication;
import com.mjsheng.myappstore.MyApplication;
public class ServiceAliveUtils {

View File

@@ -0,0 +1,65 @@
package com.mjsheng.myappstore.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
import com.mjsheng.myappstore.BuildConfig;
/**
* Created by haoge on 2017/3/2.
*/
public class ToastUtil {
static Handler mainHandler = new Handler(Looper.getMainLooper());
static Toast toast;
@SuppressLint("ShowToast")
public static void init(Context context) {
toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
debugToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
}
public static void show(final String msg) {
mainHandler.post(new Runnable() {
@Override
public void run() {
if (toast != null) {
toast.setText(msg);
toast.show();
}
}
});
}
// public static void showInCenter(String msg) {
// mainHandler.post(() -> {
// if (toast != null) {
// toast.setGravity(Gravity.CENTER, 0, 0);
// toast.setText(msg);
// toast.show();
// }
// });
// }
static Handler debugHandler = new Handler(Looper.getMainLooper());
static Toast debugToast;
public static void debugShow(final String msg) {
mainHandler.post(new Runnable() {
@Override
public void run() {
if (BuildConfig.LOG_DEBUG) {
if (toast != null) {
toast.setText(msg);
toast.show();
}
}
}
});
}
}

View File

@@ -13,6 +13,12 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
@@ -20,7 +26,6 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.Settings;
import android.support.annotation.RequiresPermission;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
@@ -28,19 +33,16 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.base.MyApplication;
import com.mjsheng.myappstore.comm.CommonDatas;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.mjsheng.myappstore.MyApplication;
import java.io.FileReader;
import java.io.InputStreamReader;
@@ -53,12 +55,9 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import okhttp3.Call;
import okhttp3.Response;
import static android.Manifest.permission.READ_PHONE_STATE;
import java.util.Map;
public class Utils {
@@ -91,9 +90,6 @@ public class Utils {
public static final String ACTION_PACKAGE_REMOVED = PACKAGE + "PACKAGE_REMOVED"; // 卸载应用
public static final String ACTION_PACKAGE_ADDED = PACKAGE + "PACKAGE_ADDED"; // 安装应用
public static int[] babyImage = {R.drawable.language, R.drawable.habit, R.drawable.knowledge, R.drawable.security, R.drawable.promotion};
public static int[] childImage = {R.drawable.yuwen, R.drawable.shuxue, R.drawable.yingyu, R.drawable.qingshang, R.drawable.yishu, R.drawable.promotion};
public static int[] youngImage = {R.drawable.yuwen, R.drawable.shuxue, R.drawable.yingyu, R.drawable.promotion};
// 学习日志上传标识
public static final String APP_LRARNLOG = "com.colorflykids.alarm";
// 学习日志下载标识
@@ -728,6 +724,66 @@ public class Utils {
return sdf.format(date);
}
public static String getSn() {
return Build.SERIAL;
}
public static Bitmap createQRImage(String content, int widthPix, int heightPix) {
try {
// if (content == null || "".equals(content)) {
// return false;
// }
//配置参数
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
//容错级别
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
//设置空白边距的宽度
hints.put(EncodeHintType.MARGIN, 1); //default is 4
// 图像数据转换,使用了矩阵转换
BitMatrix bitMatrix = null;
try {
bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix,
heightPix, hints);
} catch (WriterException e) {
e.printStackTrace();
}
int[] pixels = new int[widthPix * heightPix];
// 下面这里按照二维码的算法,逐个生成二维码的图片,
// 两个for循环是图片横列扫描的结果
for (int y = 0; y < heightPix; y++) {
for (int x = 0; x < widthPix; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * widthPix + x] = 0xff000000;
} else {
pixels[y * widthPix + x] = 0xffffffff;
}
}
}
// 生成二维码图片的格式,使用ARGB_8888
Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);
//
// if (logoBm != null) {
// bitmap = addLogo(bitmap, logoBm);
// }
//必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的,
// 内存消耗巨大!
return bitmap;
// return bitmap != null && bitmap.compress(Bitmap.CompressFormat.JPEG, 100);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//判断是否为系统应用
public static boolean isSystemApp(Context context, String pkgName) {
boolean isSystemApp = false;
@@ -749,4 +805,56 @@ public class Utils {
}
return isSystemApp;
}
public static Bitmap getRoundedBitmap(Bitmap mBitmap, Context context) {
Bitmap bgBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888);
Bitmap mask = BitmapFactory.decodeResource(context.getResources(), R.drawable.mask);
int width = mask.getWidth();
int height = mask.getHeight();
Bitmap bitmapScale = Bitmap.createScaledBitmap(mBitmap, width, height, true);
// Palette p = Palette.from(mBitmap).generate();
// Palette.Swatch vibrant = p.getVibrantSwatch();//有活力的
// int color = vibrant.getRgb(); //样本中的像素数量
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas();
Paint paint = new Paint();
canvas.setBitmap(result);
// canvas.drawColor(color);
canvas.drawBitmap(mask, 0, 0, paint);
// paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmapScale, 0, 0, paint);
// return result;
Bitmap result2 = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas2 = new Canvas();
Paint paint2 = new Paint();
canvas2.setBitmap(result2);
canvas2.drawBitmap(mask, 0, 0, paint2);
paint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas2.drawBitmap(result, 0, 0, paint2);
return result2;
// Canvas mCanvas = new Canvas();
// mCanvas.setBitmap(bgBitmap);
// Paint mPaint = new Paint();
// RectF mRectM = new RectF(scaleM, scaleM, mBitmap.getWidth() - scaleM, mBitmap.getHeight() - scaleM); //设置剪裁圆角的区域
// Rect mRect = new Rect(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
// RectF mRectF = mRectM;
//
// float roundPx = 15; //圆角半径
// mPaint.setAntiAlias(true);
// //Log.d("wy"+TAG,"mBitmap.getWidth()="+mBitmap.getWidth()+", mBitmap.getHeight()="+mBitmap.getHeight());
// mCanvas.drawRoundRect(mRectF, roundPx, roundPx, mPaint);
// mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
// mCanvas.drawBitmap(mBitmap, mRect, mRect, mPaint);
// return bgBitmap;
}
}

View File

@@ -44,7 +44,6 @@ public class NotificationDownloadCreator implements DownloadNotifier {
builder = new NotificationCompat.Builder(activity);
builder.setProgress(100, 0, false)
.setSmallIcon(activity.getApplicationInfo().icon)
.setLargeIcon(BitmapFactory.decodeResource( activity.getResources(), R.drawable.ic_launcher))
.setAutoCancel(false)
.setContentText("下载中...")
.setContentText("正在下载")