@Override protected OhmageApi.AuthenticateResponse doInBackground(String... params) { mUsername = params[0]; mPassword = params[1]; // if (mPassword.equals(DUMMY_PASSWORD)) { // Log.i(TAG, "using stored hashed password"); // } else { // Log.i(TAG, "password field modified, attempting to hash"); // try { // mHashedPassword = BCrypt.hashpw(mPassword, BCRYPT_KEY); // Log.i(TAG, "hash complete"); // } catch (Exception e) { // Log.e(TAG, "unable to hash password"); // e.printStackTrace(); // } // } OhmageApi api = new OhmageApi(getActivity()); return api.authenticate( "https://dev.mobilizingcs.org/", mUsername, mPassword, OhmageApi.CLIENT_NAME); }
@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("• "); 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; }