use of com.codename1.tools.translator.bytecodes.Field in project CodenameOne by codenameone.
the class FaceBookAccess method getUserNotifications.
/**
* Gets the user notifications (this method uses the legacy rest api see http://developers.facebook.com/docs/reference/rest/)
*
* @param userId the user id
* @param startTime Indicates the earliest time to return a notification.
* This equates to the updated_time field in the notification FQL table. If not specified, this call returns all available notifications.
* @param includeRead Indicates whether to include notifications that have already been read.
* By default, notifications a user has read are not included.
* @param notifications store notifications results into the given model,
* each entry is an Hashtable Object contaning the Object data
* @param callback the callback that should be updated when the data arrives
*/
public void getUserNotifications(String userId, String startTime, boolean includeRead, DefaultListModel notifications, final ActionListener callback) throws IOException {
checkAuthentication();
final FacebookRESTService con = new FacebookRESTService(token, "https://api.facebook.com/method/notifications.getList", false);
con.addArgument("start_time", startTime);
con.addArgument("include_read", new Boolean(includeRead).toString());
con.addArgument("format", "json");
con.setResponseDestination(notifications);
con.addResponseListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (!con.isAlive()) {
return;
}
if (callback != null) {
callback.actionPerformed(evt);
}
}
});
if (slider != null) {
SliderBridge.bindProgress(con, slider);
}
for (int i = 0; i < responseCodeListeners.size(); i++) {
con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
}
current = con;
NetworkManager.getInstance().addToQueue(con);
}
use of com.codename1.tools.translator.bytecodes.Field in project CodenameOne by codenameone.
the class ClearableTextField method wrap.
/**
* Wraps the given text field with a UI that will allow us to clear it
* @param tf the text field
* @param iconSize size in millimeters for the clear icon, -1 for default size
* @return a Container that should be added to the UI instead of the actual text field
*/
public static ClearableTextField wrap(final TextArea tf, float iconSize) {
ClearableTextField cf = new ClearableTextField();
Button b = new Button("", tf.getUIID());
if (iconSize > 0) {
FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR, iconSize);
} else {
FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR);
}
removeCmpBackground(tf);
removeCmpBackground(b);
cf.setUIID(tf.getUIID());
cf.add(BorderLayout.CENTER, tf);
cf.add(BorderLayout.EAST, b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
tf.stopEditing();
tf.setText("");
tf.startEditingAsync();
}
});
return cf;
}
use of com.codename1.tools.translator.bytecodes.Field in project CodenameOne by codenameone.
the class DefaultLookAndFeel method getTextFieldCursorX.
/**
* Calculates the position of the text field cursor within the string
*/
private int getTextFieldCursorX(TextArea ta) {
Style style = ta.getStyle();
Font f = style.getFont();
// display ******** if it is a password field
String displayText = getTextFieldString(ta);
String inputMode = ta.getInputMode();
int inputModeWidth = f.stringWidth(inputMode);
// QWERTY devices don't quite have an input mode hide it also when we have a VK
if (ta.isQwertyInput() || Display.getInstance().isVirtualKeyboardShowing()) {
inputMode = "";
inputModeWidth = 0;
}
int xPos = 0;
int cursorCharPosition = ta.getCursorX();
int cursorX = 0;
int x = 0;
if (reverseAlignForBidi(ta) == Component.RIGHT) {
if (Display.getInstance().isBidiAlgorithm()) {
// char[] dest = displayText.toCharArray();
cursorCharPosition = Display.getInstance().getCharLocation(displayText, cursorCharPosition - 1);
if (cursorCharPosition == -1) {
xPos = f.stringWidth(displayText);
} else {
displayText = Display.getInstance().convertBidiLogicalToVisual(displayText);
if (!isRTLOrWhitespace((displayText.charAt(cursorCharPosition)))) {
cursorCharPosition++;
}
xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
}
}
int displayX = ta.getX() + ta.getWidth() - style.getPaddingLeft(ta.isRTL()) - f.stringWidth(displayText);
cursorX = displayX + xPos;
x = 0;
} else {
if (cursorCharPosition > 0) {
cursorCharPosition = Math.min(displayText.length(), cursorCharPosition);
xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
}
cursorX = ta.getX() + style.getPaddingLeft(ta.isRTL()) + xPos;
if (ta.isSingleLineTextArea() && ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL())) {
if (x + xPos >= ta.getWidth() - inputModeWidth - style.getPaddingLeftNoRTL() - style.getPaddingRightNoRTL()) {
x = ta.getWidth() - inputModeWidth - style.getPaddingLeftNoRTL() - style.getPaddingRightNoRTL() - xPos - 1;
}
}
}
return cursorX + x;
}
use of com.codename1.tools.translator.bytecodes.Field in project CodenameOne by codenameone.
the class JavaSEPort method loadSkinFile.
private void loadSkinFile(InputStream skin, final JFrame frm) {
try {
ZipInputStream z = new ZipInputStream(skin);
ZipEntry e = z.getNextEntry();
final Properties props = new Properties();
BufferedImage map = null;
BufferedImage landscapeMap = null;
// if we load the native theme imediately the multi-image's will be loaded with the size of the old skin
byte[] nativeThemeData = null;
nativeThemeRes = null;
nativeTheme = null;
while (e != null) {
String name = e.getName();
if (name.equals("skin.png")) {
portraitSkin = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("header.png")) {
header = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("header_l.png")) {
headerLandscape = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin.properties")) {
props.load(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_l.png")) {
landscapeSkin = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_map.png")) {
map = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_map_l.png")) {
landscapeMap = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.endsWith(".res")) {
long esize = e.getSize();
if (esize > 0) {
nativeThemeData = new byte[(int) esize];
readFully(z, nativeThemeData);
} else {
ByteArrayOutputStream b = new ByteArrayOutputStream();
Util.copyNoClose(z, b, 8192);
nativeThemeData = b.toByteArray();
}
e = z.getNextEntry();
continue;
}
if (name.endsWith(".ttf")) {
try {
java.awt.Font result = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, z);
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(result);
} catch (FontFormatException ex) {
ex.printStackTrace();
}
e = z.getNextEntry();
continue;
}
e = z.getNextEntry();
}
z.close();
String ppi = props.getProperty("ppi");
if (ppi != null) {
double ppiD = Double.valueOf(ppi);
pixelMilliRatio = ppiD / 25.4;
} else {
String pix = props.getProperty("pixelRatio");
if (pix != null && pix.length() > 0) {
try {
pixelMilliRatio = Double.valueOf(pix);
} catch (NumberFormatException err) {
err.printStackTrace();
pixelMilliRatio = null;
}
} else {
pixelMilliRatio = null;
}
}
portraitSkinHotspots = new HashMap<Point, Integer>();
portraitScreenCoordinates = new Rectangle();
landscapeSkinHotspots = new HashMap<Point, Integer>();
landscapeScreenCoordinates = new Rectangle();
if (props.getProperty("roundScreen", "false").equalsIgnoreCase("true")) {
portraitScreenCoordinates.x = Integer.parseInt(props.getProperty("displayX"));
portraitScreenCoordinates.y = Integer.parseInt(props.getProperty("displayY"));
portraitScreenCoordinates.width = Integer.parseInt(props.getProperty("displayWidth"));
portraitScreenCoordinates.height = Integer.parseInt(props.getProperty("displayHeight"));
landscapeScreenCoordinates.x = portraitScreenCoordinates.y;
landscapeScreenCoordinates.y = portraitScreenCoordinates.x;
landscapeScreenCoordinates.width = portraitScreenCoordinates.height;
landscapeScreenCoordinates.height = portraitScreenCoordinates.width;
roundedSkin = true;
} else {
initializeCoordinates(map, props, portraitSkinHotspots, portraitScreenCoordinates);
initializeCoordinates(landscapeMap, props, landscapeSkinHotspots, landscapeScreenCoordinates);
}
platformName = props.getProperty("platformName", "se");
platformOverrides = props.getProperty("overrideNames", "").split(",");
String ua = null;
if (platformName.equals("and")) {
ua = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
} else if (platformName.equals("rim")) {
ua = "Mozilla/5.0 (BlackBerry; U; BlackBerry 9860; en-GB) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.296 Mobile Safari/534.11+";
} else if (platformName.equals("ios")) {
if (isTablet()) {
ua = "Mozilla/5.0 (iPad; U; CPU OS 4_3_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4 Safari/6533.18.5";
} else {
ua = "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5";
}
} else if (platformName.equals("me")) {
ua = "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124";
} else {
if (platformName.equals("win")) {
ua = "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800)";
} else {
ua = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
}
}
Display.getInstance().setProperty("User-Agent", ua);
isIOS = props.getProperty("systemFontFamily", "Arial").toLowerCase().contains("helvetica");
setFontFaces(props.getProperty("systemFontFamily", "Arial"), props.getProperty("proportionalFontFamily", "SansSerif"), props.getProperty("monospaceFontFamily", "Monospaced"));
int med;
int sm;
int la;
if (pixelMilliRatio == null) {
float factor = ((float) getDisplayHeightImpl()) / 480.0f;
med = (int) (15.0f * factor);
sm = (int) (11.0f * factor);
la = (int) (19.0f * factor);
} else {
med = (int) Math.round(2.6 * pixelMilliRatio.doubleValue());
sm = (int) Math.round(2 * pixelMilliRatio.doubleValue());
la = (int) Math.round(3.3 * pixelMilliRatio.doubleValue());
}
setFontSize(Integer.parseInt(props.getProperty("mediumFontSize", "" + med)), Integer.parseInt(props.getProperty("smallFontSize", "" + sm)), Integer.parseInt(props.getProperty("largeFontSize", "" + la)));
tablet = props.getProperty("tablet", "false").equalsIgnoreCase("true");
rotateTouchKeysOnLandscape = props.getProperty("rotateKeys", "false").equalsIgnoreCase("true");
touchDevice = props.getProperty("touch", "true").equalsIgnoreCase("true");
keyboardType = Integer.parseInt(props.getProperty("keyboardType", "0"));
softkeyCount = Integer.parseInt(props.getProperty("softbuttonCount", "1"));
if (softkeyCount < 2) {
// the values of the static variables to be correct!
try {
Field f = com.codename1.ui.MenuBar.class.getDeclaredField("leftSK");
f.setAccessible(true);
f.setInt(null, KeyEvent.VK_F1);
f = com.codename1.ui.MenuBar.class.getDeclaredField("rightSK");
f.setAccessible(true);
f.setInt(null, KeyEvent.VK_F2);
} catch (Throwable t) {
t.printStackTrace();
}
}
final byte[] nativeThemeFinalData = nativeThemeData;
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (nativeThemeFinalData != null) {
try {
nativeThemeRes = Resources.open(new ByteArrayInputStream(nativeThemeFinalData));
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
try {
boolean isJ2me = props.getProperty("platformName", "").equals("me");
String t = props.getProperty("nativeThemeAttribute", null);
if (t != null) {
Properties cnop = new Properties();
File cnopFile = new File("codenameone_settings.properties");
if (cnopFile.exists()) {
cnop.load(new FileInputStream(cnopFile));
int themeConst = Integer.parseInt(cnop.getProperty("codename1.j2me.nativeThemeConst", "3"));
t = cnop.getProperty(t, null);
if (isJ2me && themeConst == 3 && t != null && new File(t).exists()) {
nativeThemeRes = Resources.open(new FileInputStream(t));
}
}
}
} catch (IOException ioErr) {
ioErr.printStackTrace();
}
}
}
});
installMenu(frm, false);
} catch (IOException err) {
err.printStackTrace();
}
}
use of com.codename1.tools.translator.bytecodes.Field in project CodenameOne by codenameone.
the class IOSImplementation method editString.
public void editString(final Component cmp, final int maxSize, final int constraint, final String text, final int i) {
// 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.
pendingEditingText = false;
String defaultAsyncEditingSetting = Display.getInstance().getProperty("ios.VKBAlwaysOpen", null);
if (defaultAsyncEditingSetting == null) {
defaultAsyncEditingSetting = nativeInstance.isAsyncEditMode() ? "true" : "false";
Display.getInstance().setProperty("ios.VKBAlwaysOpen", defaultAsyncEditingSetting);
}
boolean asyncEdit = "true".equals(defaultAsyncEditingSetting) ? true : false;
try {
if (currentEditing != cmp && currentEditing != null && currentEditing instanceof TextArea) {
Display.getInstance().onEditingComplete(currentEditing, ((TextArea) currentEditing).getText());
currentEditing = null;
callHideTextEditor();
if (nativeInstance.isAsyncEditMode()) {
nativeInstance.setNativeEditingComponentVisible(false);
}
synchronized (EDITING_LOCK) {
EDITING_LOCK.notify();
}
Display.getInstance().callSerially(new Runnable() {
public void run() {
pendingEditingText = true;
Display.getInstance().editString(cmp, maxSize, constraint, text, i);
}
});
return;
}
if (cmp.isFocusable() && !cmp.hasFocus()) {
doNotHideTextEditorSemaphore++;
try {
cmp.requestFocus();
} finally {
doNotHideTextEditorSemaphore--;
}
// of our upcoming field.
if (isAsyncEditMode()) {
// flush the EDT so the focus will work...
Display.getInstance().callSerially(new Runnable() {
public void run() {
pendingEditingText = true;
Display.getInstance().editString(cmp, maxSize, constraint, text, i);
}
});
return;
}
}
// Check if the form has any setting for asyncEditing that should override
// the application defaults.
Form parentForm = cmp.getComponentForm();
if (parentForm == null) {
// 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("ios.asyncEditing") != null) {
Object async = parentForm.getClientProperty("ios.asyncEditing");
if (async instanceof Boolean) {
asyncEdit = ((Boolean) async).booleanValue();
// Log.p("Form overriding asyncEdit due to ios.asyncEditing client property: "+asyncEdit);
}
}
// editing - and should instead revert to legacy editing mode.
if (asyncEdit && !parentForm.isFormBottomPaddingEditingMode()) {
Container p = cmp.getParent();
// A crude estimate of how far the component needs to be able to scroll to make
// async editing viable. We start with half-way down the screen.
int keyboardClippingThresholdY = Display.getInstance().getDisplayWidth() / 2;
while (p != null) {
if (Accessor.scrollableYFlag(p) && p.getAbsoluteY() < keyboardClippingThresholdY) {
break;
}
p = p.getParent();
}
// no scrollabel parent automatically configure the text field for legacy mode
// nativeInstance.setAsyncEditMode(p != null);
asyncEdit = p != null;
// Log.p("Overriding asyncEdit due to form scrollability: "+asyncEdit);
} else if (parentForm.isFormBottomPaddingEditingMode()) {
// If form uses bottom padding mode, then we will always
// use async edit (unless the field explicitly overrides it).
asyncEdit = true;
// Log.p("Overriding asyncEdit due to form bottom padding edit mode: "+asyncEdit);
}
// then this will override all other settings.
if (cmp.getClientProperty("asyncEditing") != null) {
Object async = cmp.getClientProperty("asyncEditing");
if (async instanceof Boolean) {
asyncEdit = ((Boolean) async).booleanValue();
// Log.p("Overriding asyncEdit due to field asyncEditing client property: "+asyncEdit);
}
}
if (cmp.getClientProperty("ios.asyncEditing") != null) {
Object async = cmp.getClientProperty("ios.asyncEditing");
if (async instanceof Boolean) {
asyncEdit = ((Boolean) async).booleanValue();
// Log.p("Overriding asyncEdit due to field ios.asyncEditing client property: "+asyncEdit);
}
}
// Finally we set the async edit mode for this field.
// System.out.println("Async edit mode is "+asyncEdit);
nativeInstance.setAsyncEditMode(asyncEdit);
textEditorHidden = false;
currentEditing = (TextArea) cmp;
// register the edited TextArea to support moving to the next field
TextEditUtil.setCurrentEditComponent(cmp);
final NativeFont fnt = f(cmp.getStyle().getFont().getNativeFont());
boolean forceSlideUpTmp = false;
final Form current = Display.getInstance().getCurrent();
if (current instanceof Dialog && !isTablet()) {
// special case, if we are editing a small dialog we want to move it
// so the bottom of the dialog shows within the screen. This is
// described in issue 505
Dialog dlg = (Dialog) current;
Component c = dlg.getDialogComponent();
if (c.getHeight() < Display.getInstance().getDisplayHeight() / 2 && c.getAbsoluteY() + c.getHeight() > Display.getInstance().getDisplayHeight() / 2) {
forceSlideUpTmp = true;
}
}
final boolean forceSlideUp = forceSlideUpTmp;
cmp.repaint();
// give the repaint one cycle to "do its magic...
final Style stl = currentEditing.getStyle();
final boolean rtl = UIManager.getInstance().getLookAndFeel().isRTL();
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
int x = cmp.getAbsoluteX() + cmp.getScrollX();
int y = cmp.getAbsoluteY() + cmp.getScrollY();
int w = cmp.getWidth();
int h = cmp.getHeight();
int pt = stl.getPaddingTop();
int pb = stl.getPaddingBottom();
int pl = stl.getPaddingLeft(rtl);
int pr = stl.getPaddingRight(rtl);
/*
if(currentEditing != null && currentEditing.isSingleLineTextArea()) {
switch(currentEditing.getVerticalAlignment()) {
case TextArea.CENTER:
if(h > cmp.getPreferredH()) {
y += (h / 2 - cmp.getPreferredH() / 2);
}
break;
case TextArea.BOTTOM:
if(h > cmp.getPreferredH()) {
y += (h - cmp.getPreferredH());
}
break;
}
}
*/
String hint = null;
if (currentEditing != null && currentEditing.getUIManager().isThemeConstant("nativeHintBool", true) && currentEditing.getHint() != null) {
hint = currentEditing.getHint();
}
if (isAsyncEditMode()) {
// request focus triggers a scroll which flicks the textEditorHidden flag
doNotHideTextEditorSemaphore++;
try {
cmp.requestFocus();
} finally {
doNotHideTextEditorSemaphore--;
}
textEditorHidden = false;
}
boolean showToolbar = cmp.getClientProperty("iosHideToolbar") == null;
if (showToolbar && Display.getInstance().getProperty("iosHideToolbar", "false").equalsIgnoreCase("true")) {
showToolbar = false;
}
if (currentEditing != null) {
nativeInstance.editStringAt(x, y, w, h, fnt.peer, currentEditing.isSingleLineTextArea(), currentEditing.getRows(), maxSize, constraint, text, forceSlideUp, // peer,
stl.getFgColor(), // peer,
0, pt, pb, pl, pr, hint, showToolbar, Boolean.TRUE.equals(cmp.getClientProperty("blockCopyPaste")), currentEditing.getStyle().getAlignment(), currentEditing.getVerticalAlignment());
}
}
});
if (isAsyncEditMode()) {
return;
}
editNext = false;
Display.getInstance().invokeAndBlock(new Runnable() {
@Override
public void run() {
synchronized (EDITING_LOCK) {
while (instance.currentEditing == cmp) {
try {
EDITING_LOCK.wait(20);
} catch (InterruptedException ex) {
}
}
}
}
});
if (cmp instanceof TextArea && !((TextArea) cmp).isSingleLineTextArea()) {
Form form = cmp.getComponentForm();
if (form != null) {
form.revalidate();
}
}
if (editNext) {
editNext = false;
TextEditUtil.editNextTextArea();
}
} finally {
}
}
Aggregations