Go to the documentation of this file.00001 package com.rocon.nfc;
00002
00003 import android.os.Bundle;
00004 import android.app.Activity;
00005 import android.content.Intent;
00006 import android.content.SharedPreferences;
00007 import android.view.Menu;
00008 import android.view.View;
00009 import android.widget.Button;
00010 import android.widget.EditText;
00011 import android.widget.TextView;
00012
00013 public class MainActivity extends Activity {
00014
00015 private static final String PREFS_KEY_TABLE = "TABLE_KEY";
00016 private static final String PREFS_KEY_SSID = "SSID_KEY";
00017 private static final String PREFS_KEY_PW = "PW_KEY";
00018 private static final String PREFS_KEY_URI = "URI_KEY";
00019 private static final String PREFS_KEY_WEB = "WEB_KEY";
00020
00021 String table = "";
00022 String ssid = "";
00023 String password = "";
00024 String masteruri = "";
00025 String weblink = "";
00026
00027 EditText editTable = null ;
00028 EditText editSsid = null ;
00029 EditText editPassword = null ;
00030 EditText editMasterUri = null ;
00031 EditText editWebLink = null ;
00032 Button btnWrite = null ;
00033 TextView txtText = null ;
00034
00035 RoconNfcManager mNfcManager = null ;
00036
00037 @Override
00038 protected void onCreate(Bundle savedInstanceState) {
00039 super.onCreate(savedInstanceState);
00040 setContentView(R.layout.activity_main);
00041
00042 editTable = (EditText) findViewById(R.id.table);
00043 editSsid = (EditText) findViewById(R.id.ssid);
00044 editPassword = (EditText) findViewById(R.id.pasword);
00045 editMasterUri = (EditText) findViewById(R.id.master_uri);
00046 editWebLink = (EditText) findViewById(R.id.web_link);
00047 btnWrite = (Button) findViewById(R.id.nfc_write);
00048 txtText = (TextView) findViewById(R.id.text);
00049
00050 table = getPreferences(MODE_PRIVATE).getString(PREFS_KEY_TABLE, editTable.getText().toString());
00051 ssid = getPreferences(MODE_PRIVATE).getString(PREFS_KEY_SSID, editSsid.getText().toString());
00052 password = getPreferences(MODE_PRIVATE).getString(PREFS_KEY_PW, editPassword.getText().toString());
00053 masteruri = getPreferences(MODE_PRIVATE).getString(PREFS_KEY_URI, editMasterUri.getText().toString());
00054 weblink = getPreferences(MODE_PRIVATE).getString(PREFS_KEY_WEB, editWebLink.getText().toString());
00055
00056 editTable.setText(table);
00057 editSsid.setText(ssid);
00058 editPassword.setText(password);
00059 editMasterUri.setText(masteruri);
00060 editWebLink.setText(weblink);
00061
00062 mNfcManager = new RoconNfcManager(this);
00063 }
00064
00065 @Override
00066 public boolean onCreateOptionsMenu(Menu menu) {
00067
00068 getMenuInflater().inflate(R.menu.main, menu);
00069 return true;
00070 }
00071
00072 @Override
00073 protected void onPause() {
00074
00075 super.onPause();
00076
00077 if(mNfcManager != null)
00078 mNfcManager.disableForegroundDispatch() ;
00079 }
00080
00081 @Override
00082 protected void onResume() {
00083
00084 super.onResume();
00085
00086 if(mNfcManager != null)
00087 mNfcManager.enableForegroundDispatch() ;
00088 }
00089
00090 @Override
00091 protected void onNewIntent(Intent intent) {
00092
00093 super.onNewIntent(intent);
00094
00095 if(mNfcManager != null) {
00096 if(mNfcManager.onNewIntent(intent)) {
00097 txtText.setText("You can write Nfc tag");
00098 btnWrite.setEnabled(true);
00099 }
00100 }
00101 }
00102
00103 public void onClick(View v) {
00104
00105 switch(v.getId()){
00106 case R.id.nfc_write :
00107 table = editTable.getText().toString();
00108 ssid = editSsid.getText().toString();
00109 password = editPassword.getText().toString();
00110 masteruri = editMasterUri.getText().toString();
00111 weblink = editWebLink.getText().toString();
00112
00113 String payload = "ta:" + table + ";;" + "ss:" + ssid + ";;" + "pw:" + password + ";;" + "mu:" + masteruri + ";;" + "wl:" + weblink ;
00114
00115 boolean success = mNfcManager.writeMimeNdefMessage(payload, true);
00116
00117 if(success)
00118 txtText.setText("Success to write NFC Tag!");
00119 else
00120 txtText.setText("Fail to write NFC Tag!");
00121
00122 SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
00123 editor.putString(PREFS_KEY_TABLE, table);
00124 editor.putString(PREFS_KEY_SSID, ssid);
00125 editor.putString(PREFS_KEY_PW, password);
00126 editor.putString(PREFS_KEY_URI, masteruri);
00127 editor.putString(PREFS_KEY_WEB, weblink);
00128 editor.commit();
00129 }
00130 }
00131
00132 }