use of com.codename1.ui.List in project CodenameOne by codenameone.
the class ImageViewer method setImageList.
/**
* By providing this optional list of images you can allows swiping between multiple images
*
* @param model a list of images
*/
public void setImageList(ListModel<Image> model) {
if (model == null || model.getSize() == 0) {
return;
}
if (image == null) {
image = model.getItemAt(0);
}
if (swipeableImages != null) {
swipeableImages.removeDataChangedListener(listListener);
swipeableImages.removeSelectionListener((SelectionListener) listListener);
model.addDataChangedListener(listListener);
model.addSelectionListener((SelectionListener) listListener);
} else {
class Listener implements SelectionListener, DataChangedListener {
public void selectionChanged(int oldSelected, int newSelected) {
if (selectLock) {
return;
}
if (swipeableImages.getSize() > 0 && newSelected > -1 && newSelected < swipeableImages.getSize()) {
setImage(swipeableImages.getItemAt(newSelected));
}
}
public void dataChanged(int type, int index) {
if (swipeableImages.getSize() > 0 && swipeableImages.getSelectedIndex() > -1 && swipeableImages.getSelectedIndex() < swipeableImages.getSize()) {
setImage(swipeableImages.getItemAt(swipeableImages.getSelectedIndex()));
}
}
}
listListener = new Listener();
model.addDataChangedListener(listListener);
model.addSelectionListener((SelectionListener) listListener);
}
this.swipeableImages = model;
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class FaceBookAccess method getAlbumPhotos.
/**
* This method returns a list model of photos that automatically fetches additional images as necessary
* @param targetList required for the image download code
* @param albumId the id of the album
* @param photoCount the number of photos within the album
* @param placeholder a placeholder image that will determine the size of the images requested
* @return the list of the images
*/
private ListModel getAlbumPhotos(final Component targetList, final String albumId, final int photoCount, final Image placeholder) {
if (!isAuthenticated()) {
return null;
}
Hashtable[] h = new Hashtable[photoCount];
int hlen = h.length;
for (int iter = 0; iter < hlen; iter++) {
h[iter] = new Hashtable();
h[iter].put("photo", placeholder);
if (iter < 30) {
h[iter].put("fetching", Boolean.TRUE);
}
}
DefaultListModel dl = new DefaultListModel((Object[]) h) {
public Object getItem(int offset) {
Hashtable hash = (Hashtable) super.getItemAt(offset);
if (!hash.containsKey("fetching")) {
int limit = Math.min(30, photoCount - offset);
for (int iter = 0; iter < limit; iter++) {
Hashtable current = (Hashtable) super.getItemAt(iter + offset);
if (current.containsKey("fetching")) {
break;
}
current.put("fetching", Boolean.TRUE);
}
FacebookRESTService con = new FacebookRESTService(token, albumId, FacebookRESTService.PHOTOS, false);
con.setResponseDestination(this);
con.setResponseOffset(0);
con.addArgument("limit", "" + limit);
con.addArgument("offset", "" + offset);
for (int i = 0; i < responseCodeListeners.size(); i++) {
con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
}
NetworkManager.getInstance().addToQueueAndWait(con);
for (int iter = 0; iter < limit; iter++) {
Hashtable current = (Hashtable) getItemAt(iter + offset);
ImageDownloadService.createImageToStorage((String) current.get("photo"), targetList, iter + offset, "photo", ((String) current.get("id")) + placeholder.getHeight(), placeholder, ConnectionRequest.PRIORITY_NORMAL);
}
}
return hash;
}
};
FacebookRESTService con = new FacebookRESTService(token, albumId, FacebookRESTService.PHOTOS, false);
con.setResponseDestination(dl);
con.setResponseOffset(0);
con.addArgument("limit", "30");
con.addArgument("offset", "0");
for (int i = 0; i < responseCodeListeners.size(); i++) {
con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
}
NetworkManager.getInstance().addToQueueAndWait(con);
for (int iter = 0; iter < Math.min(30, photoCount); iter++) {
Hashtable hash = (Hashtable) dl.getItemAt(iter);
ImageDownloadService.createImageToStorage((String) hash.get("photo"), targetList, iter, "photo", ((String) hash.get("id")) + placeholder.getHeight(), placeholder, ConnectionRequest.PRIORITY_NORMAL);
}
return dl;
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class RangeBarChart 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 seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) {
int seriesNr = mDataset.getSeriesCount();
int length = points.size();
paint.setColor(seriesRenderer.getColor());
paint.setStyle(Style.FILL);
float halfDiffX = getHalfDiffX(points, length, seriesNr);
int start = 0;
if (startIndex > 0) {
start = 2;
}
for (int i = start; i < length; i += 4) {
if (points.size() > i + 3) {
float xMin = points.get(i);
float yMin = points.get(i + 1);
// xMin = xMax
float xMax = points.get(i + 2);
float yMax = points.get(i + 3);
drawBar(canvas, xMin, yMin, xMax, yMax, halfDiffX, seriesNr, seriesIndex, paint);
}
}
paint.setColor(seriesRenderer.getColor());
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class ScatterChart method clickableAreasForPoints.
@Override
protected ClickableArea[] clickableAreasForPoints(List<Float> points, List<Double> values, float yAxisValue, int seriesIndex, int startIndex) {
int length = points.size();
ClickableArea[] ret = new ClickableArea[length / 2];
for (int i = 0; i < length; i += 2) {
int selectableBuffer = mRenderer.getSelectableBuffer();
ret[i / 2] = new ClickableArea(PkgUtils.makeRect(points.get(i) - selectableBuffer, points.get(i + 1) - selectableBuffer, points.get(i) + selectableBuffer, points.get(i + 1) + selectableBuffer), values.get(i), values.get(i + 1));
}
return ret;
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class XYChart method drawYLabels.
/**
* The graphical representation of the labels on the Y axis.
*
* @param allYLabels the Y labels values
* @param canvas the canvas to paint to
* @param paint the paint to be used for drawing
* @param maxScaleNumber the maximum scale number
* @param left the left value of the labels area
* @param right the right value of the labels area
* @param bottom the bottom value of the labels area
* @param yPixelsPerUnit the amount of pixels per one unit in the chart labels
* @param minY the minimum value on the Y axis in the chart
*/
protected void drawYLabels(Map<Integer, List<Double>> allYLabels, Canvas canvas, Paint paint, int maxScaleNumber, int left, int right, int bottom, double[] yPixelsPerUnit, double[] minY) {
Orientation or = mRenderer.getOrientation();
boolean showGridX = mRenderer.isShowGridX();
boolean showLabels = mRenderer.isShowLabels();
boolean showTickMarks = mRenderer.isShowTickMarks();
paint.setTextSize(mRenderer.getLabelsTextSize());
for (int i = 0; i < maxScaleNumber; i++) {
paint.setTextAlign(mRenderer.getYLabelsAlign(i));
List<Double> yLabels = allYLabels.get(i);
int length = yLabels.size();
for (int j = 0; j < length; j++) {
double label = yLabels.get(j);
int axisAlign = mRenderer.getYAxisAlign(i);
boolean textLabel = mRenderer.getYTextLabel(label, i) != null;
float yLabel = (float) (bottom - yPixelsPerUnit[i] * (label - minY[i]));
if (or == Orientation.HORIZONTAL) {
if (showLabels && !textLabel) {
paint.setColor(mRenderer.getYLabelsColor(i));
if (axisAlign == Align.LEFT) {
if (showTickMarks) {
canvas.drawLine(left + getLabelLinePos(axisAlign), yLabel, left, yLabel, paint);
}
drawText(canvas, getLabel(mRenderer.getYLabelFormat(i), label), left - mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
} else {
if (showTickMarks) {
canvas.drawLine(right, yLabel, right + getLabelLinePos(axisAlign), yLabel, paint);
}
drawText(canvas, getLabel(mRenderer.getYLabelFormat(i), label), right + mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
}
}
if (showGridX) {
paint.setColor(mRenderer.getGridColor(i));
canvas.drawLine(left, yLabel, right, yLabel, paint);
}
} else if (or == Orientation.VERTICAL) {
if (showLabels && !textLabel) {
paint.setColor(mRenderer.getYLabelsColor(i));
if (showTickMarks) {
canvas.drawLine(right - getLabelLinePos(axisAlign), yLabel, right, yLabel, paint);
}
drawText(canvas, getLabel(mRenderer.getLabelFormat(), label), right + 10 + mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
}
if (showGridX) {
paint.setColor(mRenderer.getGridColor(i));
if (showTickMarks) {
canvas.drawLine(right, yLabel, left, yLabel, paint);
}
}
}
}
}
}
Aggregations