Skip to content

Commit e53a5ad

Browse files
committedMar 30, 2012
Major UI improvements to list.
1 parent 876c51f commit e53a5ad

File tree

5 files changed

+152
-52
lines changed

5 files changed

+152
-52
lines changed
 
File renamed without changes.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="fill_parent"
5+
android:layout_height="fill_parent">
6+
<TextView android:id="@+id/name"
7+
android:textSize="14sp"
8+
android:textStyle="bold"
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"/>
11+
<TextView android:id="@+id/state"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"/>
14+
</LinearLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package ca.ilanguage.rhok.imageupload;
2+
3+
public class Sample {
4+
public String name;
5+
public boolean processed;
6+
}

‎android/src/ca/ilanguage/rhok/imageupload/ui/SampleDetailsActivity.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,19 @@
2525
import android.widget.TextView;
2626

2727
public class SampleDetailsActivity extends Activity {
28-
String filepath;
29-
3028
/** Called when the activity is first created. */
3129
@Override
3230
public void onCreate(Bundle savedInstanceState) {
3331
super.onCreate(savedInstanceState);
3432
setContentView(R.layout.sample_details);
35-
filepath = App.getProcessedImageFolder(this) + File.separator
36-
+ getIntent().getStringExtra("filename");
33+
String name = getIntent().getStringExtra("name");
34+
File imagefile = new File(App.getProcessedImageFolder(this), name + ".jpg");
3735
ImageView v = (ImageView) findViewById(R.id.result_image);
3836

3937
FileInputStream in;
4038
BufferedInputStream buf;
4139
try {
42-
in = new FileInputStream(filepath);
40+
in = new FileInputStream(imagefile);
4341
buf = new BufferedInputStream(in);
4442
Bitmap bMap = BitmapFactory.decodeStream(buf);
4543
v.setImageBitmap(bMap);
@@ -54,11 +52,8 @@ public void onCreate(Bundle savedInstanceState) {
5452
}
5553
TextView t = (TextView) findViewById(R.id.result_text);
5654
try {
57-
filepath = App.getResultsFolder(this)
58-
+ File.separator
59-
+ getIntent().getStringExtra("filename").replace(".jpg",
60-
".xml");
61-
in = new FileInputStream(filepath);
55+
File xmlfile = new File(App.getProcessedImageFolder(this), name + ".xml");
56+
in = new FileInputStream(xmlfile);
6257
BufferedReader source = new BufferedReader(
6358
new InputStreamReader(in));
6459

Original file line numberDiff line numberDiff line change
@@ -1,62 +1,108 @@
11
package ca.ilanguage.rhok.imageupload.ui;
22

33
import java.io.File;
4-
import java.io.FileNotFoundException;
54
import java.util.ArrayList;
6-
import java.util.Collections;
75
import java.util.List;
86
import java.util.UUID;
97

108
import ca.ilanguage.rhok.imageupload.App;
119
import ca.ilanguage.rhok.imageupload.PetriFilmProcessingIntentService;
1210
import ca.ilanguage.rhok.imageupload.R;
11+
import ca.ilanguage.rhok.imageupload.Sample;
12+
import android.app.AlertDialog;
1313
import android.app.Dialog;
1414
import android.app.ListActivity;
1515
import android.app.ProgressDialog;
16+
import android.content.Context;
17+
import android.content.DialogInterface;
1618
import android.content.Intent;
1719
import android.net.Uri;
1820
import android.os.AsyncTask;
1921
import android.os.Bundle;
22+
import android.os.Handler;
2023
import android.util.Log;
24+
import android.view.LayoutInflater;
2125
import android.view.View;
26+
import android.view.ViewGroup;
2227
import android.widget.ArrayAdapter;
28+
import android.widget.EditText;
2329
import android.widget.ListView;
30+
import android.widget.TextView;
2431
import android.widget.Toast;
2532

2633
public class SampleListActivity extends ListActivity {
2734
private static final String TAG = "ca.ilanguage.rhok";
2835
public static final int POPULATING_DIALOG = 54;
2936

30-
static String[] samples = new String[] { "Water Source #1",
31-
"Street #3 Sample" };
37+
List<Sample> samples;
3238

3339
static int PETRI_IMAGE_REQUEST = 1;
34-
static int PROCESS_IMAGE_REQUEST = 2;
40+
// static int PROCESS_IMAGE_REQUEST = 2;
3541

3642
/** Called when the activity is first created. */
3743
@Override
3844
public void onCreate(Bundle savedInstanceState) {
3945
super.onCreate(savedInstanceState);
40-
setContentView(R.layout.samplelist);
41-
setListAdapter(new ArrayAdapter<String>(this,
42-
android.R.layout.simple_list_item_1, samples));
43-
new PopulateSamplesListTask().execute(null);
44-
46+
setContentView(R.layout.sample_list_activity);
47+
refreshList();
4548
}
4649

4750
public void onNewSampleClick(View v) {
48-
Intent intent = new Intent(this, PetrifilmCameraActivity.class);
49-
String guid = UUID.randomUUID().toString();
50-
intent.putExtra("filename", "petri_" + guid + ".jpg");
51-
startActivityForResult(intent, PETRI_IMAGE_REQUEST);
51+
AlertDialog.Builder alert = new AlertDialog.Builder(this);
52+
53+
alert.setTitle("New Sample");
54+
alert.setMessage("Enter sample name");
55+
56+
// Set an EditText view to get user input
57+
final EditText input = new EditText(this);
58+
alert.setView(input);
59+
60+
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
61+
public void onClick(DialogInterface dialog, int whichButton) {
62+
String name = input.getText().toString();
63+
Intent intent = new Intent(SampleListActivity.this,
64+
PetrifilmCameraActivity.class);
65+
intent.putExtra("filename", name + ".jpg");
66+
startActivityForResult(intent, PETRI_IMAGE_REQUEST);
67+
}
68+
});
69+
70+
alert.setNegativeButton("Cancel",
71+
new DialogInterface.OnClickListener() {
72+
public void onClick(DialogInterface dialog, int whichButton) {
73+
// Canceled.
74+
}
75+
});
76+
77+
alert.show();
5278
}
5379

80+
void refreshList()
81+
{
82+
final Handler handler=new Handler();
83+
final Runnable r = new Runnable()
84+
{
85+
public void run()
86+
{
87+
new PopulateSamplesListTask().execute();
88+
handler.postDelayed(this, 1000);
89+
}
90+
};
91+
92+
handler.post(r);
93+
}
94+
5495
@Override
5596
protected void onListItemClick(ListView l, View v, int position, long id) {
56-
Intent intent = new Intent(this, SampleDetailsActivity.class);
57-
intent.putExtra("filename", samples[position].replace("Pending - ", "").replace("Processed - ", "")+".jpg");
58-
Log.d(TAG, "Showing processed image "+samples[position]);
59-
startActivity(intent);
97+
Sample sample = samples.get(position);
98+
if (sample.processed) {
99+
Intent intent = new Intent(this, SampleDetailsActivity.class);
100+
intent.putExtra("name", sample.name);
101+
Log.d(TAG, "Showing processed image " + samples.get(position).name);
102+
startActivity(intent);
103+
} else {
104+
Toast.makeText(this, "Still processing...", Toast.LENGTH_SHORT).show();
105+
}
60106
}
61107

62108
@Override
@@ -72,48 +118,55 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
72118
intent.putExtra("outimage", filename);
73119
Log.d(TAG, "Calling process image");
74120
startService(intent);
75-
new PopulateSamplesListTask().execute(null);
121+
new PopulateSamplesListTask().execute();
76122
}
77123

78-
if (requestCode == PROCESS_IMAGE_REQUEST && resultCode == RESULT_OK) {
79-
Log.d(TAG, "Called process image");
80-
String outpath = data.getStringExtra("outpath");
81-
82-
// Launch image viewer
83-
Intent intent = new Intent();
84-
intent.setAction(Intent.ACTION_VIEW);
85-
intent.setDataAndType(Uri.parse("file://" + outpath), "image/*");
86-
startActivity(intent);
87-
}
124+
// if (requestCode == PROCESS_IMAGE_REQUEST && resultCode == RESULT_OK) {
125+
// Log.d(TAG, "Called process image");
126+
// String outpath = data.getStringExtra("outpath");
127+
//
128+
// // Launch image viewer
129+
// Intent intent = new Intent();
130+
// intent.setAction(Intent.ACTION_VIEW);
131+
// intent.setDataAndType(Uri.parse("file://" + outpath), "image/*");
132+
// startActivity(intent);
133+
// }
88134
}
89135

90136
public class PopulateSamplesListTask extends AsyncTask<Void, Void, Boolean> {
91137
@Override
92138
protected Boolean doInBackground(Void... params) {
93139
File dir = new File(
94140
App.getOriginalImageFolder(getApplicationContext()));
95-
samples = dir.list();
96-
for(int s = 0; s<samples.length; s++){
97-
String status = "Pending - ";
98-
File results = new File(App.getResultsFolder(getApplicationContext()) + File.separator + samples[s].replace(".jpg", ".xml"));
99-
if(results.exists()){
100-
status = "Processed - ";
101-
}
102-
samples[s] = status + samples[s].replace(".jpg", "");
141+
String[] sampleFiles = dir.list();
142+
samples = new ArrayList<Sample>();
143+
for (int s = 0; s < sampleFiles.length; s++) {
144+
// Trim .jpg
145+
Sample sample = new Sample();
146+
sample.name = sampleFiles[s].substring(0,
147+
sampleFiles[s].length() - 4);
148+
File results = new File(
149+
App.getResultsFolder(getApplicationContext()),
150+
sample.name + ".xml");
151+
if (results.exists())
152+
sample.processed = true;
153+
154+
samples.add(sample);
103155
}
104156
return true;
105157
}
106158

107159
protected void onPreExecute() {
108-
showDialog(POPULATING_DIALOG);
160+
// Temporarily removing for auto-refresh. put back in when done by intent
161+
//showDialog(POPULATING_DIALOG);
109162
}
110163

111164
protected void onPostExecute(Boolean result) {
112-
dismissDialog(POPULATING_DIALOG);
113-
setListAdapter(new ArrayAdapter<String>(getApplicationContext(),
114-
android.R.layout.simple_list_item_1, samples));
165+
// Temporarily removing for auto-refresh. put back in when done by intent
166+
//dismissDialog(POPULATING_DIALOG);
167+
setListAdapter(new SampleAdapter(SampleListActivity.this,
168+
R.layout.sample_list_row, samples));
115169
}
116-
117170
}
118171

119172
@Override
@@ -130,4 +183,36 @@ protected Dialog onCreateDialog(int id) {
130183
}
131184
return dialog;
132185
}
186+
187+
class SampleAdapter extends ArrayAdapter<Sample> {
188+
private List<Sample> items;
189+
190+
public SampleAdapter(Context context, int textViewResourceId,
191+
List<Sample> samples) {
192+
super(context, textViewResourceId, samples);
193+
this.items = samples;
194+
}
195+
196+
@Override
197+
public View getView(int position, View convertView, ViewGroup parent) {
198+
View v = convertView;
199+
if (v == null) {
200+
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
201+
v = vi.inflate(R.layout.sample_list_row, null);
202+
}
203+
Sample o = items.get(position);
204+
if (o != null) {
205+
TextView tt = (TextView) v.findViewById(R.id.name);
206+
TextView bt = (TextView) v.findViewById(R.id.state);
207+
if (tt != null) {
208+
tt.setText("Name: " + o.name);
209+
}
210+
if (bt != null) {
211+
bt.setText("Status: "
212+
+ (o.processed ? "Processed" : "Pending"));
213+
}
214+
}
215+
return v;
216+
}
217+
}
133218
}

0 commit comments

Comments
 (0)
Please sign in to comment.