Skip to content

Commit

Permalink
Fix suggestion input suffix padding
Browse files Browse the repository at this point in the history
  • Loading branch information
selimtoksal committed Feb 19, 2020
1 parent 4a0761c commit 77a0066
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.trendyol.suggestioninputview

import android.content.Context
import android.graphics.Canvas
import android.graphics.Rect
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatEditText

Expand All @@ -27,7 +28,8 @@ internal class SuggestionInputEditText : AppCompatEditText {

override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
val textWidth: Float = paint.measureText(suffix + text) + suffixPaddingLeft
canvas.drawText(suffix, textWidth, baseline.toFloat(), paint)
val suffixWidth: Float = paint.measureText(suffix) / 2
val textWidth: Float = paint.measureText(text.toString()) + suffixPaddingLeft
canvas.drawText(suffix, textWidth + suffixWidth, baseline.toFloat(), paint)
}
}
56 changes: 31 additions & 25 deletions sample/src/main/res/layout/activity_suggestion_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,88 @@
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="shouldShowError"
type="Boolean" />

</data>

<LinearLayout
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".suggestioninput.SuggestionInputActivity">

<androidx.cardview.widget.CardView
android:layout_marginTop="32dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginTop="32dp">

<com.trendyol.suggestioninputview.SuggestionInputView
android:clickable="false"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:id="@+id/suggestionInputView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:clickable="false"
android:inputType="number"
app:inputSuffix=""
app:errorBackground="@drawable/shape_error_background_suggestion_item"
app:horizontalPadding="@dimen/horizontal_padding_suggestion_item"
app:inputButtonBackground="@drawable/shape_selected_background_suggestion_item"
app:inputButtonText="TAMAM"
app:inputButtonTextColor="@color/text_color_selected_suggestion_item"
app:inputEditTextBackground="@drawable/shape_unselected_background_suggestion_item"
app:inputSuffix="TL"
app:minWidth="@dimen/minWidth_suggestion_item"
app:horizontalPadding="@dimen/horizontal_padding_suggestion_item"
app:verticalPadding="@dimen/vertical_padding_suggestion_item"
app:selectedBackground="@drawable/shape_selected_background_suggestion_item"
app:selectedTextColor="@color/text_color_selected_suggestion_item"
app:textSize="@dimen/text_size_suggestion_input"
app:shouldShowError="@{shouldShowError}"
app:errorBackground="@drawable/shape_error_background_suggestion_item"
app:textSize="@dimen/text_size_suggestion_input"
app:unselectedBackground="@drawable/shape_unselected_background_suggestion_item"
app:unselectedTextColor="@color/text_color_unselected_suggestion_item" />
app:unselectedTextColor="@color/text_color_unselected_suggestion_item"
app:verticalPadding="@dimen/vertical_padding_suggestion_item" />
</androidx.cardview.widget.CardView>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/buttonLoad"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="16dp"
android:gravity="center"
android:text="LOAD"
android:layout_width="match_parent"
android:layout_height="50dp"/>
android:text="LOAD" />

<LinearLayout
android:layout_marginTop="32dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginTop="32dp">

<TextView
android:text="Selected Text: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:text="Selected Text: " />

<TextView
android:id="@+id/selectedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginTop="8dp">

<TextView
android:text="Selected Value: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:text="Selected Value: " />

<TextView
android:id="@+id/selectedValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content" />
</LinearLayout>


Expand Down

0 comments on commit 77a0066

Please sign in to comment.