Git Product home page Git Product logo

inkpageindicator's Introduction

InkPageIndicator

Android Arsenal Platform API Download GitHub license

InkPageIndicator created by @nickbutcher for Plaid https://github.com/nickbutcher/plaid and backported by me for API 14+ (4.0+)

InkPageIndicator Preview

Usage

dependencies {
    implementation 'com.pacioianu.david:ink-page-indicator:1.3.0'
}
<com.pixelcan.inkpageindicator.InkPageIndicator
  android:id="@+id/indicator"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"/>

and

InkPageIndicator inkPageIndicator = (InkPageIndicator) findViewById(R.id.indicator);
inkPageIndicator.setViewPager(viewPager);

Custom attributes:

<com.pixelcan.inkpageindicator.InkPageIndicator
  android:id="@+id/indicator"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:ipi_dotDiameter="8dp"
  app:ipi_dotGap="8dp"
  app:ipi_animationDuration="320"
  app:ipi_pageIndicatorColor="@android:color/darker_gray"
  app:ipi_currentPageIndicatorColor="@android:color/black"/>

Note: Starting from version 1.3.0 we added the ipi_ prefix to the name of the attributes.

License

Copyright 2018 David Păcioianu

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

inkpageindicator's People

Contributors

adipascu avatar alashow avatar alexia8 avatar ankitpopli1891 avatar avjinder avatar davidpacioianu avatar jawnnypoo avatar vedant1811 avatar williamgueiros avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

inkpageindicator's Issues

Issue on pre-lollipop

There's an animation bug with this on pre-lollipop where the dot to the right side disappears during the transition.

See: http://webmshare.com/dLEEL

I think it's due to the change to addPath, which I don't think it a like-for-like equivelant to Path.Op.UNION.

Crash in library when last element in view pager is deleted

In my project, I have to support the view pager being updated such that any page in it can be deleted.

The InkPageIndicator library crashes when I delete the final page with an ArrayIndexOutOfBoundsException

It looks like maybe dotsToHide isn't being updated at the right time and is always expecting 1 more than it has access to after deleting.

java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 at com.pixelcan.inkpageindicator.InkPageIndicator.setDotRevealFraction(InkPageIndicator.java:655) at com.pixelcan.inkpageindicator.InkPageIndicator.access$1600(InkPageIndicator.java:47) at com.pixelcan.inkpageindicator.InkPageIndicator$PendingRetreatAnimator$3.onAnimationStart(InkPageIndicator.java:765) at android.animation.ValueAnimator.notifyStartListeners(ValueAnimator.java:981) at android.animation.ValueAnimator.start(ValueAnimator.java:1043) at android.animation.ValueAnimator.start(ValueAnimator.java:1050) at com.pixelcan.inkpageindicator.InkPageIndicator$PendingStartAnimator.startIfNecessary(InkPageIndicator.java:681) at com.pixelcan.inkpageindicator.InkPageIndicator$3.onAnimationUpdate(InkPageIndicator.java:610) at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1374) at android.animation.ValueAnimator.animationFrame(ValueAnimator.java:1298) at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1339) at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:715) at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:738) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:549) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

App crashes when calling setCurrentItem to newly added view to adapter.

Hi,
Thank you so much for this wonderful library. It is very useful and has helped me immensely.

But I found an issue with using setCurrentItem on my viewPager.
Here is the flow :

I have initialized the ViewPager, PagerAdapter and InkPageIndicator
testAdapter = new SimplePagerAdapter(testList);
testPager.setAdapter(testAdapter);
testIndicator.setViewPager(testPager);

Then I add few views to testList and call notifyDataSetChanged on testAdapter.
(Which internally calls setPageCount and pageCount gets initialized correctly, which internally calls requestLayout , which would be called on next idle cycle)
testList.add(newView);
testPager.getAdapter().notifyDataSetChanged();

Then I immediately call setCurrentItem(newViewIndex, false);
which calls setPageSelected inline which calls setSelectedPage. setSelectedPage tries to call
createMoveSelectedAnimator but dotCenterX doesn't contain newly added view's dot's X value. This is because calculateDotPositions isn't called as yet since onMeasure is not called as yet and is waiting to be called in idle cycle.

Could you please give me a suggestion on how can I fix this. I would create the patch and create pull request for the same.

Next Selected dot is shown for a frame just before animation starts

It is very hard to notice, but it gives a bad overall impression:

When animating from position 1 to position 2, the dot is supposed to move (i.e. animate) from position 1 to position 2. But if you look carefully, for a split second a dot (with the selected color) appears at position 2 and then vanishes; and then the animation takes place as expected.

