@TargetApi(14)
 private void initNFC() {
   NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
   if (nfc != null) {
     nfc.setNdefPushMessageCallback(new NfcCallback(server), this);
   }
 }
Beispiel #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    deviceNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (deviceNfcAdapter != null) {
      // Refer back to createNdefMessage to send
      deviceNfcAdapter.setNdefPushMessageCallback(this, this);

      // This will be called if message sent successfully
      deviceNfcAdapter.setOnNdefPushCompleteCallback(this, this);
    } else {
      Toast.makeText(this, "NFC not available on your device.", Toast.LENGTH_LONG).show();
    }

    addMessageInput = (EditText) findViewById(R.id.txtBoxAddMessage);
    messagesToSend = (TextView) findViewById(R.id.txtMessageToSend);
    receivedMessageOutput = (TextView) findViewById(R.id.txtMessagesReceived);
    Button addMessage = (Button) findViewById(R.id.buttonAddMessage);

    updateTextViews();

    if (getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) {
      handleNfcIntent(getIntent());
    }
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // set the main.xml layout of 3 editable textfields and an update
    // button:
    setContentView(R.layout.nfc_beam);
    findViewById(R.id.write_tag).setOnClickListener(mTagWriter);
    mName = ((EditText) findViewById(R.id.computer_name));
    mRAM = ((EditText) findViewById(R.id.computer_ram));
    mProcessor = ((EditText) findViewById(R.id.computer_processor));

    // get an instance of the context's cached NfcAdapter
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    // if null is returned this demo cannot run. Use this check if the
    // "required" parameter of <uses-feature> in the manifest is not set
    if (mNfcAdapter == null) {
      Toast.makeText(this, "Your device does not support NFC. Cannot run demo.", Toast.LENGTH_LONG)
          .show();
      finish();
      return;
    }

    // check if NFC is enabled
    checkNfcEnabled();

    // Handle foreground NFC scanning in this activity by creating a
    // PendingIntent with FLAG_ACTIVITY_SINGLE_TOP flag so each new scan
    // is not added to the Back Stack
    mNfcPendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Create intent filter to handle NDEF NFC tags detected from inside our
    // application when in "read mode":
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
      ndefDetected.addDataType("application/root.gast.playground.nfc");
    } catch (MalformedMimeTypeException e) {
      throw new RuntimeException("Could not add MIME type.", e);
    }

    // Create intent filter to detect any NFC tag when attempting to write
    // to a tag in "write mode"
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);

    // create IntentFilter arrays:
    mWriteTagFilters = new IntentFilter[] {tagDetected};
    mReadTagFilters = new IntentFilter[] {ndefDetected, tagDetected};

    // register the callback
    // usage: setNdefPushMessageCallback( callback, activity,
    // optionalExtraActivities)
    mNfcAdapter.setNdefPushMessageCallback(this, this);
  }
Beispiel #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_nfmain);

    mInfoText = (TextView) findViewById(R.id.textView);
    // Check for available NFC Adapter
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
      mInfoText = (TextView) findViewById(R.id.textView);
      mInfoText.setText("NFC is not available on this device.");
    } else {
      // Register callback to set NDEF message
      mNfcAdapter.setNdefPushMessageCallback(this, this);
      // Register callback to listen for message-sent success
      mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
    }

    // start Facebook Login
    Session.openActiveSession(
        this,
        true,
        new Session.StatusCallback() {

          // callback when session changes state
          @Override
          public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {

              // make request to the /me API
              Request.executeMeRequestAsync(
                  session,
                  new Request.GraphUserCallback() {

                    // callback after Graph API response with user object
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                      if (user != null) {
                        Toast.makeText(
                                getApplicationContext(),
                                "Welcome " + user.getName() + " : " + user.getId() + "!",
                                Toast.LENGTH_LONG)
                            .show();
                        userId = user.getId();
                      }
                    }
                  });
            }
          }
        });
  }
Beispiel #5
0
  @SuppressLint("NewApi")
  private boolean registerAndroidBeam() {
    if (android.os.Build.VERSION.SDK_INT >= 16) {

      CreateNdefMessageCallback ndefMessageCallback =
          new CreateNdefMessageCallback() {

            @Override
            public NdefMessage createNdefMessage(NfcEvent event) {
              SQLiteConnection sql = new SQLiteConnection(getApplicationContext());
              String[] user = sql.getUser();
              sql.close();

              String name = user[3] + " " + user[2];
              token =
                  Functions.makeMD5Hash(
                      name + String.valueOf((new Timestamp(System.currentTimeMillis())).getTime()));

              NdefMessage msg =
                  new NdefMessage(
                      NdefRecord.createMime(
                          "application/com.example.android.beam", (name + "|" + token).getBytes()));
              return msg;
            }
          };
      OnNdefPushCompleteCallback ndefPushCompleteCallback =
          new OnNdefPushCompleteCallback() {

            @Override
            public void onNdefPushComplete(NfcEvent event) {
              ndefOnCompleteHandler.obtainMessage(MESSAGE_SENT).sendToTarget();
            }
          };

      mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
      if (mNfcAdapter == null) {
        return false;
      } else {

        // Register callback to set NDEF message
        mNfcAdapter.setNdefPushMessageCallback(ndefMessageCallback, this);
        // Register callback to listen for message-sent success
        mNfcAdapter.setOnNdefPushCompleteCallback(ndefPushCompleteCallback, this);
      }
    }
    return true;
  }
  @TargetApi(14)
  private void setNfcCallBack() {
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
    CreateNdefMessageCallback callback =
        new CreateNdefMessageCallback() {

          @Override
          public NdefMessage createNdefMessage(NfcEvent event) {
            final String url = getUrl();
            NdefMessage msg = new NdefMessage(new NdefRecord[] {NdefRecord.createUri(url)});
            return msg;
          }
        };
    if (adapter != null) {
      adapter.setNdefPushMessageCallback(callback, this);
    }
  }
 protected void registerNdefPushMessageCallback() {
   NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
   if (nfcAdapter != null && nfcAdapter.isEnabled()) {
     nfcAdapter.setNdefPushMessageCallback(
         new NfcAdapter.CreateNdefMessageCallback() {
           @Override
           public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
             return new NdefMessage(
                 new NdefRecord[] {
                   NdefRecord.createUri(getShareableUri()),
                   NdefRecord.createApplicationRecord("eu.siacs.conversations")
                 });
           }
         },
         this);
   }
 }
  @TargetApi(14)
  void setNfcCallBack() {
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
    CreateNdefMessageCallback callback =
        new CreateNdefMessageCallback() {

          @Override
          public NdefMessage createNdefMessage(NfcEvent event) {
            FragmentManager fm = getSupportFragmentManager();
            TopiclistContainer f1 = (TopiclistContainer) fm.findFragmentById(R.id.item_list);
            final String url = f1.getNfcUrl();
            NdefMessage msg = new NdefMessage(new NdefRecord[] {NdefRecord.createUri(url)});
            return msg;
          }
        };
    if (adapter != null) {
      adapter.setNdefPushMessageCallback(callback, this);
    }
  }
Beispiel #9
0
  private String initNfcAdapter(NfcAdapter adapter) {
    StringBuilder sb = new StringBuilder();

    // nfc 功能是否开启
    if (nfcAdapter == null) {
      sb.append("支持NFC功能:" + false + "\n");
      return sb.toString();
    } else {
      sb.append("支持NFC功能:" + true + "\n");
    }
    isNfcEnable = nfcAdapter.isEnabled();
    sb.append("NFC是否开启:" + isNfcEnable + "\n");

    isNdefPushEnabled = nfcAdapter.isNdefPushEnabled();
    sb.append("Android Beam是否开启:" + isNdefPushEnabled + "\n");

    nfcAdapter.setNdefPushMessageCallback(this, this);
    nfcAdapter.setOnNdefPushCompleteCallback(this, this);

    return sb.toString();
  }
 protected void unregisterNdefPushMessageCallback() {
   NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
   if (nfcAdapter != null && nfcAdapter.isEnabled()) {
     nfcAdapter.setNdefPushMessageCallback(null, this);
   }
 }
