All Projects → kobakei → grenade

kobakei / grenade

Licence: Apache-2.0 License
[DEPRECATED] Annotation based intent builder for Android activities and services

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to grenade

better-serializer
General serializer for PHP. An alternative to JmsSerializer.
Stars: ✭ 27 (-3.57%)
Mutual labels:  annotations
WebClipChangeAppLogo
iOS14利用WebClip更换图标,做到无缝启动App
Stars: ✭ 47 (+67.86%)
Mutual labels:  intent
Flow
Android wrapper to simplify process for start an Activity
Stars: ✭ 54 (+92.86%)
Mutual labels:  intent
CrowdTruth-core
CrowdTruth framework for crowdsourcing ground truth for training & evaluation of AI systems
Stars: ✭ 45 (+60.71%)
Mutual labels:  annotations
AutoBindings
Set of annotations that aims to make your Android development experience easier along with lint checks.
Stars: ✭ 15 (-46.43%)
Mutual labels:  annotations
dagger2-ktx
Kotlin extension bridge library for Dagger2 (proof-of-concept)
Stars: ✭ 41 (+46.43%)
Mutual labels:  annotations
grpc-jwt-spring-boot-starter
Spring boot starter for gRPC framework with JWT authorization
Stars: ✭ 24 (-14.29%)
Mutual labels:  annotations
WinAnalytics
A light-weight android library that can be quickly integrated into any app to use analytics tools.
Stars: ✭ 23 (-17.86%)
Mutual labels:  annotations
IntDefs
Android constants wrapped in @IntDef annotations
Stars: ✭ 17 (-39.29%)
Mutual labels:  annotations
SingleFile-Lite
Feel the power of the Manifest V3. The future, right now!
Stars: ✭ 55 (+96.43%)
Mutual labels:  annotations
trails-proposal
Proposal for a method to create trails using the Web Annotation Data Model
Stars: ✭ 25 (-10.71%)
Mutual labels:  annotations
super-csv-annotation
'Super CSV' extention library for annotation
Stars: ✭ 29 (+3.57%)
Mutual labels:  annotations
videojs-annotation-comments
A plugin for video.js to add support for timeline moment/range comments and annotations
Stars: ✭ 129 (+360.71%)
Mutual labels:  annotations
tfvars-annotations
[not-WIP] Update values in terraform.tfvars using annotations
Stars: ✭ 20 (-28.57%)
Mutual labels:  annotations
py2puml
Generate PlantUML class diagrams to document your Python application.
Stars: ✭ 51 (+82.14%)
Mutual labels:  annotations
intentanimation
animattion between activities
Stars: ✭ 117 (+317.86%)
Mutual labels:  intent
SonataAnnotationBundle
Annotations for Sonata Admin
Stars: ✭ 23 (-17.86%)
Mutual labels:  annotations
memo
Android processing and secured library for managing SharedPreferences as key-value elements efficiently and structurally.
Stars: ✭ 18 (-35.71%)
Mutual labels:  annotations
pandas-stubs
Pandas type stubs. Helps you type-check your code.
Stars: ✭ 84 (+200%)
Mutual labels:  annotations
spring4-hibernate5-example
Spring 4 and Hibernate 5 integration example using annotations.
Stars: ✭ 16 (-42.86%)
Mutual labels:  annotations

Grenade (Deprecated)

Now I don't have time to maintain this library. By using Kotlin (especially delegated property), we can put and get intent extra as type safe way without this libary.

Build Status JitPack Android Arsenal

Grenade is annotation based intent builder for activities and services. By using this library, you can build Intent with extras and retrieve extras by type safe way and less code.

This library is strongly inspired by emilsjolander/IntentBuilder but some advanced features are added.

Download

Project build.gradle

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

App build.gradle

dependencies {
    ...
    annotationProcessor 'com.github.kobakei.grenade:processor:LATEST_VERSION'
    compile 'com.github.kobakei.grenade:library:LATEST_VERSION'
}

LATEST_VERSION is JitPack

NOTE: if you use Android Gradle Plugin before 2.2.0, you must use android-apt plugin instead of annotationProcessor configuration.

Basic usage

Add @Navigator annotation to activity and @Extra annotation to fields.

@Navigator
public class DetailActivity extends AppCompatActivity {

    // Required params
    @Extra
    String foo;
    @Extra
    int bar;

    // Optional params
    @Extra @Optional
    String hoge;
    @Extra @Optional
    boolean fuga;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}

Once you build, DetailActivityNavigator will be generated. Building intent to launch DetailActivity is as below.

// Build intent and start activity
startActivity(new DetailActivityNavigator(foo, bar)
    .hoge(hoge)
    .fuga(fuga)
    .flags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
    .build(context);

And handling intent is as below.

@Navigator
public class DetailActivity extends AppCompatActivity {

    ...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Inject fields
        DetailActivityNavigator.inject(this, getIntent());
    }
}

Of course, you can use Grenade to start Service and BroadcastReceiver as same way.

@Navigator
public class MyIntentService extends IntentService{

    @Extra
    String foo;
    @Extra
    String baz;

    @Override
    protected void onHandleIntent(Intent intent) {
      MyIntentServiceNavigator.inject(this, intent);
    }
}

// Code to start service
startService(new MyIntentServiceNavigator("foo", "baz").build(this));

Multiple constructors

By specifying fields in @Navigator annotation, multiple constructors with different set of required params will be generated.

@Navigator({
    "foo,bar1",
    "foo,bar2"
})
public class DetailActivity extends AppCompatActivity {
    @Extra
    String foo;
    @Extra
    int bar1;
    @Extra
    long bar2;

    ...
}

You can use them as below.

startActivity(new DetailActivityNavigator(foo, bar1)
    .build(context));
startActivity(new DetailActivityNavigator(foo, bar2)
    .build(context));

Handling onActivityResult

Setting Intent object to onActivityResult has the same problem as above. Grenade offers APIs to build Intent to pass setResult and to handle onActivityResult as type safe way.

As an example, let's think about handling DetailActivity's result in MasterActivity.

At first, in MasterActivity, add method to handle result of DetailActivity with @OnActivityResult annotation. Moreover, call MasterActivityNavigator.onActivityResult in onActivityResult.

@OnActivityResult(requestCode = REQ_CODE_DETAIL1, resultCodes = {Activity.RESULT_OK})
void onDetailOk(String foo, int bar) {
    Toast.makeText(this, "Detail OK", Toast.LENGTH_SHORT).show();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    MainActivityNavigator.onActivityResult(this, requestCode, resultCode, data);
}

In DetailActivity, setting result is as below:

setResult(RESULT_OK, MainActivityNavigator.resultForOnDetailOk("Hello", 123));
finish();

Once you build, putting extras and getting extras will be done in MainActivityNavigator.

Built-in support of Parceler

Parceler is a famous library to generate Parcelable reader/writer. Grenade offers build-in support of Parceler. When field type has @Parcel annotation, Grenade will wrap/unwrap an entity with Parceler. To install Parceler to your project, please read Parceler's README.

// Entity class with @Parcel annotation
@Parcel
public class User {
    ...
}
@Navigator
public class DetailActivity extends AppCompatActivity {
    // Use parcelable entity as field
    @Extra
    User user;
    ...
}
startActivity(new DetailActivityNavigator(new User())
    .build(context));

ProGuard

If you use Grenade with Parceler, ProGuard setting of Parceler is needed.

License

Copyright 2016 Keisuke Kobayashi

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].