Giter VIP home page Giter VIP logo

ticketview's Introduction

TicketView

An Android Library used to implement TicketView in android with normal, rounded and scallop corners.

Specs

API Maven Central License

Badges/Featured In

TicketView Android Arsenal AndroidDev Digest

showcase

Sample Project

For information : checkout Sample App Code in repository.

Download

TicketView on Google Play

Quick Setup

1. Include library

Using Gradle

dependencies {
    implementation 'com.vipulasri:ticketview:1.1.2'
}

What's New

See the project's Releases page for a list of versions with their change logs.

If you Watch this repository, GitHub will send you an email every time I publish an update.

2. Usage

  • In XML Layout :
<com.vipulasri.ticketview.TicketView
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:layout_marginTop="60dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:id="@+id/ticketView"
        app:ticketOrientation="vertical"
        app:ticketScallopRadius="10dp"
        app:ticketShowBorder="false"
        app:ticketScallopPositionPercent="50"
        app:ticketShowDivider="true"
        app:ticketDividerType="dash"
        app:ticketDividerPadding="0dp"
        app:ticketElevation="14dp"/>
  • Configure using xml attributes or setters in code:

    Attribute Name Default Value Description
    app:ticketOrientation="vertical" horizontal sets orientation of divider and scallop
    app:ticketBackgroundColor="@android:color/black" white sets background color
    app:ticketScallopRadius="10dp" 20dp sets scallop radius
    app:ticketScallopPositionPercent="50" 50 sets position of scallop and divider
    app:ticketShowBorder="false" false shows border if `true`
    app:ticketBorderWidth="4dp" 2dp sets border width
    app:ticketBorderColor="@color/grey" black sets border color
    app:ticketShowDivider="true" false shows divider if `true`
    app:ticketDividerType="dash" normal sets type of divider ie `normal` or `dash`
    app:ticketDividerColor="@color/colorAccent" dark gray sets divider color
    app:ticketDividerWidth="2dp" 2dp sets divider width
    app:ticketDividerPadding="0dp" 10dp sets divider padding
    app:ticketDividerDashGap="4dp" 4dp sets divider dash gap
    app:ticketDividerDashLength="8dp" 8dp sets divider dash length
    app:ticketCornerType="rounded" normal sets type of corner ie `normal` or `rounded` or `scallop`
    app:ticketCornerRadius="15dp" 4dp sets corner radius if corner rounder or scallop
    app:ticketElevation="14dp" 0dp sets elevation to ticket view on android jellybean and above
    app:ticketBackgroundBeforeDivider none sets background to ticket view before divider
    app:ticketBackgroundAfterDivider none sets background to ticket view after divider
    app:ticketShadowColor black sets shadow to ticket view

Apps that use this library

Apps using Ticket View, via AppBrain Stats

If you're using this library in your app and you'd like to list it here, Please let me know via email, pull requests or issues.

Special Thanks

Nick Butcher for helping me out with TicketView Shadow/Elevation.

License

Copyright 2017 Vipul Asri

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.

ticketview's People

Contributors

imanneo avatar nickbutcher avatar vaibhavbhandula avatar vipulasri 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ticketview's Issues

Render Problem

I have this Render Problem in the xml, i cant see the example of ticketview in the preview mode

java.lang.NoClassDefFoundError: Could not initialize class android.renderscript.RenderScript
at com.vipulasri.ticketview.TicketView.generateShadow(TicketView.java:272)
at com.vipulasri.ticketview.TicketView.doLayout(TicketView.java:254)
at com.vipulasri.ticketview.TicketView.onDraw_Original(TicketView.java:110)
at com.vipulasri.ticketview.TicketView.onDraw(TicketView.java)
at android.view.View.draw(View.java:19156)
at android.view.View.draw(View.java:19026)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4256)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:63)
at android.view.ViewGroup.drawChild(ViewGroup.java:4256)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4042)
at android.view.View.draw(View.java:19024)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4256)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:63)
at android.view.ViewGroup.drawChild(ViewGroup.java:4256)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4042)
at android.view.View.draw(View.java:19159)
at android.view.View.draw(View.java:19026)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4256)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:63)
at android.view.ViewGroup.drawChild(ViewGroup.java:4256)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4042)
at android.view.View.draw(View.java:19024)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:4256)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:63)
at android.view.ViewGroup.drawChild(ViewGroup.java:4256)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4042)
at android.view.View.draw(View.java:19159)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:403)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:541)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:424)
at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:108)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:154)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:136)
at com.android.tools.idea.rendering.RenderTask.lambda$renderInner$5(RenderTask.java:760)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Dynamic resize not working

I have a view which contains multiple textviews which will be "part of the ticket", but when I increase one of the textviews number of lines from 1 to 2, it works on the preview, but in real-time execution the resize doesn't work.