Beispiel #11
0
  // onCreate
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // requestWindowFeature(Window.FEATURE_NO_TITLE);

    // startActivity(new Intent(this,IntroActivity.class));

    textView10 = (TextView) findViewById(R.id.textView1);

    // ActionBar Basic Setting
    mAb = getActionBar();
    mAb.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00B0F0")));
    mAb.setTitle("문지기");
    mAb.setDisplayShowHomeEnabled(false);

    // Tabs_frame
    TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    Log.i(TAG, "tabHost : " + tabHost);
    tabHost.setup(); // TabHost 객체를 생성하여 setup() 메소드를 실행

    // tab1 = tab_home
    TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1");
    spec1.setContent(R.id.imageView1);
    spec1.setIndicator("", getResources().getDrawable(R.drawable.ic_home));
    tabHost.addTab(spec1);
    // tabHost.addTab(tabHost.newTabSpec("tab1")
    // .setIndicator("",getResources().getDrawable(R.drawable.ic_home))
    // .setContent(R.id.tab_home));

    // tab2 = tab_log
    TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2");
    spec2.setContent(R.id.linearLayoutLog);
    spec2.setIndicator("", getResources().getDrawable(R.drawable.ic_log));
    tabHost.addTab(spec2);

    // tab3 = tab_imageprocess
    TabHost.TabSpec spec3 = tabHost.newTabSpec("tab3");
    spec3.setContent(R.id.linearLayoutImageProcess);
    spec3.setIndicator("", getResources().getDrawable(R.drawable.ic_imageprocess));
    tabHost.addTab(spec3);

    // tab4 = tab_imagecapture
    TabHost.TabSpec spec4 = tabHost.newTabSpec("tab4");
    spec4.setContent(R.id.LinearLayoutImageCapture);
    spec4.setIndicator("", getResources().getDrawable(R.drawable.ic_imagecapture));
    tabHost.addTab(spec4);

    // tab5 = tab_setting
    TabHost.TabSpec spec5 = tabHost.newTabSpec("tab5");
    spec5.setContent(R.id.LinearLayoutSetting);
    spec5.setIndicator("", getResources().getDrawable(R.drawable.ic_setting));
    tabHost.addTab(spec5);

    tabHost.setCurrentTab(0);
    tabHost.getTabWidget().setDividerDrawable(null);

    for (int tab = 0; tab < tabHost.getTabWidget().getChildCount(); ++tab) {
      tabHost.getTabWidget().getChildAt(tab).getLayoutParams().height = 120;
    }

    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
      tabHost
          .getTabWidget()
          .getChildAt(i)
          .setBackgroundColor(Color.parseColor("#EBEBEB")); // 235235235

      tabHost.getTabWidget().setCurrentTab(1);
    }

    tabHost.setOnTabChangedListener(this);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter != null) {
      // Register callback
      mNfcAdapter.setNdefPushMessageCallback(null, this);
      mNfcAdapter.setOnNdefPushCompleteCallback(null, this);
    } else {
      setToast("이 장치는 nfc가 활성화되지 않았습니다.");
    }

    // create an NDEF message with two records of plain text type

    intent = new Intent(getApplicationContext(), MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);

    // set an intent filter for all MIME data
    IntentFilter ndefIntent = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
      ndefIntent.addDataType("*/*");
      mIntentFilters = new IntentFilter[] {ndefIntent};
    } catch (Exception e) {
      Log.e("TagDispatch", e.toString());
    }
    /*
    appIcon = (Button)findViewById(R.id.appicon);
    appName = (TextView)findViewById(R.id.appName);
    tabName = (TextView)findViewById(R.id.tabName);
    appName.setBackgroundColor(Color.TRANSPARENT);
    tabName.setBackgroundColor(Color.TRANSPARENT);

    tab0 = (Button)findViewById(R.id.tab0);
    tab1 = (Button)findViewById(R.id.tab1);
    tab2 = (Button)findViewById(R.id.tab2);
    tab3 = (Button)findViewById(R.id.tab3);
    tab4 = (Button)findViewById(R.id.tab4);
    tab0.setOnClickListener(this);
    tab1.setOnClickListener(this);
    tab2.setOnClickListener(this);
    tab3.setOnClickListener(this);
    tab4.setOnClickListener(this);
    tab0.setBackgroundColor(Color.TRANSPARENT);
    tab1.setBackgroundColor(Color.TRANSPARENT);
    tab2.setBackgroundColor(Color.TRANSPARENT);
    tab3.setBackgroundColor(Color.TRANSPARENT);
    tab4.setBackgroundColor(Color.TRANSPARENT);
    */

    // mAb = getActionBar(); // �쁾�븸��?�諛붾��? �꺆 �삎�떇�쑝濡� 蹂�寃�
    // mAb.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mImageView1 = (LinearLayout) findViewById(R.id.imageView1);
    // mImageView111 = (ImageView) findViewById(R.id.imageView111);
    // mImageView1.setOnClickListener(this);
    // mLinearLayout1 = (LinearLayout) findViewById(R.id.linearLayoutLog);
    // mLinearLayout2 = (LinearLayout) findViewById(R.id.linearLayoutImageProcess);
    // mLinearLayout3 = (LinearLayout) findViewById(R.id.LinearLayoutImageCapture);
    // mLinearLayout4 = (LinearLayout) findViewById(R.id.LinearLayoutSetting);

    /*addActionBarTab("Home"); // �쁾�븸��?�諛붿뿉 2媛쒖?�� �꺆 踰꾪?�� ?��붽�
    addActionBarTab("Log");
    addActionBarTab("Image");
    addActionBarTab("Capture");
    addActionBarTab("Setting");*/

    initializeSetting();
    initializeMainWork();
    initializeHandler();
    initializeSocket();
    initializeLog();
    initializeVideo();
    initializeCapture();

    Debug.getNativeHeapSize();
    Debug.getNativeHeapFreeSize();
    Debug.getNativeHeapAllocatedSize();

    ///////////////////////////////////
    // CONNECTION_SERVER = true;
    // CONNECTION_USER = true;
    // mVideo.setUri("rtsp://172.30.99.9:8080/application.sdp");

  }
 void disablePush() {
   adapter.setNdefPushMessageCallback(null, this);
 }
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // enable progress bar above action bar
    requestWindowFeature(Window.FEATURE_PROGRESS);

    setContentView(R.layout.activity_main);
    mImageLoading = findViewById(R.id.imageLoading);
    mIitcWebView = (IITC_WebView) findViewById(R.id.iitc_webview);
    mLvDebug = (ListView) findViewById(R.id.lvDebug);
    mViewDebug = findViewById(R.id.viewDebug);
    mBtnToggleMap = (ImageButton) findViewById(R.id.btnToggleMapVisibility);
    mEditCommand = (EditText) findViewById(R.id.editCommand);
    mEditCommand.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(
              final TextView v, final int actionId, final KeyEvent event) {
            if (EditorInfo.IME_ACTION_GO == actionId
                || EditorInfo.IME_ACTION_SEND == actionId
                || EditorInfo.IME_ACTION_DONE == actionId) {
              onBtnRunCodeClick(v);

              final InputMethodManager imm =
                  (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

              return true;
            }
            return false;
          }
        });

    mLvDebug.setAdapter(new IITC_LogAdapter(this));
    mLvDebug.setOnItemLongClickListener(this);

    // do something if user changed something in the settings
    mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mSharedPrefs.registerOnSharedPreferenceChangeListener(this);

    // enable/disable mDesktopMode mode on menu create and url load
    mDesktopMode = mSharedPrefs.getBoolean("pref_force_desktop", false);

    // enable/disable advance menu
    final String[] menuDefaults = getResources().getStringArray(R.array.pref_android_menu_default);
    mAdvancedMenu =
        mSharedPrefs.getStringSet(
            "pref_android_menu", new HashSet<String>(Arrays.asList(menuDefaults)));

    mPersistentZoom = mSharedPrefs.getBoolean("pref_persistent_zoom", false);

    // get fullscreen status from settings
    mIitcWebView.updateFullscreenStatus();

    mFileManager = new IITC_FileManager(this);
    mFileManager.setUpdateInterval(
        Integer.parseInt(mSharedPrefs.getString("pref_update_plugins_interval", "7")));

    mUserLocation = new IITC_UserLocation(this);
    mUserLocation.setLocationMode(
        Integer.parseInt(mSharedPrefs.getString("pref_user_location_mode", "0")));

    // pass ActionBar to helper because we deprecated getActionBar
    mNavigationHelper = new IITC_NavigationHelper(this, super.getActionBar());

    mMapSettings = new IITC_MapSettings(this);

    // Clear the back stack
    mBackStack.clear();

    // receive downloadManagers downloadComplete intent
    // afterwards install iitc update
    registerReceiver(
        mBroadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

    final NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
    if (nfc != null) nfc.setNdefPushMessageCallback(this, this);

    handleIntent(getIntent(), true);
  }
