Android Open Source - goodintentions Intention Launcher






From Project

Back to project page goodintentions.

License

The source code is released under:

Apache License

If you think the Android project goodintentions listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.luboganev.goodintentions;
//from ww w. j a va2  s . c o  m
import android.app.Activity;
import android.content.Context;

import com.luboganev.goodintentions.data.Intention;

public class IntentionLauncher {
  public static final int START_FOR_RESULT_DEFAULT_CODE = 101;
  
  public static String launchIntention(Activity activity, Intention intention) {
    final Context launchContext = intention.contextType == Intention.INTENTION_LAUNCH_CONTEXT_ACTIVITY ?
        activity : activity.getApplicationContext();
    switch (intention.type) {
    case Intention.INTENTION_TYPE_ACTIVITY:
      try {
        launchContext.startActivity(intention.buildIntent());
      } catch (Exception e) {
        return e.getMessage();
      }
      break;
    case Intention.INTENTION_TYPE_ACTIVITY_FOR_RESULT:
      try {
        if(intention.contextType != Intention.INTENTION_LAUNCH_CONTEXT_ACTIVITY) {
          return "Start activity for result requires activity context!";
        }
        activity.startActivityForResult(intention.buildIntent(), START_FOR_RESULT_DEFAULT_CODE);
      } catch (Exception e) {
        return e.getMessage();
      }
      break;
    case Intention.INTENTION_TYPE_SERVICE:
      try {
        launchContext.sendBroadcast(intention.buildIntent());
      } catch (Exception e) {
        return e.getMessage();
      }
      break;
    case Intention.INTENTION_TYPE_BROADCAST:
      try {
        launchContext.startService(intention.buildIntent());
      } catch (Exception e) {
        return e.getMessage();
      }
      break;
    default:
      break;
    }
    return null;
  }
}




Java Source Code List

com.luboganev.goodintentions.IntentionLauncher.java
com.luboganev.goodintentions.LogUtils.java
com.luboganev.goodintentions.UIUtils.java
com.luboganev.goodintentions.data.Intention.java
com.luboganev.goodintentions.data.LocalStorageManager.java
com.luboganev.goodintentions.data.LocalStorage.java
com.luboganev.goodintentions.ui.AboutActivity.java
com.luboganev.goodintentions.ui.MainActivity$$ViewInjector.java
com.luboganev.goodintentions.ui.MainActivity.java
com.luboganev.goodintentions.ui.views.IntentionCategoriesLinearLayout$$ViewInjector.java
com.luboganev.goodintentions.ui.views.IntentionCategoriesLinearLayout.java
com.luboganev.goodintentions.ui.views.IntentionFlagsLinearLayout$$ViewInjector.java
com.luboganev.goodintentions.ui.views.IntentionFlagsLinearLayout.java