@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(); }
@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; }