Beispiel #14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_friend);

    // initialize the variables
    friendListview = (ListView) findViewById(R.id.friend_listview);
    txtUserMessage = (TextView) findViewById(R.id.txtVwAddFriendWelcome);
    txtNFC = (TextView) findViewById(R.id.textView_nfc);

    // hide the listviews
    // friendListview.setVisibility(View.GONE);

    Intent prevIntent = getIntent();

    String welcomeMessage = "Welcome " + prevIntent.getStringExtra("username") + "!";
    UUID = android.os.Build.SERIAL;
    userName = prevIntent.getStringExtra("username");
    txtUserMessage.setText(welcomeMessage);

    // Check for available NFC Adapter
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {

      txtNFC.setText("NFC is not available on this device.");
    }
    // Register callback to set NDEF message
    mNfcAdapter.setNdefPushMessageCallback(this, this);
    // Register callback to listen for message-sent success
    mNfcAdapter.setOnNdefPushCompleteCallback(this, this);

    pendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
      ndef.addDataType("*/*"); /* Handles all MIME based dispatches.
                                           You should specify only the ones that you need. */
    } catch (MalformedMimeTypeException e) {
      throw new RuntimeException("fail", e);
    }
    intentFiltersArray =
        new IntentFilter[] {
          ndef,
        };
    friendList = new ArrayList<String>();
    //     //brandon
    friendsListTask =
        new AsyncTask<Void, Void, Void>() {
          @Override
          protected Void doInBackground(Void... params) {
            Message msg = friendsListHandle.obtainMessage();
            String message = getFriends(getApplicationContext(), userName);
            // String message = logIn(getApplicationContext(), txtUsername.getText().toString(),
            // txtPassword.getText().toString());
            Log.e(TAG, message);
            msg.obj = message;
            friendsListHandle.sendMessage(msg);
            return null;
          }

          @Override
          protected void onPostExecute(Void result) {
            // brandon - Because AsyncTasks can only be used once
            friendsListTask = null;
          }
        };

    friendsListTask.execute(null, null, null);
  }
