package com.tejia.lijin.app.util;
|
|
import android.app.Activity;
|
import android.app.ActivityManager;
|
import android.app.Application;
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageManager;
|
import android.content.res.AssetFileDescriptor;
|
import android.content.res.AssetManager;
|
import android.content.res.Resources;
|
import android.graphics.Bitmap;
|
import android.graphics.Color;
|
import android.graphics.drawable.GradientDrawable;
|
import android.media.MediaPlayer;
|
import android.net.Uri;
|
import android.os.Build;
|
import android.provider.Settings;
|
import androidx.annotation.NonNull;
|
import com.google.android.material.appbar.AppBarLayout;
|
import androidx.core.app.NotificationManagerCompat;
|
import android.util.DisplayMetrics;
|
import android.view.Display;
|
import android.view.View;
|
import android.view.WindowManager;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.alibaba.baichuan.android.trade.model.AlibcShowParams;
|
import com.alibaba.baichuan.android.trade.model.OpenType;
|
import com.app.hubert.guide.util.ScreenUtils;
|
import com.coloros.mcssdk.PushManager;
|
import com.google.gson.Gson;
|
import com.huawei.android.hms.agent.HMSAgent;
|
import com.huawei.android.hms.agent.push.handler.EnableReceiveNormalMsgHandler;
|
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
|
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
|
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
|
import com.umeng.commonsdk.UMConfigure;
|
import com.vivo.push.PushClient;
|
import com.wpc.library.util.common.StringUtils;
|
import com.xiaomi.mipush.sdk.MiPushClient;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.BuXinConstant;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.ShoppingApplication;
|
import com.tejia.lijin.app.callBack.GeneralCallback;
|
import com.tejia.lijin.app.entity.EntityFather;
|
import com.tejia.lijin.app.entity.GoodsDetail;
|
import com.tejia.lijin.app.entity.recommendinfo.RecommendGoodsInfo;
|
import com.tejia.lijin.app.entity.share.SingleGoodsShareInfo;
|
import com.tejia.lijin.app.ui.BlankBaiChuanActivity31;
|
import com.tejia.lijin.app.ui.dialog.AddZFBInfoDialog2;
|
import com.tejia.lijin.app.ui.dialog.CopyLinkDialog;
|
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
|
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
|
import com.tejia.lijin.app.ui.main.MainActivity;
|
import com.tejia.lijin.app.ui.recommend.GoodsDetailActivityTB;
|
import com.tejia.lijin.app.ui.recommend.SearchResultActivity;
|
import com.tejia.lijin.app.ui.recommend.ShareGoodsImageActivity31;
|
import com.tejia.lijin.app.util.umengCustomEvent.MainCustomEvent;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
|
import org.apache.http.Header;
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
import java.io.IOException;
|
import java.lang.reflect.Method;
|
import java.util.ArrayList;
|
import java.util.Iterator;
|
import java.util.List;
|
|
public class ToolUtil {
|
private static final String EXTRA_APP_PACKAGE = "android.provider.extra.APP_PACKAGE";
|
public static String OPPOPushInfo = "";//oppo推送内容
|
public static String VIVOPushInfo = "";//vivo推送内容
|
|
/**
|
* 设置 Shaped
|
*
|
* @param radius 圆角角度
|
* @param stroke 边框颜色
|
* @param textcolor 文字颜色
|
* @param text 文字
|
* @param view 控件
|
*/
|
public static void setShape_frame(Context mContext, int radius, String stroke, String textcolor, String text, TextView view) {
|
//动态改变shape
|
GradientDrawable shape = new GradientDrawable();
|
shape.setCornerRadius(ScreenUtils.dp2px(mContext, radius));//4
|
//设置颜色
|
shape.setStroke(ScreenUtils.dp2px(mContext, 1), Color.parseColor(stroke));//"#ffe5005c"
|
view.setBackground(shape);
|
view.setText(text);//"并夕夕"
|
view.setTextColor(Color.parseColor(textcolor));//"#fff50008"
|
}
|
|
/**
|
* 设置 Shaped
|
* 只提供 背景
|
*
|
* @param radius 圆角角度
|
* @param bgcolor 背景颜色
|
* @param view 控件
|
*/
|
public static void setShape_bg(Context mContext, int radius, String bgcolor, View view) {
|
//动态改变shape
|
GradientDrawable shape = new GradientDrawable();
|
shape.setCornerRadius(ScreenUtils.dp2px(mContext, radius));//4
|
//设置颜色
|
shape.setColor(Color.parseColor(bgcolor));
|
// shape.setStroke(ScreenUtils.dp2px(mContext, 1), Color.parseColor(stroke));//"#ffe5005c"
|
view.setBackground(shape);
|
}
|
|
/**
|
* 传入文字 Toast
|
*/
|
public static void showToast(Context context, String text) {
|
if (context != null) {
|
Toast mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
|
// mToast.setGravity(Gravity.CENTER, 0, 0);
|
mToast.show();
|
}
|
}
|
|
/**
|
* 设置通用单按钮提示弹窗
|
*
|
* @param mTitle 弹窗标题
|
* @param mMesseag 弹窗内容
|
* @param mBuName 弹窗按钮名字
|
* @param mCallback 通用接口回调
|
*/
|
public static Dialog setGeneralPop(Context mContext, String mTitle, String mMesseag, String mBuName, final GeneralCallback mCallback) {
|
AddZFBInfoDialog2.Builder builder = new AddZFBInfoDialog2.Builder(mContext);
|
builder
|
.setTitle(mTitle)
|
.setMessage(mMesseag)
|
.setPositiveButton(mBuName, new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
mCallback.onSuccess();
|
dialog.dismiss();
|
}
|
})
|
.setNegativeButton("", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
mCallback.onError();
|
dialog.dismiss();
|
}
|
});
|
Dialog dialog = builder.create();
|
dialog.show();
|
return dialog;
|
}
|
|
|
public static Dialog setGeneralPop(Context mContext, String mTitle, String mMesseag, String mBuName, int aligin, final GeneralCallback mCallback) {
|
AddZFBInfoDialog2.Builder builder = new AddZFBInfoDialog2.Builder(mContext);
|
builder
|
.setTitle(mTitle)
|
.setMessage(mMesseag)
|
.setMessageTextAligin(aligin)
|
.setPositiveButton(mBuName, new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
mCallback.onSuccess();
|
dialog.dismiss();
|
}
|
})
|
.setNegativeButton("", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
mCallback.onError();
|
dialog.dismiss();
|
}
|
});
|
Dialog dialog = builder.create();
|
dialog.show();
|
return dialog;
|
}
|
|
|
public static Dialog setGeneralPop(Context mContext, String mTitle, String mMesseag, String positiveName, String negativeName, final GeneralCallback mCallback) {
|
AddZFBInfoDialog2.Builder builder = new AddZFBInfoDialog2.Builder(mContext);
|
builder
|
.setTitle(mTitle)
|
.setMessage(mMesseag)
|
.setPositiveButton(positiveName, new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
mCallback.onSuccess();
|
dialog.dismiss();
|
}
|
})
|
.setNegativeButton(negativeName, new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
mCallback.onError();
|
dialog.dismiss();
|
}
|
});
|
Dialog dialog = builder.create();
|
dialog.show();
|
return dialog;
|
}
|
|
/**
|
* 重要提示
|
*
|
* @param mContext
|
* @param mTitle
|
* @param mMesseag
|
* @param mBuName
|
* @param mCallback
|
* @return
|
*/
|
public static Dialog setGeneralImportantPop(Context mContext, String mTitle, String mMesseag, String mBuName, final GeneralCallback mCallback) {
|
AddZFBInfoDialog2.Builder builder = new AddZFBInfoDialog2.Builder(mContext);
|
builder
|
.setTitle(mTitle)
|
.setMessageBold(true)
|
.setFontRate(1.1f)
|
.setMessageTextAligin(AddZFBInfoDialog2.Builder.TEXT_ALIGIN_MIDDLE)
|
.setMessage(mMesseag)
|
.setPositiveButton(mBuName, new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
mCallback.onSuccess();
|
dialog.dismiss();
|
}
|
})
|
.setNegativeButton("", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
mCallback.onError();
|
dialog.dismiss();
|
}
|
});
|
Dialog dialog = builder.create();
|
dialog.show();
|
return dialog;
|
}
|
|
/**
|
* 获取是否存在NavigationBar
|
*
|
* @param context
|
* @return
|
*/
|
public static boolean checkDeviceHasNavigationBar(Context context) {
|
boolean hasNavigationBar = false;
|
Resources rs = context.getResources();
|
int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
|
if (id > 0) {
|
hasNavigationBar = rs.getBoolean(id);
|
}
|
try {
|
Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
|
Method m = systemPropertiesClass.getMethod("get", String.class);
|
String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
|
if ("1".equals(navBarOverride)) {
|
hasNavigationBar = false;
|
} else if ("0".equals(navBarOverride)) {
|
hasNavigationBar = true;
|
}
|
} catch (Exception e) {
|
|
}
|
return hasNavigationBar;
|
}
|
|
/**
|
* 获取虚拟功能键高度
|
*
|
* @param context
|
* @return
|
*/
|
public static int getVirtualBarHeigh(Context context) {
|
int vh = 0;
|
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
Display display = windowManager.getDefaultDisplay();
|
DisplayMetrics dm = new DisplayMetrics();
|
try {
|
@SuppressWarnings("rawtypes")
|
Class c = Class.forName("android.view.Display");
|
@SuppressWarnings("unchecked")
|
Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
|
method.invoke(display, dm);
|
vh = dm.heightPixels - windowManager.getDefaultDisplay().getHeight();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return vh;
|
}
|
|
/**
|
* Created by Administrator
|
* 获得进程名字的方法
|
*/
|
public static String getProcessName(Context cxt, int pid) {
|
if (cxt == null) {
|
return null;
|
}
|
//获取ActivityManager对象
|
ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
|
//在运行的进程的
|
List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
|
if (runningApps == null) {
|
return null;
|
}
|
for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) {
|
if (procInfo.pid == pid) {
|
return procInfo.processName;
|
}
|
}
|
return null;
|
}
|
|
/**
|
* 打开推送内容
|
*
|
* @param context 上下文
|
* @param json 传入内容
|
*/
|
public static void startActivity(Context context, Activity activity, String json) {
|
try {
|
JSONObject jsonObject = new JSONObject(json);
|
String cClass = jsonObject.optString("activity");//miPushUrl
|
String url1 = jsonObject.optString("webUrl");
|
String id = jsonObject.optString("id");
|
String type = jsonObject.optString("type");
|
// Log.e("mResult", "MiPushMessageReceiver..." + cClass);
|
if (type.equalsIgnoreCase("baichuan")) {
|
String url = jsonObject.optString("url");
|
if (activity != null) {
|
AlibcShowParams alibcShowParams = new AlibcShowParams();
|
alibcShowParams.setOpenType(OpenType.Native);
|
JumpActivityUtil.jumpBaiChuan(activity, "", url, "", alibcShowParams);
|
} else {
|
Intent intent = new Intent(context, BlankBaiChuanActivity31.class);
|
intent.putExtra("url", url);
|
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
context.startActivity(intent);
|
}
|
} else if (type.equalsIgnoreCase("ZNX")) {
|
BuXinConstant.isPushMsg = true;
|
context.startActivity(new Intent(context, MainActivity.class));
|
} else {
|
try {
|
if (cClass.equals("com.tejia.lijin.app.ui.recommend.GoodsBrowserActivity")) {
|
cClass = GoodsDetailActivityTB.class.getName();
|
}
|
Intent intent = new Intent(context, Class.forName(JumpActivityUtil.filterActivityName(cClass)));
|
if (!StringUtils.isEmpty(url1))
|
intent.putExtra("url", url1);
|
if (!StringUtils.isEmpty(id)) {
|
intent.putExtra("id", id);
|
}
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
context.startActivity(intent);
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
}
|
}
|
} catch (JSONException e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 注册 OPPO RegId
|
*/
|
public static void registeredOPPOId(Context context) {
|
String registerId = null;
|
if (PushManager.getInstance() != null)
|
registerId = PushManager.getInstance().getRegisterID();
|
if (!StringUtils.isEmpty(registerId))
|
ShoppingApi.bindOPPOPush(context, UserUtil.getUid(ShoppingApplication.application), registerId, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
super.onSuccessPerfect(statusCode, headers, jsonObject);
|
}
|
});
|
}
|
|
/**
|
* 注册 VIVO RegId
|
*/
|
public static void registeredVIVORegId(Context context) {
|
// Log.e("eee", "registeredVIVORegId-uid: " + uid);
|
String registerId = null;
|
if (PushClient.getInstance(context) != null)
|
registerId = PushClient.getInstance(context).getRegId();
|
if (!StringUtils.isEmpty(registerId))
|
ShoppingApi.bindVIVOPush(context, UserUtil.getUid(ShoppingApplication.application), registerId, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
super.onSuccessPerfect(statusCode, headers, jsonObject);
|
}
|
});
|
}
|
|
/**
|
* 推送免打扰模式
|
*
|
* @param mContext 上下文
|
* @param isChecked 开启免打扰模式
|
*/
|
public static void notDisturb(Context mContext, boolean isChecked) {
|
if (mContext != null) {
|
switch (Build.BRAND.toLowerCase()) {
|
case "xiaomi":
|
// Log.e("eee", "推送免打扰模式: xiaomi");
|
if (isChecked) {
|
MiPushClient.setAcceptTime(mContext, 8, 0, 20, 0, null);
|
} else {
|
MiPushClient.setAcceptTime(mContext, 0, 0, 23, 59, null);
|
}
|
break;
|
case "huawei":
|
case "honor":
|
|
break;
|
case "oppo":
|
List<Integer> weekDays = new ArrayList<>();//允许推送时间 日期
|
for (int i = 0; i < 7; i++) {//周日为0 周一为1
|
weekDays.add(i);
|
}
|
if (isChecked)
|
PushManager.getInstance().setPushTime(weekDays, 20, 0, 8, 0);
|
else
|
PushManager.getInstance().setPushTime(weekDays, 0, 0, 23, 59);
|
break;
|
case "vivo":
|
break;
|
default:
|
break;
|
}
|
}
|
}
|
|
/**
|
* 打开或关闭推送
|
*/
|
public static void setPush_OFF_NO(MainActivity mContext) {
|
if (mContext != null) {
|
/**
|
* false 关闭推送
|
* _01 第一次查询(第一次查询 关闭推送 只关闭一次)
|
* true 开启推送
|
* _02 二次查询(只开启一次)
|
* */
|
SharedPreferences sp = mContext.getSharedPreferences("user", Context.MODE_PRIVATE);
|
String off_no = sp.getString("push_off_no", "false_01");
|
SharedPreferences.Editor editor = sp.edit();
|
String mBRAND = Build.BRAND.toLowerCase();
|
if (mBRAND.equals("xiaomi")) {
|
// Log.e("eee", "setPush_OFF_NO: " + mBRAND + "--" + off_no);
|
if (off_no.equals("false_01")) {//关闭一次推送
|
// Log.e("eee", "setPush_OFF_NO: 关闭MiPush推送服务");
|
MiPushClient.pausePush(mContext, null);/**暂停接收MiPush服务推送的消息*/
|
editor.putString("push_off_no", "false_02");
|
} else if (off_no.equals("true_01")) {
|
// Log.e("eee", "setPush_OFF_NO: 启用MiPush推送服务");
|
MiPushClient.resumePush(mContext, null);/**恢复接收MiPush服务推送的消息,这时服务器会把暂停时期的推送消息重新推送过来*/
|
editor.putString("push_off_no", "true_02");
|
}
|
} else if (mBRAND.equals("huawei") || mBRAND.equals("honor")) {
|
// Log.e("eee", "honor: ");
|
if (off_no.equals("false_01")) {
|
editor.putString("push_off_no", "false_02");
|
HMSAgent.Push.enableReceiveNormalMsg(false, new EnableReceiveNormalMsgHandler() {
|
@Override
|
public void onResult(int rst) {
|
}
|
});
|
} else if (off_no.equals("true_01")) {
|
editor.putString("push_off_no", "true_02");
|
HMSAgent.Push.enableReceiveNormalMsg(true, new EnableReceiveNormalMsgHandler() {
|
@Override
|
public void onResult(int rst) {
|
}
|
});
|
}
|
} else if (mBRAND.equals("oppo")) {
|
if (off_no.equals("false_01")) {
|
PushManager.getInstance().pausePush();/*** 暂停接收OPush服务推送的消息*/
|
editor.putString("push_off_no", "false_02");
|
} else if (off_no.equals("true_01")) {
|
PushManager.getInstance().resumePush();/*** 恢复接收OPush服务推送的消息,这时服务器会把暂停时期的推送消息重新推送过来*/
|
editor.putString("push_off_no", "true_02");
|
}
|
} else if (mBRAND.equals("vivo")) {
|
|
}
|
editor.commit();
|
}
|
}
|
|
/**
|
* 初始化第三方SDK
|
*/
|
public static void thirdPartySDK() {
|
if (ShoppingApplication.application != null) {
|
UMConfigure.init(ShoppingApplication.application, UMConfigure.DEVICE_TYPE_PHONE, null);
|
initImageLoader(ShoppingApplication.application.getApplicationContext());//ImageLoader
|
}
|
}
|
|
|
/**
|
* ImageLoader
|
*/
|
public static void initImageLoader(Context context) {
|
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
|
.cacheInMemory(true).bitmapConfig(Bitmap.Config.RGB_565)
|
.imageScaleType(ImageScaleType.EXACTLY).cacheOnDisk(true)
|
.build();
|
|
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
|
context).threadPoolSize(3)
|
.threadPriority(Thread.NORM_PRIORITY - 2)
|
.denyCacheImageMultipleSizesInMemory()
|
.diskCacheFileNameGenerator(new Md5FileNameGenerator())
|
.tasksProcessingOrder(QueueProcessingType.LIFO)
|
.denyCacheImageMultipleSizesInMemory()
|
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))
|
.memoryCacheSize(2 * 1024 * 1024)
|
.memoryCacheSizePercentage(13).diskCacheSize(50 * 1024 * 1024)
|
.diskCacheFileCount(100)
|
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
|
.defaultDisplayImageOptions(defaultOptions).writeDebugLogs() // Remove
|
.build();
|
|
ImageLoader.getInstance().init(config);
|
}
|
|
/**
|
* 未加入淘宝联盟(智能搜索弹窗-猜你喜欢)
|
*
|
* @param info
|
* @param type
|
*/
|
public static Dialog isNotTBAlliance(final RecommendGoodsInfo info, String type, final Activity mContext) {
|
CopyLinkDialog.Builder builder = new CopyLinkDialog.Builder(mContext);
|
builder.setMessage(info);
|
builder.setType(Integer.valueOf(type));
|
builder.setPositiveButton("", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
MainCustomEvent.rmdTbgoodsRecommendResultClick(mContext, "猜你喜欢-未加入淘宝联盟商品");
|
Intent intent = new Intent(mContext, SearchResultActivity.class);
|
intent.putExtra("content", info.getGoods().getTitle());
|
intent.putExtra("type", "猜你喜欢");
|
intent.putExtra("page", "1");
|
mContext.startActivity(intent);
|
dialog.dismiss();
|
}
|
});
|
builder.setNegativeButton("", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
dialog.dismiss();
|
}
|
});
|
Dialog dialog = builder.create();
|
dialog.show();
|
return dialog;
|
}
|
|
/**
|
* 专题列表点击
|
* 根据jumpDetail和params 来判断需要打开的方式
|
*
|
* @param mList
|
*/
|
public static void setClickSpe(EntityFather mList, Context mContext) {
|
if (mList == null) {
|
return;
|
}
|
Intent intent = null;
|
if (mList.getJumpDetail().getType().equalsIgnoreCase("baichuan") && mList.getParams() != null) {
|
//判断登陆
|
if (mList.getJumpDetail().isNeedLogin() && !isLogin(mContext)) {//
|
UserUtil.jumpLogin(mContext);
|
return;
|
}
|
AlibcShowParams alibcShowParams = new AlibcShowParams();
|
alibcShowParams.setOpenType(OpenType.Auto);
|
String url = mList.getParams().getString("url");
|
JumpActivityUtil.jumpBaiChuan((Activity) mContext, null, url, "", alibcShowParams);
|
}
|
//有 跳转页面 有参数
|
else if (mList.getJumpDetail() != null && (!StringUtils.isEmpty(mList.getJumpDetail().getActivity()))
|
&& mList.getParams() != null) {
|
//判断登陆
|
if (mList.getJumpDetail().isNeedLogin() && !isLogin(mContext)) {//
|
UserUtil.jumpLogin(mContext);
|
return;
|
}
|
try {
|
intent = new Intent(mContext, Class.forName(JumpActivityUtil.filterActivityName(mList.getJumpDetail().getActivity())));
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
if (mList.getParams() != null) {
|
@SuppressWarnings("unchecked")
|
Iterator<String> its = mList.getParams().keySet().iterator();
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = mList.getParams().getString(key);
|
intent.putExtra(key, value);
|
}
|
}
|
mContext.startActivity(intent);
|
}
|
//无 跳转页面 有参数
|
else if (mList.getJumpDetail() == null || (StringUtils.isEmpty(mList.getJumpDetail().getActivity())) && mList.getParams() != null) {
|
intent = new Intent(mContext, ShareBrowserActivity.class);
|
|
if (mList.getParams() != null) {
|
@SuppressWarnings("unchecked")
|
Iterator<String> its = mList.getParams().keySet().iterator();
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = mList.getParams().getString(key);
|
intent.putExtra(key, value);
|
}
|
}
|
mContext.startActivity(intent);
|
}
|
//有跳转页面 无参数
|
else if (mList.getJumpDetail() != null && (!StringUtils.isEmpty(mList.getJumpDetail().getActivity())) && mList.getParams() == null) {
|
try {
|
intent = new Intent(mContext, Class.forName(JumpActivityUtil.filterActivityName(mList.getJumpDetail().getActivity())));
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
mContext.startActivity(intent);
|
}
|
}
|
|
/**
|
* 判断登陆
|
*
|
* @param mContext
|
* @return 登陆状态
|
*/
|
public static boolean isLogin(Context mContext) {
|
final SharedPreferences sp = mContext.getSharedPreferences("user", Context.MODE_PRIVATE);
|
return sp.getBoolean("isLogin", false);
|
}
|
|
/**
|
* 控制AppBarLayout的滑动
|
*
|
* @param isScroll true 允许滑动 false 禁止滑动
|
*/
|
public static void setAppBarScroll(boolean isScroll, AppBarLayout appbarlayout) {
|
View mAppBarChildAt = appbarlayout.getChildAt(0);
|
AppBarLayout.LayoutParams mAppBarParams = (AppBarLayout.LayoutParams) mAppBarChildAt.getLayoutParams();
|
if (isScroll) {
|
if (mAppBarParams.getScrollFlags() == 1 || mAppBarParams.getScrollFlags() == 4) {
|
return;
|
}
|
//SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
|
mAppBarParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
|
// mAppBarParams.setScrollInterpolator(null);
|
mAppBarChildAt.setLayoutParams(mAppBarParams);
|
} else {
|
if (mAppBarParams.getScrollFlags() == 0) {
|
return;
|
}
|
mAppBarParams.setScrollFlags(0);
|
// mAppBarParams.setScrollInterpolator(null);
|
mAppBarChildAt.setLayoutParams(mAppBarParams);
|
}
|
}
|
|
/**
|
* 检测通知权限 是否开启
|
*
|
* @param mContext
|
* @return
|
*/
|
public static boolean checkNotifySetting(Context mContext) {
|
NotificationManagerCompat manager = NotificationManagerCompat.from(mContext);
|
// areNotificationsEnabled方法的有效性官方只最低支持到API 19,低于19的仍可调用此方法不过只会返回true,即默认为用户已经开启了通知。
|
boolean isOpened = manager.areNotificationsEnabled();
|
if (isOpened) {
|
return true;
|
} else {
|
return false;
|
}
|
}
|
|
/**
|
* 跳转通知权限打开页面
|
*/
|
public static void initNotifyClick(Context mContext) {
|
Intent intent = new Intent();
|
if (Build.VERSION.SDK_INT >= 26) {
|
intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
|
intent.putExtra(EXTRA_APP_PACKAGE, mContext.getPackageName());
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//21
|
intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
|
intent.putExtra("app_package", mContext.getApplicationContext().getPackageName());
|
intent.putExtra("app_uid", mContext.getApplicationInfo().uid);
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//19
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
intent.setData(Uri.parse("package:" + mContext.getApplicationContext().getPackageName()));
|
} else {
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
// intent.setData(Uri.fromParts("package:", mContext.getPackageName(), null));
|
intent.setData(Uri.parse("package:" + mContext.getPackageName()));
|
}
|
mContext.startActivity(intent);
|
}
|
|
/*****************设置小黄条*******/
|
public static void setAppPageNotification(final LinearLayout ll_notice, TextView tv_notice_content, ImageView iv_close, JSONObject jsonObject) {
|
setAppPageNotification(ll_notice, tv_notice_content, iv_close, jsonObject, null);
|
}
|
|
|
public static void setAppPageNotification(final LinearLayout ll_notice, TextView tv_notice_content, ImageView iv_close, JSONObject jsonObject, final View.OnClickListener closeListener) {
|
if (jsonObject != null && jsonObject.optInt("code") == 0) {
|
boolean isClose = jsonObject.optJSONObject("data").optBoolean("canClose");
|
String content = jsonObject.optJSONObject("data").optString("content");
|
final String contentUrl = jsonObject.optJSONObject("data").optString("contentUrl");
|
final String md5 = jsonObject.optJSONObject("data").optString("md5");
|
|
tv_notice_content.setText(content);
|
final SharedPreferences sp = ll_notice.getContext().getSharedPreferences("notice", Context.MODE_PRIVATE);
|
if (!sp.getBoolean(md5, false)) {//false 展示,true不展示
|
ll_notice.setVisibility(View.VISIBLE);
|
} else {
|
ll_notice.setVisibility(View.GONE);
|
}
|
|
if (isClose) {
|
iv_close.setImageDrawable(ll_notice.getContext().getResources().getDrawable(R.drawable.ic_notice_close));
|
iv_close.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
ll_notice.setVisibility(View.GONE);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putBoolean(md5, true);
|
editor.apply();
|
if (closeListener != null)
|
closeListener.onClick(null);
|
}
|
});
|
} else {
|
iv_close.setImageDrawable(ll_notice.getContext().getResources().getDrawable(R.drawable.ic_notice_input));
|
}
|
ll_notice.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (StringUtils.isEmpty(contentUrl))
|
return;
|
Intent intent = new Intent(ll_notice.getContext(), ShareBrowserActivity.class);
|
intent.putExtra("url", contentUrl);
|
ll_notice.getContext().startActivity(intent);
|
}
|
});
|
} else {
|
ll_notice.setVisibility(View.GONE);
|
}
|
}
|
|
/**********************用app的包名进行判断是否安装********/
|
public static boolean uninstallSoftware(Context context, String pkgName) {
|
if (pkgName == null || pkgName.isEmpty()) {
|
return false;
|
}
|
final PackageManager packageManager = context.getPackageManager();
|
List<PackageInfo> infos = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);//0
|
if (infos == null || infos.isEmpty())
|
return false;
|
for (PackageInfo info : infos) {
|
if (pkgName.equals(info.packageName)) {
|
return true;
|
}
|
}
|
return false;
|
}
|
|
/******************************获取分享链接跳转至 创建分享页面******/
|
public static void createShareLink(final Context mContext, final GoodsDetail mInfo, String from) {
|
final ShapeLoadingDialog pb = new ShapeLoadingDialog.Builder(mContext).build();
|
pb.show();
|
ShoppingApi.createShareLink(mContext, UserUtil.getUid(ShoppingApplication.application), mInfo.getGoods().getGoodsId(), mInfo.getGoods().getGoodsType() + "", from, null, null, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optString("code").equalsIgnoreCase("0")) {
|
JSONObject data = jsonObject.optJSONObject("data");
|
SingleGoodsShareInfo shareInfo = new Gson().fromJson(data.toString(), SingleGoodsShareInfo.class);
|
shareInfo.setGoodsInfo(mInfo.getGoods());
|
Intent intent = new Intent(mContext, ShareGoodsImageActivity31.class);
|
intent.putExtra("shareInfo", shareInfo);
|
mContext.startActivity(intent);
|
}
|
}
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
pb.dismiss();
|
// isClick = 0;
|
}
|
});
|
}
|
|
/***********播放红包领取音效****/
|
public static void getPlaySound(Context context) {
|
if (context == null)
|
return;
|
AssetManager assetManager;
|
MediaPlayer player = null;
|
player = new MediaPlayer();
|
assetManager = context.getResources().getAssets();
|
try {
|
AssetFileDescriptor fileDescriptor = assetManager.openFd("moneysound.aac");
|
player.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getLength());
|
player.prepare();
|
player.start();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 适配:修改设备密度
|
*/
|
private static float sNoncompatDensity;
|
private static float sNoncompatScaledDensity;
|
|
/**
|
* 今日头条适配
|
*
|
* @param activity
|
* @param application
|
*/
|
public static void setCustomDensity(@NonNull Activity activity, @NonNull final Application application) {
|
// DisplayMetrics appDisplayMetrics = application.getResources().getDisplayMetrics();
|
// if (sNoncompatDensity == 0) {
|
// sNoncompatDensity = appDisplayMetrics.density;
|
// sNoncompatScaledDensity = appDisplayMetrics.scaledDensity;
|
// // 防止系统切换后不起作用
|
// application.registerComponentCallbacks(new ComponentCallbacks() {
|
// @Override
|
// public void onConfigurationChanged(Configuration newConfig) {
|
// if (newConfig != null && newConfig.fontScale > 0) {
|
// sNoncompatScaledDensity = application.getResources().getDisplayMetrics().scaledDensity;
|
// }
|
// }
|
//
|
// @Override
|
// public void onLowMemory() {
|
//
|
// }
|
// });
|
// }
|
// float targetDensity = appDisplayMetrics.widthPixels / 360;
|
// // 防止字体变小
|
// float targetScaleDensity = targetDensity * (sNoncompatScaledDensity / sNoncompatDensity);
|
// int targetDensityDpi = (int) (160 * targetDensity);
|
//
|
// appDisplayMetrics.density = targetDensity;
|
// appDisplayMetrics.scaledDensity = targetScaleDensity;
|
// appDisplayMetrics.densityDpi = targetDensityDpi;
|
//
|
// final DisplayMetrics activityDisplayMetrics = activity.getResources().getDisplayMetrics();
|
// activityDisplayMetrics.density = targetDensity;
|
// activityDisplayMetrics.scaledDensity = targetScaleDensity;
|
// activityDisplayMetrics.densityDpi = targetDensityDpi;
|
}
|
}
|