Fixed input field cursor issues

This commit is contained in:
Phillip Hsu 2016-07-16 04:12:30 -07:00
parent c0b914500d
commit a6c8076255
4 changed files with 52 additions and 33 deletions

View File

@ -2,7 +2,6 @@ package com.philliphsu.clock2.editalarm;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -13,6 +12,7 @@ import com.philliphsu.clock2.R;
import butterknife.Bind; import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnTouch; import butterknife.OnTouch;
/** /**
@ -41,6 +41,7 @@ public class NumpadTimePickerDialog extends DialogFragment implements NumpadTime
*/ */
private int[] mInputtedDigits; private int[] mInputtedDigits;
// Don't need to keep a reference to the dismiss ImageButton
@Bind(R.id.input_time) EditText mInputField; @Bind(R.id.input_time) EditText mInputField;
@Bind(R.id.number_grid) NumpadTimePicker mNumpad; @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); View view = inflater.inflate(R.layout.dialog_time_picker_numpad, container, false);
ButterKnife.bind(this, view); 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 // 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 // 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() // the OnTimeSetListener callback contained here or the dialog's dismiss()
@ -156,6 +147,11 @@ public class NumpadTimePickerDialog extends DialogFragment implements NumpadTime
return true; return true;
} }
@OnClick(R.id.cancel)
void cancel() {
dismiss();
}
private void updateInputText(String inputText) { private void updateInputText(String inputText) {
mInputField.setText(inputText); mInputField.setText(inputText);
// Move the cursor // Move the cursor

View File

@ -1,30 +1,30 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" <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"/> <include layout="@layout/content_grid_layout_numpad"/>
<Button <Button
android:id="@+id/leftAlt" android:id="@+id/leftAlt"
style="@style/grid_element_single" style="@style/grid_element_single"
grid:layout_rowWeight="1" app:layout_rowWeight="1"
grid:layout_columnWeight="1" app:layout_columnWeight="1"
grid:layout_column="0"/> app:layout_column="0"/>
<Button <Button
android:id="@+id/rightAlt" android:id="@+id/rightAlt"
style="@style/grid_element_single" style="@style/grid_element_single"
grid:layout_rowWeight="1" app:layout_rowWeight="1"
grid:layout_columnWeight="1" app:layout_columnWeight="1"
grid:layout_column="2"/> app:layout_column="2"/>
<!-- Used to properly position the FAB --> <!-- Used to properly position the FAB -->
<FrameLayout <FrameLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="wrap_content"
grid:layout_rowWeight="1" android:minHeight="@dimen/fab_cell_height"
grid:layout_columnWeight="1" app:layout_columnWeight="1"
grid:layout_column="1"> app:layout_column="1">
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/fab" android:id="@+id/fab"
@ -41,7 +41,7 @@
android:layout_height="0dp" android:layout_height="0dp"
android:src="@drawable/ic_backspace_24dp" android:src="@drawable/ic_backspace_24dp"
android:background="?selectableItemBackground" android:background="?selectableItemBackground"
grid:layout_rowWeight="1" app:layout_rowWeight="1"
grid:layout_columnWeight="1" app:layout_columnWeight="1"
grid:layout_column="2"/> app:layout_column="2"/>
</merge> </merge>

View File

@ -1,13 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?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" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<android.support.v7.widget.Toolbar <!-- We want this to be a FrameLayout so we can make the EditText
android:id="@+id/toolbar" 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_width="match_parent"
android:layout_height="@dimen/header_height" android:layout_height="@dimen/header_height"
android:minHeight="@dimen/header_height"
android:background="@color/colorPrimary" android:background="@color/colorPrimary"
android:layout_alignParentTop="true"> android:layout_alignParentTop="true">
@ -16,21 +19,40 @@
opens, the user sees the header view as just an appbar that has opens, the user sees the header view as just an appbar that has
a single navigation icon, with no indication that the dialog a single navigation icon, with no indication that the dialog
actually displays input. --> 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 <EditText
android:id="@+id/input_time" android:id="@+id/input_time"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:textAlignment="center" android:gravity="center"
android:textSize="@dimen/time_input_text_size" android:textSize="@dimen/time_input_text_size"
android:background="@android:color/transparent" android:background="@android:color/transparent"
style="@style/TextAppearance.AppCompat.Inverse"/> 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 <com.philliphsu.clock2.editalarm.NumpadTimePicker
android:id="@+id/number_grid" android:id="@+id/number_grid"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/numpad_height" android:layout_height="@dimen/numpad_height"
android:layout_below="@id/toolbar"/> android:layout_below="@id/header"/>
</RelativeLayout> </RelativeLayout>

View File

@ -14,7 +14,8 @@
<!-- NumpadTimePickerDialog --> <!-- NumpadTimePickerDialog -->
<dimen name="header_height">72dp</dimen> <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="time_input_text_size">45sp</dimen>
<dimen name="cancel_icon_size">56dp</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> </resources>