use of com.codename1.rad.models in project CodenameOne by codenameone.
the class ComponentSelector method setPadding.
/**
* Sets padding to all components in found set.
* @param top Top padding in pixels.
* @param right Right padding in pixels
* @param bottom Bottom padding in pixels.
* @param left Left padding in pixels.
* @return
* @see #getStyle(com.codename1.ui.Component)
*/
public ComponentSelector setPadding(int top, int right, int bottom, int left) {
Style s = currentStyle();
s.setPaddingUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
s.setPadding(top, bottom, left, right);
return this;
}
use of com.codename1.rad.models in project CodenameOne by codenameone.
the class ComponentSelector method fadeOut.
/**
* Fades out components in this set.
* @param duration Duration of animation.
* @param callback Callback to run when animation completes.
* @return Self for chaining.
*/
public ComponentSelector fadeOut(int duration, final SuccessCallback<ComponentSelector> callback) {
final String placeholderProperty = "com.codename1.ui.ComponentSelector#fadeOutPlaceholder";
AnimationManager mgr = null;
ArrayList<ComponentAnimation> animations = new ArrayList<ComponentAnimation>();
final ArrayList<Component> animatingComponents = new ArrayList<Component>();
for (Component c : this) {
Container parent = c.getParent();
if (parent != null) {
AnimationManager cmgr = c.getAnimationManager();
if (cmgr != null) {
mgr = cmgr;
Container placeholder = new Container();
// placeholder.setShowEvenIfBlank(true);
c.putClientProperty(placeholderProperty, placeholder);
Component.setSameHeight(placeholder, c);
Component.setSameWidth(placeholder, c);
$(placeholder).setMargin(c.getStyle().getMarginTop(), c.getStyle().getMarginRight(false), c.getStyle().getMarginBottom(), c.getStyle().getMarginLeft(false)).setPadding(c.getStyle().getPaddingTop(), c.getStyle().getPaddingRight(false), c.getStyle().getPaddingBottom(), c.getStyle().getPaddingLeft(false));
ComponentAnimation a = parent.createReplaceTransition(c, placeholder, CommonTransitions.createFade(duration));
animations.add(a);
animatingComponents.add(c);
}
// centerBackground.add(BorderLayout.CENTER, boxy);
}
}
if (mgr != null) {
mgr.addAnimation(ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()])), new Runnable() {
public void run() {
for (final Component c : animatingComponents) {
// c.setHidden(true);
c.setVisible(false);
final Container placeholder = (Container) c.getClientProperty(placeholderProperty);
c.putClientProperty(placeholderProperty, null);
if (placeholder != null) {
Container parent = placeholder.getParent();
/*
if (parent == null) {
System.out.println("Deferring replace back");
$(new Runnable() {
public void run() {
Container parent = placeholder.getParent();
if (parent != null) {
System.out.println("Found parent after deferral");
parent.replace(placeholder, c, CommonTransitions.createEmpty());
}
}
});
} else {
*/
if (parent != null) {
parent.replace(placeholder, c, CommonTransitions.createEmpty());
}
// }
}
}
if (callback != null) {
callback.onSucess(ComponentSelector.this);
}
}
});
}
return this;
}
use of com.codename1.rad.models in project CodenameOne by codenameone.
the class AndroidImplementation method createIntentForURL.
private Intent createIntentForURL(String url) {
Intent intent;
Uri uri;
try {
if (url.startsWith("intent")) {
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
} else {
if (url.startsWith("/") || url.startsWith("file:")) {
if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to open the file")) {
return null;
}
}
intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
if (url.startsWith("/")) {
File f = new File(url);
Uri furi = null;
try {
furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f);
} catch (Exception ex) {
f = makeTempCacheCopy(f);
furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f);
}
if (Build.VERSION.SDK_INT < 21) {
List<ResolveInfo> resInfoList = getContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
getContext().grantUriPermission(packageName, furi, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
uri = furi;
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
if (url.startsWith("file:")) {
File f = new File(removeFilePrefix(url));
System.out.println("File size: " + f.length());
Uri furi = null;
try {
furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f);
} catch (Exception ex) {
f = makeTempCacheCopy(f);
furi = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", f);
}
if (Build.VERSION.SDK_INT < 21) {
List<ResolveInfo> resInfoList = getContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
getContext().grantUriPermission(packageName, furi, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
uri = furi;
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
uri = Uri.parse(url);
}
}
String mimeType = getMimeType(url);
if (mimeType != null) {
intent.setDataAndType(uri, mimeType);
} else {
intent.setData(uri);
}
}
return intent;
} catch (Exception err) {
com.codename1.io.Log.e(err);
return null;
}
}
use of com.codename1.rad.models in project CodenameOne by codenameone.
the class AndroidImplementation method drawShape.
@Override
public void drawShape(Object graphics, com.codename1.ui.geom.Shape shape, com.codename1.ui.Stroke stroke) {
AndroidGraphics ag = (AndroidGraphics) graphics;
Path p = cn1ShapeToAndroidPath(shape);
ag.drawPath(p, stroke);
}
use of com.codename1.rad.models in project CodenameOne by codenameone.
the class AndroidImplementation method fixAttachmentPath.
private String fixAttachmentPath(String attachment) {
com.codename1.io.File cn1File = new com.codename1.io.File(attachment);
File mediaStorageDir = new File(new File(getContext().getCacheDir(), "intent_files"), "Attachment");
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(Display.getInstance().getProperty("AppName", "CodenameOne"), "failed to create directory");
return null;
}
}
File newFile = new File(mediaStorageDir.getPath() + File.separator + cn1File.getName());
if (newFile.exists()) {
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
newFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + "_" + cn1File.getName());
}
// Uri fileUri = Uri.fromFile(newFile);
newFile.getParentFile().mkdirs();
// Uri imageUri = Uri.fromFile(newFile);
Uri fileUri = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider", newFile);
try {
InputStream is = FileSystemStorage.getInstance().openInputStream(attachment);
OutputStream os = new FileOutputStream(newFile);
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf)) > -1) {
os.write(buf, 0, len);
}
is.close();
os.close();
} catch (IOException ex) {
Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
}
return fileUri.toString();
}
Aggregations