Android Open Source - Android-NFC-WiFi-Controller Main Activity






From Project

Back to project page Android-NFC-WiFi-Controller.

License

The source code is released under:

MIT License

If you think the Android project Android-NFC-WiFi-Controller listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package sanchezsobrino.multimedia.anwc;
/*  www  .  j ava  2 s  .  c o  m*/
import net.sourceforge.zbar.Symbol;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.dm.zbar.android.scanner.ZBarConstants;
import com.dm.zbar.android.scanner.ZBarScannerActivity;

public class MainActivity extends Activity {
  private static final int ZBAR_SCANNER_REQUEST = 0;

  private Button connectButton;
  private Button addButton;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    connectButton = (Button) findViewById(R.id.connectButton);
    addButton = (Button) findViewById(R.id.addButton);

    connectButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        launchQRScanner();
      }
    });

    addButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        startActivity(new Intent(getApplicationContext(), ControlActivity.class));
      }
    });

  }

  public void launchQRScanner() {
    if (isCameraAvailable()) {
      Intent intent = new Intent(this, ZBarScannerActivity.class);
      intent.putExtra(ZBarConstants.SCAN_MODES, new int[] { Symbol.QRCODE });
      startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
    } else {
      Toast.makeText(this, "Cmara no disponible", Toast.LENGTH_SHORT).show();
    }
  }

  public boolean isCameraAvailable() {
    PackageManager pm = getPackageManager();

    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
      return true;
    }

    return false;
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
      Intent i = new Intent(getApplicationContext(), ConnectedActivity.class);
      i.putExtra("socket", data.getStringExtra(ZBarConstants.SCAN_RESULT));
      startActivity(i);
    } else if (resultCode == RESULT_CANCELED) {
      Toast.makeText(this, "Camera unavailable", Toast.LENGTH_SHORT).show();
    }
  }

  @Override
  public void onBackPressed() {
    super.onBackPressed();
    finish();
  }
}




Java Source Code List

com.dm.zbar.android.scanner.CameraPreview.java
com.dm.zbar.android.scanner.ZBarConstants.java
com.dm.zbar.android.scanner.ZBarScannerActivity.java
sanchezsobrino.multimedia.anwc.CodeEvent.java
sanchezsobrino.multimedia.anwc.ConnectedActivity.java
sanchezsobrino.multimedia.anwc.ControlActivity.java
sanchezsobrino.multimedia.anwc.MainActivity.java
sanchezsobrino.multimedia.anwc.NfcUtils.java
sanchezsobrino.multimedia.anwc.business.AboutMenuItemListener.java
sanchezsobrino.multimedia.anwc.business.ChoosePortDialogListener.java
sanchezsobrino.multimedia.anwc.business.CodeEvent.java
sanchezsobrino.multimedia.anwc.business.CustomQRCode.java
sanchezsobrino.multimedia.anwc.business.ExitMenuItemListener.java
sanchezsobrino.multimedia.anwc.business.InstructionsMenuItemListener.java
sanchezsobrino.multimedia.anwc.business.KeySimulator.java
sanchezsobrino.multimedia.anwc.business.LocalizedString.java
sanchezsobrino.multimedia.anwc.business.TCPServer.java
sanchezsobrino.multimedia.anwc.persistence.LocalizedStringManager.java
sanchezsobrino.multimedia.anwc.presentation.ChoosePortDialog.java
sanchezsobrino.multimedia.anwc.presentation.LogPane.java
sanchezsobrino.multimedia.anwc.presentation.MainWindow.java