Code Monkey home page Code Monkey logo

tack's Introduction

Tack

Tack是一款简单、快捷、轻量级的Bundle数据注入和存储的扩展框架

使用Tack,你可以实现:

  1. 从Bundle\Intent读取常用数据类型数据
  2. 向Bundle\Intent存入常用数据类型数据
  3. 从Bundle\Intent读取数据并注入到Activity中的变量
  4. 从Bundle\Intent读取数据并注入到Fragment中的变量
  5. 通过工厂更方便的创建Bundle,避免硬编码

依赖

添加JitPack仓库

maven { url 'https://jitpack.io' }

添加依赖

dependencies {
	annotationProcessor 'com.github.kayoSun.Tack:tackprocessor:${lastversion}'
	implementation 'com.github.kayoSun.Tack:tackapi:${lastversion}'
}

混淆配置

-keep class com.kayo.lib.tack.annos.**
-keep class * extends com.kayo.lib.tack.api.ITackImpl
-keepclasseswithmembernames class * {
    @com.kayo.lib.tack.annos.* <fields>;
}

使用

1.为Activity变量注入数据,可以设置key,如果不设置key,则取变量名

public class MainActivity extends AppCompatActivity {

    //注入数据,key为agr1
    @Paste
    String agr1;

    //注入数据,key为您指定的name
    @Paste("name")
    String agr2;

    @Inject//注入数据
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

2.Fragment同Acticity

public class MainFragment extends Fragment {

    //注入数据,key为agr1
    @Paste
    String agr1;

    //注入数据,key为您指定的name
    @Paste("name")
    String agr2;

    @Inject//注入数据
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
       super.onViewCreated(view, savedInstanceState);
    }
}

3.您可以用指定数据类型注解,可以设置默认值

支持的注解

Annotation Data Type
PasteB byte
PasteD double
PasteF float
PasteI int
PasteL long
PasteS String
Paste any
public class MainActivity extends AppCompatActivity {

    //指定String类型注解,默认值为abc
    @PasteS(defaultVar = "abc")
    String agr1;

    ... ...
}

Gradle版本注意事项

Tack version Android Projects
0.0.2 Gradle 4.6
0.0.3 Gradle 4.6
1.0.0 Gradle 6.+

联系作者

欢迎提issue

License

Copyright 2018 Kayo

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.

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.