Giter VIP home page Giter VIP logo

base's Introduction

Base

Download Issue Count License Blog

Base是针对于Android开发封装好一些常用的基类,主要包括通用的Adapter、Activity、Fragment、Dialog等、和一些常用的Util类,只为更简单。

Base 3.x 在Base 2.x 的基础上进行了重构,最大的变化是将adapter提取了出来,单独作为一个library(base-adapter)。

Gif展示(示例App)

Image

引入

Maven:

//base
<dependency>
  <groupId>com.king.base</groupId>
  <artifactId>base</artifactId>
  <version>3.0.0</version>
  <type>pom</type>
</dependency>

//base-adapter
<dependency>
  <groupId>com.king.base</groupId>
  <artifactId>adapter</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

Gradle:

//base
compile 'com.king.base:base:3.0.0'

//base-adapter
compile 'com.king.base:adapter:1.0.0'

Lvy:

//base
<dependency org='com.king.base' name='base' rev='3.0.0'>
  <artifact name='$AID' ext='pom'></artifact>
</dependency>

//base-adapter
<dependency org='com.king.base' name='adapter' rev='1.0.0'>
  <artifact name='$AID' ext='pom'></artifact>
</dependency>

引入的库:

//base
provided 'com.android.support:appcompat-v7:25.3.+'
//base-adapter
provided 'com.android.support:appcompat-v7:25.3.+'
provided 'com.android.support:recyclerview-v7:25.3.+'

简要说明:

Base主要实用地方体现在:出统一的代码风格,实用的各种基类,BaseActivity和BaseFragment里面还有许多实用的代码封装,只要用了Base,使用Fragment就感觉跟使用Activtiy基本是一样的。

代码示例:

通用的Adapter

/**
  * 
  * 只需继承通用的适配器(ViewHolderAdapter或ViewHolderRecyclerAdapter),简单的几句代码,妈妈再也不同担心我写自定义适配器了。
  */
public class TestAdapter extends ViewHolderAdapter<String> {


    public TestAdapter(Context context, List<String> listData) {
        super(context, listData);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, String s, int position) {
        return inflate(R.layout.list_item);
    }

    @Override
    public void bindViewDatas(ViewHolder holder, String s, int position) {
        holder.setText(R.id.tv,s);
    }
}

基类BaseActivity

public class TestActivity extends BaseActivity {

    private TextView tv;
    private Button btn;

    @Override
    public void initUI() {
        //TODO:初始化UI
        setContentView(R.layout.activity_test);
        tv = findView(R.id.tv);
        btn = findView(R.id.btn);
    }

    @Override
    public void initData() {
        //TODO:初始化数据(绑定数据)
        tv.setText("text");
    }

    @Override
    public void addListeners() {
        //TODO:添加监听事件
    }

}

GestureActivity

public class TestGestureActivity extends GestureActivity {

    private TextView tv;
    private Button btn;

    @Override
    public void initUI() {
        //TODO:初始化UI
        setContentView(R.layout.activity_test);
        tv = findView(R.id.tv);
        btn = findView(R.id.btn);
    }

    @Override
    public void initData() {
        //TODO:初始化数据(绑定数据)
        tv.setText("text");
    }

    @Override
    public void addListeners() {
        //TODO:添加监听事件
    }

    @Override
    public void onLeftFling() {
        //TODO:向左滑动
    }

    @Override
    public boolean onRightFling() {
        //TODO:向右滑动,默认执行finish,返回为true表示拦截事件。
        return false;
    }
}

SplashActivity

public class TestSplashActivity extends SplashActivity {
    @Override
    public int getContentViewId() {
        return R.layout.activity_splash;
    }

    @Override
    public Animation.AnimationListener getAnimationListener() {
        return new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //TODO: 启动动画结束,可执行跳转逻辑
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        };
    }
}

BaseFragment

public class TestFragment extends BaseFragment {
    @Override
    public int inflaterRootView() {
        return R.layout.fragment_test;
    }

    @Override
    public void initUI() {
        //TODO:初始化UI
    }

    @Override
    public void initData() {
         //TODO:初始化数据(绑定数据)
    }

    @Override
    public void addListeners() {
        //TODO:添加监听事件
    }

}

BaseDialogFragment

public class TestDialogFragment extends BaseDialogFragment {
    @Override
    public int inflaterRootView() {
        return R.layout.fragment_test_dialog;
    }

    @Override
    public void initUI() {
        //TODO:初始化UI
    }

    @Override
    public void initData() {
        //TODO:初始化数据(绑定数据)
    }

    @Override
    public void addListeners() {
        //TODO:添加监听事件
    }

}

WebFragment

    WebFragment实现基本webView功能

其他小功能

使用Log: 统一控制管理Log

 LogUtils.v(); 
 
 LogUtils.d();
 
 LogUtils.i();
 
 LogUtils.w();
 
 LogUtils.e();
 
 LogUtils.twf();
 
 LogUtils.println();

使用Toast

 showToast(CharSequence text);
 
 showToast(@StringRes  int resId);

使用Dialog

 showDialog(View v);
 showProgressDialog();
 
 showProgressDialog(@LayoutRes int resId);
 
 showProgressDialog(View v);

App中有主要源码使用示例。更多实用黑科技,请速速使用Base体会吧。

关于我

Name: Jenly

Email: [email protected] / [email protected]

CSDN: http://www.csdn.net/jenly121

Github: https://github.com/jenly1314

微信公众号:

公众号

加入QQ群: 20867961

License

Copyright © 2015, 2016 Jenly Yu 

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

base's People

Contributors

jenly1314 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.