CordovaInterface.java 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. package org.apache.cordova;
  18. import android.app.Activity;
  19. import android.content.Context;
  20. import android.content.Intent;
  21. import org.apache.cordova.CordovaPlugin;
  22. import java.util.concurrent.ExecutorService;
  23. /**
  24. * The Activity interface that is implemented by CordovaActivity.
  25. * It is used to isolate plugin development, and remove dependency on entire Cordova library.
  26. */
  27. public interface CordovaInterface {
  28. /**
  29. * Launch an activity for which you would like a result when it finished. When this activity exits,
  30. * your onActivityResult() method will be called.
  31. *
  32. * @param command The command object
  33. * @param intent The intent to start
  34. * @param requestCode The request code that is passed to callback to identify the activity
  35. */
  36. abstract public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode);
  37. /**
  38. * Set the plugin to be called when a sub-activity exits.
  39. *
  40. * @param plugin The plugin on which onActivityResult is to be called
  41. */
  42. abstract public void setActivityResultCallback(CordovaPlugin plugin);
  43. /**
  44. * Get the Android activity.
  45. *
  46. * If a custom engine lives outside of the Activity's lifecycle the return value may be null.
  47. *
  48. * @return the Activity
  49. */
  50. public abstract Activity getActivity();
  51. /**
  52. * Get the Android context.
  53. *
  54. * @return the Context
  55. */
  56. public Context getContext();
  57. /**
  58. * Called when a message is sent to plugin.
  59. *
  60. * @param id The message id
  61. * @param data The message data
  62. * @return Object or null
  63. */
  64. public Object onMessage(String id, Object data);
  65. /**
  66. * Returns a shared thread pool that can be used for background tasks.
  67. */
  68. public ExecutorService getThreadPool();
  69. /**
  70. * Sends a permission request to the activity for one permission.
  71. */
  72. public void requestPermission(CordovaPlugin plugin, int requestCode, String permission);
  73. /**
  74. * Sends a permission request to the activity for a group of permissions
  75. */
  76. public void requestPermissions(CordovaPlugin plugin, int requestCode, String [] permissions);
  77. /**
  78. * Check for a permission. Returns true if the permission is granted, false otherwise.
  79. */
  80. public boolean hasPermission(String permission);
  81. }