package com.sheep.gamegroup.util;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.kfzs.duanduan.utils.ApkUtils;
import com.kfzs.duanduan.view.DialogStorageLow;
import com.sheep.gamegroup.absBase.AbsObserver;
import com.sheep.gamegroup.module.find.bean.ColorBalanceFilter;
import com.sheep.gamegroup.module.find.util.IFilter;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.entity.CreditCard;
import com.sheep.gamegroup.model.entity.DialogConfig;
import com.sheep.gamegroup.model.entity.LoginEntity;
import com.sheep.gamegroup.model.entity.LoginUser;
import com.sheep.gamegroup.model.entity.UserEntity;
import com.sheep.gamegroup.model.entity.Video;
import com.sheep.gamegroup.model.util.SheepSubscriber;
import com.sheep.gamegroup.usage.AppUsageManager;
import com.sheep.gamegroup.util.viewHelper.CacheImageUtil;
import com.sheep.gamegroup.view.activity.ActInstallApkList;
import com.sheep.gamegroup.view.activity.ActMain;
import com.sheep.gamegroup.view.activity.ActSheepApkList;
import com.sheep.gamegroup.view.activity.ActSheepPngList;
import com.sheep.gamegroup.view.activity.ActTestExpression;
import com.sheep.gamegroup.view.activity.ActWeb;
import com.sheep.gamegroup.view.activity.NotificationsUtils;
import com.sheep.gamegroup.view.dialog.DialogGameOrTaskOrGift;
import com.sheep.gamegroup.view.dialog.DialogLoading;
import com.sheep.gamegroup.view.dialog.DialogNewbieTaskList;
import com.sheep.gamegroup.view.dialog.DialogProgress;
import com.sheep.jiuyan.samllsheep.BuildConfig;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.SheepApp;
import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
import com.sheep.jiuyan.samllsheep.utils.DeviceUtils;
import com.sheep.jiuyan.samllsheep.utils.G;
import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.FileCallBack;
import com.zhy.http.okhttp.callback.StringCallback;

import org.wysaid.nativePort.CGENativeLibrary;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import cn.finalteam.rxgalleryfinal.bean.MediaBean;
import cn.finalteam.rxgalleryfinal.utils.MediaUtils;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import okhttp3.Call;
import rx.functions.Action1;

import static android.content.Context.NOTIFICATION_SERVICE;
import static com.sheep.gamegroup.util.CommonUtil.LONG_MAO_APP_PACKAGE_NAME;
import static com.sheep.gamegroup.util.CommonUtil.LONG_MAO_APP_URI;
import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;

/**
 * Created by realicing on 2018/5/3.
 * realicing@sina.com
 */
public class TestUtil {
    private static TestUtil textUtils;

    public static TestUtil getInstance() {
        if (textUtils == null)
            textUtils = new TestUtil();
        return textUtils;
    }

