package com.zswc.creativity.utils;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import com.ysnows.base.utils.ShellUtil;

public class IntentUtils {

    public static Intent searchIntent(Context context, String kw) {
        Intent intent = new Intent("android.intent.action.WEB_SEARCH");
        intent.putExtra("query", kw);
        intent.setPackage(context.getPackageName());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        return intent;
    }

    public static Intent nIntent(String packageName, String className) {
//        if (ConfigColor.ClassName.WX_PAY_CODE.equals(className) || ConfigColor.ClassName.WX_FRIENDS_CIRCLE.equals(className)) {
        ShellUtil.checkRootPermission();
//        }
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(packageName, className));
        return intent;
    }

    public static Intent nIntentWithAction(String action) {
        return new Intent(action);
    }


    public static Intent shareIntent(String packageName, String className, String content) {

        Intent intent = new Intent();
        intent.setComponent(new ComponentName(packageName, className));
        intent.setAction(Intent.ACTION_SEND);//设置分享行为
        intent.setType("text/plain");//设置分享内容的类型
        intent.putExtra(Intent.EXTRA_SUBJECT, "");//添加分享内容标题
        intent.putExtra(Intent.EXTRA_TEXT, content);//添加分享内容

        return intent;
    }

    public static Intent nIntentWithParams(String packageName, String className, String paramsName, String paramsValue) {

//        if (ConfigColor.ClassName.WX_PAY_CODE.equals(className) || ConfigColor.ClassName.WX_FRIENDS_CIRCLE.equals(className)) {
        ShellUtil.checkRootPermission();
//        }

        Intent intent = new Intent();
        intent.setComponent(new ComponentName(packageName, className));

        if ("@1".equals(paramsValue)) {
            intent.putExtra(paramsName, true);
        } else if ("@0".equals(paramsValue)) {
            intent.putExtra(paramsName, false);
        } else {
            intent.putExtra(paramsName, paramsValue);
        }

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        return intent;
    }

}
