Added comments, string and integer values, and text view for Async.

Trouble connecting to host to download images now. Don't know if it is
my network problem or not. Made no changes to downloading code.
master
tokugawa 2014-03-10 00:07:57 -04:00
parent a7b8f196a2
commit f0c626dcaf
5 changed files with 27 additions and 17 deletions

View File

@ -15,7 +15,7 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:numColumns="@integer/COLUMN_COUNT"
android:numColumns="@integer/column_count"
android:columnWidth="90dp" />
<Button
@ -23,6 +23,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/Exit" />
android:text="@string/exit_button_text" />
</LinearLayout>

View File

@ -6,8 +6,8 @@
<ImageView
android:id="@+id/imageView1"
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_width="@dimen/image_width"
android:layout_height="@dimen/image_height"
android:src="@drawable/ic_launcher" />
<TextView

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="ROW_COUNT">2</integer>
<integer name="COLUMN_COUNT">2</integer>
<integer name="column_count">2</integer>
<dimen name="image_width">140dp</dimen>
<dimen name="image_height">140dp</dimen>
</resources>

View File

@ -10,6 +10,11 @@
<string name="football_main_image">http://farm9.staticflickr.com/8441/7882624916_5f62cb318f_z.jpg</string>
<string name="title_activity_photo">UNC Charlotte Photos</string>
<string name="title_activity_photo_thread">UNC Charlotte Photos</string>
<string name="Exit">Exit</string>
<string name="exit_button_text">Exit</string>
<string name="download_error">Error Downloading</string>
<string name="uncc">UNC Charlotte</string>
<string name="sports">Sports</string>
<string name="ifest">Ifest</string>
<string name="commencement">Commencement</string>
</resources>

View File

@ -33,9 +33,10 @@ public class PhotoActivity extends Activity {
ProgressDialog progress;
LinearLayout root;
GridView photoGrid;
public int[] imageUrlIds = {R.string.uncc_main_image, R.string.football_main_image,
int[] imageUrlIds = {R.string.uncc_main_image, R.string.football_main_image,
R.string.ifest_main_image, R.string.commencement_main_image
};
int[] imageNames = {R.string.uncc, R.string.sports, R.string.ifest, R.string.commencement};
ArrayList<Bitmap> bitmapList = new ArrayList<Bitmap>();
int downloadProgress;
@ -98,17 +99,14 @@ public class PhotoActivity extends Activity {
@Override
protected void onPostExecute(Bitmap result)
{
if (result == null)//set failed images to a default image
{
//set blank image
}
//already a default picture included in grid_schema.xml, so no need to set a blank pic
bitmapList.add(result);
downloadProgress++;
if(downloadProgress>=imageUrlIds.length)
{
progress.dismiss();
//all images are loaded, so set them in the grid
photoGrid.setAdapter(new ImageAdapter(photoGrid.getContext()));
}
}
@ -130,13 +128,13 @@ public class PhotoActivity extends Activity {
}
@Override
public Object getItem(int position)
public Object getItem(int position)//no purpose. only to fill the requirement of needing the method.
{
return position;
}
@Override
public long getItemId(int position)
public long getItemId(int position)//no purpose. only to fill the requirement of needing the method.
{
return position;
}
@ -149,25 +147,31 @@ public class PhotoActivity extends Activity {
if(vi == null)
{
//create layout of what we want one grid section to look like
vi = getLayoutInflater().inflate(R.layout.grid_schema, null);
holder.textView = (TextView)vi.findViewById(R.id.textView1);
holder.imageView = (ImageView)vi.findViewById(R.id.imageView1);
vi.setTag(holder);
vi.setTag(holder);//associate the views in the holder to the grid
}
else
{
holder = (Holder)(vi.getTag());
}
holder.textView.setText(imageUrlIds[position]);
//set the views in the grid to what was loaded
holder.textView.setText(getString(R.string.download_error));
if(bitmapList.get(position)!=null)
{
holder.imageView.setImageBitmap(bitmapList.get(position));
holder.textView.setText(getString(imageNames[position]));
}
return vi;
}
}
//views included in one grid section
static class Holder
{
TextView textView;