void netActivatedAtLeader(NetInfo net) { // update GUI showGroup(3); // ssl boolean checked = useSSLBox.isChecked(); // String pass = net.pass; if (pass != null && (pass.length() == 0 || pass.equals("*"))) { pass = null; } peerNetData = new PeerNetInfo(net.name, net.pass, net.encrypt, net.hidden, checked, net.addr); Log.d(TAG, "encode QRCode for: " + peerNetData.encode()); int dim = mTypes.getWidth(); // int dim = groupNType.getWidth(); Log.d(TAG, "image view dim=" + dim); // try { Bitmap bitmap = QRCodeEncoder.encodeAsBitmap(peerNetData.encode(), dim); qrCodeView.setImageBitmap(bitmap); } catch (WriterException e) { Log.e(TAG, "Could not encode barcode", e); } catch (IllegalArgumentException e) { Log.e(TAG, "Could not encode barcode", e); } // init NFC transfer if (mNfcAdapter != null) { Log.d(TAG, "init NFC transfer"); initNfcTransfer(peerNetData); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == DECODE_QRCODE_REQ) { String res = data.getStringExtra("DecodeResult"); // hide my-member gui, show progr dialog showGroup(-1); // Log.d(TAG, "Decoded raw res: " + res); if (res != null) { peerNetData = PeerNetInfo.decode(res); if (peerNetData != null) { Log.d(TAG, "Decoded QRCode: " + peerNetData.toString()); Log.d(TAG, "chosen Ntype : " + chosenNType); setupWifiConn(peerNetData); } } } }
@TargetApi(Build.VERSION_CODES.GINGERBREAD) void processNfcIntent(Intent intent) { nfcIntent = intent; Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; // get encoded data String res = new String(msg.getRecords()[0].getPayload()); // show progr bar showGroup(-1); // handle it Log.d(TAG, "Decoded raw res: " + res); isLeader = false; chosenNType = NetInfo.WiFi; if (res != null) { peerNetData = PeerNetInfo.decode(res); if (peerNetData != null) { Log.d(TAG, "Decoded PeerNetInfo: " + peerNetData.toString()); Log.d(TAG, "chosen Ntype : " + chosenNType); setupWifiConn(peerNetData); } } }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) void initNfcTransfer(PeerNetInfo qrData) { if (mNfcAdapter != null && mNfcAdapter.isEnabled() && useNFC) { NdefMessage msg = new NdefMessage( new NdefRecord[] { new NdefRecord( NdefRecord.TNF_MIME_MEDIA, "application/com.xconns.peerdevicenet.connector" .getBytes(Charset.forName("US-ASCII")), new byte[0], qrData.encode().getBytes(Charset.forName("US-ASCII"))) }); mNfcAdapter.setNdefPushMessage(msg, this); } }