    public static void testChange(final Activity activity, TextView test_change) {
        if (isTest() && !ConfigUtil.getInstance().isFileExists()) {
            test_change.setVisibility(View.VISIBLE);
            test_change.setText(SheepApp.getInstance().getConnectAddress().getName());
            test_change.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    final ConnectAddress[] connectAddresses = ConnectAddress.values();
                    AlertDialog dialog = new AlertDialog.Builder(activity).setTitle("请选择要切换的服务器")
                            .setSingleChoiceItems(new ArrayAdapter<>(activity, android.R.layout.simple_list_item_single_choice, connectAddresses), SheepApp.getInstance().getConnectAddress().ordinal(), new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int which) {
                                    SheepApp.getInstance().setConnectAddress(connectAddresses[which]);
                                }
                            })
                            .create();
                    dialog.show();
                }
            });
        }
    }

    public static void testChangeUser(final Activity activity, TextView test_change) {
        if (isTest() && !ConfigUtil.getInstance().isFileExists()) {

            test_change.setVisibility(View.VISIBLE);
            test_change.setText("切换账号");
            test_change.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    final List<LoginUser> loginUserList = MyDbManager.getInstance().getAllLoginUser();
//                    if (ListUtil.isEmpty(loginUserList)) {//无用户
//                        return;
//                    }
                    final List<Object> list = ListUtil.emptyList();
                    list.add("test");
                    list.add("清理清除aCache");
                    list.add("清理图片");
                    list.add("下载小绵羊");
                    ListUtil.addAll(list, loginUserList);
                    AlertDialog dialog = new AlertDialog.Builder(activity).setTitle("选择要登录的账号")
                            .setAdapter(new ArrayAdapter<>(activity, android.R.layout.simple_list_item_1, list), new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int which) {
                                    Object object = ListUtil.getItem(list, which);
                                    if (object instanceof LoginUser) {
                                        SpUtils.saveToken(SheepApp.getInstance(), ((LoginUser) object).getToken());
                                        CommonUtil.getInstance().updateUserInfo(new Action1<UserEntity>() {
                                            @Override
                                            public void call(UserEntity userEntity) {
                                                if (userEntity != null)
                                                    DataUtil.getInstance().initUserEntity(userEntity);
                                            }
                                        });
                                        ActivityManager.getInstance().finishAllActivity();
                                        Intent intent = new Intent(SheepApp.getInstance(), ActMain.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                        SheepApp.getInstance().startActivity(intent);
                                    } else if (object instanceof String) {
                                        switch (object.toString()) {
                                            case "清理图片":
                                                new Thread(new Runnable() {
                                                    @Override
                                                    public void run() {
                                                        Glide.get(SheepApp.getInstance()).clearDiskCache();//清理图片
                                                    }
                                                }).start();
                                                break;
                                            case "下载小绵羊":
                                                downloadApkFromJenkins();
                                                break;
                                            case "清理清除aCache":
                                                DataUtil.getInstance().clearACache();
                                                break;
                                            case "test":
                                                test(activity);
                                                break;
                                        }
                                    }
                                }
                            }).create();
                    dialog.show();
                }
            });
        }
    }

    public static void saveUser(LoginEntity loginEty) {
        if (isTest()) {
            if (loginEty != null && loginEty.getUser() != null) {
                LoginUser loginUser = new LoginUser();
                loginUser.setServiceName(SheepApp.getInstance().getConnectAddress().getName());
                loginUser.setId(loginEty.getUser().getOpen_id() + loginUser.getServiceName());
                loginUser.setToken(loginEty.getToken());
                loginUser.setNickname(loginEty.getUser().getNickname());
                MyDbManager.getInstance().saveOrUpdate(loginUser);
            }
        }
    }

    public static void addUser(final String token) {
        if (isTest()) {
            SheepApp.getInstance().getNetComponent().getApiService().getInfo()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                        @Override
                        public void onNext(BaseMessage baseMessage) {
                            UserEntity userEntity = baseMessage.getData(UserEntity.class);
                            LoginEntity loginEntity = new LoginEntity();
                            loginEntity.setToken(token);
                            loginEntity.setUser(userEntity);
                            saveUser(loginEntity);
                        }

                        @Override
                        public void onError(BaseMessage baseMessage) {
                            G.showToast(baseMessage);
                        }
                    });
        }
    }

    public static boolean isSheep() {
        return TextUtils.equals("sheep", BuildConfig.FLAVOR) && !BuildConfig.DEBUG;
    }

    public static boolean isTest() {
        return BuildConfig.DEBUG || !"sheep".equals(BuildConfig.FLAVOR);
    }

    public static void downloadApkFromJenkins() {
        Jump2View.getInstance().goWeb(ActivityManager.getInstance().currentActivity(), "http://10.8.210.20:8080/jenkins/job/android_small_sheep/", "从jenkins下载小绵羊安装包");
    }

    /**
     * 交通
     * http://mobi.yixiaozhao.jiyuonline.com/bank/10
     * http://10.8.210.172:8095/BCM_Insert.js
     * <p>
     * 浦发
     * https://ecentre.spdbccc.com.cn/creditcard/indexActivity.htm?data=P754372&itemcode=2017000032
     * http://10.8.210.172:8095/SPDB_Insert.js
     *
     * @param activity
     */
    public static void test(final Activity activity) {
        final String[] items = {"复制token", "添加token", "复制打点数据", "从jenkins下载小绵羊安装包", "测试表情包",
                "游戏搜索", "测试bitmap", "根据原始图片生成滤镜图片", "剪切视频","编辑视频", "我的关注", "足迹",
                "测试联通卡", "测试联通卡2", "测试签名1", "测试签名2", "测试孔剑秋faq正式服",
                "跳转QQ1", "跳转QQ2", "跳转QQ3", "跳转白白QQ", "龙猫竞猜", "龙猫竞猜-scheme",
                "有米科技", "手机型号测试", "测试通知栏", "测试自定义通知栏", "测试自定义通知栏2",
                "开启通知栏权限0", "开启通知栏权限1", "开启通知栏权限2", "开启通知栏权限3",
                "开启通知栏权限", "通知栏权限1", "通知栏权限2", "通知栏权限8.0", "测试支付", "测试内部h5", "测试外部h5",
                "会长推广游戏", "移动积分兑换", "审核中心", "检查正版", "crc32", "loading", "progress", "查看截图",
                "复制IMEI", "小米游戏", "测试可用金额", "测试定位信息", "测试apk的渠道", "幂动科技",
                "游戏帐号", "游戏代充", "尝试开启第三方应用使用情况", "测试代理页面", "第三方应用使用情况",
                "开启第三方应用使用情况", "h5跳转", "新手对话框", "md5", "空间不足提示框",
                "显示已经安装应用列表", "复制faq地址", "复制代理地址", "复制世界杯地址", "任务游戏列表", "世界杯活动", "交通银行信用卡测试",
                "浦发银行信用卡测试", "测试游戏模块", "打卡成功提示", "定向货币详情", "进入绑定身份认证界面时的提示", "提交身份认证时的提示", "检查标签",
                "友盟分享", "了解小绵羊", "提现成功"};
        AlertDialog dialog = new AlertDialog.Builder(activity).setTitle("请选择测试项目")
                .setItems(items, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (items[which]) {
                            case "测试bitmap":
                                testBitmap();
                                break;
                            case "根据原始图片生成滤镜图片":
                                testCreateFilterbleImg(ViewUtil.getNetImgByName("alter_original"));
                                break;
                            case "剪切视频":
                                testCutVideo();
                                break;
                            case "编辑视频":
                                testEditVideo();
                                break;
                            case "足迹":
                                Jump2View.getInstance().goActFootPrint();
                                break;
                            case "我的关注":
                                Jump2View.getInstance().goActMyFocus();
                                break;
                            case "测试联通卡":
                                Jump2View.getInstance().goActOverrideJsWeb(activity, items[which], "http://10.8.210.236:5000/#/", "http://10.8.210.236:5000/chart.js");
                                break;
                            case "测试联通卡2":
                                Jump2View.getInstance().goActOverrideJsWeb(activity, items[which], "http://10.8.210.236:5000/#/", "http://10.8.220.248/shared//html/test.js");
                                break;
                            case "测试孔剑秋faq正式服":
                                Jump2View.getInstance().goWeb(activity, " http://10.8.210.236:8080/#/faq", items[which]);
                                break;
                            case "测试签名1":
                                LogUtil.println("测试签名", ApkUtils.getApkSignMd5StrByPackageName("com.realicing.android.upgrade.sheep", null));
                                break;
                            case "测试签名2":
                                testApkSign2();
                                break;
                            case "跳转QQ1":
                                QQUtil.skip1(activity, "532588232");
                                break;
                            case "跳转QQ2":
                                QQUtil.skip2(activity, "532588232");
                                break;
                            case "跳转QQ3":
                                QQUtil.skip3(activity, "532588232");
                                break;
                            case "跳转白白QQ":
                                QQUtil.skip3(activity, "2441310002");
                                break;
                            case "测试表情包":
                                testExpression(activity);
                                break;
                            case "测试通知栏":
                                testNotification(activity);
                                break;
                            case "测试自定义通知栏":
                                Intent bdIntent = new Intent();
                                bdIntent.setAction(JPushInterface.ACTION_MESSAGE_RECEIVED);
                                Bundle bundle = new Bundle();
                                bundle.putString(JPushInterface.EXTRA_MESSAGE, "测试" + JPushInterface.EXTRA_MESSAGE);
                                Map<String, Object> map = new HashMap<>();
                                map.put("title", "测试title");
                                map.put("msg", "测试msgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
                                map.put("type", 71);
                                map.put("url", "www.baidu.com");
                                bundle.putString(JPushInterface.EXTRA_EXTRA, JSON.toJSONString(map));
                                bdIntent.putExtras(bundle);
                                activity.sendBroadcast(bdIntent);
                                break;
                            case "测试自定义通知栏2":
                                Intent bdIntent2 = new Intent();
                                bdIntent2.setAction(JPushInterface.ACTION_MESSAGE_RECEIVED);
                                Bundle bundle2 = new Bundle();
                                bundle2.putString(JPushInterface.EXTRA_MESSAGE, "测试" + JPushInterface.EXTRA_MESSAGE);
                                Map<String, Object> map2 = new HashMap<>();
                                map2.put("title", "测试title");
                                map2.put("type", 71);
                                map2.put("url", "www.baidu.com");
                                bundle2.putString(JPushInterface.EXTRA_EXTRA, JSON.toJSONString(map2));
                                bdIntent2.putExtras(bundle2);
                                activity.sendBroadcast(bdIntent2);
                                break;
                            case "有米科技":
                                Jump2View.getInstance().goYm(activity);
                                break;
                            case "手机型号测试":
                                G.showToast(Build.BRAND);
                                break;
                            case "开启通知栏权限":
                                NotificationsUtils.goToNotificationSetting(activity);
                                break;
                            case "开启通知栏权限0":
                                NotificationsUtils.goToNotificationSetting0(activity);
                                break;
                            case "开启通知栏权限1":
                                NotificationsUtils.goToNotificationSetting1(activity);
                                break;
                            case "开启通知栏权限2":
                                NotificationsUtils.goToNotificationSetting2(activity);
                                break;
                            case "开启通知栏权限3":
                                NotificationsUtils.goToNotificationSetting3(activity);
                                break;
                            case "通知栏权限1":
                                G.showToast("" + NotificationManagerCompat.from(activity).areNotificationsEnabled());
                                break;
                            case "通知栏权限2":
                                G.showToast("" + NotificationsUtils.isNotificationEnabled(activity));
                                break;
                            case "通知栏权限8.0":
                                G.showToast("" + NotificationsUtils.isEnableV26(activity));
                                break;
                            case "测试支付":
                                Jump2View.getInstance().goActPay(activity, "6460393611589586944", SpUtils.getToken(activity));
                                break;
                            case "测试内部h5":
                                Jump2View.getInstance().goWeb(activity, "www.17xmy.com/", "小绵羊官网");
                                break;
                            case "测试外部h5":
                                Jump2View.getInstance().goWeb(activity, "www.17xmy.com/");
                                break;
                            case "龙猫竞猜":
                                try {
                                    PackageUtil.startApp(SheepApp.getInstance(), LONG_MAO_APP_PACKAGE_NAME);
                                } catch (Exception e) {
                                    G.showToast(e.getMessage());
                                }
                                break;
                            case "龙猫竞猜-scheme":
                                try {
                                    Intent intent = Intent.parseUri(LONG_MAO_APP_URI, Intent.URI_INTENT_SCHEME);
                                    intent.setComponent(null);
                                    activity.startActivity(intent);
                                } catch (Exception e) {
                                    G.showToast(e.getMessage());
                                }
                                break;
                            case "会长推广游戏":
                                new DialogGameOrTaskOrGift(activity, "1106204266").showDialog();
                                break;
                            case "移动积分兑换":
                                Jump2View.getInstance().goActExchangeCMCC(activity);
                                break;
                            case "从jenkins下载小绵羊安装包":
                                downloadApkFromJenkins();
                                break;
                            case "审核中心":
                                Jump2View.getInstance().goAuditTastList(activity, null);
                                break;
                            case "检查正版":
                                PngUtil.isKfzsSheepApp();
                                break;
                            case "crc32":
                                activity.startActivity(new Intent(activity, ActSheepPngList.class));
                                break;
                            case "loading":
                                DialogLoading.showDialog(activity);
                                break;
                            case "progress":
                                DialogProgress.showDialog(activity);
                                break;
                            case "查看截图":
                                File root = DataUtil.getScreenShotsDir();
                                if (!root.exists() || root.listFiles().length <= 0) {
                                    G.showToast("暂无截图");
                                } else {
                                    File dir = DataUtil.getScreenShotsDir().listFiles()[0];
                                    if (dir.exists()) {
                                        G.showToast("截图个数为：" + dir.list().length);
                                    } else {
                                        G.showToast("截图目录不存在");
                                    }
                                    if (dir.list().length > 0) {
                                        Jump2View.getInstance().selectImgFiles(activity, 7, dir.listFiles());
                                    }
                                }
                                break;
                            case "小米游戏":
                                Jump2View.getInstance().goXiaomiGameList(activity, null);
                                break;
                            case "测试定位信息":
                                String jsonString = LocationUtils.getInstance().getLocationJSONObject().toJSONString();
                                G.showToast(jsonString);
                                StringUtils.CopyText(jsonString);
                                break;
                            case "测试apk的渠道":
                                Intent intent = new Intent(activity, ActSheepApkList.class);
                                activity.startActivity(intent);
                                break;
                            case "测试可用金额":
                                CommonUtil.getInstance()
                                        .getVoucherAndRatio(activity, 115 + "", new Action1<BaseMessage>() {
                                            @Override
                                            public void call(BaseMessage baseMessage) {

                                            }
                                        });
                                break;
                            case "幂动科技":
                                Jump2View.getInstance().goMiDong(activity, "http://10.8.210.172:8081/#/?authorization=123123");
                                break;
                            case "游戏帐号":
                                Jump2View.getInstance().goGameAccount(activity, "http://10.8.210.172:8081/#/?authorization=123123");
                                break;
                            case "游戏代充":
                                Jump2View.getInstance().goGameRecharge(activity, "http://10.8.210.172:8081/#/?authorization=123123");
                                break;
                            case "复制打点数据":
                                UMConfigUtils.copyDaDianData();
                                break;
                            case "游戏搜索":
                                Jump2View.getInstance().goGameSearch(activity, null);
                                break;
                            case "测试代理页面":
                                CommonUtil.getInstance().initUrlConfigByNet("agenturl", new Action1<String>() {
                                    @Override
                                    public void call(String url) {
                                        Jump2View.getInstance().goWeb(activity, url, "代理服务");
                                    }
                                });
                                break;
                            case "尝试开启第三方应用使用情况":
                                AppUsageManager.getInstance().tryOpenLookAppUsageStatsPermission(false);
                                break;
                            case "第三方应用使用情况":
                                AppUsageManager.getInstance().println();
                                break;
                            case "开启第三方应用使用情况":
                                AppUsageManager.getInstance().openLookAppUsageStatsPermission();
                                break;
                            case "h5跳转":
                                Jump2View.getInstance().goXianWanWeb(activity, null);
                                break;
                            case "新手对话框":
                                DialogNewbieTaskList.tryShowDialog(activity);
                                break;
                            case "md5":
                                String md5 = SysAppUtil.getConnectAdrressFileMD5();
                                StringUtils.CopyText(md5);
                                G.showToast(md5);
                                break;
                            case "空间不足提示框":
                                DialogStorageLow.showDialog(null);
                                break;
                            case "显示已经安装应用列表":
                                showHasInstallApkList(activity);
                                break;
                            case "添加token":
                                CharSequence text = StringUtils.getCopyText();
                                if(text != null) {
                                    SpUtils.saveToken(activity, text.toString());
                                    addUser(text.toString());
                                }
                                break;
                            case "复制token":
                                StringUtils.CopyText(SpUtils.getToken(activity));
                                break;
                            case "复制IMEI":
                                StringUtils.CopyText(new DeviceUtils(activity).getIMEI());
                                G.showToast(TimeUtil.newInstance().getDayBegin() + "|" + TimeUtil.newInstance().big2Today("2018-07-27", TimeUtil.FORMAT_DD_LINE));
                                break;
                            case "复制faq地址":
                                copyUrl("faqurl");
                                break;
                            case "复制代理地址":
                                copyUrl("agenturl");
                                break;
                            case "复制世界杯地址":
                                copyUrl("world_cup_url");
                                break;
                            case "任务游戏列表":
                                Jump2View.getInstance().goGameMakeMoney(activity, 0);
                                break;
                            case "世界杯活动":
                                Jump2View.getInstance().goWeb(activity, SheepApp.getInstance().getConnectAddress().getWorldCupUrl(), "测试世界杯活动");
                                break;
                            case "交通银行信用卡测试":
                                CreditCard creditCard = new CreditCard();
                                creditCard.setCardName(items[which]);
                                creditCard.setName("交通银行信用卡");
//                                creditCard.setLoadUrl("http://mobi.yixiaozhao.jiyuonline.com/bank/10");
                                creditCard.setLoadUrl("https://creditcardapp.bankcomm.com/applynew/front/apply/campus/index.html?trackCode=A021316596752");
                                creditCard.setScriptUrl("http://10.8.210.172:8095/BCM_Insert.js");
                                Jump2View.getInstance().goCreditCardWeb(activity, creditCard);
                                break;
                            case "测试游戏模块":
                                Jump2View.getInstance().goMainGame(activity);
                                break;
                            case "打卡成功提示":
                                ViewUtil.showMsgDialog(activity, new DialogConfig().setTitle("恭喜您").setMsg("打卡成功，活动结束后平分奖励会直接发放到个人账户中")
                                        .setBtnLeftText("好的").setBtnRightText("查看战绩")
                                        .setBtnRightOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                Jump2View.getInstance().goSignRecordAct(activity, null);
                                            }
                                        }));
                                break;
                            case "检查标签":
                                Jump2View.getInstance().checkLabel(activity, null);
                                break;
                            case "定向货币详情":
                                ViewUtil.showOrienteeringDetails(activity);
                                break;
                            case "进入绑定身份认证界面时的提示":
                                ViewUtil.showMsgDialog(activity, new DialogConfig().setTitle("温馨提示")
                                        .setMsg("根据国家相关法律规定，为保障线上交易活动的安全，参与互联网大额提现等资金活动时需要进行实名认证。\n完成实名认证后，再次提现将不需要进行验证。")
                                        .setMsgGravity(Gravity.START).setMsgIndent(2).setBtnLeftText("确定"));
                                break;
                            case "提交身份认证时的提示":
                                ViewUtil.showMsgDialog(activity, new DialogConfig().setTitle("重要提示").setMsgMore(String.format(Locale.CHINA, "你已执行%d次实名认证操作", 0))
                                        .setMsg("实名认证首次免费。请务必确认您所提交的认证信息真实有效。若因信息填写错误造成认证失败。再次申请认证时需扣除您0.5绵羊币/次作为认证费用，请务必谨慎填写认证信息。")
                                        .setMsgColor("0.5绵羊币/次", "#FF0000")
                                        .setMsgIndent(2)
                                        .setMsgGravity(Gravity.START)
                                        .setBtnLeftText("返回修改").setBtnRightText("确认提交")
                                        .setBtnRightOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                G.showToast("下一步提交");
                                            }
                                        }));
                                break;
                            case "浦发银行信用卡测试":
                                CreditCard creditCard1 = new CreditCard();
                                creditCard1.setCardName(items[which]);
                                creditCard1.setName("浦发银行信用卡");
                                creditCard1.setLoadUrl("https://ecentre.spdbccc.com.cn/creditcard/indexActivity.htm?data=P754372&itemcode=2017000032");
                                creditCard1.setScriptUrl("http://10.8.210.172:8095/SPDB_Insert.js");
                                Jump2View.getInstance().goCreditCardWeb(activity, creditCard1);
                                break;
                            case "友盟分享":
                                TestUtil.getInstance().testUmen(activity);
                            case "了解小绵羊":
                                Jump2View.getInstance().goUnderstandSheep(activity, null);
                                break;
                            case "提现成功":
                                Jump2View.getInstance().goWithdrawalResultview(activity, 1000);
                                break;

                        }
                    }
                }).create();
        dialog.show();
    }

    //根据原始图片生成滤镜图片
    private static void testBitmap() {
        Bitmap bmp = BitmapFactory.decodeResource(SheepApp.getInstance().getResources(), R.drawable.icon_lj);
        Bitmap result = Bitmap.createBitmap(G.WIDTH, G.HEIGHT, Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(result);
        Paint paint = new Paint();
        Matrix matrix = new Matrix();
        matrix.setTranslate(G.getRealPix(100), G.getRealPix(100));
        canvas.drawBitmap(bmp, matrix, paint);
        ViewUtil.saveImage(result, ClassFileHelper.DIR, String.valueOf(System.currentTimeMillis()) + ".png");
    }

    //根据原始图片生成滤镜图片
    private static void testCreateFilterbleImg(String url) {
        CacheImageUtil.cacheAndLoadImg(url, new Action1<File>() {
            @Override
            public void call(File file) {
                Observable.just(file)
                        .flatMap(new Function<File, ObservableSource<Bitmap>>() {
                            @Override
                            public ObservableSource<Bitmap> apply(File file) throws Exception {
                                Bitmap src = BitmapFactory.decodeFile(file.getAbsolutePath());
//                                ViewUtil.saveImage(src, ClassFileHelper.DIR, String.valueOf(System.currentTimeMillis()) + ".png");
                                return Observable.just(src);
                            }
                        })
                        .subscribeOn(Schedulers.io())
                        .flatMap(new Function<Bitmap, Observable<Integer>>() {
                            @Override
                            public Observable<Integer> apply(final Bitmap src) throws Exception {
                                List<IFilter> list = ColorBalanceFilter.getDefaultFilterList();
                                ListUtil.forEach(list, new Action1<IFilter>() {
                                    @Override
                                    public void call(IFilter filter) {
                                        Bitmap dstImage = CGENativeLibrary.filterImage_MultipleEffects(src, filter.getConfig(), 1.0f);
                                        ViewUtil.saveImage(dstImage, ClassFileHelper.DIR, String.valueOf(System.currentTimeMillis()) + ".png");
                                        dstImage.recycle();
                                    }
                                });
                                src.recycle();
                                return Observable.just(list.size());
                            }
                        })
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new AbsObserver<Integer>() {
                            @Override
                            public void onNext(Integer integer) {
                                G.showToast(String.valueOf(integer));
                            }
                        });
            }
        });

    }

    private static void testCutVideo() {
        Observable.create(new ObservableOnSubscribe<MediaBean>() {
            @Override
            public void subscribe(ObservableEmitter<MediaBean> emitter) throws Exception {
                List<MediaBean> mediaBeanList = MediaUtils.getMediaWithVideoList(SheepApp.getInstance(), 1, 1);
                MediaBean item = ListUtil.getItem(mediaBeanList, 0);
                emitter.onNext(item);
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new AbsObserver<MediaBean>() {
                    @Override
                    public void onNext(MediaBean mediaBean) {
                        Jump2View.getInstance().goActCutVideo(Video.from(mediaBean));
                    }
                });

    }
    private static void testEditVideo() {
        Observable.create(new ObservableOnSubscribe<MediaBean>() {
            @Override
            public void subscribe(ObservableEmitter<MediaBean> emitter) throws Exception {
                List<MediaBean> mediaBeanList = MediaUtils.getMediaWithVideoList(SheepApp.getInstance(), 1, 1);
                MediaBean item = ListUtil.getItem(mediaBeanList, 0);
                emitter.onNext(item);
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new AbsObserver<MediaBean>() {
                    @Override
                    public void onNext(MediaBean mediaBean) {
                        Jump2View.getInstance().goActEditVideo(Video.from(mediaBean));
                    }
                });

    }

    private static void testApkSign2() {
        LogUtil.println("测试签名", ApkUtils.getApkSignMd5StrByPath(new File(DIR, "559E2C4A81182E2674570B4AE3C9C440.apk").getAbsolutePath(), null));
    }

    //测试表情包
    private static void testExpression(Activity activity) {
        activity.startActivity(new Intent(activity, ActTestExpression.class));
    }

    //测试直接显示通知栏
    private static void testNotification(Activity activity) {
        String id = "my_channel_01";
        String name = activity.getString(R.string.app_name);
        NotificationManager notificationManager = (NotificationManager) activity.getSystemService(NOTIFICATION_SERVICE);
        if (notificationManager != null) {
            Notification notification;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH);
                notificationManager.createNotificationChannel(mChannel);
                notification = new NotificationCompat.Builder(activity, id)
                        .setContentTitle("5 new messages")
                        .setContentText("hahaha")
                        .setSmallIcon(R.mipmap.ic_launcher).build();
            } else {
                NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(activity, id)
                        .setContentTitle("5 new messages")
                        .setContentText("hahaha")
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setOngoing(true);
                notification = notificationBuilder.build();
            }
            notificationManager.notify(111123, notification);
        }
    }


    private static void copyUrl(final String name) {
        CommonUtil.getInstance().initUrlConfigByNet(name, new Action1<String>() {
            @Override
            public void call(String url) {
                StringUtils.CopyText(ActWeb.addUrlToken(url));
            }
        });
    }

    private static void showHasInstallApkList(Activity activity) {
        Intent intent = new Intent(activity, ActInstallApkList.class);
        activity.startActivity(intent);
    }

    //3.4.5版本之前的版本
    public static boolean isLTVersion3_4_5() {
        return BuildConfig.VERSION_CODE < 3004005;
    }

    /**
     * umen 分享
     */
    private void testUmen(Activity context) {
        UMImage umImage = new UMImage(context, R.mipmap.icon);
        new ShareAction(context)
                .withText("hehe")
                .withMedia(umImage)
                .setDisplayList(
                        SHARE_MEDIA.QQ,
                        SHARE_MEDIA.WEIXIN)
                .setCallback(new UMShareListener() {
                    @Override
                    public void onStart(SHARE_MEDIA share_media) {
                        Log.e("start---" + share_media.getName(), share_media.getName());
                    }

                    @Override
                    public void onResult(SHARE_MEDIA share_media) {
                        Log.e("result---" + share_media.getName(), share_media.getName());
                    }

                    @Override
                    public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                        Log.e("error---" + share_media.getName(), share_media.getName() +
                                ",msg:" + throwable.getMessage());
                    }

                    @Override
                    public void onCancel(SHARE_MEDIA share_media) {
                        Log.e("delete---" + share_media.getName(), share_media.getName());
                    }
                })
                .open();
    }

    private static final String URL_START = "http://10.8.210.20:8080/jenkins/job/android_small_sheep/";

    //通过jenkins服务器打包结果进行检查更新
    public static void checkUpdateFromJenkins(final Activity activity, final String ignoreMd5, final Action1<Integer> action1) {
        //加载jenkins信息来判断是否当前安装的是最新的安装包
        OkHttpUtils.get().url("http://10.8.210.20:8080/jenkins/job/android_small_sheep").build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                SysAppUtil.checkUpdateNewVersion(activity, ignoreMd5, action1);
            }

            @Override
            public void onResponse(String response, int id) {
                int start = response.indexOf("最后一次成功的构建结果");
                int end = response.indexOf("最新修改记录");
                try {
                    String result = response.substring(start, end);
                    ArrayList<String> arrayList = StringUtils.getAllSatisfyStr(result, "<a.+?href=\\\"(.+?)\\\">");
                    ListUtil.removeItem(arrayList, new ListUtil.CallBack<String, Boolean>() {
                        @Override
                        public Boolean call(String msg) {
                            return !msg.endsWith(".apk\">");
                        }
                    });
                    int index = 0;
                    switch (BuildConfig.FLAVOR) {
                        case "developSheeptest":
                            index = BuildConfig.DEBUG ? 0 : 1;
                            break;
                        case "sheep":
                            index = BuildConfig.DEBUG ? 2 : 3;
                            break;
                        case "sheeptestjiguang":
                            index = BuildConfig.DEBUG ? 4 : 5;
                            break;
                    }
                    String url = URL_START + arrayList.get(index).split("\"")[1];
                    downloadApkAndCheckInstall(url, action1);
                } catch (Exception e) {
                    e.printStackTrace();
                    G.showToast(e.getMessage());
                }
            }
        });
    }

    //下载apk文件后检查是否是最新的
    private static void downloadApkAndCheckInstall(final String url, final Action1<Integer> action1) {
        String name = Uri.parse(url).getLastPathSegment();
        if (name == null) {
            name = url.hashCode() + ".apk";
        }
        PackageInfo packageInfo = ApkUtils.getPackageInfo(BuildConfig.APPLICATION_ID);
        if (packageInfo == null)
            return;
        final File myApkFile = new File(packageInfo.applicationInfo.sourceDir);
        final File file = new File(DIR, name);
        if (file.exists()) {
            if (Md5Util.checkMD5(myApkFile, file)) {
                if (action1 == null)
                    G.showToast("应用已经是最新版本");
            } else {
                if (action1 == null)
                    G.showToast("文件已经存在，正在安装");
                ApkUtils.installApk(SheepApp.getInstance(), file.getAbsolutePath());
            }
            return;
        }
        OkHttpUtils.get().url(url).build().execute(new FileCallBack(DIR, name) {
            @Override
            public void inProgress(float progress, long total, int id) {
                if (action1 == null)
                    G.showToast(String.format(Locale.CHINA, "%d%%", Math.round(progress * 100)));
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                if (action1 == null)
                    G.showToast("下载失败");
            }

            @Override
            public void onResponse(File response, int id) {
                if (action1 == null)
                    G.showToast("下载完成");
                if (response.exists()) {
                    if (action1 == null)
                        G.showToast("文件已经是最新");
                    if (Md5Util.checkMD5(myApkFile, response)) {
                        if (action1 == null)
                            G.showToast("应用已经是最新");
                    } else {
                        ApkUtils.installApk(SheepApp.getInstance(), response.getAbsolutePath());
                    }
                }
            }
        });
    }

    //开启后可 测试充值与绑定微信和身份信息逻辑 等
    public static boolean isDev() {
        return BuildConfig.DEBUG;
//        return false;
    }
}