use of com.codename1.ui in project CodenameOne by codenameone.
the class ResetableTextWatcher method hideTextEditor.
/**
* Hides the native text editor while keeping the active async edit session going.
* This will effectively hide the native text editor, and show the light-weight text area
* with cursor still in the correct position.
*/
private void hideTextEditor() {
if (!mIsEditing || textEditorHidden || mEditText == null) {
return;
}
textEditorHidden = true;
final TextArea ta = mEditText.mTextArea;
// Since this may be called off the UI thread, we need to issue async request on UI thread
// to hide the text area.
impl.getActivity().runOnUiThread(new Runnable() {
public void run() {
if (mEditText != null && mEditText.mTextArea == ta) {
// Note: Setting visibility to GONE doesn't work here because the TextWatcher
// will stop receiving input from the keyboard, so we don't have a way to
// reactivate the text editor when the user starts typing again. Using the margin
// to move it off screen keeps the text editor active.
mEditLayoutParams.setMargins(-Display.getInstance().getDisplayWidth(), 0, 0, 0);
InPlaceEditView.this.requestLayout();
final int cursorPos = mEditText.getSelectionStart();
// Since we are going to be displaying the CN1 text area now, we need to update
// the cursor. That needs to happen on the EDT.
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (mEditText != null && mEditText.mTextArea == ta && mIsEditing && textEditorHidden) {
if (ta instanceof TextField) {
((TextField) ta).setCursorPosition(cursorPos);
}
}
}
});
}
}
});
// Repaint the CN1 text area on the EDT. This is necessary because while the native editor
// was shown, the cn1 text area paints only its background. Now that the editor is hidden
// it should paint its foreground also.
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (mEditText != null && mEditText.mTextArea != null) {
mEditText.mTextArea.repaint();
}
}
});
// repaintTextEditor(true);
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class BlackBerryImplementation method sendMessage.
public void sendMessage(String[] recipients, String subject, Message msg) {
Folder[] folders = Session.getDefaultInstance().getStore().list(Folder.SENT);
net.rim.blackberry.api.mail.Message message = new net.rim.blackberry.api.mail.Message(folders[0]);
try {
Address[] toAdds = new Address[recipients.length];
for (int i = 0; i < recipients.length; i++) {
Address address = new Address(recipients[i], "");
toAdds[i] = address;
}
message.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, toAdds);
message.setSubject(subject);
} catch (Exception e) {
EventLog.getInstance().logErrorEvent("err " + e.getMessage());
}
try {
if (msg.getAttachment() != null && msg.getAttachment().length() > 0) {
Multipart content = new Multipart();
TextBodyPart tbp = new TextBodyPart(content, msg.getContent());
content.addBodyPart(tbp);
InputStream stream = com.codename1.io.FileSystemStorage.getInstance().openInputStream(msg.getAttachment());
byte[] buf;
buf = IOUtilities.streamToBytes(stream);
stream.close();
String name = msg.getAttachment();
name = name.substring(name.lastIndexOf(getFileSystemSeparator()) + 1, name.length());
SupportedAttachmentPart sap = new SupportedAttachmentPart(content, msg.getAttachmentMimeType(), name, buf);
content.addBodyPart(sap);
message.setContent(content);
} else {
message.setContent(msg.getContent());
}
app.setWaitingForReply(true);
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));
} catch (Exception ex) {
EventLog.getInstance().logErrorEvent("err " + ex.getMessage());
}
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class GoogleImpl method nativeLoginImpl.
private void nativeLoginImpl(final GoogleApiClient client) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(client);
AndroidNativeUtil.startActivityForResult(signInIntent, RC_SIGN_IN, new IntentResultListener() {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
final GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
String displayName = acct.getDisplayName();
String acctId = acct.getId();
String email = acct.getEmail();
String requestIdToken = acct.getIdToken();
Set<Scope> grantedScopes = acct.getGrantedScopes();
String code = acct.getServerAuthCode();
String scopeStr = scope;
System.out.println("Token is " + acct.getIdToken());
if (acct.getIdToken() == null && clientId != null && clientSecret != null) {
Log.p("Received null ID token even though clientId and clientSecret are set.");
}
// otherwise we'll set the token to null.
if (clientId != null && clientSecret != null && requestIdToken != null && code != null) {
ConnectionRequest req = new ConnectionRequest() {
@Override
protected void readResponse(InputStream input) throws IOException {
Map<String, Object> json = new JSONParser().parseJSON(new InputStreamReader(input, "UTF-8"));
if (json.containsKey("access_token")) {
setAccessToken(new AccessToken((String) json.get("access_token"), null));
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
callback.loginSuccessful();
}
});
} else {
setAccessToken(new AccessToken(null, null));
Log.p("Failed to retrieve the access token from the google auth server. Login succeeded, but access token is null, so you won't be able to use it to retrieve additional information.");
Log.p("Response was " + json);
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
callback.loginSuccessful();
}
});
}
}
};
req.setUrl("https://www.googleapis.com/oauth2/v4/token");
req.addArgument("grant_type", "authorization_code");
// req.addArgument("client_id", "555462747934-iujpd5saj4pjpibo7c6r9tbjfef22rh1.apps.googleusercontent.com");
req.addArgument("client_id", clientId);
// req.addArgument("client_secret", "650YqplrnAI0KXb9LMUnVNnx");
req.addArgument("client_secret", clientSecret);
req.addArgument("redirect_uri", "");
req.addArgument("code", code);
req.addArgument("id_token", requestIdToken);
req.setPost(true);
req.setReadResponseForErrors(true);
NetworkManager.getInstance().addToQueue(req);
} else {
setAccessToken(new AccessToken(null, null));
Log.p("The access token was set to null because one of clientId, clientSecret, requestIdToken, or auth were null");
Log.p("The login succeeded, but you won't be able to make any requests to Google's REST apis using the login token.");
Log.p("In order to obtain a token that can be used with Google's REST APIs, you need to set the clientId, and clientSecret of" + "the GoogleConnect instance to valid OAuth2.0 Client IDs for Web Clients.");
Log.p("See https://console.developers.google.com/apis/credentials");
Log.p("You can get the OAuth2.0 client ID for this project in your google-services.json file in the oauth_client section");
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
callback.loginSuccessful();
}
});
}
} else {
if (callback != null) {
if (callback != null) {
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
callback.loginFailed(GooglePlayServicesUtil.getErrorString(result.getStatus().getStatusCode()));
}
});
}
}
}
}
}
});
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class GoogleImpl method onConnectionFailed.
public void onConnectionFailed(final ConnectionResult cr) {
if (AndroidNativeUtil.getActivity() == null) {
return;
}
final CodenameOneActivity main = (CodenameOneActivity) AndroidNativeUtil.getActivity();
if (!mIntentInProgress && cr.hasResolution()) {
try {
mIntentInProgress = true;
main.startIntentSenderForResult(cr.getResolution().getIntentSender(), 0, null, 0, 0, 0);
main.setIntentResultListener(new com.codename1.impl.android.IntentResultListener() {
public void onActivityResult(int requestCode, int resultCode, android.content.Intent data) {
mIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
main.restoreIntentResultListener();
}
});
} catch (SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
mIntentInProgress = false;
mGoogleApiClient.connect();
}
return;
}
if (callback != null) {
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
callback.loginFailed(GooglePlayServicesUtil.getErrorString(cr.getErrorCode()));
}
});
}
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class IOSImplementation method createAlphaMask.
// -------------------------------------------------------------------------
// METHODS FOR DRAWING SHAPES AND TRANSFORMATIONS
// -------------------------------------------------------------------------
/**
* Creates a platform-specific alpha mask for a shape. This is used to cache
* masks in the {@link com.codename1.ui.GeneralPath} class. On iOS the alpha
* mask is an OpenGL texture ID (not a raster of alpha pixels), but other platforms
* may use different representations if they like.
*
* <p>The {@link com.codename1.ui.Graphics#drawAlphaMask} method
* is used to draw a mask on the graphics context and this will ultimately call {@link #drawAlphaMask}
* which can be platform specific also.
* </p>
* @param shape The shape that will have an alpha mask created.
* @param stroke The stroke settings for stroking the outline of the mask. Leave null to produce a fill
* mask.
* @return The platform specific alpha mask object or null if it is not supported or failed.
* @see #deleteAlphaMask
* @see #drawAlphaMask
* @see #isAlphaMaskSupported
* @see com.codename1.ui.Graphics#drawAlphaMask
* @see com.codename1.ui.GeneralPath#getAlphaMask
*/
public TextureAlphaMask createAlphaMask(Shape shape, Stroke stroke) {
int[] bounds = new int[] { 0, 0, 0, 0 };
long tex = nativeCreateAlphaMaskForShape(shape, stroke, bounds);
Rectangle shapeBounds = shape.getBounds();
int[] padding = new int[] { // top
shapeBounds.getY() - bounds[1], // right
bounds[2] - (shapeBounds.getX() + shapeBounds.getWidth()), // bottom
bounds[3] - (shapeBounds.getY() + shapeBounds.getHeight()), // left
shapeBounds.getX() - bounds[0] };
if (tex == 0) {
return null;
}
return new TextureAlphaMask(tex, new Rectangle(bounds[0], bounds[1], bounds[2] - bounds[0], bounds[3] - bounds[1]), padding);
}
Aggregations