-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
045b73c
commit 68ba983
Showing
2 changed files
with
92 additions
and
9 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...n/java/net/lucode/hackware/magicindicatordemo/example/CustomNavigatorExampleActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,83 @@ | ||
package net.lucode.hackware.magicindicatordemo.example; | ||
|
||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import net.lucode.hackware.magicindicator.MagicIndicator; | ||
import net.lucode.hackware.magicindicator.ViewPagerHelper; | ||
import net.lucode.hackware.magicindicator.buildins.circlenavigator.CircleNavigator; | ||
import net.lucode.hackware.magicindicatordemo.R; | ||
import net.lucode.hackware.magicindicatordemo.ext.navigator.ScaleCircleNavigator; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class CustomNavigatorExampleActivity extends AppCompatActivity { | ||
private static final String[] CHANNELS = new String[]{"CUPCAKE", "DONUT", "ECLAIR", "GINGERBREAD", "HONEYCOMB", "ICE_CREAM_SANDWICH", "JELLY_BEAN", "KITKAT", "LOLLIPOP", "M", "NOUGAT"}; | ||
private List<String> mDataList = Arrays.asList(CHANNELS); | ||
private ExamplePagerAdapter mExamplePagerAdapter = new ExamplePagerAdapter(mDataList); | ||
|
||
private ViewPager mViewPager; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_custom_navigator_example_layout); | ||
|
||
mViewPager = (ViewPager) findViewById(R.id.view_pager); | ||
mViewPager.setAdapter(mExamplePagerAdapter); | ||
|
||
initMagicIndicator1(); | ||
initMagicIndicator2(); | ||
initMagicIndicator3(); | ||
} | ||
|
||
private void initMagicIndicator1() { | ||
MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator1); | ||
CircleNavigator circleNavigator = new CircleNavigator(this); | ||
circleNavigator.setCircleCount(CHANNELS.length); | ||
circleNavigator.setCircleColor(Color.RED); | ||
circleNavigator.setCircleClickListener(new CircleNavigator.OnCircleClickListener() { | ||
@Override | ||
public void onClick(int index) { | ||
mViewPager.setCurrentItem(index); | ||
} | ||
}); | ||
magicIndicator.setNavigator(circleNavigator); | ||
ViewPagerHelper.bind(magicIndicator, mViewPager); | ||
} | ||
|
||
private void initMagicIndicator2() { | ||
MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator2); | ||
CircleNavigator circleNavigator = new CircleNavigator(this); | ||
circleNavigator.setFollowTouch(false); | ||
circleNavigator.setCircleCount(CHANNELS.length); | ||
circleNavigator.setCircleColor(Color.RED); | ||
circleNavigator.setCircleClickListener(new CircleNavigator.OnCircleClickListener() { | ||
@Override | ||
public void onClick(int index) { | ||
mViewPager.setCurrentItem(index); | ||
} | ||
}); | ||
magicIndicator.setNavigator(circleNavigator); | ||
ViewPagerHelper.bind(magicIndicator, mViewPager); | ||
} | ||
|
||
private void initMagicIndicator3() { | ||
MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator3); | ||
ScaleCircleNavigator scaleCircleNavigator = new ScaleCircleNavigator(this); | ||
scaleCircleNavigator.setCircleCount(CHANNELS.length); | ||
scaleCircleNavigator.setNormalCircleColor(Color.LTGRAY); | ||
scaleCircleNavigator.setSelectedCircleColor(Color.DKGRAY); | ||
scaleCircleNavigator.setCircleClickListener(new ScaleCircleNavigator.OnCircleClickListener() { | ||
@Override | ||
public void onClick(int index) { | ||
mViewPager.setCurrentItem(index); | ||
} | ||
}); | ||
magicIndicator.setNavigator(scaleCircleNavigator); | ||
ViewPagerHelper.bind(magicIndicator, mViewPager); | ||
} | ||
} |
33 changes: 24 additions & 9 deletions
33
app/src/main/res/layout/activity_custom_navigator_example_layout.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/activity_custom_navigator_example" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context="net.lucode.hackware.magicindicatordemo.example.CustomNavigatorExampleActivity"> | ||
|
||
<TextView | ||
<android.support.v4.view.ViewPager | ||
android:id="@+id/view_pager" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
<net.lucode.hackware.magicindicator.MagicIndicator | ||
android:id="@+id/magic_indicator1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="@dimen/common_navigator_height" | ||
android:layout_alignParentBottom="true" | ||
android:layout_centerHorizontal="true" /> | ||
|
||
<net.lucode.hackware.magicindicator.MagicIndicator | ||
android:id="@+id/magic_indicator2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="@dimen/common_navigator_height" | ||
android:layout_above="@+id/magic_indicator1" | ||
android:layout_centerHorizontal="true" /> | ||
|
||
<net.lucode.hackware.magicindicator.MagicIndicator | ||
android:id="@+id/magic_indicator3" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true" | ||
android:text="coming soon!" /> | ||
android:layout_height="@dimen/common_navigator_height" | ||
android:layout_above="@id/magic_indicator2" | ||
android:layout_centerHorizontal="true" /> | ||
|
||
</RelativeLayout> |