`
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.Toolbar
android:id="@+id/fakeToolbar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:backgroundTint="?attr/transparent"
android:elevation="1dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.08"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ticketPreviewLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?attr/darkBackgroundColor"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/fakeToolbar">

<com.vipulasri.ticketview.TicketView
  android:id="@+id/ticketView"
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_margin="16dp"
  android:elevation="4dp"
  app:layout_constraintBottom_toBottomOf="parent"
  app:layout_constraintEnd_toEndOf="parent"
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  app:ticketCornerRadius="4dp"
  app:ticketCornerType="rounded"
  app:ticketOrientation="vertical"
  app:ticketScallopRadius="12dp"/>

<TextView
  android:id="@+id/ticketValidity"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_marginStart="12dp"
  android:elevation="4dp"
  android:text="gültig in 110 • 1 Stunde"
  android:textColor="?attr/secondaryTextColor"
  android:textSize="16sp"
  app:layout_constraintBottom_toTopOf="@+id/ticketType"
  app:layout_constraintEnd_toStartOf="@+id/ticketPrice"
  app:layout_constraintStart_toStartOf="@id/ticketView"
  app:layout_constraintTop_toTopOf="@id/ticketPrice"
  app:layout_constraintVertical_bias="0" />

<TextView
  android:id="@+id/ticketPrice"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_marginEnd="12dp"
  android:elevation="4dp"
  android:text="2,70 €"
  app:layout_constraintBottom_toTopOf="@id/ticketPriceLevel"
  android:textColor="?attr/defaultTextColor"
  android:textStyle="bold"
  android:textSize="16sp"
  android:layout_marginTop="12dp"
  app:layout_constraintEnd_toEndOf="@id/ticketView"
  app:layout_constraintTop_toTopOf="@id/ticketView" />

<TextView
  android:id="@+id/ticketPriceLevel"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_marginEnd="12dp"
  android:elevation="4dp"
  android:layout_marginBottom="8dp"
  android:text="Preisstufe 1"
  android:textColor="?attr/secondaryTextColor"
  android:textSize="16sp"
  app:layout_constraintVertical_bias="0"
  android:textStyle="bold"
  app:layout_constraintBottom_toTopOf="@+id/ticketType"
  app:layout_constraintEnd_toEndOf="@id/ticketView"
  app:layout_constraintTop_toBottomOf="@id/ticketPrice" />

<TextView
  android:id="@+id/ticketType"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_marginStart="12dp"
  android:layout_marginEnd="12dp"
  android:elevation="4dp"
  android:text="Einzelfahrkarte"
  android:maxLines="2"
  android:textColor="?attr/themeTextColor"
  android:textSize="22sp"
  android:textStyle="bold"
  app:layout_constraintEnd_toEndOf="@id/ticketView"
  app:layout_constraintBottom_toBottomOf="@id/ticketView"
  app:layout_constraintStart_toStartOf="@id/ticketView"
  app:layout_constraintTop_toTopOf="@id/ticketView" />

<TextView
  android:id="@+id/ticketBought"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_marginEnd="12dp"
  android:elevation="4dp"
  android:text="Gekauft:"
  android:textColor="?attr/secondaryTextColor"
  android:textStyle="bold"
  android:textSize="16sp"
  android:layout_marginTop="8dp"
  app:layout_constraintEnd_toEndOf="@id/ticketView"
  app:layout_constraintVertical_bias="1"
  app:layout_constraintTop_toBottomOf="@id/ticketType"
  app:layout_constraintBottom_toTopOf="@id/ticketBoughtDate" />

<TextView
  android:id="@+id/ticketBoughtDate"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_marginEnd="12dp"
  android:layout_marginBottom="20dp"
  android:elevation="4dp"
  android:text="Heute 12:20"
  app:layout_constraintTop_toBottomOf="@id/ticketBought"
  android:textColor="?attr/defaultTextColor"
  android:textSize="16sp"
  app:layout_constraintVertical_bias="0"
  android:textStyle="bold"
  app:layout_constraintBottom_toBottomOf="@+id/ticketView"
  app:layout_constraintEnd_toEndOf="@id/ticketView" />

<TextView
  android:id="@+id/ticketRemainingValidity"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_marginStart="12dp"
  android:elevation="4dp"
  android:text="Noch 25 min gültig"
  android:textColor="?attr/defaultTextColor"
  android:textSize="18sp"
  android:textStyle="bold"
  app:layout_constraintBottom_toBottomOf="@id/ticketBoughtDate"
  app:layout_constraintEnd_toStartOf="@+id/ticketBoughtDate"
  app:layout_constraintStart_toStartOf="@id/ticketView" />

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?attr/surfaceColor"
android:padding="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ticketPreviewLayout" />

</androidx.constraintlayout.widget.ConstraintLayout>`

RSIllegalArgumentException: Radius out of range (0 < r <= 25)

