BaseUserApiImpl.java
2.94 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
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();
}
}