Example #1
0
 public Bitmap createBitmap(Object image) {
   if (image instanceof TiBlob) {
     TiBlob blob = (TiBlob) image;
     return TiUIHelper.createBitmap(blob.getInputStream());
   } else if (image instanceof FileProxy) {
     FileProxy file = (FileProxy) image;
     try {
       return TiUIHelper.createBitmap(file.getBaseFile().getInputStream());
     } catch (IOException e) {
       Log.e(
           LCAT,
           "Error creating drawable from file: " + file.getBaseFile().getNativeFile().getName(),
           e);
     }
   } else if (image instanceof String) {
     String url = proxy.getTiContext().resolveUrl(null, (String) image);
     TiBaseFile file =
         TiFileFactory.createTitaniumFile(proxy.getTiContext(), new String[] {url}, false);
     try {
       return TiUIHelper.createBitmap(file.getInputStream());
     } catch (IOException e) {
       Log.e(LCAT, "Error creating drawable from path: " + image.toString(), e);
     }
   } else if (image instanceof TiDict) {
     TiBlob blob = TiUIHelper.getImageFromDict((TiDict) image);
     if (blob != null) {
       return TiUIHelper.createBitmap(blob.getInputStream());
     } else {
       Log.e(LCAT, "Couldn't find valid image in object: " + image.toString());
     }
   }
   return null;
 }
 @Override
 public void focus() {
   super.focus();
   if (nativeView != null) {
     if (proxy.hasProperty(TiC.PROPERTY_EDITABLE)
         && !(TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_EDITABLE)))) {
       TiUIHelper.showSoftKeyboard(nativeView, false);
     } else {
       TiUIHelper.requestSoftInputChange(proxy, nativeView);
     }
   }
 }
  @Kroll.method
  public void takeScreenshot(KrollFunction callback) {
    Activity a = TiApplication.getAppCurrentActivity();

    if (a == null) {
      Log.w(TAG, "Could not get current activity for takeScreenshot.", Log.DEBUG_MODE);
      callback.callAsync(getKrollObject(), new Object[] {null});
      return;
    }

    while (a.getParent() != null) {
      a = a.getParent();
    }

    Window w = a.getWindow();

    while (w.getContainer() != null) {
      w = w.getContainer();
    }

    KrollDict image = TiUIHelper.viewToImage(null, w.getDecorView());
    if (callback != null) {
      callback.callAsync(getKrollObject(), new Object[] {image});
    }
  }
Example #4
0
  @Override
  public void processProperties(TiDict d) {
    super.processProperties(d);

    TextView tv = (TextView) getNativeView();
    // Only accept one, prefer text to title.
    if (d.containsKey("text")) {
      tv.setText(TiConvert.toString(d, "text"));
    } else if (d.containsKey("title")) { // TODO this may not need to be supported.
      tv.setText(TiConvert.toString(d, "title"));
    }

    if (d.containsKey("color")) {
      tv.setTextColor(TiConvert.toColor(d, "color"));
    }
    if (d.containsKey("highlightedColor")) {
      tv.setHighlightColor(TiConvert.toColor(d, "highlightedColor"));
    }
    if (d.containsKey("font")) {
      TiUIHelper.styleText(tv, d.getTiDict("font"));
    }
    if (d.containsKey("textAlign")) {
      String textAlign = d.getString("textAlign");
      setAlignment(tv, textAlign);
    }
    tv.invalidate();
  }
