Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Redoing for a gallery view

  • Loading branch information...
commit c30a63e5d315d1faaf7fb56422d8db9aa0c6a7a7 1 parent f7ecb07
@tarebyte tarebyte authored
View
50 src/com/unitedware/collage/GalleryAdapter.java
@@ -0,0 +1,50 @@
+package com.unitedware.collage;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.RelativeLayout;
+
+public class GalleryAdapter extends BaseAdapter {
+
+ // Member Variables
+ Context mContext;
+ private Bitmap[] mImageArray;
+
+ public GalleryAdapter(Context context, Bitmap[] imageArrBitmaps) {
+ mContext = context;
+ mImageArray = imageArrBitmaps;
+ }
+
+ public int getCount() {
+ // TODO Auto-generated method stub
+ return mImageArray.length;
+ }
+
+ public Object getItem(int position) {
+ // TODO Auto-generated method stub
+ return position;
+ }
+
+ public long getItemId(int position) {
+ // TODO Auto-generated method stub
+ return position;
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ // TODO Auto-generated method stub
+ final ImageView imageView = new ImageView(mContext);
+ imageView.setImageBitmap(mImageArray[position]);
+
+ // put black borders around the image
+ final RelativeLayout borderImg = new RelativeLayout(mContext);
+ borderImg.setPadding(20, 20, 20, 20);
+ borderImg.setBackgroundColor(0xff000000);// black
+ borderImg.addView(imageView);
+ return borderImg;
+ }
+
+}
View
15 src/com/unitedware/collage/ImageAdapter.java
@@ -2,7 +2,6 @@
import android.content.Context;
import android.graphics.Bitmap;
-import android.os.Environment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
@@ -13,15 +12,15 @@
// Member Variables
private Context mContext;
- private Bitmap[] finalGridImages;
+ private Bitmap[] finalGalleryImages;
- public ImageAdapter(Context c, Bitmap[] gridImages) {
+ public ImageAdapter(Context c, Bitmap[] images) {
mContext = c;
- finalGridImages = gridImages;
+ finalGalleryImages = images;
}
public int getCount() {
- return finalGridImages.length;
+ return finalGalleryImages.length;
}
public Object getItem(int position) {
@@ -46,16 +45,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
// Sets imageView from Bitmap array if there are actually photos there
- if (finalGridImages[0] == null) {
+ if (finalGalleryImages[0] == null) {
imageView.setImageResource(mThumbIdsPlaceHolder[position]);
} else {
- imageView.setImageBitmap(finalGridImages[position]);
+ imageView.setImageBitmap(finalGalleryImages[position]);
}
return imageView;
}
- String dir = Environment.getExternalStorageDirectory() + "/Collage/";
-
// A place holder for right now
private Integer[] mThumbIdsPlaceHolder = { R.drawable.ic_launcher };
}
View
111 src/com/unitedware/collage/UploadPhoto.java
@@ -14,17 +14,20 @@
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
+import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
+import android.widget.Gallery;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
@@ -42,15 +45,16 @@
Button selectAnother;
Bundle extras;
Bitmap userPhoto;
- Bitmap[] gridImages;
+ Bitmap[] galleryImages;
ImageView mImageView;
TextView title;
+ String TAG = "UPLOADPHOTOACTIVITY";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photoview);
- GridView gridview = (GridView) findViewById(R.id.sdcard);
+ Gallery galleryView = (Gallery) findViewById(R.id.sdcard);
initialize();
@@ -59,30 +63,42 @@ public void onCreate(Bundle savedInstanceState) {
isViewHidden = true;
choosePhotoOption();
startUp++;
- // Setup the Bitmap Array for the Image Adapter
- gridview.setAdapter(new ImageAdapter(this, gridImages));
}
- }
- public void initialize() {
- selectAnother = (Button) findViewById(R.id.bChoosePhoto);
- selectAnother.setOnClickListener(this);
- // selectAnother.setVisibility(View.GONE);
- title = (TextView) findViewById(R.id.tvUploadTitle);
- // title.setVisibility(View.GONE);
+ String collageDir = (Environment.getExternalStorageDirectory() + "/Collage/");
+ // galleryImages = getGalleryImages(collageDir);
- /*
- * Create the directory if needed for the gridView This is setup to also
- * test to make sure if it was created, I needed something visual right
- * now, this won't go in final development
- */
+ // Sets the gallery view whether the user has photos or not
+ // if (galleryImages[0] == null) {
+ galleryView.setAdapter(new GalleryAdapter(this, null));
+ // } else {
+ // Log.v(TAG, "gallerImages is not empty!");
+ // galleryView.setAdapter(new GalleryAdapter(this, galleryImages));
+ // }
+ }
- File collageDirectory = new File(
- Environment.getExternalStorageDirectory() + "/Collage");
- boolean success = false;
- if (!collageDirectory.exists()) {
- success = collageDirectory.mkdir();
+ @SuppressWarnings("null")
+ public Bitmap[] getGalleryImages(String picDir) {
+ // TODO Auto-generated method stub
+ Bitmap[] imgArrBitmaps = null;
+
+ File filePath = new File(picDir);
+ Log.v(TAG, "The path is: " + picDir);
+ String[] filesInPath = filePath.list();
+ Log.v(TAG, "There are: " + filesInPath.length + " files in the path.");
+ Log.v(TAG, "The first file is: " + filesInPath[0]);
+ for (int i = 0; i < filesInPath.length; i++) {
+ Log.v(TAG, "Made it in the for loop");
+ String fileToConvert = picDir + filesInPath[i];
+ Log.v(TAG, "The first path file to be converted is: "
+ + fileToConvert);
+ Bitmap newImage = BitmapFactory.decodeFile(fileToConvert);
+ Log.v(TAG, newImage.toString());
+ Log.v(TAG, imgArrBitmaps[i].toString());
+ Log.v(TAG, "The Bitmap is: " + imgArrBitmaps[i]);
}
+ Log.v(TAG, "There are: " + imgArrBitmaps.length + "in the Bitmap Array");
+ return imgArrBitmaps;
}
public void choosePhotoOption() {
@@ -123,17 +139,6 @@ public void onClick(DialogInterface dialog, int item) {
}
- public boolean showView(boolean isHidden) {
-
- // Reveals layout if necessary
- if (isHidden == true) {
- selectAnother.setVisibility(View.VISIBLE);
- title.setVisibility(View.VISIBLE);
- return isHidden = false;
- }
- return isHidden;
- }
-
public void CopyandMoveFile(File sourceFile, String destination)
throws IOException {
FileChannel in = null;
@@ -165,16 +170,27 @@ public String getRealPathFromUri(Uri contentUri) {
return cursor.getString(column_index);
}
- /*
- * (non-Javadoc)
- *
- * @see android.app.Activity#onActivityResult(int, int,
- * android.content.Intent) This onActivity result needs to changed from just
- * setting one picture, to multiple pictures, in order to do this you need
- * to save these to a file directory, I have already set up the permissions.
- * This will allow me to use the ImageAdapter class grab all the photos from
- * the directory and display them into the gridview
- */
+ public void initialize() {
+ selectAnother = (Button) findViewById(R.id.bChoosePhoto);
+ selectAnother.setOnClickListener(this);
+ // selectAnother.setVisibility(View.GONE);
+ title = (TextView) findViewById(R.id.tvUploadTitle);
+ // title.setVisibility(View.GONE);
+
+ /*
+ * Create the directory if needed for the gridView This is setup to also
+ * test to make sure if it was created, I needed something visual right
+ * now, this won't go in final development
+ */
+
+ File collageDirectory = new File(
+ Environment.getExternalStorageDirectory() + "/Collage");
+ boolean success = false;
+ if (!collageDirectory.exists()) {
+ success = collageDirectory.mkdir();
+ }
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -262,4 +278,15 @@ public void onClick(View v) {
break;
}
}
+
+ public boolean showView(boolean isHidden) {
+
+ // Reveals layout if necessary
+ if (isHidden == true) {
+ selectAnother.setVisibility(View.VISIBLE);
+ title.setVisibility(View.VISIBLE);
+ return isHidden = false;
+ }
+ return isHidden;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.