use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.
the class LinesLayer method paintSegment.
/**
* Paint a segment.
*
* @param g a Graphics Object to paint on
* @param segment array of Coord to draw a Line.
* @param tile
*/
protected void paintSegment(Graphics g, Coord[] segment, Tile tile) {
int pointsNo = segment.length;
for (int i = 1; i < pointsNo; i++) {
Coord start = (Coord) segment[i - 1];
Coord end = (Coord) segment[i];
Point s = tile.pointPosition(start);
Point e = tile.pointPosition(end);
g.drawLine(s.getX(), s.getY(), e.getX(), e.getY());
// lame & simple way to make line thicker
g.drawLine(s.getX() - 1, s.getY(), e.getX() - 1, e.getY());
g.drawLine(s.getX() + 1, s.getY(), e.getX() + 1, e.getY());
g.drawLine(s.getX(), s.getY() - 1, e.getX(), e.getY() - 1);
g.drawLine(s.getX(), s.getY() + 1, e.getX(), e.getY() + 1);
}
}
use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.
the class PointsLayer method addPoint.
/**
* Adds a point to the PointsLayer
*
* @param point a point to add
*/
public void addPoint(PointLayer point) {
Image pointIcon = point.getIcon();
if (pointIcon == null) {
point.setIcon(icon);
}
if (!point.isProjected()) {
Coord c = getProjection().fromWGS84(point);
point.setLatitude(c.getLatitude());
point.setLongitude(c.getLongitude());
point.setProjected(true);
}
points.addElement(point);
}
use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.
the class ResetableTextWatcher method edit.
/**
* Entry point for using this class
* @param impl The current running activity
* @param component Any subclass of com.codename1.ui.TextArea
* @param inputType One of the TextArea's input-type constants
*/
public static void edit(final AndroidImplementation impl, final Component component, final int inputType) {
if (impl.getActivity() == null) {
throw new IllegalArgumentException("activity is null");
}
if (component == null) {
throw new IllegalArgumentException("component is null");
}
if (!(component instanceof TextArea)) {
throw new IllegalArgumentException("component must be instance of TextArea");
}
final TextArea textArea = (TextArea) component;
final String initialText = textArea.getText();
textArea.putClientProperty("InPlaceEditView.initialText", initialText);
// The very first time we try to edit a string, let's determine if the
// system default is to do async editing. If the system default
// is not yet set, we set it here, and it will be used as the default from now on
// We do this because the nativeInstance.isAsyncEditMode() value changes
// to reflect the currently edited field so it isn't a good way to keep a
// system default.
String defaultAsyncEditingSetting = Display.getInstance().getProperty("android.VKBAlwaysOpen", null);
if (defaultAsyncEditingSetting == null) {
defaultAsyncEditingSetting = impl.isAsyncEditMode() ? "true" : "false";
Display.getInstance().setProperty("android.VKBAlwaysOpen", defaultAsyncEditingSetting);
}
boolean asyncEdit = "true".equals(defaultAsyncEditingSetting) ? true : false;
// Check if the form has any setting for asyncEditing that should override
// the application defaults.
final Form parentForm = component.getComponentForm();
if (parentForm == null) {
com.codename1.io.Log.p("Attempt to edit text area that is not on a form. This is not supported");
return;
}
if (parentForm.getClientProperty("asyncEditing") != null) {
Object async = parentForm.getClientProperty("asyncEditing");
if (async instanceof Boolean) {
asyncEdit = ((Boolean) async).booleanValue();
// Log.p("Form overriding asyncEdit due to asyncEditing client property: "+asyncEdit);
}
}
if (parentForm.getClientProperty("android.asyncEditing") != null) {
Object async = parentForm.getClientProperty("android.asyncEditing");
if (async instanceof Boolean) {
asyncEdit = ((Boolean) async).booleanValue();
// Log.p("Form overriding asyncEdit due to ios.asyncEditing client property: "+asyncEdit);
}
}
if (parentForm.isFormBottomPaddingEditingMode()) {
asyncEdit = true;
}
// then this will override all other settings.
if (component.getClientProperty("asyncEditing") != null) {
Object async = component.getClientProperty("asyncEditing");
if (async instanceof Boolean) {
asyncEdit = ((Boolean) async).booleanValue();
// Log.p("Overriding asyncEdit due to field asyncEditing client property: "+asyncEdit);
}
}
if (component.getClientProperty("android.asyncEditing") != null) {
Object async = component.getClientProperty("android.asyncEditing");
if (async instanceof Boolean) {
asyncEdit = ((Boolean) async).booleanValue();
// Log.p("Overriding asyncEdit due to field ios.asyncEditing client property: "+asyncEdit);
}
}
// if true, then in async mode we are currently editing and are switching to another field
final boolean isEditedFieldSwitch;
// If we are already editing, we need to finish that up before we proceed to edit the next field.
synchronized (editingLock) {
if (mIsEditing) {
if (impl.isAsyncEditMode()) {
// Using isEditedFieldSwitch was causing issues with cursors not showing up.
// https://github.com/codenameone/CodenameOne/issues/2353
// https://stackoverflow.com/questions/49004370/focus-behaviour-in-textarea-in-cn1
// Disabling this feature by default now, but can be re-enabled by setting
// Display.getInstance().setProperty("android.reuseTextEditorOnSwitch", "true");
// This editedFieldSwitch feature was added a while back to improve experience on older
// Android devices where the field switching was going too slow.
// https://github.com/codenameone/CodenameOne/issues/2012
// This issue was resolved in this commit (https://github.com/jaanushansen/CodenameOne/commit/f3e53a80704149e4d7cde276d01c1368bcdcfe2c)
// which was submitted as part of a pull request. This fix has been the source of several
// regressions, mostly related to properties not being propagated properly when a text field is changed
// However, this issue (with the cursor not showing up), doesn't appear to have a simple solution
// so, I'm disabling this feature for now.
isEditedFieldSwitch = "true".equals(Display.getInstance().getProperty("android.reuseTextEditorOnSwitch", "false"));
final String[] out = new String[1];
TextArea prevTextArea = null;
if (sInstance != null && sInstance.mLastEditText != null) {
prevTextArea = sInstance.mLastEditText.getTextArea();
}
if (prevTextArea != null) {
final TextArea fPrevTextArea = prevTextArea;
final String retVal = sInstance.mLastEditText.getText().toString();
Display.getInstance().callSerially(new Runnable() {
public void run() {
Display.getInstance().onEditingComplete(fPrevTextArea, retVal);
}
});
}
InPlaceEditView.setEditedTextField(textArea);
nextTextArea = null;
} else {
isEditedFieldSwitch = false;
final InPlaceEditView instance = sInstance;
if (instance != null && instance.mEditText != null && instance.mEditText.mTextArea == textArea) {
instance.showTextEditorAgain();
return;
}
if (!isClosing && sInstance != null && sInstance.mEditText != null) {
isClosing = true;
impl.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
instance.endEditing(REASON_UNDEFINED, true, 0);
}
});
}
afterClose = new Runnable() {
@Override
public void run() {
impl.callHideTextEditor();
Display.getInstance().editString(component, textArea.getMaxSize(), inputType, textArea.getText());
}
};
return;
}
} else {
isEditedFieldSwitch = false;
}
mIsEditing = true;
isClosing = false;
afterClose = null;
}
impl.setAsyncEditMode(asyncEdit);
// textArea.setPreferredSize(prefSize);
if (!impl.isAsyncEditMode() && textArea instanceof TextField) {
((TextField) textArea).setEditable(false);
}
final boolean scrollableParent = isScrollableParent(textArea);
// We wrap the text area so that we can safely pass data across to the
// android UI thread.
final TextAreaData textAreaData = new TextAreaData(textArea);
impl.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (!isEditedFieldSwitch) {
releaseEdit();
if (sInstance == null) {
sInstance = new InPlaceEditView(impl);
impl.relativeLayout.addView(sInstance);
}
// Let's try something new here
// We'll ALWAYS try resize edit mode (since it just works better)
// But we'll detect whether the field is still covered by the keyboard
// and switch to pan mode if necessary.
}
if (scrollableParent || parentForm.isFormBottomPaddingEditingMode()) {
setEditMode(true);
} else {
trySetEditMode(true);
}
sInstance.startEditing(impl.getActivity(), textAreaData, initialText, inputType, isEditedFieldSwitch);
}
});
final String[] out = new String[1];
// In order to reuse the code the runs after edit completion, we will wrap it in a runnable
// For sync edit mode, we will just run onComplete.run() at the end of this method. For
// Async mode we add the Runnable to the textarea as a client property, then run it
// when editing eventually completes.
Runnable onComplete = new Runnable() {
public void run() {
if (!impl.isAsyncEditMode() && textArea instanceof TextField) {
((TextField) textArea).setEditable(true);
}
textArea.setPreferredSize(null);
if (sInstance != null && sInstance.mLastEditText != null && sInstance.mLastEditText.mTextArea == textArea) {
String retVal = sInstance.mLastEditText.getText().toString();
if (!impl.isAsyncEditMode()) {
sInstance.mLastEditText = null;
impl.getActivity().runOnUiThread(new Runnable() {
public void run() {
releaseEdit();
}
});
}
out[0] = retVal;
} else {
out[0] = initialText;
}
Display.getInstance().onEditingComplete(component, out[0]);
if (impl.isAsyncEditMode()) {
impl.callHideTextEditor();
} else {
// lock.
if (sInstance != null) {
Display.getInstance().invokeAndBlock(new Runnable() {
public void run() {
while (sInstance != null) {
com.codename1.io.Util.sleep(5);
}
}
});
}
}
// Release the editing flag
synchronized (editingLock) {
mIsEditing = false;
}
// as a runnable ... this should take priority over the "nextTextArea" setting
if (afterClose != null) {
Display.getInstance().callSerially(afterClose);
} else if (nextTextArea != null) {
final TextArea next = nextTextArea;
nextTextArea = null;
next.requestFocus();
Display.getInstance().callSerially(new Runnable() {
public void run() {
Display.getInstance().editString(next, next.getMaxSize(), next.getConstraint(), next.getText());
}
});
}
}
};
textArea.requestFocus();
textArea.repaint();
if (impl.isAsyncEditMode()) {
component.putClientProperty("android.onAsyncEditingComplete", onComplete);
return;
}
// Make this call synchronous
// We set this flag so that waitForEditCompletion can block on it.
// The flag will be released inside the endEditing method which will
// allow the method to proceed.
waitingForSynchronousEditingCompletion = true;
waitForEditCompletion();
onComplete.run();
}
use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.
the class ScatterChart method drawSeries.
/**
* The graphical representation of a series.
*
* @param canvas the canvas to paint to
* @param paint the paint to be used for drawing
* @param points the array of points to be used for drawing the series
* @param seriesRenderer the series renderer
* @param yAxisValue the minimum value of the y axis
* @param seriesIndex the index of the series currently being drawn
* @param startIndex the start index of the rendering points
*/
@Override
public void drawSeries(Canvas canvas, Paint paint, List<Float> points, XYSeriesRenderer renderer, float yAxisValue, int seriesIndex, int startIndex) {
paint.setColor(renderer.getColor());
final float stroke = paint.getStrokeWidth();
if (renderer.isFillPoints()) {
paint.setStyle(Style.FILL);
} else {
paint.setStrokeWidth(renderer.getPointStrokeWidth());
paint.setStyle(Style.STROKE);
}
int length = points.size();
// switch on ENUM's generates reflection code that screws up J2ME
PointStyle ps = renderer.getPointStyle();
if (ps == PointStyle.X) {
paint.setStrokeWidth(renderer.getPointStrokeWidth());
for (int i = 0; i < length; i += 2) {
drawX(canvas, paint, points.get(i), points.get(i + 1));
}
} else {
if (ps == PointStyle.CIRCLE) {
for (int i = 0; i < length; i += 2) {
drawCircle(canvas, paint, points.get(i), points.get(i + 1));
}
} else {
if (ps == PointStyle.TRIANGLE) {
float[] path = new float[6];
for (int i = 0; i < length; i += 2) {
drawTriangle(canvas, paint, path, points.get(i), points.get(i + 1));
}
} else {
if (ps == PointStyle.SQUARE) {
for (int i = 0; i < length; i += 2) {
drawSquare(canvas, paint, points.get(i), points.get(i + 1));
}
} else {
if (ps == PointStyle.DIAMOND) {
float[] path = new float[8];
for (int i = 0; i < length; i += 2) {
drawDiamond(canvas, paint, path, points.get(i), points.get(i + 1));
}
} else {
if (ps == PointStyle.POINT) {
for (int i = 0; i < length; i += 2) {
canvas.drawPoint(points.get(i), points.get(i + 1), paint);
}
}
}
}
}
}
}
/*switch (renderer.getPointStyle()) {
case X:
paint.setStrokeWidth(renderer.getPointStrokeWidth());
for (int i = 0; i < length; i += 2) {
drawX(canvas, paint, points.get(i), points.get(i + 1));
}
break;
case CIRCLE:
for (int i = 0; i < length; i += 2) {
drawCircle(canvas, paint, points.get(i), points.get(i + 1));
}
break;
case TRIANGLE:
float[] path = new float[6];
for (int i = 0; i < length; i += 2) {
drawTriangle(canvas, paint, path, points.get(i), points.get(i + 1));
}
break;
case SQUARE:
for (int i = 0; i < length; i += 2) {
drawSquare(canvas, paint, points.get(i), points.get(i + 1));
}
break;
case DIAMOND:
path = new float[8];
for (int i = 0; i < length; i += 2) {
drawDiamond(canvas, paint, path, points.get(i), points.get(i + 1));
}
break;
case POINT:
for (int i = 0; i < length; i += 2) {
canvas.drawPoint(points.get(i), points.get(i + 1), paint);
}
break;
}*/
paint.setStrokeWidth(stroke);
}
use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.
the class XYChart method drawChartValuesText.
/**
* The graphical representation of the series values as text.
*
* @param canvas the canvas to paint to
* @param series the series to be painted
* @param renderer the series renderer
* @param paint the paint to be used for drawing
* @param points the array of points to be used for drawing the series
* @param seriesIndex the index of the series currently being drawn
* @param startIndex the start index of the rendering points
*/
protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRenderer renderer, Paint paint, List<Float> points, int seriesIndex, int startIndex) {
if (points.size() > 2) {
// there are more than one point
// record the first point's position
float previousPointX = points.get(0);
float previousPointY = points.get(1);
for (int k = 0; k < points.size(); k += 2) {
if (k == 2) {
// not
if (Math.abs(points.get(2) - points.get(0)) > renderer.getDisplayChartValuesDistance() || Math.abs(points.get(3) - points.get(1)) > renderer.getDisplayChartValuesDistance()) {
// first point
drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex)), points.get(0), points.get(1) - renderer.getChartValuesSpacing(), paint, 0);
// second point
drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + 1)), points.get(2), points.get(3) - renderer.getChartValuesSpacing(), paint, 0);
previousPointX = points.get(2);
previousPointY = points.get(3);
}
} else if (k > 2) {
// are not too close, display
if (Math.abs(points.get(k) - previousPointX) > renderer.getDisplayChartValuesDistance() || Math.abs(points.get(k + 1) - previousPointY) > renderer.getDisplayChartValuesDistance()) {
drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + k / 2)), points.get(k), points.get(k + 1) - renderer.getChartValuesSpacing(), paint, 0);
previousPointX = points.get(k);
previousPointY = points.get(k + 1);
}
}
}
} else {
// if only one point, display it
for (int k = 0; k < points.size(); k += 2) {
drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + k / 2)), points.get(k), points.get(k + 1) - renderer.getChartValuesSpacing(), paint, 0);
}
}
}
Aggregations