MainApplication.java 13.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
package com.ivt.android.me;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Environment;
import android.support.multidex.MultiDex;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.Volley;
import com.cnlive.libs.util.Config;
import com.huawei.PEPlayerInterface.PEAudioDeviceName;
import com.huawei.PEPlayerInterface.PEVideoDeviceName;
import com.ivt.android.me.bean.GiftInfoBean;
import com.ivt.android.me.bean.RedPaBean;
import com.ivt.android.me.bean.UserEntity;
import com.ivt.android.me.server.NetReceiver;
import com.ivt.android.me.ui.base.BaseActivity;
import com.ivt.android.me.utils.HttpLogInfo;
import com.ivt.android.me.utils.publics.LogUtil;
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.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import cn.cmvideo.sdk.common.CmVideoApplication;
import cn.jpush.android.api.JPushInterface;
import io.vov.vitamio.Vitamio;

public class MainApplication extends CmVideoApplication {

    public static final int ToastTime = 2000;
    /**
     * 是否调试状态
     */
    public static final Boolean IS_DEBUG = false;
    /**
     * 工程TAG
     */
    private static final String TAG = "ME+";
    /**
     * 工程最新版本号
     */
    public static int NEW_VERSION = 1;

    public static Bitmap Advert = null;

    /**
     * 点击推送进行数据传输的Bundle
     */
    public static Bundle SeeLiveBundle;

    /**
     * 本次app抢到的红包
     */
    public static List<RedPaBean> RDPIDS;
    /**
     * 获取SD卡路径
     */
    public static final String SD_ROOT = Environment
            .getExternalStorageDirectory().getPath();
    /**
     * 获取数据库路径
     */
    public static String DB_ROOT = SD_ROOT + "me";

    /**
     * 发礼物的线程池
     */
    public static ExecutorService SendGiftPool;
    public static List<GiftInfoBean> gifts;

    /**
     * 自己的贡献榜
     */
    public static List<UserEntity> MyGiftlist;
    /**
     * 自己的贡献榜的时间
     */
    public static Long MyGiftTime;
    public static String SeeGiftListUserId = "";

    /**
     * 其他人自己的贡献榜
     */
    public static List<UserEntity> OtherGiftlist;
    /**
     * 其他人贡献榜的时间
     */
    public static Long OtherGiftTime;
    private static MainApplication mInstance;
    public static boolean Islive = false;

    // 自己的关注
    public static List<UserEntity> MyAttentUsers = new ArrayList<UserEntity>();

    private static Context context;

    NetReceiver mReceiver = new NetReceiver();
    IntentFilter mFilter = new IntentFilter();


    //++++++++++++++++++plus+++++++++++++++++++++++++++++
    public static long appOnlineStart = 0;
    public static boolean appOnline = false;
    public static int userID = 0;
    private RequestQueue mRequestQueue;
    private String mVideoADList;
    //统计视频的区块
    public static String mediaRef = "index";

    public static Context getContext() {
        return context;
    }

    private static List<BaseActivity> listActivitie = new ArrayList<BaseActivity>();

    public static MainApplication getInstance() {

        return mInstance;

    }

    @Override
    public void onCreate() {
        super.onCreate();

        Config.init(this, "118_itdr6ijv09", "24557a1060598e010749ec11b43ac9d62e8a765d3463cf");

        mInstance = this;
        new LogUtil().SetDEBUG(IS_DEBUG, TAG);
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager wm = (WindowManager) this .getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(dm);
        DB_ROOT = "/data/data/" + getPackageName() + "/databases";
        mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        registerReceiver(mReceiver, mFilter);
        context = getApplicationContext();
        SendGiftPool = Executors.newSingleThreadExecutor();
        gifts = new ArrayList<GiftInfoBean>();
        RDPIDS = new ArrayList<RedPaBean>();

        if (!IS_DEBUG){
//            HttpLogInfo.getInstance().init(getApplicationContext());
        }
        JPushInterface.setDebugMode(IS_DEBUG);    // 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);            // 初始化 JPush
        initImageLoader(this);
        try {
            System.loadLibrary("mg20pbase");
        } catch(Exception e){ }
    }

