diff --git a/.classpath b/.classpath
index 5176974..d57ec02 100644
--- a/.classpath
+++ b/.classpath
@@ -2,8 +2,8 @@
-
+
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c5a8e6c..6100348 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2,12 +2,13 @@
+ android:versionCode="32"
+ android:versionName="2.9.8" >
+
@@ -28,7 +29,7 @@
android:name=".DemoList"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
- android:theme="@android:style/Theme.Holo.Light.DialogWhenLarge" >
+ android:theme="@android:style/Theme.Holo.Light" >
@@ -39,7 +40,7 @@
android:name=".DownloadManagerDemo"
android:configChanges="orientation|keyboardHidden"
android:label="@string/download_manager_demo_activity_title"
- android:theme="@android:style/Theme.Holo.Light.DialogWhenLarge" >
+ android:theme="@android:style/Theme.Holo.Light" >
@@ -48,53 +49,65 @@
+
+
+
+
+ android:theme="@android:style/Theme.Holo.Light" >
+ android:theme="@android:style/Theme.Holo.Light" >
+ android:theme="@android:style/Theme.Holo.Light" >
+ android:theme="@android:style/Theme.Holo.Light" >
+ android:theme="@android:style/Theme.Holo.Light" >
+ android:theme="@android:style/Theme.Holo.Light" >
+ android:theme="@android:style/Theme.Holo.Light" >
+ android:theme="@android:style/Theme.Holo.Light" >
diff --git a/ReadMe.txt b/ReadMe.txt
new file mode 100644
index 0000000..25c464f
--- /dev/null
+++ b/ReadMe.txt
@@ -0,0 +1,5 @@
+中文:
+需要从https://github.com/Trinea/AndroidCommon或https://code.google.com/p/trinea-android-common/source/checkout拉下TrineaAndroidCommon工程做为android lib引入,不会的可以参考http://www.trinea.cn/?p=637
+
+English Version:
+get source code of TrineaAndroidCommon from https://github.com/Trinea/AndroidCommon or https://code.google.com/p/trinea-android-common/source/checkout, and import it as a android common lib to TrineaAndroidDemo, you can reference from http://www.trinea.cn/?p=637
diff --git a/libs/android-support-v4.jar b/libs/android-support-v4.jar
new file mode 100644
index 0000000..feaf44f
Binary files /dev/null and b/libs/android-support-v4.jar differ
diff --git a/lint.xml b/lint.xml
new file mode 100644
index 0000000..7edd00c
--- /dev/null
+++ b/lint.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/proguard.cfg b/proguard.cfg
index 12dd039..63395d0 100644
--- a/proguard.cfg
+++ b/proguard.cfg
@@ -34,3 +34,11 @@
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
+-libraryjars libs/android-support-v4.jar
+-dontwarn android.support.v4.**
+-keep class android.support.v4.** { *; }
+-keep interface android.support.v4.app.** { *; }
+-keep class cn.trinea.android.common.** { *; }
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
\ No newline at end of file
diff --git a/project.properties b/project.properties
index ec74fa2..45331c5 100644
--- a/project.properties
+++ b/project.properties
@@ -12,4 +12,6 @@
# Project target.
target=android-14
-android.library.reference.1=../trinea-android-common
+android.library.reference.1=..\\trinea-android-common
+proguard.config=proguard.cfg
+android.library.reference.2=../../TrineaOnline/trinea-android-common
diff --git a/res/drawable-hdpi/trinea.png b/res/drawable-hdpi/trinea.png
new file mode 100644
index 0000000..a488c6a
Binary files /dev/null and b/res/drawable-hdpi/trinea.png differ
diff --git a/res/drawable-ldpi/trinea.png b/res/drawable-ldpi/trinea.png
new file mode 100644
index 0000000..a488c6a
Binary files /dev/null and b/res/drawable-ldpi/trinea.png differ
diff --git a/res/drawable-mdpi/trinea.png b/res/drawable-mdpi/trinea.png
new file mode 100644
index 0000000..a488c6a
Binary files /dev/null and b/res/drawable-mdpi/trinea.png differ
diff --git a/res/drawable/image_border.xml b/res/drawable/image_border.xml
new file mode 100644
index 0000000..4b0a6f1
--- /dev/null
+++ b/res/drawable/image_border.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/image_cache_demo.xml b/res/layout/image_cache_demo.xml
new file mode 100644
index 0000000..5eb22a0
--- /dev/null
+++ b/res/layout/image_cache_demo.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/image_sdcard_cache_demo.xml b/res/layout/image_sdcard_cache_demo.xml
new file mode 100644
index 0000000..dd84c20
--- /dev/null
+++ b/res/layout/image_sdcard_cache_demo.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index 3c275c2..91a55ab 100644
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -29,5 +29,20 @@
文件将下载到:
更新于:
-
+
+ 个人主页:
+ 更多介绍:
+
+ SearchView介绍及搜索提示实现
+ viewpager实现画廊效果
+ 系统下载管理使用
+ Gallery滑动一页(一个Item)效果
+ ViewPager、Fragment使用
+ Service介绍
+ BroadcastReceiver介绍
+ BorderScrollViewDemo介绍
+ 下拉刷新及底部加载更多Listview
+ ImageCache使用
+ ImageSDCardCache使用
+ Trinea
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
deleted file mode 100644
index 0d2c4cc..0000000
--- a/res/values/attrs.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index b4e5a4f..0a58c18 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -3,6 +3,7 @@
45dp
15dp
+ 4dp
8dp
60dp
40dp
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9dc0fdd..9d6fdd1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3,6 +3,8 @@
Trinea Android Demo
+ ImageSDCardCache Demo
+ ImageCache Demo
Drop Down And Load More ListView Demo
onBottom onTop ScrollView Demo
SearchView Demo
@@ -42,4 +44,20 @@
file will be saved to sdcard, the path is:
updated at:
+
+ Profile:
+ Description:
+
+ SearchView Desc And Implement Search Tip
+ Viewpager With Multi Page
+ Download Manager Usage
+ Slide One Page Gallery Usage
+ ViewPager And Fragment Usage
+ Android Service Usage
+ Android BroadcastReceiver Usage
+ BorderScrollView Usage
+ Drop Down And On Bottom Listview
+ ImageCache Usage
+ ImageSDCardCache Usage
+ Trinea
diff --git a/src/cn/trinea/android/demo/DemoList.java b/src/cn/trinea/android/demo/DemoList.java
index 2398b17..748100f 100644
--- a/src/cn/trinea/android/demo/DemoList.java
+++ b/src/cn/trinea/android/demo/DemoList.java
@@ -3,12 +3,9 @@
import java.util.Arrays;
import java.util.LinkedList;
-import cn.trinea.android.common.service.impl.ImageCache;
-
import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
-import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
@@ -24,9 +21,10 @@ public class DemoList extends BaseActivity {
public static final String TAG = "DemoList";
- private static final String[] mStrings = { "DropDownListViewDemo", "onBottom onTop ScrollView Demo",
- "DownloadManager Demo", "SearchView Demo", "ViewPager Multi Fragment Demo\r\n(ViewPager一屏多Fragment)",
- "Slide One Page Gallery Demo", "ViewPager Demo", "Service Demo", "BroadcastReceiver Demo" };
+ private static final String[] mStrings = { "ImageSDCardCache Demo", "ImageCache Demo", "DropDownListView Demo",
+ "onBottom onTop ScrollView Demo", "DownloadManager Demo", "SearchView Demo",
+ "ViewPager Multi Fragment Demo", "Slide One Page Gallery Demo", "ViewPager Demo", "Service Demo",
+ "BroadcastReceiver Demo" };
private static final int total = mStrings.length - 1;
@@ -47,7 +45,13 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
- if (position == total - 8) {
+ if (position == total - 10) {
+ Intent intent = new Intent(DemoList.this, ImageSDCardCacheDemo.class);
+ startActivity(intent);
+ } else if (position == total - 9) {
+ Intent intent = new Intent(DemoList.this, ImageCacheDemo.class);
+ startActivity(intent);
+ } else if (position == total - 8) {
Intent intent = new Intent(DemoList.this, DropDownListViewDemo.class);
startActivity(intent);
} else if (position == total - 7) {
@@ -77,5 +81,24 @@ public void onItemClick(AdapterView> parent, View view, int position, long id)
}
}
});
+ // startActivity(new Intent(getApplicationContext(), ImageCacheDemo.class));
+ // startActivity(new Intent("android.intent.action.VIEW_DOWNLOADS"));
+ // Intent i = new Intent(Intent.ACTION_VIEW);
+ // i.setData(Uri.parse("http://122.193.23.191/down.myapp.com/android/48157/1176342/com.tencent.mm_261.apk?mkey=51cc3a56ba89d0cf&f=a821&p=.apk"));
+ // startActivity(i);
+ // final Context context = getApplicationContext();
+ // new Thread() {
+ //
+ // public void run() {
+ // DownloadManager.Request request = new Request(
+ // Uri.parse("http://122.193.23.191/down.myapp.com/android/48157/1176342/com.tencent.mm_261.apk?mkey=51cc3a56ba89d0cf&f=a821&p=.apk"));
+ // DownloadManager manager = (DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);
+ // manager.enqueue(request);
+ //
+ // Intent i = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
+ // i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ // startActivity(i);
+ // }
+ // }.start();
}
}
diff --git a/src/cn/trinea/android/demo/ImageCacheDemo.java b/src/cn/trinea/android/demo/ImageCacheDemo.java
new file mode 100644
index 0000000..65daf42
--- /dev/null
+++ b/src/cn/trinea/android/demo/ImageCacheDemo.java
@@ -0,0 +1,140 @@
+package cn.trinea.android.demo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.view.Display;
+import android.view.View;
+import android.view.animation.AlphaAnimation;
+import android.widget.ImageView;
+import android.widget.ImageView.ScaleType;
+import android.widget.RelativeLayout;
+import android.widget.RelativeLayout.LayoutParams;
+import cn.trinea.android.common.service.impl.ImageCache;
+import cn.trinea.android.common.service.impl.ImageCache.OnImageCallbackListener;
+import cn.trinea.android.common.service.impl.RemoveTypeLastUsedTimeFirst;
+
+/**
+ * ImageCacheDemo
+ *
+ * @author gxwu@lewatek.com 2013-6-25
+ */
+public class ImageCacheDemo extends BaseActivity {
+
+ /** column number **/
+ public static final int COLUMNS = 2;
+ /** imageView default height **/
+ public static final int IMAGEVIEW_DEFAULT_HEIGHT = 400;
+
+ private RelativeLayout parentLayout;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState, R.layout.image_cache_demo);
+
+ Context context = getApplicationContext();
+ parentLayout = (RelativeLayout)findViewById(R.id.image_cache_parent_layout);
+ initImageUrlList();
+ IMAGE_CACHE.setContext(context);
+
+ int count = 0, viewId = 0x7F24FFF0;
+ int verticalSpacing, horizontalSpacing;
+ verticalSpacing = horizontalSpacing = getResources().getDimensionPixelSize(R.dimen.dp_4);
+ Display display = getWindowManager().getDefaultDisplay();
+ int imageWidth = (display.getWidth() - (COLUMNS + 1) * horizontalSpacing) / COLUMNS;
+ for (String imageUrl : imageUrlList) {
+ ImageView imageView = new ImageView(context);
+ imageView.setId(++viewId);
+ imageView.setScaleType(ScaleType.CENTER);
+ imageView.setBackgroundResource(R.drawable.image_border);
+ parentLayout.addView(imageView);
+
+ // set imageView layout params
+ LayoutParams layoutParams = (RelativeLayout.LayoutParams)imageView.getLayoutParams();
+ layoutParams.width = imageWidth;
+ layoutParams.topMargin = verticalSpacing;
+ layoutParams.rightMargin = horizontalSpacing;
+ int column = count % COLUMNS;
+ int row = count / COLUMNS;
+ if (row > 0) {
+ layoutParams.addRule(RelativeLayout.BELOW, viewId - COLUMNS);
+ }
+ if (column > 0) {
+ layoutParams.addRule(RelativeLayout.RIGHT_OF, viewId - 1);
+ }
+
+ // get image
+ if (!IMAGE_CACHE.get(imageUrl, imageView)) {
+ imageView.setImageResource(R.drawable.trinea);
+ layoutParams.height = IMAGEVIEW_DEFAULT_HEIGHT;
+ }
+ count++;
+ }
+ }
+
+ /** icon cache **/
+ public static final ImageCache IMAGE_CACHE = new ImageCache(128);
+
+ static {
+ /** init icon cache **/
+ OnImageCallbackListener imageCallBack = new OnImageCallbackListener() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onImageLoaded(String imageUrl, Drawable imageDrawable, View view, boolean isInCache) {
+ if (view != null && imageDrawable != null) {
+ ImageView imageView = (ImageView)view;
+ imageView.setImageDrawable(imageDrawable);
+ // first time show with animation
+ if (!isInCache) {
+ imageView.startAnimation(getInAlphaAnimation(2000));
+ }
+
+ // auto set height accroding to rate between height and widght
+ LayoutParams imageParams = (LayoutParams)imageView.getLayoutParams();
+ imageParams.height = imageParams.width * imageDrawable.getIntrinsicHeight()
+ / imageDrawable.getIntrinsicWidth();
+ imageView.setScaleType(ScaleType.FIT_XY);
+ }
+ }
+ };
+ IMAGE_CACHE.setOnImageCallbackListener(imageCallBack);
+ IMAGE_CACHE.setCacheFullRemoveType(new RemoveTypeLastUsedTimeFirst());
+
+ IMAGE_CACHE.setHttpReadTimeOut(10000);
+ IMAGE_CACHE.setOpenWaitingQueue(true);
+ IMAGE_CACHE.setValidTime(-1);
+ }
+
+ public static AlphaAnimation getInAlphaAnimation(long durationMillis) {
+ AlphaAnimation inAlphaAnimation = new AlphaAnimation(0, 1);
+ inAlphaAnimation.setDuration(durationMillis);
+ return inAlphaAnimation;
+ }
+
+ private List imageUrlList;
+
+ private void initImageUrlList() {
+ imageUrlList = new ArrayList();
+ imageUrlList.add("http://farm8.staticflickr.com/7403/9146300103_03423db0cc.jpg");
+ imageUrlList.add("http://farm4.staticflickr.com/3755/9148527824_6c156185ea.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7409/9148527822_36fa37d7ca_z.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7403/9146300103_03423db0cc.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7318/9148527808_e804baef0b.jpg");
+ imageUrlList.add("http://farm3.staticflickr.com/2857/9148527928_3063544889.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7318/9146300275_5fe995d123.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7351/9148527976_8a4e75ae87.jpg");
+ imageUrlList.add("http://farm4.staticflickr.com/3679/9146300263_5c2191232a_o.jpg");
+ imageUrlList.add("http://farm3.staticflickr.com/2863/9148527892_31f9377351_o.jpg");
+ imageUrlList.add("http://farm3.staticflickr.com/2888/9148527996_f05118d7de_o.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7310/9148528008_8e8f51997a.jpg");
+ imageUrlList.add("http://farm3.staticflickr.com/2849/9148528108_dfcda19507.jpg");
+ imageUrlList.add("http://farm4.staticflickr.com/3739/9148528022_e9bf03058f.jpg");
+ imageUrlList.add("http://farm4.staticflickr.com/3696/9146300409_dfa9d7c603.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7288/9146300469_bd3420c75b_z.jpg");
+ }
+}
diff --git a/src/cn/trinea/android/demo/ImageSDCardCacheDemo.java b/src/cn/trinea/android/demo/ImageSDCardCacheDemo.java
new file mode 100644
index 0000000..04fb9c3
--- /dev/null
+++ b/src/cn/trinea/android/demo/ImageSDCardCacheDemo.java
@@ -0,0 +1,201 @@
+package cn.trinea.android.demo;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.Bundle;
+import android.os.Environment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.animation.AlphaAnimation;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.ImageView.ScaleType;
+import android.widget.RelativeLayout.LayoutParams;
+import cn.trinea.android.common.service.impl.FileNameRuleImageUrl;
+import cn.trinea.android.common.service.impl.ImageSDCardCache;
+import cn.trinea.android.common.service.impl.ImageSDCardCache.OnImageSDCallbackListener;
+import cn.trinea.android.common.service.impl.RemoveTypeLastUsedTimeFirst;
+import cn.trinea.android.common.util.ListUtils;
+import cn.trinea.android.common.view.SlideOnePageGallery;
+
+/**
+ * ImageSDCardCacheDemo
+ *
+ * @author gxwu@lewatek.com 2013-6-25
+ */
+public class ImageSDCardCacheDemo extends BaseActivity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState, R.layout.slide_one_page_gallery_demo);
+
+ Context context = getApplicationContext();
+ initImageUrlList();
+ IMAGE_SD_CACHE.setContext(context);
+
+ SlideOnePageGallery imageGallery = (SlideOnePageGallery)findViewById(R.id.app_app_image_gallery);
+ ImageAdapter adapter = new ImageAdapter(context);
+ adapter.setImageUrlList(imageUrlList);
+ imageGallery.setAdapter(adapter);
+
+ }
+
+ /** icon cache **/
+ public static final ImageSDCardCache IMAGE_SD_CACHE = new ImageSDCardCache();
+
+ static {
+ /** init icon cache **/
+ OnImageSDCallbackListener imageCallBack = new OnImageSDCallbackListener() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onImageLoaded(String imageUrl, String imagePath, View view, boolean isInCache) {
+ ImageView imageView = (ImageView)view;
+
+ // avoid oom caused by bitmap size exceeds VM budget
+ BitmapFactory.Options option = new BitmapFactory.Options();
+ option.inSampleSize = getImageScale(imagePath);
+ Bitmap bm = BitmapFactory.decodeFile(imagePath, option);
+ if (bm != null) {
+ // auto set height
+ LayoutParams imageParams = (LayoutParams)imageView.getLayoutParams();
+ imageParams.height = imageParams.width * bm.getHeight() / bm.getWidth();
+ imageView.setScaleType(ScaleType.FIT_XY);
+ imageView.setImageBitmap(bm);
+
+ // first time show with animation
+ if (!isInCache) {
+ imageView.startAnimation(getInAlphaAnimation(2000));
+ }
+ }
+ }
+ };
+ IMAGE_SD_CACHE.setOnImageSDCallbackListener(imageCallBack);
+ IMAGE_SD_CACHE.setCacheFullRemoveType(new RemoveTypeLastUsedTimeFirst());
+ IMAGE_SD_CACHE.setCacheFolder(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
+ + "TrineaAndroidCommon");
+ IMAGE_SD_CACHE.setFileNameRule(new FileNameRuleImageUrl());
+
+ IMAGE_SD_CACHE.setHttpReadTimeOut(10000);
+ IMAGE_SD_CACHE.setOpenWaitingQueue(true);
+ IMAGE_SD_CACHE.setValidTime(-1);
+ }
+
+ public static AlphaAnimation getInAlphaAnimation(long durationMillis) {
+ AlphaAnimation inAlphaAnimation = new AlphaAnimation(0, 1);
+ inAlphaAnimation.setDuration(durationMillis);
+ return inAlphaAnimation;
+ }
+
+ /**
+ * scale image to fixed height and weight
+ *
+ * @param imagePath
+ * @return
+ */
+ private static int getImageScale(String imagePath) {
+ BitmapFactory.Options option = new BitmapFactory.Options();
+ // set inJustDecodeBounds to true, allowing the caller to query the bitmap info without having to allocate the
+ // memory for its pixels.
+ option.inJustDecodeBounds = true;
+ BitmapFactory.decodeFile(imagePath, option);
+
+ int scale = 1;
+ while (option.outWidth / scale >= IMAGE_MAX_WIDTH || option.outHeight / scale >= IMAGE_MAX_HEIGHT) {
+ scale *= 2;
+ }
+ return scale;
+ }
+
+ private static int IMAGE_MAX_WIDTH = 480;
+ private static int IMAGE_MAX_HEIGHT = 960;
+
+ private List imageUrlList;
+
+ private void initImageUrlList() {
+ imageUrlList = new ArrayList();
+ imageUrlList.add("http://farm8.staticflickr.com/7403/9146300103_03423db0cc.jpg");
+ imageUrlList.add("http://farm4.staticflickr.com/3755/9148527824_6c156185ea.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7409/9148527822_36fa37d7ca_z.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7403/9146300103_03423db0cc.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7318/9148527808_e804baef0b.jpg");
+ imageUrlList.add("http://farm3.staticflickr.com/2857/9148527928_3063544889.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7318/9146300275_5fe995d123.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7351/9148527976_8a4e75ae87.jpg");
+ imageUrlList.add("http://farm4.staticflickr.com/3679/9146300263_5c2191232a_o.jpg");
+ imageUrlList.add("http://farm3.staticflickr.com/2863/9148527892_31f9377351_o.jpg");
+ imageUrlList.add("http://farm3.staticflickr.com/2888/9148527996_f05118d7de_o.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7310/9148528008_8e8f51997a.jpg");
+ imageUrlList.add("http://farm3.staticflickr.com/2849/9148528108_dfcda19507.jpg");
+ imageUrlList.add("http://farm4.staticflickr.com/3739/9148528022_e9bf03058f.jpg");
+ imageUrlList.add("http://farm4.staticflickr.com/3696/9146300409_dfa9d7c603.jpg");
+ imageUrlList.add("http://farm8.staticflickr.com/7288/9146300469_bd3420c75b_z.jpg");
+ }
+
+ private static class ImageAdapter extends BaseAdapter {
+
+ private LayoutInflater inflater;
+ public List imageUrlList;
+
+ public ImageAdapter(Context context){
+ super();
+ inflater = LayoutInflater.from(context);
+ }
+
+ @Override
+ public int getCount() {
+ return ListUtils.isEmpty(imageUrlList) ? 0 : imageUrlList.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return ListUtils.isEmpty(imageUrlList) ? null : imageUrlList.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder holder;
+ if (convertView == null) {
+ convertView = inflater.inflate(R.layout.image_list_item, null);
+ holder = new ViewHolder();
+ holder.imageView = (ImageView)convertView.findViewById(R.id.image_list_image);
+ convertView.setTag(holder);
+ } else {
+ holder = (ViewHolder)convertView.getTag();
+ }
+
+ // if not in cache, set default icon
+ if (!IMAGE_SD_CACHE.get(imageUrlList.get(position), holder.imageView)) {
+ holder.imageView.setImageResource(R.drawable.trinea);
+ holder.imageView.setScaleType(ScaleType.CENTER);
+ }
+ return convertView;
+ }
+
+ public void setImageUrlList(List imageUrlList) {
+ this.imageUrlList = imageUrlList;
+ }
+
+ /**
+ * ViewHolder
+ *
+ * @author Trinea 2012-11-22
+ */
+ static class ViewHolder {
+
+ ImageView imageView;
+ }
+ }
+}
diff --git a/src/cn/trinea/android/demo/ViewPagerDemo.java b/src/cn/trinea/android/demo/ViewPagerDemo.java
index f51e3be..8bb3bc7 100644
--- a/src/cn/trinea/android/demo/ViewPagerDemo.java
+++ b/src/cn/trinea/android/demo/ViewPagerDemo.java
@@ -34,12 +34,11 @@ protected void onCreate(Bundle savedInstanceState) {
AppUtils.initTrineaInfo(this, trineaInfoTv, getClass());
ViewPager vp = (ViewPager)findViewById(R.id.view_pager);
-
for (int i = 0; i < 3; i++) {
ViewPagerFragment viewPagerFragment1 = new ViewPagerFragment();
Bundle bundle = new Bundle();
bundle.putInt("upImageId", 0);
- bundle.putString("text", "页面" + i);
+ bundle.putString("text", "Page " + i);
viewPagerFragment1.setArguments(bundle);
titleList.add("title " + i);
fragmentList.add(viewPagerFragment1);
diff --git a/src/cn/trinea/android/demo/utils/AppUtils.java b/src/cn/trinea/android/demo/utils/AppUtils.java
index ccf201f..4e978ca 100644
--- a/src/cn/trinea/android/demo/utils/AppUtils.java
+++ b/src/cn/trinea/android/demo/utils/AppUtils.java
@@ -12,6 +12,8 @@
import cn.trinea.android.demo.BroadcastReceiverDemo;
import cn.trinea.android.demo.DownloadManagerDemo;
import cn.trinea.android.demo.DropDownListViewDemo;
+import cn.trinea.android.demo.ImageCacheDemo;
+import cn.trinea.android.demo.ImageSDCardCacheDemo;
import cn.trinea.android.demo.R;
import cn.trinea.android.demo.SearchViewDemo;
import cn.trinea.android.demo.ServiceDemo;
@@ -26,12 +28,13 @@
*/
public class AppUtils {
- public static String PROFILE = "个人主页: ";
- public static String ABOUT = "相关介绍见: ";
-
public static void initTrineaInfo(final Activity activity, Button trineaInfoTv, Class sourClass) {
trineaInfoTv = (Button)activity.findViewById(R.id.trineaInfo);
- final String[] result = getText(sourClass);
+ if (trineaInfoTv == null) {
+ return;
+ }
+
+ final String[] result = getText(activity, sourClass);
Spanned text = Html.fromHtml(result[1]);
trineaInfoTv.setText(text);
trineaInfoTv.setOnClickListener(new OnClickListener() {
@@ -46,46 +49,54 @@ public void onClick(View v) {
});
}
- public static String[] getText(Class sourClass) {
- String prefix = null, url = null, name = null;
+ public static String[] getText(Activity activity, Class sourClass) {
+ int prefixSrcId = R.string.description, contentSrcId;
+ String url = null;
if (sourClass == SearchViewDemo.class) {
url = "http://www.trinea.cn/android/android-searchview%E4%BB%8B%E7%BB%8D%E5%8F%8A%E6%90%9C%E7%B4%A2%E6%8F%90%E7%A4%BA%E5%AE%9E%E7%8E%B0/";
- name = "SearchView介绍及搜索提示实现";
+ contentSrcId = R.string.desc_search_view;
} else if (sourClass == ViewPagerMulTiFragmentDemo.class) {
url = "http://www.trinea.cn/android/viewpager%E5%AE%9E%E7%8E%B0%E7%94%BB%E5%BB%8A%E4%B8%80%E5%B1%8F%E5%A4%9A%E4%B8%AAfragment%E6%95%88%E6%9E%9C/";
- name = "viewpager实现画廊效果";
+ contentSrcId = R.string.desc_view_pager_multi_page;
} else if (sourClass == DownloadManagerDemo.class) {
url = "http://www.trinea.cn/android/android系统下载管理downloadmanager功能介绍及使用示例";
- name = "系统下载管理使用";
+ contentSrcId = R.string.desc_download_manager;
} else if (sourClass == SlideOnePageGalleryDemo.class) {
url = "http://www.trinea.cn/android/gallery滑动一页一个item效果/";
- name = "Gallery滑动一页(一个Item)效果";
+ contentSrcId = R.string.desc_slide_gallery;
} else if (sourClass == ViewPagerDemo.class) {
url = "http://www.cnblogs.com/trinea/archive/2012/11/23/2771273.html";
- name = "ViewPager、Fragment使用";
+ contentSrcId = R.string.desc_view_pager;
} else if (sourClass == ServiceDemo.class) {
url = "http://www.cnblogs.com/trinea/archive/2012/11/08/2699856.html";
- name = "Service介绍";
+ contentSrcId = R.string.desc_service;
} else if (sourClass == BroadcastReceiverDemo.class) {
url = "http://www.cnblogs.com/trinea/archive/2012/11/09/2763182.html";
- name = "BroadcastReceiver介绍";
+ contentSrcId = R.string.desc_broadcast_receiver;
} else if (sourClass == BorderScrollViewDemo.class) {
url = "http://www.trinea.cn/?p=445";
- name = "BorderScrollViewDemo介绍";
+ contentSrcId = R.string.desc_border_scroll_view;
} else if (sourClass == DropDownListViewDemo.class) {
url = "http://www.trinea.cn/?p=523";
- name = "下拉刷新及底部加载更多Listview";
+ contentSrcId = R.string.desc_drop_down_listview;
+ } else if (sourClass == ImageCacheDemo.class) {
+ url = "http://www.trinea.cn/?p=704";
+ contentSrcId = R.string.desc_image_cache;
+ } else if (sourClass == ImageSDCardCacheDemo.class) {
+ url = "http://www.trinea.cn/?p=757";
+ contentSrcId = R.string.desc_image_sdcard_cache;
} else {
- prefix = "个人主页:";
+ prefixSrcId = R.string.profile;
url = "http://www.trinea.cn";
- name = " Trinea";
+ contentSrcId = R.string.desc_default;
}
- String[] result = new String[] { url, getUrlInfo(prefix, url, name) };
+ String[] result = new String[] { url,
+ getUrlInfo(activity.getString(prefixSrcId), url, activity.getString(contentSrcId)) };
return result;
}
- private static String getUrlInfo(String prefix, String url, String name) {
- return new StringBuilder().append(prefix == null ? ABOUT : prefix).append("").append(name).append("").toString();
+ private static String getUrlInfo(String prefix, String url, String content) {
+ return new StringBuilder().append(prefix).append("").append(content)
+ .append("").toString();
}
}