Esempio n. 1
0
 @Override
 public void eventListenerRemoved(String eventName, int count, KrollProxy proxy) {
   super.eventListenerRemoved(eventName, count, proxy);
   if (eventName.equals(TiC.EVENT_CLICK)
       && count == 0
       && proxy.equals(this)
       && !(proxy instanceof TiWindowProxy)) {
     if (proxy.hasProperty(TiC.PROPERTY_TOUCH_ENABLED)
         && !TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_TOUCH_ENABLED))) {
       setClickable(false);
     }
   }
 }
Esempio n. 2
0
  protected void initialize() throws IOException {
    try {
      mp = new MediaPlayer();
      String url = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_URL));
      if (URLUtil.isAssetUrl(url)) {
        Context context = proxy.getTiContext().getTiApp();
        String path = url.substring(TiConvert.ASSET_URL.length());
        AssetFileDescriptor afd = null;
        try {
          afd = context.getAssets().openFd(path);
          // Why mp.setDataSource(afd) doesn't work is a problem for another day.
          // http://groups.google.com/group/android-developers/browse_thread/thread/225c4c150be92416
          mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        } catch (IOException e) {
          Log.e(LCAT, "Error setting file descriptor: ", e);
        } finally {
          if (afd != null) {
            afd.close();
          }
        }
      } else {
        Uri uri = Uri.parse(url);
        if (uri.getScheme().equals(TiC.PROPERTY_FILE)) {
          mp.setDataSource(uri.getPath());
        } else {
          remote = true;
          mp.setDataSource(url);
        }
      }

      mp.setLooping(looping);
      mp.setOnCompletionListener(this);
      mp.setOnErrorListener(this);
      mp.setOnInfoListener(this);
      mp.setOnBufferingUpdateListener(this);

      mp.prepare(); // Probably need to allow for Async
      setState(STATE_INITIALIZED);

      setVolume(volume);
      if (proxy.hasProperty(TiC.PROPERTY_TIME)) {
        setTime(TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_TIME)));
      }
    } catch (Throwable t) {
      Log.w(LCAT, "Issue while initializing : ", t);
      release();
      setState(STATE_STOPPED);
    }
  }
 @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);
   }
 }