    public static void initImageLoader(Context context) {
        final int default_res = android.R.color.transparent;
        DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()
                .bitmapConfig(Bitmap.Config.ALPHA_8)
                .imageScaleType(ImageScaleType.EXACTLY)
                .displayer(new FadeInBitmapDisplayer(100))
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .showImageOnLoading(default_res)
                .showImageForEmptyUri(default_res)
                .showImageOnFail(default_res)
                .build();
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                .defaultDisplayImageOptions(displayImageOptions)
                .tasksProcessingOrder(QueueProcessingType.FIFO)
                .build();
        ImageLoader.getInstance().init(config);
    }

    /**
     * 添加activity到清除列表
     *
     * @param activity void
     */
    public static void addActivity(BaseActivity activity) {
        listActivitie.add(activity);
    }

    /**
     * 将activity 移除 清除列表
     *
     * @param activity void
     */
    public static void removeActivity(Activity activity) {
        listActivitie.remove(activity);
    }

    /**
     * 将清除列表的activity finish void
     */

    public static void finishActivity() {
        for (int i = listActivitie.size() - 1; i >= 0; i--) {
            listActivitie.get(i).finish();
        }
    }

    public static void degugFinishActivity() {
        for (int i = listActivitie.size() - 1; i >= 0; i--) {
            listActivitie.get(i).finish();
        }
    }

    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    public <T> void addToRequestQueue(Request<T> req, String tag) {
        req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
        VolleyLog.d("Adding request to queue: %s", req.getUrl());
        getRequestQueue().add(req);
    }

