Giter Club home page Giter Club logo

camper's Introduction

Intent Builder

Some useful builders and utilities.

Install

Install from gradle using jcenter.

repositories {
    jcenter()
}

dependencies {
    compile "org.fmedlin:camper:0.1.0"
}

Examples

Start an explicit Activity

public class MainActivity {
  public void doit() {
    Intent intent = IntentBuilder.start(TargetActivity.class)
      .extra(EXTRA_ITEM, item)
      .extra(EXTRA_ID, 2L)
      .build();

    startActivity(this, intent);
  }
}

IntentBuilder can also start the activity

public class MainActivity {
  public void doit() {
    Intent intent = IntentBuilder.start(TargetActivity.class)
      .from(this)
      .extra(EXTRA_ITEM, item)
      .extra(EXTRA_ID, 2L)
      .execute();
  }
}

Create implicit Intents

Intent intent = IntentBuilder.with(Intent.ACTION_VIEW, Uri.parse("http://google.com"))
  .build();

Or:

Intent intent = IntentBuilder.with(Intent.ACTION_VIEW)
  .data(Uri.parse("http://google.com"))
  .build();

Or:

Intent intent = IntentBuilder.with(Uri.parse("http://google.com"))
  .action(Intent.ACTION_VIEW)
  .build();

Load up on extras

Intent intent = IntentBuilder.with(this)
  .action(ACTION_SEND)
  .type("text/plain")
  .extra(EXTRA_EMAIL, "[email protected]")
  .extra(EXTRA_SUBJECT, "Please read")
  .extra(EXTRA_ID, 2L)
  .extra(EXTRA_PCT_COMPLETE, 3.141f)
  .extra(EXTRA_IS_EXTRA, true)
  .extra(EXTRA_STATUS, (Serializable) "Likes to read email")
  .category(Intent.CATEGORY_HOME, Intent.CATEGORY_BROWSABLE)
  .flags(Intent.FLAG_ACTIVITY_NO_ANIMATION, Intent.FLAG_ACTIVITY_NO_HISTORY)
  .fillIn(intent, fillInFlags)
  .build();

Copy constructor

public Intent copyIntent(Intent original, String emailAddress) {
  return IntentBuilder.copy(original)
    .extra(EXTRA_EMAIL, emailAddress)
    .build();

Choosers

Start a chooser on the intent if it resolves

IntentBuilder.with(Intent.ACTION_SEND)
  .chooser(getString(R.string.chooser_title))
  .execute(context, getPackageManager())
  .onResolveFailure(listener)
  .execute()

or just construct the chooser intent

Intent chooserIntent = IntentBuilder.with(Intent.ACTION_SEND)
  .chooser(getString(R.string.chooser_title))
  .build()

// I am responsible for resolving the activity.
startActivity(chooserIntent);

Todo

  • Add all extra types
  • Improve README
  • Add bintray javadocs and sources
  • Add choosers to builder and sample
  • Add travis.yml
  • Add categories, flags, fillIns
  • 0.2
  • Add live template xml file
  • Add intent reader class
  • 0.3
  • Add bundle builder class
  • 0.4

Contributing

  • Clone the project
  • Run unit tests with ./gradlew test
  • Make a pull request with your changes, including tests.

License

Copyright 2016 by Fred Medlin.

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.

camper's People

Contributors

fmedlin avatar

Watchers

 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.