Exemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentFragment(new ResponsePromptsFragment());

    mImageLoader = ImageLoader.get(this);

    // inflate the campaign-specific info page into the scrolling framelayout
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // and inflate all the possible commands into the button tray
    inflater.inflate(R.layout.response_info_buttons, mButtonTray, true);

    // Prepare the loader. Either re-connect with an existing one,
    // or start a new one.
    getSupportLoaderManager().initLoader(0, null, this);

    mapViewButton = (TextView) findViewById(R.id.response_info_button_view_map);
    mapViewButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(OhmageApplication.VIEW_MAP, getIntent().getData()));
          }
        });
  }
Exemplo n.º 2
0
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (!data.moveToFirst()) {
      return;
    }

    final String surveyName = data.getString(ResponseQuery.SURVEY_TITLE);
    final Long completedDate = data.getLong(ResponseQuery.TIME);

    mHeadertext.setText(surveyName);
    mSubtext.setText(data.getString(ResponseQuery.CAMPAIGN_NAME));
    SimpleDateFormat df = new SimpleDateFormat();
    mNotetext.setText(df.format(new Date(completedDate)));

    final String iconUrl = data.getString(ResponseQuery.CAMPAIGN_ICON);
    if (iconUrl == null
        || mImageLoader.bind(mIconView, iconUrl, null) != ImageLoader.BindResult.OK) {
      mIconView.setImageResource(R.drawable.apple_logo);
    }

    mEntityHeader.setVisibility(View.VISIBLE);

    // Make the map view button status aware so it can provide some useful info about the gps state
    if (data.getInt(ResponseQuery.STATUS) == Response.STATUS_WAITING_FOR_LOCATION) {
      mapViewButton.setText("Waiting for Location");
      mapViewButton.setEnabled(false);
    } else if (!(SurveyGeotagService.LOCATION_VALID.equals(
        data.getString(ResponseQuery.LOCATION_STATUS)))) {
      mapViewButton.setText("Location Not Available");
      mapViewButton.setEnabled(false);
    } else {
      mapViewButton.setText("View Map");
      mapViewButton.setEnabled(true);
    }
  }
Exemplo n.º 3
0
 public PromptResponsesAdapter(
     Context context, Cursor c, String[] from, int[] to, int flags, String responseId) {
   super(context, R.layout.response_prompt_list_item, c, from, to, flags);
   mImageLoader = ImageLoader.get(context);
   setViewBinder(this);
   mResponseId = responseId;
 }
Exemplo n.º 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentFragment(new ResponsePromptsFragment());

    mResponseHelper = new ResponseActivityHelper(this);

    mImageLoader = ImageLoader.get(this);

    // inflate the campaign-specific info page into the scrolling framelayout
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // and inflate all the possible commands into the button tray
    inflater.inflate(R.layout.response_info_buttons, mButtonTray, true);

    // Prepare the loader. Either re-connect with an existing one,
    // or start a new one.
    getSupportLoaderManager().initLoader(0, null, this);

    mapViewButton = (TextView) findViewById(R.id.response_info_button_view_map);
    mapViewButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Analytics.widget(v);
            startActivity(new Intent(OhmageApplication.VIEW_MAP, getIntent().getData()));
          }
        });

    uploadButton = (TextView) findViewById(R.id.response_info_button_upload);
    uploadButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Analytics.widget(v);
            if (mStatus == Response.STATUS_STANDBY)
              mResponseHelper.queueForUpload(getIntent().getData());
            else {
              Bundle bundle = new Bundle();
              bundle.putParcelable(ResponseActivityHelper.KEY_URI, getIntent().getData());
              showDialog(mStatus, bundle);
            }
          }
        });
  }
Exemplo n.º 5
0
      @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;
      }
Exemplo n.º 6
0
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (!data.moveToFirst()) {
      Toast.makeText(this, R.string.response_info_response_deleted, Toast.LENGTH_SHORT).show();
      finish();
      return;
    }

    final String surveyName = data.getString(ResponseQuery.SURVEY_TITLE);
    final Long completedDate = data.getLong(ResponseQuery.TIME);
    mStatus = data.getInt(ResponseQuery.STATUS);

    if (mStatus == Response.STATUS_STANDBY)
      uploadButton.setContentDescription(
          getString(R.string.response_info_entity_action_button_upload_description));
    else if (mStatus == Response.STATUS_WAITING_FOR_LOCATION)
      uploadButton.setContentDescription(
          getString(R.string.response_info_entity_action_button_upload_force_description));
    else
      uploadButton.setContentDescription(
          getString(R.string.response_info_entity_action_button_upload_error_description));

    mHeadertext.setText(surveyName);
    mSubtext.setText(data.getString(ResponseQuery.CAMPAIGN_NAME));
    // If we aren't in single campaign mode, show the campaign name
    mSubtext.setVisibility((ConfigHelper.isSingleCampaignMode()) ? View.GONE : View.VISIBLE);
    SimpleDateFormat df = new SimpleDateFormat();
    mNotetext.setText(df.format(new Date(completedDate)));

    final String iconUrl = data.getString(ResponseQuery.CAMPAIGN_ICON);
    if (iconUrl == null
        || mImageLoader.bind(mIconView, iconUrl, null) != ImageLoader.BindResult.OK) {
      mIconView.setImageResource(R.drawable.apple_logo);
    }

    mEntityHeader.setVisibility(View.VISIBLE);

    // Make the map view button status aware so it can provide some useful info about the gps state
    if (mStatus == Response.STATUS_WAITING_FOR_LOCATION) {
      mapViewButton.setText(R.string.response_info_gps_wait);
      mapViewButton.setEnabled(false);
    } else if (!(SurveyGeotagService.LOCATION_VALID.equals(
        data.getString(ResponseQuery.LOCATION_STATUS)))) {
      mapViewButton.setText(R.string.response_info_no_location);
      mapViewButton.setEnabled(false);
    } else {
      mapViewButton.setText(R.string.response_info_view_map);
      mapViewButton.setEnabled(true);
    }

    // Make upload button visible if applicable
    uploadButton.setVisibility(View.VISIBLE);
    switch (mStatus) {
      case Response.STATUS_DOWNLOADED:
      case Response.STATUS_UPLOADED:
        uploadButton.setVisibility(View.GONE);
        break;
      case Response.STATUS_STANDBY:
      case Response.STATUS_WAITING_FOR_LOCATION:
        uploadButton.setText(R.string.response_info_upload);
        uploadButton.setEnabled(true);
        break;
      case Response.STATUS_QUEUED:
      case Response.STATUS_UPLOADING:
        uploadButton.setText(R.string.response_info_uploading);
        uploadButton.setEnabled(false);
        break;
      default:
        // Error
        uploadButton.setText(R.string.response_info_upload_error);
        uploadButton.setEnabled(true);
    }
  }