    public <T> void addToRequestQueue(Request<T> req) {
        // set the default tag if tag is empty
        req.setTag(TAG);
//        getRequestQueue().getCache().invalidate(req.getOriginUrl(), true);
        getRequestQueue().add(req);
    }

    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {
            mRequestQueue = Volley.newRequestQueue(getApplicationContext());
        }
        return mRequestQueue;
    }

    public void setVideoADList(String videoADList) {
        mVideoADList = videoADList;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }



    private int videoRenderID = 0;

    private int audioRenderID = 0;

    private int curFPSFlg = 0;

    private int ccFlg = 0;

    private int localCache = 0;

    private int localCacheTimeLength = 0;

    private String localCachePath = "";

    private int maxBitrate = 0;

    private int subtlDisMode = 0;

    private int logLevel = 0;

    private int trackBufferTime = 0;

    private float playSpeed = 0;

    private int logcatFlag = 1;

    private int breakPointFlag = 0;

    private final static int OUTLOG_CONSOLE = 0;
    private int outLogType = OUTLOG_CONSOLE;

    private String outlogPath = "";

    private int CpuMonitorFlag = 0;

    private String audioRenderType = PEAudioDeviceName.PE_AUDIO_DEVICE_NAME_OPENSLES;
    private String videoRenderType = PEVideoDeviceName.PE_VIDEO_DEVICE_NAME_OPENGLES;
    private int videoDecoderType = 0;
    private int audioDecoderType = 0;
    private List<Map<String, Integer>> breakPointList = new ArrayList<Map<String, Integer>>();


    public void setBreakPointTime(String url, int time) {
        if (breakPointList == null) {
            return;
        }

        List<Map<String, Integer>> tempList = new ArrayList<Map<String, Integer>>();
        for (Map<String, Integer> m : breakPointList) {
            for (String key : m.keySet()) {
                if (key.equals(url)) {
                    tempList.add(m);
                }
            }
        }
        breakPointList.removeAll(tempList);
        Map<String, Integer> map = new HashMap<String, Integer>();
        map.put(url, time);
        breakPointList.add(map);

    }

    public int getSubtlDisplayMode() {
        return subtlDisMode;
    }

    public int getBreakPointTime(String url) {
        if (breakPointList == null || breakPointList.size() == 0) {
            return 0;
        }
        for (Map<String, Integer> m : breakPointList) {
            for (String key : m.keySet()) {
                if (key.equals(url)) {
                    return m.get(key);
                }
            }
        }
        return 0;
    }
    public int getBreakPointFlg() {
        return breakPointFlag;
    }
    public int getLocalCacheFlg() {
        return localCache;
    }
    public String getAudioRenderType() {
        return audioRenderType;
    }
    public int getAudioDecoderType() {
        return audioDecoderType;
    }

    public void setAudioDecoderType(int value) {
        audioDecoderType = value;
    }
    public String getVideoRenderType() {
        return videoRenderType;
    }
    public int getVideoDecoderType() {
        return videoDecoderType;
    }

    public void setVideoDecoderType(int value) {
        videoDecoderType = value;
    }

    public int getVideoRenderID() {
        return videoRenderID;
    }

    public void setVideoRenderID(int videoRenderID) {
        this.videoRenderID = videoRenderID;
    }

    public int getAudioRenderID() {
        return audioRenderID;
    }

    public void setAudioRenderID(int audioRenderID) {
        this.audioRenderID = audioRenderID;
    }


    public void setCurFPS(int value) {
        curFPSFlg = value;
    }

    public int getCurFPS() {
        return curFPSFlg;
    }

    public void setCCFlg(int value) {
        ccFlg = value;
    }

    public int getCCFlg() {
        return ccFlg;
    }

    public void setMaximumBitrate(int value) {
        maxBitrate = value;
    }

    public int getMaximumBitrate() {
        return maxBitrate;
    }

    public void setOutlogType(int value) {
        outLogType = value;
    }

    public int getOutlogType() {
        return outLogType;
    }






    public int getLocalCache() {
        return localCache;
    }

    public void setLocalCache(int localCache) {
        this.localCache = localCache;
    }

    public int getLocalCacheTimeLength() {
        return localCacheTimeLength;
    }

    public void setLocalCacheTimeLength(int localCacheTimeLength) {
        this.localCacheTimeLength = localCacheTimeLength;
    }

    public String getLocalCachePath() {
        return localCachePath;
    }

    public void setLocalCachePath(String localCachePath) {
        this.localCachePath = localCachePath;
    }


    public int getSubtlDisMode() {
        return subtlDisMode;
    }

    public void setSubtlDisMode(int subtlDisMode) {
        this.subtlDisMode = subtlDisMode;
    }

    public int getLogLevel() {
        return logLevel;
    }

    public void setLogLevel(int logLevel) {
        this.logLevel = logLevel;
    }

    public int getTrackBufferTime() {
        return trackBufferTime;
    }

    public void setTrackBufferTime(int trackBufferTime) {
        this.trackBufferTime = trackBufferTime;
    }

    public float getPlaySpeed() {
        return playSpeed;
    }

    public void setPlaySpeed(float playSpeed) {
        this.playSpeed = playSpeed;
    }

    public int getLogcatFlag() {
        return logcatFlag;
    }

    public void setLogcatFlag(int logcatFlag) {
        this.logcatFlag = logcatFlag;
    }

    public int getBreakPointFlag() {
        return breakPointFlag;
    }

    public void setBreakPointFlag(int breakPointFlag) {
        this.breakPointFlag = breakPointFlag;
    }

    public List<Map<String, Integer>> getBreakPointList() {
        return breakPointList;
    }

    public void setBreakPointList(List<Map<String, Integer>> breakPointList) {
        this.breakPointList = breakPointList;
    }

    public void setOutlogPath(String value) {
        outlogPath = value;
    }

    public String getOutlogPath() {
        return outlogPath;
    }

    public void setCpuMonitor(int value) {
        CpuMonitorFlag = value;
    }

    public int getCpuMonitor() {
        return CpuMonitorFlag;
    }
}