Merge branch 'develop'

master
panxw 11 years ago
commit 020fe73e29

@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

@ -12,7 +12,8 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme"
android:name="com.allthelucky.common.view.sample.SampleApp" >
<activity
android:name="com.allthelucky.common.view.sample.SampleActivity"
android:label="@string/app_name" >

@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.allthelucky.common.view.AutoImageIndicatorView
<com.allthelucky.common.view.ImageIndicatorView
android:id="@+id/auto_indicate_view"
android:layout_width="match_parent"
android:layout_height="120dp" />

@ -0,0 +1,182 @@
package com.allthelucky.common.view;
import android.os.Handler;
import android.os.Message;
import com.allthelucky.common.view.ImageIndicatorView;
/**
* Auto BrocastManager for ImageIndicatorView
*
* @author steven-pan
*
*/
public class AutoBrocastManager {
/**
*
*/
private boolean broadcastEnable = false;
/**
*
*/
private static final long DEFAULT_STARTMILS = 2 * 1000;
/**
*
*/
private static final long DEFAULT_INTEVALMILS = 3 * 1000;
/**
* ms
*/
private long startMils = DEFAULT_STARTMILS;
/**
* ms
*/
private long intevalMils = DEFAULT_INTEVALMILS;
/**
*
*/
private final static int RIGHT = 0;
/**
*
*/
private final static int LEFT = 1;
/**
*
*/
private int direction = RIGHT;
/**
*
*/
private static final int DEFAULT_TIMES = -1;
/**
*
*/
private int broadcastTimes = DEFAULT_TIMES;
/**
*
*/
private int timesCount = 0;
/**
*
*/
private Handler broadcastHandler = null;
/**
* target ImageIndicatorView
*/
private ImageIndicatorView mImageIndicatorView = null;
public AutoBrocastManager(ImageIndicatorView imageIndicatorView) {
this.mImageIndicatorView = imageIndicatorView;
this.broadcastHandler = new BroadcastHandler(AutoBrocastManager.this);
}
/**
*
*
* @param startMils
* ms(8s)
* @param intevelMils
* ms(3s)
*/
public void setBroadcastTimeIntevel(long startMils, long intevelMils) {
this.startMils = startMils;
this.intevalMils = intevelMils;
}
/**
*
*
* @param flag
*
*/
public void setBroadcastEnable(boolean flag) {
this.broadcastEnable = flag;
}
/**
*
*
* @param times
*
*/
public void setBroadCastTimes(int times) {
this.broadcastTimes = times;
}
/**
*
*/
public void loop() {
if (broadcastEnable) {
broadcastHandler.sendEmptyMessageDelayed(0, this.startMils);
}
}
protected void handleMessage(android.os.Message msg) {
if (broadcastEnable) {
if (System.currentTimeMillis()
- mImageIndicatorView.getRefreshTime() < 5 * 1000) {// 最近一次划动间隔小于5s
return;
}
if ((broadcastTimes != DEFAULT_TIMES)
&& (timesCount > broadcastTimes)) {// 循环次数用完
return;
}
if (direction == RIGHT) {// roll right
if (mImageIndicatorView.getCurrentIndex() < mImageIndicatorView
.getTotalCount()) {
if (mImageIndicatorView.getCurrentIndex() == mImageIndicatorView
.getTotalCount() - 1) {
timesCount++;// 循环次数次数加1
direction = LEFT;
} else {
mImageIndicatorView
.getViewPager()
.setCurrentItem(
mImageIndicatorView.getCurrentIndex() + 1,
true);
}
}
} else {// roll left
if (mImageIndicatorView.getCurrentIndex() >= 0) {
if (mImageIndicatorView.getCurrentIndex() == 0) {
direction = RIGHT;
} else {
mImageIndicatorView
.getViewPager()
.setCurrentItem(
mImageIndicatorView.getCurrentIndex() - 1,
true);
}
}
}
broadcastHandler.sendEmptyMessageDelayed(1, this.intevalMils);
}
}
static class BroadcastHandler extends Handler {
private AutoBrocastManager autoBrocastManager;
public BroadcastHandler(AutoBrocastManager autoBrocastManager) {
this.autoBrocastManager = autoBrocastManager;
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (this.autoBrocastManager != null) {
autoBrocastManager.handleMessage(msg);
}
}
}
}

