how are they? I have the following problem and I inherited an app a while ago (without knowing how to program in android) and they asked me now that they want to change the design of it.
To something similar to this, where the orange part would go the logo and in the items the part of NFC, DNI, yaviene, contact and help:
I really tried looking for tutorial videos but they all start from scratch and I do not really adapt it to the current code, both java and xml.
I leave the MainActivity code to see if you can help me.
public class MainActivity extends AppCompatActivity {
//TextView label;
IntentFilter[] filters;
String[][] techs;
PendingIntent pendingIntent;
NfcAdapter adapter;
long numero;
//private Button boton;
private boolean nfcFalse= false;
String date = (DateFormat.format("ddMMyyyy", new java.util.Date()).toString());
int fecha=Integer.parseInt(date);
int c=98;
int valor=((c*5)+(BuildConfig. VERSION_CODE)+(fecha*2));
String hexvalor=Integer.toHexString(valor);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter = NfcAdapter.getDefaultAdapter(this);
if (adapter != null) {
//label = (TextView) findViewById(R.id.label);
pendingIntent = PendingIntent.getActivity(
this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter mifare = new IntentFilter((NfcAdapter.ACTION_TECH_DISCOVERED));
filters = new IntentFilter[]{mifare};
techs = new String[][]{new String[]{NfcA.class.getName()}};
}else {
Toast toast = Toast.makeText(getApplicationContext(),
"SU EQUIPO NO POSEE NFC!", Toast.LENGTH_LONG);
toast.show();
nfcFalse=true;
}
}
public void onPause() {
super.onPause();
if (nfcFalse != true) {
adapter.disableForegroundDispatch(this);
}
}
public void onResume() {
super.onResume();
if (nfcFalse != true) {
adapter.enableForegroundDispatch(this, pendingIntent, filters, techs);
}
}
public void onNewIntent(Intent intent) {
if (nfcFalse != true) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] id = tag.getId();
ByteBuffer wrapped = ByteBuffer.wrap(id);
wrapped.order(ByteOrder.BIG_ENDIAN);
int signedInt = wrapped.getInt();
numero = signedInt & 0xffffffffl;
if (numero > 0) {
Toast toast = Toast.makeText(getApplicationContext(),
"Tarjeta Leida Correctamente, RETIRE LA TARJETA Y PULSE CONSULTAR!", Toast.LENGTH_LONG);
toast.show();
//final Button boton = (Button) findViewById(R.id.boton);
//boton.setText("presione para consultar");
} else {
Toast toast = Toast.makeText(getApplicationContext(),
"Tarjeta no Detectada, Verifique que el NFC este Activado!", Toast.LENGTH_LONG);
toast.show();
}
}
}
public final static String EXTRA = "com.example.nfctest.app.consultar";
public void lanzarConsultar(View view) {
if (numero > 0) {
Intent i = new Intent(this, consultar.class);
String serie = Long.toString(numero);
String key=(hexvalor);
String keytarres=(serie+"&k="+key);
i.putExtra(EXTRA, keytarres);
startActivity(i);
} else {
if (nfcFalse!=true) {
Toast toast = Toast.makeText(getApplicationContext(),
"Tarjeta no Detectada, Verifique que el NFC este Activado!", Toast.LENGTH_LONG);
toast.show();
finishActivity(0);
}else{
Toast toast = Toast.makeText(getApplicationContext(),
"SU EQUIPO NO POSEE NFC, CONSULTE POR DNI", Toast.LENGTH_LONG);
toast.show();
finishActivity(0);
}
}
}
public final static String EXTRAKEY = "com.example.nfctest.app.consultardni";
public void lanzarConsultarDni(View view) {
Intent i = new Intent(this, consultardni.class);
String key = (hexvalor);
i.putExtra(EXTRAKEY,key);
startActivity(i);
}
//public final static String YAVIENE = "com.example.nfctest.app.consultar";
//LLAMA A LA CLASE YA VIENE
public void lanzarYaViene(View view) {
Intent i = new Intent(this, yaviene.class);
//String serie = Long.toString(numero);
// i.putExtra(<YAVIENE, serie);
startActivity(i);
}
public void lanzaromniplay(View view) throws InterruptedException {
WifiManager myWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if(myWifiManager.isWifiEnabled()==false){
Toast toast = Toast.makeText(getApplicationContext(),
"Habilitando WIFI!", Toast.LENGTH_LONG);
toast.show();
Log.e("scan", "conect wifi");
myWifiManager.setWifiEnabled(true);
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
}
}
String networkSSID = "omniplay";
String networkPass = "omniplay";
boolean encontrada=false;
boolean borrada=false;
for(WifiConfiguration configG : myWifiManager.getConfiguredNetworks()){
Log.e("scan", "G: "+configG.SSID+" "+"\""+"omniplay"+"\"");
if(configG.SSID.equals("\""+"omniplay"+"\"")){
myWifiManager.removeNetwork(configG.networkId);
borrada=true;
encontrada=true;
Log.e("scan", "borrada " + configG.SSID);
break;
}
}
if ((myWifiManager.isWifiEnabled() && borrada) || (myWifiManager.isWifiEnabled() && !encontrada)) {
WifiConfiguration config = new WifiConfiguration();
config.SSID = "\"" + networkSSID + "\"";
config.preSharedKey = "\"" + networkPass + "\"";
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
int id = wifiManager.addNetwork(config);
myWifiManager.disconnect();
myWifiManager.enableNetwork(id, true);
myWifiManager.reconnect();
//myWifiManager.saveConfiguration();
try {
Thread.sleep(10000);
Log.e("scan", "conect");
Intent i = new Intent(this, omniplay.class);
startActivity(i);
} catch (InterruptedException ex) {
Toast toast = Toast.makeText(getApplicationContext(),
"No Conectado!", Toast.LENGTH_LONG);
toast.show();
}
}else {
Toast toast = Toast.makeText(getApplicationContext(),
"Algo ocurrio!", Toast.LENGTH_LONG);
toast.show();
}
}
public void PopUp (View v){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("La lectura de su tarjeta de viaje mediante el teléfono celular podrá hacerse sólo cuando el dispositivo cuente con tecnología NFC, y el sensor se encuentre activado.\n" +
"Consulte el manual de usuario de su teléfono para verificar si cuenta con esta característica.\n" +
"Esta aplicacíon utiliza la conexión a internet disponible en su teléfono celular.\n"+
"©2015. Global Visum S.A. / Siscadat S.A. \n")
.setTitle("Acerca De")
.setCancelable(false)
.setNeutralButton("Ok!",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
public void onClickContacto(View v) {
LayoutInflater inflater = getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.contacto, null);
final EditText etAsunto = (EditText) dialoglayout.findViewById(R.id.et_EmailAsunto);
final EditText etMensaje = (EditText) dialoglayout.findViewById(R.id.et_EmailMensaje);
final EditText etDatos = (EditText) dialoglayout.findViewById(R.id.et_Datos);
final EditText etCel = (EditText) dialoglayout.findViewById(R.id.et_Cel);
Button btnEnviarMail = (Button) dialoglayout.findViewById(R.id.btnEnviarMail);
btnEnviarMail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String datos = etDatos.getText().toString();
String cel = etCel.getText().toString();
if (((datos == null) || (datos.equals("")))
|| ((cel == null) || (cel.equals("")))) {
Toast toast = Toast.makeText(getApplicationContext(),
"Por Favor Ingrese Datos Personales y N° de Celular", Toast.LENGTH_LONG);
toast.show();
} else {
String subject = etAsunto.getText().toString();
String message = etMensaje.getText().toString();
/* AccountManager am = AccountManager.get(MainActivity.this);
Account[] accounts = am.getAccounts();
String phoneNumber="0";
ArrayList googleAccounts = new ArrayList();
for (Account ac : accounts) {
String acname = ac.name;
String actype = ac.type;
System.out.println("Accounts : " + acname + ", " + actype);
if(actype.equals("com.whatsapp")){
phoneNumber = ac.name;
Log.d(phoneNumber,"cel");
}
}*/
// LLAMO A LA VARIABLE CORREO CREADO EN SRC/MAIN/RES"NOMBRE DE EMPRESA"/VALUES/STRING
Intent mail = new Intent(Intent.ACTION_SEND);
mail.putExtra(Intent.EXTRA_EMAIL, new String[]{getString(R.string.correo)});
mail.putExtra(Intent.EXTRA_SUBJECT, subject);
mail.putExtra(Intent.EXTRA_TEXT, " Contacto Pasajero " + datos + ", " + cel + ": " + message);
mail.setType("message/rfc822");
startActivity(Intent.createChooser(mail, "Seleciona un cliente de correo"));
etAsunto.setText("");
etMensaje.setText("");
etDatos.setText("");
etCel.setText("");
}
}
});
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialoglayout);
//builder.setTitle("Contacto");
builder.setCancelable(true);
builder.setPositiveButton("Listo!",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.show();
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@mipmap/fondo">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="90dp"
android:layout_marginBottom="260dp">
<Button
android:layout_width="160dp"
android:layout_height="140dp"
android:id="@+id/boton"
android:background="@drawable/botonleer"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="lanzarConsultar"
android:layout_gravity="center"
android:layout_marginLeft="15dp" />
<Button
android:layout_width="160dp"
android:layout_height="140dp"
android:id="@+id/boton1"
android:background="@drawable/botondniaccion"
android:layout_alignBottom="@+id/boton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="lanzarConsultarDni"
android:layout_gravity="center"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="270dp"
android:layout_marginBottom="71dp">
<Button
android:layout_width="160dp"
android:layout_height="130dp"
android:id="@+id/boton2"
android:background="@drawable/yaniene"
android:onClick="lanzarYaViene"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="15dp" />
<Button
android:layout_width="160dp"
android:layout_height="130dp"
android:id="@+id/botonomni"
android:background="@drawable/omniplay"
android:onClick="lanzaromniplay"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="10dp" />
</LinearLayout>
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/boton3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/ayuda"
android:onClick="PopUp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/boton4"
android:onClick="onClickContacto"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="false"
android:background="@drawable/contacto"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp" />
</RelativeLayout>