Skip to content

Commit

Permalink
Bug fixing on setOnClickListener cannot response any touches
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhamhadisyah committed Apr 3, 2022
1 parent 200bc29 commit 007992a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion VerticalIconButton/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ afterEvaluate {

groupId = 'com.github.ilhamhadisyah'
artifactId = 'VerticalIconButton'
version = '1.8.1'
version = '1.8.2'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.cardview.widget.CardView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import com.google.android.material.card.MaterialCardView

class VerticalIconBoxedButton : RelativeLayout {
class VerticalIconBoxedButton : MaterialCardView {
private var mContext: Context
private lateinit var attrs: AttributeSet
private var styleAttr = 0
Expand Down Expand Up @@ -143,7 +142,7 @@ class VerticalIconBoxedButton : RelativeLayout {

/** Check if stroke added */
if (strokeColor != 0) {
setStrokeColor(strokeColor as Int)
setButtonStrokeColor(strokeColor as Int)
}

/** Check if icon weight added */
Expand All @@ -170,7 +169,7 @@ class VerticalIconBoxedButton : RelativeLayout {
iconImage.requestLayout()
}

fun setStrokeColor(color: Int) {
fun setButtonStrokeColor(color: Int) {
rootLayout.strokeColor = color
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.annotation.ColorInt
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import com.google.android.material.card.MaterialCardView

class VerticalIconButton : RelativeLayout {
class VerticalIconButton : MaterialCardView {
private var mContext: Context
private lateinit var attrs: AttributeSet
private var styleAttr = 0
Expand Down Expand Up @@ -73,6 +72,8 @@ class VerticalIconButton : RelativeLayout {
private fun initView() {
this.view = this
inflate(mContext, R.layout.button_layout, this)
this.isClickable = true
this.isFocusable = true

val arr: TypedArray =
mContext.obtainStyledAttributes(attrs, R.styleable.VerticalIconButton, styleAttr, 0)
Expand Down Expand Up @@ -132,7 +133,7 @@ class VerticalIconButton : RelativeLayout {

/** Check if stroke added */
if (strokeColor != 0) {
setStrokeColor(strokeColor as Int)
setButtonStrokeColor(strokeColor as Int)
}

/** Check if icon weight added */
Expand All @@ -148,8 +149,9 @@ class VerticalIconButton : RelativeLayout {
}

fun setIconMarginTop(margin: Float) {
val layoutParams: ConstraintLayout.LayoutParams = iconImage.layoutParams as ConstraintLayout.LayoutParams
layoutParams.setMargins(0,margin.toInt(),0,0)
val layoutParams: ConstraintLayout.LayoutParams =
iconImage.layoutParams as ConstraintLayout.LayoutParams
layoutParams.setMargins(0, margin.toInt(), 0, 0)
iconImage.layoutParams = layoutParams
}

Expand All @@ -159,7 +161,7 @@ class VerticalIconButton : RelativeLayout {
iconImage.requestLayout()
}

fun setStrokeColor(color: Int) {
fun setButtonStrokeColor(color: Int) {
rootLayout.strokeColor = color
}

Expand Down
2 changes: 0 additions & 2 deletions VerticalIconButton/src/main/res/layout/button_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
app:cardCornerRadius="13dp"
app:strokeWidth="0dp">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
app:cardCornerRadius="13dp"
app:strokeWidth="0dp">

Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android-extensions'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,29 @@ package com.hadisyah.verticaliconbuttonsample

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.hadisyah.verticaliconbutton.VerticalIconBoxedButton
import com.hadisyah.verticaliconbutton.VerticalIconButton

class MainActivity : AppCompatActivity() {

private lateinit var button : VerticalIconButton
private lateinit var button2 : VerticalIconBoxedButton

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

button = findViewById(R.id.button_test)
button2 = findViewById(R.id.button2)

button.setOnClickListener{
Toast.makeText(this, "dsashdiasbdoashb", Toast.LENGTH_SHORT).show()
}

button2.setOnClickListener{
Toast.makeText(this, "a", Toast.LENGTH_SHORT).show()
}

}
}
7 changes: 4 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
app:layout_constraintTop_toTopOf="parent">

<com.hadisyah.verticaliconbutton.VerticalIconButton
android:id="@+id/button_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
Expand All @@ -26,10 +27,12 @@
app:n_button_text_size="6sp"
app:n_icon="@mipmap/ic_launcher"
app:n_icon_weight="90" />

<com.hadisyah.verticaliconbutton.VerticalIconBoxedButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:id="@+id/button2"
android:layout_weight="1"
app:button_text="This is an example"
app:button_text_size="7sp"
Expand All @@ -42,10 +45,10 @@
android:layout_margin="5dp"
android:layout_weight="1"
app:button_background_color_normal="#43A047"
app:icon_background_color="#FDD835"
app:button_text="This is an example"
app:button_text_size="7sp"
app:icon="@mipmap/ic_launcher"
app:icon_background_color="#FDD835"
app:icon_weight="90" />
</androidx.appcompat.widget.LinearLayoutCompat>

Expand All @@ -71,6 +74,4 @@
</androidx.appcompat.widget.LinearLayoutCompat>




</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 007992a

Please sign in to comment.