Example #5
0
  @Kroll.method
  public TiBlob getFilteredImage(Object image, @Kroll.argument(optional = true) HashMap options) {
    String cacheKey = null;
    if (image instanceof String) {
      cacheKey = (String) image;
    } else if (image instanceof TiBlob) {
      cacheKey = ((TiBlob) image).getCacheKey();
    } else {
      cacheKey = java.lang.System.identityHashCode(image) + "";
    }
    Drawable drawable = TiUIHelper.buildImageDrawable(getActivity(), image, false, this);
    if (drawable == null) {
      return null;
    }

    Pair<Drawable, KrollDict> result = null;
    if (options != null) {
      if (options.containsKey("callback")) {
        KrollFunction callback = (KrollFunction) options.get("callback");
        options.remove("callback");
        if (callback != null) {
          (new FilterDrawableTask()).execute(this, drawable, options, callback);
          return null;
        }
      }
      result = TiImageHelper.drawableFiltered(drawable, options, cacheKey, false);
    }

    if (result != null) {
      TiBlob blob = TiBlob.blobFromObject(result.first);
      blob.addInfo(result.second);
      return blob;
    }
    return null;
  }
 @Override
 public void setOpacity(float opacity) {
   TiImageView view = getView();
   if (view != null) {
     view.setColorFilter(TiUIHelper.createColorFilterForOpacity(opacity));
     super.setOpacity(opacity);
   }
 }
Example #7
0
 public void onFocusChange(View v, boolean hasFocus) {
   if (hasFocus) {
     TiUIHelper.requestSoftInputChange(proxy, v);
     proxy.fireEvent(TiC.EVENT_FOCUS, getFocusEventObject(hasFocus));
   } else {
     proxy.fireEvent(TiC.EVENT_BLUR, getFocusEventObject(hasFocus));
   }
 }
 public void handleTextAlign(String textAlign, String verticalAlign) {
   if (verticalAlign == null) {
     verticalAlign = field ? "middle" : "top";
   }
   if (textAlign == null) {
     textAlign = "left";
   }
   TiUIHelper.setAlignment(tv, textAlign, verticalAlign);
 }
Example #9
0
 protected void setOpacity(View view, float opacity) {
   if (view != null) {
     TiUIHelper.setDrawableOpacity(view.getBackground(), opacity);
     if (opacity == 1) {
       clearOpacity(view);
     }
     view.invalidate();
   }
 }
  @Override
  /**
   * When this activity pauses, this method sets the current activity to null, fires a javascript
   * 'pause' event, and if the activity is finishing, remove all dialogs associated with it.
   */
  protected void onPause() {
    inForeground = false;
    super.onPause();
    isResumed = false;

    Log.d(TAG, "Activity " + this + " onPause", Log.DEBUG_MODE);

    TiApplication tiApp = getTiApp();
    if (tiApp.isRestartPending()) {
      releaseDialogs(true);
      if (!isFinishing()) {
        finish();
      }
      return;
    }

    if (!windowStack.empty()) {
      windowStack.peek().onWindowFocusChange(false);
    }

    TiApplication.updateActivityTransitionState(true);
    tiApp.setCurrentActivity(this, null);
    TiUIHelper.showSoftKeyboard(getWindow().getDecorView(), false);

    if (this.isFinishing()) {
      releaseDialogs(true);
    } else {
      // release non-persistent dialogs when activity hides
      releaseDialogs(false);
    }

    if (activityProxy != null) {
      activityProxy.fireSyncEvent(TiC.EVENT_PAUSE, null);
    }

    synchronized (lifecycleListeners.synchronizedList()) {
      for (OnLifecycleEvent listener : lifecycleListeners.nonNull()) {
        try {
          TiLifecycle.fireLifecycleEvent(this, listener, TiLifecycle.LIFECYCLE_ON_PAUSE);

        } catch (Throwable t) {
          Log.e(TAG, "Error dispatching lifecycle event: " + t.getMessage(), t);
        }
      }
    }

    // Checkpoint for ti.end event
    if (tiApp != null) {
      tiApp.postAnalyticsEvent(TiAnalyticsEventFactory.createAppEndEvent());
    }
  }
 public void setBackgroundImageProperty(TiDict d, String property) {
   String path = TiConvert.toString(d, property);
   String url = tiContext.resolveUrl(null, path);
   TiBaseFile file = TiFileFactory.createTitaniumFile(tiContext, new String[] {url}, false);
   try {
     setBackgroundDrawable(new BitmapDrawable(TiUIHelper.createBitmap(file.getInputStream())));
   } catch (IOException e) {
     Log.e(LCAT, "Error creating background image from path: " + path.toString(), e);
   }
 }
 private void updatePath() {
   if (bounds.isEmpty()) return;
   path = null;
   RectF outerRect = TiUIHelper.insetRect(boundsF, mPadding);
   if (radius != null) {
     path = new Path();
     path.setFillType(FillType.EVEN_ODD);
     if (pathWidth > 0) {
       path.addRoundRect(outerRect, radius, Direction.CW);
       float padding = 0;
       float maxPadding = 0;
       RectF innerRect = new RectF();
       maxPadding = Math.min(bounds.width() / 2, bounds.height() / 2);
       padding = Math.min(pathWidth, maxPadding);
       innerRect.set(
           outerRect.left + padding,
           outerRect.top + padding,
           outerRect.right - padding,
           outerRect.bottom - padding);
       path.addRoundRect(innerRect, innerRadiusFromPadding(outerRect, padding), Direction.CCW);
     } else {
       // adjustment not see background under border because of antialias
       path.addRoundRect(TiUIHelper.insetRect(outerRect, 0.3f), radius, Direction.CW);
     }
   } else {
     if (pathWidth > 0) {
       path = new Path();
       path.setFillType(FillType.EVEN_ODD);
       path.addRect(outerRect, Direction.CW);
       int padding = 0;
       int maxPadding = 0;
       RectF innerRect = new RectF();
       maxPadding = (int) Math.min(bounds.width() / 2, bounds.height() / 2);
       padding = (int) Math.min(pathWidth, maxPadding);
       innerRect.set(
           outerRect.left + padding,
           outerRect.top + padding,
           outerRect.right - padding,
           outerRect.bottom - padding);
       path.addRect(innerRect, Direction.CCW);
     }
   }
 }