@ -1,181 +0,0 @@
package com.allthelucky.common.view;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
/**
* (
*
* @author savant-pan
*
*/
public class AutoImageIndicatorView extends ImageIndicatorView {
/**
*
*/
private ScheduledExecutorService scheduler;
/**
*
*/
private boolean broadcastEnagle = false;
/**
*
*/
private static final long DEFAULT_STARTMILS = 2 * 1000;
/**
*
*/
private static final long DEFAULT_INTEVALMILS = 3 * 1000;
/**
* ms
*/
private long startMils = DEFAULT_STARTMILS;
/**
* ms
*/
private long intevalMils = DEFAULT_INTEVALMILS;
/**
*
*/
private final static int RIGHT = 0;
/**
*
*/
private final static int LEFT = 1;
/**
*
*/
private int direction = RIGHT;
/**
*
*/
private static final int DEFAULT_TIMES = -1;
/**
*
*/
private int broadcastTimes = DEFAULT_TIMES;
/**
*
*/
private int timesCount = 0;
/**
*
*/
private Handler broadcastHandler = null;
public AutoImageIndicatorView(Context context, AttributeSet attrs) {
super(context, attrs);
this.init();
}
public AutoImageIndicatorView(Context context) {
super(context);
this.init();
}
private void init() {
this.broadcastHandler = new BroadcastHandler(AutoImageIndicatorView.this);
this.scheduler = Executors.newScheduledThreadPool(1);
}
/**
*
*
* @param startMils
* ms(8s)
* @param intevelMils
* ms(3s)
*/
public void setBroadcastTimeIntevel(long startMils, long intevelMils) {
this.startMils = startMils;
this.intevalMils = intevelMils;
}
/**
*
*
* @param flag
*
*/
public void setBroadcastEnable(boolean flag) {
this.broadcastEnagle = flag;
}
/**
*
*
* @param times
*
*/
public void setBroadCastTimes(int times) {
this.broadcastTimes = times;
}
@Override
public void show() {
super.show();
// 定时播放服务
this.scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
if (broadcastEnagle) {
if (System.currentTimeMillis() - getRefreshTime() < 5 * 1000) {// 最近一次划动间隔小于5s
return;
}
if ((broadcastTimes != DEFAULT_TIMES) && (timesCount > broadcastTimes)) {// 循环次数用完
return;
}
broadcastHandler.sendEmptyMessage(0);
}
}
}, this.startMils, this.intevalMils, TimeUnit.MILLISECONDS);
}
protected void handleMessage(android.os.Message msg) {
if (direction == RIGHT) {// roll right
if (getCurrentIndex() < getTotalCount()) {
if (getCurrentIndex() == getTotalCount() - 1) {
timesCount++;// 循环次数次数加1
direction = LEFT;
} else {
getViewPager().setCurrentItem(getCurrentIndex() + 1, true);
}
}
} else {// roll left
if (getCurrentIndex() >= 0) {
if (getCurrentIndex() == 0) {
direction = RIGHT;
} else {
getViewPager().setCurrentItem(getCurrentIndex() - 1, true);
}
}
}
}
}
class BroadcastHandler extends Handler {
private AutoImageIndicatorView autoImageIndicatorView;
public BroadcastHandler(AutoImageIndicatorView autoImageIndicatorView) {
this.autoImageIndicatorView = autoImageIndicatorView;
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (this.autoImageIndicatorView != null) {
autoImageIndicatorView.handleMessage(msg);
}
}
}