Works well with API level below 16

Not exactly an issue.

But most of the new apps in India are targeting API 15 or above.

And this can be made compatible with API 14 and above by replacing:

postInvalidateOnAnimation() with

'ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this)'

When retreating from dot x to dot x-1, dot x-2 flashes

UPDATE: This seems to be an issue when using a custom ViewPager. When using a generic ViewPager it does not happen.

Hi, I have noticed this issue both on Lollipop and Nougat devices. When scrolling a viewpager backwards, eg. when scrolling from page 6 to page 5, I notice that as soon as the animations complete, dot 4 flashes. This happens on all page scrolls from right to left, but not the other way around. So, scrolling from page 5 to page 6 doesn't have this issue.

Maybe this is a simple fix of not including that dot in the ones to be redrawn, but I'm not sure what part of the code I need to touch for this.

align bottom

Would be nice to be able to set the gravity to bottom too.

The test app does not work if count of items in the Adapter is increased (more then 30)

Hi There,

The test app does not work if coun of items in the Adapter is slightly increase. Make it more then 30.
The log I am seeing is like

19 08-24 16:01:42.345 F 23570 23570 DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
20 08-24 16:01:42.345 F 23570 23570 DEBUG   : Build fingerprint: google/shamu/shamu:7.1.1/N6F27I/4118426:user/release-keys
21 08-24 16:01:42.345 F 23570 23570 DEBUG   : Revision: 0
22 08-24 16:01:42.345 F 23570 23570 DEBUG   : ABI: arm
23 08-24 16:01:42.345 F 23570 23570 DEBUG   : pid: 22397, tid: 22440, name: hwuiTask1 >>> com.pixelcan.ipidemo <<<
24 08-24 16:01:42.346 F 23570 23570 DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
25 08-24 16:01:42.349 F 23570 23570 DEBUG   : r0 00000000 r1 000057a8 r2 00000006 r3 00000008
26 08-24 16:01:42.349 F 23570 23570 DEBUG   : r4 8e16f978 r5 00000006 r6 8e16f920 r7 0000010c
27 08-24 16:01:42.349 F 23570 23570 DEBUG   : r8 8e16d6d8 r9 8e16d490 sl 8e16d628 fp 8e16d7b0
28 08-24 16:01:42.349 F 23570 23570 DEBUG   : ip 0000000c sp 8e16d358 lr b067a5c7 pc b067ce30 cpsr 600f0010
29 08-24 16:01:42.372 F 23570 23570 DEBUG   :
30 08-24 16:01:42.372 F 23570 23570 DEBUG   : backtrace:
31 08-24 16:01:42.372 F 23570 23570 DEBUG   : #00 pc 00049e30 /system/lib/libc.so (tgkill+12)
32 08-24 16:01:42.372 F 23570 23570 DEBUG   : #1 pc 000475c3 /system/lib/libc.so (pthread_kill+34)
33 08-24 16:01:42.373 F 23570 23570 DEBUG   : #2 pc 0001d635 /system/lib/libc.so (raise+10)
34 08-24 16:01:42.373 F 23570 23570 DEBUG   : #3 pc 00019181 /system/lib/libc.so (__libc_android_abort+34)
35 08-24 16:01:42.373 F 23570 23570 DEBUG   : #4 pc 00017048 /system/lib/libc.so (abort+4)
36 08-24 16:01:42.373 F 23570 23570 DEBUG   : #5 pc 002afccd /system/lib/libskia.so (_Z15sk_malloc_flagsjj+28)
37 08-24 16:01:42.373 F 23570 23570 DEBUG   : #6 pc 0013c6d7 /system/lib/libskia.so (_ZN12SkChunkAlloc8newBlockEjNS_13AllocFailTypeE+26)
38 08-24 16:01:42.373 F 23570 23570 DEBUG   : #7 pc 0013c707 /system/lib/libskia.so (_ZN12SkChunkAlloc19addBlockIfNecessaryEjNS_13AllocFailTypeE+18)
39 08-24 16:01:42.373 F 23570 23570 DEBUG   : #8 pc 0013c727 /system/lib/libskia.so (_ZN12SkChunkAlloc5allocEjNS_13AllocFailTypeE+14)
40 08-24 16:01:42.373 F 23570 23570 DEBUG   : #9 pc 00149eb7 /system/lib/libskia.so (_ZN13SkEdgeBuilder7addQuadEPK7SkPoint+10)
41 08-24 16:01:42.373 F 23570 23570 DEBUG   : #10 pc 0014a667 /system/lib/libskia.so
42 08-24 16:01:42.373 F 23570 23570 DEBUG   : #11 pc 0014a557 /system/lib/libskia.so (_ZN13SkEdgeBuilder5buildERK6SkPathPK7SkIRectib+406)
43 08-24 16:01:42.373 F 23570 23570 DEBUG   : #12 pc 0019139b /system/lib/libskia.so (_Z12sk_fill_pathRK6SkPathPK7SkIRectP9SkBlitteriiiRK8SkRegion+62)
44 08-24 16:01:42.373 F 23570 23570 DEBUG   : #13 pc 0018e03b /system/lib/libskia.so (_ZN6SkScan12AntiFillPathERK6SkPathRK8SkRegionP9SkBlitterb+682)
45 08-24 16:01:42.373 F 23570 23570 DEBUG   : #14 pc 0014679b /system/lib/libskia.so (_ZNK6SkDraw8drawPathERK6SkPathRK7SkPaintPK8SkMatrixbbP9SkBlitter+678)
46 08-24 16:01:42.373 F 23570 23570 DEBUG   : #15 pc 001275cf /system/lib/libskia.so (_ZN14SkBitmapDevice8drawPathERK6SkDrawRK6SkPathRK7SkPaintPK8SkMatrixb+30)
47 08-24 16:01:42.373 F 23570 23570 DEBUG   : #16 pc 0013956b /system/lib/libskia.so (_ZN8SkCanvas10onDrawPathERK6SkPathRK7SkPaint+370)
48 08-24 16:01:42.373 F 23570 23570 DEBUG   : #17 pc 000485c3 /system/lib/libhwui.so
49 08-24 16:01:42.373 F 23570 23570 DEBUG   : #18 pc 000488bb /system/lib/libhwui.so
50 08-24 16:01:42.373 F 23570 23570 DEBUG   : #19 pc 00025087 /system/lib/libhwui.so
51 08-24 16:01:42.373 F 23570 23570 DEBUG   : #20 pc 000299d1 /system/lib/libhwui.so
52 08-24 16:01:42.373 F 23570 23570 DEBUG   : #21 pc 0000e3a3 /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+270)
53 08-24 16:01:42.374 F 23570 23570 DEBUG   : #22 pc 00067d21 /system/lib/libandroid_runtime.so (_ZN7android14AndroidRuntime15javaThreadShellEPv+80)
54 08-24 16:01:42.374 F 23570 23570 DEBUG   : #23 pc 00047093 /system/lib/libc.so (_ZL15__pthread_startPv+22)
55 08-24 16:01:42.374 F 23570 23570 DEBUG   : #24 pc 00019bdd /system/lib/libc.so (__start_thread+6)

