package com.ttstd.dialer.service;

import android.accessibilityservice.AccessibilityService;
import android.content.ComponentName;
import android.content.Intent;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;

import com.ttstd.dialer.db.contact.ContactInfo;
import com.ttstd.dialer.utils.ApkUtils;

public class DialerAccessibilityService extends AccessibilityService {
    private static final String TAG = "AccessibilityService";


    public static final int ACTION_VIDEO = 1;
    public static final int ACTION_AUDIO = 2;

    private ContactInfo mContactInfo;

    private int mCallType = ACTION_VIDEO;

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {

    }

    @Override
    public void onInterrupt() {

    }

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

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent != null) {
            mContactInfo = (ContactInfo) intent.getSerializableExtra("ContactInfo");
            mCallType = intent.getIntExtra("callType", 1);
            if (mContactInfo != null) {
                startWeixin();
            }
        }
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private void startWeixin() {
        Intent intent = new Intent();
        ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.setComponent(cmp);
        try {
            startActivity(intent);
        } catch (Exception e) {
            Log.e(TAG, "launchWeChat: " + e.getMessage());
        }
    }
}
