Skip to content

Commit

Permalink
modify ImageCacheDemo
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinea committed Oct 26, 2013
1 parent 0b8b886 commit c3574b8
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 293 deletions.
10 changes: 8 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.trinea.android.demo"
android:versionCode="33"
android:versionName="2.9.9" >
android:versionCode="35"
android:versionName="2.9.11" >

<uses-sdk android:minSdkVersion="14" />

Expand Down Expand Up @@ -54,6 +54,12 @@
android:label="@string/imagesdcardcache_demo_activity_title"
android:theme="@android:style/Theme.Holo.Light" >
</activity>
<activity
android:name=".CanvasDrawDemo"
android:configChanges="orientation|keyboardHidden"
android:label="@string/imagecache_demo_activity_title"
android:theme="@android:style/Theme.Holo.Light" >
</activity>
<activity
android:name=".ImageCacheDemo"
android:configChanges="orientation|keyboardHidden"
Expand Down
2 changes: 1 addition & 1 deletion src/cn/trinea/android/demo/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* BaseActivity
*
* @author Trinea 2013-6-1
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-6-1
*/
public class BaseActivity extends Activity {

Expand Down
3 changes: 1 addition & 2 deletions src/cn/trinea/android/demo/BorderScrollViewDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import android.view.Display;
import android.widget.TextView;
import android.widget.Toast;

import cn.trinea.android.common.view.BorderScrollView;
import cn.trinea.android.common.view.BorderScrollView.OnBorderListener;

/**
* BorderScrollViewDemo
*
* @author Trinea 2013-5-27
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-5-27
*/
public class BorderScrollViewDemo extends BaseActivity {

Expand Down
9 changes: 1 addition & 8 deletions src/cn/trinea/android/demo/BroadcastReceiverDemo.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*
* Copyright 2012 Trinea.cn All right reserved. This software is the
* confidential and proprietary information of Trinea.cn ("Confidential
* Information"). You shall not disclose such Confidential Information and shall
* use it only in accordance with the terms of the license agreement you entered
* into with Trinea.cn.
*/
package cn.trinea.android.demo;

import android.app.Activity;
Expand All @@ -22,7 +15,7 @@
/**
* BroadcastReceiver Demo,包括普通广播、本地广播、有序广播、粘性广播
*
* @author Trinea 2012-9-20
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2012-9-20
*/
public class BroadcastReceiverDemo extends BaseActivity {

Expand Down
72 changes: 72 additions & 0 deletions src/cn/trinea/android/demo/CanvasDrawDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cn.trinea.android.demo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

/**
* CanvasDrawDemo
*
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-10-11
*/
public class CanvasDrawDemo extends BaseActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.canvas_demo);

RelativeLayout layout = (RelativeLayout)findViewById(R.id.canvas_demo_layout);
CanvasDemoView view = new CanvasDemoView(this);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.leftMargin = 600;
// params.addRule(RelativeLayout.CENTER_IN_PARENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
layout.addView(view, params);
}

public class CanvasDemoView extends View {

public CanvasDemoView(Context context){
super(context);
}

public CanvasDemoView(Context context, AttributeSet attrs){
super(context, attrs);
}

Paint paint = new Paint();

protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);

canvas.drawText("画贝塞尔曲线:", 10, 310, paint);
paint.reset();
// paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.GREEN);
Path path2 = new Path();
path2.moveTo(100, 320);// 设置Path的起点
path2.quadTo(150, 310, 170, 400); // 设置贝塞尔曲线的控制点坐标和终点坐标
// canvas.drawPath(path2, paint);//画出贝塞尔曲线
Path path1 = new Path();
path1.moveTo(30, 400);// 设置Path的起点
path1.quadTo(100, 310, 170, 400); // 设置贝塞尔曲线的控制点坐标和终点坐标
canvas.drawPath(path1, paint);// 画出贝塞尔曲线

// paint.setColor(Color.rgb(160, 160, 160));
// float width = 2.5f;
// paint.setStrokeWidth(width);
// RectF oval = new RectF(0, 0, 100, 150);
// canvas.drawRect(oval, paint);
// paint.setStyle(Paint.Style.STROKE);
// paint.setColor(Color.rgb(60, 160, 0));
// canvas.drawArc(oval, 0, 90, false, paint);
}
}
}
2 changes: 1 addition & 1 deletion src/cn/trinea/android/demo/DemoList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* demo list list
*
* @author Trinea 2012-6-17
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2012-6-17
*/
public class DemoList extends BaseActivity {

Expand Down
10 changes: 6 additions & 4 deletions src/cn/trinea/android/demo/DownloadManagerDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import cn.trinea.android.demo.utils.DownloadManagerPro;
import cn.trinea.android.common.util.DownloadManagerPro;
import cn.trinea.android.common.util.PreferencesUtils;

/**
* DownloadManagerDemo
*
* @author Trinea 2013-5-9
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-5-9
*/
public class DownloadManagerDemo extends BaseActivity {

public static final String DOWNLOAD_FOLDER_NAME = "Trinea";
public static final String DOWNLOAD_FILE_NAME = "MeiLiShuo.apk";

public static final String APK_URL = "http://img.meilishuo.net/css/images/AndroidShare/Meilishuo_3.6.1_10006.apk";
public static final String KEY_NAME_DOWNLOAD_ID = "downloadId";

private Button downloadButton;
private ProgressBar downloadProgress;
Expand Down Expand Up @@ -118,7 +120,7 @@ private void initData() {
* get download id from preferences.<br/>
* if download id bigger than 0, means it has been downloaded, then query status and show right text;
*/
downloadId = PreferencesUtils.getLongPreferences(context, PreferencesUtils.KEY_NAME_DOWNLOAD_ID);
downloadId = PreferencesUtils.getLong(context, KEY_NAME_DOWNLOAD_ID);
updateView();
downloadButton.setOnClickListener(new OnClickListener() {

Expand All @@ -142,7 +144,7 @@ public void onClick(View v) {
request.setMimeType("application/cn.trinea.download.file");
downloadId = downloadManager.enqueue(request);
/** save download id to preferences **/
PreferencesUtils.putLongPreferences(context, PreferencesUtils.KEY_NAME_DOWNLOAD_ID, downloadId);
PreferencesUtils.putLong(context, KEY_NAME_DOWNLOAD_ID, downloadId);
updateView();
}
});
Expand Down
3 changes: 1 addition & 2 deletions src/cn/trinea/android/demo/DropDownListViewDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;

import cn.trinea.android.common.view.DropDownListView;
import cn.trinea.android.common.view.DropDownListView.OnDropDownListener;

/**
* DropDownListViewDemo
*
* @author Trinea 2013-6-1
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-6-1
*/
public class DropDownListViewDemo extends BaseActivity {

Expand Down
20 changes: 14 additions & 6 deletions src/cn/trinea/android/demo/ImageCacheDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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.ImageMemoryCache.OnImageCallbackListener;
import cn.trinea.android.common.service.impl.RemoveTypeLastUsedTimeFirst;

/**
Expand All @@ -25,11 +25,12 @@
public class ImageCacheDemo extends BaseActivity {

/** column number **/
public static final int COLUMNS = 2;
public static final int COLUMNS = 2;
/** imageView default height **/
public static final int IMAGEVIEW_DEFAULT_HEIGHT = 400;
public static final int IMAGEVIEW_DEFAULT_HEIGHT = 400;
public static final String TAG_CACHE = "image_cache";

private RelativeLayout parentLayout;
private RelativeLayout parentLayout;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -38,6 +39,7 @@ public void onCreate(Bundle savedInstanceState) {
Context context = getApplicationContext();
parentLayout = (RelativeLayout)findViewById(R.id.image_cache_parent_layout);
initImageUrlList();
IMAGE_CACHE.initData(this, TAG_CACHE);
IMAGE_CACHE.setContext(context);

int count = 0, viewId = 0x7F24FFF0;
Expand Down Expand Up @@ -75,8 +77,14 @@ public void onCreate(Bundle savedInstanceState) {
}
}

@Override
protected void onDestroy() {
IMAGE_CACHE.saveDataToDb(this, TAG_CACHE);
super.onDestroy();
}

/** icon cache **/
public static final ImageCache IMAGE_CACHE = new ImageCache(128);
public static final ImageCache IMAGE_CACHE = new ImageCache(128, 512);

static {
/** init icon cache **/
Expand All @@ -94,7 +102,7 @@ public void onImageLoaded(String imageUrl, Drawable imageDrawable, View view, bo
imageView.startAnimation(getInAlphaAnimation(2000));
}

// auto set height accroding to rate between height and widght
// auto set height accroding to rate between height and weight
LayoutParams imageParams = (LayoutParams)imageView.getLayoutParams();
imageParams.height = imageParams.width * imageDrawable.getIntrinsicHeight()
/ imageDrawable.getIntrinsicWidth();
Expand Down
15 changes: 10 additions & 5 deletions src/cn/trinea/android/demo/ImageSDCardCacheDemo.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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;
Expand All @@ -31,12 +29,15 @@
*/
public class ImageSDCardCacheDemo extends BaseActivity {

public static final String TAG_CACHE = "image_sdcard_cache";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.slide_one_page_gallery_demo);

Context context = getApplicationContext();
initImageUrlList();
IMAGE_SD_CACHE.initData(context, TAG_CACHE);
IMAGE_SD_CACHE.setContext(context);

SlideOnePageGallery imageGallery = (SlideOnePageGallery)findViewById(R.id.app_app_image_gallery);
Expand All @@ -46,6 +47,12 @@ public void onCreate(Bundle savedInstanceState) {

}

@Override
protected void onDestroy() {
IMAGE_SD_CACHE.saveDataToDb(this, TAG_CACHE);
super.onDestroy();
}

/** icon cache **/
public static final ImageSDCardCache IMAGE_SD_CACHE = new ImageSDCardCache();

Expand Down Expand Up @@ -79,8 +86,6 @@ public void onImageLoaded(String imageUrl, String imagePath, View view, boolean
};
IMAGE_SD_CACHE.setOnImageSDCallbackListener(imageCallBack);
IMAGE_SD_CACHE.setCacheFullRemoveType(new RemoveTypeLastUsedTimeFirst<String>());
IMAGE_SD_CACHE.setCacheFolder(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
+ "TrineaAndroidCommon");
IMAGE_SD_CACHE.setFileNameRule(new FileNameRuleImageUrl());

IMAGE_SD_CACHE.setHttpReadTimeOut(10000);
Expand Down Expand Up @@ -144,7 +149,7 @@ private static class ImageAdapter extends BaseAdapter {
private LayoutInflater inflater;
public List<String> imageUrlList;

public ImageAdapter(Context context){
public ImageAdapter(Context context) {
super();
inflater = LayoutInflater.from(context);
}
Expand Down
9 changes: 1 addition & 8 deletions src/cn/trinea/android/demo/MyAIDLService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*
* Copyright 2012 Trinea.cn All right reserved. This software is the
* confidential and proprietary information of Trinea.cn ("Confidential
* Information"). You shall not disclose such Confidential Information and shall
* use it only in accordance with the terms of the license agreement you entered
* into with Trinea.cn.
*/
package cn.trinea.android.demo;

import android.app.Service;
Expand All @@ -16,7 +9,7 @@
/**
* MyAIDLService
*
* @author Trinea 2013-5-9
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-5-9
*/
public class MyAIDLService extends Service {

Expand Down
2 changes: 1 addition & 1 deletion src/cn/trinea/android/demo/MyIntentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* MyIntentService
*
* @author Trinea 2013-5-9
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-5-9
*/
public class MyIntentService extends IntentService {

Expand Down
9 changes: 1 addition & 8 deletions src/cn/trinea/android/demo/MyService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*
* Copyright 2012 Trinea.cn All right reserved. This software is the
* confidential and proprietary information of Trinea.cn ("Confidential
* Information"). You shall not disclose such Confidential Information and shall
* use it only in accordance with the terms of the license agreement you entered
* into with Trinea.cn.
*/
package cn.trinea.android.demo;

import android.app.Service;
Expand All @@ -16,7 +9,7 @@
/**
* MyService
*
* @author Trinea 2013-5-9
* @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2013-5-9
*/
public class MyService extends Service {

Expand Down
Loading

0 comments on commit c3574b8

Please sign in to comment.