Example #13
0
 // This handler callback is tied to the UI thread.
 public boolean handleMessage(Message msg) {
   switch (msg.what) {
     case MSG_GETVIEWIMAGE:
       {
         AsyncResult result = (AsyncResult) msg.obj;
         result.setResult(TiUIHelper.viewToBitmap(null, (View) result.getArg()));
         return true;
       }
   }
   return super.handleMessage(msg);
 }
Example #14
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));
         }
       });
 }
Example #15
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();
          }
        });
  }
Example #16
0
  private void handleBackgroundImage(KrollDict d) {
    String bg = d.getString(TiC.PROPERTY_BACKGROUND_IMAGE);
    String bgSelected = d.getString(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE);
    String bgFocused = d.getString(TiC.PROPERTY_BACKGROUND_FOCUSED_IMAGE);
    String bgDisabled = d.getString(TiC.PROPERTY_BACKGROUND_DISABLED_IMAGE);

    String bgColor = d.getString(TiC.PROPERTY_BACKGROUND_COLOR);
    String bgSelectedColor = d.getString(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR);
    String bgFocusedColor = d.getString(TiC.PROPERTY_BACKGROUND_FOCUSED_COLOR);
    String bgDisabledColor = d.getString(TiC.PROPERTY_BACKGROUND_DISABLED_COLOR);

    TiContext tiContext = getProxy().getTiContext();
    if (bg != null) {
      bg = tiContext.resolveUrl(null, bg);
    }
    if (bgSelected != null) {
      bgSelected = tiContext.resolveUrl(null, bgSelected);
    }
    if (bgFocused != null) {
      bgFocused = tiContext.resolveUrl(null, bgFocused);
    }
    if (bgDisabled != null) {
      bgDisabled = tiContext.resolveUrl(null, bgDisabled);
    }

    if (bg != null
        || bgSelected != null
        || bgFocused != null
        || bgDisabled != null
        || bgColor != null
        || bgSelectedColor != null
        || bgFocusedColor != null
        || bgDisabledColor != null) {
      if (background == null) {
        applyCustomBackground(false);
      }

      Drawable bgDrawable =
          TiUIHelper.buildBackgroundDrawable(
              tiContext,
              bg,
              bgColor,
              bgSelected,
              bgSelectedColor,
              bgDisabled,
              bgDisabledColor,
              bgFocused,
              bgFocusedColor);
      background.setBackgroundDrawable(bgDrawable);
    }
  }