Dot disappears when you begin to scroll to left but stop

Step to reproduce:

Create a ViewPager with 3 pages.
Go to the second page.
Begin to scroll to the first page, but stop the movement so that you actually stay on the second.
The first dot disappears.

The bug doesn't show when you slide to right.

No support for AndroidX

I have just migrated to AndroidX and I can't compile my app because InkPageIndicator uses ViewPager from android design support library

Save PageIndicator state

Basically, just add

@Override
  public void onRestoreInstanceState(Parcelable state) {
    SavedState savedState = (SavedState)state;
    super.onRestoreInstanceState(savedState.getSuperState());
    currentPage = savedState.currentPage;
    requestLayout();
  }

  @Override
  public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    SavedState savedState = new SavedState(superState);
    savedState.currentPage = currentPage;
    return savedState;
  }

  static class SavedState extends BaseSavedState {
    int currentPage;

    public SavedState(Parcelable superState) {
      super(superState);
    }

    private SavedState(Parcel in) {
      super(in);
      currentPage = in.readInt();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
      super.writeToParcel(dest, flags);
      dest.writeInt(currentPage);
    }

    @SuppressWarnings("UnusedDeclaration")
    public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>() {
      @Override
      public SavedState createFromParcel(Parcel in) {
        return new SavedState(in);
      }

      @Override
      public SavedState[] newArray(int size) {
        return new SavedState[size];
      }
    };
  }

Change indicator colors

Is there a way to change the pageIndicatorColor and the currentPageIndicatorColor programmatically?
Thanks

Manifest merger failed

Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute application@label value=(Kapt Issue) from AndroidManifest.xml:6:9-35
is also present at [com.pacioianu.david:ink-page-indicator:1.2.0] AndroidManifest.xml:12:9-41 value=(@string/app_name).
Suggestion: add 'tools:replace="android:label"' to element at AndroidManifest.xml:4:5-14:19 to override.

It become too slow when I add much page.

In sample app, when I add 20 pages, it become very very slow and completely unusable.
I found it's caused by a line code in InkPageIndicator.drawUnselected(Canvas canvas).
......
// draw any settled, revealing or joining dots
for (int page = 0; page < pageCount; page++) {
int nextXIndex = page == pageCount - 1 ? page : page + 1;
Path unselectedPath = getUnselectedPath(page,
dotCenterX[page],
dotCenterX[nextXIndex],
page == pageCount - 1 ? INVALID_FRACTION : joiningFractions[page],
dotRevealFractions[page]);
unselectedPath.addPath(combinedUnselectedPath);
combinedUnselectedPath.addPath(unselectedPath);
}
......

I don't known why the bold line is need there? but when I delete it, this issue disappeared.
the bold line and the under line, seem will add some circle paths to the final draw path very much times, so it cause this issue.

Please pardon my poor english!

Page count could be zero which causes crash

I was working on dynamic view pager. Since the library is listening to the adapter changes, i notice that there is a function called reset state where the pageCount - 1 should handle properly as the page count could go to zero.

Null Pointer Exception on Android 4

Hi,

I have many reports of NPE on devices running Android 4. I couldn't figure out the origin of the problem since I cannot reproduce it. Below the stack trace. Any idea?

java.lang.NullPointerException: 
  at com.pixelcan.inkpageindicator.InkPageIndicator.a (InkPageIndicator.java:338)
  at com.pixelcan.inkpageindicator.InkPageIndicator.onDraw (InkPageIndicator.java:327)
  at android.view.View.draw (View.java:14629)
  at android.view.View.getDisplayList (View.java:13523)
  at android.view.View.getDisplayList (View.java:13565)
  at android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:3202)
  at android.view.View.getDisplayList (View.java:13460)
  at android.view.View.getDisplayList (View.java:13565)
  at android.view.View.draw (View.java:14343)
  at android.view.ViewGroup.drawChild (ViewGroup.java:3228)
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:3084)
  at android.view.View.draw (View.java:14632)
  at android.view.View.getDisplayList (View.java:13523)
  at android.view.View.getDisplayList (View.java:13565)
  at android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:3202)
  at android.view.View.getDisplayList (View.java:13460)
  at android.view.View.getDisplayList (View.java:13565)
  at android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:3202)
  at android.view.View.getDisplayList (View.java:13460)
  at android.view.View.getDisplayList (View.java:13565)
  at android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:3202)
  at android.view.View.getDisplayList (View.java:13460)
  at android.view.View.getDisplayList (View.java:13565)
  at android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:3202)
  at android.view.View.getDisplayList (View.java:13460)
  at android.view.View.getDisplayList (View.java:13565)
  at android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:3202)
  at android.view.View.getDisplayList (View.java:13460)
  at android.view.View.getDisplayList (View.java:13565)
  at android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:3202)
  at android.view.View.getDisplayList (View.java:13460)
  at android.view.View.getDisplayList (View.java:13565)
  at android.view.ViewGroup.dispatchGetDisplayList (ViewGroup.java:3202)
  at android.view.View.getDisplayList (View.java:13460)
  at android.view.View.getDisplayList (View.java:13565)
  at android.view.HardwareRenderer$GlRenderer.buildDisplayList (HardwareRenderer.java:1577)
  at android.view.HardwareRenderer$GlRenderer.draw (HardwareRenderer.java:1451)
  at android.view.ViewRootImpl.draw (ViewRootImpl.java:2398)
  at android.view.ViewRootImpl.performDraw (ViewRootImpl.java:2264)
  at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1892)
  at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1006)
  at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:5652)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:761)
  at android.view.Choreographer.doCallbacks (Choreographer.java:574)
  at android.view.Choreographer.doFrame (Choreographer.java:544)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:747)
  at android.os.Handler.handleCallback (Handler.java:733)
  at android.os.Handler.dispatchMessage (Handler.java:95)
  at android.os.Looper.loop (Looper.java:136)
  at android.app.ActivityThread.main (ActivityThread.java:5426)
  at java.lang.reflect.Method.invokeNative (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1268)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1084)
  at dalvik.system.NativeStart.main (Native Method

Add tags to custom library view attributes

In some cases, names of own attributes or attributes in other libraries can be equal with your library attributes. That's why resource merger could exit with an error while building. Like this:

Attribute "animationDuration" has already been defined

I propose you to add tags like pi_animationDuration to your attributes. That's might be helpful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.