package com.mobil.time;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import android.R.color;
import android.R.string;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
public class CambiarNIP extends Activity {
EditText getInput, getInput2, getInput3;
TextView haduken, haduken2;
ProgressThread progThread;
ProgressDialog progDialog;
int typeBar;
int delay = 40;
int maxBarValue =0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cambiar_nip);
getInput = (EditText) findViewById(R.id.txtNiPactual);
getInput2 = (EditText) findViewById(R.id.txtNIPnuevo);
getInput3 = (EditText) findViewById(R.id.txtNIPconfirmar);
Button boton = (Button) findViewById(R.id.BcambioNIP);
haduken = (TextView) findViewById(R.id.txttodo);
haduken2 = (TextView) findViewById(R.id.txtconexion);
boton.setOnClickListener(new View.OnClickListener() {
String a, b, c;
@Override
public void onClick(View v) {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imei = telephonyManager.getDeviceId();
String d = imei;
String a = getInput.getText().toString();
String b = getInput2.getText().toString();
String c = getInput3.getText().toString();
if (a.length()<=4 || b.length()<=4 || c.length()<=4) {
haduken.setText("Campos Incompletos o Vacios");
} else {
if (b.equals(c)) {
typeBar = 1;
showDialog(typeBar);
Socket socket = null;
DataOutputStream dataOutputStream = null;
DataInputStream dataInputStream = null;
try {
socket = new Socket("10.0.2.2", 4445);
haduken.setText("30\n" + a + "\n" + b + "\n" + c
+ "\n" + d);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
haduken.setText("El NIP no coincide");
}
}
}
});
} @Override
protected Dialog onCreateDialog(int id) {
switch(id) {
case 1:
progDialog = new ProgressDialog(this);
progDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progDialog.setMax(maxBarValue);
progDialog.setMessage("Enviando datos porfavor ESPERE !!!:");
progThread = new ProgressThread(handler);
progThread.start();
return progDialog;
default:
return null;
}
}
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
int total = msg.getData().getInt("total");
progDialog.setProgress(total);
if (total >= 100){
dismissDialog(typeBar);
progThread.setState(ProgressThread.DONE);
}
}
};
private class ProgressThread extends Thread {
final static int DONE = 0;
final static int RUNNING = 1;
Handler mHandler;
int mState;
int total;
ProgressThread(Handler h) {
mHandler = h;
}
@Override
public void run() {
mState = RUNNING;
total = maxBarValue;
while (mState == RUNNING) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
Log.e("ERROR", "El proceso fue interrumpido");
}
Message msg = mHandler.obtainMessage();
Bundle b = new Bundle();
b.putInt("total", total);
msg.setData(b);
mHandler.sendMessage(msg);
total++;
}
}
public void setState(int state) {
mState = state;
}
}
}