Skip to content

Commit

Permalink
Library:
Browse files Browse the repository at this point in the history
Fix crash when unsetting key background (by setting it to 0).
Allow setting the layout for the keyboard view itself in xml as attribute "layout".
Add getters for keyboard and popupwindow instances to NumberKeyboardPopup

Sample:
Update sample to include AOSP style keyboard via "layout" attribute.
  • Loading branch information
unverbraucht committed Aug 22, 2018
1 parent 68c00d7 commit 36a355e
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,20 @@ public void setKeyPadding(int px) {
*/
public void setNumberKeyBackground(@DrawableRes int background) {
for (TextView key : numericKeys) {
key.setBackground(ContextCompat.getDrawable(getContext(), background));
if (background == 0) {
key.setBackgroundResource(0);
} else {
key.setBackground(ContextCompat.getDrawable(getContext(), background));
}
}
if (modifierKeys != null) {
for (View modifierKey : modifierKeys) {
if (modifierKey instanceof TextView) {
modifierKey.setBackground(ContextCompat.getDrawable(getContext(), background));
if (background == 0) {
modifierKey.setBackgroundResource(0);
} else {
modifierKey.setBackground(ContextCompat.getDrawable(getContext(), background));
}
}
}
}
Expand Down Expand Up @@ -413,6 +421,8 @@ private void initializeAttributes(AttributeSet attrs) {
leftAuxBtnBackground = R.drawable.key_bg;
rightAuxBtnBackground = R.drawable.key_bg;
}
// Get layout ID
layoutId = array.getResourceId(R.styleable.NumberKeyboard_layout, layoutId);
} finally {
array.recycle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public PopupWindow getPopupWindow() {
return popupWindow;
}

@NonNull
public NumberKeyboard getKeyboard() {
return keyboard;
}

private Runnable delayHidePopupRunnable = new Runnable() {

@Override
Expand Down
1 change: 1 addition & 0 deletions lib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<attr name="leftAuxBtnBackground" format="reference"/>
<attr name="rightAuxBtnIcon" format="reference"/>
<attr name="rightAuxBtnBackground" format="reference"/>
<attr name="layout" format="reference"/>
</declare-styleable>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.widget.EditText;
import android.widget.TextView;

import com.davidmiguel.numberkeyboard.NumberKeyboard;
import com.davidmiguel.numberkeyboard.NumberKeyboardPopup;

import java.text.DecimalFormat;
Expand Down Expand Up @@ -82,6 +83,10 @@ protected void onCreate(Bundle savedInstanceState) {

popup = new NumberKeyboardPopup.Builder(findViewById(R.id.main_view)).setEditTextListener().setKeyboardLayout(R.layout.popup_keyboard).build(amountEditText);

final NumberKeyboard keyboard = popup.getKeyboard();
keyboard.setNumberKeyBackground(0);
keyboard.setKeyPadding(0);

amountEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
266 changes: 266 additions & 0 deletions sample/src/main/res/layout/number_keyboard_4rows_aosp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
<?xml version="1.0" encoding="utf-8"?>

<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/key1Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/key4Container"
app:layout_constraintEnd_toStartOf="@+id/key2Container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/key1"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/one"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/key2Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/key5Container"
app:layout_constraintEnd_toStartOf="@+id/key3Container"
app:layout_constraintStart_toEndOf="@+id/key1Container"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/key2"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/two"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/key3Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/key6Container"
app:layout_constraintEnd_toStartOf="@+id/modifier1Container"
app:layout_constraintStart_toEndOf="@+id/key2Container"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/key3"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/three"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/modifier1Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/key6Container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/key3Container"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/keyModifier1"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/minus"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/key4Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/key7Container"
app:layout_constraintEnd_toStartOf="@+id/key5Container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/key1Container">

<TextView
android:id="@+id/key4"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/four"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>


<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/key5Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/key8Container"
app:layout_constraintEnd_toStartOf="@+id/key6Container"
app:layout_constraintStart_toEndOf="@+id/key4Container"
app:layout_constraintTop_toBottomOf="@+id/key2Container">

<TextView
android:id="@+id/key5"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/five"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/key6Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/key9Container"
app:layout_constraintEnd_toStartOf="@+id/modifier2Container"
app:layout_constraintStart_toEndOf="@+id/key5Container"
app:layout_constraintTop_toBottomOf="@+id/key3Container">

<TextView
android:id="@+id/key6"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/six"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/modifier2Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/key9Container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/key6Container"
app:layout_constraintTop_toBottomOf="@+id/key3Container">

<TextView
android:id="@+id/keyModifier2"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/comma"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/key7Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/leftAuxBtnContainer"
app:layout_constraintEnd_toStartOf="@+id/key8Container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/key4Container">

<TextView
android:id="@+id/key7"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/seven"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>


<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/key8Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/key0Container"
app:layout_constraintEnd_toStartOf="@+id/key9Container"
app:layout_constraintStart_toEndOf="@+id/key7Container"
app:layout_constraintTop_toBottomOf="@+id/key5Container">

<TextView
android:id="@+id/key8"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/eight"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/key9Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/rightAuxBtnContainer"
app:layout_constraintEnd_toStartOf="@+id/modifier3Container"
app:layout_constraintStart_toEndOf="@+id/key8Container"
app:layout_constraintTop_toBottomOf="@+id/key6Container">

<TextView
android:id="@+id/key9"
style="@style/keyNoBg"
android:padding="0dp"
android:text="@string/nine"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/modifier3Container"
style="@style/keyContainer"
app:layout_constraintBottom_toTopOf="@+id/rightAuxBtnContainer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/key9Container"
app:layout_constraintTop_toBottomOf="@+id/key6Container">

<ImageView
android:id="@+id/buttonModifier3"
style="@style/keyNoBg"
android:scaleType="center"
app:srcCompat="@drawable/ic_backspace"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/leftAuxBtnContainer"
style="@style/keyContainer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/key0Container"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/key7Container">

<ImageView
android:id="@+id/leftAuxBtn"
style="@style/keyNoBg"
android:scaleType="center"
app:srcCompat="@drawable/ic_fingerprint"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>


<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/key0Container"
style="@style/keyContainer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/rightAuxBtnContainer"
app:layout_constraintStart_toEndOf="@+id/leftAuxBtnContainer"
app:layout_constraintTop_toBottomOf="@+id/key8Container">

<TextView
android:id="@+id/key0"
style="@style/keyNoBg"
android:text="@string/zero"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/rightAuxBtnContainer"
style="@style/keyContainer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/modifier4Container"
app:layout_constraintStart_toEndOf="@+id/key0Container"
app:layout_constraintTop_toBottomOf="@+id/key9Container">

<ImageView
android:id="@+id/rightAuxBtn"
style="@style/keyNoBg"
android:scaleType="center"
app:srcCompat="@drawable/ic_backspace"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>

<com.davidmiguel.numberkeyboard.SquareFrameLayout
android:id="@+id/modifier4Container"
style="@style/keyContainer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/rightAuxBtnContainer"
app:layout_constraintTop_toBottomOf="@+id/key9Container">

<ImageView
android:id="@+id/buttonModifier4"
style="@style/keyNoBg"
android:scaleType="center"
app:srcCompat="@drawable/ic_check_circle"/>

</com.davidmiguel.numberkeyboard.SquareFrameLayout>
</merge>
1 change: 1 addition & 0 deletions sample/src/main/res/layout/popup_keyboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<com.davidmiguel.numberkeyboard.NumberKeyboard xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:keyboard="http://schemas.android.com/apk/res-auto"
android:background="@android:color/white"
keyboard:layout="@layout/number_keyboard_4rows_aosp"
android:layout_width="match_parent" android:layout_height="match_parent"
keyboard:keyboardType="four_columns"
/>

0 comments on commit 36a355e

Please sign in to comment.