Ejemplo n.º 1
0
  @Override
  public void initialize(CordovaInterface cordova, CordovaWebView webView) {

    super.initialize(cordova, webView);

    WindowManager manager =
        ((WindowManager)
            cordova.getActivity().getApplicationContext().getSystemService(Context.WINDOW_SERVICE));

    WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
    localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    localLayoutParams.gravity = Gravity.TOP;
    localLayoutParams.flags =
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            |

            // this is to enable the notification to recieve touch events
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            |

            // Draws over status bar
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

    localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    localLayoutParams.height =
        (int) (30 * cordova.getActivity().getResources().getDisplayMetrics().scaledDensity);
    localLayoutParams.format = PixelFormat.TRANSPARENT;

    CustomViewGroup view = new CustomViewGroup(cordova.getActivity().getApplicationContext());

    manager.addView(view, localLayoutParams);
  }
Ejemplo n.º 2
0
 @SuppressLint("InlinedApi")
 private ProgressDialog createProgressDialog(CordovaInterface cordova) {
   int currentapiVersion = android.os.Build.VERSION.SDK_INT;
   if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
     return new ProgressDialog(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
   } else {
     return new ProgressDialog(cordova.getActivity());
   }
 }
Ejemplo n.º 3
0
 @SuppressLint("NewApi")
 private AlertDialog.Builder createDialog(CordovaInterface cordova) {
   int currentapiVersion = android.os.Build.VERSION.SDK_INT;
   if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
     return new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
   } else {
     return new AlertDialog.Builder(cordova.getActivity());
   }
 }
 @Override
 public void initialize(CordovaInterface cordova, CordovaWebView webView) {
   super.initialize(cordova, webView);
   mContext = cordova.getActivity();
   mContentResolver = cordova.getActivity().getContentResolver();
   genIncomingCallBroadcastReceiver();
   cordova
       .getActivity()
       .registerReceiver(
           mIncomingCallBroadcastReceiver, new IntentFilter(ACTION_PHONE_STATE_CHANGED));
 }
Ejemplo n.º 5
0
 @Override
 public void initialize(final CordovaInterface cordova, CordovaWebView webView) {
   safeToFireMessages = false;
   super.initialize(cordova, webView);
   ChromeGcm.webView = webView;
   executorService = cordova.getThreadPool();
   if (cordova.getActivity().getIntent().hasExtra(PAYLOAD_LABEL)) {
     cordova.getActivity().moveTaskToBack(true);
   }
   context = cordova.getActivity().getApplicationContext();
 }
Ejemplo n.º 6
0
  /**
   * Returns the real path of the given URI string. If the given URI string represents a content://
   * URI, the real path is retrieved from the media store.
   *
   * @param uriString the URI string of the audio/image/video
   * @param cordova the current application context
   * @return the full path to the file
   */
  @SuppressWarnings("deprecation")
  public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;

    if (uriString.startsWith("content://")) {
      String[] proj = {_DATA};
      Cursor cursor =
          cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
      int column_index = cursor.getColumnIndexOrThrow(_DATA);
      cursor.moveToFirst();
      realPath = cursor.getString(column_index);
      if (realPath == null) {
        LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
      }
    } else if (uriString.startsWith("file://")) {
      realPath = uriString.substring(7);
      if (realPath.startsWith("/android_asset/")) {
        LOG.e(
            LOG_TAG,
            "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.",
            uriString);
        realPath = null;
      }
    } else {
      realPath = uriString;
    }

    return realPath;
  }
  /**
   * Wrapper para criação de Threads
   *
   * @param job
   * @param jobTitle
   * @param jobName
   */
  private void runJob(final Runnable job, final String jobTitle, final String jobName) {
    // Start the job from main thread
    mCordova
        .getActivity()
        .runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                // Progress dialog available due job execution
                final ProgressDialog dialog = new ProgressDialog(mCordova.getActivity());
                dialog.setTitle(jobTitle);
                dialog.setMessage(jobName);
                dialog.setCancelable(false);
                dialog.setCanceledOnTouchOutside(false);
                dialog.show();

                Thread t =
                    new Thread(
                        new Runnable() {
                          @Override
                          public void run() {
                            try {
                              job.run();
                            } finally {
                              dialog.dismiss();
                            }
                          }
                        });
                t.start();
              }
            });
  }
 /**
  * Constructor.
  *
  * @param ctx
  * @param app
  */
 public XWalkCordovaChromeClient(CordovaInterface ctx, CordovaWebView app) {
   super(((XWalkCordovaWebView) app).getView());
   this.cordova = ctx;
   this.appView = (XWalkCordovaWebView) app;
   this.appView
       .getView()
       .setXWalkWebChromeClient(new CordovaWebChromeClient(ctx.getActivity(), app));
 }
  public void tokenizeCard(CallbackContext callbackContext) {
    log("tokenizing card");
    if (card == null) {
      callbackContext.error("No card to tokenize");
      return;
    }

    TokenizationHandler tokenHandler = new TokenizationHandler(card, callbackContext);
    card.tokenize(tokenHandler, cordova.getActivity().getApplicationContext());
  }
