Search in sources :

Example 21 with ActionListener

use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.

the class AndroidImplementation method openGallery.

public void openGallery(final ActionListener response, int type) {
    if (getActivity() == null) {
        throw new RuntimeException("Cannot open galery in background mode");
    }
    if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to browse the photos")) {
        return;
    }
    callback = new EventDispatcher();
    callback.addListener(response);
    Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    if (type == Display.GALLERY_VIDEO) {
        galleryIntent.setType("video/*");
    } else if (type == Display.GALLERY_IMAGE) {
        galleryIntent.setType("image/*");
    } else if (type == -9999) {
        galleryIntent = new Intent();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            galleryIntent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        } else {
            galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
        }
        galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
        // set MIME type for image
        galleryIntent.setType("*/*");
        galleryIntent.putExtra(Intent.EXTRA_MIME_TYPES, Display.getInstance().getProperty("android.openGallery.accept", "*/*").split(","));
    } else {
        galleryIntent.setType("*/*");
    }
    this.getActivity().startActivityForResult(galleryIntent, OPEN_GALLERY);
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

Example 22 with ActionListener

use of com.codename1.ui.events.ActionListener 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());
}
Also used : Configuration(android.content.res.Configuration) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Paint(android.graphics.Paint)

Example 23 with ActionListener

use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.

the class BlackBerryImplementation method init.

public void init(Object m) {
    instance = this;
    app = (CodenameOneUiApplication) m;
    if (askForPermission) {
        app.invokeAndWait(new Runnable() {

            public void run() {
                ApplicationPermissions permRequest = new ApplicationPermissions();
                permRequest.addPermission(ApplicationPermissions.PERMISSION_EMAIL);
                permRequest.addPermission(ApplicationPermissions.PERMISSION_FILE_API);
                permRequest.addPermission(ApplicationPermissions.PERMISSION_WIFI);
                try {
                    // ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION
                    permRequest.addPermission(11);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_MEDIA
                    permRequest.addPermission(21);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_INPUT_SIMULATION
                    permRequest.addPermission(6);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_LOCATION_DATA
                    permRequest.addPermission(14);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_ORGANIZER_DATA
                    permRequest.addPermission(16);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_INTERNET
                    permRequest.addPermission(7);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_RECORDING
                    permRequest.addPermission(17);
                } catch (Exception e) {
                }
                ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
                if (!apm.invokePermissionsRequest(permRequest)) {
                    exitApplication();
                    return;
                }
            }
        });
    }
    app.enableKeyUpEvents(true);
    if (!app.isHandlingEvents()) {
        new Thread() {

            public void run() {
                app.enterEventDispatcher();
            }
        }.start();
    }
    Dialog.setCommandsAsButtons(true);
    UIManager.getInstance().addThemeRefreshListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            Hashtable themeProps = new Hashtable();
            themeProps.put("SoftButton.margin", "0,0,0,0");
            themeProps.put("SoftButton.padding", "0,0,0,0");
            UIManager.getInstance().addThemeProps(themeProps);
        }
    });
    RecordEnumeration e = null;
    RecordStore r = null;
    try {
        r = RecordStore.openRecordStore("FAT", true);
        if (r.getNumRecords() > 0) {
            e = r.enumerateRecords(null, null, false);
            while (e.hasNextElement()) {
                byte[] rec = e.nextRecord();
                ByteArrayInputStream bi = new ByteArrayInputStream(rec);
                DataInputStream di = new DataInputStream(bi);
                String name = di.readUTF();
                short key = di.readShort();
                di.close();
                bi.close();
                fat.put(name, new Short(key));
                if (key >= currentKey) {
                    currentKey += key;
                }
            }
            e.destroy();
            e = null;
        }
        r.closeRecordStore();
        r = null;
    } catch (Exception ex) {
        ex.printStackTrace();
        cleanup(r);
        cleanup(e);
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) RecordEnumeration(javax.microedition.rms.RecordEnumeration) ApplicationPermissions(net.rim.device.api.applicationcontrol.ApplicationPermissions) DataInputStream(java.io.DataInputStream) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) ActionListener(com.codename1.ui.events.ActionListener) ByteArrayInputStream(java.io.ByteArrayInputStream) RecordStore(javax.microedition.rms.RecordStore) ApplicationPermissionsManager(net.rim.device.api.applicationcontrol.ApplicationPermissionsManager)

Example 24 with ActionListener

use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.

the class IOSImplementation method openGallery.

@Override
public void openGallery(ActionListener response, int type) {
    if (!nativeInstance.checkPhotoLibraryUsage()) {
        throw new RuntimeException("Please add the ios.NSPhotoLibraryUsageDescription build hint");
    }
    captureCallback = new EventDispatcher();
    captureCallback.addListener(response);
    nativeInstance.openGallery(type);
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

Example 25 with ActionListener

use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.

the class IOSImplementation method captureAudio.

public void captureAudio(ActionListener response) {
    if (!nativeInstance.checkMicrophoneUsage()) {
        throw new RuntimeException("Please add the ios.NSMicrophoneUsageDescription build hint");
    }
    dropEvents = false;
    String p = FileSystemStorage.getInstance().getAppHomePath();
    if (!p.endsWith("/")) {
        p += "/";
    }
    try {
        final Media media = MediaManager.createMediaRecorder(p + "cn1TempAudioFile", MediaManager.getAvailableRecordingMimeTypes()[0]);
        media.play();
        boolean b = Dialog.show("Recording", "", "Save", "Cancel");
        final Dialog d = new Dialog("Recording");
        media.pause();
        media.cleanup();
        d.dispose();
        if (b) {
            response.actionPerformed(new ActionEvent(p + "cn1TempAudioFile"));
        } else {
            FileSystemStorage.getInstance().delete(p + "cn1TempAudioFile");
            response.actionPerformed(null);
        }
    } catch (IOException err) {
        err.printStackTrace();
        response.actionPerformed(null);
    }
}
Also used : Dialog(com.codename1.ui.Dialog) ActionEvent(com.codename1.ui.events.ActionEvent) Media(com.codename1.media.Media) IOException(java.io.IOException)

Aggregations

ActionEvent (com.codename1.ui.events.ActionEvent)61 ActionListener (com.codename1.ui.events.ActionListener)61 IOException (java.io.IOException)25 BorderLayout (com.codename1.ui.layouts.BorderLayout)20 EventDispatcher (com.codename1.ui.util.EventDispatcher)16 Hashtable (java.util.Hashtable)14 NetworkEvent (com.codename1.io.NetworkEvent)13 Form (com.codename1.ui.Form)13 Vector (java.util.Vector)11 Container (com.codename1.ui.Container)10 Button (com.codename1.ui.Button)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)8 Dialog (com.codename1.ui.Dialog)7 EncodedImage (com.codename1.ui.EncodedImage)6 Image (com.codename1.ui.Image)6 Label (com.codename1.ui.Label)6 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)6 MediaException (javax.microedition.media.MediaException)6 RecordStoreException (javax.microedition.rms.RecordStoreException)6