public ImageGallery(ComponentContainer container, String[] picnames, int[] basestyle) {
   super(container);
   view = new Gallery(container.$context());
   adapter = new ImageAdapter(container.$context(), basestyle);
   adapter.setFiles(picnames);
   view.setAdapter(adapter);
   view.setOnItemClickListener(this);
   container.$add(this);
   view.requestLayout();
 }
  /** Sets the items of the ListView through an adapter */
  public void setAdapterData() {
    adapter =
        new ArrayAdapter<Spannable>(
            container.$context(), android.R.layout.simple_list_item_1, itemsToColoredText());
    view.setAdapter(adapter);

    adapterCopy =
        new ArrayAdapter<Spannable>(container.$context(), android.R.layout.simple_list_item_1);
    for (int i = 0; i < adapter.getCount(); ++i) {
      adapterCopy.insert(adapter.getItem(i), i);
    }
  }
Exemple #3
0
  /**
   * Creates a new WebViewer component.
   *
   * @param container container the component will be placed in
   */
  public WebViewer(ComponentContainer container) {
    super(container);

    webview = new WebView(container.$context());
    webview.setWebViewClient(new WebViewerClient());
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setFocusable(true);
    // enable pinch zooming and zoom controls
    webview.getSettings().setBuiltInZoomControls(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.

    followLinks = true;
    HomeUrl("");
    Width(LENGTH_FILL_PARENT);
    Height(LENGTH_FILL_PARENT);
  }
Exemple #4
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");
    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);
  }
  /**
   * Creates a new ButtonBase component.
   *
   * @param container container, component will be placed in
   */
  public ButtonBase(ComponentContainer container) {
    super(container);
    view = new android.widget.Button(container.$context());

    // Save the default values in case the user wants them back later.
    defaultButtonDrawable = view.getBackground();
    defaultColorStateList = view.getTextColors();

    // Adds the component to its designated container
    container.$add(this);

    // Listen to clicks and focus changes
    view.setOnClickListener(this);
    view.setOnFocusChangeListener(this);
    view.setOnLongClickListener(this);
    view.setOnTouchListener(this);

    // Default property values
    TextAlignment(Component.ALIGNMENT_CENTER);
    // BackgroundColor and Image are dangerous properties:
    // Once either of them is set, the 3D bevel effect for the button is
    // irretrievable, except by reloading defaultButtonDrawable, defined above.
    BackgroundColor(Component.COLOR_DEFAULT);
    Image("");
    Enabled(true);
    fontTypeface = Component.TYPEFACE_DEFAULT;
    TextViewUtil.setFontTypeface(view, fontTypeface, bold, italic);
    FontSize(Component.FONT_DEFAULT_SIZE);
    Text("");
    TextColor(Component.COLOR_DEFAULT);
    Shape(Component.BUTTON_SHAPE_DEFAULT);
  }
Exemple #7
0
 /**
  * Constructor for Toggle Button component when using the GLE.
  *
  * @param container
  * @param resourceId
  */
 public Toggle(ComponentContainer container, int resourceId) {
   super(container, resourceId);
   view = (ToggleButton) container.$context().findViewById(resourceId);
   if (view == null) {
     throw new IllegalArgumentException(
         "View with resource Id " + resourceId + " is coming up null!");
   }
   view.setOnCheckedChangeListener(this);
 }
 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();
 }
