package
com.study.account;
import
java.io.InputStream;
import
java.net.URL;
import
java.net.URLEncoder;
import
org.xmlpull.v1.XmlPullParser;
import
org.xmlpull.v1.XmlPullParserFactory;
import
android.app.Activity;
import
android.os.Bundle;
import
android.util.Log;
import
android.view.View;
import
android.view.Window;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.EditText;
import
android.widget.Toast;
import
android.app.AlertDialog;
import
android.content.DialogInterface;
public
class
JoinActivity
extends
Activity {
EditText Email;
EditText Password;
EditText Passwordcheck;
EditText Name;
Button Join;
Button Cancel;
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Email = (EditText)findViewById(R.id.editText1);
Password = (EditText )findViewById(R.id.editText2);
Passwordcheck = (EditText )findViewById(R.id.EditText01);
Name = (EditText)findViewById(R.id.editText3);
Join = (Button)findViewById(R.id.joinOkay);
Cancel = (Button)findViewById(R.id.Cancel);
Cancel.setOnClickListener(
new
OnClickListener() {
public
void
onClick(View v) {
AlertDialog dialog = createDialogBox();
dialog.show();
}
});
Join.setOnClickListener(
new
OnClickListener() {
public
void
onClick(View v) {
if
( Email.getText().toString().equals(
""
) ||
Password.getText().toString().equals(
""
)||
Passwordcheck.getText().toString().equals(
""
)||
Name.getText().toString().equals(
""
) ) {
Toast.makeText(JoinActivity.
this
,
"이름이나 가격을 입력하세요"
, Toast.LENGTH_SHORT).show();
return
;
}
runOnUiThread(
new
Runnable() {
public
void
run() {
String email = Email.getText().toString();
String pwd= Password.getText().toString();
String pwdcheck = Passwordcheck.getText().toString();
String name = Name.getText().toString();
try
{
URL url =
new
URL(SERVER_ADDRESS +
"/insert.php?"
+
"userid="
+ URLEncoder.encode(email,
"UTF-8"
)
+
"&userpassword="
+ URLEncoder.encode(pwd,
"UTF-8"
)
+
"&username="
+ URLEncoder.encode(name,
"UTF-8"
));
url.openStream();
String result = getXmlData(
"insertresult.xml"
,
"result"
);
if
(result.equals(
"1"
)) {
Toast.makeText(JoinActivity.
this
,
"DB insert 성공"
, Toast.LENGTH_SHORT).show();
Email.setText(
""
);
Password.setText(
""
);Name.setText(
""
);
}
else
Toast.makeText(JoinActivity.
this
,
"DB insert 실패"
, Toast.LENGTH_SHORT).show();
}
catch
(Exception e) {
Log.e(
"Error"
, e.getMessage());
}
}
});
}
});
setContentView(R.layout.activity_join);
}
private
String getXmlData(String filename, String str) {
String rss = SERVER_ADDRESS +
"/"
;
String ret =
""
;
try
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(
true
);
XmlPullParser xpp = factory.newPullParser();
URL server =
new
URL(rss + filename);
InputStream is = server.openStream();
xpp.setInput(is,
"UTF-8"
);
int
eventType = xpp.getEventType();
while
(eventType != XmlPullParser.END_DOCUMENT) {
if
(eventType == XmlPullParser.START_TAG) {
if
(xpp.getName().equals(str)) {
ret = xpp.nextText();
}
}
eventType = xpp.next();
}
}
catch
(Exception e) {
Log.e(
"Error"
, e.getMessage());
}
return
ret;
}
private
AlertDialog createDialogBox(){
AlertDialog.Builder builder =
new
AlertDialog.Builder(
this
);
builder.setTitle(
"안내"
);
builder.setMessage(
"취소하시겠습니까?"
);
builder.setIcon(R.drawable.alert_dialog_icon);
builder.setPositiveButton(
"아니오"
,
new
DialogInterface.OnClickListener() {
public
void
onClick(DialogInterface dialog,
int
whichButton) {
}
});
builder.setNeutralButton(
"예"
,
new
DialogInterface.OnClickListener() {
public
void
onClick(DialogInterface dialog,
int
whichButton) {
finish();
}
});
AlertDialog dialog = builder.create();
return
dialog;
}
}