Revert edit texts
This commit is contained in:
parent
c35a97782c
commit
0e247c3c79
10 changed files with 245 additions and 1004 deletions
|
@ -43,7 +43,7 @@
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:focusableInTouchMode="true"/>
|
android:focusableInTouchMode="true"/>
|
||||||
|
|
||||||
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
|
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
||||||
android:id="@+id/latitude_box"
|
android:id="@+id/latitude_box"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -52,15 +52,16 @@
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:layout_marginRight="12dp">
|
android:layout_marginRight="12dp">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.CursorTextView
|
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||||
|
android:inputType="numberSigned"
|
||||||
android:imeOptions="actionNext"
|
android:imeOptions="actionNext"
|
||||||
android:id="@+id/latitude_input_text_view"
|
android:id="@+id/latitude_edit_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
|
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
||||||
|
|
||||||
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
|
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
||||||
android:id="@+id/longitude_box"
|
android:id="@+id/longitude_box"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -69,15 +70,16 @@
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:layout_marginRight="12dp">
|
android:layout_marginRight="12dp">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.CursorTextView
|
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||||
|
android:inputType="numberSigned"
|
||||||
android:imeOptions="actionNext"
|
android:imeOptions="actionNext"
|
||||||
android:id="@+id/longitude_input_text_view"
|
android:id="@+id/longitude_edit_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
|
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
||||||
|
|
||||||
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
|
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
||||||
android:id="@+id/name_box"
|
android:id="@+id/name_box"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -86,14 +88,15 @@
|
||||||
android:layout_marginEnd="10dp"
|
android:layout_marginEnd="10dp"
|
||||||
android:layout_marginRight="10dp">
|
android:layout_marginRight="10dp">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.CursorTextView
|
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||||
|
android:inputType="text"
|
||||||
android:imeOptions="actionDone"
|
android:imeOptions="actionDone"
|
||||||
android:id="@+id/name_input_text_view"
|
android:id="@+id/name_edit_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="@string/access_hint_enter_name"/>
|
android:hint="@string/access_hint_enter_name"/>
|
||||||
|
|
||||||
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
|
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/options_button"
|
android:id="@+id/options_button"
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
|
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
||||||
android:id="@+id/latitude_box"
|
android:id="@+id/latitude_box"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
@ -94,28 +94,30 @@
|
||||||
android:layout_marginRight="16dp"
|
android:layout_marginRight="16dp"
|
||||||
android:layout_marginEnd="16dp">
|
android:layout_marginEnd="16dp">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.CursorTextView
|
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||||
|
android:inputType="numberSigned"
|
||||||
android:imeOptions="actionNext"
|
android:imeOptions="actionNext"
|
||||||
android:id="@+id/latitude_input_text_view"
|
android:id="@+id/latitude_edit_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
|
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
||||||
|
|
||||||
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
|
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
||||||
android:id="@+id/longitude_box"
|
android:id="@+id/longitude_box"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
osmand:labelText="@string/navigate_point_longitude">
|
osmand:labelText="@string/navigate_point_longitude">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.CursorTextView
|
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||||
|
android:inputType="numberSigned"
|
||||||
android:imeOptions="actionNext"
|
android:imeOptions="actionNext"
|
||||||
android:id="@+id/longitude_input_text_view"
|
android:id="@+id/longitude_edit_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
|
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -125,7 +127,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.OsmandTextViewFieldBoxes
|
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
||||||
android:id="@+id/name_box"
|
android:id="@+id/name_box"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
@ -134,14 +136,15 @@
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginRight="16dp">
|
android:layout_marginRight="16dp">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.CursorTextView
|
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||||
|
android:inputType="text"
|
||||||
android:imeOptions="actionDone"
|
android:imeOptions="actionDone"
|
||||||
android:hint="@string/access_hint_enter_name"
|
android:hint="@string/access_hint_enter_name"
|
||||||
android:id="@+id/name_input_text_view"
|
android:id="@+id/name_edit_text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
</net.osmand.plus.widgets.OsmandTextViewFieldBoxes>
|
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:focusableInTouchMode="true"/>
|
android:focusableInTouchMode="true"/>
|
||||||
|
|
||||||
<net.osmand.plus.widgets.OsmandEditTextFieldBoxes
|
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
||||||
android:id="@+id/name_text_box"
|
android:id="@+id/name_text_box"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -26,6 +26,6 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
</net.osmand.plus.widgets.OsmandEditTextFieldBoxes>
|
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -32,6 +32,7 @@ import android.view.WindowManager;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -48,13 +49,13 @@ import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.widgets.OsmandTextViewFieldBoxes;
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
|
import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
|
||||||
|
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -89,8 +90,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
private boolean lightTheme;
|
private boolean lightTheme;
|
||||||
private boolean useOsmandKeyboard = true;
|
private boolean useOsmandKeyboard = true;
|
||||||
private int coordinateFormat = -1;
|
private int coordinateFormat = -1;
|
||||||
private List<OsmandTextViewFieldBoxes> textFieldBoxes;
|
private List<OsmandTextFieldBoxes> textFieldBoxes;
|
||||||
private List<TextView> inputTextViews;
|
private List<EditText> inputEditTexts;
|
||||||
private View mainView;
|
private View mainView;
|
||||||
private IconsCache iconsCache;
|
private IconsCache iconsCache;
|
||||||
private Location location;
|
private Location location;
|
||||||
|
@ -180,11 +181,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
});
|
});
|
||||||
|
|
||||||
textFieldBoxes = new ArrayList<>();
|
textFieldBoxes = new ArrayList<>();
|
||||||
final OsmandTextViewFieldBoxes latitudeBox = (OsmandTextViewFieldBoxes) mainView.findViewById(R.id.latitude_box);
|
final OsmandTextFieldBoxes latitudeBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box);
|
||||||
textFieldBoxes.add(latitudeBox);
|
textFieldBoxes.add(latitudeBox);
|
||||||
final OsmandTextViewFieldBoxes longitudeBox = (OsmandTextViewFieldBoxes) mainView.findViewById(R.id.longitude_box);
|
final OsmandTextFieldBoxes longitudeBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box);
|
||||||
textFieldBoxes.add(longitudeBox);
|
textFieldBoxes.add(longitudeBox);
|
||||||
final OsmandTextViewFieldBoxes nameBox = (OsmandTextViewFieldBoxes) mainView.findViewById(R.id.name_box);
|
final OsmandTextFieldBoxes nameBox = (OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box);
|
||||||
nameBox.setEndIcon(iconsCache.getThemedIcon(R.drawable.ic_action_keyboard));
|
nameBox.setEndIcon(iconsCache.getThemedIcon(R.drawable.ic_action_keyboard));
|
||||||
nameBox.getEndIconImageButton().setOnClickListener(new View.OnClickListener() {
|
nameBox.getEndIconImageButton().setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -202,22 +203,22 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
|
|
||||||
registerTextFieldBoxes();
|
registerTextFieldBoxes();
|
||||||
|
|
||||||
inputTextViews = new ArrayList<>();
|
inputEditTexts = new ArrayList<>();
|
||||||
final TextView latitudeInputTextView = (TextView) mainView.findViewById(R.id.latitude_input_text_view);
|
final EditText latitudeEditText = (EditText) mainView.findViewById(R.id.latitude_edit_text);
|
||||||
inputTextViews.add(latitudeInputTextView);
|
inputEditTexts.add(latitudeEditText);
|
||||||
final TextView longitudeInputTextView = (TextView) mainView.findViewById(R.id.longitude_input_text_view);
|
final EditText longitudeEditText = (EditText) mainView.findViewById(R.id.longitude_edit_text);
|
||||||
inputTextViews.add(longitudeInputTextView);
|
inputEditTexts.add(longitudeEditText);
|
||||||
final TextView nameInputTextView = (TextView) mainView.findViewById(R.id.name_input_text_view);
|
final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text);
|
||||||
inputTextViews.add(nameInputTextView);
|
inputEditTexts.add(nameEditText);
|
||||||
|
|
||||||
registerInputTextViews();
|
registerInputTextViews();
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
latitudeBox.select();
|
latitudeBox.select();
|
||||||
} else {
|
} else {
|
||||||
changeInputTextViewHints();
|
changeInputEditTextHints();
|
||||||
changeInputTextViewLengths();
|
changeInputEditTextsLengths();
|
||||||
changeKeyboardInInputTextViews();
|
changeKeyboardInEditTexts();
|
||||||
}
|
}
|
||||||
|
|
||||||
final View mapMarkersLayout = mainView.findViewById(R.id.map_markers_layout);
|
final View mapMarkersLayout = mainView.findViewById(R.id.map_markers_layout);
|
||||||
|
@ -268,21 +269,21 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||||
View focusedView = getDialog().getCurrentFocus();
|
View focusedView = getDialog().getCurrentFocus();
|
||||||
if (focusedView != null && focusedView instanceof TextView) {
|
if (focusedView != null && focusedView instanceof EditText) {
|
||||||
TextView focusedTextView = (TextView) focusedView;
|
EditText focusedEditText = (EditText) focusedView;
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case CLEAR_BUTTON_POSITION:
|
case CLEAR_BUTTON_POSITION:
|
||||||
focusedTextView.setText("");
|
focusedEditText.setText("");
|
||||||
break;
|
break;
|
||||||
case DELETE_BUTTON_POSITION:
|
case DELETE_BUTTON_POSITION:
|
||||||
String str = focusedTextView.getText().toString();
|
String str = focusedEditText.getText().toString();
|
||||||
if (str.length() > 0) {
|
if (str.length() > 0) {
|
||||||
str = str.substring(0, str.length() - 1);
|
str = str.substring(0, str.length() - 1);
|
||||||
focusedTextView.setText(str);
|
focusedEditText.setText(str);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
focusedTextView.append(keyboardAdapter.getItem(i));
|
focusedEditText.append(keyboardAdapter.getItem(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,7 +354,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (OsmandTextViewFieldBoxes textFieldBox : textFieldBoxes) {
|
for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) {
|
||||||
textFieldBox.getPanel().setOnTouchListener(textFieldBoxOnTouchListener);
|
textFieldBox.getPanel().setOnTouchListener(textFieldBoxOnTouchListener);
|
||||||
}
|
}
|
||||||
changeKeyboardInBoxes();
|
changeKeyboardInBoxes();
|
||||||
|
@ -378,9 +379,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable editable) {
|
public void afterTextChanged(Editable editable) {
|
||||||
View focusedView = getDialog().getCurrentFocus();
|
View focusedView = getDialog().getCurrentFocus();
|
||||||
if (focusedView != null && focusedView instanceof TextView) {
|
if (focusedView != null && focusedView instanceof EditText) {
|
||||||
TextView focusedTextView = (TextView) focusedView;
|
EditText focusedEditText = (EditText) focusedView;
|
||||||
String str = focusedTextView.getText().toString();
|
String str = focusedEditText.getText().toString();
|
||||||
int strLength = str.length();
|
int strLength = str.length();
|
||||||
if (len < strLength) {
|
if (len < strLength) {
|
||||||
String strAfterChanging = str.substring(len);
|
String strAfterChanging = str.substring(len);
|
||||||
|
@ -402,24 +403,26 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
}
|
}
|
||||||
if (strDivider != null) {
|
if (strDivider != null) {
|
||||||
String textToSet = strBeforeChanging + strDivider + strAfterChanging;
|
String textToSet = strBeforeChanging + strDivider + strAfterChanging;
|
||||||
focusedTextView.setText(textToSet);
|
focusedEditText.setText(textToSet);
|
||||||
|
focusedEditText.setSelection(textToSet.length());
|
||||||
}
|
}
|
||||||
} else if (len > strLength) {
|
} else if (len > strLength) {
|
||||||
if (strLength > 0 && (".:").contains(str.substring(strLength - 1))) {
|
if (strLength > 0 && (".:").contains(str.substring(strLength - 1))) {
|
||||||
focusedTextView.setText(str.substring(0, str.length() - 1));
|
focusedEditText.setText(str.substring(0, str.length() - 1));
|
||||||
}
|
}
|
||||||
|
focusedEditText.setSelection(focusedEditText.getText().length());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((strLength == DEGREES_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_DEGREES)
|
if ((strLength == DEGREES_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_DEGREES)
|
||||||
|| (strLength == MINUTES_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_MINUTES)
|
|| (strLength == MINUTES_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_MINUTES)
|
||||||
|| (strLength == SECONDS_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_SECONDS)) {
|
|| (strLength == SECONDS_MAX_LENGTH && coordinateFormat == PointDescription.FORMAT_SECONDS)) {
|
||||||
switchToNextInput(focusedTextView.getId());
|
switchToNextInput(focusedEditText.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
View.OnTouchListener inputTextViewOnTouchListener = new View.OnTouchListener() {
|
View.OnTouchListener inputEditTextOnTouchListener = new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||||
if (useOsmandKeyboard || !orientationPortrait) {
|
if (useOsmandKeyboard || !orientationPortrait) {
|
||||||
|
@ -438,60 +441,61 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
View.OnLongClickListener inputTextViewOnLongClickListener = new View.OnLongClickListener() {
|
View.OnLongClickListener inputEditTextOnLongClickListener = new View.OnLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(final View view) {
|
public boolean onLongClick(final View view) {
|
||||||
final TextView inputTextView = (TextView) view;
|
final EditText inputEditText = (EditText) view;
|
||||||
PopupMenu popupMenu = new PopupMenu(getContext(), inputTextView);
|
PopupMenu popupMenu = new PopupMenu(getContext(), inputEditText);
|
||||||
Menu menu = popupMenu.getMenu();
|
Menu menu = popupMenu.getMenu();
|
||||||
popupMenu.getMenuInflater().inflate(R.menu.copy_paste_menu, menu);
|
popupMenu.getMenuInflater().inflate(R.menu.copy_paste_menu, menu);
|
||||||
final ClipboardManager clipboardManager = ((ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE));
|
final ClipboardManager clipboardManager = ((ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE));
|
||||||
MenuItem pasteMenuItem = menu.findItem(R.id.action_paste);
|
MenuItem pasteMenuItem = menu.findItem(R.id.action_paste);
|
||||||
if (clipboardManager == null || !clipboardManager.hasPrimaryClip() ||
|
if (clipboardManager == null || !clipboardManager.hasPrimaryClip() ||
|
||||||
!clipboardManager.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
|
!clipboardManager.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
|
||||||
pasteMenuItem.setEnabled(false);
|
pasteMenuItem.setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
pasteMenuItem.setEnabled(true);
|
pasteMenuItem.setEnabled(true);
|
||||||
}
|
}
|
||||||
if (clipboardManager != null) {
|
if (clipboardManager != null) {
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_copy:
|
case R.id.action_copy:
|
||||||
String labelText;
|
String labelText;
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.latitude_input_text_view:
|
case R.id.latitude_edit_text:
|
||||||
labelText = LATITUDE_LABEL;
|
labelText = LATITUDE_LABEL;
|
||||||
break;
|
break;
|
||||||
case R.id.longitude_input_text_view:
|
case R.id.longitude_edit_text:
|
||||||
labelText = LONGITUDE_LABEL;
|
labelText = LONGITUDE_LABEL;
|
||||||
break;
|
break;
|
||||||
case R.id.name_input_text_view:
|
case R.id.name_edit_text:
|
||||||
labelText = NAME_LABEL;
|
labelText = NAME_LABEL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
labelText = "";
|
labelText = "";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ClipData clip = ClipData.newPlainText(labelText, inputTextView.getText().toString());
|
ClipData clip = ClipData.newPlainText(labelText, inputEditText.getText().toString());
|
||||||
clipboardManager.setPrimaryClip(clip);
|
clipboardManager.setPrimaryClip(clip);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_paste:
|
case R.id.action_paste:
|
||||||
ClipData.Item pasteItem = clipboardManager.getPrimaryClip().getItemAt(0);
|
ClipData.Item pasteItem = clipboardManager.getPrimaryClip().getItemAt(0);
|
||||||
CharSequence pasteData = pasteItem.getText();
|
CharSequence pasteData = pasteItem.getText();
|
||||||
if (pasteData != null) {
|
if (pasteData != null) {
|
||||||
String str = inputTextView.getText().toString();
|
String str = inputEditText.getText().toString();
|
||||||
inputTextView.setText(str + pasteData.toString());
|
inputEditText.setText(str + pasteData.toString());
|
||||||
}
|
inputEditText.setSelection(inputEditText.getText().length());
|
||||||
return true;
|
}
|
||||||
}
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
});
|
return false;
|
||||||
popupMenu.show();
|
}
|
||||||
}
|
});
|
||||||
return true;
|
popupMenu.show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -501,20 +505,20 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
public void onFocusChange(View view, boolean b) {
|
public void onFocusChange(View view, boolean b) {
|
||||||
int resId;
|
int resId;
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.latitude_input_text_view:
|
case R.id.latitude_edit_text:
|
||||||
resId = R.id.latitude_box;
|
resId = R.id.latitude_box;
|
||||||
break;
|
break;
|
||||||
case R.id.longitude_input_text_view:
|
case R.id.longitude_edit_text:
|
||||||
resId = R.id.longitude_box;
|
resId = R.id.longitude_box;
|
||||||
break;
|
break;
|
||||||
case R.id.name_input_text_view:
|
case R.id.name_edit_text:
|
||||||
resId = R.id.name_box;
|
resId = R.id.name_box;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
resId = 0;
|
resId = 0;
|
||||||
}
|
}
|
||||||
if (resId != 0) {
|
if (resId != 0) {
|
||||||
OsmandTextViewFieldBoxes textFieldBox = mainView.findViewById(resId);
|
OsmandTextFieldBoxes textFieldBox = mainView.findViewById(resId);
|
||||||
if (b) {
|
if (b) {
|
||||||
textFieldBox.setHasFocus(true);
|
textFieldBox.setHasFocus(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -541,12 +545,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (TextView textView : inputTextViews) {
|
for (TextView textView : inputEditTexts) {
|
||||||
// if (textView.getId() != R.id.name_input_text_view) {
|
if (textView.getId() != R.id.name_edit_text) {
|
||||||
// textView.addTextChangedListener(textWatcher);
|
textView.addTextChangedListener(textWatcher);
|
||||||
// }
|
}
|
||||||
textView.setOnTouchListener(inputTextViewOnTouchListener);
|
textView.setOnTouchListener(inputEditTextOnTouchListener);
|
||||||
textView.setOnLongClickListener(inputTextViewOnLongClickListener);
|
textView.setOnLongClickListener(inputEditTextOnLongClickListener);
|
||||||
textView.setOnFocusChangeListener(focusChangeListener);
|
textView.setOnFocusChangeListener(focusChangeListener);
|
||||||
textView.setOnEditorActionListener(inputTextViewOnEditorActionListener);
|
textView.setOnEditorActionListener(inputTextViewOnEditorActionListener);
|
||||||
}
|
}
|
||||||
|
@ -557,8 +561,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
@Override
|
@Override
|
||||||
public void onCoordinateFormatChanged(int format) {
|
public void onCoordinateFormatChanged(int format) {
|
||||||
coordinateFormat = format;
|
coordinateFormat = format;
|
||||||
changeInputTextViewHints();
|
changeInputEditTextHints();
|
||||||
changeInputTextViewLengths();
|
changeInputEditTextsLengths();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -568,7 +572,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
changeOsmandKeyboardVisibility(false);
|
changeOsmandKeyboardVisibility(false);
|
||||||
}
|
}
|
||||||
changeKeyboardInBoxes();
|
changeKeyboardInBoxes();
|
||||||
changeKeyboardInInputTextViews();
|
changeKeyboardInEditTexts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -591,20 +595,20 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeKeyboardInBoxes() {
|
private void changeKeyboardInBoxes() {
|
||||||
for (OsmandTextViewFieldBoxes textFieldBox : textFieldBoxes) {
|
for (OsmandTextFieldBoxes textFieldBox : textFieldBoxes) {
|
||||||
textFieldBox.setUseOsmandKeyboard(useOsmandKeyboard);
|
textFieldBox.setUseOsmandKeyboard(useOsmandKeyboard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeKeyboardInInputTextViews() {
|
private void changeKeyboardInEditTexts() {
|
||||||
int coordinateInputType = useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_NUMBER;
|
// int coordinateInputType = useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_NUMBER;
|
||||||
int nameInputType = useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_TEXT;
|
// int nameInputType = useOsmandKeyboard ? InputType.TYPE_NULL : InputType.TYPE_CLASS_TEXT;
|
||||||
for (TextView inputTextView : inputTextViews) {
|
// for (TextView inputTextView : inputEditTexts) {
|
||||||
inputTextView.setInputType(inputTextView.getId() == R.id.name_input_text_view ? nameInputType : coordinateInputType);
|
// inputTextView.setInputType(inputTextView.getId() == R.id.name_edit_text ? nameInputType : coordinateInputType);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeInputTextViewLengths() {
|
private void changeInputEditTextsLengths() {
|
||||||
int maxLength;
|
int maxLength;
|
||||||
if (coordinateFormat == PointDescription.FORMAT_DEGREES) {
|
if (coordinateFormat == PointDescription.FORMAT_DEGREES) {
|
||||||
maxLength = DEGREES_MAX_LENGTH;
|
maxLength = DEGREES_MAX_LENGTH;
|
||||||
|
@ -614,14 +618,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
maxLength = SECONDS_MAX_LENGTH;
|
maxLength = SECONDS_MAX_LENGTH;
|
||||||
}
|
}
|
||||||
InputFilter[] filtersArray = new InputFilter[] {new InputFilter.LengthFilter(maxLength)};
|
InputFilter[] filtersArray = new InputFilter[] {new InputFilter.LengthFilter(maxLength)};
|
||||||
for (TextView textView : inputTextViews) {
|
for (EditText editText : inputEditTexts) {
|
||||||
if (textView.getId() != R.id.name_input_text_view) {
|
if (editText.getId() != R.id.name_edit_text) {
|
||||||
textView.setFilters(filtersArray);
|
editText.setFilters(filtersArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeInputTextViewHints() {
|
private void changeInputEditTextHints() {
|
||||||
String hint;
|
String hint;
|
||||||
if (coordinateFormat == PointDescription.FORMAT_DEGREES) {
|
if (coordinateFormat == PointDescription.FORMAT_DEGREES) {
|
||||||
hint = DEGREES_HINT;
|
hint = DEGREES_HINT;
|
||||||
|
@ -630,28 +634,28 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
} else {
|
} else {
|
||||||
hint = SECONDS_HINT;
|
hint = SECONDS_HINT;
|
||||||
}
|
}
|
||||||
for (TextView textView : inputTextViews) {
|
for (EditText editText : inputEditTexts) {
|
||||||
if (textView.getId() != R.id.name_input_text_view) {
|
if (editText.getId() != R.id.name_edit_text) {
|
||||||
textView.setHint(hint);
|
editText.setHint(hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchToNextInput(int id) {
|
private void switchToNextInput(int id) {
|
||||||
if (id == R.id.latitude_input_text_view) {
|
if (id == R.id.latitude_edit_text) {
|
||||||
((OsmandTextViewFieldBoxes) mainView.findViewById(R.id.longitude_box)).select();
|
((OsmandTextFieldBoxes) mainView.findViewById(R.id.longitude_box)).select();
|
||||||
} else {
|
} else {
|
||||||
((OsmandTextViewFieldBoxes) mainView.findViewById(R.id.name_box)).select();
|
((OsmandTextFieldBoxes) mainView.findViewById(R.id.name_box)).select();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMapMarker() {
|
private void addMapMarker() {
|
||||||
String latitude = ((TextView) mainView.findViewById(R.id.latitude_input_text_view)).getText().toString();
|
String latitude = ((EditText) mainView.findViewById(R.id.latitude_edit_text)).getText().toString();
|
||||||
String longitude = ((TextView) mainView.findViewById(R.id.longitude_input_text_view)).getText().toString();
|
String longitude = ((EditText) mainView.findViewById(R.id.longitude_edit_text)).getText().toString();
|
||||||
String locPhrase = latitude + ", " + longitude;
|
String locPhrase = latitude + ", " + longitude;
|
||||||
LatLon latLon = MapUtils.parseLocation(locPhrase);
|
LatLon latLon = MapUtils.parseLocation(locPhrase);
|
||||||
if (latLon != null) {
|
if (latLon != null) {
|
||||||
String name = ((TextView) mainView.findViewById(R.id.name_input_text_view)).getText().toString();
|
String name = ((EditText) mainView.findViewById(R.id.name_edit_text)).getText().toString();
|
||||||
addMapMarker(latLon, name);
|
addMapMarker(latLon, name);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getContext(), getString(R.string.wrong_format), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), getString(R.string.wrong_format), Toast.LENGTH_SHORT).show();
|
||||||
|
@ -672,14 +676,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
mapMarkers.add(mapMarker);
|
mapMarkers.add(mapMarker);
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
clearInputs();
|
clearInputs();
|
||||||
((OsmandTextViewFieldBoxes) mainView.findViewById(R.id.latitude_box)).select();
|
((OsmandTextFieldBoxes) mainView.findViewById(R.id.latitude_box)).select();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearInputs() {
|
private void clearInputs() {
|
||||||
for (TextView inputTextView : inputTextViews) {
|
for (EditText inputEditText : inputEditTexts) {
|
||||||
inputTextView.setText("");
|
inputEditText.setText("");
|
||||||
}
|
}
|
||||||
for (OsmandTextViewFieldBoxes osmandTextFieldBox : textFieldBoxes) {
|
for (OsmandTextFieldBoxes osmandTextFieldBox : textFieldBoxes) {
|
||||||
osmandTextFieldBox.deactivate();
|
osmandTextFieldBox.deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import android.widget.LinearLayout;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||||
import net.osmand.plus.widgets.OsmandEditTextFieldBoxes;
|
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||||
|
@ -57,14 +57,14 @@ public class RenameMarkerBottomSheetDialogFragment extends BottomSheetDialogFrag
|
||||||
AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
|
AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_input_text_view);
|
final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text);
|
||||||
nameEditText.setText(marker.getName(mapActivity));
|
nameEditText.setText(marker.getName(mapActivity));
|
||||||
nameEditText.requestFocus();
|
nameEditText.requestFocus();
|
||||||
final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
|
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
|
||||||
View textBox = mainView.findViewById(R.id.name_text_box);
|
View textBox = mainView.findViewById(R.id.name_text_box);
|
||||||
if (textBox instanceof OsmandEditTextFieldBoxes) {
|
if (textBox instanceof OsmandTextFieldBoxes) {
|
||||||
((OsmandEditTextFieldBoxes) textBox).activate(true);
|
((OsmandTextFieldBoxes) textBox).activate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {
|
mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
|
@ -17,7 +17,7 @@ import android.widget.LinearLayout;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.plus.widgets.OsmandEditTextFieldBoxes;
|
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||||
|
@ -73,11 +73,11 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
|
||||||
displayedName = suggestedName + "_" + (++ind);
|
displayedName = suggestedName + "_" + (++ind);
|
||||||
fout = new File(dir, displayedName + GPX_SUFFIX);
|
fout = new File(dir, displayedName + GPX_SUFFIX);
|
||||||
}
|
}
|
||||||
final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_input_text_view);
|
final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text);
|
||||||
nameEditText.setText(displayedName);
|
nameEditText.setText(displayedName);
|
||||||
View textBox = mainView.findViewById(R.id.name_text_box);
|
View textBox = mainView.findViewById(R.id.name_text_box);
|
||||||
if (textBox instanceof OsmandEditTextFieldBoxes) {
|
if (textBox instanceof OsmandTextFieldBoxes) {
|
||||||
((OsmandEditTextFieldBoxes) textBox).activate(true);
|
((OsmandTextFieldBoxes) textBox).activate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {
|
mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
package net.osmand.plus.widgets;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.support.v7.widget.AppCompatTextView;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
|
|
||||||
public class CursorTextView extends AppCompatTextView {
|
|
||||||
|
|
||||||
private Paint linePaint;
|
|
||||||
private Rect bounds;
|
|
||||||
|
|
||||||
public CursorTextView(Context context) {
|
|
||||||
super(context);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CursorTextView(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CursorTextView(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
linePaint = new Paint();
|
|
||||||
linePaint.setAntiAlias(true);
|
|
||||||
linePaint.setFilterBitmap(true);
|
|
||||||
linePaint.setColor(Color.RED);
|
|
||||||
bounds = new Rect();
|
|
||||||
setFocusable(true);
|
|
||||||
setFocusableInTouchMode(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getFreezesText() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas) {
|
|
||||||
super.onDraw(canvas);
|
|
||||||
Paint.FontMetrics fontMetrics = getPaint().getFontMetrics();
|
|
||||||
float height = fontMetrics.bottom - fontMetrics.top + fontMetrics.leading;
|
|
||||||
Paint paint = getPaint();
|
|
||||||
String text = getText().toString();
|
|
||||||
paint.getTextBounds(text, 0, text.length(), bounds);
|
|
||||||
int width = bounds.width();
|
|
||||||
canvas.drawLine(width, 0, width, height, linePaint);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package net.osmand.plus.widgets;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.support.v4.view.ViewCompat;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
|
|
||||||
import studio.carbonylgroup.textfieldboxes.TextFieldBoxes;
|
|
||||||
|
|
||||||
public class OsmandEditTextFieldBoxes extends TextFieldBoxes {
|
|
||||||
|
|
||||||
public OsmandEditTextFieldBoxes(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OsmandEditTextFieldBoxes(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OsmandEditTextFieldBoxes(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void activate(boolean animated) {
|
|
||||||
super.activate(animated);
|
|
||||||
}
|
|
||||||
}
|
|
82
OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java
Normal file
82
OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
package net.osmand.plus.widgets;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v4.view.ViewCompat;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
|
import studio.carbonylgroup.textfieldboxes.TextFieldBoxes;
|
||||||
|
|
||||||
|
public class OsmandTextFieldBoxes extends TextFieldBoxes {
|
||||||
|
|
||||||
|
private boolean useOsmandKeyboard;
|
||||||
|
|
||||||
|
public OsmandTextFieldBoxes(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsmandTextFieldBoxes(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsmandTextFieldBoxes(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseOsmandKeyboard(boolean useOsmandKeyboard) {
|
||||||
|
this.useOsmandKeyboard = useOsmandKeyboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinishInflate() {
|
||||||
|
super.onFinishInflate();
|
||||||
|
if (editText != null) {
|
||||||
|
this.panel.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
select();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.iconImageButton.setOnClickListener(new OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
select();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void select() {
|
||||||
|
if(!OsmandTextFieldBoxes.this.isActivated()) {
|
||||||
|
OsmandTextFieldBoxes.this.activate(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
OsmandTextFieldBoxes.this.setHasFocus(true);
|
||||||
|
if (!useOsmandKeyboard) {
|
||||||
|
OsmandTextFieldBoxes.this.inputMethodManager.showSoftInput(OsmandTextFieldBoxes.this.editText, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activate(boolean animated) {
|
||||||
|
super.activate(animated);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deactivate() {
|
||||||
|
if(this.editText.getText().toString().isEmpty()) {
|
||||||
|
ViewCompat.animate(this.floatingLabel).alpha(1.0F).scaleX(1.0F).scaleY(1.0F).translationY(0.0F).setDuration((long)this.ANIMATION_DURATION);
|
||||||
|
this.editTextLayout.setVisibility(View.INVISIBLE);
|
||||||
|
if(this.editText.hasFocus()) {
|
||||||
|
if (!useOsmandKeyboard) {
|
||||||
|
this.inputMethodManager.hideSoftInputFromWindow(this.editText.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
|
||||||
|
}
|
||||||
|
this.editText.clearFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.activated = false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,765 +0,0 @@
|
||||||
package net.osmand.plus.widgets;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.PorterDuffColorFilter;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.support.v4.content.ContextCompat;
|
|
||||||
import android.support.v4.view.ViewCompat;
|
|
||||||
import android.support.v7.widget.AppCompatImageButton;
|
|
||||||
import android.support.v7.widget.AppCompatTextView;
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
public class OsmandTextViewFieldBoxes extends FrameLayout {
|
|
||||||
public int DEFAULT_ERROR_COLOR;
|
|
||||||
public int DEFAULT_PRIMARY_COLOR;
|
|
||||||
public int DEFAULT_TEXT_COLOR;
|
|
||||||
public int DEFAULT_DISABLED_TEXT_COLOR;
|
|
||||||
public int DEFAULT_BG_COLOR;
|
|
||||||
protected boolean enabled;
|
|
||||||
protected String labelText;
|
|
||||||
protected String helperText;
|
|
||||||
protected int maxCharacters;
|
|
||||||
protected int minCharacters;
|
|
||||||
protected int helperTextColor;
|
|
||||||
protected int errorColor;
|
|
||||||
protected int primaryColor;
|
|
||||||
protected int panelBackgroundColor;
|
|
||||||
protected int iconSignifierResourceId;
|
|
||||||
protected int endIconResourceId;
|
|
||||||
protected boolean isResponsiveIconColor;
|
|
||||||
protected boolean hasClearButton;
|
|
||||||
protected boolean hasFocus;
|
|
||||||
protected View panel;
|
|
||||||
protected View bottomLine;
|
|
||||||
protected ViewGroup editTextLayout;
|
|
||||||
protected AppCompatTextView inputText;
|
|
||||||
protected AppCompatTextView helperLabel;
|
|
||||||
protected AppCompatTextView counterLabel;
|
|
||||||
protected AppCompatTextView floatingLabel;
|
|
||||||
protected AppCompatImageButton clearButton;
|
|
||||||
protected AppCompatImageButton iconImageButton;
|
|
||||||
protected AppCompatImageButton endIconImageButton;
|
|
||||||
protected InputMethodManager inputMethodManager;
|
|
||||||
protected RelativeLayout rightShell;
|
|
||||||
protected RelativeLayout upperPanel;
|
|
||||||
protected RelativeLayout bottomPart;
|
|
||||||
protected RelativeLayout inputLayout;
|
|
||||||
protected int labelColor = -1;
|
|
||||||
protected int labelTopMargin = -1;
|
|
||||||
protected int ANIMATION_DURATION = 100;
|
|
||||||
protected boolean onError = false;
|
|
||||||
protected boolean activated = false;
|
|
||||||
protected boolean doNotRemoveError = false;
|
|
||||||
private boolean useOsmandKeyboard;
|
|
||||||
|
|
||||||
public OsmandTextViewFieldBoxes(Context context) {
|
|
||||||
super(context);
|
|
||||||
this.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OsmandTextViewFieldBoxes(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
this.init();
|
|
||||||
this.handleAttributes(context, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OsmandTextViewFieldBoxes(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
this.init();
|
|
||||||
this.handleAttributes(context, attrs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUseOsmandKeyboard(boolean useOsmandKeyboard) {
|
|
||||||
this.useOsmandKeyboard = useOsmandKeyboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void init() {
|
|
||||||
this.initDefaultColor();
|
|
||||||
this.inputMethodManager = (InputMethodManager)this.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initDefaultColor() {
|
|
||||||
Resources.Theme theme = this.getContext().getTheme();
|
|
||||||
this.DEFAULT_ERROR_COLOR = ContextCompat.getColor(this.getContext(), studio.carbonylgroup.textfieldboxes.R.color.A400red);
|
|
||||||
TypedArray themeArray = theme.obtainStyledAttributes(new int[]{16842800});
|
|
||||||
this.DEFAULT_BG_COLOR = adjustAlpha(themeArray.getColor(0, 0), 0.06F);
|
|
||||||
themeArray = theme.obtainStyledAttributes(new int[]{studio.carbonylgroup.textfieldboxes.R.attr.colorPrimary});
|
|
||||||
if(isLight(this.DEFAULT_BG_COLOR)) {
|
|
||||||
this.DEFAULT_PRIMARY_COLOR = lighter(themeArray.getColor(0, 0), 0.2F);
|
|
||||||
} else {
|
|
||||||
this.DEFAULT_PRIMARY_COLOR = themeArray.getColor(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
themeArray = theme.obtainStyledAttributes(new int[]{16843282});
|
|
||||||
this.DEFAULT_TEXT_COLOR = themeArray.getColor(0, 0);
|
|
||||||
themeArray = theme.obtainStyledAttributes(new int[]{16842803});
|
|
||||||
float disabledAlpha = themeArray.getFloat(0, 0.0F);
|
|
||||||
themeArray = theme.obtainStyledAttributes(new int[]{16843282});
|
|
||||||
this.DEFAULT_DISABLED_TEXT_COLOR = adjustAlpha(themeArray.getColor(0, 0), disabledAlpha);
|
|
||||||
themeArray.recycle();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AppCompatTextView findTextViewChild() {
|
|
||||||
return this.getChildCount() > 0 && this.getChildAt(0) instanceof AppCompatTextView?(AppCompatTextView) this.getChildAt(0):null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onFinishInflate() {
|
|
||||||
super.onFinishInflate();
|
|
||||||
this.inputText = this.findTextViewChild();
|
|
||||||
if(this.inputText != null) {
|
|
||||||
this.addView(LayoutInflater.from(this.getContext()).inflate(studio.carbonylgroup.textfieldboxes.R.layout.text_field_boxes_layout, this, false));
|
|
||||||
this.removeView(this.inputText);
|
|
||||||
this.inputText.setBackgroundColor(0);
|
|
||||||
this.inputLayout = (RelativeLayout)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_input_layout);
|
|
||||||
this.inputLayout.addView(this.inputText);
|
|
||||||
this.inputLayout.setAlpha(0.0F);
|
|
||||||
this.panel = this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_panel);
|
|
||||||
this.floatingLabel = (AppCompatTextView)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_label);
|
|
||||||
this.floatingLabel.setPivotX(0.0F);
|
|
||||||
this.floatingLabel.setPivotY(0.0F);
|
|
||||||
this.bottomLine = this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.bg_bottom_line);
|
|
||||||
this.rightShell = (RelativeLayout)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_right_shell);
|
|
||||||
this.upperPanel = (RelativeLayout)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_upper_panel);
|
|
||||||
this.bottomPart = (RelativeLayout)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_bottom);
|
|
||||||
this.labelColor = this.floatingLabel.getCurrentTextColor();
|
|
||||||
this.clearButton = (AppCompatImageButton)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_clear_button);
|
|
||||||
this.clearButton.setColorFilter(this.DEFAULT_TEXT_COLOR);
|
|
||||||
this.clearButton.setAlpha(0.35F);
|
|
||||||
this.endIconImageButton = (AppCompatImageButton)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_end_icon_button);
|
|
||||||
this.endIconImageButton.setColorFilter(this.DEFAULT_TEXT_COLOR);
|
|
||||||
this.endIconImageButton.setAlpha(0.54F);
|
|
||||||
this.helperLabel = (AppCompatTextView)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_helper);
|
|
||||||
this.counterLabel = (AppCompatTextView)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_counter);
|
|
||||||
this.iconImageButton = (AppCompatImageButton)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_imageView);
|
|
||||||
this.editTextLayout = (ViewGroup)this.findViewById(studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_editTextLayout);
|
|
||||||
this.labelTopMargin = ((RelativeLayout.LayoutParams)RelativeLayout.LayoutParams.class.cast(this.floatingLabel.getLayoutParams())).topMargin;
|
|
||||||
this.panel.setOnClickListener(new OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
select();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.iconImageButton.setOnClickListener(new OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
select();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.inputText.setOnFocusChangeListener(new OnFocusChangeListener() {
|
|
||||||
public void onFocusChange(View view, boolean b) {
|
|
||||||
if(b) {
|
|
||||||
setHasFocus(true);
|
|
||||||
} else {
|
|
||||||
setHasFocus(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.inputText.addTextChangedListener(new TextWatcher() {
|
|
||||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterTextChanged(Editable editable) {
|
|
||||||
if(!doNotRemoveError) {
|
|
||||||
removeError();
|
|
||||||
updateCounterText();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.clearButton.setOnClickListener(new OnClickListener() {
|
|
||||||
public void onClick(View view) {
|
|
||||||
inputText.setText("");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if(!this.inputText.getText().toString().isEmpty() || this.hasFocus) {
|
|
||||||
this.activate(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setLabelText(this.labelText);
|
|
||||||
this.setHelperText(this.helperText);
|
|
||||||
this.setHelperTextColor(this.helperTextColor);
|
|
||||||
this.setErrorColor(this.errorColor);
|
|
||||||
this.setPrimaryColor(this.primaryColor);
|
|
||||||
this.setPanelBackgroundColor(this.panelBackgroundColor);
|
|
||||||
this.setMaxCharacters(this.maxCharacters);
|
|
||||||
this.setMinCharacters(this.minCharacters);
|
|
||||||
this.setEnabled(this.enabled);
|
|
||||||
this.setIconSignifier(this.iconSignifierResourceId);
|
|
||||||
this.setEndIcon(this.endIconResourceId);
|
|
||||||
this.setIsResponsiveIconColor(this.isResponsiveIconColor);
|
|
||||||
this.setHasClearButton(this.hasClearButton);
|
|
||||||
this.setHasFocus(this.hasFocus);
|
|
||||||
this.updateCounterText();
|
|
||||||
this.updateBottomViewVisibility();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void select() {
|
|
||||||
if(!isActivated()) {
|
|
||||||
activate(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
setHasFocus(true);
|
|
||||||
if (!useOsmandKeyboard) {
|
|
||||||
inputMethodManager.showSoftInput(inputText, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
||||||
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
|
||||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
|
||||||
if(widthMode == 1073741824) {
|
|
||||||
this.inputLayout.getLayoutParams().width = -1;
|
|
||||||
this.upperPanel.getLayoutParams().width = -1;
|
|
||||||
this.editTextLayout.getLayoutParams().width = -1;
|
|
||||||
if(this.endIconImageButton.getVisibility() == VISIBLE) {
|
|
||||||
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(1, 0);
|
|
||||||
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(0, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_end_icon_button);
|
|
||||||
if(Build.VERSION.SDK_INT >= 17) {
|
|
||||||
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(17, 0);
|
|
||||||
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(16, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_end_icon_button);
|
|
||||||
}
|
|
||||||
|
|
||||||
((RelativeLayout.LayoutParams)this.endIconImageButton.getLayoutParams()).addRule(1, 0);
|
|
||||||
((RelativeLayout.LayoutParams)this.endIconImageButton.getLayoutParams()).addRule(11);
|
|
||||||
if(Build.VERSION.SDK_INT >= 17) {
|
|
||||||
((RelativeLayout.LayoutParams)this.endIconImageButton.getLayoutParams()).addRule(17, 0);
|
|
||||||
((RelativeLayout.LayoutParams)this.endIconImageButton.getLayoutParams()).addRule(21);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.hasClearButton) {
|
|
||||||
((RelativeLayout.LayoutParams)this.inputLayout.getLayoutParams()).addRule(0, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_clear_button);
|
|
||||||
} else {
|
|
||||||
((RelativeLayout.LayoutParams)this.inputLayout.getLayoutParams()).addRule(0, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_end_icon_button);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(1, 0);
|
|
||||||
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(11);
|
|
||||||
if(Build.VERSION.SDK_INT >= 17) {
|
|
||||||
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(17, 0);
|
|
||||||
((RelativeLayout.LayoutParams)this.clearButton.getLayoutParams()).addRule(21);
|
|
||||||
}
|
|
||||||
|
|
||||||
((RelativeLayout.LayoutParams)this.inputLayout.getLayoutParams()).addRule(0, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_clear_button);
|
|
||||||
}
|
|
||||||
} else if(widthMode == -2147483648) {
|
|
||||||
this.inputLayout.getLayoutParams().width = -2;
|
|
||||||
this.upperPanel.getLayoutParams().width = -2;
|
|
||||||
this.editTextLayout.getLayoutParams().width = -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(heightMode == 1073741824) {
|
|
||||||
this.panel.getLayoutParams().height = -1;
|
|
||||||
this.rightShell.getLayoutParams().height = -1;
|
|
||||||
this.upperPanel.getLayoutParams().height = -1;
|
|
||||||
((RelativeLayout.LayoutParams)this.bottomPart.getLayoutParams()).addRule(3, 0);
|
|
||||||
((RelativeLayout.LayoutParams)this.bottomLine.getLayoutParams()).addRule(3, 0);
|
|
||||||
((RelativeLayout.LayoutParams)this.bottomPart.getLayoutParams()).addRule(12);
|
|
||||||
((RelativeLayout.LayoutParams)this.bottomLine.getLayoutParams()).addRule(12);
|
|
||||||
((RelativeLayout.LayoutParams)this.panel.getLayoutParams()).addRule(2, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_bottom);
|
|
||||||
} else if(heightMode == -2147483648) {
|
|
||||||
this.panel.getLayoutParams().height = -2;
|
|
||||||
this.rightShell.getLayoutParams().height = -2;
|
|
||||||
this.upperPanel.getLayoutParams().height = -2;
|
|
||||||
((RelativeLayout.LayoutParams)this.bottomPart.getLayoutParams()).addRule(3, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_panel);
|
|
||||||
((RelativeLayout.LayoutParams)this.bottomLine.getLayoutParams()).addRule(3, studio.carbonylgroup.textfieldboxes.R.id.text_field_boxes_upper_panel);
|
|
||||||
((RelativeLayout.LayoutParams)this.bottomPart.getLayoutParams()).addRule(12, 0);
|
|
||||||
((RelativeLayout.LayoutParams)this.bottomLine.getLayoutParams()).addRule(12, 0);
|
|
||||||
((RelativeLayout.LayoutParams)this.panel.getLayoutParams()).addRule(2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void handleAttributes(Context context, AttributeSet attrs) {
|
|
||||||
try {
|
|
||||||
TypedArray styledAttrs = context.obtainStyledAttributes(attrs, studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes);
|
|
||||||
this.labelText = styledAttrs.getString(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_labelText) == null?"":styledAttrs.getString(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_labelText);
|
|
||||||
this.helperText = styledAttrs.getString(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_helperText) == null?"":styledAttrs.getString(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_helperText);
|
|
||||||
this.helperTextColor = styledAttrs.getInt(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_helperTextColor, this.DEFAULT_TEXT_COLOR);
|
|
||||||
this.errorColor = styledAttrs.getInt(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_errorColor, this.DEFAULT_ERROR_COLOR);
|
|
||||||
this.primaryColor = styledAttrs.getColor(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_primaryColor, this.DEFAULT_PRIMARY_COLOR);
|
|
||||||
this.panelBackgroundColor = styledAttrs.getColor(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_panelBackgroundColor, this.DEFAULT_BG_COLOR);
|
|
||||||
this.maxCharacters = styledAttrs.getInt(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_maxCharacters, 0);
|
|
||||||
this.minCharacters = styledAttrs.getInt(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_minCharacters, 0);
|
|
||||||
this.enabled = styledAttrs.getBoolean(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_enabled, true);
|
|
||||||
this.iconSignifierResourceId = styledAttrs.getResourceId(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_iconSignifier, 0);
|
|
||||||
this.endIconResourceId = styledAttrs.getResourceId(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_endIcon, 0);
|
|
||||||
this.isResponsiveIconColor = styledAttrs.getBoolean(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_isResponsiveIconColor, true);
|
|
||||||
this.hasClearButton = styledAttrs.getBoolean(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_hasClearButton, false);
|
|
||||||
this.hasFocus = styledAttrs.getBoolean(studio.carbonylgroup.textfieldboxes.R.styleable.TextFieldBoxes_hasFocus, false);
|
|
||||||
styledAttrs.recycle();
|
|
||||||
} catch (Exception var4) {
|
|
||||||
var4.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() {
|
|
||||||
if(this.inputText.getText().toString().isEmpty()) {
|
|
||||||
ViewCompat.animate(this.floatingLabel).alpha(1.0F).scaleX(1.0F).scaleY(1.0F).translationY(0.0F).setDuration((long)this.ANIMATION_DURATION);
|
|
||||||
this.editTextLayout.setVisibility(INVISIBLE);
|
|
||||||
if(this.inputText.hasFocus()) {
|
|
||||||
if (!useOsmandKeyboard) {
|
|
||||||
this.inputMethodManager.hideSoftInputFromWindow(this.inputText.getWindowToken(), 0);
|
|
||||||
}
|
|
||||||
this.inputText.clearFocus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.activated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void activate(boolean animated) {
|
|
||||||
this.editTextLayout.setVisibility(VISIBLE);
|
|
||||||
if(this.inputText.getText().toString().isEmpty() && !this.isActivated()) {
|
|
||||||
this.inputLayout.setAlpha(0.0F);
|
|
||||||
this.floatingLabel.setScaleX(1.0F);
|
|
||||||
this.floatingLabel.setScaleY(1.0F);
|
|
||||||
this.floatingLabel.setTranslationY(0.0F);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(animated) {
|
|
||||||
ViewCompat.animate(this.inputLayout).alpha(1.0F).setDuration((long)this.ANIMATION_DURATION);
|
|
||||||
ViewCompat.animate(this.floatingLabel).scaleX(0.75F).scaleY(0.75F).translationY((float)(-this.labelTopMargin + this.getContext().getResources().getDimensionPixelOffset(studio.carbonylgroup.textfieldboxes.R.dimen.text_field_boxes_margin_top))).setDuration((long)this.ANIMATION_DURATION);
|
|
||||||
} else {
|
|
||||||
this.inputLayout.setAlpha(1.0F);
|
|
||||||
this.floatingLabel.setScaleX(0.75F);
|
|
||||||
this.floatingLabel.setScaleY(0.75F);
|
|
||||||
this.floatingLabel.setTranslationY((float)(-this.labelTopMargin + this.getContext().getResources().getDimensionPixelOffset(studio.carbonylgroup.textfieldboxes.R.dimen.text_field_boxes_margin_top)));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.activated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setHighlightColor(int colorRes) {
|
|
||||||
this.floatingLabel.setTextColor(colorRes);
|
|
||||||
setCursorDrawableColor(this.inputText, colorRes);
|
|
||||||
if(this.getIsResponsiveIconColor()) {
|
|
||||||
this.iconImageButton.setColorFilter(colorRes);
|
|
||||||
if(colorRes == this.DEFAULT_TEXT_COLOR) {
|
|
||||||
this.iconImageButton.setAlpha(0.54F);
|
|
||||||
} else {
|
|
||||||
this.iconImageButton.setAlpha(1.0F);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(colorRes == this.DEFAULT_DISABLED_TEXT_COLOR) {
|
|
||||||
this.iconImageButton.setAlpha(0.35F);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.bottomLine.setBackgroundColor(colorRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateCounterText() {
|
|
||||||
if(this.hasClearButton) {
|
|
||||||
if(this.inputText.getText().toString().length() == 0) {
|
|
||||||
this.showClearButton(false);
|
|
||||||
} else {
|
|
||||||
this.showClearButton(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int length = this.inputText.getText().toString().replaceAll(" ", "").replaceAll("\n", "").length();
|
|
||||||
String lengthStr = Integer.toString(length) + " / ";
|
|
||||||
if(this.maxCharacters > 0) {
|
|
||||||
if(this.minCharacters > 0) {
|
|
||||||
this.counterLabel.setText(lengthStr + Integer.toString(this.minCharacters) + "-" + Integer.toString(this.maxCharacters));
|
|
||||||
if(length >= this.minCharacters && length <= this.maxCharacters) {
|
|
||||||
this.removeCounterError();
|
|
||||||
} else {
|
|
||||||
this.setCounterError();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.counterLabel.setText(lengthStr + Integer.toString(this.maxCharacters) + "");
|
|
||||||
if(length > this.maxCharacters) {
|
|
||||||
this.setCounterError();
|
|
||||||
} else {
|
|
||||||
this.removeCounterError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if(this.minCharacters > 0) {
|
|
||||||
this.counterLabel.setText(lengthStr + Integer.toString(this.minCharacters) + "+");
|
|
||||||
if(length < this.minCharacters) {
|
|
||||||
this.setCounterError();
|
|
||||||
} else {
|
|
||||||
this.removeCounterError();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.counterLabel.setText("");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateBottomViewVisibility() {
|
|
||||||
if(this.helperLabel.getText().toString().isEmpty() && this.counterLabel.getText().toString().isEmpty()) {
|
|
||||||
this.bottomPart.setVisibility(GONE);
|
|
||||||
} else {
|
|
||||||
this.bottomPart.setVisibility(GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setCounterError() {
|
|
||||||
this.onError = true;
|
|
||||||
this.setHighlightColor(this.errorColor);
|
|
||||||
this.counterLabel.setTextColor(this.errorColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void removeCounterError() {
|
|
||||||
this.onError = false;
|
|
||||||
if(this.hasFocus) {
|
|
||||||
this.setHighlightColor(this.primaryColor);
|
|
||||||
} else {
|
|
||||||
this.setHighlightColor(this.DEFAULT_TEXT_COLOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.counterLabel.setTextColor(this.DEFAULT_TEXT_COLOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setError(String errorText, boolean giveFocus) {
|
|
||||||
if(this.enabled) {
|
|
||||||
this.onError = true;
|
|
||||||
this.activate(true);
|
|
||||||
this.setHighlightColor(this.errorColor);
|
|
||||||
this.helperLabel.setTextColor(this.errorColor);
|
|
||||||
this.helperLabel.setText(errorText);
|
|
||||||
if(giveFocus) {
|
|
||||||
this.setHasFocus(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeError() {
|
|
||||||
this.onError = false;
|
|
||||||
if(this.hasFocus) {
|
|
||||||
this.setHighlightColor(this.primaryColor);
|
|
||||||
} else {
|
|
||||||
this.setHighlightColor(this.DEFAULT_TEXT_COLOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.helperLabel.setTextColor(this.helperTextColor);
|
|
||||||
this.helperLabel.setText(this.helperText);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showClearButton(boolean show) {
|
|
||||||
if(show) {
|
|
||||||
this.clearButton.setVisibility(VISIBLE);
|
|
||||||
} else {
|
|
||||||
this.clearButton.setVisibility(GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLabelText(String labelText) {
|
|
||||||
this.labelText = labelText;
|
|
||||||
this.floatingLabel.setText(this.labelText);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHelperText(String helperText) {
|
|
||||||
this.helperText = helperText;
|
|
||||||
this.helperLabel.setText(this.helperText);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHelperTextColor(int colorRes) {
|
|
||||||
this.helperTextColor = colorRes;
|
|
||||||
this.helperLabel.setTextColor(this.helperTextColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorColor(int colorRes) {
|
|
||||||
this.errorColor = colorRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrimaryColor(int colorRes) {
|
|
||||||
this.primaryColor = colorRes;
|
|
||||||
if(this.hasFocus) {
|
|
||||||
this.setHighlightColor(this.primaryColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPanelBackgroundColor(int colorRes) {
|
|
||||||
this.panelBackgroundColor = colorRes;
|
|
||||||
this.panel.getBackground().setColorFilter(new PorterDuffColorFilter(colorRes, PorterDuff.Mode.SRC_IN));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxCharacters(int maxCharacters) {
|
|
||||||
this.maxCharacters = maxCharacters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeMaxCharacters() {
|
|
||||||
this.maxCharacters = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMinCharacters(int minCharacters) {
|
|
||||||
this.minCharacters = minCharacters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeMinCharacters() {
|
|
||||||
this.minCharacters = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnabled(boolean enabled) {
|
|
||||||
this.enabled = enabled;
|
|
||||||
if(this.enabled) {
|
|
||||||
this.inputText.setEnabled(true);
|
|
||||||
this.inputText.setFocusableInTouchMode(true);
|
|
||||||
this.inputText.setFocusable(true);
|
|
||||||
this.helperLabel.setVisibility(VISIBLE);
|
|
||||||
this.counterLabel.setVisibility(VISIBLE);
|
|
||||||
this.bottomLine.setVisibility(VISIBLE);
|
|
||||||
this.panel.setEnabled(true);
|
|
||||||
this.iconImageButton.setEnabled(true);
|
|
||||||
this.iconImageButton.setClickable(true);
|
|
||||||
this.setHighlightColor(this.DEFAULT_TEXT_COLOR);
|
|
||||||
this.updateCounterText();
|
|
||||||
} else {
|
|
||||||
this.removeError();
|
|
||||||
this.setHasFocus(false);
|
|
||||||
this.inputText.setEnabled(false);
|
|
||||||
this.inputText.setFocusableInTouchMode(false);
|
|
||||||
this.inputText.setFocusable(false);
|
|
||||||
this.iconImageButton.setClickable(false);
|
|
||||||
this.iconImageButton.setEnabled(false);
|
|
||||||
this.helperLabel.setVisibility(INVISIBLE);
|
|
||||||
this.counterLabel.setVisibility(INVISIBLE);
|
|
||||||
this.bottomLine.setVisibility(INVISIBLE);
|
|
||||||
this.panel.setEnabled(false);
|
|
||||||
this.setHighlightColor(this.DEFAULT_DISABLED_TEXT_COLOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIconSignifier(int resourceID) {
|
|
||||||
this.iconSignifierResourceId = resourceID;
|
|
||||||
if(this.iconSignifierResourceId != 0) {
|
|
||||||
this.iconImageButton.setImageResource(this.iconSignifierResourceId);
|
|
||||||
this.iconImageButton.setVisibility(VISIBLE);
|
|
||||||
} else {
|
|
||||||
this.removeIconSignifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIconSignifier(Drawable drawable) {
|
|
||||||
this.removeIconSignifier();
|
|
||||||
this.iconImageButton.setImageDrawable(drawable);
|
|
||||||
this.iconImageButton.setVisibility(VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeIconSignifier() {
|
|
||||||
this.iconSignifierResourceId = 0;
|
|
||||||
this.iconImageButton.setVisibility(GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndIcon(int resourceID) {
|
|
||||||
this.endIconResourceId = resourceID;
|
|
||||||
if(this.endIconResourceId != 0) {
|
|
||||||
this.endIconImageButton.setImageResource(this.endIconResourceId);
|
|
||||||
this.endIconImageButton.setVisibility(VISIBLE);
|
|
||||||
} else {
|
|
||||||
this.removeEndIcon();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndIcon(Drawable drawable) {
|
|
||||||
this.removeEndIcon();
|
|
||||||
this.endIconImageButton.setImageDrawable(drawable);
|
|
||||||
this.endIconImageButton.setVisibility(VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeEndIcon() {
|
|
||||||
this.endIconResourceId = 0;
|
|
||||||
this.endIconImageButton.setVisibility(GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasFocus(boolean hasFocus) {
|
|
||||||
this.hasFocus = hasFocus;
|
|
||||||
if(this.hasFocus) {
|
|
||||||
this.activate(true);
|
|
||||||
this.inputText.requestFocus();
|
|
||||||
if(!this.onError && this.enabled) {
|
|
||||||
this.setHighlightColor(this.primaryColor);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.deactivate();
|
|
||||||
if(!this.onError && this.enabled) {
|
|
||||||
this.setHighlightColor(this.DEFAULT_TEXT_COLOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsResponsiveIconColor(boolean isResponsiveIconColor) {
|
|
||||||
this.isResponsiveIconColor = isResponsiveIconColor;
|
|
||||||
if(this.isResponsiveIconColor) {
|
|
||||||
if(this.hasFocus) {
|
|
||||||
this.iconImageButton.setColorFilter(this.primaryColor);
|
|
||||||
this.iconImageButton.setAlpha(1.0F);
|
|
||||||
} else {
|
|
||||||
this.iconImageButton.setColorFilter(this.DEFAULT_TEXT_COLOR);
|
|
||||||
this.iconImageButton.setAlpha(0.54F);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.iconImageButton.setColorFilter(this.primaryColor);
|
|
||||||
this.iconImageButton.setAlpha(1.0F);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasClearButton(boolean hasClearButton) {
|
|
||||||
this.hasClearButton = hasClearButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabelText() {
|
|
||||||
return this.labelText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHelperText() {
|
|
||||||
return this.helperText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCounterText() {
|
|
||||||
return this.counterLabel.getText().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHelperTextColor() {
|
|
||||||
return this.helperTextColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getErrorColor() {
|
|
||||||
return this.errorColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPrimaryColor() {
|
|
||||||
return this.primaryColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPanelBackgroundColor() {
|
|
||||||
return this.panelBackgroundColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxCharacters() {
|
|
||||||
return this.maxCharacters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMinCharacters() {
|
|
||||||
return this.minCharacters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public View getPanel() {
|
|
||||||
return this.panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public View getBottomLine() {
|
|
||||||
return this.bottomLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AppCompatTextView getHelperLabel() {
|
|
||||||
return this.helperLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AppCompatTextView getCounterLabel() {
|
|
||||||
return this.counterLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AppCompatTextView getFloatingLabel() {
|
|
||||||
return this.floatingLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AppCompatImageButton getIconImageButton() {
|
|
||||||
return this.iconImageButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AppCompatImageButton getEndIconImageButton() {
|
|
||||||
return this.endIconImageButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isActivated() {
|
|
||||||
return this.activated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return this.enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIconSignifierResourceId() {
|
|
||||||
return this.iconSignifierResourceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEndIconResourceId() {
|
|
||||||
return this.endIconResourceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getIsResponsiveIconColor() {
|
|
||||||
return this.isResponsiveIconColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getHasClearButton() {
|
|
||||||
return this.hasClearButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getHasFocus() {
|
|
||||||
return this.hasFocus;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void setCursorDrawableColor(AppCompatTextView _inputText, int _colorRes) {
|
|
||||||
try {
|
|
||||||
Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
|
|
||||||
fCursorDrawableRes.setAccessible(true);
|
|
||||||
int mCursorDrawableRes = fCursorDrawableRes.getInt(_inputText);
|
|
||||||
Field fEditor = TextView.class.getDeclaredField("mEditor");
|
|
||||||
fEditor.setAccessible(true);
|
|
||||||
Object editor = fEditor.get(_inputText);
|
|
||||||
Class<?> clazz = editor.getClass();
|
|
||||||
Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
|
|
||||||
fCursorDrawable.setAccessible(true);
|
|
||||||
Drawable[] drawables = new Drawable[]{ContextCompat.getDrawable(_inputText.getContext(), mCursorDrawableRes), ContextCompat.getDrawable(_inputText.getContext(), mCursorDrawableRes)};
|
|
||||||
drawables[0].setColorFilter(_colorRes, PorterDuff.Mode.SRC_IN);
|
|
||||||
drawables[1].setColorFilter(_colorRes, PorterDuff.Mode.SRC_IN);
|
|
||||||
fCursorDrawable.set(editor, drawables);
|
|
||||||
} catch (Throwable var9) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static int lighter(int color, float _factor) {
|
|
||||||
int red = (int)(((float) Color.red(color) * (1.0F - _factor) / 255.0F + _factor) * 255.0F);
|
|
||||||
int green = (int)(((float)Color.green(color) * (1.0F - _factor) / 255.0F + _factor) * 255.0F);
|
|
||||||
int blue = (int)(((float)Color.blue(color) * (1.0F - _factor) / 255.0F + _factor) * 255.0F);
|
|
||||||
return Color.argb(Color.alpha(color), red, green, blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static boolean isLight(int color) {
|
|
||||||
return Math.sqrt((double)(Color.red(color) * Color.red(color)) * 0.241D + (double)(Color.green(color) * Color.green(color)) * 0.691D + (double)(Color.blue(color) * Color.blue(color)) * 0.068D) > 130.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static int adjustAlpha(int color, float _toAlpha) {
|
|
||||||
int alpha = Math.round(255.0F * _toAlpha);
|
|
||||||
int red = Color.red(color);
|
|
||||||
int green = Color.green(color);
|
|
||||||
int blue = Color.blue(color);
|
|
||||||
return Color.argb(alpha, red, green, blue);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue