为了快速Android开发整理出的一套框架,BaseFragment,BaseActivity,RecyleAdapter

来源:互联网 发布:超级基因优化txt下载 编辑:程序博客网 时间:2024/06/10 07:09

一.在gradle中设置好引用的框架 下面是我开发所引用的框架

compile 'com.google.code.gson:gson:2.2.4'compile 'com.android.support:recyclerview-v7:24.2.0'compile 'com.zhy:okhttputils:2.6.2'//okhttp的异步封装compile 'com.android.support:design:24.2.0'compile 'com.jakewharton:butterknife:8.4.0'apt 'com.jakewharton:butterknife-compiler:8.4.0'//注释框架 添加监听实例化控件compile 'com.github.bumptech.glide:glide:3.7.0'//图片加载compile 'com.android.support:cardview-v7:24.2.0'compile 'com.github.dmytrodanylyk.circular-progress-button:library:1.1.3'//动画效果转变状态超棒Buttoncompile 'me.imid.swipebacklayout.lib:library:1.0.0'//使Activity侧滑返回
1.SharedPreferencesHelper 
public class SharedPreferencesHelper {public static final int SAVE_BUT_UNLOGIN = 0;public static final int SAVE_AND_LOGIN = 1;public static final int UN_SAVE = 2;SharedPreferences sp;SharedPreferences.Editor editor;Context context;@SuppressLint("CommitPrefEdits")public SharedPreferencesHelper(Context c, String name) {context = c;sp = context.getSharedPreferences(name, 0);editor = sp.edit();}public void putIntValue(String key, int value) {editor = sp.edit();editor.putInt(key, value);editor.commit();}public int getIntValue(String key) {return sp.getInt(key, 0);}public void putStringValue(String key, String value) {editor = sp.edit();editor.putString(key, value);editor.commit();}public String getStringValue(String key) {return sp.getString(key, null);}public void putBooleanValue(String key, Boolean value) {editor = sp.edit();editor.putBoolean(key, value);editor.commit();}public boolean getBooleanValue(String key) {return sp.getBoolean(key, false);}}


2.BaseActivity篇

public abstract class SwipBaseActivity extends AppCompatActivity implements SwipeBackActivityBase {    private SwipeBackActivityHelper mHelper;    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        mHelper = new SwipeBackActivityHelper(this);        mHelper.onActivityCreate();        setContentView(setLayout());        ButterKnife.bind(this);        initView();        loadData();    }        @Override    protected void onPostCreate(Bundle savedInstanceState) {        super.onPostCreate(savedInstanceState);        mHelper.onPostCreate();    }    @Override    public SwipeBackLayout getSwipeBackLayout() {        return mHelper.getSwipeBackLayout();    }    @Override    public void setSwipeBackEnable(boolean enable) {        getSwipeBackLayout().setEnableGesture(enable);    }    @Override    public void scrollToFinishActivity() {        Utils.convertActivityToTranslucent(this);        getSwipeBackLayout().scrollToFinishActivity();    }    public abstract int setLayout();    public abstract void initView();    public abstract void loadData();    Handler han = new Handler();    //不带附加数据快捷跳转    public <T extends Activity>  void start(final Class<T> c){        startActivity(new Intent(SwipBaseActivity.this,c));    }    //延时跳转    public <T extends Activity>  void delayedStartActivity(final Class<T> c, long time){        han.postDelayed(new Runnable() {            @Override            public void run() {                finish();                startActivity(new Intent(SwipBaseActivity.this,c));            }        },time);    }    //延时跳转附带数据 并结束当前页    public void delayedStartActivity(final Intent in, long time, final boolean finish){        han.postDelayed(new Runnable() {            @Override            public void run() {                startActivity(in);                if(finish)finish();            }        },time);    }    //确定按钮添加点击事件的Dialog    public void showDialog(String title, String message, DialogInterface.OnClickListener click){        AlertDialog.Builder bui = new AlertDialog.Builder(this);        bui.setTitle(title).setMessage(message).setNegativeButton("确定",click).setPositiveButton("取消",null).show();    }    //自定义内容的Dialog 推荐将Activity设置为Design主题 这样所有的控件都比较好看    public AlertDialog showViewDialog(View view, String title){        AlertDialog.Builder bui = new AlertDialog.Builder(this);        AlertDialog dia = bui.setView(view).setTitle(title).create();        dia.show();        return dia;    }    //解析布局文件返回View    public View inflateView(int id){        return LayoutInflater.from(this).inflate(id,null,false);    }    //在父View中实例化某个子控件    protected <T extends View> T getView(View pa,int id){        return (T)pa.findViewById(id);    }    //使用SnackBar全局提示 取代吐司    public void showHint(String hint,View v){        Snackbar.make(v,hint, Snackbar.LENGTH_SHORT).show();    }    //右侧带一个可以点击的textview    public void showHint(String hint, String action, View.OnClickListener click){        View view=getLayoutInflater().inflate(setLayout(),null,false);        Snackbar.make(view,hint, Snackbar.LENGTH_SHORT).setAction(action,click).show();    }    //获取自己封装的SharedPreferences对象    public SharedPreferencesHelper getSPHelper(String name){        return new SharedPreferencesHelper(this,name);    }    //true表示有未输入edittext(传入多个edittext判断是否有空的)    public boolean isEempt(EditText... ed){           for(EditText e:ed){               if(TextUtils.isEmpty(e.getText()))return true;           }        return false;    }    //log    public void log(String l){        Log.e(this.getClass().getName()+"类",l);    }    /**     * 手机号正则表达式 验证     */    public static boolean isMobileNO(String mobiles) {        Pattern p = Pattern                .compile("^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$");        Matcher m = p.matcher(mobiles);        return m.matches();    }}


0 0
原创粉丝点击