Example #17
0
  private void handleBackgroundImage(KrollDict d) {
    String bg = d.getString(TiC.PROPERTY_BACKGROUND_IMAGE);
    String bgSelected = d.getString(TiC.PROPERTY_BACKGROUND_SELECTED_IMAGE);
    String bgFocused = d.getString(TiC.PROPERTY_BACKGROUND_FOCUSED_IMAGE);
    String bgDisabled = d.getString(TiC.PROPERTY_BACKGROUND_DISABLED_IMAGE);

    String bgColor = d.getString(TiC.PROPERTY_BACKGROUND_COLOR);
    String bgSelectedColor = d.getString(TiC.PROPERTY_BACKGROUND_SELECTED_COLOR);
    String bgFocusedColor = d.getString(TiC.PROPERTY_BACKGROUND_FOCUSED_COLOR);
    String bgDisabledColor = d.getString(TiC.PROPERTY_BACKGROUND_DISABLED_COLOR);

    if (bg != null) {
      bg = resolveImageUrl(bg);
    }
    if (bgSelected != null) {
      bgSelected = resolveImageUrl(bgSelected);
    }
    if (bgFocused != null) {
      bgFocused = resolveImageUrl(bgFocused);
    }
    if (bgDisabled != null) {
      bgDisabled = resolveImageUrl(bgDisabled);
    }

    if (bg != null
        || bgSelected != null
        || bgFocused != null
        || bgDisabled != null
        || bgColor != null
        || bgSelectedColor != null
        || bgFocusedColor != null
        || bgDisabledColor != null) {
      if (background == null) {
        applyCustomBackground(false);
      }

      Drawable bgDrawable =
          TiUIHelper.buildBackgroundDrawable(
              bg,
              d.getBoolean(TiC.PROPERTY_BACKGROUND_REPEAT),
              bgColor,
              bgSelected,
              bgSelectedColor,
              bgDisabled,
              bgDisabledColor,
              bgFocused,
              bgFocusedColor);

      background.setBackgroundDrawable(bgDrawable);
    }
  }
Example #18
0
  @Kroll.method
  public TiBlob getFilteredScreenshot(HashMap options) {
    if (options != null) {
      if (options.containsKey("callback")) {
        KrollFunction callback = (KrollFunction) options.get("callback");
        if (callback != null) {
          (new FilterScreenShotTask()).execute(options);
          return null;
        }
      }
    }

    //        View view = TiApplication.getAppCurrentActivity().getWindow()
    //                .getDecorView();
    View view =
        TiApplication.getAppCurrentActivity()
            .getWindow()
            .getDecorView()
            .findViewById(android.R.id.content);
    if (view == null) {
      return null;
    }

    Bitmap bitmap = null;
    try {
      if (TiApplication.isUIThread()) {
        bitmap = TiUIHelper.viewToBitmap(null, view);
      } else {
        bitmap =
            (Bitmap)
                TiMessenger.sendBlockingMainMessage(
                    getMainHandler().obtainMessage(MSG_GETVIEWIMAGE), view);
      }
      //            Rect statusBar = new Rect();
      //            view.getWindowVisibleDisplayFrame(statusBar);
      //            bitmap = Bitmap.createBitmap(bitmap, 0, statusBar.top,
      //                    bitmap.getWidth(), bitmap.getHeight() - statusBar.top,
      //                    null, true);
    } catch (Exception e) {
      bitmap = null;
    }
    return getFilteredImage(bitmap, options);
  }
 private void styleTextView(int position, TextView tv) {
   TiViewProxy rowProxy = (TiViewProxy) this.getItem(position);
   if (fontProperties != null) {
     TiUIHelper.styleText(
         tv,
         fontProperties[TiUIHelper.FONT_FAMILY_POSITION],
         fontProperties[TiUIHelper.FONT_SIZE_POSITION],
         fontProperties[TiUIHelper.FONT_WEIGHT_POSITION],
         fontProperties[TiUIHelper.FONT_STYLE_POSITION]);
   }
   if (!setDefaultTextColor) {
     defaultTextColor = tv.getCurrentTextColor();
     setDefaultTextColor = true;
   }
   if (rowProxy.hasProperty(TiC.PROPERTY_COLOR)) {
     final int color = TiConvert.toColor((String) rowProxy.getProperty(TiC.PROPERTY_COLOR));
     tv.setTextColor(color);
   } else {
     tv.setTextColor(defaultTextColor);
   }
 }
