Commit 8641c806 authored by Alan McNatty's avatar Alan McNatty
Browse files

Refactored some of the Util static methods to be Artefact methods (made sense to me).

Also added support for thumbnails on the list view - still to add to the details view also.
parent 9ed811ce
......@@ -115,6 +115,29 @@
style="@android:style/TextAppearance.Small"
android:text="Allow Comments"/>
</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">
<TextView android:text="@string/upload_files_label"
android:layout_width="60dp"
android:singleLine="false"
android:layout_height="wrap_content"
android:textStyle="bold"
style="@android:style/TextAppearance.Small">
</TextView>
<ImageView android:id="@+id/txtArtefactFileThumb"
android:layout_width="96dip"
android:layout_height="96dip"
style="@android:style/TextAppearance.Small">
</ImageView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
......@@ -136,7 +159,7 @@
style="@android:style/TextAppearance.Small">
</TextView>
</LinearLayout>
<LinearLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ArtefactSettingsButtonLayout"
android:layout_width="fill_parent"
......@@ -145,16 +168,8 @@
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button android:text="@string/btnupload"
android:id="@+id/btnUpload"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/MaharaButton"
>
</Button>
<Button android:text="@string/btnview"
android:id="@+id/btnView"
<Button android:text="@string/btnedit"
android:id="@+id/btnEdit"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
......
......@@ -3,48 +3,11 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/gradient"
android:background="@drawable/gradient"
>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/middle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/gradient"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="0dp"
>
<TextView android:id="@+id/banner_text"
android:text="@string/artefacts_banner_text"
android:layout_width="wrap_content"
android:singleLine="false"
android:layout_height="wrap_content"
android:textStyle="bold"
style="@android:style/TextAppearance.Large"
android:layout_below="@+id/banner"
/>
<TextView android:id="@+id/banner_text2"
android:text="@string/artefacts_banner_text2"
android:layout_width="fill_parent"
android:singleLine="false"
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Small"
android:layout_below="@+id/banner_text"
/>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/body_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/headerBackground"
android:layout_below="@+id/middle"
>
<ImageView
android:id="@+id/saved"
......@@ -61,7 +24,6 @@
android:singleLine="true"
android:layout_height="wrap_content"
style="@style/headerText"
android:layout_below="@+id/banner_text2"
android:layout_marginLeft="10dp"
android:gravity="left|bottom"
android:layout_toRightOf="@id/saved"
......
......@@ -10,7 +10,7 @@
<string name="options_menu_account">Account &amp; Sync</string>
<string name="options_menu_camera">Camera</string>
<string name="options_menu_gallery">Gallery</string>
<string name="options_menu_compose">Write Journal</string>
<string name="options_menu_compose">Write</string>
<string name="options_menu_deleteall">Delete All</string>
<string name="options_menu_uploadall">Upload All</string>
<string name="options_menu_viewsaved">Saved</string>
......@@ -86,19 +86,17 @@
<string name="pref_menu_scan">Scan</string>
<string name="btnok">OK</string>
<string name="btnnewjournalpost_write">New Journal Entry</string>
<string name="btnnewjournalpost_camera">Take a Picture</string>
<string name="btnedit">Edit</string>
<string name="btnupload">Upload</string>
<string name="btnsave">Save</string>
<string name="btndelete">Delete</string>
<string name="btnsendlabel">Send</string>
<string name="btnview">View</string>
<string name="btncancellabel">Cancel</string>
<string name="lbluploadoptions">Upload Settings</string>
<string name="artifact_retrieve_error">Error Retrieving Details</string>
<string name="artifactsettings">Settings</string>
<string name="artifactsettings">Post Settings</string>
<string name="transferprogress">Upload progress</string>
<string name="uploadstarting">Your Upload is Starting</string>
<string name="uploadfinished">Your Upload is Finished</string>
......@@ -127,8 +125,9 @@
<string name="upload_title_label">Title:</string>
<string name="upload_description_label">Entry:</string>
<string name="upload_tags_label">Tag(s):</string>
<string name="upload_time_label">Saved:</string>
<string name="upload_time_label">Last:</string>
<string name="upload_files_label">Files:</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>
<string name="load_config_success">Successfully loaded the configuration file.</string>
......
......@@ -21,7 +21,9 @@
package nz.net.catalyst.MaharaDroid;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import org.json.JSONArray;
import org.json.JSONException;
......@@ -40,6 +42,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;
......@@ -99,49 +103,6 @@ public class Utils {
return false;
}
public static String getFilePath(Context context, String u) {
Uri uri = Uri.parse(u);
String file_path = 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.DATA}, null, null, null);
if (cursor != null) {
if ( DEBUG ) Log.d(TAG, "cursor query succeeded");
cursor.moveToFirst();
try {
file_path = 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;
}
} else {
if ( DEBUG ) Log.d(TAG, "Not content scheme - returning native path");
// Not a content query
file_path = uri.getPath();
File t = new File(file_path);
if ( ! t.exists() )
return null;
}
// Online image not in gallery
// TODO check http://jimmi1977.blogspot.co.nz/2012/01/android-api-quirks-getting-image-from.html
// for workaround
if ( file_path == "null" ){
return null;
}
if ( DEBUG ) Log.d(TAG, "file path valid [" + file_path + "]");
return file_path;
}
public static String updateTokenFromResult(JSONObject json, Context mContext) {
String newToken = null;
......
......@@ -21,17 +21,35 @@
package nz.net.catalyst.MaharaDroid.data;
import java.io.File;
import java.util.List;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.ui.ArtefactExpandableListAdapterActivity;
import nz.net.catalyst.MaharaDroid.ui.ArtifactSettingsActivity;
import nz.net.catalyst.MaharaDroid.upload.TransferService;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.util.Log;
public class Artefact extends Object implements Parcelable {
static final String TAG = LogConfig.getLogTag(Artefact.class);
// whether DEBUG level logging is enabled (whether globally, or explicitly
// for this log tag)
static final boolean DEBUG = LogConfig.isDebug(TAG);
// whether VERBOSE level logging is enabled
static final boolean VERBOSE = LogConfig.VERBOSE;
private long id = 0;
private long time;
private String filename;
......@@ -52,6 +70,9 @@ public class Artefact extends Object implements Parcelable {
public String getFilename() {
return filename;
}
public String getBaseFilename() {
return ( filename == null ) ? null : filename.substring(filename.lastIndexOf("/") + 1);
}
public String getTitle() {
return title;
}
......@@ -251,5 +272,83 @@ public class Artefact extends Object implements Parcelable {
artefactData.loadSavedArtefacts(id);
artefactData.close();
}
public String getFilePath(Context context) {
if ( filename == null )
return null;
Uri uri = Uri.parse(filename);
String file_path = 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.DATA}, null, null, null);
if (cursor != null) {
if ( DEBUG ) Log.d(TAG, "cursor query succeeded");
cursor.moveToFirst();
try {
file_path = 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;
}
} else {
if ( DEBUG ) Log.d(TAG, "Not content scheme - returning native path");
// Not a content query
file_path = uri.getPath();
File t = new File(file_path);
if ( ! t.exists() )
return null;
}
// Online image not in gallery
// TODO check http://jimmi1977.blogspot.co.nz/2012/01/android-api-quirks-getting-image-from.html
// for workaround
if ( file_path == "null" ){
return null;
}
if ( DEBUG ) Log.d(TAG, "file path valid [" + file_path + "]");
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;
}
}
......@@ -151,7 +151,7 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
// Only include artefacts with either no attached file or valid files (may have been deleted in the background so we check)
if ( a.getFilename() == null ||
( a.getFilename() != null && Utils.getFilePath(mContext, a.getFilename()) != null ) ) {
( a.getFilename() != null && a.getFilePath(mContext) != null ) ) {
a_array[items++] = a;
} else {
Log.i(TAG, "Artefact '" + a.getTitle() +
......
......@@ -289,6 +289,7 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
}
Date date = new Date (art.getTime());
LinearLayout l;
// TODO General YUCK .. need to clean up and create a Journal / MaharaProvide class / utility methods
// && Long.valueOf(art.getJournalId()) <= 0
if ( art.isJournal() ) {
......@@ -308,24 +309,38 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
if ( DEBUG ) Log.d(TAG, "getChildView draft: " + art.getIsDraft());
if ( DEBUG ) Log.d(TAG, "getChildView allow comments: " + art.getAllowComments());
}
// TDODO hide layout
l = (LinearLayout)convertView.findViewById(R.id.ArtefactJournalLayout);
if ( l != null ) l.setVisibility(LinearLayout.VISIBLE);
l = (LinearLayout)convertView.findViewById(R.id.ArtefactJournalExtrasLayout);
if ( l != null ) l.setVisibility(LinearLayout.VISIBLE);
} else {
// TDODO hide layout
LinearLayout l;
l = (LinearLayout)convertView.findViewById(R.id.ArtefactJournalLayout);
if ( l != null ) l.setVisibility(LinearLayout.GONE);
l = (LinearLayout)convertView.findViewById(R.id.ArtefactJournalExtrasLayout);
if ( l != null ) l.setVisibility(LinearLayout.GONE);
}
((TextView) convertView.findViewById(R.id.txtArtefactTime)).setText(date.toString());
((TextView) convertView.findViewById(R.id.txtArtefactFilename)).setText(art.getFilename());
((TextView) convertView.findViewById(R.id.txtArtefactDescription)).setText(art.getDescription());
((TextView) convertView.findViewById(R.id.txtArtefactTags)).setText(art.getTags());
((Button) convertView.findViewById(R.id.btnUpload)).setOnClickListener(this);
((Button) convertView.findViewById(R.id.btnUpload)).setTag(art);
((Button) convertView.findViewById(R.id.btnView)).setEnabled( art.getFilename() != null );
((Button) convertView.findViewById(R.id.btnView)).setOnClickListener(this);
((Button) convertView.findViewById(R.id.btnView)).setTag(art);
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));
iv.setClickable(true);
iv.setOnClickListener(this);
iv.setTag(art);
iv.invalidate();
if ( l != null ) l.setVisibility(LinearLayout.VISIBLE);
} else {
if ( l != null ) l.setVisibility(LinearLayout.GONE);
}
((Button) convertView.findViewById(R.id.btnEdit)).setOnClickListener(this);
((Button) convertView.findViewById(R.id.btnEdit)).setTag(art);
((Button) convertView.findViewById(R.id.btnDelete)).setOnClickListener(this);
((Button) convertView.findViewById(R.id.btnDelete)).setTag(art);
return convertView;
......@@ -397,10 +412,10 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
Artefact a = (Artefact) v.getTag();;
switch (v.getId()) {
case R.id.btnUpload:
case R.id.btnEdit:
a.edit(eContext);
break;
case R.id.btnView:
case R.id.txtArtefactFileThumb:
a.view(eContext);
break;
case R.id.btnDelete:
......
......@@ -165,15 +165,7 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
// If single - show the title (with default) and description
if ( uris.length == 1 ) {
if ( DEBUG ) Log.d(TAG, "Have a single upload");
String filepath = Utils.getFilePath(this, uris[0]);
if (filepath != null) {
// Default the title to the filename and make it all selected for easy replacement
String title = filepath.substring(filepath.lastIndexOf("/") + 1);
((EditText)findViewById(R.id.txtArtefactTitle)).setText(title);
((EditText)findViewById(R.id.txtArtefactTitle)).selectAll();
if ( DEBUG ) Log.d(TAG, "filepath = '" + filepath + "'");
}
setDefaultTitle(uris[0]);
} else if ( uris.length > 1 ) {
if ( DEBUG ) Log.d(TAG, "Have a multi upload");
} else {
......@@ -192,6 +184,22 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
btnUpload.setEnabled(false);
}
}
private void setDefaultTitle(String f) {
EditText et = (EditText)findViewById(R.id.txtArtefactTitle);
if ( et.getText().toString().length() > 0 ) {
return;
}
if (f != null) {
// Default the title to the filename and make it all selected for easy replacement
String title = f.substring(f.lastIndexOf("/") + 1);
et.setText(title);
et.selectAll();
if ( DEBUG ) Log.d(TAG, "setDefaultTitle: '" + title + "'");
}
}
private void setDefaultTag() {
if ( mPrefs.getBoolean(getResources().getString(R.string.pref_upload_tags_default_key), false) ) {
......@@ -272,7 +280,6 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
String title = ((EditText)findViewById(R.id.txtArtefactTitle)).getText().toString();
String description = ((EditText)findViewById(R.id.txtArtefactDescription)).getText().toString();
String tags = ((EditText) findViewById(R.id.txtArtefactTags)).getText().toString();
String filename = null;
int jk = (int) ((Spinner) findViewById(R.id.upload_journal_spinner)).getSelectedItemId();
String journal = journalKeys[jk];
......@@ -316,9 +323,8 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
for ( int i = 0; i < uris.length; i++ ) {
filename = ( uris[i] == null || Utils.getFilePath(this, uris[i]) == null ) ? null : filename;
a.setFilename(filename);
if ( VERBOSE ) Log.v(TAG, "InitiateUpload have file, name is '" + filename + "'");
a.setFilename(uris[i]);
if ( VERBOSE ) Log.v(TAG, "InitiateUpload have file, name is '" + uris[i] + "'");
uploader_intent = new Intent(this, TransferService.class);
uploader_intent.putExtra("artefact", a);
......@@ -426,16 +432,20 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
Uri uri;
switch (requestCode) {
case GlobalResources.REQ_CAMERA_RETURN:
if ( ! intent.hasExtra(MediaStore.EXTRA_OUTPUT) )
break;
uri = (Uri) intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
a.setFilename(uri.toString());
a.save(mContext);
// a.setFilename(uri.toString());
// a.save(mContext);
uris = new String[] { uri.toString() };
setDefaultTitle(uris[0]);
break;
case GlobalResources.REQ_GALLERY_RETURN:
uri = intent.getData();
a.setFilename(uri.toString());
a.save(mContext);
// a.setFilename(uri.toString());
// a.save(mContext);
uris = new String[] { uri.toString() };
setDefaultTitle(uris[0]);
break;
}
}
......
......@@ -88,7 +88,7 @@ public class TransferService extends Service {
a.getIsDraft(), a.getAllowComments(),
getUploadFolderPref(),
getUploadTagsPref(a.getTags()),
a.getFilename(),
a.getFilePath(mContext),
a.getTitle(),
a.getDescription(),
mContext);
......@@ -106,16 +106,7 @@ public class TransferService extends Service {
//m_uploads.clear();
} else if ( result.has("success") ) {
Utils.updateTokenFromResult(result, mContext);
// if ( result.has("id") ) {
// try {
// a.setId(result.getLong("id"));
// a.save(mContext);
// } catch (JSONException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
a.delete(mContext);
// }
a.delete(mContext);
publishProgress(new String[]{"finish", id, a.getTitle()});
}
}
......
......@@ -276,7 +276,7 @@ public class RestClient {
title = paramVals[i];
}
else if (paramNames[i].equals("filename")) {
file = new File(Utils.getFilePath(context, paramVals[i]));
file = new File(paramVals[i]);
continue;
}
sig_params.put(paramNames[i], paramVals[i]);
......
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