Ejemplo n.º 10
0
  /**
   * Returns the mime type of the data specified by the given URI string.
   *
   * @param uriString the URI string of the data
   * @return the mime type of the specified data
   */
  public static String getMimeType(String uriString, CordovaInterface cordova) {
    String mimeType = null;

    Uri uri = Uri.parse(uriString);
    if (uriString.startsWith("content://")) {
      mimeType = cordova.getActivity().getContentResolver().getType(uri);
    } else {
      mimeType = getMimeTypeForExtension(uri.getPath());
    }

    return mimeType;
  }
Ejemplo n.º 11
0
 /**
  * Returns an input stream based on given URI string.
  *
  * @param uriString the URI string from which to obtain the input stream
  * @param cordova the current application context
  * @return an input stream into the data at the given URI or null if given an invalid URI string
  * @throws IOException
  */
 public static InputStream getInputStreamFromUriString(String uriString, CordovaInterface cordova)
     throws IOException {
   if (uriString.startsWith("content")) {
     Uri uri = Uri.parse(uriString);
     return cordova.getActivity().getContentResolver().openInputStream(uri);
   } else if (uriString.startsWith("file://")) {
     int question = uriString.indexOf("?");
     if (question > -1) {
       uriString = uriString.substring(0, question);
     }
     if (uriString.startsWith("file:///android_asset/")) {
       Uri uri = Uri.parse(uriString);
       String relativePath = uri.getPath().substring(15);
       return cordova.getActivity().getAssets().open(relativePath);
     } else {
       return new FileInputStream(getRealPath(uriString, cordova));
     }
   } else {
     return new FileInputStream(getRealPath(uriString, cordova));
   }
 }
Ejemplo n.º 12
0
  @Override
  public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    context = cordova.getActivity();

    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location != null) {
      onLocationChanged(location);
    }
  }
  @Override
  public void initialize(final CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      final Activity activity = cordova.getActivity();
      final Window window = activity.getWindow();

      setTranslucentStatus(window);

      tintManager = new SystemBarTintManager(activity);
    }
  }
Ejemplo n.º 14
0
  /**
   * Sets the context of the Command. This can then be used to do things like get file paths
   * associated with the Activity.
   *
   * @param cordova The context of the main Activity.
   * @param webView The CordovaWebView Cordova is running in.
   */
  public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    this.sockMan =
        (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    this.connectionCallbackContext = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    if (this.receiver == null) {
      this.receiver =
          new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
              // (The null check is for the ARM Emulator, please use Intel Emulator for better
              // results)
              if (NetworkManager.this.webView != null)
                updateConnectionInfo(sockMan.getActiveNetworkInfo());
            }
          };
      webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
  }
Ejemplo n.º 15
0
 public Object onMessage(String id, Object data) {
   return cordova.onMessage(id, data);
 }