Example #20
0
 @Override
 public void propertyChanged(String key, Object oldValue, Object newValue, TiProxy proxy) {
   if (DBG) {
     Log.d(LCAT, "Property: " + key + " old: " + oldValue + " new: " + newValue);
   }
   TextView tv = (TextView) getNativeView();
   if (key.equals("text")) {
     tv.setText(TiConvert.toString(newValue));
     tv.requestLayout();
   } else if (key.equals("color")) {
     tv.setTextColor(TiConvert.toColor((String) newValue));
   } else if (key.equals("highlightedColor")) {
     tv.setHighlightColor(TiConvert.toColor((String) newValue));
   } else if (key.equals("textAlign")) {
     setAlignment(tv, TiConvert.toString(newValue));
     tv.requestLayout();
   } else if (key.equals("font")) {
     TiUIHelper.styleText(tv, (TiDict) newValue);
     tv.requestLayout();
   } else {
     super.propertyChanged(key, oldValue, newValue, proxy);
   }
 }
Example #21
0
 @Override
 protected TiBlob doInBackground(Object... params) {
   HashMap options = (HashMap) params[0];
   View view = TiApplication.getAppCurrentActivity().getWindow().getDecorView();
   Bitmap bitmap = null;
   try {
     bitmap = TiUIHelper.viewToBitmap(null, view);
     Rect statusBar = new Rect();
     view.getWindowVisibleDisplayFrame(statusBar);
     bitmap =
         Bitmap.createBitmap(
             bitmap,
             0,
             statusBar.top,
             bitmap.getWidth(),
             bitmap.getHeight() - statusBar.top,
             null,
             true);
   } catch (Exception e) {
     bitmap = null;
   }
   return getFilteredImage(bitmap, options);
 }
  @Override
  public void finish() {
    TiDict data = new TiDict();
    for (WeakReference<TiContext> contextRef : contexts) {
      if (contextRef.get() != null) {
        contextRef.get().dispatchEvent("close", data, proxy);
      }
    }

    if (createdContext != null && createdContext.get() != null) {
      createdContext.get().dispatchEvent("close", data, proxy);
    }

    boolean animate = true;
    Intent intent = getIntent();

    if (intent != null) {
      if (intent.getBooleanExtra("finishRoot", false)) {
        if (getApplication() != null) {
          TiApplication tiApp = getTiApp();
          if (tiApp != null) {
            TiRootActivity rootActivity = tiApp.getRootActivity();
            if (rootActivity != null) {
              rootActivity.finish();
            }
          }
        }
      }
      animate = intent.getBooleanExtra("animate", animate);
    }

    super.finish();
    if (!animate) {
      TiUIHelper.overridePendingTransition(this);
    }
  }
