无码人妻精一区二区三区,eeuss影院www在线观看,无码精品久久久久久人妻中字,日韩av高清在线看片

推薦新聞
BaseActivity 里到底應該寫哪些內(nèi)容?
發(fā)布者:深藍互聯(lián)
發(fā)布時間:2019-07-19
點擊:次
 
  1. 修改BaseActiviy的繼承為Fragment(可以實現(xiàn)dialogfragment)
  2. 增加isDebug和APP_NAME,在Application中聲明,方便日志打印,區(qū)分測試版本和正式版本
  3. 添加快速點擊導致的各種問題。
public abstract class BaseActivity extends FragmentActivity implements
		OnClickListener {
	/** 是否沉浸狀態(tài)欄 **/
	private boolean isSetStatusBar = true;
	/** 是否允許全屏 **/
	private boolean mAllowFullScreen = true;
	/** 是否禁止旋轉(zhuǎn)屏幕 **/
	private boolean isAllowScreenRoate = false;
	/** 當前Activity渲染的視圖View **/
	private View mContextView = null;
	/** 是否輸出日志信息 **/
	private boolean isDebug;
	private String APP_NAME;
	protected final String TAG = this.getClass().getSimpleName();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		isDebug = MApplication.isDebug;
		APP_NAME = MApplication.APP_NAME;
		$Log(TAG + "-->onCreate()");
		try {
			Bundle bundle = getIntent().getExtras();
			initParms(bundle);
			mContextView = LayoutInflater.from(this)
					.inflate(bindLayout(), null);
			if (mAllowFullScreen) {
				this.getWindow().setFlags(
						WindowManager.LayoutParams.FLAG_FULLSCREEN,
						WindowManager.LayoutParams.FLAG_FULLSCREEN);
				requestWindowFeature(Window.FEATURE_NO_TITLE);
			}
			if (isSetStatusBar) {
				steepStatusBar();
			}
			setContentView(mContextView);
			if (!isAllowScreenRoate) {
				setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
			} else {
				setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
			}
			initView(mContextView);
			doBusiness(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * [沉浸狀態(tài)欄]
	 */
	private void steepStatusBar() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			// 透明狀態(tài)欄
			getWindow().addFlags(
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
			// 透明導航欄
			getWindow().addFlags(
					WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
		}
	}

	/**
	 * [初始化Bundle參數(shù)]
	 * 
	 * @param parms
	 */
	public abstract void initParms(Bundle parms);

	/**
	 * [綁定布局]
	 * 
	 * @return
	 */
	public abstract int bindLayout();

	/**
	 * [重寫: 1.是否沉浸狀態(tài)欄 2.是否全屏 3.是否禁止旋轉(zhuǎn)屏幕]
	 */
	// public abstract void setActivityPre();

	/**
	 * [初始化控件]
	 * 
	 * @param view
	 */
	public abstract void initView(final View view);

	/**
	 * [業(yè)務操作]
	 * 
	 * @param mContext
	 */
	public abstract void doBusiness(Context mContext);

	/** View點擊 **/
	public abstract void widgetClick(View v);

	@Override
	public void onClick(View v) {
		if (fastClick())
			widgetClick(v);
	}

	/**
	 * [頁面跳轉(zhuǎn)]
	 * 
	 * @param clz
	 */
	public void startActivity(Class<?> clz) {
		startActivity(clz, null);
	}

	/**
	 * [攜帶數(shù)據(jù)的頁面跳轉(zhuǎn)]
	 * 
	 * @param clz
	 * @param bundle
	 */
	public void startActivity(Class<?> clz, Bundle bundle) {
		Intent intent = new Intent();
		intent.setClass(this, clz);
		if (bundle != null) {
			intent.putExtras(bundle);
		}
		startActivity(intent);
	}

	@SuppressWarnings("unchecked")
	public <T extends View> T $(int resId) {
		return (T) super.findViewById(resId);
	}

	/**
	 * [含有Bundle通過Class打開編輯界面]
	 * 
	 * @param cls
	 * @param bundle
	 * @param requestCode
	 */
	public void startActivityForResult(Class<?> cls, Bundle bundle,
			int requestCode) {
		Intent intent = new Intent();
		intent.setClass(this, cls);
		if (bundle != null) {
			intent.putExtras(bundle);
		}
		startActivityForResult(intent, requestCode);
	}

	@Override
	protected void onResume() {
		super.onResume();
		$Log(TAG + "--->onResume()");
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		$Log(TAG + "--->onDestroy()");
	}

	/**
	 * [是否允許全屏]
	 * 
	 * @param allowFullScreen
	 */
	public void setAllowFullScreen(boolean allowFullScreen) {
		this.mAllowFullScreen = allowFullScreen;
	}

	/**
	 * [是否設(shè)置沉浸狀態(tài)欄]
	 * 
	 * @param allowFullScreen
	 */
	public void setSteepStatusBar(boolean isSetStatusBar) {
		this.isSetStatusBar = isSetStatusBar;
	}

	/**
	 * [是否允許屏幕旋轉(zhuǎn)]
	 * 
	 * @param isAllowScreenRoate
	 */
	public void setScreenRoate(boolean isAllowScreenRoate) {
		this.isAllowScreenRoate = isAllowScreenRoate;
	}

	/**
	 * [日志輸出]
	 * 
	 * @param msg
	 */
	protected void $Log(String msg) {
		if (isDebug) {
			Log.d(APP_NAME, msg);
		}
	}

	/**
	 * [防止快速點擊]
	 * 
	 * @return
	 */
	private boolean fastClick() {
		long lastClick = 0;
		if (System.currentTimeMillis() - lastClick <= 1000) {
			return false;
		}
		lastClick = System.currentTimeMillis();
		return true;
	}
}
public abstract class BaseFragment extends Fragment implements OnClickListener {
	private boolean isDebug;
	private String APP_NAME;
	protected final String TAG = this.getClass().getSimpleName();
	private View mContextView = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		isDebug = MApplication.isDebug;
		APP_NAME = MApplication.APP_NAME;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mContextView = inflater.inflate(bindLayout(), container, false);
		initView(mContextView);
		doBusiness(getActivity());
		return mContextView;
	}

	/**
	 * [綁定布局]
	 * 
	 * @return
	 */
	public abstract int bindLayout();

	/**
	 * [初始化控件]
	 * 
	 * @param view
	 */
	public abstract void initView(final View view);

	/**
	 * [業(yè)務操作]
	 * 
	 * @param mContext
	 */
	public abstract void doBusiness(Context mContext);

	/** View點擊 **/
	public abstract void widgetClick(View v);

	@Override
	public void onClick(View v) {
		if (fastClick())
			widgetClick(v);
	}

	@SuppressWarnings("unchecked")
	public <T extends View> T $(View view, int resId) {
		return (T) view.findViewById(resId);
	}

	/**
	 * [日志輸出]
	 * 
	 * @param msg
	 */
	protected void $Log(String msg) {
		if (isDebug) {
			Log.d(APP_NAME, msg);
		}
	}

	/**
	 * [防止快速點擊]
	 * 
	 * @return
	 */
	private boolean fastClick() {
		long lastClick = 0;
		if (System.currentTimeMillis() - lastClick <= 1000) {
			return false;
		}
		lastClick = System.currentTimeMillis();
		return true;
	}
}

 

關(guān)注深藍互聯(lián)公眾號
Copyright ? 2013-2025 深藍互聯(lián) 版權(quán)所有
友情鏈接: