Commit 800f8911 authored by Alan McNatty's avatar Alan McNatty

Fixed a few bugs (I catch and removed save on capture incase of cancel).

Also improved thumbnail, added default - changed way the default is shown (not on details -I think that is OK).
Also fixed the intent handling by adding some mimetype setDataAndType .. pretty nasty how you have to
find the mime-type and set the filter for each possible type .. doesn't seem to be a better way .. oh well - best efforts
for our supported content (see Manifest activity filters).
parent 0eeb1ff2
......@@ -135,6 +135,7 @@
<ImageView android:id="@+id/txtArtefactFileThumb"
android:layout_width="96dip"
android:layout_height="96dip"
android:src="@drawable/nopreview"
style="@android:style/TextAppearance.Small">
</ImageView>
......
......@@ -108,12 +108,12 @@
<string name="uploadingartifact">Uploading ...</string>
<string name="uploading">Uploading</string>
<string name="uploadnoconnection">Sorry you don\'t have a working data connection to upload at this time.</string>
<string name="uploadincomplete">Enter a title and an entry for journals</string>
<string name="uploadincomplete">Sorry you must enter a title and an entry for journal posts</string>
<string name="filetransfers">File Transfers</string>
<string name="upload_journal_label">Journal:</string>
<string name="upload_journal_prompt">Upload as file or choose Journal</string>
<string name="upload_journal_default">Upload as file</string>
<string name="upload_journal_prompt">Upload file(s) or post to a Journal</string>
<string name="upload_journal_default">Upload file(s)</string>
<string name="upload_is_draft_label"></string>
<string name="upload_is_draft_text">Check this if your entry is a draft. As a draft no one except you can see it.</string>
<string name="upload_allow_comments_label"></string>
......@@ -129,7 +129,7 @@
<string name="upload_journal_description_label">Entry:</string>
<string name="upload_tags_label">Tag(s):</string>
<string name="upload_time_label">Last:</string>
<string name="upload_files_label">Files:</string>
<string name="upload_files_label">File:</string>
<string name="load_config_download_error">Sorry there was an error downloading the configuration file.</string>
<string name="load_config_error">Sorry there was an error parsing the configuration file.</string>
......
......@@ -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 = false;
private static final boolean DEBUG = true;
/**
* 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 = false;
public static final boolean VERBOSE = true;
private static final int MAX_LOG_TAG_LENGTH = 23;
......
......@@ -353,15 +353,14 @@ public class Utils {
} 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");
if ( DEBUG ) Log.d(TAG, "getFileThumbData couldn't get content from file cursor");
}
cursor.close();
}
}
return bm;
}
}
......@@ -27,6 +27,7 @@ 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.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
......@@ -245,8 +246,21 @@ public class Artefact extends Object implements Parcelable {
artefactData.close();
}
public void view(Context mContext) {
Intent i = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(this.getFilename()));
mContext.startActivity(i);
try {
Intent i;
String mimetype = this.getFileMimeType(mContext);
if ( mimetype == null ) {
i = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(this.getFilename()));
} else {
i = new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.parse(this.getFilename()), mimetype);
if ( DEBUG ) Log.d(TAG, "Artefact mimetype '" + mimetype + "'");
}
mContext.startActivity(i);
} catch ( ActivityNotFoundException e ) {
// If activity not found you need to set SetDataAndType .. ideally we'd get the type
// from the content query
Log.e(TAG, "Artefact view error - not activity found for '" + this.getFilename() + "'");
}
}
public void edit(Context mContext) {
......@@ -284,7 +298,8 @@ public class Artefact extends Object implements Parcelable {
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.DATA}, null, null, null);
Cursor cursor = cr.query(uri, new String[]{ android.provider.MediaStore.MediaColumns.DATA,
android.provider.MediaStore.MediaColumns.MIME_TYPE}, null, null, null);
if (cursor != null) {
if ( DEBUG ) Log.d(TAG, "cursor query succeeded");
cursor.moveToFirst();
......@@ -317,8 +332,47 @@ public class Artefact extends Object implements Parcelable {
if ( DEBUG ) Log.d(TAG, "file path valid [" + file_path + "]");
return file_path;
}
public String getFileMimeType(Context context) {
if ( filename == null )
return null;
Uri uri = Uri.parse(filename);
String mimetype = null;
if ( DEBUG ) Log.d(TAG, "URI = '" + uri.toString() + "', scheme = '" + uri.getScheme() + "'");
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.MIME_TYPE}, null, null, null);
if (cursor != null) {
if ( DEBUG ) Log.d(TAG, "cursor query succeeded");
cursor.moveToFirst();
try {
mimetype = cursor.getString(0);
} catch ( android.database.CursorIndexOutOfBoundsException e ) {
if ( DEBUG ) Log.d(TAG, "couldn't get file_path from cursor");
return null;
}
cursor.close();
} else {
if ( DEBUG ) Log.d(TAG, "cursor query failed");
return null;
}
// TODO .. Yuck - extend this?
} else if ( uri.getLastPathSegment().endsWith(".mp4") ) {
mimetype = "video/mp4";
} else if ( uri.getLastPathSegment().endsWith(".mp3") ) {
mimetype = "audio/mp3";
} else if ( uri.getLastPathSegment().endsWith(".m4a") ) {
mimetype = "audio/mpeg";
}
return mimetype;
}
public Bitmap getFileThumbData(Context context) {
return Utils.getFileThumbData(context, this.filename);
return Utils.getFileThumbData(context, this.getFilename());
}
}
......@@ -34,6 +34,7 @@ import nz.net.catalyst.MaharaDroid.ui.about.AboutActivity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
......@@ -338,13 +339,18 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
l = (LinearLayout)convertView.findViewById(R.id.ArtefactFileLayout);
if ( art.getFilename() != null ) {
ImageView iv = (ImageView) convertView.findViewById(R.id.txtArtefactFileThumb);
((TextView) convertView.findViewById(R.id.txtArtefactFilename)).setText(art.getFilename());
iv.setImageBitmap(art.getFileThumbData(eContext));
ImageView iv = (ImageView) convertView.findViewById(R.id.txtArtefactFileThumb);
iv.setClickable(true);
iv.setOnClickListener(this);
iv.setTag(art);
iv.invalidate();
Bitmap bm = art.getFileThumbData(eContext);
if ( bm != null ) {
iv.setImageBitmap(bm);
iv.invalidate();
}
if ( l != null ) l.setVisibility(LinearLayout.VISIBLE);
} else {
if ( l != null ) l.setVisibility(LinearLayout.GONE);
......
......@@ -484,7 +484,7 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
}
a.setFilename(uri.toString());
setDefaultTitle(a.getBaseFilename(mContext));
a.save(mContext);
//a.save(mContext); // don't auto save - they might want to cancel
uris = new String[] { uri.toString() };
break;
case GlobalResources.REQ_GALLERY_RETURN:
......@@ -493,7 +493,7 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
a = new Artefact(uri.toString());
}
a.setFilename(uri.toString());
a.save(mContext);
//a.save(mContext); // don't auto save - they might want to cancel
setDefaultTitle(a.getBaseFilename(mContext));
uris = new String[] { uri.toString() };
break;
......
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