/**
   * Creates a new TextMessage component.
   *
   * @param container ignored (because this is a non-visible component)
   */
  public Texting(ComponentContainer container) {
    super(container.$form());
    Log.d(TAG, "Texting constructor");
    Texting.component = (Texting) this;
    activity = container.$context();

    SharedPreferences prefs = activity.getSharedPreferences(PREF_FILE, Activity.MODE_PRIVATE);
    if (prefs != null) {
      receivingEnabled = prefs.getBoolean(PREF_RCVENABLED, true);
      googleVoiceEnabled = prefs.getBoolean(PREF_GVENABLED, false);
      Log.i(
          TAG,
          "Starting with receiving Enabled="
              + receivingEnabled
              + " GV enabled="
              + googleVoiceEnabled);
    } else {
      receivingEnabled = true;
      googleVoiceEnabled = false;
    }

    smsManager = SmsManager.getDefault();
    PhoneNumber("");

    isInitialized = false; // Set true when the form is initialized and can dispatch
    isRunning = false; // This will be set true in onResume and false in onPause

    // Register this component for lifecycle callbacks
    container.$form().registerForOnInitialize(this);
    container.$form().registerForOnResume(this);
    container.$form().registerForOnPause(this);
    container.$form().registerForOnStop(this);
  }
Beispiel #2
0
  public SensorDB(ComponentContainer container) {
    super(container.$form());
    // TODO Auto-generated constructor stub
    // Set up listeners
    form.registerForOnDestroy(this);
    mainUIThreadActivity = container.$context();
    handler = new Handler();

    // we use dbName as pipelineName, each app (package) has their unique dbName, which is
    // packagename + "__SENSOR_DB__"
    pipelineName = SensorDbUtil.getPipelineName(mainUIThreadActivity);

    exportPath =
        new File(Environment.getExternalStorageDirectory(), form.getPackageName())
            + File.separator
            + "export";
    exportFormat =
        NameValueDatabaseService.EXPORT_CSV; // set the exporting format as csv by default

    //    Intent i = new Intent(mainUIThreadActivity, FunfManager.class);
    //    mainUIThreadActivity.startService(i);

    if (!Launcher.isLaunched()) {
      Log.i(TAG, "firstTime launching....");
      Launcher.launch(mainUIThreadActivity);
    }

    // bind to FunfManger (in case the user wants to set up the schedule)
    doBindService();
    // now we get(bind) to the Pipleline class that exists
    // we can set upload and archive periods using the pipeline
    form.registerForOnDestroy(this);
  }
  /**
   * Creates a new TextMessage component.
   *
   * @param container ignored (because this is a non-visible component)
   */
  public Texting(ComponentContainer container) {
    super(container.$form());
    Log.d(TAG, "Texting constructor");
    this.container = container;
    Texting.component = (Texting) this;
    activity = container.$context();

    SharedPreferences prefs = activity.getSharedPreferences(PREF_FILE, Activity.MODE_PRIVATE);
    if (prefs != null) {
      receivingEnabled = prefs.getInt(PREF_RCVENABLED, -1);
      if (receivingEnabled == -1) {
        if (prefs.getBoolean(PREF_RCVENABLED_LEGACY, true)) {
          receivingEnabled = ComponentConstants.TEXT_RECEIVING_FOREGROUND;
        } else {
          receivingEnabled = ComponentConstants.TEXT_RECEIVING_OFF;
        }
      }

      googleVoiceEnabled = prefs.getBoolean(PREF_GVENABLED, false);
      Log.i(
          TAG,
          "Starting with receiving Enabled="
              + receivingEnabled
              + " GV enabled="
              + googleVoiceEnabled);
    } else {
      receivingEnabled = ComponentConstants.TEXT_RECEIVING_FOREGROUND;
      googleVoiceEnabled = false;
    }

    // Handles authenticating for GV feature.  This sets the authToken.
    if (googleVoiceEnabled) new AsyncAuthenticate().execute();

    smsManager = SmsManager.getDefault();
    PhoneNumber("");

    isInitialized = false; // Set true when the form is initialized and can dispatch
    isRunning = false; // This will be set true in onResume and false in onPause

    // Register this component for lifecycle callbacks
    container.$form().registerForOnInitialize(this);
    container.$form().registerForOnResume(this);
    container.$form().registerForOnPause(this);
    container.$form().registerForOnStop(this);
  }
