Skip to content

Commit bbeabe5

Browse files
committed
Initial commit
0 parents  commit bbeabe5

28 files changed

+571
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches/build_file_checksums.ser
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
.DS_Store
9+
/build
10+
/captures
11+
.externalNativeBuild
12+
.idea

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'com.android.library'
2+
3+
apply plugin: 'kotlin-android'
4+
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
android {
8+
compileSdkVersion 28
9+
defaultConfig {
10+
minSdkVersion 19
11+
targetSdkVersion 28
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
23+
implementation 'com.android.support:appcompat-v7:28.0.0'
24+
25+
implementation 'org.buffer.android:counter-view:1.0'
26+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="android.buffer.org.ui_kit"/>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.buffer.android.components
2+
3+
import android.buffer.org.ui_kit.R
4+
import android.content.Context
5+
import android.graphics.Typeface
6+
import android.support.v4.content.ContextCompat
7+
import android.support.v7.widget.AppCompatButton
8+
import android.util.AttributeSet
9+
import android.view.Gravity.CENTER_HORIZONTAL
10+
11+
class RoundedButton @JvmOverloads constructor(context: Context,
12+
attrs: AttributeSet? = null,
13+
defStyleAttr: Int = 0)
14+
: AppCompatButton(context, attrs, defStyleAttr) {
15+
16+
init {
17+
setBackground(attrs)
18+
gravity = CENTER_HORIZONTAL
19+
isClickable = true
20+
typeface = Typeface.DEFAULT_BOLD
21+
}
22+
23+
private fun setBackground(attrs: AttributeSet? = null) {
24+
val style = ButtonStyle.fromIdentifier(getStyleIdentifierFromStyleableAttributes(attrs))
25+
when (style) {
26+
ButtonStyle.DARK -> {
27+
setTextColor(ContextCompat.getColor(context, R.color.white))
28+
setBackgroundResource(R.drawable.button_bfr_round_dark)
29+
}
30+
ButtonStyle.LIGHT -> {
31+
setTextColor(ContextCompat.getColor(context, R.color.white))
32+
setBackgroundResource(R.drawable.button_bfr_round_light)
33+
}
34+
ButtonStyle.CLEAR -> {
35+
setTextColor(ContextCompat.getColor(context, R.color.outer_space))
36+
setBackgroundResource(R.drawable.button_bfr_round_white)
37+
}
38+
}
39+
}
40+
41+
private fun getStyleIdentifierFromStyleableAttributes(attrs: AttributeSet?): Int {
42+
val styledAttributes = context.theme.obtainStyledAttributes(
43+
attrs,
44+
R.styleable.RoundedButtonStyles,
45+
0, 0)
46+
47+
if (styledAttributes.hasValue(R.styleable.RoundedButtonStyles_bufferButtonStyle)) {
48+
return styledAttributes.getInt(R.styleable.RoundedButtonStyles_bufferButtonStyle, 0)
49+
}
50+
return 0
51+
}
52+
53+
private enum class ButtonStyle {
54+
DARK, LIGHT, CLEAR;
55+
56+
companion object {
57+
fun fromIdentifier(identifier: Int): ButtonStyle {
58+
return when (identifier) {
59+
0 -> DARK
60+
1 -> LIGHT
61+
2 -> CLEAR
62+
else -> DARK
63+
}
64+
}
65+
}
66+
}
67+
68+
69+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<corners android:radius="@dimen/button_radius" />
5+
<solid android:color="@color/light_grey" />
6+
</shape>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<corners android:radius="@dimen/button_radius" />
5+
<solid android:color="@color/white" />
6+
</shape>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:drawable="@drawable/button_bfr_round_dark_disabled" android:state_enabled="false" />
4+
<item android:drawable="@drawable/button_bfr_round_dark_unfocused" android:state_enabled="true" android:state_focused="false" android:state_pressed="false" android:state_selected="false" />
5+
<item android:drawable="@drawable/button_bfr_round_dark_unfocused" android:state_enabled="true" android:state_focused="false" android:state_pressed="false" android:state_selected="true" />
6+
<item android:drawable="@drawable/button_bfr_round_dark_pressed" android:state_enabled="true" android:state_pressed="true" />
7+
</selector>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<corners android:radius="@dimen/button_radius" />
5+
<solid android:color="@color/misty_grey" />
6+
</shape>

0 commit comments

Comments
 (0)