I'm using it in a RecyclerView and it crashes the app with this error?

 android.renderscript.RSIllegalArgumentException: Radius out of range (0 < r <= 25).
        at android.renderscript.ScriptIntrinsicBlur.setRadius(ScriptIntrinsicBlur.java:82)
        at com.vipulasri.ticketview.BlurBuilder.blur(BlurBuilder.java:20)
        at com.vipulasri.ticketview.TicketView.generateShadow(TicketView.java:281)
        at com.vipulasri.ticketview.TicketView.doLayout(TicketView.java:262)
        at com.vipulasri.ticketview.TicketView.onDraw(TicketView.java:111)

Full logcat error in this gist

Here's the TicketView I'm using
it shows perfectly fine in the preview btw.

 <com.vipulasri.ticketview.TicketView
        android:id="@+id/ticketView"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_marginHorizontal="16dp"
        android:layout_marginVertical="5dp"
        app:ticketBackgroundColor="@color/white"
        app:ticketCornerRadius="10dp"
        app:ticketCornerType="rounded"
        app:ticketDividerColor="#D9D9D9"
        app:ticketDividerDashGap="6dp"
        app:ticketDividerDashLength="8dp"
        app:ticketDividerPadding="5dp"
        app:ticketDividerType="dash"
        app:ticketDividerWidth="1dp"
        app:ticketElevation="3dp"
        app:ticketOrientation="horizontal"
        app:ticketScallopPositionPercent="77"
        app:ticketScallopRadius="10dp"
        app:ticketShadowColor="@color/black"
        app:ticketShowBorder="false"
        app:ticketShowDivider="true" />

Ability to export Ticket as an image

  • The title says it all. Is there a built-in functionality that lets the user export the View into some kind of an image? The basic idea is to make it shareable through android intent. I am willing to work on something if it's not yet available or not in the works.

Rename attrs

Hi, first thanks for creating such an awesome library.

Is it possible to change the attribute names so it won't collide with other libraries? (like adding ticketview_ or ticket as a prefix(like the ticketElevation?)

I want to use this library but currently it attributes collides with other libraries i am using. (in my case the orientation resource name has conflicts)

AGPBI: {"kind":"error","text":"Attribute "orientation" already defined with incompatible format.","sources":[{"file":"/Users/xxxx/.gradle/caches/transforms-1/files-1.1/{other-library-name}/f85a8ad0b0222b4a35fd6da2e9a9be73/res/values/values.xml","position":{"startLine":86,"startColumn":4,"startOffset":5685,"endColumn":51,"endOffset":5732}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Original attribute defined here.","sources":[{"file":"/Users/xxx/.gradle/caches/transforms-1/files-1.1/{other-library-name}/f85a8ad0b0222b4a35fd6da2e9a9be73/res/values/values.xml","position":{"startLine":86,"startColumn":4,"startOffset":5685,"endColumn":51,"endOffset":5732}}],"original":"","tool":"AAPT"}

Stating from here
https://developer.android.com/studio/projects/android-library

Resource merge conflicts
The build tools merge resources from a library module with those of a dependent app module. If a given resource ID is defined in both modules, the resource from the app is used.
If conflicts occur between multiple AAR libraries, then the resource from the library listed first in the dependencies list (toward the top of the dependencies block) is used.
To avoid resource conflicts for common resource IDs, consider using a prefix or other consistent naming scheme that is unique to the module (or is unique across all project modules).

Ticketview does not work in recycler view

first of all, congratulations for your repository. I'm trying to use with the recycler view and create a list view of ticket view. But it is not displayed. Do you have a similar example?

how to use this view?

Hi Vipul Asri, thanks for this nice view

but i have a question about how to use this view?

is there any gradle work or something to get this view as a library?

thanks again dude :)

Multiple dividiers?

Does this library can support multiple divisions like for example i need 3 sections for my ticket? Thanks!

How to handle Unit Test ?

When I try to unit Test with robolectric, I got errors, I think it is about mocking...

I can not call as TicketView class and mock.

Error:

error: attribute ticketBorderColor (aka com.component.test:ticketBorderColor) not found.

How can we mock the view?

Improve the documentation

Hi, I'm trying to use your library in my application but I'm having some issues about:

  1. How can I populate the view? I've created in my XML layout, but how can I set an image and the various information I have to display?
  2. Is it possible to have a sample code (the one inside your play store's app would be perfect)?
  3. Also, I saw some code in this repo for example. Is it possible to use and have it in Java?
  4. A better documentation or a wiki maybe is the most missing point in this library.

Let me know and thanks for your work!

Can be ViewGroup?

How i can obtain this layout with this library?
ImageView with inverter rounded corners or based on shape of layout like view.setClipToOutline(true);
Thanks.
29

backgroung color and text on ticket

HI, I am unable to view on ticket view. if i used transparent background it gives gray color background in devices. please help me with including layout over ticketview

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.