Permalink
Browse files

user volley instead of AQuery.image, it is really nice.

  • Loading branch information...
lytsing committed May 25, 2013
1 parent 953d0c5 commit 7c84aea7ae27e6fa7da7aa4e477e41e07c1d79ac
View
@@ -5,6 +5,7 @@
<classpathentry kind="lib" path="libs/android-query-full.0.24.3.jar"/>
<classpathentry kind="lib" path="libs/CWAC-SackOfViewsAdapter.jar"/>
<classpathentry kind="lib" path="libs/gson-2.2.2.jar"/>
<classpathentry kind="lib" path="libs/volley.jar"/>
<classpathentry kind="lib" path="libs/weibo.sdk.android.sso.jar"/>
<classpathentry kind="lib" path="libs/android-support-v4.jar"/>
<classpathentry kind="src" path="src"/>
View
@@ -55,5 +55,24 @@ <h3>Notices for Project:</h3>
Copyright (c) 2012 Fabian Leon
</pre>
</body></html>
<h3>Notices for files:</h3>
<ul>
<li>volley.jar</li>
</ul>
<pre>
Copyright (C) 2011 The Android Open Source Project
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.
</pre>
</body></html>
View
Binary file not shown.
@@ -27,7 +27,7 @@
android:layout_width="48dip"
android:layout_height="48dip" >
<ImageView
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/ivItemPortrait"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -126,7 +126,7 @@
android:layout_marginTop="5.0dip"
android:layout_marginRight="5.0dip"
android:layout_marginBottom="5.0dip">
<ImageView
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/tweet_upload_pic1"
android:background="@null"
android:visibility="gone"
@@ -16,6 +16,8 @@
package org.lytsing.android.weibo;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.androidquery.AQuery;
import com.weibo.sdk.android.WeiboException;
@@ -47,9 +49,12 @@
private List<Statuses> mStatuses;
public StatusItemAdapter(Context context) {
private final ImageLoader mImageLoader;
public StatusItemAdapter(Context context, ImageLoader imageLoader) {
mContext = context;
mStatuses = new ArrayList<Statuses>();
mImageLoader = imageLoader;
}
@Override
@@ -68,13 +73,13 @@ public long getItemId(int position) {
}
static class ViewHolder {
ImageView userImage;
NetworkImageView userImage;
TextView userName;
ImageView gps;
ImageView pic;
TextView time;
TextView content;
ImageView thumbnailPic;
NetworkImageView thumbnailPic;
TextView tweetForm;
ImageView tweetRedirectPic;
TextView tweetRedirect;
@@ -102,13 +107,13 @@ public View getView(int position, View convertView, ViewGroup parent) {
//if (convertView == null) {
convertView = Util.inflateView(R.layout.list_item_status, mContext);
holder = new ViewHolder();
holder.userImage = (ImageView) convertView.findViewById(R.id.ivItemPortrait);
holder.userImage = (NetworkImageView) convertView.findViewById(R.id.ivItemPortrait);
holder.userName = (TextView) convertView.findViewById(R.id.tvItemName);
holder.gps = (ImageView) convertView.findViewById(R.id.ivItemGps);
holder.pic = (ImageView) convertView.findViewById(R.id.ivItemPic);
holder.time = (TextView) convertView.findViewById(R.id.tvItemDate);
holder.content = (TextView) convertView.findViewById(R.id.tvItemContent);
holder.thumbnailPic = (ImageView) convertView.findViewById(R.id.tweet_upload_pic1);
holder.thumbnailPic = (NetworkImageView) convertView.findViewById(R.id.tweet_upload_pic1);
holder.tweetForm = (TextView) convertView.findViewById(R.id.tweet_form);
holder.tweetRedirectPic = (ImageView) convertView.findViewById(R.id.tweet_redirect_pic);
holder.tweetRedirect = (TextView) convertView.findViewById(R.id.tweet_redirect);
@@ -132,6 +137,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
//Enable hardware acceleration if the device has API 11 or above
aq.hardwareAccelerated11();
// Comment it, now use volley :-)
/*
Bitmap placeholder = aq.getCachedImage(R.drawable.portrait_image_empty);
if (aq.shouldDelay(position, convertView, parent, statuses.user.profile_image_url)) {
@@ -140,6 +147,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
aq.id(holder.userImage).image(statuses.user.profile_image_url, true, true, 0, 0,
placeholder, AQuery.FADE_IN);
}
*/
holder.userImage.setImageUrl(statuses.user.profile_image_url, mImageLoader);
holder.userName.setText(statuses.user.name);
@@ -194,13 +203,19 @@ public View getView(int position, View convertView, ViewGroup parent) {
final String middleImageUrl = statuses.bmiddle_pic;
final String originalPicUrl = statuses.original_pic;
// Comment it, now use volley :-)
/*
Bitmap loadingImg = aq.getCachedImage(R.drawable.chat_pic_loading);
if (aq.shouldDelay(position, convertView, parent, statuses.thumbnail_pic)) {
aq.id(holder.thumbnailPic).image(loadingImg, 1.0f).visible();
} else {
aq.id(holder.thumbnailPic).image(statuses.thumbnail_pic, false, true, 0, 0, loadingImg,
AQuery.FADE_IN).visible();
}
*/
holder.thumbnailPic.setImageUrl(statuses.user.profile_image_url, mImageLoader);
aq.id(holder.thumbnailPic).clicked(new View.OnClickListener() {
@@ -18,7 +18,13 @@
package org.lytsing.android.weibo;
import android.app.Application;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import com.android.volley.toolbox.Volley;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.BitmapAjaxCallback;
import com.weibo.sdk.android.Oauth2AccessToken;
@@ -32,6 +38,10 @@
private static Oauth2AccessToken sOauth2AccessToken;
private final LruCache<String, Bitmap> mImageCache = new LruCache<String, Bitmap>(20);
private ImageLoader mImageLoader;
@Override
public void onCreate() {
super.onCreate();
@@ -40,6 +50,22 @@ public void onCreate() {
sWeibo = Weibo.getInstance(Configuration.CONSUMER_KEY, Configuration.REDIRECT_CALLBACK_URL);
sOauth2AccessToken = AccessTokenKeeper.readAccessToken(this);
RequestQueue queue = Volley.newRequestQueue(this);
ImageCache imageCache = new ImageCache() {
@Override
public void putBitmap(String key, Bitmap value) {
mImageCache.put(key, value);
}
@Override
public Bitmap getBitmap(String key) {
return mImageCache.get(key);
}
};
mImageLoader = new ImageLoader(queue, imageCache);
// set the max number of concurrent network connections, default is 4
@@ -81,6 +107,10 @@ public Weibo getWeibo() {
public Oauth2AccessToken getOauth2AccessToken() {
return sOauth2AccessToken;
}
public ImageLoader getImageLoader() {
return mImageLoader;
}
}
@@ -39,6 +39,7 @@
import org.lytsing.android.weibo.Consts;
import org.lytsing.android.weibo.R;
import org.lytsing.android.weibo.StatusItemAdapter;
import org.lytsing.android.weibo.WeiboApplication;
import org.lytsing.android.weibo.model.Statuses;
import org.lytsing.android.weibo.model.WeiboObject;
import org.lytsing.android.weibo.util.Log;
@@ -135,7 +136,7 @@ public void onLoadMore() {
mListView.setLastUpdated(getLastSyncTime(Preferences.PREF_LAST_SYNC_TIME));
mAdapter = new StatusItemAdapter(this);
mAdapter = new StatusItemAdapter(this, WeiboApplication.getWeiboApplication().getImageLoader());
getFriendsTimeline(0, 0);

0 comments on commit 7c84aea

Please sign in to comment.