@Override public void run() { try { qRCodeBitmap = EncodingHandler.createQRCode(Constant.APP_DOWNLOAD_WEBSITE , (int) (2 * getResources().getDimension(R.dimen.qrcode_size))); } catch (WriterException e) { e.printStackTrace(); Log.e(TAG, "initData try {Bitmap qrcode = EncodingHandler.createQRCode(contactJson, ivContactQRCodeCode.getWidth());" + " >> } catch (WriterException e) {" + e.getMessage()); } runUiThread(new Runnable() { @Override public void run() { ivAboutQRCode.setImageBitmap(qRCodeBitmap); } }); } });
@Override public void run() { try { qRCodeBitmap = EncodingHandler.createQRCode(Constant.APP_DOWNLOAD_WEBSITE , (int) (2 * getResources().getDimension(R.dimen.qrcode_size))); } catch (WriterException e) { e.printStackTrace(); Log.e(TAG, "initData try {Bitmap qrcode = EncodingHandler.createQRCode(contactJson, ivContactQRCodeCode.getWidth());" + " >> } catch (WriterException e) {" + e.getMessage()); } runUiThread(new Runnable() { @Override public void run() { ivAboutQRCode.setImageBitmap(qRCodeBitmap); } }); } });
protected void setQRCode(User user) { if (user == null) { Log.e(TAG, "setQRCode user == null" + " || StringUtil.isNotEmpty(user.getPhone(), true) == false >> return;"); return; } try { qRCodeBitmap = EncodingHandler.createQRCode(JSON.toJSONString(user) , (int) (2 * getResources().getDimension(R.dimen.qrcode_size))); } catch (WriterException e) { e.printStackTrace(); Log.e(TAG, "initData try {Bitmap qrcode = EncodingHandler.createQRCode(contactJson, ivQRCodeCode.getWidth());" + " >> } catch (WriterException e) {" + e.getMessage()); } runUiThread(new Runnable() { @Override public void run() { ivQRCodeProgress.setVisibility(View.GONE); ivQRCodeCode.setImageBitmap(qRCodeBitmap); } }); }
protected void setQRCode(User user) { // if (user == null) { // Log.e(TAG, "setQRCode user == null" + // " || StringUtil.isNotEmpty(user.getPhone(), true) == false >> return;"); // return; // } try { //不能暴露用户隐私 qRCodeBitmap = EncodingHandler.createQRCode(HttpRequest.URL_GET + JSON.toJSONString(new JSONRequest(new apijson.demo.server.model.User(userId))) , (int) (2 * getResources().getDimension(R.dimen.qrcode_size))); } catch (WriterException e) { e.printStackTrace(); Log.e(TAG, "initData try {Bitmap qrcode = EncodingHandler.createQRCode(contactJson, ivQRCodeCode.getWidth());" + " >> } catch (WriterException e) {" + e.getMessage()); } runUiThread(new Runnable() { @Override public void run() { ivQRCodeProgress.setVisibility(View.GONE); ivQRCodeCode.setImageBitmap(qRCodeBitmap); } }); }
public void updateQrCode(WifiNetwork wifiNetwork) { DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); float widthInDp = 200f; int widthInPixels = (int) (metrics.density * widthInDp + 0.5f); try { Bitmap qrCodeBitmap = QrCodeUtils.generateWifiQrCode(widthInPixels, wifiNetwork); qrCodeImageView.setImageBitmap(qrCodeBitmap); } catch (final WriterException e) { Log.d(TAG, e.getMessage()); } } }
@Override public void CreateQrCode() { JSONObject userJson = HTApp.getInstance().getUserJson(); JSONObject allobj = new JSONObject(); allobj.put("codeType",2); JSONObject object =new JSONObject(); object.put(HTConstant.JSON_KEY_HXID,HTApp.getInstance().getUsername()); object.put(HTConstant.JSON_KEY_NICK,userJson.getString(HTConstant.JSON_KEY_NICK)); object.put(HTConstant.JSON_KEY_TEL,userJson.getString(HTConstant.JSON_KEY_TEL)); object.put(HTConstant.JSON_KEY_FXID,userJson.getString(HTConstant.JSON_KEY_FXID)); object.put(HTConstant.JSON_KEY_SEX,userJson.getString(HTConstant.JSON_KEY_SEX)); object.put(HTConstant.JSON_KEY_AVATAR,userJson.getString(HTConstant.JSON_KEY_AVATAR)); object.put(HTConstant.JSON_KEY_PROVINCE,userJson.getString(HTConstant.JSON_KEY_PROVINCE)); object.put(HTConstant.JSON_KEY_CITY,userJson.getString(HTConstant.JSON_KEY_CITY)); object.put(HTConstant.JSON_KEY_SIGN,userJson.getString(HTConstant.JSON_KEY_SIGN)); allobj.put("data",object.toJSONString()); try { Bitmap bitmap = generateQRCode(allobj.toJSONString()); codeView.showQrCode(bitmap); } catch (WriterException e) { codeView.showError(e.getMessage()); e.printStackTrace(); } }
@Override public void CreateQrCode() { JSONObject userJson = HTApp.getInstance().getUserJson(); String key = "userInfo:"; JSONObject object =new JSONObject(); object.put(HTConstant.JSON_KEY_HXID,HTApp.getInstance().getUsername()); object.put(HTConstant.JSON_KEY_NICK,userJson.getString(HTConstant.JSON_KEY_NICK)); object.put(HTConstant.JSON_KEY_TEL,userJson.getString(HTConstant.JSON_KEY_TEL)); object.put(HTConstant.JSON_KEY_FXID,userJson.getString(HTConstant.JSON_KEY_FXID)); object.put(HTConstant.JSON_KEY_SEX,userJson.getString(HTConstant.JSON_KEY_SEX)); object.put(HTConstant.JSON_KEY_AVATAR,userJson.getString(HTConstant.JSON_KEY_AVATAR)); object.put(HTConstant.JSON_KEY_PROVINCE,userJson.getString(HTConstant.JSON_KEY_PROVINCE)); object.put(HTConstant.JSON_KEY_CITY,userJson.getString(HTConstant.JSON_KEY_CITY)); object.put(HTConstant.JSON_KEY_SIGN,userJson.getString(HTConstant.JSON_KEY_SIGN)); try { Bitmap bitmap = generateQRCode(key + object.toJSONString()); codeView.showQrCode(bitmap); } catch (WriterException e) { codeView.showError(e.getMessage()); e.printStackTrace(); } }
/** * 生成自定义尺寸带logo的二维码 * * @param output 图片文件 * @param width 宽 * @param height 高 * @param logoImg logo图片 * @param text 二维码内容 * @param title 二维码图片描述 * @param size 字体大小 */ public static void createCodeLogo(File output, String text, InputStream logoImg, String title, int width, int height, int size) { try { internal._codeHeight = height; internal._codeWidth = width; internal._logoImg = logoImg; internal._text = title; internal._fontSize = size; internal._output = output; BitMatrix bitMatrix = internal.createCode(text); internal.addMaterial(bitMatrix); } catch (WriterException e) { log.error(e.getMessage()); throw new UtilException("生成自定义尺寸带logo的二维码失败"); } }
/** * 二维码支付 */ private void qRCodePayment() { // TODO Auto-generated method stub if (gateway instanceof PaymentQRCode) { PaymentQRCode paymentQRCode = (PaymentQRCode) gateway; try { buildQRCodeImage(paymentQRCode.getPaymentQRCodeContent()); } catch (IOException e) { // TODO Auto-generated catch block throw new GatewayException(e.getMessage(), e); } catch (WriterException e) { // TODO Auto-generated catch block throw new GatewayException(e.getMessage(), e); } return; } throw new NotImplementedException(gateway.getGatewayType() + " 没有实现 PaymentQRCode 支付接口"); }
@NonNull @Override public Uri generate(@NonNull String text) throws QRBarcodeGeneratorException { try { BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, QR_PIXELS, QR_PIXELS); Bitmap bitmap = bitMatrixToBitmap(bitMatrix); return fileUriHandler.saveFile(bitmap); } catch (WriterException e) { Logger.e("decodeQR failed. ", e); throw new QRBarcodeGeneratorException("Cannot generate a QR, caused by : " + e.getMessage(), e); } catch (IOException e) { Logger.e("decodeQR failed. ", e); throw new QRFileHandlingException("Cannot load QR file, caused by :" + e.getMessage(), e); } }