Beispiel #4
0
 public Texting(ComponentContainer paramComponentContainer)
 {
   super(paramComponentContainer.$form());
   Log.d("Texting Component", "Texting constructor");
   this.container = paramComponentContainer;
   component = this;
   activity = paramComponentContainer.$context();
   SharedPreferences localSharedPreferences = activity.getSharedPreferences("TextingState", 0);
   if (localSharedPreferences != null)
   {
     receivingEnabled = localSharedPreferences.getInt("receiving2", -1);
     if (receivingEnabled == -1)
     {
       if (localSharedPreferences.getBoolean("receiving", true)) {
         receivingEnabled = 2;
       }
     }
     else
     {
       this.googleVoiceEnabled = localSharedPreferences.getBoolean("gvenabled", false);
       Log.i("Texting Component", "Starting with receiving Enabled=" + receivingEnabled + " GV enabled=" + this.googleVoiceEnabled);
     }
   }
   for (;;)
   {
     if (this.googleVoiceEnabled) {
       new AsyncAuthenticate().execute(new Void[0]);
     }
     this.smsManager = SmsManager.getDefault();
     PhoneNumber("");
     this.isInitialized = false;
     isRunning = false;
     paramComponentContainer.$form().registerForOnInitialize(this);
     paramComponentContainer.$form().registerForOnResume(this);
     paramComponentContainer.$form().registerForOnPause(this);
     paramComponentContainer.$form().registerForOnStop(this);
     return;
     receivingEnabled = 1;
     break;
     receivingEnabled = 2;
     this.googleVoiceEnabled = false;
   }
 }
 public ImageGallery(
     ComponentContainer container, String[] picnames, int[] basestyle, int resourceId) {
   super(container, resourceId);
   view = null;
   Gallery view = (Gallery) container.$form().findViewById(resourceId);
   adapter = new ImageAdapter(container.$context(), basestyle);
   adapter.setFiles(picnames);
   view.setAdapter(adapter);
   view.setOnItemClickListener(this);
   view.requestLayout();
 }
