BaseUserApiImpl.java 2.94 KB
package com.cnlive.strike.myinterfacce;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;

import com.cnlive.strike.moudle.user.model.LoginSuccessInfo;


public class BaseUserApiImpl implements IUSERAPI {
    private Context context;
    private static IUSERAPIEventHandler iuserapiEventHandler;
    private Class<?> responseClass = null;
    private OnStartActivityListener onStartActivityListener;
    private static int type;

    public BaseUserApiImpl(Context context) {
        this.context = context;
    }


    @Override
    public void onLoginSuccess() {
        startActivity();
        type = 0;
    }

    @Override
    public void showMainView(LoginSuccessInfo loginSuccessInfo) {
        startActivity();
        type = 1;

    }

    @Override
    public boolean handleIntent(Intent var1, IUSERAPIEventHandler var2) {
        this.iuserapiEventHandler = var2;
        Log.e("asdasdasc", "handleIntent: " + type);
        return false;
    }

    private boolean startActivity() {
        boolean result = false;
        if (null == context) {
            return result;
        }
        if (null == responseClass) {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packageInfo = null;
            try {
                packageInfo = packageManager.getPackageInfo(
                        context.getPackageName(), PackageManager.GET_ACTIVITIES);
                for (ActivityInfo activity : packageInfo.activities) {
                    CharSequence labelSeq = activity.loadLabel(packageManager);
                    if (null == activity || null != labelSeq || null == activity.name || TextUtils.isEmpty(activity.name)) {
                        if ("UserAPI".equals(labelSeq)) {
                            Class<?> aClass = Class.forName(activity.name);
                            Intent intent = new Intent(context, aClass);
                            context.startActivity(intent);
                            Log.e("回调结果", activity.name);
                            result = true;
                            break;
                        } else {
                            continue;
                        }

                    } else {
                        continue;
                    }
                }
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        } else {
            Intent intent = new Intent(context, responseClass);
            context.startActivity(intent);
            result = true;
        }
        return result;
    }

    public interface OnStartActivityListener {
        void success();
    }
}