7

The following image should represent an PhoneGap/Cordova app which is marked in blue. The red area should be an Android Fragment.

enter image description here

Is it possible tho have an Android Fragment which overlays a PhoneGap Activity?

Edit: The overlaying Android Fragment should the tasks like image manipulation. How do I have to write a PhoneGap plugin that communicates with the Fragment?

Michael
  • 32,527
  • 49
  • 210
  • 370

1 Answers1

7

the way i did this was by writing a plugin that shows a custom dialog without border, background shadow, etc.

my execute() method looks like this:

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (resources == null)
            resources = cordova.getActivity().getApplication().getResources();
        if (package_name == null)
            package_name = cordova.getActivity().getApplication().getPackageName();
        if (inflator == null) {
            inflator = cordova.getActivity().getLayoutInflater();
        }

        if (action.equals("show")) {
            this.show(args, callbackContext);
            return true;
        }

        return false;  // Returning false results in a "MethodNotFound" error.
}

and the show() method contains something like this:

[...]
    Runnable runnable = new Runnable() {
        public void run() {
            pinpad = new Dialog(cordova.getActivity());
            pinpad.requestWindowFeature(Window.FEATURE_NO_TITLE);
            Window window = pinpad.getWindow();
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            WindowManager.LayoutParams wlp = window.getAttributes();
            wlp.gravity = Gravity.BOTTOM;
            window.setAttributes(wlp);

            pinpad.setCancelable(false);
            pinpad.setContentView(view);
            pinpad.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, (int) height);
            pinpad.show();
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
[...]

if your window (the red part) has to be placed in some particular position (not in the center or at the bottom of the screen) then you have to pass coordinates from javascript to native plugin.

pelotasplus
  • 9,852
  • 1
  • 35
  • 37
  • Could you publish your plugin on github or share some more details? Is this code from a fragment? – Michael Jun 04 '14 at 12:38
  • Could you please explain what you do and what other have to do to use your code? – Michael Jun 04 '14 at 15:03
  • 2
    this code shows native android dialog on top of phonegap app. if i get it correctly, this is what you wanted? what to do? you have to create a phonegap plugin and call it from js. then plugin whill show a dialog on top of your phonegap app. – pelotasplus Jun 05 '14 at 12:32
  • Can I put everything in an Android Dialog? Are there any limitations? – Michael Jun 05 '14 at 21:48
  • I don't think there are. A DialogFragment also has its own View, and is a full-fledged Fragment. – EpicPandaForce Jun 13 '14 at 14:16