@ -5,9 +5,6 @@ import java.util.Arrays;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
@ -19,12 +16,9 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.allthelucky.http.RequestListener;
import com.allthelucky.http.RequestManager;
import com.app.library.common.view.R;
/**
@ -149,28 +143,28 @@ public class ImageIndicatorView extends RelativeLayout {
*
* @return
*/
protected ViewPager getViewPager() {
public ViewPager getViewPager() {
return viewPager;
}
/**
* Index
*/
protected int getCurrentIndex() {
public int getCurrentIndex() {
return this.currentIndex;
}
/**
* VIEW
*/
protected int getTotalCount() {
public int getTotalCount() {
return this.totelCount;
}
/**
*
*/
protected long getRefreshTime() {
public long getRefreshTime() {
return this.refreshTime;
}
@ -236,75 +230,6 @@ public class ImageIndicatorView extends RelativeLayout {
}
}
/**
* URL
*
* @param urlList
* URL
*/
public void setupLayoutByImageUrl(final List<String> urlList) {
if (urlList == null)
throw new NullPointerException();
final int len = urlList.size();
if (len > 0) {
for (int index = 0; index < len; index++) {
final ImageView pageItem = new ImageView(getContext());
pageItem.setScaleType(ScaleType.FIT_XY);
loadImage(pageItem, urlList.get(index), R.drawable.ic_launcher);
addViewItem(pageItem);
}
}
}
private void loadImage(final ImageView pageItem, final String imageUrl,final int imageResId ) {
/**
* load callback for RequestManager
*/
final RequestListener requestListener = new RequestListener() {
@Override
public void onStart() {
}
@Override
public void onCompleted(int statusCode, byte[] data, long lastModified, String description, int actionId) {
if (RequestListener.ERR == statusCode) {
pageItem.setImageResource(imageResId);
} else {
if (null != data) {
BitmapFactory.Options o = new BitmapFactory.Options();// decode image size
o.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length, o);
final int REQUIRED_SIZE = 100; // Find the correct scale value.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
BitmapFactory.Options options = new Options();// decode with scale
options.inSampleSize = scale;
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options);
if (bitmap != null) {
pageItem.setImageBitmap(bitmap);
} else {
pageItem.setImageResource(imageResId);
}
}
}
}
};
RequestManager.getInstance().get(getContext(), imageUrl, null, requestListener, true, 0);
}
/**
*
*

@ -0,0 +1,33 @@
package com.allthelucky.common.view.network;
import com.android.http.RequestManager;
import com.android.volley.toolbox.ImageLoader;
import android.app.Application;
/**
* @description NetworkApp
*
* @author steven-pan
*
*/
public class NetworkApp extends Application {
private static ImageLoader sImageLoader = null;
private final NetworkImageCache imageCacheMap = new NetworkImageCache();
public static ImageLoader getImageLoader() {
return sImageLoader;
}
@Override
public void onCreate() {
super.onCreate();
RequestManager.getInstance().init(NetworkApp.this);
sImageLoader = new ImageLoader(RequestManager.getInstance()
.getRequestQueue(), imageCacheMap);
}
}

@ -0,0 +1,44 @@
package com.allthelucky.common.view.network;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
/**
* @description NetworkImageCache
*
* @auther steven-pan
*/
public class NetworkImageCache extends LruCache<String, Bitmap> implements
ImageCache {
public NetworkImageCache() {
this(getDefaultLruCacheSize());
}
public NetworkImageCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
}

@ -0,0 +1,52 @@
package com.allthelucky.common.view.network;
import java.util.List;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView.ScaleType;
import com.allthelucky.common.view.ImageIndicatorView;
import com.android.http.WebImageView;
import com.app.library.common.view.R;
/**
* Network ImageIndicatorView, by urls
*
* @author steven-pan
*
*/
public class NetworkImageIndicatorView extends ImageIndicatorView {
public NetworkImageIndicatorView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NetworkImageIndicatorView(Context context) {
super(context);
}
/**
* URL
*
* @param urlList
* URL
*/
public void setupLayoutByImageUrl(final List<String> urlList) {
if (urlList == null)
throw new NullPointerException();
final int len = urlList.size();
if (len > 0) {
for (int index = 0; index < len; index++) {
final WebImageView pageItem = new WebImageView(getContext());
pageItem.setScaleType(ScaleType.FIT_XY);
pageItem.setDefaultImageResId(R.drawable.ic_launcher);
pageItem.setImageUrl(urlList.get(index),
NetworkApp.getImageLoader());
addViewItem(pageItem);
}
}
}
}

@ -3,19 +3,19 @@ package com.allthelucky.common.view.sample;
import android.app.Activity;
import android.os.Bundle;
import com.allthelucky.common.view.AutoImageIndicatorView;
import com.allthelucky.common.view.AutoBrocastManager;
import com.allthelucky.common.view.ImageIndicatorView;
import com.app.library.common.view.R;
public class AutoImageIndicatorActivity extends Activity {
private AutoImageIndicatorView autoImageIndicatorView;
private ImageIndicatorView autoImageIndicatorView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_indicator_auto);
this.autoImageIndicatorView = (AutoImageIndicatorView) findViewById(R.id.auto_indicate_view);
this.autoImageIndicatorView = (ImageIndicatorView) findViewById(R.id.auto_indicate_view);
autoImageIndicatorView.setOnItemChangeListener(new ImageIndicatorView.OnItemChangeListener() {
@Override
public void onPosition(int position, int totalCount) {
@ -34,11 +34,16 @@ public class AutoImageIndicatorActivity extends Activity {
private void initView() {
final Integer[] resArray = new Integer[] { R.drawable.poster1, R.drawable.poster2, R.drawable.poster3 };
this.autoImageIndicatorView.setBroadcastEnable(true);
this.autoImageIndicatorView.setBroadCastTimes(5);//循环播放5次
this.autoImageIndicatorView.setBroadcastTimeIntevel(2 * 1000, 3 * 1000);//播放启动时间及间隔
this.autoImageIndicatorView.setupLayoutByDrawable(resArray);//图片
this.autoImageIndicatorView.show();
AutoBrocastManager autoBrocastManager = new AutoBrocastManager(this.autoImageIndicatorView);
autoBrocastManager.setBroadcastEnable(true);
autoBrocastManager.setBroadCastTimes(5);//循环播放5次
autoBrocastManager.setBroadcastTimeIntevel(2 * 1000, 3 * 1000);//播放启动时间及间隔
autoBrocastManager.loop();
}
}

@ -0,0 +1,17 @@
package com.allthelucky.common.view.sample;
import com.allthelucky.common.view.network.NetworkApp;
/**
* SampleApp
*
* @author steven-pan
*
*/
public class SampleApp extends NetworkApp {
@Override
public void onCreate() {
super.onCreate();
}
}
Loading…
Cancel
Save