Example #23
0
  @Override
  public void processProperties(TiDict d) {
    super.processProperties(d);

    if (d.containsKey("enabled")) {
      tv.setEnabled(d.getBoolean("enabled"));
    }
    if (d.containsKey("value")) {
      tv.setText(d.getString("value"));
    }
    if (d.containsKey("color")) {
      tv.setTextColor(TiConvert.toColor(d, "color"));
    }
    if (d.containsKey("hintText")) {
      tv.setHint(d.getString("hintText"));
    }
    if (d.containsKey("font")) {
      TiUIHelper.styleText(tv, d.getTiDict("font"));
    }
    if (d.containsKey("textAlign") || d.containsKey("verticalAlign")) {
      String textAlign = null;
      String verticalAlign = null;
      if (d.containsKey("textAlign")) {
        textAlign = d.getString("textAlign");
      }
      if (d.containsKey("verticalAlign")) {
        verticalAlign = d.getString("verticalAlign");
      }
      handleTextAlign(textAlign, verticalAlign);
    }
    if (d.containsKey("returnKeyType")) {
      handleReturnKeyType(d.getInt("returnKeyType"));
    }
    if (d.containsKey("keyboardType")) {
      boolean autocorrect = true;
      if (d.containsKey("autocorrect")) {
        autocorrect = d.getBoolean("autocorrect");
      }
      handleKeyboardType(d.getInt("keyboardType"), autocorrect);
    }

    if (d.containsKey("autocapitalization")) {

      Capitalize autoCapValue = null;

      switch (d.getInt("autocapitalization")) {
        case TEXT_AUTOCAPITALIZATION_NONE:
          autoCapValue = Capitalize.NONE;
          break;

        case TEXT_AUTOCAPITALIZATION_ALL:
          autoCapValue = Capitalize.CHARACTERS;
          break;

        case TEXT_AUTOCAPITALIZATION_SENTENCES:
          autoCapValue = Capitalize.SENTENCES;
          break;

        case TEXT_AUTOCAPITALIZATION_WORDS:
          autoCapValue = Capitalize.WORDS;
          break;

        default:
          Log.w(
              LCAT, "Unknown AutoCapitalization Value [" + d.getString("autocapitalization") + "]");
          break;
      }

      if (null != autoCapValue) {
        tv.setKeyListener(TextKeyListener.getInstance(false, autoCapValue));
      }
    }

    if (d.containsKey("passwordMask")) {
      if (TiConvert.toBoolean(d.get("passwordMask"))) {
        // This shouldn't be needed but it's belts & braces
        tv.setKeyListener(TextKeyListener.getInstance(false, Capitalize.NONE));
        // Both setTransform & keyboard type are required
        tv.setTransformationMethod(PasswordTransformationMethod.getInstance());
        // We also need to set the keyboard type - otherwise the password mask won't be applied
        handleKeyboardType(KEYBOARD_PASSWORD, false);
      }
    }
  }
  private Intent createAlarmNotifyIntent(KrollDict args, int requestCode) {
    int notificationIcon = 0;
    String contentTitle = "";
    String contentText = "";
    String notificationSound = "";
    boolean playSound = optionIsEnabled(args, "playSound");
    boolean doVibrate = optionIsEnabled(args, "vibrate");
    boolean showLights = optionIsEnabled(args, "showLights");
    if (args.containsKeyAndNotNull(TiC.PROPERTY_CONTENT_TITLE)
        || args.containsKeyAndNotNull(TiC.PROPERTY_CONTENT_TEXT)) {
      if (args.containsKeyAndNotNull(TiC.PROPERTY_CONTENT_TITLE)) {
        contentTitle = TiConvert.toString(args, TiC.PROPERTY_CONTENT_TITLE);
      }
      if (args.containsKeyAndNotNull(TiC.PROPERTY_CONTENT_TEXT)) {
        contentText = TiConvert.toString(args, TiC.PROPERTY_CONTENT_TEXT);
      }
      ;
    }

    if (args.containsKey(TiC.PROPERTY_ICON)) {
      Object icon = args.get(TiC.PROPERTY_ICON);
      if (icon instanceof Number) {
        notificationIcon = ((Number) icon).intValue();
      } else {
        String iconUrl = TiConvert.toString(icon);
        String iconFullUrl = resolveUrl(null, iconUrl);
        notificationIcon = TiUIHelper.getResourceId(iconFullUrl);
        if (notificationIcon == 0) {
          utils.debugLog("No image found for " + iconUrl);
          utils.debugLog("Default icon will be used");
        }
      }
    }

    if (args.containsKey(TiC.PROPERTY_SOUND)) {
      notificationSound = TiConvert.toString(args, TiC.PROPERTY_SOUND);
    }

    if (args.containsKey("rootActivity")) {
      rootActivityClassName = TiConvert.toString(args, "rootActivity");
    }

    Intent intent =
        new Intent(
            TiApplication.getInstance().getApplicationContext(), AlarmNotificationListener.class);
    // Add some extra information so when the alarm goes off we have enough to create the
    // notification
    intent.putExtra("notification_title", contentTitle);
    intent.putExtra("notification_msg", contentText);
    intent.putExtra("notification_has_icon", (notificationIcon != 0));
    intent.putExtra("notification_icon", notificationIcon);
    intent.putExtra("notification_sound", notificationSound);
    intent.putExtra("notification_play_sound", playSound);
    intent.putExtra("notification_vibrate", doVibrate);
    intent.putExtra("notification_show_lights", showLights);
    intent.putExtra("notification_requestcode", requestCode);
    intent.putExtra("notification_root_classname", rootActivityClassName);
    intent.putExtra("notification_request_code", requestCode);
    intent.setData(Uri.parse("alarmId://" + requestCode));
    return intent;
  }
