use of com.andframe.feature.AfIntent in project AndFrameWorks by scwang90.
the class AfActivity method onCreate.
// </editor-fold>
// <editor-fold desc="生命周期">
/**
* final 原始 onCreated(Bundle bundle)
* 子类只能重写 onCreated(Bundle bundle,AfIntent intent)
*/
@Override
protected void onCreate(Bundle bundle) {
try {
$.pager().onActivityCreated(this);
if (AfStackTrace.isLoopCall()) {
// System.out.println("递归检测");
super.onCreate(bundle);
return;
}
MustLogin must = AfReflecter.getAnnotation(getClass(), AfActivity.class, MustLogin.class);
if (must != null && !AfApp.get().isUserLogined()) {
if (Activity.class.isAssignableFrom(must.value())) {
startActivity(new Intent(this, must.value()));
} else if (Fragment.class.isAssignableFrom(must.value())) {
// noinspection unchecked
startFragment((Class<? extends Fragment>) must.value());
}
makeToastShort(must.remark());
super.onCreate(bundle);
finish();
return;
}
Injecter.doInject(this);
LayoutBinder.doBind(this);
} catch (final Throwable e) {
// handle 可能会根据 Activity 弹窗提示错误信息
// 当前 Activity 即将关闭,提示窗口也会关闭
// 用定时器 等到原始 Activity 再提示弹窗
AfDispatcher.dispatch(() -> AfExceptionHandler.handle(e, TAG() + ".onCreated"), 500);
super.onCreate(bundle);
makeToastShort("页面启动失败", e);
this.finish();
}
try {
this.onCreated(bundle);
LifeCycleInjecter.injectOnCreate(this, bundle);
} catch (Exception e) {
AfDispatcher.dispatch(() -> AfExceptionHandler.handle(e, TAG() + ".onCreated"), 500);
makeToastShort("页面启动失败", e);
this.finish();
}
}
use of com.andframe.feature.AfIntent in project AndFrameWorks by scwang90.
the class Injecter method injectExtra.
private static void injectExtra(Field field, Object handler, Context context) {
InjectExtraInvalid invalid = AfReflecter.getAnnotation(handler.getClass(), InjectExtraInvalid.class);
if (invalid != null && invalid.value().length == 0) {
return;
}
if (field.isAnnotationPresent(InjectExtra.class)) {
InjectExtra inject = field.getAnnotation(InjectExtra.class);
if (invalid != null) {
boolean find = false;
for (String extra : invalid.value()) {
if (TextUtils.equals(extra, inject.value())) {
find = true;
break;
}
}
if (find) {
return;
}
}
try {
Extrater intent = new AfIntent();
if (handler instanceof Activity) {
intent = new AfIntent(((Activity) handler).getIntent());
} else if (handler instanceof Fragment) {
final Fragment fragment = (Fragment) handler;
Bundle bundle = fragment.getArguments();
if (bundle != null) {
intent = new AfBundle(fragment.getArguments()) {
@Override
public <T> T get(String _key, Class<T> clazz) {
T t = super.get(_key, clazz);
if (t == null && fragment.getActivity() != null) {
return new AfIntent(fragment.getActivity().getIntent()).get(_key, clazz);
}
return t;
}
@Override
public <T> List<T> getList(String _key, Class<T> clazz) {
List<T> list = super.getList(_key, clazz);
if (list == null || list.size() == 0) {
return new AfIntent(fragment.getActivity().getIntent()).getList(_key, clazz);
}
return list;
}
};
} else {
if (context instanceof Activity && fragment.getActivity() == null) {
intent = new AfIntent(((Activity) context).getIntent());
} else {
intent = new AfIntent(fragment.getActivity().getIntent());
}
}
}
Object value;
Class<?> type = field.getType();
Type generic = field.getGenericType();
if (type.isArray()) {
type = type.getComponentType();
List<?> list = intent.getList(inject.value(), type);
value = Array.newInstance(type, list.size());
value = list.toArray((Object[]) value);
} else if (List.class.equals(type)) {
ParameterizedType parameterized = (ParameterizedType) generic;
type = (Class<?>) parameterized.getActualTypeArguments()[0];
value = intent.getList(inject.value(), type);
} else {
value = intent.get(inject.value(), type);
}
if (value != null) {
field.setAccessible(true);
field.set(handler, value);
} else if (inject.necessary()) {
if (inject.remark().length() > 0) {
throw new AfException("缺少必须参数:" + inject.remark());
} else {
throw new AfException("缺少必须参数:" + inject.value());
}
}
} catch (AfException e) {
throw e;
} catch (Throwable e) {
if (inject.necessary()) {
throw new RuntimeException("缺少必须参数", e);
}
AfExceptionHandler.handle(e, TAG(handler, "doInject.InjectExtra.") + field.getName());
}
}
}
use of com.andframe.feature.AfIntent in project AndFrameWorks by scwang90.
the class AfPagerManager method startActivity.
@Override
public void startActivity(Class<? extends Activity> clazz, Object... args) {
AfActivity activity = currentActivity();
if (activity != null && activity.isRecycled()) {
activity.startActivity(clazz, args);
} else {
AfApp app = AfApp.get();
AfIntent intent = new AfIntent(app, clazz);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putKeyVaules(args);
app.startActivity(intent);
}
}
Aggregations