Commit 00bf0dde authored by mengcuiguang's avatar mengcuiguang

添加引用类

parent 31df89d8
package com.mints.street package com.mints.street
import android.content.Context
import android.os.StrictMode import android.os.StrictMode
import android.os.StrictMode.VmPolicy import android.os.StrictMode.VmPolicy
import android.util.Log import android.util.Log
import com.fry.base.base.BaseApp import com.fry.base.base.BaseApp
import com.mints.street.manager.CsjGroMoreManager
import com.mints.street.manager.UmengManager
import java.util.concurrent.TimeoutException import java.util.concurrent.TimeoutException
/** /**
* Created by 冯瑞雨 on 2021/7/1. * Created by 冯瑞雨 on 2021/7/1.
*/ */
class AppApplication :BaseApp() { class AppApplication : BaseApp() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
mContext = this
thirdConfig()
val builder = VmPolicy.Builder() val builder = VmPolicy.Builder()
StrictMode.setVmPolicy(builder.build()) StrictMode.setVmPolicy(builder.build())
builder.detectFileUriExposure() builder.detectFileUriExposure()
...@@ -28,5 +35,23 @@ class AppApplication :BaseApp() { ...@@ -28,5 +35,23 @@ class AppApplication :BaseApp() {
} }
} }
/*
* 三方配置
*/
private fun thirdConfig() {
UmengManager.preInit()
// GroMore
CsjGroMoreManager.init(this)
}
companion object {
var mContext: AppApplication? = null
fun getContext(): AppApplication? {
return mContext
}
}
} }
\ No newline at end of file
package com.mints.street.ad;
import android.app.Activity;
import android.content.Context;
import android.provider.Settings;
import com.bytedance.msdk.api.TTAdConfig;
import com.bytedance.msdk.api.TTAdConstant;
import com.bytedance.msdk.api.TTMediationAdSdk;
import com.bytedance.msdk.api.UserInfoForSegment;
import com.mints.street.common.Constant;
import com.mints.street.BuildConfig;
import java.util.HashMap;
import java.util.Map;
/**
* 可以用一个单例来保存TTAdManager实例,在需要初始化sdk的时候调用
*/
public class TTGroMoreAdManagerHolder {
public static final String TT_AD_APPID = "";
public static final String TT_AD_NAME = Constant.MINTS_APP_NAME;
private static boolean sInit;
public static void init(Context context) {
doInit(context);
}
public static void initUnitySdkBanner(Activity activity) {
TTMediationAdSdk.initUnityForBanner(activity);
}
//step1:接入网盟广告sdk的初始化操作,详情见接入文档和穿山甲平台说明
private static void doInit(Context context) {
if (!sInit) {
TTMediationAdSdk.initialize(context, buildConfig(context));
sInit = true;
}
}
private static TTAdConfig buildConfig(Context context) {
UserInfoForSegment userInfo = new UserInfoForSegment();
Map<String, String> customInfos = new HashMap<>();
// customInfos.put("aaaa", "test111");
// customInfos.put("bbbb", "test222");
userInfo.setCustomInfos(customInfos);
return new TTAdConfig.Builder()
.appId(TT_AD_APPID) //必填 ,不能为空
.appName(TT_AD_NAME) //必填,不能为空
.openAdnTest(false)//开启第三方ADN测试时需要设置为true,会每次重新拉去最新配置,release 包情况下必须关闭.默认false
.isPanglePaid(false)//是否为费用户
.setPublisherDid(getAndroidId(context)) //用户自定义device_id
.openDebugLog(BuildConfig.DEBUG) //测试阶段打开,可以通过日志排查问题,上线时去除该调用
.usePangleTextureView(true) //使用TextureView控件播放视频,默认为SurfaceView,当有SurfaceView冲突的场景,可以使用TextureView
.setPangleTitleBarTheme(TTAdConstant.TITLE_BAR_THEME_DARK)
.allowPangleShowNotify(true) //是否允许sdk展示通知栏提示
.allowPangleShowPageWhenScreenLock(true) //是否在锁屏场景支持展示广告落地页
.setPangleDirectDownloadNetworkType(TTAdConstant.NETWORK_STATE_WIFI, TTAdConstant.NETWORK_STATE_3G) //允许直接下载的网络状态集合
.needPangleClearTaskReset()//特殊机型过滤,部分机型出现包解析失败问题(大部分是三星)。参数取android.os.Build.MODEL
.setUserInfoForSegment(userInfo) // 设置流量分组的信息
.build();
}
public static String getAndroidId(Context context) {
String androidId = null;
try {
androidId = Settings.System.getString(context.getContentResolver(), Settings.System.ANDROID_ID);
} catch (Exception e) {
e.printStackTrace();
}
return androidId;
}
}
package com.mints.street.common
object Constant {
/**
* app名称
*/
const val MINTS_APP_NAME = "3D高清街景"
/**
* 应用包名
*/
const val MINTS_PKG_NAME = "com.mints.street"
}
package com.mints.street.manager
import com.mints.street.AppApplication
import com.mints.street.ad.TTGroMoreAdManagerHolder
/**
* 穿山甲GroMore
*/
object CsjGroMoreManager {
var AD_UNIT_SPLASH_ID = "" // 开屏
fun init(application: AppApplication) {
TTGroMoreAdManagerHolder.init(application)
}
}
\ No newline at end of file
package com.mints.street.manager
import com.umeng.analytics.MobclickAgent
import com.umeng.commonsdk.UMConfigure
import com.mints.street.BuildConfig
import com.mints.street.AppApplication
import com.mints.street.utils.CommonUtils
object UmengManager {
fun preInit(){
UMConfigure.preInit(AppApplication.getContext(), CommonUtils.getAppMetaData(AppApplication.getContext(), "UMENG_KEY"),
CommonUtils.getAppMetaData(AppApplication.getContext(), "CHANNEL_NAME"))
}
/**
* 友盟初始化
*/
fun initUm() {
try {
/*
* 参数4:设备类型,必须参数,传参数为UMConfigure.DEVICE_TYPE_PHONE则表示手机;传参数为UMConfigure.DEVICE_TYPE_BOX则表示盒子;默认为手机。
* 参数5:Push推送业务的secret,需要集成Push功能时必须传入Push的secret,否则传空。
*/
UMConfigure.init(
AppApplication.getContext(),
CommonUtils.getAppMetaData(AppApplication.getContext(), "UMENG_KEY"),
CommonUtils.getAppMetaData(AppApplication.getContext(), "CHANNEL_NAME"),
UMConfigure.DEVICE_TYPE_PHONE,
""
)
UMConfigure.setLogEnabled(BuildConfig.DEBUG)
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.LEGACY_MANUAL)
} catch (e: java.lang.Exception) {
e.printStackTrace()
}
}
}
\ No newline at end of file
/*
* Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
*
* Licensed under the Apache License, Version 2.0 (the "License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mints.street.utils;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextUtils;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 描述:CommonUtils
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcga@163.com
*/
public class CommonUtils {
/**
* return if str is empty
*
* @param str
* @return
*/
public static boolean isEmpty(String str) {
if (str == null || str.length() == 0 || str.equalsIgnoreCase("null") || str.isEmpty() || str.equals("")) {
return true;
} else {
return false;
}
}
/**
* decode Unicode string
*
* @param s
* @return
*/
public static String decodeUnicodeStr(String s) {
StringBuilder sb = new StringBuilder(s.length());
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if (c == '\\' && chars[i + 1] == 'u') {
char cc = 0;
for (int j = 0; j < 4; j++) {
char ch = Character.toLowerCase(chars[i + 2 + j]);
if ('0' <= ch && ch <= '9' || 'a' <= ch && ch <= 'f') {
cc |= (Character.digit(ch, 16) << (3 - j) * 4);
} else {
cc = 0;
break;
}
}
if (cc > 0) {
i += 5;
sb.append(cc);
continue;
}
}
sb.append(c);
}
return sb.toString();
}
/**
* encode Unicode string
*
* @param s
* @return
*/
public static String encodeUnicodeStr(String s) {
StringBuilder sb = new StringBuilder(s.length() * 3);
for (char c : s.toCharArray()) {
if (c < 256) {
sb.append(c);
} else {
sb.append("\\u");
sb.append(Character.forDigit((c >>> 12) & 0xf, 16));
sb.append(Character.forDigit((c >>> 8) & 0xf, 16));
sb.append(Character.forDigit((c >>> 4) & 0xf, 16));
sb.append(Character.forDigit((c) & 0xf, 16));
}
}
return sb.toString();
}
/**
* convert time str
*
* @param time
* @return
*/
public static String convertTime(int time) {
time /= 1000;
int minute = time / 60;
int second = time % 60;
minute %= 60;
return String.format("%02d:%02d", minute, second);
}
/**
* url is usable
*
* @param url
* @return
*/
public static boolean isUrlUsable(String url) {
URL urlTemp = null;
HttpURLConnection connt = null;
try {
urlTemp = new URL(url);
connt = (HttpURLConnection) urlTemp.openConnection();
connt.setRequestMethod("HEAD");
int returnCode = connt.getResponseCode();
if (returnCode == HttpURLConnection.HTTP_OK) {
return true;
}
} catch (Exception e) {
return false;
} finally {
if (connt != null) {
connt.disconnect();
}
}
return false;
}
/**
* is url
*
* @param url
* @return
*/
public static boolean isUrl(String url) {
Pattern pattern = Pattern.compile("^([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~\\/])+$");
return pattern.matcher(url).matches();
}
/**
* get toolbar height
*
* @param context
* @return
*/
public static int getToolbarHeight(Context context) {
final TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(
new int[]{android.R.attr.actionBarSize});
int toolbarHeight = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
return toolbarHeight;
}
/**
* Using regular expressions
*
* @param regular
* @param value
* @return
*/
public static boolean getConformToRegular(String regular, String value) {
boolean flag = false;
if (!TextUtils.isEmpty(regular) && !TextUtils.isEmpty(value)) {
Pattern p = Pattern.compile(regular);
Matcher m = p.matcher(value);
flag = m.matches();
}
return flag;
}
/**
* 禁止输入emoji
*/
public static InputFilter emojiFilter = new InputFilter() {
Pattern emoji = Pattern.compile(
"[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",
Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
int dstart,
int dend) {
Matcher emojiMatcher = emoji.matcher(source);
if (emojiMatcher.find()) {
return "";
}
return null;
}
};
/**
* 获取application中指定的meta-data
*
* @return 如果没有获取成功(没有对应值 , 或者异常),则返回值为空
*/
public static String getAppMetaData(Context ctx, String key) {
if (ctx == null || TextUtils.isEmpty(key)) {
return null;
}
String resultData = null;
try {
PackageManager packageManager = ctx.getPackageManager();
if (packageManager != null) {
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA);
if (applicationInfo != null) {
if (applicationInfo.metaData != null) {
resultData = applicationInfo.metaData.getString(key);
}
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return "";
}
return resultData;
}
public static String formatString(String str) {
if (str.contains(".")) {
String[] array = str.split("\\.");
String str0 = array[0];
String str1 = array[1];
if (str0.length() <= 3) {
return str0 + "." + str1;
} else {
return formatString(str0.substring(0, str0.length() - 3)) + ',' + str0.substring(str0.length() - 3) + "." + str1;
}
} else {
if (str.length() <= 3) {
return str;
} else {
return formatString(str.substring(0, str.length() - 3)) + ',' + str.substring(str.length() - 3);
}
}
}
}
#Thu Jul 08 19:11:44 CST 2021 #Thu Jul 08 19:52:09 CST 2021
VERSION_BUILD=2612 VERSION_BUILD=2613
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment