package com.oux.photocaption;

import java.util.ArrayList;
import android.app.Activity;
import android.app.ActionBar;
import android.content.res.TypedArray;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.GridView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
import android.util.Log;
 
/**
 *
 * @author javatechig {@link http://javatechig.com}
 * @author sebastien michel
 *
 */
public class PhotoCaptionGallery extends Activity implements OnItemClickListener {
    static final String TAG = "photoCaptionGallery";
    private GridView gridView;
    private GridViewAdapter customGridAdapter;
    ActionBar actionBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gallery);

        actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.app_name);
        actionBar.setSubtitle(R.string.mode_gallery);

        gridView = (GridView) findViewById(R.id.gridView);

        // TODO: try to navigate by album (NavigationList).
        customGridAdapter = new GridViewAdapter(this, R.layout.row_grid, getData());
        gridView.setAdapter(customGridAdapter);

        Log.i(TAG, "Creating setOnItemClickListener");
        gridView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        Intent intent = new Intent(Intent.ACTION_VIEW, customGridAdapter.getUri(position), this,PhotoCaptionView.class);
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.gallery_actions, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent intent;
        switch (item.getItemId()) {
            case R.id.action_capture:
                intent = new Intent(this,PhotoCaptionEdit.class);
                startActivity(intent);
                finish();
                return true;
            case android.R.id.home:
                finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    private ArrayList getData() {
        final ArrayList imageItems = new ArrayList();

        return imageItems;

    }

}

@@ -422,24 +422,83 @@
 ckListener;%0A
+import android.widget.AdapterView.OnItemLongClickListener;%0A
 import andro
@@ -629,16 +629,328 @@
 il.Log;%0A
+import android.animation.Animator;%0Aimport android.animation.AnimatorListenerAdapter;%0Aimport android.animation.AnimatorSet;%0Aimport android.animation.ObjectAnimator;%0Aimport android.view.animation.DecelerateInterpolator;%0Aimport android.widget.ImageView;%0Aimport android.graphics.Point;%0Aimport android.graphics.Rect;%0A
  %0A/**%0A *
@@ -1117,16 +1117,40 @@
 Listener
+,OnItemLongClickListener
  %7B%0A    s
@@ -1299,16 +1299,118 @@
 tionBar;
+%0A    // zoom animation%0A    private Animator mCurrentAnimator;%0A    private int mShortAnimationDuration;
 %0A%0A    @O
@@ -2102,24 +2102,176 @@
 ener(this);%0A
+        gridView.setOnItemLongClickListener(this);%0A        mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);%0A
     %7D%0A%0A    @
@@ -2359,24 +2359,99 @@
  long id) %7B%0A
+        Log.i(TAG, %22onItemClick:%22 + v + %22 pos=%22 + position + %22 id=%22 + id);%0A
         Inte
@@ -2492,16 +2492,32 @@
 ON_VIEW,
+%0A               
  customG
@@ -2605,32 +2605,573 @@
 intent);%0A    %7D%0A%0A
+    @Override%0A    public boolean onItemLongClick(AdapterView%3C?%3E parent, View v, int position, long id) %7B%0A        Log.i(TAG, %22onItemLongClick:%22 + v + %22 pos=%22 + position + %22 id=%22 + id);%0A        Intent intent = new Intent(Intent.ACTION_EDIT,%0A                customGridAdapter.getUri(position), this,PhotoCaptionEdit.class);%0A        startActivity(intent);%0A        return true;%0A    %7D%0A%0A    @Override%0A    public void onRestart() %7B%0A        Log.i(TAG, %22onRestart%22);%0A        customGridAdapter.notifyDataSetChanged();%0A        super.onRestart();%0A    %7D%0A%0A
     @Override%0A  
@@ -4021,11 +4021,10 @@
 %0A%0A    %7D%0A
-%0A
 %7D%0A

Add notifyDataSetChanged() to refresh gridview and add longclick to edit caption