ShapeView


Source link: https://github.com/StephenVinouze/ShapeView

ShapeView

Drawing shapes can be achieved in many ways and depend mostly on how complex your shape is. This Kotlin library intends to leverage how to draw basic shapes so that you need only focus on how to draw your shape using this toolbox.

Half circle edge shape Ticket shape

Gradle Dependency

Add this in your root build.gradle file:

allprojects {
  repositories {

// ... other repositories
maven {
 url "https://jitpack.io" 
}
  
}
 
}

Then add the dependencies that you need in your project.

dependencies {

compile 'com.github.StephenVinouze:ShapeView:1.1.1' 
}

Usage

An abstract ShapeView class allows you to configure two paths: one path is used to fill your content while the other can be used to draw a stroke around your shape. This class exposes three custom XML attributes:

  • shapeColor: define which color will fill your shape
  • shapeStrokeColor: define which color will be used for the stroke around your shape (if any)
  • shapeStrokeWidth: define the width of your stroke (if any)
  • [NEW] shapeDashOnWidth: define the width of your stroke's dash filled line (if any)
  • [NEW] shapeDashOffWidth: define the width between your stroke's dash (if any)

These attributes lets you define both in XML and programmatically your basic shapes. Starting from that, you can easily extend ShapeView to draw your own shapes by using the Path instance that the class provides.

Finally, ShapeView extends from RelativeLayout so you can easily put any view inside your shape.

Examples

This library provides two shapes: a basic HalfCircleEdgeShapeView and a more complex TicketShapeView

HalfCircleEdgeShapeView

This class extends from ShapeView and overrides both onSizeChanged() and onDraw() methods. The idea is to draw a shape with half circle at both left and right edges by using the Path instance. This shape can for instance be used as a Button.

<com.github.stephenvinouze.shapeview.shapes.HalfCircleEdgeShapeView

android:layout_width="250dp"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:padding="10dp"

app:shapeColor="@color/colorAccent"

app:shapeStrokeColor="@color/colorPrimaryDark"

app:shapeStrokeWidth="2dp"  app:shapeDashOnWidth="4dp"

app:shapeDashOffWidth="2dp">
 <!-- Any subviews you want -->
</com.github.stephenvinouze.shapeview.shapes.HalfCircleEdgeShapeView>

TicketShapeView

Similar to the previous shape, we define the shape using the Path instance to draw a ticket like shape. We provide a few custom XML attributes to define both innerRadius and outerRadius that will be applied to this shape. You can also specify where the inner radius will be applied.

<com.github.stephenvinouze.shapeview.shapes.TicketShapeView

android:layout_width="250dp"

android:layout_height="150dp"

app:innerOffset="30dp"

app:innerRadius="5dp"

app:outerRadius="7dp"

app:shapeColor="@color/colorAccent">
 <!-- Any subviews you want -->
</com.github.stephenvinouze.shapeview.shapes.TicketShapeView>

License

Copyright 2016 Stephen Vinouze.  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. 

Resources

An easy way to dynamically replace Strings of your Android App or provide new languages Over-the-air without needed to publish a new release on Google Play.
A complete library to build Android apps with a built-in theme engine.
Custom Text Editor like WhatsApp
Get android keyboard height using an overlay popup-window
Android ListView example written in Kotlin
How to get email account android user. Assumed first email has been added is the primary email.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes