// Put up our own UI for how to handle the decoded contents.
 private void handleDecodeInternally(
     Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
   String content = rawResult.getText();
   Logger.i(content);
   Logger.i(StringUtils.isURL(content) + "");
   if (StringUtils.isURL(content)) {
     showCardView(content);
   } else {
     WarningDialog(content);
   }
 }
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   if (holder == null) {
     Logger.i("*** WARNING *** surfaceCreated() gave us a null surface!");
   }
   if (!hasSurface) {
     Logger.i("gogogo");
     hasSurface = true;
     initCamera(holder);
   }
 }
Example #3
0
  public void onCreate() {
    mApplication = this;
    Logger.setDebug(true);
    Logger.getLogger().setTag("wechat");
    ImageCacheUtil.init(this);
    Thread.setDefaultUncaughtExceptionHandler(AppException.getAppExceptionHandler());
    L.disableLogging();
    mNotificationManager =
        (NotificationManager) getSystemService(android.content.Context.NOTIFICATION_SERVICE);
    CookieStore cookieStore = new PersistentCookieStore(this);
    QYRestClient.getIntance().setCookieStore(cookieStore);

    Intent intent = new Intent();
    intent.setAction("tools.NetworkState.Service");
    startService(intent);
  }
  /**
   * 接收通知点击的函数。注:推送通知被用户点击前,应用无法通过接口获取通知的内容。
   *
   * @param context 上下文
   * @param title 推送的通知的标题
   * @param description 推送的通知的描述
   * @param customContentString 自定义内容,为空或者json字符串
   */
  @Override
  public void onNotificationClicked(
      Context context, String title, String description, String customContentString) {
    String notifyString =
        "通知点击 title=\""
            + title
            + "\" description=\""
            + description
            + "\" customContent="
            + customContentString;
    Logger.i(notifyString);

    // 自定义内容获取方式,mykey和myvalue对应通知推送时自定义内容中设置的键和值
    if (customContentString != null & customContentString != "") {
      JSONObject customJson = null;
      try {
        customJson = new JSONObject(customContentString);
        String myvalue = null;
        if (customJson.isNull("mykey")) {
          myvalue = customJson.getString("mykey");
        }
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    // Demo更新界面展示代码,应用请在这里加入自己的处理逻辑
    updateContent(context, notifyString);
  }
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   switch (keyCode) {
     case KeyEvent.KEYCODE_BACK:
       if (source == IntentSource.NATIVE_APP_INTENT) {
         setResult(RESULT_CANCELED);
         AppManager.getAppManager().finishActivity(this);
         overridePendingTransition(R.anim.exit_in_from_left, R.anim.exit_out_to_right);
         return true;
       }
       if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK)
           && lastResult != null) {
         restartPreviewAfterDelay(0L);
         Logger.i("dd");
         return true;
       } else {
         AppManager.getAppManager().finishActivity(this);
         overridePendingTransition(R.anim.exit_in_from_left, R.anim.exit_out_to_right);
       }
       break;
     case KeyEvent.KEYCODE_FOCUS:
     case KeyEvent.KEYCODE_CAMERA:
       // Handle these events so they don't launch the Camera app
       return true;
       // Use volume up/down to turn on light
     case KeyEvent.KEYCODE_VOLUME_DOWN:
       cameraManager.setTorch(false);
       return true;
     case KeyEvent.KEYCODE_VOLUME_UP:
       cameraManager.setTorch(true);
       return true;
   }
   return super.onKeyDown(keyCode, event);
 }
  /**
   * listTags() 的回调函数。
   *
   * @param context 上下文
   * @param errorCode 错误码。0表示列举tag成功;非0表示失败。
   * @param tags 当前应用设置的所有tag。
   * @param requestId 分配给对云推送的请求的id
   */
  @Override
  public void onListTags(Context context, int errorCode, List<String> tags, String requestId) {
    String responseString = "onListTags errorCode=" + errorCode + " tags=" + tags;
    Logger.i(responseString);

    // Demo更新界面展示代码,应用请在这里加入自己的处理逻辑
    updateContent(context, responseString);
  }
 /**
  * 接收透传消息的函数。
  *
  * @param context 上下文
  * @param message 推送的消息
  * @param customContentString 自定义内容,为空或者json字符串
  */
 @Override
 public void onMessage(Context context, String message, String customContentString) {
   String messageString =
       "透传消息 message=\"" + message + "\" customContentString=" + customContentString;
   Logger.i(messageString);
   if (message != null & message != "") {
     JSONObject customJson = null;
     try {
       customJson = new JSONObject(message);
       String title = customJson.getString("title");
       String content = customJson.getString("description");
       showNotify(title, content);
     } catch (JSONException e) {
       Logger.i(e);
       e.printStackTrace();
     }
   }
   //
   //		// Demo更新界面展示代码,应用请在这里加入自己的处理逻辑
   //		updateContent(context, messageString);
 }
  /**
   * PushManager.stopWork() 的回调函数。
   *
   * @param context 上下文
   * @param errorCode 错误码。0表示从云推送解绑定成功;非0表示失败。
   * @param requestId 分配给对云推送的请求的id
   */
  @Override
  public void onUnbind(Context context, int errorCode, String requestId) {
    String responseString = "onUnbind errorCode=" + errorCode + " requestId = " + requestId;
    Logger.i(responseString);

    // 解绑定成功,设置未绑定flag,
    if (errorCode == 0) {
      Utils.setBind(context, false);
    }
    // Demo更新界面展示代码,应用请在这里加入自己的处理逻辑
    updateContent(context, responseString);
  }
