Exemplo n.º 1
0
 // Methods
 @Kroll.method
 public void showText(final String text, final int style) {
   Log.d(TAG, "showText called");
   TiUIHelper.runUiDelayedIfBlock(
       new Runnable() {
         @Override
         public void run() {
           Crouton.showText(
               TiApplication.getInstance().getCurrentActivity(), text, getStyle(style));
         }
       });
 }
Exemplo n.º 2
0
  @Kroll.method
  public void show(KrollDict args) {
    Log.d(TAG, "show called");

    final Crouton crouton;

    Activity activity;
    String text = "";
    Style style = null;
    Builder config = new Configuration.Builder();

    if (args.containsKey(TiC.PROPERTY_ACTIVITY)) {
      ActivityProxy activityProxy = (ActivityProxy) args.get(TiC.PROPERTY_ACTIVITY);
      activity = activityProxy.getActivity();
    } else {
      activity = TiApplication.getInstance().getCurrentActivity();
    }

    if (args.containsKey(TiC.PROPERTY_TEXT)) {
      text = TiConvert.toString(args.get(TiC.PROPERTY_TEXT));
    }

    if (args.containsKey(TiC.PROPERTY_STYLE)) {
      style = getStyle(TiConvert.toInt(args.get(TiC.PROPERTY_STYLE)));
    }

    if (args.containsKey(TiC.PROPERTY_COLOR)) {

      String color = (String) args.get(TiC.PROPERTY_COLOR);

      style = new Style.Builder().setBackgroundColorValue(TiConvert.toColor(color)).build();
    }

    if (style == null) {
      style = Style.INFO;
    }

    crouton = Crouton.makeText(activity, text, style);

    if (args.containsKey(TiC.PROPERTY_DURATION)) {
      config.setDuration(TiConvert.toInt(args.get(TiC.PROPERTY_DURATION)));
      crouton.setConfiguration(config.build());
    }

    TiUIHelper.runUiDelayedIfBlock(
        new Runnable() {
          @Override
          public void run() {
            crouton.show();
          }
        });
  }