@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());
    }
  }
Exemple #2
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();
                      }
                    }
                  });
            }
          }
        });
  }
  @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;
  }
Exemple #4
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();
  }
  @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();
    }
  }
Exemple #6
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");

  }
Exemple #7
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(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);
  }