use of com.codename1.processing.Result in project CodenameOne by codenameone.
the class ResourceEditorView method duplicateItemActionPerformed.
// GEN-LAST:event_deleteUnusedImagesActionPerformed
private void duplicateItemActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_duplicateItemActionPerformed
if (selectedResource != null && loadedResources.containsResource(selectedResource)) {
Box rename = new Box(BoxLayout.X_AXIS);
rename.add(new JLabel("New Name: "));
JTextField field = new JTextField(selectedResource, 20);
rename.add(Box.createHorizontalStrut(3));
rename.add(field);
int result = JOptionPane.showConfirmDialog(mainPanel, rename, "Duplicate", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
String val = field.getText();
if (loadedResources.containsResource(val)) {
JOptionPane.showMessageDialog(mainPanel, "An Element By This Name Already Exists", "Rename", JOptionPane.ERROR_MESSAGE);
duplicateItemActionPerformed(evt);
return;
}
try {
// this effectively creates a new instance of the object
ByteArrayOutputStream bo = new ByteArrayOutputStream();
boolean m = loadedResources.isModified();
loadedResources.save(bo);
if (m) {
loadedResources.setModified();
}
bo.close();
EditableResources r = new EditableResources();
r.openFile(new ByteArrayInputStream(bo.toByteArray()));
loadedResources.addResourceObjectDuplicate(selectedResource, val, r.getResourceObject(selectedResource));
setSelectedResource(val);
} catch (IOException err) {
err.printStackTrace();
}
}
} else {
JOptionPane.showMessageDialog(mainPanel, "An Element Must Be Selected", "Rename", JOptionPane.ERROR_MESSAGE);
}
}
use of com.codename1.processing.Result in project CodenameOne by codenameone.
the class AddAndScaleMultiImage method generate.
public void generate(File[] files, EditableResources res) {
for (File f : files) {
try {
BufferedImage bi = ImageIO.read(f);
EditableResources.MultiImage newImage = new EditableResources.MultiImage();
int[] DPIS = new int[] { com.codename1.ui.Display.DENSITY_VERY_LOW, com.codename1.ui.Display.DENSITY_LOW, com.codename1.ui.Display.DENSITY_MEDIUM, com.codename1.ui.Display.DENSITY_HIGH, com.codename1.ui.Display.DENSITY_VERY_HIGH, com.codename1.ui.Display.DENSITY_HD, com.codename1.ui.Display.DENSITY_560, com.codename1.ui.Display.DENSITY_2HD, com.codename1.ui.Display.DENSITY_4K };
EncodedImage[] images = new EncodedImage[DPIS.length];
int imageCount = 0;
JSpinner[] ws = { veryLowWidth, lowWidth, mediumWidth, highWidth, veryHighWidth, hdWidth, hd560Width, hd2Width, hd4kWidth };
JSpinner[] hs = { veryLowHeight, lowHeight, mediumHeight, highHeight, veryHighHeight, hdHeight, hd560Height, hd2Height, hd4kHeight };
if (squareImages.isSelected()) {
hs = ws;
}
for (int iter = 0; iter < ws.length; iter++) {
images[iter] = createScale(bi, ws[iter], hs[iter]);
if (images[iter] != null) {
imageCount++;
}
}
if (imageCount > 0) {
int offset = 0;
EncodedImage[] result = new EncodedImage[imageCount];
int[] resultDPI = new int[imageCount];
for (int iter = 0; iter < images.length; iter++) {
if (images[iter] != null) {
result[offset] = images[iter];
resultDPI[offset] = DPIS[iter];
offset++;
}
}
newImage.setDpi(resultDPI);
newImage.setInternalImages(result);
String destName = f.getName();
int count = 1;
while (res.containsResource(destName)) {
destName = f.getName() + " " + count;
}
res.setMultiImage(destName, newImage);
}
} catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Error reading file: " + f, "IO Error", JOptionPane.ERROR_MESSAGE);
}
}
}
use of com.codename1.processing.Result in project CodenameOne by codenameone.
the class ImageDownloadService method postResponse.
/**
* {@inheritDoc}
*/
protected void postResponse() {
// trigger an exception in case of an invalid image
result.getWidth();
Image image = result;
if (toScale != null && toScale.getWidth() != image.getWidth() && toScale.getHeight() != image.getHeight()) {
image = scaleImage(image, toScale, maintainAspectRatio);
}
final Image i = image;
if (parentLabel != null) {
final Dimension pref = parentLabel.getPreferredSize();
if (parentLabel.getComponentForm() != null) {
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (isDownloadToStyles()) {
parentLabel.getUnselectedStyle().setBgImage(i);
parentLabel.getSelectedStyle().setBgImage(i);
parentLabel.getPressedStyle().setBgImage(i);
} else {
parentLabel.setIcon(i);
}
Dimension newPref = parentLabel.getPreferredSize();
// sized image in place or has a hardcoded preferred size.
if (pref.getWidth() != newPref.getWidth() || pref.getHeight() != newPref.getHeight()) {
parentLabel.getComponentForm().revalidate();
}
}
});
} else {
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (isDownloadToStyles()) {
parentLabel.getUnselectedStyle().setBgImage(i);
parentLabel.getSelectedStyle().setBgImage(i);
parentLabel.getPressedStyle().setBgImage(i);
} else {
parentLabel.setIcon(i);
}
}
});
}
parentLabel.repaint();
return;
} else {
if (targetList != null) {
setEntryInListModel(targetOffset, image);
// revalidate only once to avoid multiple revalidate refreshes during scroll
if (targetList.getParent() != null) {
if (alwaysRevalidate) {
targetList.getParent().revalidate();
} else {
if (targetList.getClientProperty("$imgDSReval") == null) {
targetList.putClientProperty("$imgDSReval", Boolean.TRUE);
targetList.getParent().revalidate();
} else {
targetList.repaint();
}
}
}
}
}
// if this is a list cell renderer component
fireResponseListener(new NetworkEvent(this, result));
}
use of com.codename1.processing.Result in project CodenameOne by codenameone.
the class ResetableTextWatcher method showVirtualKeyboard.
/**
* Show or hide the virtual keyboard if necessary
* @param show Show the keyboard if true, hide it otherwise
*/
private void showVirtualKeyboard(boolean show) {
Log.i(TAG, "showVirtualKeyboard show=" + show);
boolean result = false;
if (show) {
// If we're in landscape, Android will not show the soft
// keyboard unless SHOW_FORCED is requested
Configuration config = mResources.getConfiguration();
boolean isLandscape = (config.orientation == Configuration.ORIENTATION_LANDSCAPE);
int showFlags = isLandscape ? InputMethodManager.SHOW_FORCED : InputMethodManager.SHOW_IMPLICIT;
mInputManager.restartInput(mEditText);
result = mInputManager.showSoftInput(mEditText, showFlags, mResultReceiver);
} else {
if (mEditText == null) {
if (showVKB) {
mInputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
} else {
result = mInputManager.hideSoftInputFromWindow(mEditText.getWindowToken(), 0, mResultReceiver);
}
closedTime = System.currentTimeMillis();
}
showVKB = show;
final boolean showKeyboard = showVKB;
final ActionListener listener = Display.getInstance().getVirtualKeyboardListener();
if (listener != null) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// keyboard is opened or closed
try {
Thread.sleep(600);
} catch (InterruptedException ex) {
}
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
ActionEvent evt = new ActionEvent(showKeyboard);
listener.actionPerformed(evt);
}
});
}
});
t.setUncaughtExceptionHandler(AndroidImplementation.exceptionHandler);
t.start();
}
Log.d(TAG, "InputMethodManager returned " + Boolean.toString(result).toUpperCase());
}
use of com.codename1.processing.Result in project CodenameOne by codenameone.
the class FacebookImpl method inviteFriends.
@Override
public void inviteFriends(String appLinkUrl, String previewImageUrl, final Callback cb) {
if (AndroidNativeUtil.getActivity() == null) {
throw new RuntimeException("Cannot invite friends while running in the background.");
}
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder().setApplinkUrl(appLinkUrl).setPreviewImageUrl(previewImageUrl).build();
final CodenameOneActivity activity = (CodenameOneActivity) AndroidNativeUtil.getActivity();
if (cb == null) {
AppInviteDialog.show(activity, content);
} else {
AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
final CallbackManager mCallbackManager = CallbackManager.Factory.create();
activity.setIntentResultListener(new IntentResultListener() {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mCallbackManager.onActivityResult(requestCode, resultCode, data);
activity.restoreIntentResultListener();
}
});
appInviteDialog.registerCallback(mCallbackManager, new FacebookCallback<AppInviteDialog.Result>() {
@Override
public void onSuccess(AppInviteDialog.Result result) {
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
cb.onSucess(null);
}
});
}
@Override
public void onCancel() {
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
cb.onError(null, null, -1, "User Cancelled");
}
});
}
@Override
public void onError(final FacebookException e) {
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
cb.onError(null, e, 0, e.getMessage());
}
});
}
});
appInviteDialog.show(content);
}
}
}
Aggregations