@Override
  public void onReceive(final Context context, Intent intent) {
    Log.v(TAG, "onReceive");

    // start components
    SharedPreferences settings =
        context.getSharedPreferences(Mobility.MOBILITY, Context.MODE_PRIVATE);
    if (settings.getBoolean(MobilityControl.MOBILITY_ON, false)) {
      //			Intent MobilityServiceIntent = new Intent(context, MobilityService.class);
      //			context.stopService(MobilityServiceIntent);
      //			context.startService(MobilityServiceIntent);
      //			context.startService(new Intent(context, Mobility.class));
      Log.v(TAG, "Boot receiver called start!");
      Mobility.start(context.getApplicationContext());
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get the notification description from the intent
    Intent intent = getIntent();
    String desc = intent.getStringExtra(KEY_NOTIF_CONFIG);
    if (desc == null) {
      Log.e(TAG, "NotifEditActivity: No notification " + "description passed. Exiting...");

      finish();
      return;
    }

    // Parse and load the description
    mNotifDesc = new NotifDesc();
    if (!mNotifDesc.loadString(desc)) {
      Log.e(
          TAG,
          "NotifEditActivity: Failed to parse the "
              + "notification description passed. Exiting...");

      finish();
      return;
    }

    setContentView(R.layout.trigger_editor);

    Button b = (Button) findViewById(R.id.trig_edit_done);
    b.setOnClickListener(this);
    b = (Button) findViewById(R.id.trig_edit_cancel);
    b.setOnClickListener(this);

    // Update the GUI with the data
    initializeListData();
    setupListAdaptor();
    validateDataAndUpdateView();
  }
Example #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    UserPreferencesHelper preferencesHelper = new UserPreferencesHelper(this);

    if (preferencesHelper.isUserDisabled()) {
      ((OhmageApplication) getApplication()).resetAll();
    }

    if (!AccountHelper.accountExists()) {
      Log.v(TAG, "no credentials saved, so launch Login");
      startActivity(AccountHelper.getLoginIntent(this));
      finish();
      return;
    }
  }
  /**
   * Checks if the passed condition is true based on the passed list of node responses. If the id
   * does not exist in the responses, assume the response is NULL.
   *
   * @param condition The condition to check.
   * @param previousResponses The List of previous responses.
   * @return Whether or not the condition is true.
   */
  public static boolean evaluateCondition(String condition, List<DataPoint> previousResponses) {
    // Blank conditions are always valid
    if (!"".equals(condition)) {
      start s = null;

      try {
        // The API is odd, we have to instantiate an object just to use its static methods below,
        // we do not actually need to keep the object around for any reason
        if (!conditionParserInitialized) {
          new ConditionParser(new StringReader(condition));
          conditionParserInitialized = true;
        } else {
          ConditionParser.ReInit(new StringReader(condition));
        }
        // Call start statically even though we have to instantiate the object above
        s = ConditionParser.start();

        ConditionDepthFirst<Boolean, Boolean> visitor =
            new ConditionDepthFirst<Boolean, Boolean>(previousResponses);
        // Check the condition against the previous responses
        Boolean conditionValue = visitor.visit(s, null);

        /*if (DataPointConditionEvaluator._logger.isDebugEnabled()) {
            DataPointConditionEvaluator._logger.debug("Condition [" + condition + "] evaluated as " + conditionValue.toString());
        }*/
        Log.v(TAG, "Condition [" + condition + "] evaluated as " + conditionValue.toString());

        return conditionValue.booleanValue();

      } catch (ParseException pe) {

        throw new IllegalArgumentException(
            "Condition failed to parse, should have been checked in the XML validator: "
                + condition);
      }
    }

    return true;
  }
      @Override
      public boolean setViewValue(View view, Cursor cursor, int columnIndex) {

        if (cursor.getColumnName(columnIndex).equals(PromptResponses.PROMPT_RESPONSE_VALUE)) {
          final String value = cursor.getString(columnIndex);

          if (view.getTag() instanceof ImageView) {
            String campaignUrn = cursor.getString(cursor.getColumnIndex(Responses.CAMPAIGN_URN));
            final File file = Response.getTemporaryResponsesMedia(value);
            final ImageView imageView = (ImageView) view.getTag();

            if (file != null && file.exists()) {
              try {
                BitmapDrawable d = (BitmapDrawable) imageView.getDrawable();
                if (d != null) d.getBitmap().recycle();
                Bitmap img = Utilities.decodeImage(file, 600);
                imageView.setImageBitmap(img);
                imageView.setOnClickListener(
                    new View.OnClickListener() {

                      @Override
                      public void onClick(View v) {
                        Analytics.widget(v, "View Local Fullsize Image");
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setDataAndType(Uri.fromFile(file), "image/jpeg");
                        mContext.startActivity(intent);
                      }
                    });
                return true;
              } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              } catch (IOException e) {
                Log.e(TAG, "Error decoding image", e);
              }
            }

            String url = OhmageApi.defaultImageReadUrl(value, campaignUrn, "small");
            final String largeUrl = OhmageApi.defaultImageReadUrl(value, campaignUrn, null);
            imageView.setOnClickListener(
                new View.OnClickListener() {

                  @Override
                  public void onClick(View v) {
                    Analytics.widget(v, "View Fullsize Image");
                    Intent intent =
                        new Intent(OhmageApplication.ACTION_VIEW_REMOTE_IMAGE, Uri.parse(largeUrl));
                    mContext.startActivity(intent);
                  }
                });

            mImageLoader.clearErrors();
            BindResult bindResult =
                mImageLoader.bind(
                    (ImageView) view.getTag(),
                    url,
                    new Callback() {

                      @Override
                      public void onImageLoaded(ImageView view, String url) {
                        imageView.setVisibility(View.VISIBLE);
                        imageView.setClickable(true);
                        imageView.setFocusable(true);
                      }

                      @Override
                      public void onImageError(ImageView view, String url, Throwable error) {
                        imageView.setVisibility(View.VISIBLE);
                        imageView.setImageResource(android.R.drawable.ic_dialog_alert);
                        imageView.setClickable(false);
                        imageView.setFocusable(false);
                      }
                    });
            if (bindResult == ImageLoader.BindResult.ERROR) {
              imageView.setImageResource(android.R.drawable.ic_dialog_alert);
              imageView.setClickable(false);
              imageView.setFocusable(false);
            } else if (bindResult == ImageLoader.BindResult.LOADING) {
              imageView.setVisibility(View.GONE);
            }
          } else if (view.getTag() instanceof TextView) {
            String prompt_type = getItemPromptType(cursor);
            if ("multi_choice_custom".equals(prompt_type) || "multi_choice".equals(prompt_type)) {
              try {
                JSONArray choices = new JSONArray(value);
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < choices.length(); i++) {
                  if (i != 0) builder.append("<br\\>");
                  builder.append("&bull; ");
                  builder.append(OhmageMarkdown.parseHtml(choices.get(i).toString()));
                }
                ((TextView) view.getTag()).setText(Html.fromHtml(builder.toString()));
                return true;
              } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            } else if ("single_choice_custom".equals(prompt_type)
                || "single_choice".equals(prompt_type)) {
              ((TextView) view.getTag()).setText(OhmageMarkdown.parse(value));
              return true;
            } else if ("timestamp".equals(prompt_type)) {
              SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
              try {
                long time = format.parse(value).getTime();
                StringBuilder timeDisplay =
                    new StringBuilder(
                        DateUtils.formatDateTime(mContext, time, DateUtils.FORMAT_SHOW_YEAR));
                timeDisplay.append(" at ");
                timeDisplay.append(
                    DateUtils.formatDateTime(mContext, time, DateUtils.FORMAT_SHOW_TIME));

                ((TextView) view.getTag()).setText(timeDisplay);
                return true;
              } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            }
            ((TextView) view.getTag()).setText(value);
          }
          return true;
        }

        return false;
      }