Exemple #9
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 = "";
  }
 /**
  * Returns the name of the activity that corresponds to this ActivityStarer, or an empty string if
  * no corresponding activity can be found.
  */
 @SimpleFunction(
     description =
         "Returns the name of the activity that corresponds to this "
             + "ActivityStarer, or an empty string if no corresponding activity can be found.")
 public String ResolveActivity() {
   Intent intent = buildActivityIntent();
   PackageManager pm = container.$context().getPackageManager();
   ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
   if (resolveInfo != null && resolveInfo.activityInfo != null) {
     return resolveInfo.activityInfo.name;
   }
   return "";
 }
  /**
   * Creates a new HVArrangement component.
   *
   * @param container container, component will be placed in
   * @param orientation one of {@link ComponentConstants#LAYOUT_ORIENTATION_HORIZONTAL}. {@link
   *     ComponentConstants#LAYOUT_ORIENTATION_VERTICAL}
   */
  public HVArrangement(ComponentContainer container, int orientation) {
    super(container);
    context = container.$context();

    this.orientation = orientation;
    viewLayout =
        new LinearLayout(
            context,
            orientation,
            ComponentConstants.EMPTY_HV_ARRANGEMENT_WIDTH,
            ComponentConstants.EMPTY_HV_ARRANGEMENT_HEIGHT);

    container.$add(this);
  }
  /** 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);
    }
  }
  /**
   * 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);
  }
  /**
   * 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();
  }
 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;
   }
 }
Exemple #16
0
  /**
   * Creates a new linked data form in the specified container.
   *
   * @param container
   */
  public LinkedDataForm(ComponentContainer container) {
    super(container);
    context = container.$context();
    layout =
        new LinearLayout(
            context,
            ComponentConstants.LAYOUT_ORIENTATION_VERTICAL,
            ComponentConstants.EMPTY_HV_ARRANGEMENT_WIDTH,
            ComponentConstants.EMPTY_HV_ARRANGEMENT_HEIGHT);
    AlignmentUtil alignmentSetter = new AlignmentUtil(layout);
    alignmentSetter.setHorizontalAlignment(ComponentConstants.HORIZONTAL_ALIGNMENT_DEFAULT);
    alignmentSetter.setVerticalAlignment(ComponentConstants.VERTICAL_ALIGNMENT_DEFAULT);
    components = new ArrayList<AndroidViewComponent>();
    concept = "";
    baseUri = "";
    property = "";
    Log.d(LOG_TAG, "Created linked data form");

    container.$add(this);
  }
Exemple #17
0
  /**
   * Creates a new CheckBox component.
   *
   * @param container container, component will be placed in
   */
  public CheckBox(ComponentContainer container) {
    super(container);

    view = new android.widget.CheckBox(container.$context());

    // Listen to focus changes
    view.setOnFocusChangeListener(this);
    view.setOnCheckedChangeListener(this);

    // Adds the component to its designated container
    container.$add(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);
    Checked(false);
  }
Exemple #18
0
 public TinyDB(ComponentContainer paramComponentContainer) {
   super(paramComponentContainer.$form());
   this.context = paramComponentContainer.$context();
   this.sharedPreferences = this.context.getSharedPreferences("TinyDB1", 0);
 }
  /**
   * Creates a new ListView component.
   *
   * @param container container that the component will be placed in
   */
  public ListView(ComponentContainer container) {
    super(container);
    this.container = container;
    items = YailList.makeEmptyList();
    // initialize selectionIndex which also sets selection
    SelectionIndex(0);
    view = new android.widget.ListView(container.$context());
    view.setOnItemClickListener(this);
    view.setChoiceMode(android.widget.ListView.CHOICE_MODE_SINGLE);
    view.setScrollingCacheEnabled(false);
    listViewLayout = new LinearLayout(container.$context());
    listViewLayout.setOrientation(LinearLayout.VERTICAL);

    txtSearchBox = new EditText(container.$context());
    txtSearchBox.setSingleLine(true);
    txtSearchBox.setWidth(Component.LENGTH_FILL_PARENT);
    txtSearchBox.setPadding(10, 10, 10, 10);
    txtSearchBox.setHint("Search list...");

    // set up the listener
    txtSearchBox.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            adapter.getFilter().filter(cs);
          }

          @Override
          public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // no-op. Required method
          }

          @Override
          public void afterTextChanged(Editable arg0) {
            // no-op. Required method
          }
        });

    if (showFilter) {
      txtSearchBox.setVisibility(View.VISIBLE);
    } else {
      txtSearchBox.setVisibility(View.GONE);
    }

    // set the colors and initialize the elements
    // note that the TextColor and ElementsFromString setters
    // need to have the textColor set first, since they reset the
    // adapter

    Width(Component.LENGTH_FILL_PARENT);
    BackgroundColor(DEFAULT_BACKGROUND_COLOR);
    SelectionColor(DEFAULT_SELECTION_COLOR);

    textColor = DEFAULT_TEXT_COLOR;
    TextColor(textColor);
    textSize = DEFAULT_TEXT_SIZE;
    TextSize(textSize);
    ElementsFromString("");

    listViewLayout.addView(txtSearchBox);
    listViewLayout.addView(view);
    listViewLayout.requestLayout();
    container.$add(this);
  };
Exemple #20
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");
    }
  }
Exemple #21
0
 /**
  * Constructor for Toggle Button component.
  *
  * @param container
  */
 public Toggle(ComponentContainer container) {
   super(container);
   view = new ToggleButton(container.$context());
   view.setOnCheckedChangeListener(this);
   container.$add(this);
 }