diff --git a/OSJ Forum/.settings/org.eclipse.jdt.ui.prefs b/OSJ Forum/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..d16a9ff --- /dev/null +++ b/OSJ Forum/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,54 @@ +cleanup.add_default_serial_version_id=false +cleanup.add_generated_serial_version_id=true +cleanup.add_missing_annotations=true +cleanup.add_missing_deprecated_annotations=true +cleanup.add_missing_methods=true +cleanup.add_missing_nls_tags=false +cleanup.add_missing_override_annotations=true +cleanup.add_missing_override_annotations_interface_methods=true +cleanup.add_serial_version_id=true +cleanup.always_use_blocks=false +cleanup.always_use_parentheses_in_expressions=false +cleanup.always_use_this_for_non_static_field_access=false +cleanup.always_use_this_for_non_static_method_access=false +cleanup.convert_to_enhanced_for_loop=true +cleanup.correct_indentation=true +cleanup.format_source_code=true +cleanup.format_source_code_changes_only=false +cleanup.make_local_variable_final=true +cleanup.make_parameters_final=true +cleanup.make_private_fields_final=true +cleanup.make_type_abstract_if_missing_method=false +cleanup.make_variable_declarations_final=true +cleanup.never_use_blocks=true +cleanup.never_use_parentheses_in_expressions=true +cleanup.organize_imports=true +cleanup.qualify_static_field_accesses_with_declaring_class=false +cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +cleanup.qualify_static_member_accesses_with_declaring_class=true +cleanup.qualify_static_method_accesses_with_declaring_class=false +cleanup.remove_private_constructors=true +cleanup.remove_trailing_whitespaces=true +cleanup.remove_trailing_whitespaces_all=true +cleanup.remove_trailing_whitespaces_ignore_empty=false +cleanup.remove_unnecessary_casts=true +cleanup.remove_unnecessary_nls_tags=true +cleanup.remove_unused_imports=true +cleanup.remove_unused_local_variables=true +cleanup.remove_unused_private_fields=true +cleanup.remove_unused_private_members=true +cleanup.remove_unused_private_methods=true +cleanup.remove_unused_private_types=true +cleanup.sort_members=true +cleanup.sort_members_all=false +cleanup.use_blocks=true +cleanup.use_blocks_only_for_return_and_throw=false +cleanup.use_parentheses_in_expressions=true +cleanup.use_this_for_non_static_field_access=true +cleanup.use_this_for_non_static_field_access_only_if_necessary=true +cleanup.use_this_for_non_static_method_access=true +cleanup.use_this_for_non_static_method_access_only_if_necessary=true +cleanup_profile=_Ricky +cleanup_settings_version=2 +eclipse.preferences.version=1 diff --git a/OSJ Forum/AndroidManifest.xml b/OSJ Forum/AndroidManifest.xml index ede2864..5f74c6c 100644 --- a/OSJ Forum/AndroidManifest.xml +++ b/OSJ Forum/AndroidManifest.xml @@ -1,5 +1,5 @@
  • android-xmlrpc - Very thin xmlrpc client library for Android platform
  • -
  • Android-PullToRefresh - A project to provide a reusable Pull to Refresh widget for Android.
  • +
  • Android-PullToRefresh - A project to provide a reusable Pull to Refresh widget for Android
  • +
  • CWAC Thumbnail - Images in Lists, Without the Wait
  • +
  • CWAC AdapterWrapper - Adding Bits o' Functionality
  • +
  • CWAC Bus - Services And Activities, Communicating
  • +
  • CWAC Cache - Dealing With Pesky Download Times
  • +
  • CWAC Task - A Bit More Background Task Goodness

  • diff --git a/OSJ Forum/libs/CWAC-AdapterWrapper.jar b/OSJ Forum/libs/CWAC-AdapterWrapper.jar new file mode 100644 index 0000000..ebbe0d9 Binary files /dev/null and b/OSJ Forum/libs/CWAC-AdapterWrapper.jar differ diff --git a/OSJ Forum/libs/CWAC-Bus.jar b/OSJ Forum/libs/CWAC-Bus.jar new file mode 100644 index 0000000..c44b1f2 Binary files /dev/null and b/OSJ Forum/libs/CWAC-Bus.jar differ diff --git a/OSJ Forum/libs/CWAC-Cache.jar b/OSJ Forum/libs/CWAC-Cache.jar new file mode 100644 index 0000000..93c5267 Binary files /dev/null and b/OSJ Forum/libs/CWAC-Cache.jar differ diff --git a/OSJ Forum/libs/CWAC-Task.jar b/OSJ Forum/libs/CWAC-Task.jar new file mode 100644 index 0000000..64479c9 Binary files /dev/null and b/OSJ Forum/libs/CWAC-Task.jar differ diff --git a/OSJ Forum/res/layout/item_post.xml b/OSJ Forum/res/layout/item_post.xml index 39ef8d6..e3d3e7e 100644 --- a/OSJ Forum/res/layout/item_post.xml +++ b/OSJ Forum/res/layout/item_post.xml @@ -1,7 +1,9 @@ + android:layout_height="match_parent" + android:padding="5dip" + > + android:layout_height="wrap_content" + android:padding="5dip" > + /> cache = null; + private Activity host = null; + + private final ThumbnailBus.Receiver onCache = new ThumbnailBus.Receiver() { + @Override + public void onReceive(final ThumbnailMessage message) { + final ImageView image = message.getImageView(); + + host.runOnUiThread(new Runnable() { + @Override + public void run() { + if (image.getTag() != null && image.getTag().toString().equals(message.getUrl())) + image.setImageDrawable(cache.get(message.getUrl())); + } + }); + } + }; + + /** + * Constructor wrapping a supplied ListAdapter + */ + public ThumbnailAdapter(final Activity host, final ListAdapter wrapped, final SimpleWebImageCache cache, final int[] imageIds) { + super(wrapped); + + this.host = host; + this.imageIds = imageIds; + this.cache = cache; + + cache.getBus().register(getBusKey(), onCache); + } + + public void close() { + cache.getBus().unregister(onCache); + } + + private String getBusKey() { + return toString(); + } + + /** + * Get a View that displays the data at the specified position in the data + * set. In this case, if we are at the end of the list and we are still in + * append mode, we ask for a pending view and return it, plus kick off the + * background task to append more data to the wrapped adapter. + * + * @param position + * Position of the item whose data we want + * @param convertView + * View to recycle, if not null + * @param parent + * ViewGroup containing the returned View + */ + @Override + public View getView(final int position, final View convertView, final ViewGroup parent) { + final View result = super.getView(position, convertView, parent); + + processView(result); + + return result; + } + + public void processView(final View row) { + Log.v(TAG, "Processing View"); + for (final int imageId : imageIds) { + final ImageView image = (ImageView) row.findViewById(imageId); + + if (image != null && image.getTag() != null) { + final ThumbnailMessage msg = cache.getBus().createMessage(getBusKey()); + + msg.setImageView(image); + msg.setUrl(image.getTag().toString()); + + try { + cache.notify(msg.getUrl(), msg); + } catch (final Throwable t) { + Log.e(TAG, "Exception trying to fetch image", t); + } + } + } + } +} \ No newline at end of file diff --git a/OSJ Forum/src/com/commonsware/cwac/thumbnail/ThumbnailBus.java b/OSJ Forum/src/com/commonsware/cwac/thumbnail/ThumbnailBus.java new file mode 100644 index 0000000..6c1edbe --- /dev/null +++ b/OSJ Forum/src/com/commonsware/cwac/thumbnail/ThumbnailBus.java @@ -0,0 +1,36 @@ +/*** + Copyright (c) 2008-2009 CommonsWare, LLC + + Licensed under the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. You may obtain + a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +package com.commonsware.cwac.thumbnail; + +import com.commonsware.cwac.bus.AbstractBus; + +public class ThumbnailBus extends AbstractBus { + class MatchStrategy implements AbstractBus.Strategy { + @Override + public boolean isMatch(final ThumbnailMessage message, final String filter) { + return filter != null && message != null && filter.equals(message.getKey()); + } + } + + public ThumbnailBus() { + super(); + + setStrategy(new MatchStrategy()); + } + + public ThumbnailMessage createMessage(final String key) { + return new ThumbnailMessage(key); + } +} \ No newline at end of file diff --git a/OSJ Forum/src/com/commonsware/cwac/thumbnail/ThumbnailMessage.java b/OSJ Forum/src/com/commonsware/cwac/thumbnail/ThumbnailMessage.java new file mode 100644 index 0000000..78ee5ad --- /dev/null +++ b/OSJ Forum/src/com/commonsware/cwac/thumbnail/ThumbnailMessage.java @@ -0,0 +1,47 @@ +/*** +Copyright (c) 2008-2009 CommonsWare, LLC + +Licensed under the Apache License, Version 2.0 (the "License"); you may +not use this file except in compliance with the License. You may obtain +a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ + +package com.commonsware.cwac.thumbnail; + +import android.widget.ImageView; + +public class ThumbnailMessage { + private final String key; + private ImageView image; + private String url; + + public ThumbnailMessage(final String key) { + this.key = key; + } + + public ImageView getImageView() { + return image; + } + + public String getKey() { + return key; + } + + public String getUrl() { + return url; + } + + public void setImageView(final ImageView image) { + this.image = image; + } + + public void setUrl(final String url) { + this.url = url; + } +} \ No newline at end of file diff --git a/OSJ Forum/src/org/RickBarrette/osj/forum/ForumDetailFragment.java b/OSJ Forum/src/org/RickBarrette/osj/forum/ForumDetailFragment.java index 8a39554..5809469 100644 --- a/OSJ Forum/src/org/RickBarrette/osj/forum/ForumDetailFragment.java +++ b/OSJ Forum/src/org/RickBarrette/osj/forum/ForumDetailFragment.java @@ -35,6 +35,10 @@ import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ListView; +import com.commonsware.cwac.cache.SimpleWebImageCache; +import com.commonsware.cwac.thumbnail.ThumbnailAdapter; +import com.commonsware.cwac.thumbnail.ThumbnailBus; +import com.commonsware.cwac.thumbnail.ThumbnailMessage; import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment; import com.handmark.pulltorefresh.library.PullToRefreshBase; @@ -173,7 +177,8 @@ public class ForumDetailFragment extends PullToRefreshListFragment implements Da @Override public void run() { TopicContent.getTopics((String) mItem.content.get("forum_id"), mDb); - setListAdapter(new TopicAdapter(getActivity())); + setListAdapter(new ThumbnailAdapter(getActivity(), new TopicAdapter(getActivity()), new SimpleWebImageCache(null, null, + 101, new ThumbnailBus()), new int[] { R.id.quickContactBadge1 })); getPullToRefreshListView().onRefreshComplete(); } }); diff --git a/OSJ Forum/src/org/RickBarrette/osj/forum/TopicDetailFragment.java b/OSJ Forum/src/org/RickBarrette/osj/forum/TopicDetailFragment.java index 7c44fd1..ca4b128 100644 --- a/OSJ Forum/src/org/RickBarrette/osj/forum/TopicDetailFragment.java +++ b/OSJ Forum/src/org/RickBarrette/osj/forum/TopicDetailFragment.java @@ -35,6 +35,10 @@ import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ListView; +import com.commonsware.cwac.cache.SimpleWebImageCache; +import com.commonsware.cwac.thumbnail.ThumbnailAdapter; +import com.commonsware.cwac.thumbnail.ThumbnailBus; +import com.commonsware.cwac.thumbnail.ThumbnailMessage; import com.handmark.pulltorefresh.extras.listfragment.PullToRefreshListFragment; import com.handmark.pulltorefresh.library.PullToRefreshBase; @@ -171,7 +175,8 @@ public class TopicDetailFragment extends PullToRefreshListFragment implements Da @Override public void run() { ThreadContent.getThread((String) mItem.content.get("topic_id"), mDb); - setListAdapter(new ThreadAdapter(getActivity())); + setListAdapter(new ThumbnailAdapter(getActivity(), new ThreadAdapter(getActivity()), new SimpleWebImageCache(null, null, + 101, new ThumbnailBus()), new int[] { R.id.quickContactBadge1 })); getPullToRefreshListView().onRefreshComplete(); } }); diff --git a/OSJ Forum/src/org/RickBarrette/osj/forum/TopicListFragment.java b/OSJ Forum/src/org/RickBarrette/osj/forum/TopicListFragment.java index abf20f7..f2872fa 100644 --- a/OSJ Forum/src/org/RickBarrette/osj/forum/TopicListFragment.java +++ b/OSJ Forum/src/org/RickBarrette/osj/forum/TopicListFragment.java @@ -32,6 +32,11 @@ import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ListView; +import com.commonsware.cwac.cache.SimpleWebImageCache; +import com.commonsware.cwac.thumbnail.ThumbnailAdapter; +import com.commonsware.cwac.thumbnail.ThumbnailBus; +import com.commonsware.cwac.thumbnail.ThumbnailMessage; + public class TopicListFragment extends ListFragment { private static final String STATE_ACTIVATED_POSITION = "activated_position"; @@ -61,7 +66,8 @@ public class TopicListFragment extends ListFragment { @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setListAdapter(new TopicAdapter(getActivity())); + setListAdapter(new ThumbnailAdapter(getActivity(), new TopicAdapter(getActivity()), new SimpleWebImageCache(null, null, 101, + new ThumbnailBus()), new int[] { R.id.quickContactBadge1 })); } @Override diff --git a/OSJ Forum/src/org/RickBarrette/osj/forum/content/ThreadAdapter.java b/OSJ Forum/src/org/RickBarrette/osj/forum/content/ThreadAdapter.java index 2943bc2..96bf80d 100644 --- a/OSJ Forum/src/org/RickBarrette/osj/forum/content/ThreadAdapter.java +++ b/OSJ Forum/src/org/RickBarrette/osj/forum/content/ThreadAdapter.java @@ -129,6 +129,8 @@ public class ThreadAdapter extends BaseAdapter { holder.title.setText((String) getItem(position).get("post_title")); holder.user.setText((String) getItem(position).get("post_author_name")); holder.post.setText((String) getItem(position).get("post_content")); + holder.badage.setImageResource(R.drawable.ic_launcher); + holder.badage.setTag("http://www.gravatar.com/avatar/9b4f3d34ca3ce31198efac149c3a1ca2?s=300&d=identicon&r=PG"); return convertView; } diff --git a/OSJ Forum/src/org/RickBarrette/osj/forum/content/TopicAdapter.java b/OSJ Forum/src/org/RickBarrette/osj/forum/content/TopicAdapter.java index f2e23a2..40b99a2 100644 --- a/OSJ Forum/src/org/RickBarrette/osj/forum/content/TopicAdapter.java +++ b/OSJ Forum/src/org/RickBarrette/osj/forum/content/TopicAdapter.java @@ -131,6 +131,8 @@ public class TopicAdapter extends BaseAdapter { holder.user.setText((String) getItem(position).get("topic_author_name")); holder.lastestPost.setText((String) getItem(position).get("short_content")); holder.newPosts.setVisibility(Boolean.parseBoolean((String) getItem(position).get("new_post")) ? View.VISIBLE : View.GONE); + holder.badage.setImageResource(R.drawable.ic_launcher); + holder.badage.setTag("http://www.gravatar.com/avatar/9b4f3d34ca3ce31198efac149c3a1ca2?s=300&d=identicon&r=PG"); return convertView; }