| | |
| | | package com.weikou.beibeivideo; |
| | | |
| | | import android.app.Activity; |
| | | import android.app.ActivityManager; |
| | | import android.app.Application; |
| | | import android.content.BroadcastReceiver; |
| | | import android.content.ComponentName; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.IntentFilter; |
| | | import android.graphics.Color; |
| | | import android.content.SharedPreferences; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | | import android.support.multidex.MultiDex; |
| | | import android.util.Log; |
| | | import android.widget.Toast; |
| | | |
| | | |
| | | import com.alibaba.baichuan.android.trade.AlibcTradeSDK; |
| | | import com.alibaba.baichuan.android.trade.callback.AlibcTradeInitCallback; |
| | | import com.baidu.mobads.AppActivity; |
| | | import com.fun.xm.FSPlayer; |
| | | import com.iBookStar.views.YmConfig; |
| | | import com.funshion.playsdk.callback.FunshionPlayInitCallback; |
| | | import com.funshion.playsdk.register.IAuthCodeGetter; |
| | | import com.lcjian.library.util.ManifestDataUtil; |
| | | import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; |
| | | import com.nostra13.universalimageloader.core.ImageLoader; |
| | |
| | | import com.umeng.commonsdk.UMConfigure; |
| | | import com.umeng.socialize.PlatformConfig; |
| | | import com.umeng.socialize.UMShareAPI; |
| | | import com.weikou.beibeivideo.ui.video.FunshionPlayerFragment; |
| | | import com.weikou.beibeivideo.entity.ad.AdPidInfo; |
| | | import com.weikou.beibeivideo.entity.ad.AdPositionEnum; |
| | | import com.weikou.beibeivideo.entity.ad.SplashAdLoadInfo; |
| | | import com.weikou.beibeivideo.ui.SplashActivity; |
| | | import com.weikou.beibeivideo.ui.ad.SplashADFragment; |
| | | import com.weikou.beibeivideo.ui.ad.SplashAdActivity; |
| | | import com.weikou.beibeivideo.ui.push.PushOpenClickActivity; |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.util.CrashHandler; |
| | | import com.weikou.beibeivideo.util.FunshionConstant; |
| | | import com.weikou.beibeivideo.util.UserUtil; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.ad.CSJConstant; |
| | | import com.weikou.beibeivideo.util.ad.GDTConstant; |
| | | import com.weikou.beibeivideo.util.ad.TTAdManagerHolder; |
| | | import com.weikou.beibeivideo.util.downutil.StringUtils; |
| | | import com.weikou.beibeivideo.util.novel.NovelJNZUtil; |
| | | import com.yeshi.push.PushUtil; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | |
| | | import de.greenrobot.event.EventBus; |
| | | |
| | | |
| | | public class BeibeiVideoApplication extends Application { |
| | | |
| | | private final String TAG = BeibeiVideoApplication.class.getName(); |
| | | |
| | | public static BeibeiVideoApplication application = null; |
| | | public static String deviceName = null; |
| | | public static String deviceNumber = null; |
| | |
| | | return instance; |
| | | } |
| | | |
| | | private Handler handler = new Handler() { |
| | | @Override |
| | | public void handleMessage(Message msg) { |
| | | super.handleMessage(msg); |
| | | switch (msg.what) { |
| | | case 0: |
| | | if (authCodeCallBack != null) |
| | | BeibeiVideoAPI.getFuntvAuthCode(application, new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject.optBoolean("IsPost")) { |
| | | String authCode = jsonObject.optString("Data"); |
| | | if (!StringUtils.isNullOrEmpty(authCode)) { |
| | | SharedPreferences.Editor editor = application.getSharedPreferences("funtv", Context.MODE_PRIVATE).edit(); |
| | | editor.putString("authCode", authCode); |
| | | editor.commit(); |
| | | } |
| | | authCodeCallBack.onSuccess(authCode); |
| | | } else { |
| | | SharedPreferences share = application.getSharedPreferences("funtv", Context.MODE_PRIVATE); |
| | | String authCode = share.getString("authCode", ""); |
| | | if (!StringUtils.isNullOrEmpty(authCode)) { |
| | | authCodeCallBack.onSuccess(authCode); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { |
| | | super.onFailure(statusCode, headers, responseString, throwable); |
| | | SharedPreferences share = application.getSharedPreferences("funtv", Context.MODE_PRIVATE); |
| | | String authCode = share.getString("authCode", ""); |
| | | if (!StringUtils.isNullOrEmpty(authCode)) { |
| | | authCodeCallBack.onSuccess(authCode); |
| | | } |
| | | } |
| | | } |
| | | ); |
| | | |
| | | break; |
| | | |
| | | } |
| | | } |
| | | }; |
| | | |
| | | |
| | | private IAuthCodeGetter.AuthCodeCallBack authCodeCallBack; |
| | | |
| | | @Override |
| | | public void onCreate() { |
| | |
| | | crashHandler.init(getApplicationContext()); |
| | | } |
| | | |
| | | this.registerActivityLifecycleCallbacks(new MyActivityLifecycleCallbacks()); |
| | | application = this; |
| | | MultiDex.install(this); |
| | | //友盟初始化 |
| | |
| | | super.onCreate(); |
| | | instance = this; |
| | | ImageLoader.getInstance().init(buildDefaultILC(this)); |
| | | initX5(); |
| | | // initX5(); |
| | | initCSJAd(); |
| | | GDTADManager.getInstance().initWith(this, BeibeiConstant.GDT_ID); |
| | | initWX(); |
| | | initTaoKe(); |
| | | try { |
| | | //初始化播放插件 |
| | | FSPlayer.init(this, FunshionConstant.APICODE); |
| | | FSPlayer.init(this, FunshionConstant.APP_ID, new IAuthCodeGetter() { |
| | | @Override |
| | | public void getAuthCode(AuthCodeCallBack authCodeCallBack) { |
| | | BeibeiVideoApplication.this.authCodeCallBack = authCodeCallBack; |
| | | handler.sendEmptyMessage(0); |
| | | } |
| | | }, new FunshionPlayInitCallback() { |
| | | |
| | | @Override |
| | | public void onSuccess() { |
| | | Log.i(TAG, "风行播放器初始化成功"); |
| | | } |
| | | |
| | | @Override |
| | | public void onFail(int i, String s) { |
| | | Log.i(TAG, "风行播放器初始化失败:" + i + "-" + s); |
| | | } |
| | | }); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | //百度内容联盟 |
| | | try { |
| | | AppActivity.setActionBarColorTheme(AppActivity.ActionBarColorTheme.ACTION_BAR_BLACK_THEME); |
| | | AppActivity.setActionBarColorTheme(AppActivity.ActionBarColorTheme.ACTION_BAR_WHITE_THEME); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | //推送 |
| | | PushUtil.inintPush(this, new PushUtil.ITokenListener() { |
| | | |
| | | @Override |
| | | public void onToken(String romType, String regId) { |
| | | BeibeiVideoAPI.pushBindToken(application, romType, regId, new BasicTextHttpResponseHandler() { |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | |
| | | } |
| | | }, true); |
| | | } |
| | | }); |
| | | |
| | | Intent intent = new Intent(this, PushOpenClickActivity.class); |
| | | intent.putExtra("activity", "test"); |
| | | JSONObject params = new JSONObject(); |
| | | try { |
| | | //聚能赚 |
| | | YmConfig.initNovel(this, "8845"); |
| | | NovelJNZUtil.setUid(this); |
| | | } catch (Exception e) { |
| | | |
| | | params.put("id", "123123"); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | intent.putExtra("params", params.toString()); |
| | | String uriString = intent.toUri(Intent.URI_INTENT_SCHEME); |
| | | Log.i(TAG, uriString); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | private void initTaoKe(){ |
| | | private void initTaoKe() { |
| | | AlibcTradeSDK.asyncInit(this, new AlibcTradeInitCallback() { |
| | | @Override |
| | | public void onSuccess() { |
| | |
| | | |
| | | @Override |
| | | public void onFailure(int code, String msg) { |
| | | Log.i(TAG, "百川初始化失败:" + code + "-" + msg); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | public void onViewInitFinished(boolean arg0) { |
| | | // TODO Auto-generated method stub |
| | | //x5內核初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核。 |
| | | Log.d("app", " onViewInitFinished is " + arg0); |
| | | Log.d(TAG, " onViewInitFinished is " + arg0); |
| | | } |
| | | |
| | | @Override |
| | |
| | | private void initCSJAd() { |
| | | TTAdManagerHolder.init(this); |
| | | } |
| | | |
| | | |
| | | class MyActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks { |
| | | private int mFinalCount; |
| | | |
| | | @Override |
| | | public void onActivityCreated(Activity activity, Bundle savedInstanceState) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onActivityStarted(Activity activity) { |
| | | mFinalCount++; |
| | | //如果mFinalCount ==1,说明是从后台到前台 |
| | | if (mFinalCount == 1) { |
| | | Log.e(TAG, "应用从后台切换到前台"); |
| | | // 进入前台 改为热启动 |
| | | //判断当前activity |
| | | ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); |
| | | ComponentName cn = am.getRunningTasks(1).get(0).topActivity; |
| | | if (!cn.getClassName().equalsIgnoreCase(SplashActivity.class.getName())) { |
| | | //小于30分钟不展示 |
| | | // 测试 |
| | | if (System.currentTimeMillis() - SplashADFragment.lastShowTime < 1000 * 60 * 30L) |
| | | return; |
| | | |
| | | if (SplashADFragment.isAdLoaded()) { |
| | | startActivity(new Intent(getApplicationContext(), SplashAdActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); |
| | | return; |
| | | } |
| | | |
| | | AdUtil.AD_TYPE type1 = AdUtil.getAdType(getApplicationContext(), AdPositionEnum.splashHotStart); |
| | | String pid1 = AdUtil.getAdPid(getApplicationContext(), AdPositionEnum.splashHotStart); |
| | | |
| | | |
| | | AdPidInfo adPidInfo1 = null; |
| | | AdPidInfo adPidInfo2 = null; |
| | | if (type1 != null) { |
| | | String defaultPid = null; |
| | | if (type1 == AdUtil.AD_TYPE.csj) { |
| | | defaultPid = CSJConstant.SPLASH_AD_HOT; |
| | | } else if (type1 == AdUtil.AD_TYPE.gdt) { |
| | | defaultPid = GDTConstant.PID_SPLASH_HOT; |
| | | } |
| | | if (StringUtils.isNullOrEmpty(pid1)) { |
| | | defaultPid = pid1; |
| | | } |
| | | adPidInfo1 = new AdPidInfo(type1, defaultPid); |
| | | if (type1 == AdUtil.AD_TYPE.csj) { |
| | | adPidInfo2 = new AdPidInfo(AdUtil.AD_TYPE.gdt, GDTConstant.PID_SPLASH_HOT); |
| | | } else if (type1 == AdUtil.AD_TYPE.gdt) { |
| | | adPidInfo2 = new AdPidInfo(AdUtil.AD_TYPE.csj, CSJConstant.SPLASH_AD_HOT); |
| | | } |
| | | } |
| | | |
| | | |
| | | SplashADFragment.loadAd(getApplicationContext(), adPidInfo1, adPidInfo2, null, null, true, new SplashADFragment.AdLoadResultListener() { |
| | | |
| | | @Override |
| | | public void onAdLoad(SplashAdLoadInfo adLoadInfo) { |
| | | //展示广告 |
| | | try { |
| | | startActivity(new Intent(getApplicationContext(), SplashAdActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); |
| | | } catch (SecurityException e) { |
| | | |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onNoAd() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onClose() { |
| | | //广点通广告适用 |
| | | //结束广告 |
| | | //通过eventbus通知页面关闭 |
| | | EventBus.getDefault().post(new SplashAdLoadInfo(null, 0)); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onActivityResumed(Activity activity) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onActivityPaused(Activity activity) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onActivityStopped(Activity activity) { |
| | | mFinalCount--; |
| | | //如果mFinalCount ==0,说明是前台到后台 |
| | | if (mFinalCount == 0) { |
| | | Log.e(TAG, "应用从前台切换到后台"); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onActivitySaveInstanceState(Activity activity, Bundle outState) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onActivityDestroyed(Activity activity) { |
| | | |
| | | } |
| | | } |
| | | } |