public class ExceptionUtils {
/**
* 对象的非空校验
*
* @param object 代校验的参数
* @param message 如果参数为空时的异常堆栈信息
* @param
* @return
*/
public static T checkoutNotNull(T object, String message) {
if (object == null) {
throw new NullPointerException(message);
}
return object;
}
}
public class ZMDialog {
public static class Builder {
private Context context;
private String title;
private String message;
private String positiveMessage;
private String negativeMessage;
private ZMSubscriber positiveClickEvent;
private ZMSubscriber negativeClickEvent;
private boolean cancelable;
public Builder(Context context) {
this.context = context;
}
public Context getContext() {
return context;
}
public String getTitle() {
return title;
}
public Builder setTitle(String title) {
this.title = title;
return this;
}
public String getMessage() {
return message;
}
public Builder setMessage(String message) {
this.message = message;
return this;
}
public String getPositiveMessage() {
return positiveMessage;
}
public Builder setPositiveMessage(String positiveMessage) {
this.positiveMessage = positiveMessage;
return this;
}
public String getNegativeMessage() {
return negativeMessage;
}
/**
* 单选对话框的话,需要用这个
*
* @param negativeMessage
* @return
*/
public Builder setNegativeMessage(String negativeMessage) {
this.negativeMessage = negativeMessage;
return this;
}
public ZMSubscriber getPositiveClickEvent() {
return positiveClickEvent;
}
public Builder setPositiveClickEvent(ZMSubscriber positiveClickEvent) {
this.positiveClickEvent = positiveClickEvent;
return this;
}
public ZMSubscriber getNegativeClickEvent() {
return negativeClickEvent;
}
/**
* 单选对话框的话,需要用这个
*
* @param negativeClickEvent
* @return
*/
public Builder setNegativeClickEvent(ZMSubscriber negativeClickEvent) {
this.negativeClickEvent = negativeClickEvent;
return this;
}
public boolean isCancelable() {
return cancelable;
}
public Builder setCancelable(boolean cancelable) {
this.cancelable = cancelable;
return this;
}
public ZMDialog builder() {
return new ZMDialog(this);
}
}
private ZMDialog(final Builder zmDialogBuilder) {
MaterialDialog.Builder materialBuilder = new MaterialDialog.Builder(zmDialogBuilder.getContext());
materialBuilder.canceledOnTouchOutside(zmDialogBuilder.isCancelable())
.title(zmDialogBuilder.getTitle())
.content(zmDialogBuilder.getMessage())
.positiveText(zmDialogBuilder.getPositiveMessage())
.negativeText(zmDialogBuilder.getNegativeMessage())
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
zmDialogBuilder.getPositiveClickEvent().onNext(null);
}
})
.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
zmDialogBuilder.getNegativeClickEvent().onNext(null);
}
})
.build()
.show();
}
}
@Override
public void dealWithCustomAction(Context context, UMessage uMessage) {
super.dealWithCustomAction(context, uMessage);
PushMessage pushMessage = new PushMessage();
......//此处为公司机密 PushMessageDispatcher.getInstance().onClick(context, pushMessage);
}
public class BusActivity extends BaseActivityWithToolBar {
private static final String KEY_TASK_ID = "TASK_ID";
public static Intent getCallingIntent(Context context, String taskId) {
Intent intent = new Intent();
intent.putExtra(KEY_TASK_ID, taskId);
intent.setClass(context, BusActivity.class);
return intent;
}
}
public class Navigator {
/**
* 跳转登陆页
*
* @param context
*/
public void navigateToLogin(@NonNull Context context) {
Intent intent = LoginActivity.getCallingIntent(context);
context.startActivity(intent);
}
}
@AnyRes References any type of R. resource.
代码中使用这些,可以规范方法入参,问题出在编译阶段,减少运行时的异常
public class PermissionHelper {
/**
* 检查App是否有定位权限
*
* @param activity
* @return true ,已授权,false,未授权
*/
public static boolean checkLocationPermission(Activity activity) {
if (Build.VERSION.SDK_INT >= PERMISSION_LIMIT) {
return PermissionUtils.checkGroupPermissions(activity, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION});
} else {
return true;
}
}
}
public class MissionFragment extends BaseFragment {
/**
* fragment中权限请求方法
*/
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_PERMISSION_REQUEST_CODE);
/**
* 权限请求回调方法
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (locationPermissionGranted(requestCode, permissions, grantResults)) {
navigateToMissionDetail();
}
}
}
`
/**
* 支付界面入口标示
*/
public enum PaymentEntrance {
/**
* 巴士车票
*/
BUS_TICKET,
/**
* 定制巴士
*/
ZOUME_BUS,
/**
* 当前行程:列表
*/
TRIPS_LIST,
/**
* 当前行程:详情
*/
TRIP_DETAIL
}
`
`
/**
* 获取携带过来的数据
* 用以初始化界面以及发送网络请求
*/
private void handleExtraParam() {
Bundle bundle = getArguments();
if (bundle != null && bundle.containsKey(EXTRA_PAYMENT_ENTEANCE)) {
paymentEntrance = (PaymentEntrance) bundle.getSerializable(EXTRA_PAYMENT_ENTEANCE);
paymentInfo = bundle.getSerializable(EXTRA_PAYMENT_INFO);
switch (paymentEntrance) {
case BUS_TICKET:
refreshUI((ZMBusTicketOrder) paymentInfo);
break;
case ZOUME_BUS:
refreshUI((ZouMeBusOrderParam) paymentInfo);
break;
case TRIPS_LIST:
case TRIP_DETAIL:
refreshUI((TripOrder) paymentInfo);
break;
}
}
}
`
`
private static int SELECT_STATE = 0;
private static final int TOGGLE_START_OR = 8;
private static final int TOGGLE_START_AND = 7;
private static final int TOGGLE_DESTINATION_OR = 4;
private static final int TOGGLE_DESTINATION_AND = 11;
private static final int TOGGLE_LINER_OR = 2;
private static final int TOGGLE_LINER_AND = 13;
private static final int TOGGLE_PASSENGER_OR = 1;
private static final int TOGGLE_PASSENGER_AND = 14;
public static final int CODE_SELECT_START = 1;
public static final int CODE_SELECT_DESTINATION = 2;
public static final int CODE_KEY_SOURCE_SEARCH = 5;
public static final int CODE_ADD_PASSENGER = 4;
//标志位变换控制方法
SELECT_STATE = SELECT_STATE & TOGGLE_START_AND;
SELECT_STATE = SELECT_STATE & TOGGLE_DESTINATION_AND;
`
`
public interface HasComponent {
C getComponent();
}
`