Skip to content

🚧 Implementation of the barrier tape for android

License

Notifications You must be signed in to change notification settings

alexmedv/BarrierTape

Repository files navigation

🚧 BarrierTape

ℹ️ About

Barrier tape is a great way to get a user's attention or alert them when a feature of your app is unavailable. This library allows you to create a barrier tape of different colors and shapes. It can be used as a background for any View or as content of ImageView

🔧 Installation

Add the following dependency to your build.gradle file:

dependencies {
  implementation 'com.github.alexmedv:BarrierTape:1.0.0'
}

⚠️ Don't forget to add the JitPack maven repository to the list of repositories: maven { url "https://jitpack.io" }

🕹️ Playground

For a better understanding of the library's capabilities, there is a playground in the demo app. The user can change all the parameters in real time: color palettes, sizes, width of stripes, etc.

✨ Examples

The BarrierTapeDrawable can be used immediately after it is created without any additional setup. The result will be a rectangle with yellow and black lines

// create with default settings
imageView.background = BarrierTapeDrawable()


Now let's add some colors by replacing the default colors. You need at least two colors, the maximum number of colors is unlimited.
⚠️ Note that all parameter changes must be performed in the main thread

val barrierTape = BarrierTapeDrawable()
barrierTape.setColors(listOf(0xcf322e, 0xd7d4d5))
imageView.background = barrierTape

The width of the lines and their incline can be changed. All dimensions are specified in pixels.

val barrierTape = BarrierTapeDrawable().apply {
  setColors(listOf(0x000000, 0xECB537))
  stripeWidth = 80
  isReversed = true
}

You can round any corners of a shape independently of each other
⚠️ Can only be used for Shape.RECTANGLE

imageView.background = BarrierTapeDrawable().apply {
  setColors(listOf(0x408d57,0x47a157, 0x6dba5e, 0x8fcf61, 0x43b7ad, 0x489ad8, 0x3777bd, 0x2e6187, 0x9a3f40, 0xe03d3c, 0xf0892f, 0xf3c73d))
  stripeWidth = 90
  setRadius(topLeftRadius = 40F, topRightRadius = 40F, bottomLeftRadius = 0F, bottomRightRadius = 0F)
  // to set the same radius for all corners you can use setRadius(40F)
}

The barrier tape can be drawn in any of five shapes: RECTANGLE, OVAL, CIRCLE, TRIANGLE and EQUILATERAL_TRIANGLE

imageView.background = BarrierTapeDrawable().apply {
  shape = Shape.EQUILATERAL_TRIANGLE
  triangleOrientation = TriangleOrientation.TOP
}

The barrier tape can be displayed as a frame. To use this mode, borderWidth must be greater than zero.

imageView.background = BarrierTapeDrawable().apply {
  borderWidth = 15
}

🤝 Contributions are welcome

Please use the issues page to report any bug you find or to request a new feature.

📝 License

  Copyright 2022 Alexander Medvedev
  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.

About

🚧 Implementation of the barrier tape for android

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages