udpate README.md

master
winfirm 11 years ago
parent 731a0bbeac
commit 8ca6c74f29

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<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>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<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>

@ -1,33 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AndroidImageIndicator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AndroidImageIndicator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -1,8 +1,8 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/arrow_left_focus" android:state_pressed="true"/>
<item android:drawable="@drawable/arrow_left_focus" android:state_selected="true"/>
<item android:drawable="@drawable/arrow_left_focus" android:state_focused="true"/>
<item android:drawable="@drawable/arrow_left"/>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/arrow_left_focus" android:state_pressed="true"/>
<item android:drawable="@drawable/arrow_left_focus" android:state_selected="true"/>
<item android:drawable="@drawable/arrow_left_focus" android:state_focused="true"/>
<item android:drawable="@drawable/arrow_left"/>
</selector>

@ -1,8 +1,8 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/arrow_right_focus" android:state_pressed="true"/>
<item android:drawable="@drawable/arrow_right_focus" android:state_selected="true"/>
<item android:drawable="@drawable/arrow_right_focus" android:state_focused="true"/>
<item android:drawable="@drawable/arrow_right"/>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/arrow_right_focus" android:state_pressed="true"/>
<item android:drawable="@drawable/arrow_right_focus" android:state_selected="true"/>
<item android:drawable="@drawable/arrow_right_focus" android:state_focused="true"/>
<item android:drawable="@drawable/arrow_right"/>
</selector>

@ -1,53 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="bottom" >
<Button
android:id="@+id/left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/arrow_left_selector" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="bottom" >
<Button
android:id="@+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/arrow_right_selector" />
</LinearLayout>
<LinearLayout
android:id="@+id/indicater_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:gravity="center"
android:minHeight="10dp"
android:minWidth="60dp"
android:orientation="horizontal" >
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="bottom" >
<Button
android:id="@+id/left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/arrow_left_selector" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="bottom" >
<Button
android:id="@+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/arrow_right_selector" />
</LinearLayout>
<LinearLayout
android:id="@+id/indicater_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:gravity="center"
android:minHeight="10dp"
android:minWidth="60dp"
android:orientation="horizontal" >
</LinearLayout>
</RelativeLayout>

@ -1,7 +1,7 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AndroidImageIndicator</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AndroidImageIndicator</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
</resources>

@ -1,20 +1,20 @@
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>

@ -1,460 +1,460 @@
package com.allthelucky.common.view;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.app.library.common.view.R;
/**
* ,(Gallery)
*
* @author savant-pan
*
*/
public class ImageIndicatorView extends RelativeLayout {
/**
* ViewPager
*/
private ViewPager viewPager;
/**
*
*/
private LinearLayout indicateLayout;
/**
*
*/
private Button leftButton;
/**
*
*/
private Button rightButton;
/**
*
*/
private List<View> viewList = new ArrayList<View>();
private Handler refreshHandler;
/**
*
*/
private OnItemChangeListener onItemChangeListener;
/**
*
*/
private OnItemClickListener onItemClickListener;
/**
*
*/
private int totelCount = 0;
/**
*
*/
private int currentIndex = 0;
/**
* +
*/
public static final int INDICATE_ARROW_ROUND_STYLE = 0;
/**
*
*/
public static final int INDICATE_USERGUIDE_STYLE = 1;
/**
* INDICATOR
*/
private int indicatorStyle = INDICATE_ARROW_ROUND_STYLE;
/**
*
*/
private long refreshTime = 0l;
/**
* 广
*/
public interface OnItemChangeListener {
void onPosition(int position, int totalCount);
}
/**
*
*/
public interface OnItemClickListener {
void OnItemClick(View view, int position);
}
public ImageIndicatorView(Context context, AttributeSet attrs) {
super(context, attrs);
this.init(context);
}
public ImageIndicatorView(Context context) {
super(context);
this.init(context);
}
/**
* @param context
*/
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.image_indicator_layout, this);
this.viewPager = (ViewPager) findViewById(R.id.view_pager);
this.indicateLayout = (LinearLayout) findViewById(R.id.indicater_layout);
this.leftButton = (Button) findViewById(R.id.left_button);
this.rightButton = (Button) findViewById(R.id.right_button);
this.leftButton.setVisibility(View.GONE);
this.rightButton.setVisibility(View.GONE);
this.viewPager.setOnPageChangeListener(new PageChangeListener());
final ArrowClickListener arrowClickListener = new ArrowClickListener();
this.leftButton.setOnClickListener(arrowClickListener);
this.rightButton.setOnClickListener(arrowClickListener);
this.refreshHandler = new ScrollIndicateHandler(ImageIndicatorView.this);
}
/**
* ViewPager
*
* @return
*/
public ViewPager getViewPager() {
return viewPager;
}
/**
* Index
*/
public int getCurrentIndex() {
return this.currentIndex;
}
/**
* VIEW
*/
public int getTotalCount() {
return this.totelCount;
}
/**
*
*/
public long getRefreshTime() {
return this.refreshTime;
}
/**
* View
*
* @param view
*/
public void addViewItem(View view) {
final int position = viewList.size();
view.setOnClickListener(new ItemClickListener(position));
this.viewList.add(view);
}
/**
*
*/
private class ItemClickListener implements View.OnClickListener {
private int position = 0;
public ItemClickListener(int position) {
this.position = position;
}
@Override
public void onClick(View view) {
if (onItemClickListener != null) {
onItemClickListener.OnItemClick(view, position);
}
}
}
/**
* Drawable
*
* @param resArray
* Drawable
*/
public void setupLayoutByDrawable(final Integer resArray[]) {
if (resArray == null)
throw new NullPointerException();
this.setupLayoutByDrawable(Arrays.asList(resArray));
}
/**
* Drawable
*
* @param resList
* Drawable
*/
public void setupLayoutByDrawable(final List<Integer> resList) {
if (resList == null)
throw new NullPointerException();
final int len = resList.size();
if (len > 0) {
for (int index = 0; index < len; index++) {
final View pageItem = new ImageView(getContext());
pageItem.setBackgroundResource(resList.get(index));
addViewItem(pageItem);
}
}
}
/**
*
*
* @param index
* postion
*/
public void setCurrentItem(int index) {
this.currentIndex = index;
}
/**
* INDICATOR_ARROW_ROUND_STYLE
*
* @param style
* INDICATOR_USERGUIDE_STYLEINDICATOR_ARROW_ROUND_STYLE
*/
public void setIndicateStyle(int style) {
this.indicatorStyle = style;
}
/**
*
*
* @param onGuideListener
*/
public void setOnItemChangeListener(OnItemChangeListener onItemChangeListener) {
if (onItemChangeListener == null) {
throw new NullPointerException();
}
this.onItemChangeListener = onItemChangeListener;
}
/**
*
*
* @param onItemClickListener
*/
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
/**
*
*/
public void show() {
this.totelCount = viewList.size();
final LayoutParams params = (LayoutParams) indicateLayout.getLayoutParams();
if (INDICATE_USERGUIDE_STYLE == this.indicatorStyle) {// 操作指引
params.bottomMargin = 45;
}
this.indicateLayout.setLayoutParams(params);
// 初始化指示器
for (int index = 0; index < this.totelCount; index++) {
final View indicater = new ImageView(getContext());
this.indicateLayout.addView(indicater, index);
}
this.refreshHandler.sendEmptyMessage(currentIndex);
// 为ViewPager配置数据
this.viewPager.setAdapter(new MyPagerAdapter(this.viewList));
this.viewPager.setCurrentItem(currentIndex, false);
}
/**
*
*/
private class ArrowClickListener implements View.OnClickListener {
@Override
public void onClick(View view) {
if (view == leftButton) {
if (currentIndex >= (totelCount - 1)) {
return;
} else {
viewPager.setCurrentItem(currentIndex + 1, true);
}
} else {
if (totelCount <= 0) {
return;
} else {
viewPager.setCurrentItem(currentIndex - 1, true);
}
}
}
}
/**
*
*/
private class PageChangeListener implements OnPageChangeListener {
@Override
public void onPageSelected(int index) {
currentIndex = index;
refreshHandler.sendEmptyMessage(index);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
}
/**
*
*/
protected void refreshIndicateView() {
this.refreshTime = System.currentTimeMillis();
for (int index = 0; index < totelCount; index++) {
final ImageView imageView = (ImageView) this.indicateLayout.getChildAt(index);
if (this.currentIndex == index) {
imageView.setBackgroundResource(R.drawable.image_indicator_focus);
} else {
imageView.setBackgroundResource(R.drawable.image_indicator);
}
}
if (INDICATE_USERGUIDE_STYLE == this.indicatorStyle) {// 操作指引不显示箭头
this.leftButton.setVisibility(View.GONE);
this.rightButton.setVisibility(View.GONE);
} else {// 显示箭头各状态
if (totelCount <= 1) {
leftButton.setVisibility(View.GONE);
rightButton.setVisibility(View.GONE);
} else if (totelCount == 2) {
if (currentIndex == 0) {
leftButton.setVisibility(View.VISIBLE);
rightButton.setVisibility(View.GONE);
} else {
leftButton.setVisibility(View.GONE);
rightButton.setVisibility(View.VISIBLE);
}
} else {
if (currentIndex == 0) {
leftButton.setVisibility(View.VISIBLE);
rightButton.setVisibility(View.GONE);
} else if (currentIndex == (totelCount - 1)) {
leftButton.setVisibility(View.GONE);
rightButton.setVisibility(View.VISIBLE);
} else {
leftButton.setVisibility(View.VISIBLE);
rightButton.setVisibility(View.VISIBLE);
}
}
}
if (this.onItemChangeListener != null) {// 页面改更了
try {
this.onItemChangeListener.onPosition(this.currentIndex, this.totelCount);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class MyPagerAdapter extends PagerAdapter {
private List<View> pageViews = new ArrayList<View>();
public MyPagerAdapter(List<View> pageViews) {
this.pageViews = pageViews;
}
@Override
public int getCount() {
return pageViews.size();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public int getItemPosition(Object object) {
return super.getItemPosition(object);
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView(pageViews.get(arg1));
}
@Override
public Object instantiateItem(View arg0, int arg1) {
((ViewPager) arg0).addView(pageViews.get(arg1));
return pageViews.get(arg1);
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {
}
@Override
public void finishUpdate(View arg0) {
}
}
}
class ScrollIndicateHandler extends Handler {
private ImageIndicatorView scrollIndicateView;
public ScrollIndicateHandler(ImageIndicatorView scrollIndicateView) {
this.scrollIndicateView = scrollIndicateView;
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (this.scrollIndicateView != null) {
scrollIndicateView.refreshIndicateView();
}
}
}
package com.allthelucky.common.view;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.app.library.common.view.R;
/**
* ,(Gallery)
*
* @author savant-pan
*
*/
public class ImageIndicatorView extends RelativeLayout {
/**
* ViewPager
*/
private ViewPager viewPager;
/**
*
*/
private LinearLayout indicateLayout;
/**
*
*/
private Button leftButton;
/**
*
*/
private Button rightButton;
/**
*
*/
private List<View> viewList = new ArrayList<View>();
private Handler refreshHandler;
/**
*
*/
private OnItemChangeListener onItemChangeListener;
/**
*
*/
private OnItemClickListener onItemClickListener;
/**
*
*/
private int totelCount = 0;
/**
*
*/
private int currentIndex = 0;
/**
* +
*/
public static final int INDICATE_ARROW_ROUND_STYLE = 0;
/**
*
*/
public static final int INDICATE_USERGUIDE_STYLE = 1;
/**
* INDICATOR
*/
private int indicatorStyle = INDICATE_ARROW_ROUND_STYLE;
/**
*
*/
private long refreshTime = 0l;
/**
* 广
*/
public interface OnItemChangeListener {
void onPosition(int position, int totalCount);
}
/**
*
*/
public interface OnItemClickListener {
void OnItemClick(View view, int position);
}
public ImageIndicatorView(Context context, AttributeSet attrs) {
super(context, attrs);
this.init(context);
}
public ImageIndicatorView(Context context) {
super(context);
this.init(context);
}
/**
* @param context
*/
private void init(Context context) {
LayoutInflater.from(context).inflate(R.layout.image_indicator_layout, this);
this.viewPager = (ViewPager) findViewById(R.id.view_pager);
this.indicateLayout = (LinearLayout) findViewById(R.id.indicater_layout);
this.leftButton = (Button) findViewById(R.id.left_button);
this.rightButton = (Button) findViewById(R.id.right_button);
this.leftButton.setVisibility(View.GONE);
this.rightButton.setVisibility(View.GONE);
this.viewPager.setOnPageChangeListener(new PageChangeListener());
final ArrowClickListener arrowClickListener = new ArrowClickListener();
this.leftButton.setOnClickListener(arrowClickListener);
this.rightButton.setOnClickListener(arrowClickListener);
this.refreshHandler = new ScrollIndicateHandler(ImageIndicatorView.this);
}
/**
* ViewPager
*
* @return
*/
public ViewPager getViewPager() {
return viewPager;
}
/**
* Index
*/
public int getCurrentIndex() {
return this.currentIndex;
}
/**
* VIEW
*/
public int getTotalCount() {
return this.totelCount;
}
/**
*
*/
public long getRefreshTime() {
return this.refreshTime;
}
/**
* View
*
* @param view
*/
public void addViewItem(View view) {
final int position = viewList.size();
view.setOnClickListener(new ItemClickListener(position));
this.viewList.add(view);
}
/**
*
*/
private class ItemClickListener implements View.OnClickListener {
private int position = 0;
public ItemClickListener(int position) {
this.position = position;
}
@Override
public void onClick(View view) {
if (onItemClickListener != null) {
onItemClickListener.OnItemClick(view, position);
}
}
}
/**
* Drawable
*
* @param resArray
* Drawable
*/
public void setupLayoutByDrawable(final Integer resArray[]) {
if (resArray == null)
throw new NullPointerException();
this.setupLayoutByDrawable(Arrays.asList(resArray));
}
/**
* Drawable
*
* @param resList
* Drawable
*/
public void setupLayoutByDrawable(final List<Integer> resList) {
if (resList == null)
throw new NullPointerException();
final int len = resList.size();
if (len > 0) {
for (int index = 0; index < len; index++) {
final View pageItem = new ImageView(getContext());
pageItem.setBackgroundResource(resList.get(index));
addViewItem(pageItem);
}
}
}
/**
*
*
* @param index
* postion
*/
public void setCurrentItem(int index) {
this.currentIndex = index;
}
/**
* INDICATOR_ARROW_ROUND_STYLE
*
* @param style
* INDICATOR_USERGUIDE_STYLEINDICATOR_ARROW_ROUND_STYLE
*/
public void setIndicateStyle(int style) {
this.indicatorStyle = style;
}
/**
*
*
* @param onGuideListener
*/
public void setOnItemChangeListener(OnItemChangeListener onItemChangeListener) {
if (onItemChangeListener == null) {
throw new NullPointerException();
}
this.onItemChangeListener = onItemChangeListener;
}
/**
*
*
* @param onItemClickListener
*/
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
/**
*
*/
public void show() {
this.totelCount = viewList.size();
final LayoutParams params = (LayoutParams) indicateLayout.getLayoutParams();
if (INDICATE_USERGUIDE_STYLE == this.indicatorStyle) {// 操作指引
params.bottomMargin = 45;
}
this.indicateLayout.setLayoutParams(params);
// 初始化指示器
for (int index = 0; index < this.totelCount; index++) {
final View indicater = new ImageView(getContext());
this.indicateLayout.addView(indicater, index);
}
this.refreshHandler.sendEmptyMessage(currentIndex);
// 为ViewPager配置数据
this.viewPager.setAdapter(new MyPagerAdapter(this.viewList));
this.viewPager.setCurrentItem(currentIndex, false);
}
/**
*
*/
private class ArrowClickListener implements View.OnClickListener {
@Override
public void onClick(View view) {
if (view == leftButton) {
if (currentIndex >= (totelCount - 1)) {
return;
} else {
viewPager.setCurrentItem(currentIndex + 1, true);
}
} else {
if (totelCount <= 0) {
return;
} else {
viewPager.setCurrentItem(currentIndex - 1, true);
}
}
}
}
/**
*
*/
private class PageChangeListener implements OnPageChangeListener {
@Override
public void onPageSelected(int index) {
currentIndex = index;
refreshHandler.sendEmptyMessage(index);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
}
/**
*
*/
protected void refreshIndicateView() {
this.refreshTime = System.currentTimeMillis();
for (int index = 0; index < totelCount; index++) {
final ImageView imageView = (ImageView) this.indicateLayout.getChildAt(index);
if (this.currentIndex == index) {
imageView.setBackgroundResource(R.drawable.image_indicator_focus);
} else {
imageView.setBackgroundResource(R.drawable.image_indicator);
}
}
if (INDICATE_USERGUIDE_STYLE == this.indicatorStyle) {// 操作指引不显示箭头
this.leftButton.setVisibility(View.GONE);
this.rightButton.setVisibility(View.GONE);
} else {// 显示箭头各状态
if (totelCount <= 1) {
leftButton.setVisibility(View.GONE);
rightButton.setVisibility(View.GONE);
} else if (totelCount == 2) {
if (currentIndex == 0) {
leftButton.setVisibility(View.VISIBLE);
rightButton.setVisibility(View.GONE);
} else {
leftButton.setVisibility(View.GONE);
rightButton.setVisibility(View.VISIBLE);
}
} else {
if (currentIndex == 0) {
leftButton.setVisibility(View.VISIBLE);
rightButton.setVisibility(View.GONE);
} else if (currentIndex == (totelCount - 1)) {
leftButton.setVisibility(View.GONE);
rightButton.setVisibility(View.VISIBLE);
} else {
leftButton.setVisibility(View.VISIBLE);
rightButton.setVisibility(View.VISIBLE);
}
}
}
if (this.onItemChangeListener != null) {// 页面改更了
try {
this.onItemChangeListener.onPosition(this.currentIndex, this.totelCount);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class MyPagerAdapter extends PagerAdapter {
private List<View> pageViews = new ArrayList<View>();
public MyPagerAdapter(List<View> pageViews) {
this.pageViews = pageViews;
}
@Override
public int getCount() {
return pageViews.size();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public int getItemPosition(Object object) {
return super.getItemPosition(object);
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView(pageViews.get(arg1));
}
@Override
public Object instantiateItem(View arg0, int arg1) {
((ViewPager) arg0).addView(pageViews.get(arg1));
return pageViews.get(arg1);
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {
}
@Override
public void finishUpdate(View arg0) {
}
}
}
class ScrollIndicateHandler extends Handler {
private ImageIndicatorView scrollIndicateView;
public ScrollIndicateHandler(ImageIndicatorView scrollIndicateView) {
this.scrollIndicateView = scrollIndicateView;
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (this.scrollIndicateView != null) {
scrollIndicateView.refreshIndicateView();
}
}
}

@ -34,15 +34,14 @@ public class AutoImageIndicatorActivity extends Activity {
private void initView() {
final Integer[] resArray = new Integer[] { R.drawable.poster1, R.drawable.poster2, R.drawable.poster3 };
this.autoImageIndicatorView.setupLayoutByDrawable(resArray);//图片
this.autoImageIndicatorView.setupLayoutByDrawable(resArray);
this.autoImageIndicatorView.show();
AutoPlayManager autoBrocastManager = new AutoPlayManager(this.autoImageIndicatorView);
autoBrocastManager.setBroadcastEnable(true);
autoBrocastManager.setBroadCastTimes(5);//循环播放5
autoBrocastManager.setBroadcastTimeIntevel(3 * 1000, 3 * 1000);//播放启动时间及间隔
autoBrocastManager.setBroadCastTimes(5);//循环
autoBrocastManager.setBroadcastTimeIntevel(3 * 1000, 3 * 1000);//首次启动时间及间隔
autoBrocastManager.loop();
}
}

@ -5,31 +5,26 @@ Android image indicator for user guide or auto broadcast effect.
Style 1:
----------------------
common mode:
common mode:
<com.allthelucky.common.view.ImageIndicatorView
android:id="@+id/indicate_view"
android:layout_width="match_parent"
android:layout_height="160dp" />
set ImageIndicatorView as:
imageIndicatorView = (ImageIndicatorView) findViewById(R.id.indicate_view);
final Integer[] resArray = new Integer[] { R.drawable.ic_launcher, R.drawable.ic_launcher };
imageIndicatorView.setupLayoutByDrawable(resArray);
imageIndicatorView.show();
broadcast mode:
set ImageIndicatorView as:
AutoPlayManager autoBrocastManager = new AutoPlayManager(this.autoImageIndicatorView);
autoBrocastManager.setBroadcastEnable(true);
autoBrocastManager.setBroadCastTimes(5);//循环次数
autoBrocastManager.setBroadcastTimeIntevel(3 * 1000, 3 * 1000);//首次启动时间及间隔
autoBrocastManager.loop();
broadcast mode:
<com.allthelucky.common.view.AutoImageIndicatorView
android:id="@+id/auto_indicate_view"
android:layout_width="match_parent"
android:layout_height="160dp" />
set AutoImageIndicatorView as:
set AutoImageIndicatorView as:
autoImageIndicatorView = (AutoImageIndicatorView) findViewById(R.id.auto_indicate_view);
final Integer[] resArray = new Integer[] { R.drawable.ic_launcher, R.drawable.ic_launcher };
autoImageIndicatorView.setBroadcastEnable(true);
@ -40,23 +35,19 @@ set AutoImageIndicatorView as:
![ScreenShot](https://raw.github.com/winfirm/android-image-indicator/master/AndroidImageIndicatorSample/screenshot/poster0.jpg)
Style2(user guide mode):
----------------------
Style2(user guide mode):
<com.allthelucky.common.view.ImageIndicatorView
android:id="@+id/guide_indicate_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
set ImageIndicatorView as:
set ImageIndicatorView as:
this.imageIndicatorView = (ImageIndicatorView) findViewById(R.id.guide_indicate_view);
final Integer[] resArray = new Integer[] { R.drawable.ic_launcher, R.drawable.ic_launcher };
imageIndicatorView.setupLayoutByDrawable(resArray);
imageIndicatorView.setIndicateStyle(ImageIndicatorView.INDICATE_USERGUIDE_STYLE);
imageIndicatorView.show();
![ScreenShot](https://raw.github.com/winfirm/android-image-indicator/master/AndroidImageIndicatorSample/screenshot/guider_00.jpg)
![ScreenShot](https://raw.github.com/winfirm/android-image-indicator/master/AndroidImageIndicatorSample/screenshot/guider_00.jpg)
![ScreenShot](https://raw.github.com/winfirm/android-image-indicator/master/AndroidImageIndicatorSample/screenshot/guider_01.jpg)

Loading…
Cancel
Save