Android Open Source - Abstack-books-management Camera Plugin






From Project

Back to project page Abstack-books-management.

License

The source code is released under:

MIT License

If you think the Android project Abstack-books-management listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.abstack.book.plugin;
/*from w w  w.j a v  a2 s  .  c o m*/
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.abstack.book.CaptureActivity;

public class CameraPlugin extends CordovaPlugin{
  @Override
  public boolean execute(String action, JSONArray args,
      CallbackContext callbackContext) throws JSONException {
    if ("scan".equals(action)) {
      this.scan(args, callbackContext);
    }
    return true;
  }

  private void scan(JSONArray args, CallbackContext callbackContext) {
    Intent openCameraIntent = new Intent(this.cordova.getActivity(),CaptureActivity.class);
    hand.setCallback(callbackContext);
    this.cordova.startActivityForResult(this, openCameraIntent, 0);
    PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT);  
        mPlugin.setKeepCallback(true);  
        callbackContext.sendPluginResult(mPlugin);
  }
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    //????????????????????
    if (resultCode == Activity.RESULT_OK) {
      Bundle bundle = data.getExtras();
      final String scanResult = bundle.getString("result");
      new Thread(new Runnable(){
        @Override
        public void run() {
          Message message = new Message();
          message.obj = scanResult;
          message.what = OK;
          hand.sendMessage(message);
        }
      }).start();
    }
  }
  public final static int OK = 200; 
  
  @SuppressLint("HandlerLeak")
  class Hand extends Handler {
    public CallbackContext callback;
    public void setCallback(CallbackContext callback) {
      this.callback = callback;
    }
  }
  private Hand hand = new Hand() {
    public void handleMessage(Message msg) {
      Log.wtf("assert", msg.obj.toString());
      switch (msg.what) {
      case OK:
        if (callback!=null)
          callback.success("{\"success\": true, \"ISBN\": \""+msg.obj+"\"}");
          break;
      default:
        if (callback!=null)
          callback.error("{\"success\": false, \"message\": \"????????\"}");
      }
    };
  };
}




Java Source Code List

com.abstack.book.AbstackBook.java
com.abstack.book.CaptureActivity.java
com.abstack.book.plugin.CameraPlugin.java
com.abstack.book.plugin.ToastPlugin.java
com.abstack.book.plugin.camera.AutoFocusCallback.java
com.abstack.book.plugin.camera.CameraConfigurationManager.java
com.abstack.book.plugin.camera.CameraManager.java
com.abstack.book.plugin.camera.FlashlightManager.java
com.abstack.book.plugin.camera.PlanarYUVLuminanceSource.java
com.abstack.book.plugin.camera.PreviewCallback.java
com.abstack.book.plugin.camera.decoding.CaptureActivityHandler.java
com.abstack.book.plugin.camera.decoding.DecodeFormatManager.java
com.abstack.book.plugin.camera.decoding.DecodeHandler.java
com.abstack.book.plugin.camera.decoding.DecodeThread.java
com.abstack.book.plugin.camera.decoding.FinishListener.java
com.abstack.book.plugin.camera.decoding.InactivityTimer.java
com.abstack.book.plugin.camera.decoding.Intents.java
com.abstack.book.plugin.camera.encoding.EncodingHandler.java
com.abstack.book.plugin.camera.util.HttpConnection.java
com.abstack.book.plugin.camera.view.ViewfinderResultPointCallback.java
com.abstack.book.plugin.camera.view.ViewfinderView.java