Fixed input field cursor issues
This commit is contained in:
parent
c0b914500d
commit
a6c8076255
@ -2,7 +2,6 @@ package com.philliphsu.clock2.editalarm;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -13,6 +12,7 @@ import com.philliphsu.clock2.R;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnTouch;
|
||||
|
||||
/**
|
||||
@ -41,6 +41,7 @@ public class NumpadTimePickerDialog extends DialogFragment implements NumpadTime
|
||||
*/
|
||||
private int[] mInputtedDigits;
|
||||
|
||||
// Don't need to keep a reference to the dismiss ImageButton
|
||||
@Bind(R.id.input_time) EditText mInputField;
|
||||
@Bind(R.id.number_grid) NumpadTimePicker mNumpad;
|
||||
|
||||
@ -94,16 +95,6 @@ public class NumpadTimePickerDialog extends DialogFragment implements NumpadTime
|
||||
View view = inflater.inflate(R.layout.dialog_time_picker_numpad, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
Toolbar toolbar = ButterKnife.findById(view, R.id.toolbar);
|
||||
toolbar.setNavigationIcon(android.R.drawable.ic_menu_close_clear_cancel);
|
||||
// Can't do a method bind on the navigation icon because we don't own it
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
// Can't do a method bind because the FAB is not part of this dialog's layout
|
||||
// Also can't do the bind in the Numpad's class, because it doesn't have access to
|
||||
// the OnTimeSetListener callback contained here or the dialog's dismiss()
|
||||
@ -156,6 +147,11 @@ public class NumpadTimePickerDialog extends DialogFragment implements NumpadTime
|
||||
return true;
|
||||
}
|
||||
|
||||
@OnClick(R.id.cancel)
|
||||
void cancel() {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
private void updateInputText(String inputText) {
|
||||
mInputField.setText(inputText);
|
||||
// Move the cursor
|
||||
|
||||
@ -1,30 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:grid="http://schemas.android.com/apk/res-auto">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<include layout="@layout/content_grid_layout_numpad"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/leftAlt"
|
||||
style="@style/grid_element_single"
|
||||
grid:layout_rowWeight="1"
|
||||
grid:layout_columnWeight="1"
|
||||
grid:layout_column="0"/>
|
||||
app:layout_rowWeight="1"
|
||||
app:layout_columnWeight="1"
|
||||
app:layout_column="0"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/rightAlt"
|
||||
style="@style/grid_element_single"
|
||||
grid:layout_rowWeight="1"
|
||||
grid:layout_columnWeight="1"
|
||||
grid:layout_column="2"/>
|
||||
app:layout_rowWeight="1"
|
||||
app:layout_columnWeight="1"
|
||||
app:layout_column="2"/>
|
||||
|
||||
<!-- Used to properly position the FAB -->
|
||||
<FrameLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
grid:layout_rowWeight="1"
|
||||
grid:layout_columnWeight="1"
|
||||
grid:layout_column="1">
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/fab_cell_height"
|
||||
app:layout_columnWeight="1"
|
||||
app:layout_column="1">
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
@ -41,7 +41,7 @@
|
||||
android:layout_height="0dp"
|
||||
android:src="@drawable/ic_backspace_24dp"
|
||||
android:background="?selectableItemBackground"
|
||||
grid:layout_rowWeight="1"
|
||||
grid:layout_columnWeight="1"
|
||||
grid:layout_column="2"/>
|
||||
app:layout_rowWeight="1"
|
||||
app:layout_columnWeight="1"
|
||||
app:layout_column="2"/>
|
||||
</merge>
|
||||
@ -1,13 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- TOneverDO: Use LinearLayout, because it doesn't obey LWM -->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
<!-- We want this to be a FrameLayout so we can make the EditText
|
||||
field LWM, because that solves all of our cursor issues, and so we
|
||||
can put the ImageButton on top (z-level) -->
|
||||
<FrameLayout
|
||||
android:id="@+id/header"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/header_height"
|
||||
android:minHeight="@dimen/header_height"
|
||||
android:background="@color/colorPrimary"
|
||||
android:layout_alignParentTop="true">
|
||||
|
||||
@ -16,21 +19,40 @@
|
||||
opens, the user sees the header view as just an appbar that has
|
||||
a single navigation icon, with no indication that the dialog
|
||||
actually displays input. -->
|
||||
<!-- If we were to use LWW, we would have issues with the cursor.
|
||||
(1) It won't show initially, because the view is not big enough to
|
||||
accommodate the cursor drawable. A hacky solution is to set the hint
|
||||
to a single whitespace character.
|
||||
(2) Additionally, when text is inputted, the cursor gets cut off
|
||||
as it advances in position, probably because the text rendered at
|
||||
the set text size is bigger than the view bounds. A satisfactory
|
||||
solution has not been found. We tried adding padding to the end,
|
||||
but that ended up decentralizing the view.
|
||||
-->
|
||||
<EditText
|
||||
android:id="@+id/input_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:textSize="@dimen/time_input_text_size"
|
||||
android:background="@android:color/transparent"
|
||||
style="@style/TextAppearance.AppCompat.Inverse"/>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
<!-- TOneverDO: Before the EditText, because we need this on top -->
|
||||
<ImageButton
|
||||
android:id="@+id/cancel"
|
||||
android:layout_width="@dimen/cancel_icon_size"
|
||||
android:layout_height="@dimen/cancel_icon_size"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="?selectableItemBackground"
|
||||
android:src="@android:drawable/ic_menu_close_clear_cancel"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<com.philliphsu.clock2.editalarm.NumpadTimePicker
|
||||
android:id="@+id/number_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/numpad_height"
|
||||
android:layout_below="@id/toolbar"/>
|
||||
android:layout_below="@id/header"/>
|
||||
|
||||
</RelativeLayout>
|
||||
@ -14,7 +14,8 @@
|
||||
|
||||
<!-- NumpadTimePickerDialog -->
|
||||
<dimen name="header_height">72dp</dimen>
|
||||
<dimen name="numpad_height">270dp</dimen>
|
||||
<dimen name="numpad_height">300dp</dimen>
|
||||
<dimen name="time_input_text_size">45sp</dimen>
|
||||
<dimen name="cancel_icon_size">56dp</dimen>
|
||||
<dimen name="fab_cell_height">88dp</dimen> <!-- 56dp fab size + 16dp top margin + 16dp bottom margin -->
|
||||
</resources>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user