Auto size text and keyboard styling

This commit is contained in:
PavelRatushny 2017-10-23 18:58:38 +03:00
parent 066888bef0
commit d6dbf27e14
10 changed files with 82 additions and 53 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/map_widget_blue" android:state_pressed="true"/>
<item android:color="@color/bg_color_dark"/>
<item android:drawable="@color/map_widget_blue" android:state_pressed="true"/>
<item android:drawable="@color/bg_color_dark"/>
</selector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/keyboard_text_color_light_pressed" android:state_pressed="true"/>
<item android:color="@color/keyboard_text_color_light"/>
</selector>

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:osmand="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:orientation="vertical"
@ -21,8 +21,8 @@
android:id="@+id/coordinate_input_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_map_toolbar"
app:contentInsetLeft="54dp"
app:contentInsetStart="54dp">
osmand:contentInsetLeft="54dp"
osmand:contentInsetStart="54dp">
<LinearLayout
android:orientation="horizontal"
@ -73,7 +73,7 @@
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
app:labelText="@string/navigate_point_latitude">
osmand:labelText="@string/navigate_point_latitude">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:hint="50:00.0000"
@ -92,7 +92,7 @@
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
app:labelText="@string/navigate_point_longitude">
osmand:labelText="@string/navigate_point_longitude">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:hint="50:00.0000"
@ -115,7 +115,7 @@
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
app:labelText="@string/shared_string_name">
osmand:labelText="@string/shared_string_name">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:hint="@string/access_hint_enter_name"
@ -145,6 +145,7 @@
</LinearLayout>
<LinearLayout
tools:visibility="gone"
android:id="@+id/keyboard_layout"
android:layout_gravity="bottom"
android:orientation="vertical"
@ -180,14 +181,16 @@
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
osmand:src="@drawable/ic_action_arrow_down"/>
tools:src="@drawable/ic_action_arrow_down"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="?attr/dashboard_divider"/>
<net.osmand.plus.widgets.TextViewEx
<android.support.v7.widget.AppCompatTextView
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:maxLines="1"
android:ellipsize="end"
android:id="@+id/add_marker"
@ -196,8 +199,8 @@
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/keyboard_color"
osmand:typeface="@string/font_roboto_regular"
android:textColor="?attr/keyboard_item_text_color"
osmand:autoSizeTextType="uniform"
android:text="@string/shared_string_add"/>
</LinearLayout>

View file

@ -112,7 +112,6 @@
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:visibility="gone"
android:id="@+id/coordinate_input_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"

View file

@ -1,19 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="56dp"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
<android.support.v7.widget.AppCompatTextView
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:id="@+id/keyboard_item"
android:textAllCaps="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/keyboard_color"
osmand:typeface="@string/font_roboto_regular"
android:textColor="?attr/keyboard_item_text_color"
app:autoSizeTextType="uniform"
tools:text="3"/>
</LinearLayout>

View file

@ -8,6 +8,7 @@
<attr name="routeParameterTitleColor" format="color"/>
<attr name="chart_marker_background" format="reference" />
<!-- list colors -->
<attr name="keyboard_item_text_color" format="reference" />
<attr name="ctx_menu_info_divider" format="color"/>
<attr name="searchbar_text" format="color"/>
<attr name="searchbar_text_hint" format="color"/>

View file

@ -264,6 +264,9 @@
<color name="marker_circle_button_color_dark">#525e66</color>
<color name="keyboard_color">#545454</color>
<color name="keyboard_text_color_light">#545454</color>
<color name="keyboard_text_color_light_pressed">#ffffff</color>
<color name="keyboard_text_color_dark">#ffffff</color>
</resources>

View file

@ -171,6 +171,8 @@
<item name="color_dialog_buttons">@color/color_dialog_buttons_light</item>
<item name="popupMenuStyle">@style/PopupMenuLight</item>
<item name="keyboard_item_text_color">@drawable/keyboard_item_text_color_light</item>
</style>
<style name="OverflowMenuButton" parent="@style/Widget.AppCompat.ActionButton.Overflow">
@ -341,6 +343,8 @@
<item name="color_dialog_buttons">@color/color_dialog_buttons_dark</item>
<item name="popupMenuStyle">@style/PopupMenuDark</item>
<item name="keyboard_item_text_color">@color/keyboard_text_color_dark</item>
</style>
<style name="FreeVersionBanner" parent="OsmandDarkTheme">

View file

@ -50,14 +50,18 @@ public class AndroidUtils {
@Override
public void run() {
if (!isHardwareKeyboardAvailable(view.getContext())) {
showSoftKeyboard(view);
}
}
});
}
public static void showSoftKeyboard(final View view) {
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}
}
});
}
public static void hideSoftKeyboard(final Activity activity, final View input) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);

View file

