master
allthelucky 13 years ago
parent f103f57efa
commit 907941dfea

@ -14,7 +14,7 @@
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme" > android:theme="@style/AppTheme" >
<activity <activity
android:name="com.app.library.common.view.sample.SampleActivity" android:name="com.allthelucky.common.view.sample.SampleActivity"
android:label="@string/app_name" > android:label="@string/app_name" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -22,9 +22,9 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".sample.AutoImageIndicatorActivity" /> <activity android:name="com.allthelucky.common.view.sample.AutoImageIndicatorActivity" />
<activity android:name=".sample.GuideImageIndicatorActivity" /> <activity android:name="com.allthelucky.common.view.sample.GuideImageIndicatorActivity" />
<activity android:name=".sample.ImageIndicatorActivity" /> <activity android:name="com.allthelucky.common.view.sample.ImageIndicatorActivity" />
</application> </application>
</manifest> </manifest>

@ -4,7 +4,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
> >
<com.app.library.common.view.ImageIndicatorView <com.allthelucky.common.view.ImageIndicatorView
android:id="@+id/indicate_view" android:id="@+id/indicate_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="120dp" /> android:layout_height="120dp" />

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

@ -3,11 +3,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >
<com.app.library.common.view.ImageIndicatorView <com.allthelucky.common.view.ImageIndicatorView
android:id="@+id/guide_indicate_view" android:id="@+id/guide_indicate_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" />
</com.app.library.common.view.ImageIndicatorView>
<Button <Button
android:id="@+id/button1" android:id="@+id/button1"

@ -1,4 +1,4 @@
package com.app.library.common.view; package com.allthelucky.common.view;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;

@ -1,10 +1,13 @@
package com.app.library.common.view; package com.allthelucky.common.view;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.Parcelable; import android.os.Parcelable;
@ -20,7 +23,9 @@ import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import com.app.library.http.UrlImageView; import com.allthelucky.http.RequestListener;
import com.allthelucky.http.RequestManager;
import com.app.library.common.view.R;
/** /**
* ,(Gallery) * ,(Gallery)
@ -244,14 +249,62 @@ public class ImageIndicatorView extends RelativeLayout {
final int len = urlList.size(); final int len = urlList.size();
if (len > 0) { if (len > 0) {
for (int index = 0; index < len; index++) { for (int index = 0; index < len; index++) {
final UrlImageView pageItem = new UrlImageView(getContext()); final ImageView pageItem = new ImageView(getContext());
pageItem.setScaleType(ScaleType.FIT_XY); pageItem.setScaleType(ScaleType.FIT_XY);
pageItem.setURLAsync(urlList.get(index)); loadImage(pageItem, urlList.get(index), R.drawable.ic_launcher);
addViewItem(pageItem); 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);
}
/** /**
* *
* *

@ -1,10 +1,10 @@
package com.app.library.common.view.sample; package com.allthelucky.common.view.sample;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import com.app.library.common.view.AutoImageIndicatorView; import com.allthelucky.common.view.AutoImageIndicatorView;
import com.app.library.common.view.ImageIndicatorView; import com.allthelucky.common.view.ImageIndicatorView;
import com.app.library.common.view.R; import com.app.library.common.view.R;
public class AutoImageIndicatorActivity extends Activity { public class AutoImageIndicatorActivity extends Activity {

@ -1,4 +1,4 @@
package com.app.library.common.view.sample; package com.allthelucky.common.view.sample;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
@ -6,7 +6,7 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast; import android.widget.Toast;
import com.app.library.common.view.ImageIndicatorView; import com.allthelucky.common.view.ImageIndicatorView;
import com.app.library.common.view.R; import com.app.library.common.view.R;
public class GuideImageIndicatorActivity extends Activity implements View.OnClickListener, public class GuideImageIndicatorActivity extends Activity implements View.OnClickListener,

@ -1,9 +1,9 @@
package com.app.library.common.view.sample; package com.allthelucky.common.view.sample;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import com.app.library.common.view.ImageIndicatorView; import com.allthelucky.common.view.ImageIndicatorView;
import com.app.library.common.view.R; import com.app.library.common.view.R;
public class ImageIndicatorActivity extends Activity { public class ImageIndicatorActivity extends Activity {

@ -1,4 +1,4 @@
package com.app.library.common.view.sample; package com.allthelucky.common.view.sample;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
Loading…
Cancel
Save