Getting in image location and using it to post?

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Getting in image location and using it to post?

Postby digitalspaghetti » Sun Jan 25, 2009 4:39 pm

Hey folks,

I am writing a client for Brightkite, which has a REST api that allows you to post photos to their service.

I have the following code below as a gallery chooser, but I want to know the best way to get the location of the full image to pass to the OAuth request. I don't need the Post part (as there is an example here: solved_http-post_request_to_restful_rails_web-application-t3655.html)

The post takes a form like this as a curl request:

REST URL formats:
/places/<place id>/photos
/objects/<object id>
/places/<place id>/photos/<object id>

Required parameters:
photo[photo] : JPEG, PNG, GIF or BMP file
Optional parameters:
photo[body] : note or caption for the photo (up to 140 characters of text)


Here is the code I have below, and I'd appreciate any help with it:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.ifies.brightroid.posts;
  2.  
  3. import org.ifies.brightroid.R;
  4.  
  5. import android.app.Activity;
  6. import android.content.Context;
  7. import android.content.res.TypedArray;
  8. import android.database.Cursor;
  9. import android.net.Uri;
  10. import android.os.Bundle;
  11. import android.util.Log;
  12. import android.view.ContextMenu;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.view.ViewGroup;
  16. import android.view.ContextMenu.ContextMenuInfo;
  17. import android.widget.AdapterView;
  18. import android.widget.BaseAdapter;
  19. import android.widget.Gallery;
  20. import android.widget.ImageView;
  21. import android.widget.Toast;
  22. import android.widget.AdapterView.AdapterContextMenuInfo;
  23. import android.widget.AdapterView.OnItemClickListener;
  24. import android.provider.MediaStore;
  25.  
  26. public class PostGallery extends Activity {
  27.        
  28.         private Context mContext;
  29.     private Cursor cursor;
  30.     private int column_index;
  31.  
  32.     @Override
  33.     public void onCreate(Bundle savedInstanceState) {
  34.         super.onCreate(savedInstanceState);
  35.         setContentView(R.layout.post_gallery);
  36.        
  37.         String [] proj={MediaStore.Images.Thumbnails._ID};
  38.         cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
  39.                 proj, // Which columns to return
  40.                 null,       // WHERE clause; which rows to return (all rows)
  41.                 null,       // WHERE clause selection arguments (none)
  42.                 null); // Order-by clause (ascending by name)
  43.         column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
  44.         // Reference the Gallery view
  45.         Gallery g = (Gallery) findViewById(R.id.gallery);
  46.         // Set the adapter to our custom adapter (below)
  47.         g.setAdapter(new ImageAdapter(this));
  48.  
  49.         // Set a item click listener, and just Toast the clicked position
  50.         g.setOnItemClickListener(new OnItemClickListener() {
  51.             public void onItemClick(AdapterView parent, View v, int position, long id) {
  52.                 Toast.makeText(PostGallery.this, "" + position, Toast.LENGTH_SHORT).show();
  53.             }
  54.         });
  55.  
  56.         // We also want to show context menu for longpressed items in the gallery
  57.         registerForContextMenu(g);
  58.     }
  59.  
  60.     @Override
  61.     public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
  62.         menu.add("Testing");
  63.     }
  64.  
  65.     @Override
  66.     public boolean onContextItemSelected(MenuItem item) {
  67.         AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
  68.         Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show();
  69.         return true;
  70.     }
  71.  
  72.     public class ImageAdapter extends BaseAdapter {
  73.         int mGalleryItemBackground;
  74.  
  75.         public ImageAdapter(Context c) {
  76.             mContext = c;
  77.             // See res/values/attrs.xml for the <declare-styleable> that defines
  78.             // Gallery1.
  79.             TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
  80.             mGalleryItemBackground = a.getResourceId(
  81.                     R.styleable.Gallery1_android_galleryItemBackground, 0);
  82.             a.recycle();
  83.         }
  84.  
  85.         public int getCount() {
  86.                 Log.i("Total Count", "Count " + cursor.getCount());
  87.                 return cursor.getCount();
  88.                 //return 4;
  89.         }
  90.  
  91.         public Object getItem(int position) {
  92.             return position;
  93.         }
  94.  
  95.         public long getItemId(int position) {
  96.             return position;
  97.         }
  98.  
  99.         public View getView(int position, View convertView, ViewGroup parent) {
  100.                 ImageView i = new ImageView(mContext);
  101.                 if (convertView == null) {
  102.                         cursor.moveToPosition(position);
  103.                         int id = cursor.getInt(column_index);
  104.                         i.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""+id));
  105.                         i.setScaleType(ImageView.ScaleType.FIT_XY);
  106.                         i.setLayoutParams(new Gallery.LayoutParams(136, 88));
  107.  
  108.                         // The preferred Gallery item background
  109.                         i.setBackgroundResource(mGalleryItemBackground);
  110.                 }
  111.                 return i;
  112.         }
  113.       }
  114. }
  115.  
Parsed in 0.047 seconds, using GeSHi 1.0.8.4
digitalspaghetti
Freshman
Freshman
 
Posts: 6
Joined: Sun Jan 04, 2009 11:52 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 5 guests