美文网首页
安卓架构一

安卓架构一

作者: 楚南玄 | 来源:发表于2017-06-27 15:07 被阅读21次

    整体思路

    1、activity基础类,包含沉浸式,标题栏;BaseActivity,BaseFragment
    2、http,socket(volley),eventBus,gson
    3、log日志
    4、butterKnife
    5、空白页、底部栏
    6、刷新、加载更多
    7、加载图片,glide以及glide图片形状的那个
    8、工具类,util
    9、com.panda.bike
    10、命名规则参照https://github.com/Blankj/AndroidStandardDevelop
    11、尝试使用Rxjava
    12、loading的加载弹窗

    BaseActivity

    加入统一的标题头,沉浸式状态栏,eventBus,ButterKnife等

    代码:

    package com.panda.sharebike.ui.base;
    
    import android.os.Build;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.Window;
    import android.widget.LinearLayout;
    import android.widget.RelativeLayout;
    
    import com.panda.sharebike.R;
    import com.panda.sharebike.model.MessageEvent;
    import com.panda.sharebike.ui.widget.CustomTitleBar;
    
    import org.greenrobot.eventbus.EventBus;
    import org.greenrobot.eventbus.Subscribe;
    import org.greenrobot.eventbus.ThreadMode;
    
    import butterknife.ButterKnife;
    public abstract class BaseActivity extends AppCompatActivity {
        private CustomTitleBar titleBar;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            /*
            隐藏系统title注意的两点:
    
            继承AppCompatActivity时使用:
            supportRequestWindowFeature(Window.FEATURENOTITLE)
    
            继承activity时使用:
            requestWindowFeature(Window.FEATURENOTITLE)
             */
            supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
            LinearLayout linearLayout = new LinearLayout(this);
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            titleBar = new CustomTitleBar(this);
            linearLayout.addView(titleBar);
            linearLayout.addView(LayoutInflater.from(this).inflate(getLayoutView(), new RelativeLayout(this)));
            setContentView(linearLayout);
    
            ViewGroup contentFrameLayout = (ViewGroup) findViewById(Window.ID_ANDROID_CONTENT);
            View parentView = contentFrameLayout.getChildAt(0);
            if (parentView != null && Build.VERSION.SDK_INT >= 14) {
                parentView.setFitsSystemWindows(true);
            }
            ButterKnife.bind(this);
            setUpView();
        }
    
        /**
         * 返回当前Activity布局文件的id
         */
        abstract protected int getLayoutView();
    
        protected void setUpView() {
            titleBar.setTitle(getTitle().toString());
            titleBar.setLeftIcon(R.drawable.icon_title_back, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    finish();
                }
            });
        }
    
        @Subscribe(threadMode = ThreadMode.MAIN)
        public void onMessageEvent(MessageEvent event) {/* Do something */}
    
        @Override
        public void onStart() {
            super.onStart();
            EventBus.getDefault().register(this);
        }
    
        @Override
        public void onStop() {
            super.onStop();
            EventBus.getDefault().unregister(this);
        }
    
        protected void setTitle(String title) {
            titleBar.setTitle(title);
        }
    
        protected void setLeftIcon(int resId, View.OnClickListener listener) {
            titleBar.setLeftIcon(resId, listener);
        }
    
        protected void setTvLeft(String text, View.OnClickListener listener) {
            titleBar.setTvLeft(text, listener);
        }
    
        protected void setRightIcon(int resId, View.OnClickListener listener) {
            titleBar.setRightIcon(resId, listener);
        }
    
        protected void setTvRight(String text, View.OnClickListener listener) {
            titleBar.setTvRight(text, listener);
        }
    
        protected void hideTitleBar() {
            titleBar.setVisibility(View.GONE);
        }
    }   ```

    相关文章

      网友评论

          本文标题:安卓架构一

          本文链接:https://www.haomeiwen.com/subject/qbrecxtx.html