package com.jleo;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
public abstract class Action {
public void setActivity(Activity activity) {
this.activity = activity;
}
public void apply(Activity activity){
this.setActivity(activity);
activity.setContentView(getViewId());
}
public void apply(Activity activity, Action precedentAction){
this.setActivity(activity);
this.precedentAction = precedentAction;
activity.setContentView(getViewId());
}
abstract void apply();
public abstract int getViewId();
public abstract void unapply(Activity activity);
public <T> T findViewById(int id,Class<T> c){
return c.cast(activity.findViewById(id));
}
public Context getApplicationContext() {
return activity.getApplicationContext();
}
public <T> T getSystemService(String locationService,Class<T> clazz) {
return (T) activity.getSystemService(locationService);
}
public void showDialog(int dialogId){
activity.showDialog(TraceMe.DIALOG_INTERACT);
}
public <T extends Action> void forward(Class<T> clazz,
Action loginAction) {
try {
clazz.newInstance().apply(activity, loginAction);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
}
private Activity activity;
private Action precedentAction;
public void alert(int titleId) {
new AlertDialog.Builder(activity).setIcon(R.drawable.alert_dialog_icon)
.setTitle(titleId).setSingleChoiceItems(R.array.ok, 0,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.dismiss();
}
}).show();
}
public void alert(String title) {
new AlertDialog.Builder(activity).setIcon(R.drawable.alert_dialog_icon)
.setTitle(title).setSingleChoiceItems(R.array.ok, 0,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.dismiss();
}
}).show();
}
}
asd
最新推荐文章于 2022-02-25 23:02:56 发布