Beispiel #15
0
  @Override
  protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
    // TODO Auto-generated method stub

    final Dialog pDialog = dialog;
    switch (id) {
      case DIALOG_CAPTURE:
        int position = args.getInt("selected");
        BitmapFactory.Options bfo = new BitmapFactory.Options();
        bfo.inSampleSize = 1;

        String arrImage[] = mImageAdapter.getImagePath(position).split("/");
        String imageName = "";
        if (arrImage.length == 6) {
          imageName = arrImage[5];
        }
        TextView textView = (TextView) dialog.findViewById(R.id.textView1);
        textView.setText(imageName);

        Bitmap bm = BitmapFactory.decodeFile(mImageAdapter.getImagePath(position), bfo);
        Bitmap resized = Bitmap.createScaledBitmap(bm, imgWidth, imgHeight, true);
        ImageView imageView = (ImageView) dialog.findViewById(R.id.imageView2);
        imageView.setImageBitmap(resized);
        imageView.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                pDialog.dismiss();
              }
            });
        break;
      case DIALOG_PASSWORD:
        dialog.setOnDismissListener(
            new OnDismissListener() {

              @Override
              public void onDismiss(DialogInterface dialog) {
                // TODO Auto-generated method stub
                // Send Unlock Message
                if (mPassword.getTmpPassword().equals("")) {
                  String PASSWORD = mPassword.getPassword();
                  if (tButton3.isChecked()) {
                    dataID = String.valueOf(Constants.MSG_NFC);
                    data = PASSWORD;
                    dataLen = mSocket.makeDataLenToByte(data.length());
                    mSocket.sendMessage(dataID.getBytes(), dataLen, data.getBytes());
                  } else {
                    dataID = String.valueOf(Constants.MSG_UNLOCK);
                    data = PASSWORD + "," + mUser.getName() + "," + String.valueOf(mUser.getIcon());
                    dataLen = mSocket.makeDataLenToByte(data.length());
                    mSocket.sendMessage(dataID.getBytes(), dataLen, data.getBytes());
                  }
                } else {
                  mPassword.setTmpPassword();
                }
              }
            });
        break;
      case DIALOG_SELECTICON:
        // mListener.setDialog(dialog);
        // mListener.setView();
        break;

      case DIALOG_NFC:
        mNfcAdapter.setNdefPushMessageCallback(this, this);
        mNfcAdapter.setOnNdefPushCompleteCallback(this, this);

      case DIALOG_SENSOR:
        dialog.setCanceledOnTouchOutside(true);
    }
  }
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setResult(RESULT_USER_CANCELED);

    // getResourseIdByName(getPackageName(), "layout", "activity_invoice")

    System.out.println("Starting init...");

    setContentView(R.layout.activity_invoice);

    System.out.println("Layout set...");

    status = (TextView) findViewById(R.id.status);
    price = (TextView) findViewById(R.id.price);
    refund = (Button) findViewById(R.id.refund);

    launchWallet = (Button) findViewById(R.id.launchWallet);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    loadingQr = (ProgressBar) findViewById(R.id.loadingQr);
    qrView = (ImageView) findViewById(R.id.qr);

    showQR = (TextView) findViewById(R.id.showQr);
    address = (TextView) findViewById(R.id.address);
    timeRemaining = (TextView) findViewById(R.id.timeRemaining);
    conversion = (TextView) findViewById(R.id.conversion);

    Thread t =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                if (savedInstanceState != null) {
                  InvoiceActivity.this.mInvoice = savedInstanceState.getParcelable(INVOICE);
                  InvoiceActivity.this.client = savedInstanceState.getParcelable(CLIENT);
                  InvoiceActivity.this.triggeredWallet =
                      savedInstanceState.getBoolean(TRIGGERED_WALLET);
                } else {
                  InvoiceActivity.this.mInvoice = getIntent().getParcelableExtra(INVOICE);
                  InvoiceActivity.this.client = getIntent().getParcelableExtra(CLIENT);
                  InvoiceActivity.this.triggeredWallet =
                      getIntent().getBooleanExtra(TRIGGERED_WALLET, false);
                }
              }
            });

    t.start();
    while (mInvoice == null) {
      try {
        t.join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    progressBar.setRotation(180);
    price.setText(mInvoice.getBtcPrice() + " BTC");
    timeRemaining.setText(getRemainingTimeAsString());
    conversion.setText(
        mInvoice.getBtcPrice() + " BTC = " + mInvoice.getPrice() + mInvoice.getCurrency());
    address.setText(getAddress());
    address.setPaintFlags(address.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    address.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            ClipboardManager ClipMan =
                (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipMan.setPrimaryClip(
                ClipData.newPlainText("label", mInvoice.getPaymentUrls().getBIP73()));
            Toast toast =
                Toast.makeText(
                    getApplicationContext(),
                    "Copied payment address to clipboard",
                    Toast.LENGTH_LONG);
            toast.show();
          }
        });
    showQR.setPaintFlags(showQR.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    showQR.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            triggerQrLoad();
          }
        });
    launchWallet.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent bitcoinIntent = new Intent(Intent.ACTION_VIEW);
            bitcoinIntent.setData(Uri.parse(mInvoice.getBIP21due()));
            startActivity(bitcoinIntent);
          }
        });

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter != null) {
      // Register callback to set NDEF message
      mNfcAdapter.setNdefPushMessageCallback(this, this);

      // Register callback to listen for message-sent success
      mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
    } else {
      Log.i("InvoiceActivity", "NFC is not available on this device");
    }
    if (!triggeredWallet) {
      if (BitPayAndroid.isWalletAvailable(this)) {
        Intent bitcoinIntent = new Intent(Intent.ACTION_VIEW);
        bitcoinIntent.setData(Uri.parse(mInvoice.getBIP21due()));
        triggeredWallet = true;
        startActivity(bitcoinIntent);
      } else {
        Toast.makeText(
                getApplicationContext(),
                "You don't have any bitcoin wallets installed.",
                Toast.LENGTH_LONG)
            .show();
        triggerQrLoad();
      }
    } else {
      triggerStatusCheck();
    }
  }
 void enablePush() {
   adapter.setNdefPushMessageCallback(this, this);
 }