@ -19,6 +19,7 @@ import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.data.PointDescription;
@ -28,7 +29,6 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandTextFieldBoxes;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.widgets.TextViewEx;
import java.util.ArrayList;
import java.util.List;
@ -55,6 +55,8 @@ public class CoordinateInputDialogFragment extends DialogFragment {
private List<OsmandTextFieldBoxes> textFieldBoxes;
private ExtendedEditText nameEditText;
private List<ExtendedEditText> extendedLatLonEditTexts;
private View mainView;
private IconsCache iconsCache;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -72,9 +74,9 @@ public class CoordinateInputDialogFragment extends DialogFragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container);
mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container);
final MapActivity mapActivity = getMapActivity();
final IconsCache ic = getMyApplication().getIconsCache();
iconsCache = getMyApplication().getIconsCache();
Fragment coordinateInputBottomSheetDialogFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(CoordinateInputBottomSheetDialogFragment.TAG);
if (coordinateInputBottomSheetDialogFragment != null) {
@ -94,6 +96,9 @@ public class CoordinateInputDialogFragment extends DialogFragment {
optionsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!useOsmandKeyboard) {
AndroidUtils.hideSoftKeyboard(getMapActivity(), focusedEditText);
}
CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment();
Bundle args = new Bundle();
args.putInt(COORDINATE_FORMAT, coordinateFormat);
@ -178,7 +183,8 @@ public class CoordinateInputDialogFragment extends DialogFragment {
} else {
strToAppend = ":";
}
focusedEditText.append(strToAppend);
focusedEditText.setText(str + strToAppend);
focusedEditText.setSelection(strLength + 1);
} else if (strLength == 5 && coordinateFormat != PointDescription.FORMAT_DEGREES && len < strLength) {
String strToAppend;
if (coordinateFormat == PointDescription.FORMAT_MINUTES) {
@ -186,9 +192,11 @@ public class CoordinateInputDialogFragment extends DialogFragment {
} else {
strToAppend = ":";
}
focusedEditText.append(strToAppend);
focusedEditText.setText(str + strToAppend);
focusedEditText.setSelection(strLength + 1);
} else if (strLength == 8 && coordinateFormat == PointDescription.FORMAT_SECONDS && len < strLength) {
focusedEditText.append(".");
focusedEditText.setText(str + ".");
focusedEditText.setSelection(strLength + 1);
} else if ((strLength == DEGREES_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_DEGREES)
|| (strLength == MINUTES_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_MINUTES)
|| (strLength == SECONDS_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_SECONDS)) {
@ -245,21 +253,14 @@ public class CoordinateInputDialogFragment extends DialogFragment {
}
});
final ImageView showHideKeyBoardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon);
final View keyboardDivider = mainView.findViewById(R.id.keyboard_divider);
showHideKeyBoardIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_arrow_down));
showHideKeyBoardIcon.setOnClickListener(new View.OnClickListener() {
final ImageView showHideKeyboardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon);
showHideKeyboardIcon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_arrow_down));
showHideKeyboardIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int keyboardVisibility = keyboardGrid.getVisibility();
if (keyboardVisibility == View.VISIBLE) {
keyboardGrid.setVisibility(View.GONE);
keyboardDivider.setVisibility(View.GONE);
showHideKeyBoardIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_arrow_up));
} else {
keyboardGrid.setVisibility(View.VISIBLE);
keyboardDivider.setVisibility(View.VISIBLE);
showHideKeyBoardIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_arrow_down));
if (useOsmandKeyboard) {
boolean isCurrentlyVisible = isOsmandKeyboardCurrentlyVisible();
changeOsmandKeyboardVisibility(!isCurrentlyVisible);
}
}
});
@ -287,6 +288,9 @@ public class CoordinateInputDialogFragment extends DialogFragment {
@Override
public void onKeyboardChanged(boolean useOsmandKeyboard) {
CoordinateInputDialogFragment.this.useOsmandKeyboard = useOsmandKeyboard;
if (!useOsmandKeyboard && isOsmandKeyboardCurrentlyVisible()) {
changeOsmandKeyboardVisibility(false);
}
changeKeyboardInBoxes();
changeKeyboardInEditTexts();
}
@ -298,6 +302,18 @@ public class CoordinateInputDialogFragment extends DialogFragment {
};
}
private boolean isOsmandKeyboardCurrentlyVisible() {
return mainView.findViewById(R.id.keyboard_grid_view).getVisibility() == View.VISIBLE;
}
private void changeOsmandKeyboardVisibility(boolean show) {
int visibility = show ? View.VISIBLE : View.GONE;
mainView.findViewById(R.id.keyboard_grid_view).setVisibility(visibility);
mainView.findViewById(R.id.keyboard_divider).setVisibility(visibility);
((ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon))
.setImageDrawable(iconsCache.getThemedIcon(show ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up));
}
private void changeEditTextLengths() {
int maxLength;
if (coordinateFormat == PointDescription.FORMAT_DEGREES) {
@ -321,7 +337,7 @@ public class CoordinateInputDialogFragment extends DialogFragment {
public void changeKeyboardInEditTexts() {
for (ExtendedEditText extendedEditText : extendedLatLonEditTexts) {
extendedEditText.setInputType(useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_TEXT);
extendedEditText.setInputType(useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_NUMBER);
}
nameEditText.setInputType(useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_TEXT);
}
@ -359,17 +375,9 @@ public class CoordinateInputDialogFragment extends DialogFragment {
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.input_coordinate_keyboard_item, parent, false);
}
convertView.setBackgroundResource(lightTheme ? R.drawable.keyboard_item_light_bg : R.drawable.keyboard_item_dark_bg);
TextViewEx keyboardItem = (TextViewEx) convertView.findViewById(R.id.keyboard_item);
// if (position == DELETE_BUTTON_POSITION || position == CLEAR_BUTTON_POSITION) {
// keyboardItem.setTextSize(getResources().getDimension(R.dimen.default_list_text_size));
// } else {
// keyboardItem.setTextSize(getResources().getDimension(R.dimen.map_button_text_size));
// }
keyboardItem.setText(getItem(position));
}
((TextView) convertView.findViewById(R.id.keyboard_item)).setText(getItem(position));
return convertView;
}