Create custom AutoCompleteTextView which can be used inside of a TextInputLayout to show a nice square with the suggestion like the other text fields used in the app.

This commit is contained in:
Severiano Jaramillo 2018-12-07 12:17:45 -06:00
parent 39073e3d9c
commit b9a765e682
4 changed files with 94 additions and 27 deletions

View file

@ -22,7 +22,7 @@ import cy.agorise.bitsybitshareswallet.utils.Constants
import cy.agorise.bitsybitshareswallet.viewmodels.UserAccountViewModel
import cy.agorise.graphenej.*
import kotlinx.android.synthetic.main.fragment_receive_transaction.*
import java.util.HashMap
import java.util.*
class ReceiveTransactionFragment : Fragment() {
private val TAG = this.javaClass.simpleName
@ -113,4 +113,27 @@ class ReceiveTransactionFragment : Fragment() {
bitmap.setPixels(pixels, 0, w, 0, 0, w, h)
return bitmap
}
// /**
// * Updates the UI to show amount and address to send the payment
// *
// * @param amount Amount in crypto to be paid
// * @param address Address to pay amount
// */
// private fun updateAmountAddressUI(amount: Double, account: String) {
// // Trick to format correctly really small floating point numbers
// val df = DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH))
// df.maximumFractionDigits = 340
//
// val cryptoAmount = Helper.getCryptoAmountLocaleFormatted(
// locale, amount,
// inputCoinType.toLowerCase(), this
// )
//
// val txtAmount = getString(R.string.please_pay_s_s, cryptoAmount, inputCoinType.toUpperCase())
// val txtAddress = getString(R.string.to_s, account)
//
// tvTotalCryptoAmount.setText(txtAmount)
// tvReceivingAddress.setText(txtAddress)
// }
}

View file

@ -0,0 +1,45 @@
package cy.agorise.bitsybitshareswallet.views
import android.content.Context
import android.util.AttributeSet
import com.google.android.material.textfield.TextInputLayout
import android.view.inputmethod.InputConnection
import android.view.inputmethod.EditorInfo
import androidx.appcompat.widget.AppCompatAutoCompleteTextView
/**
* Custom AutoCompleteTextView to be used inside a TextInputLayout, so that they can share their hint
* From https://stackoverflow.com/a/41864063/5428997
*/
class MyTextInputAutoCompleteTextView : AppCompatAutoCompleteTextView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? {
val ic = super.onCreateInputConnection(outAttrs)
if (ic != null && outAttrs.hintText == null) {
// If we don't have a hint and our parent is a TextInputLayout, use it's hint for the
// EditorInfo. This allows us to display a hint in 'extract mode'.
val parent = parent
if (parent is TextInputLayout) {
outAttrs.hintText = parent.hint
}
}
// An EditText that lets you use actions ("Done", "Go", etc.) on multi-line edits.
val imeActions = outAttrs.imeOptions and EditorInfo.IME_MASK_ACTION
if (imeActions and EditorInfo.IME_ACTION_DONE != 0) {
// clear the existing action
outAttrs.imeOptions = outAttrs.imeOptions xor imeActions
// set the DONE action
outAttrs.imeOptions = outAttrs.imeOptions or EditorInfo.IME_ACTION_DONE
}
if (outAttrs.imeOptions and EditorInfo.IME_FLAG_NO_ENTER_ACTION != 0) {
outAttrs.imeOptions = outAttrs.imeOptions and EditorInfo.IME_FLAG_NO_ENTER_ACTION.inv()
}
return ic
}
}

View file

@ -38,30 +38,28 @@
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.Bitsy.TextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Spinner
android:id="@+id/spAsset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_height="0dp"
android:layout_marginStart="12dp"
android:visibility="gone"
app:layout_constraintTop_toTopOf="@+id/tilAmount"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/centeredVerticalGuideline"/>
android:hint="@string/text__asset"
app:layout_constraintTop_toTopOf="@id/tilAmount"
app:layout_constraintBottom_toBottomOf="@id/tilAmount"
app:layout_constraintStart_toEndOf="@id/centeredVerticalGuideline"
app:layout_constraintEnd_toEndOf="parent">
<View
android:id="@+id/vSpinner"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginTop="12dp"
android:background="@color/darkGray"
app:layout_constraintTop_toBottomOf="@+id/spAsset"
app:layout_constraintEnd_toEndOf="@+id/spAsset"
app:layout_constraintStart_toStartOf="@+id/spAsset" />
<cy.agorise.bitsybitshareswallet.views.MyTextInputAutoCompleteTextView
android:id="@+id/actvAsset"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="12dp"
android:paddingEnd="8dp"
android:maxLines="1"
android:lines="1"
android:imeOptions="actionDone"/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/ivQR"

View file

@ -41,15 +41,16 @@
<!-- Balances -->
<string name="title_transactions">Transactions</string>
<!-- Send Transaction Fragment -->
<!-- Send & Receive Transaction -->
<string name="text__to">To</string>
<string name="text__amount">Amount</string>
<string name="text__memo">Memo</string>
<string name="text__scan_qr">Scan QR</string>
<string name="text__asset">Asset</string>
<!-- Settings -->
<string name="title_settings">Settings</string>
<string name="night_mode">Night mode</string>
<string name="text__amount">Amount</string>
<string name="text__memo">Memo</string>
<string name="text__scan_qr">Scan QR</string>
</resources>