Ejemplo n.º 16
0
 public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {
   cordova.startActivityForResult(command, intent, requestCode);
 }
  @Override
  public void initialize(final CordovaInterface cordova, final CordovaWebView webView) {
    super.initialize(cordova, webView);
    am = (AudioManager) cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
    reader = new AudioJackReader(am, true);

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    cordova
        .getActivity()
        .registerReceiver(
            new BroadcastReceiver() {
              @Override
              public void onReceive(Context context, Intent intent) {

                if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {

                  boolean plugged = (intent.getIntExtra("state", 0) == 1);

                  /* Mute the audio output if the reader is unplugged. */
                  reader.setMute(!plugged);
                  mute = !plugged;
                }
              }
            },
            filter);

    final StringBuffer buffer = new StringBuffer();
    final StringBuffer atrBuffer = new StringBuffer();

    reader.setSleepTimeout(30);

    reader.setOnPiccAtrAvailableListener(
        new AudioJackReader.OnPiccAtrAvailableListener() {
          @Override
          public void onPiccAtrAvailable(AudioJackReader audioJackReader, byte[] bytes) {
            Log.w(TAG, bytesToHex(bytes));

            atrBuffer.append(bytesToHex(bytes));
          }
        });

    reader.setOnPiccResponseApduAvailableListener(
        new AudioJackReader.OnPiccResponseApduAvailableListener() {
          @Override
          public void onPiccResponseApduAvailable(AudioJackReader audioJackReader, byte[] bytes) {
            byte[] resultBytes = new byte[bytes.length - 2];
            byte[] statusBytes = new byte[2];

            System.arraycopy(bytes, 0, resultBytes, 0, bytes.length - 2);
            System.arraycopy(bytes, bytes.length - 2, statusBytes, 0, 2);

            Log.w(TAG, bytesToHex(statusBytes));

            buffer.append(bytesToHex(resultBytes));
            buffer.append("");
          }
        });

    reader.setOnStatusAvailableListener(
        new AudioJackReader.OnStatusAvailableListener() {
          @Override
          public void onStatusAvailable(AudioJackReader audioJackReader, final Status status) {
            timer.cancel();

            cordova
                .getActivity()
                .runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        JSONArray resultArray = new JSONArray();
                        resultArray.put(Integer.toString(status.getBatteryLevel()));
                        resultArray.put(Integer.toString(status.getSleepTimeout()));

                        PluginResult dataResult =
                            new PluginResult(PluginResult.Status.OK, resultArray);
                        callbackContext.sendPluginResult(dataResult);
                      }
                    });
          }
        });

    reader.setOnDeviceIdAvailableListener(
        new AudioJackReader.OnDeviceIdAvailableListener() {
          @Override
          public void onDeviceIdAvailable(AudioJackReader audioJackReader, final byte[] bytes) {
            // reader.sleep();
            timer.cancel();

            cordova
                .getActivity()
                .runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        PluginResult dataResult =
                            new PluginResult(PluginResult.Status.OK, bytesToHex(bytes));
                        callbackContext.sendPluginResult(dataResult);
                      }
                    });
          }
        });

    reader.setOnResultAvailableListener(
        new AudioJackReader.OnResultAvailableListener() {
          @Override
          public void onResultAvailable(AudioJackReader audioJackReader, Result result) {
            // reader.sleep();
            timer.cancel();

            final String stringResult = buffer.toString();
            final String atrResult = atrBuffer.toString();

            Log.i(TAG, "Result Available");
            Log.i(TAG, stringResult);

            cordova
                .getActivity()
                .runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (timedOut) {
                          PluginResult dataResult =
                              new PluginResult(PluginResult.Status.OK, "TIMEDOUT");
                          callbackContext.sendPluginResult(dataResult);
                        } else {
                          JSONArray resultArray = new JSONArray();
                          resultArray.put(stringResult.replaceAll("\\s", ""));
                          resultArray.put(atrResult.replaceAll("\\s", ""));

                          PluginResult dataResult =
                              new PluginResult(PluginResult.Status.OK, resultArray);
                          callbackContext.sendPluginResult(dataResult);
                        }
                      }
                    });
            buffer.delete(0, buffer.length());
            atrBuffer.delete(0, atrBuffer.length());
          }
        });
  }
Ejemplo n.º 18
0
 public Activity getActivity() {
   return cordova.getActivity();
 }
Ejemplo n.º 19
0
 public void setActivityResultCallback(CordovaPlugin plugin) {
   cordova.setActivityResultCallback(plugin);
 }
 public void initialize(CordovaInterface cordova, CordovaWebView webView) {
   super.initialize(cordova, webView);
   this.sensorManager =
       (SensorManager) cordova.getActivity().getSystemService(Context.SENSOR_SERVICE);
 }
 /**
  * Sets the context of the Command. This can then be used to do things like get file paths
  * associated with the Activity.
  *
  * @param cordova The context of the main Activity.
  * @param webView The CordovaWebView Cordova is running in.
  */
 public void initialize(CordovaInterface cordova, CordovaWebView webView) {
   super.initialize(cordova, webView);
   context = cordova.getActivity().getApplicationContext();
   Log.v(TAG, "Init LocalAssets");
 }
 /**
  * Constructor.
  *
  * @param cordova
  * @param view
  */
 public SalesforceIceCreamWebViewClient(CordovaInterface cordova, CordovaWebView view) {
   super(cordova, view);
   this.ctx = (SalesforceDroidGapActivity) cordova.getActivity();
   this.cordovaWebView = view;
 }
 /**
  * Constructor.
  *
  * @param ctx
  * @param app
  */
 public CordovaChromeClient(CordovaInterface ctx, CordovaWebView app) {
   super(app);
   this.cordova = ctx;
   this.appView = app;
   this.appView.setXWalkWebChromeClient(new CordovaWebChromeClient(ctx.getActivity(), app));
 }
Ejemplo n.º 24
0
 public ExecutorService getThreadPool() {
   return cordova.getThreadPool();
 }