Example #9
0
  private void sendFeedback() {

    try {
      imm.hideSoftInputFromWindow(mContent.getWindowToken(), 0);
      String content = mContent.getText().toString();
      Logger.i(content);
      if (StringUtils.empty(content)) {
        UIHelper.ToastMessage(getApplicationContext(), "请输入内容", Toast.LENGTH_SHORT);
        return;
      }
      loadingPd = UIHelper.showProgress(this, null, null, true);
      AppClient.sendFeedback(
          appContext,
          content,
          new ClientCallback() {
            @Override
            public void onSuccess(Entity data) {
              UIHelper.dismissProgress(loadingPd);
              show1OptionsDialog(oprators);
            }

            @Override
            public void onFailure(String message) {
              UIHelper.dismissProgress(loadingPd);
              UIHelper.ToastMessage(getApplicationContext(), message, Toast.LENGTH_SHORT);
            }

            @Override
            public void onError(Exception e) {
              UIHelper.dismissProgress(loadingPd);
              Logger.i(e);
              UIHelper.ToastMessage(getApplicationContext(), "网络不给力", Toast.LENGTH_SHORT);
            }
          });
    } catch (Exception e) {
      Logger.i(e);
    }
  }
 @Override
 protected void onPause() {
   if (handler != null) {
     handler.quitSynchronously();
     handler = null;
   }
   inactivityTimer.onPause();
   ambientLightManager.stop();
   cameraManager.closeDriver();
   if (!hasSurface) {
     Logger.i("remove callback");
     SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
     SurfaceHolder surfaceHolder = surfaceView.getHolder();
     surfaceHolder.removeCallback(this);
   }
   super.onPause();
 }
  private void updateContent(Context context, String content) {
    //		Logger.i( "updateContent");
    //		String logText = "" + Utils.logStringCache;
    //
    //		if (!logText.equals("")) {
    //			logText += "\n";
    //		}
    //
    //		SimpleDateFormat sDateFormat = new SimpleDateFormat("HH-mm-ss");
    //		logText += sDateFormat.format(new Date()) + ": ";
    //		logText += content;
    Logger.i(content);
    //		Utils.logStringCache = logText;

    //		Intent intent = new Intent();
    //        intent.setClass(context.getApplicationContext(), Index.class);
    //        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    //        context.getApplicationContext().startActivity(intent);
  }
  /**
   * delTags() 的回调函数。
   *
   * @param context 上下文
   * @param errorCode 错误码。0表示某些tag已经删除成功;非0表示所有tag均删除失败。
   * @param successTags 成功删除的tag
   * @param failTags 删除失败的tag
   * @param requestId 分配给对云推送的请求的id
   */
  @Override
  public void onDelTags(
      Context context,
      int errorCode,
      List<String> sucessTags,
      List<String> failTags,
      String requestId) {
    String responseString =
        "onDelTags errorCode="
            + errorCode
            + " sucessTags="
            + sucessTags
            + " failTags="
            + failTags
            + " requestId="
            + requestId;
    Logger.i(responseString);

    // Demo更新界面展示代码,应用请在这里加入自己的处理逻辑
    updateContent(context, responseString);
  }
  // Briefly show the contents of the barcode, then handle the result outside Barcode Scanner.
  private void handleDecodeExternally(
      Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    if (barcode != null) {
      viewfinderView.drawResultBitmap(barcode);
    }

    long resultDurationMS;
    if (getIntent() == null) {
      resultDurationMS = DEFAULT_INTENT_RESULT_DURATION_MS;
    } else {
      resultDurationMS =
          getIntent()
              .getLongExtra(
                  Intents.Scan.RESULT_DISPLAY_DURATION_MS, DEFAULT_INTENT_RESULT_DURATION_MS);
    }

    // Since this message will only be shown for a second, just tell the user what kind of
    // barcode was found (e.g. contact info) rather than the full contents, which they won't
    // have time to read.
    if (resultDurationMS > 0) {
      Logger.i(getString(resultHandler.getDisplayTitle()));
    }

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
      ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
      CharSequence text = resultHandler.getDisplayContents();
      if (text != null) {
        clipboard.setText(text);
      }
    }

    if (source == IntentSource.NATIVE_APP_INTENT) {

      // Hand back whatever action they requested - this can be changed to Intents.Scan.ACTION when
      // the deprecated intent is retired.
      Intent intent = new Intent(getIntent().getAction());
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
      intent.putExtra(Intents.Scan.RESULT, rawResult.toString());
      intent.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString());
      byte[] rawBytes = rawResult.getRawBytes();
      if (rawBytes != null && rawBytes.length > 0) {
        intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes);
      }
      Map<ResultMetadataType, ?> metadata = rawResult.getResultMetadata();
      if (metadata != null) {
        if (metadata.containsKey(ResultMetadataType.UPC_EAN_EXTENSION)) {
          intent.putExtra(
              Intents.Scan.RESULT_UPC_EAN_EXTENSION,
              metadata.get(ResultMetadataType.UPC_EAN_EXTENSION).toString());
        }
        Integer orientation = (Integer) metadata.get(ResultMetadataType.ORIENTATION);
        if (orientation != null) {
          intent.putExtra(Intents.Scan.RESULT_ORIENTATION, orientation.intValue());
        }
        String ecLevel = (String) metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
        if (ecLevel != null) {
          intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, ecLevel);
        }
        Iterable<byte[]> byteSegments =
            (Iterable<byte[]>) metadata.get(ResultMetadataType.BYTE_SEGMENTS);
        if (byteSegments != null) {
          int i = 0;
          for (byte[] byteSegment : byteSegments) {
            intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, byteSegment);
            i++;
          }
        }
      }
      sendReplyMessage(R.id.return_scan_result, intent, resultDurationMS);

    } else if (source == IntentSource.PRODUCT_SEARCH_LINK) {

      // Reformulate the URL which triggered us into a query, so that the request goes to the same
      // TLD as the scan URL.
      int end = sourceUrl.lastIndexOf("/scan");
      String replyURL =
          sourceUrl.substring(0, end)
              + "?q="
              + resultHandler.getDisplayContents()
              + "&source=zxing";
      sendReplyMessage(R.id.launch_product_query, replyURL, resultDurationMS);

    } else if (source == IntentSource.ZXING_LINK) {

      if (scanFromWebPageManager != null && scanFromWebPageManager.isScanFromWebPage()) {
        String replyURL = scanFromWebPageManager.buildReplyURL(rawResult, resultHandler);
        sendReplyMessage(R.id.launch_product_query, replyURL, resultDurationMS);
      }
    }
  }
  @Override
  protected void onResume() {
    super.onResume();
    lightState = false;
    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;
    lastResult = null;

    resetStatusView();

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
      Logger.i("restart cam");
      // The activity was paused but not stopped, so the surface still exists. Therefore
      // surfaceCreated() won't be called, so init the camera here.
      initCamera(surfaceHolder);
    } else {
      Logger.i("install cam");
      // Install the callback and wait for surfaceCreated() to init the camera.
      surfaceHolder.addCallback(this);
      surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    beepManager.updatePrefs();
    ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    Intent intent = getIntent();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    copyToClipboard =
        prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
            && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));

    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;

    if (intent != null) {

      String action = intent.getAction();
      String dataString = intent.getDataString();

      if (Intents.Scan.ACTION.equals(action)) {

        // Scan the formats the intent requested, and return the result to the calling activity.
        source = IntentSource.NATIVE_APP_INTENT;
        decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);

        if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
          int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
          int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
          if (width > 0 && height > 0) {
            cameraManager.setManualFramingRect(width, height);
          }
        }

        String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
        if (customPromptMessage != null) {
          Logger.i(customPromptMessage);
        }

      } else if (dataString != null
          && dataString.contains(PRODUCT_SEARCH_URL_PREFIX)
          && dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {

        // Scan only products and send the result to mobile Product Search.
        source = IntentSource.PRODUCT_SEARCH_LINK;
        sourceUrl = dataString;
        decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;

      } else if (isZXingURL(dataString)) {

        // Scan formats requested in query string (all formats if none specified).
        // If a return URL is specified, send the results there. Otherwise, handle it ourselves.
        source = IntentSource.ZXING_LINK;
        sourceUrl = dataString;
        Uri inputUri = Uri.parse(dataString);
        scanFromWebPageManager = new ScanFromWebPageManager(inputUri);
        decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);
      }

      characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);
    }
  }