Example #25
0
 public void blur() {
   if (nativeView != null) {
     TiUIHelper.showSoftKeyboard(nativeView, false);
     nativeView.clearFocus();
   }
 }
Example #26
0
 public KrollDict toImage() {
   return TiUIHelper.viewToImage(proxy.getProperties(), getNativeView());
 }
 @Override
 public KrollDict handleToImage() {
   return TiUIHelper.viewToImage(
       getTiContext(), this.properties, getTiContext().getActivity().getWindow().getDecorView());
 }
 @Override
 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
   super.onLayout(changed, left, top, right, bottom);
   TiUIHelper.firePostLayoutEvent(proxy);
 }
  @Override
  public void processProperties(KrollDict d) {
    super.processProperties(d);

    if (d.containsKey(TiC.PROPERTY_ENABLED)) {
      tv.setEnabled(TiConvert.toBoolean(d, TiC.PROPERTY_ENABLED, true));
    }

    if (d.containsKey(TiC.PROPERTY_MAX_LENGTH) && field) {
      maxLength = TiConvert.toInt(d.get(TiC.PROPERTY_MAX_LENGTH), -1);
    }

    // Disable change event temporarily as we are setting the default value
    disableChangeEvent = true;
    if (d.containsKey(TiC.PROPERTY_VALUE)) {
      tv.setText(d.getString(TiC.PROPERTY_VALUE));
    } else {
      tv.setText("");
    }
    disableChangeEvent = false;

    if (d.containsKey(TiC.PROPERTY_COLOR)) {
      tv.setTextColor(TiConvert.toColor(d, TiC.PROPERTY_COLOR));
    }

    if (d.containsKey(TiC.PROPERTY_HINT_TEXT)) {
      tv.setHint(d.getString(TiC.PROPERTY_HINT_TEXT));
    }

    if (d.containsKey(TiC.PROPERTY_ELLIPSIZE)) {
      if (TiConvert.toBoolean(d, TiC.PROPERTY_ELLIPSIZE)) {
        tv.setEllipsize(TruncateAt.END);
      } else {
        tv.setEllipsize(null);
      }
    }

    if (d.containsKey(TiC.PROPERTY_FONT)) {
      TiUIHelper.styleText(tv, d.getKrollDict(TiC.PROPERTY_FONT));
    }

    if (d.containsKey(TiC.PROPERTY_TEXT_ALIGN) || d.containsKey(TiC.PROPERTY_VERTICAL_ALIGN)) {
      String textAlign = null;
      String verticalAlign = null;
      if (d.containsKey(TiC.PROPERTY_TEXT_ALIGN)) {
        textAlign = d.getString(TiC.PROPERTY_TEXT_ALIGN);
      }
      if (d.containsKey(TiC.PROPERTY_VERTICAL_ALIGN)) {
        verticalAlign = d.getString(TiC.PROPERTY_VERTICAL_ALIGN);
      }
      handleTextAlign(textAlign, verticalAlign);
    }

    if (d.containsKey(TiC.PROPERTY_RETURN_KEY_TYPE)) {
      handleReturnKeyType(TiConvert.toInt(d.get(TiC.PROPERTY_RETURN_KEY_TYPE), RETURNKEY_DEFAULT));
    }

    if (d.containsKey(TiC.PROPERTY_KEYBOARD_TYPE)
        || d.containsKey(TiC.PROPERTY_AUTOCORRECT)
        || d.containsKey(TiC.PROPERTY_PASSWORD_MASK)
        || d.containsKey(TiC.PROPERTY_AUTOCAPITALIZATION)
        || d.containsKey(TiC.PROPERTY_EDITABLE)) {
      handleKeyboard(d);
    }

    if (d.containsKey(TiC.PROPERTY_AUTO_LINK)) {
      TiUIHelper.linkifyIfEnabled(tv, d.get(TiC.PROPERTY_AUTO_LINK));
    }
  }
 @Override
 public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
   if (Log.isDebugModeEnabled()) {
     Log.d(TAG, "Property: " + key + " old: " + oldValue + " new: " + newValue, Log.DEBUG_MODE);
   }
   if (key.equals(TiC.PROPERTY_ENABLED)) {
     tv.setEnabled(TiConvert.toBoolean(newValue));
   } else if (key.equals(TiC.PROPERTY_VALUE)) {
     tv.setText(TiConvert.toString(newValue));
   } else if (key.equals(TiC.PROPERTY_MAX_LENGTH)) {
     maxLength = TiConvert.toInt(newValue);
     // truncate if current text exceeds max length
     Editable currentText = tv.getText();
     if (maxLength >= 0 && currentText.length() > maxLength) {
       CharSequence truncateText = currentText.subSequence(0, maxLength);
       int cursor = tv.getSelectionStart() - 1;
       if (cursor > maxLength) {
         cursor = maxLength;
       }
       tv.setText(truncateText);
       tv.setSelection(cursor);
     }
   } else if (key.equals(TiC.PROPERTY_COLOR)) {
     tv.setTextColor(TiConvert.toColor((String) newValue));
   } else if (key.equals(TiC.PROPERTY_HINT_TEXT)) {
     tv.setHint((String) newValue);
   } else if (key.equals(TiC.PROPERTY_ELLIPSIZE)) {
     if (TiConvert.toBoolean(newValue)) {
       tv.setEllipsize(TruncateAt.END);
     } else {
       tv.setEllipsize(null);
     }
   } else if (key.equals(TiC.PROPERTY_TEXT_ALIGN) || key.equals(TiC.PROPERTY_VERTICAL_ALIGN)) {
     String textAlign = null;
     String verticalAlign = null;
     if (key.equals(TiC.PROPERTY_TEXT_ALIGN)) {
       textAlign = TiConvert.toString(newValue);
     } else if (proxy.hasProperty(TiC.PROPERTY_TEXT_ALIGN)) {
       textAlign = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_TEXT_ALIGN));
     }
     if (key.equals(TiC.PROPERTY_VERTICAL_ALIGN)) {
       verticalAlign = TiConvert.toString(newValue);
     } else if (proxy.hasProperty(TiC.PROPERTY_VERTICAL_ALIGN)) {
       verticalAlign = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_VERTICAL_ALIGN));
     }
     handleTextAlign(textAlign, verticalAlign);
   } else if (key.equals(TiC.PROPERTY_KEYBOARD_TYPE)
       || (key.equals(TiC.PROPERTY_AUTOCORRECT)
           || key.equals(TiC.PROPERTY_AUTOCAPITALIZATION)
           || key.equals(TiC.PROPERTY_PASSWORD_MASK)
           || key.equals(TiC.PROPERTY_EDITABLE))) {
     KrollDict d = proxy.getProperties();
     handleKeyboard(d);
   } else if (key.equals(TiC.PROPERTY_RETURN_KEY_TYPE)) {
     handleReturnKeyType(TiConvert.toInt(newValue));
   } else if (key.equals(TiC.PROPERTY_FONT)) {
     TiUIHelper.styleText(tv, (HashMap) newValue);
   } else if (key.equals(TiC.PROPERTY_AUTO_LINK)) {
     TiUIHelper.linkifyIfEnabled(tv, newValue);
   } else {
     super.propertyChanged(key, oldValue, newValue, proxy);
   }
 }