Beispiel #6
0
  /**
   * Creates a new VideoPlayer component.
   *
   * @param container
   */
  public VideoPlayer(ComponentContainer container) {
    super(container);
    container.$form().registerForOnDestroy(this);
    videoView = new ResizableVideoView(container.$context());
    videoView.setMediaController(new MediaController(container.$context()));
    videoView.setOnCompletionListener(this);
    videoView.setOnErrorListener(this);
    videoView.setOnPreparedListener(this);

    // add the component to the designated container
    container.$add(this);
    // set a default size
    container.setChildWidth(this, ComponentConstants.VIDEOPLAYER_PREFERRED_WIDTH);
    container.setChildHeight(this, ComponentConstants.VIDEOPLAYER_PREFERRED_HEIGHT);

    // Make volume buttons control media, not ringer.
    container.$form().setVolumeControlStream(AudioManager.STREAM_MUSIC);

    sourcePath = "";
  }
 /**
  * Creates a new ActivityStarter component.
  *
  * @param container container, kept for access to form and context
  */
 public ActivityStarter(ComponentContainer container) {
   super(container.$form());
   // Save the container for later
   this.container = container;
   result = "";
   Action(Intent.ACTION_MAIN);
   ActivityPackage("");
   ActivityClass("");
   DataUri("");
   DataType("");
   ExtraKey("");
   ExtraValue("");
   ResultName("");
 }
  /**
   * Creates a new Clock component.
   *
   * @param container ignored (because this is a non-visible component)
   */
  public Clock(ComponentContainer container) {
    super(container.$form());
    timerInternal = new TimerInternal(this, DEFAULT_ENABLED, DEFAULT_INTERVAL);

    // Set up listeners
    form.registerForOnResume(this);
    form.registerForOnStop(this);
    form.registerForOnDestroy(this);

    if (form instanceof ReplForm) {
      // In REPL, if this Clock component was added to the project after the onResume call occurred,
      // then onScreen would be false, but the REPL app is, in fact, on screen.
      onScreen = true;
    }
  }
 public Spannable[] itemsToColoredText() {
   // TODO(hal): Generalize this so that different items could have different
   // colors and even fonts and sizes
   int size = items.size();
   int displayTextSize = textSize;
   Spannable[] objects = new Spannable[size];
   for (int i = 1; i <= size; i++) {
     // Note that the ListPicker and otherPickers pickers convert Yail lists to string by calling
     // YailList.ToStringArray.
     // ListView however, does the string conversion via the adapter, so we must ensure
     // that the adapter uses YailListElementToSring
     String itemString = YailList.YailListElementToString(items.get(i));
     // Is there a more efficient way to do conversion to spannable strings that does not
     // need to allocate new objects?
     Spannable chars = new SpannableString(itemString);
     chars.setSpan(new ForegroundColorSpan(textColor), 0, chars.length(), 0);
     if (!container.$form().getCompatibilityMode()) {
       displayTextSize = (int) (textSize * container.$form().deviceDensity());
     }
     chars.setSpan(new AbsoluteSizeSpan(displayTextSize), 0, chars.length(), 0);
     objects[i - 1] = chars;
   }
   return objects;
 }
  /**
   * Creates a new LocationSensor component.
   *
   * @param container ignored (because this is a non-visible component)
   */
  public LocationSensor(ComponentContainer container) {
    super(container.$form());
    handler = new Handler();
    // Set up listener
    form.registerForOnResume(this);
    form.registerForOnStop(this);

    // Initialize sensor properties (60 seconds; 5 meters)
    timeInterval = 60000;
    distanceInterval = 5;

    // Initialize location-related fields
    Context context = container.$context();
    geocoder = new Geocoder(context);
    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    locationCriteria = new Criteria();
    myLocationListener = new MyLocationListener();
  }
 protected Sprite(ComponentContainer paramComponentContainer, Handler paramHandler) {
   this.androidUIHandler = paramHandler;
   if (!(paramComponentContainer instanceof Canvas)) {
     throw new IllegalArgumentError(
         "Sprite constructor called with container " + paramComponentContainer);
   }
   this.canvas = ((Canvas) paramComponentContainer);
   this.canvas.addSprite(this);
   this.registeredCollisions = new HashSet();
   this.timerInternal = new TimerInternal(this, true, 100, paramHandler);
   Heading(0.0D);
   Enabled(true);
   Interval(100);
   Speed(0.0F);
   Visible(true);
   Z(1.0D);
   paramComponentContainer.$form().registerForOnDestroy(this);
 }
  /**
   * Sets whether you want the {@link #MessageReceived(String,String)} event to get run when a new
   * text message is received.
   *
   * @param enabled 0 = never receive, 1 = receive foreground only, 2 = receive always
   */
  @DesignerProperty(
      editorType = PropertyTypeConstants.PROPERTY_TYPE_TEXT_RECEIVING,
      defaultValue = "2") // Default is FOREGROUND
  @SimpleProperty()
  public void ReceivingEnabled(int enabled) {
    if ((enabled < ComponentConstants.TEXT_RECEIVING_OFF)
        || (enabled > ComponentConstants.TEXT_RECEIVING_ALWAYS)) {
      container
          .$form()
          .dispatchErrorOccurredEvent(
              this, "Texting", ErrorMessages.ERROR_BAD_VALUE_FOR_TEXT_RECEIVING, enabled);
      return;
    }

    Texting.receivingEnabled = enabled;
    SharedPreferences prefs = activity.getSharedPreferences(PREF_FILE, Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(PREF_RCVENABLED, enabled);
    editor.remove(PREF_RCVENABLED_LEGACY); // Remove any legacy value
    editor.commit();
  }
Beispiel #13
0
  public CheckBox(ComponentContainer container, int resourceId) {
    super(container, resourceId);

    // view = (android.widget.CheckBox) form.findViewById(resourceId);
    view = null;
    android.widget.CheckBox view =
        (android.widget.CheckBox) container.$form().findViewById(resourceId);
    // Listen to focus changes
    view.setOnFocusChangeListener(this);
    view.setOnCheckedChangeListener(this);

    // BackgroundColor(Component.COLOR_NONE);
    // Enabled(true);
    // fontTypeface = Component.TYPEFACE_DEFAULT;
    // TextViewUtil.setFontTypeface(view, fontTypeface, bold, italic);
    // FontSize(Component.FONT_DEFAULT_SIZE);
    // Text("");
    // TextColor(Component.COLOR_BLACK);
    getfontTypeFace();
    Checked(false);
  }
  /** Start the activity. */
  @SimpleFunction(description = "Start the activity corresponding to this ActivityStarter.")
  public void StartActivity() {
    resultIntent = null;
    result = "";

    Intent intent = buildActivityIntent();

    if (requestCode == 0) {
      // First time, we need to register this as an ActivityResultListener with the Form.
      // The Form's onActivityResult method will be called when the activity returns. If we
      // register with the Form and then use the requestCode when we start an activity, the Form
      // will call our resultReturned method.
      requestCode = form.registerForActivityResult(this);
    }

    try {
      container.$context().startActivityForResult(intent, requestCode);
      String openAnim = container.$form().getOpenAnimType();
      AnimationUtil.ApplyOpenScreenAnimation(container.$context(), openAnim);
    } catch (ActivityNotFoundException e) {
      form.dispatchErrorOccurredEvent(
          this, "StartActivity", ErrorMessages.ERROR_ACTIVITY_STARTER_NO_CORRESPONDING_ACTIVITY);
    }
  }
Beispiel #15
0
 public TinyDB(ComponentContainer paramComponentContainer) {
   super(paramComponentContainer.$form());
   this.context = paramComponentContainer.$context();
   this.sharedPreferences = this.context.getSharedPreferences("TinyDB1", 0);
 }
 /** Creates a new FtcAnalogOutput component. */
 public FtcAnalogOutput(ComponentContainer container) {
   super(container.$form());
 }
Beispiel #17
0
  /**
   * Creates a new Survey component.
   *
   * @param container container the component will be placed in
   * @throws IOException
   */
  public Survey(ComponentContainer container) throws IOException {
    super(container);
    mainUI = container.$form();
    exportRoot =
        new java.io.File(Environment.getExternalStorageDirectory(), mainUI.getPackageName())
            + java.io.File.separator
            + "export";

    JsonParser parse = new JsonParser();
    webview = new WebView(container.$context());
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setFocusable(true);
    webview.setVerticalScrollBarEnabled(true);

    container.$add(this);

    webview.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                  v.requestFocus();
                }
                break;
            }
            return false;
          }
        });

    // set the initial default properties. Height and Width
    // will be fill-parent, which will be the default for the web viewer.

    Width(LENGTH_FILL_PARENT);
    Height(LENGTH_FILL_PARENT);

    // set default survey style
    style = TEXTBOX; // default style

    // see if the Survey is created by someone tapping on a notification!
    // create the Survey and load it in the webviewer
    /* e.g.
     * value = {
     * "style": "multipleChoice",
     * "question": "What is your favorite food"
     * "options": ["apple", "banana", "strawberry", "orange"],
     * "surveyGroup": "MIT-food-survey"
     * }
     *
     */
    initValues = container.$form().getSurveyStartValues();
    Log.i(TAG, "startVal Suvey:" + initValues.toString());
    if (initValues != "") {

      JsonObject values = (JsonObject) parse.parse(initValues);
      this.style = values.get("style").getAsString();
      this.question = values.get("question").getAsString();
      this.surveyGroup = values.get("surveyGroup").getAsString();
      ArrayList<String> arrOptions = new ArrayList<String>();
      JsonArray _options = values.get("options").getAsJsonArray();
      for (int i = 0; i < _options.size(); i++) {
        arrOptions.add(_options.get(i).getAsString());
      }

      this.options = arrOptions;
      this.styleFromIntent = values.get("style").getAsString();
      Log.i(TAG, "Survey component got created");
    }
  }