ActivityStarter


Source link: https://github.com/MarcinMoskala/ActivityStarter

ActivityStarter

Android Library that provides simpler way to start the Activities with multiple arguments.

Library bindes fields to Actity, Fragment, Service or Receiver arguments and generates simple starters. Thanks to that you can:

  • Eliminate all putExtra and getXXXExtra methods
  • Forget about all keys that were used to pass arguments (unless you want to define custom onces)
  • Start liking starting flags and intent creation

Full documentation is located here. Here is TOC:

To stay up-to-date with news about library

Example

With ActivityStarter, to pass arguments to Activity, Fragment, Service or BroadcastReceiver, all you need is @Arg annotation before parameters that needs to be passed:

public class MainActivity extends BaseActivity {

@Arg String name;
  @Arg int id;
  @Arg char grade;
  @Arg boolean passing; 
}

And ActivityStarter.fill(this); in BaseActivity:

class BaseActivity extends AppCompatActivity {

@Override
  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ActivityStarter.fill(this);

  
}

@Override // This is optional, only when we want to keep arguments changes in case of rotation etc.
  protected void onSaveInstanceState(Bundle outState) {

super.onSaveInstanceState(outState);

ActivityStarter.save(this);

  
}
 
}

Then, you can start Activity using generated starter:

MainActivityStarter.start(context, name, id, grade, passing);

Similar way, you can take Intent or start activity with flags:

MainActivityStarter.getIntent(context, name, id, grade, passing);
 MainActivityStarter.startWithFlags(context, name, id, grade, passing, FLAG_ACTIVITY_SINGLE_TOP);

Arguments can be passed to Activities, Fragments, Services or BroadcastReceiver. Arguments can also be Optional.

Optional

You can make optional arguments:

public class MainActivity extends BaseActivity {

@Arg(optional = true) String name;
  @Arg(optional = true) long id = -1; 
}

Then additional generators with not all arguments will be created

MainActivityStarter.start(context);
 MainActivityStarter.start(context, name);
 MainActivityStarter.start(context, id);
 MainActivityStarter.start(context, name, id);

Further reading here.

Kotlin

ActivityStarter is supporting Kotlin to allow properties that are not-null and both read-write or read-only:

class StudentDataActivity : BaseActivity() {

@get:Arg(optional = true) var name: String by argExtra(defaultName)
  @get:Arg(optional = true) val id: Int by argExtra(defaultId)
  @get:Arg var grade: Char  by argExtra()
  @get:Arg val passing: Boolean by argExtra() 
}

Values are taken lazily and kept as fields, but there are still saved if ActivityStarter.save(this) is called in onSaveInstanceState. When all properties are provided by delegate, then there is no need to call ActivityStarter.fill(this) in onCreate.

Parceler

Since version 0.70, there is native support for Parceler library. To wrap and unwrap parameter using Parceler, use Arg annotation with parceler property set to true:

@Arg(parceler = true) StudentParcel studentParceler; 

See example here.

Installation

For Java project add in build.gradle file:

dependencies {

  compile 'com.marcinmoskala.activitystarter:activitystarter:1.00'
  apt 'com.marcinmoskala.activitystarter:activitystarter-compiler:1.00' 
}

For Kotlin project add in build.gradle file:

apply plugin: 'kotlin-kapt'  dependencies {

  compile 'com.marcinmoskala.activitystarter:activitystarter:1.00'
  kapt 'com.marcinmoskala.activitystarter:activitystarter-compiler:1.00' 
}

If you want to use Kotlin-specific elements (property delegate argExtra), then add in build.gradle file:

apply plugin: 'kotlin-kapt'  dependencies {

  compile 'com.marcinmoskala.activitystarter:activitystarter:1.00'
  compile 'com.marcinmoskala.activitystarter:activitystarter-kotlin:1.00'
  kapt 'com.marcinmoskala.activitystarter:activitystarter-compiler:1.00' 
}

And while library is located on JitPack, remember to add on module build.gradle (unless you already have it):

repositories {

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

More information on Installation page.

Other libraries

If you like it, remember to leave the star and check out my other libraries:

  • PreferenceHolder - Library for simple SharedPreference management in Kotlin
  • ArcSeekBar - Good looking curved Android SeekBar
  • VideoPlayView - Custom Android view with video player, loader and placeholder image
  • KotlinAndroidViewBindings - Bindings for properties with simple Kotlin types (Boolean, String) to layout traits (visibility, text).

License

Copyright 2017 Marcin Moska?a  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. 

Resources

SpannedGridLayouManager is a layout manager that will resize and reorder views based on a provided SpanSize.

Photo Editor SDK contains a lot of features like edit, scale, rotate and draw on images like Instagram stories.

A reactive layer on top of universal image loader (easy and hassle-free) using RxJava 2.

A fluent tooltip for Android.

In shortest terms, Silly Android is a set of most commonly used workarounds, fixes and utilities, all of which should have been included in the core Android framework by default. When you find yourself asking questions like "Why is this simple task so complicated to do?" or "How was this not done by default?" - Silly Android should be the help you need.

A utils class that help load image from content provider using glide.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes