Commit 2f1b1394 authored by Alan McNatty's avatar Alan McNatty

With the last commit - moved to an actual gallery. Also as we're nearing...

With the last commit - moved to an actual gallery. Also as we're nearing stable we've set debug / verbose off by default now
parent c98f476c
......@@ -208,15 +208,17 @@
</TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ArtefactFileLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
</LinearLayout>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FileGallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:gravity="center_horizontal"
android:layout_gravity="fill_horizontal"
android:spacing="5dip"
android:scrollbars="horizontal"
/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ArtefactSettingsButtonLayout"
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/file_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/txtArtefactFileThumb"
android:layout_width="96dip"
android:layout_height="96dip"
style="@android:style/TextAppearance.Small">
</ImageView>
</FrameLayout>
\ No newline at end of file
......@@ -46,7 +46,7 @@ public class LogConfig {
* Rather than checking this directly, classes should use LogConfig.isDebug(TAG) to
* determine whether to log a DEBUG level.
*/
private static final boolean DEBUG = true;
private static final boolean DEBUG = false;
/**
* Whether the application should allow any tags to log at VERBOSE level.
......@@ -56,7 +56,7 @@ public class LogConfig {
* The Java compiler is unable to strip out calls to Log.isLoggable()
* (although, maybe the Dalvik compiler, or the JIT can ???)
*/
public static final boolean VERBOSE = true;
public static final boolean VERBOSE = false;
private static final int MAX_LOG_TAG_LENGTH = 23;
......
......@@ -37,6 +37,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
......@@ -325,4 +327,36 @@ public class Utils {
cursor.close();
return new String[][] { k, v };
}
public static Bitmap getFileThumbData(Context context, String filename) {
Uri uri = Uri.parse(filename);
Bitmap bm = null;
if ( uri.getScheme() != null && uri.getScheme().equals("content") ) {
// Get the filename of the media file and use that as the default title.
ContentResolver cr = context.getContentResolver();
Cursor cursor = cr.query(uri, new String[]{android.provider.MediaStore.MediaColumns._ID}, null, null, null);
if (cursor != null) {
if ( DEBUG ) Log.d(TAG, "cursor query succeeded");
cursor.moveToFirst();
try {
Long id = cursor.getLong(0);
cursor.close();
if ( uri.getPath().contains("images") ) {
// Default to try image thumbnail ..
bm = MediaStore.Images.Thumbnails.getThumbnail(cr, id, MediaStore.Images.Thumbnails.MICRO_KIND, null);
} else if ( uri.getPath().contains("video") ) {
// else look for a video thumbnail
bm = MediaStore.Video.Thumbnails.getThumbnail(cr, id, MediaStore.Video.Thumbnails.MICRO_KIND, null);
} else {
bm = BitmapFactory.decodeResource(null, context.getApplicationInfo().icon, null);
}
} catch ( android.database.CursorIndexOutOfBoundsException e ) {
if ( DEBUG ) Log.d(TAG, "couldn't get file_path from cursor");
}
cursor.close();
}
}
return bm;
}
}
......@@ -24,6 +24,7 @@ package nz.net.catalyst.MaharaDroid.data;
import java.io.File;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.Utils;
import nz.net.catalyst.MaharaDroid.ui.ArtifactSettingsActivity;
import nz.net.catalyst.MaharaDroid.upload.TransferService;
import android.content.ContentResolver;
......@@ -317,36 +318,7 @@ public class Artefact extends Object implements Parcelable {
return file_path;
}
public Bitmap getFileThumbData(Context context) {
Uri uri = Uri.parse(filename);
Bitmap bm = null;
if ( uri.getScheme() != null && uri.getScheme().equals("content") ) {
// Get the filename of the media file and use that as the default title.
ContentResolver cr = context.getContentResolver();
Cursor cursor = cr.query(uri, new String[]{android.provider.MediaStore.MediaColumns._ID}, null, null, null);
if (cursor != null) {
if ( DEBUG ) Log.d(TAG, "cursor query succeeded");
cursor.moveToFirst();
try {
Long id = cursor.getLong(0);
cursor.close();
if ( uri.getPath().contains("images") ) {
// Default to try image thumbnail ..
bm = MediaStore.Images.Thumbnails.getThumbnail(cr, id, MediaStore.Images.Thumbnails.MICRO_KIND, null);
} else if ( uri.getPath().contains("video") ) {
// else look for a video thumbnail
bm = MediaStore.Video.Thumbnails.getThumbnail(cr, id, MediaStore.Video.Thumbnails.MICRO_KIND, null);
} else {
bm = BitmapFactory.decodeResource(null, context.getApplicationInfo().icon, null);
}
} catch ( android.database.CursorIndexOutOfBoundsException e ) {
if ( DEBUG ) Log.d(TAG, "couldn't get file_path from cursor");
}
cursor.close();
}
}
return bm;
return Utils.getFileThumbData(context, this.filename);
}
}
......@@ -37,19 +37,22 @@ import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
......@@ -92,6 +95,7 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
// 2) by attaching a single photo to the UI if the artefact object
// doesn't yet exist (multi scenario only) - one will be created
private Artefact a;
private ImageAdapter ia;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -164,8 +168,6 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
setDefaultJournal();
// TODO - get working .. for multiple files by URL also .. no operational yet :(
// showFileThumbnail(a);
} else if ( m_extras.containsKey("uri") ) {
if ( DEBUG ) Log.d(TAG, "Have a new upload");
......@@ -198,35 +200,18 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
btnUpload.setEnabled(false);
}
}
private void showFileThumbnail(Artefact art) {
// TODO Auto-generated method stub
LinearLayout l = (LinearLayout) findViewById(R.id.ArtefactFileLayout);
if ( VERBOSE ) Log.v(TAG, "showFileThumbnail called");
public void onStart() {
super.onStart();
}
public void onResume() {
super.onResume();
ia = new ImageAdapter(this, uris);
Gallery gallery = (Gallery) findViewById(R.id.FileGallery);
gallery.setAdapter(ia);
}
if ( art.getFilename() != null ) {
LayoutInflater inflator = getLayoutInflater();
// we set attachToRoot to false so that the returned view is the
// link frame, not parent's root
View linkFrame = inflator.inflate(R.layout.artefact_settings_file_frame, l, false);
ImageView iv = (ImageView) linkFrame.findViewById(R.id.txtArtefactFileThumb);
// ((TextView) findViewById(R.id.txtArtefactFilename)).setText(art.getFilename());
iv.setImageBitmap(art.getFileThumbData(mContext));
iv.setClickable(true);
iv.setOnClickListener(this);
iv.setTag(art);
iv.invalidate();
if ( l != null ) l.setVisibility(LinearLayout.VISIBLE);
l.invalidate();
((View) l.getParent()).invalidate();
if ( DEBUG ) Log.d(TAG, "Adding file '" + art.getFilename() + "' thumbnail to view");
} else {
if ( l != null ) l.setVisibility(LinearLayout.GONE);
if ( VERBOSE ) Log.v(TAG, "no file(name) so no thumbnail(s) to show");
}
}
private void setDefaultTitle(String f) {
EditText et = (EditText)findViewById(R.id.txtArtefactTitle);
......@@ -578,4 +563,43 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
tv.setText(getResources().getString(R.string.upload_file_description_label));
}
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private String[] u = new String[] { };
public ImageAdapter(Context c, String[] uris) {
mContext = c;
u = uris;
}
public int getCount() {
return u.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView iv = new ImageView(mContext);
iv.setImageBitmap(Utils.getFileThumbData(mContext, u[position]));
// iv.setClickable(true);
// iv.setOnClickListener(this);
// iv.setLayoutParams(new Gallery.LayoutParams(96, 96));
// iv.setPadding(4, 4, 4, 4);
// iv.setScaleType(ImageView.ScaleType.FIT_XY);
// imageView.setBackgroundResource(mGalleryItemBackground);
// parent.invalidate();
// convertView.invalidate();
return iv;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment