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:
Using java Syntax Highlighting
- package org.ifies.brightroid.posts;
- import org.ifies.brightroid.R;
- import android.app.Activity;
- import android.content.Context;
- import android.content.res.TypedArray;
- import android.database.Cursor;
- import android.net.Uri;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.ContextMenu;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.ContextMenu.ContextMenuInfo;
- import android.widget.AdapterView;
- import android.widget.BaseAdapter;
- import android.widget.Gallery;
- import android.widget.ImageView;
- import android.widget.Toast;
- import android.widget.AdapterView.AdapterContextMenuInfo;
- import android.widget.AdapterView.OnItemClickListener;
- import android.provider.MediaStore;
- public class PostGallery extends Activity {
- private Context mContext;
- private Cursor cursor;
- private int column_index;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.post_gallery);
- String [] proj={MediaStore.Images.Thumbnails._ID};
- cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
- proj, // Which columns to return
- null, // WHERE clause; which rows to return (all rows)
- null, // WHERE clause selection arguments (none)
- null); // Order-by clause (ascending by name)
- column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
- // Reference the Gallery view
- Gallery g = (Gallery) findViewById(R.id.gallery);
- // Set the adapter to our custom adapter (below)
- g.setAdapter(new ImageAdapter(this));
- // Set a item click listener, and just Toast the clicked position
- g.setOnItemClickListener(new OnItemClickListener() {
- public void onItemClick(AdapterView parent, View v, int position, long id) {
- Toast.makeText(PostGallery.this, "" + position, Toast.LENGTH_SHORT).show();
- }
- });
- // We also want to show context menu for longpressed items in the gallery
- registerForContextMenu(g);
- }
- @Override
- public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
- menu.add("Testing");
- }
- @Override
- public boolean onContextItemSelected(MenuItem item) {
- AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
- Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show();
- return true;
- }
- public class ImageAdapter extends BaseAdapter {
- int mGalleryItemBackground;
- public ImageAdapter(Context c) {
- mContext = c;
- // See res/values/attrs.xml for the <declare-styleable> that defines
- // Gallery1.
- TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
- mGalleryItemBackground = a.getResourceId(
- R.styleable.Gallery1_android_galleryItemBackground, 0);
- a.recycle();
- }
- public int getCount() {
- Log.i("Total Count", "Count " + cursor.getCount());
- return cursor.getCount();
- //return 4;
- }
- public Object getItem(int position) {
- return position;
- }
- public long getItemId(int position) {
- return position;
- }
- public View getView(int position, View convertView, ViewGroup parent) {
- ImageView i = new ImageView(mContext);
- if (convertView == null) {
- cursor.moveToPosition(position);
- int id = cursor.getInt(column_index);
- i.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, ""+id));
- i.setScaleType(ImageView.ScaleType.FIT_XY);
- i.setLayoutParams(new Gallery.LayoutParams(136, 88));
- // The preferred Gallery item background
- i.setBackgroundResource(mGalleryItemBackground);
- }
- return i;
- }
- }
- }
Parsed in 0.047 seconds, using GeSHi 1.0.8.4

