-1
Good afternoon! I’m having a doubt on android where I’m creating an app to evaluate the user’s mood .
I create the code in such a way that I accept only one option per day Only now I need to include a window informing that he has already performed the test if he has already done and I need that after he has answered open a dialog box to include personal information like phone name etc.. Below is the code made until the moment:
public class ActPrincipal extends Activity {
private ImageButton ibMuitoSatisfeito, ibSatisfeito, ibNeutro, ibInsatisfeito, ibMuitoInsatisfeito;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_principal);
ibMuitoSatisfeito = (ImageButton) findViewById(R.id.ibMuitoInsatisfeito);
ibSatisfeito = (ImageButton) findViewById(R.id.ibSatisfeito);
ibNeutro = (ImageButton) findViewById(R.id.ibNeutro);
ibInsatisfeito = (ImageButton) findViewById(R.id.ibInsatisfeito);
ibMuitoInsatisfeito = (ImageButton) findViewById(R.id.ibMuitoInsatisfeito);
ibMuitoSatisfeito.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
salvarAvaliacao(1);
return true;
}
}
);
ibSatisfeito.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
salvarAvaliacao(2);
return true;
}
}
); ibNeutro.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
salvarAvaliacao(3);
return true;
}
}
);
ibMuitoInsatisfeito.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
salvarAvaliacao(5);
return true;
}
}
);
}
public void salvarAvaliacao(int nro) {
Controlador controlador = new Controlador(getBaseContext());
Avaliacao avaliacao = new Avaliacao();
avaliacao.setDataAvaliacao(new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
avaliacao.setHorario(new SimpleDateFormat("HH:mm:ss").format(new Date()));
avaliacao.setAvaliacao(nro);
avaliacao.setEnviado(0);
if (android.os.Build.VERSION.SDK_INT > 22) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 12);
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Location localizacao = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
if (localizacao != null && ((new Date()).getTime() - localizacao.getTime()) / 1000 < 3600) {
avaliacao.setLatitude(localizacao.getLatitude());
avaliacao.setLongitude(localizacao.getLongitude());
}
}
controlador.inserir(avaliacao);
Toast.makeText(this, getString(R.string.msg_agradecimento), Toast.LENGTH_SHORT).show();
}
public void btAbrirActAvaliacao(View v) {
startActivity(new Intent(this, ActAvaliacao.class));
}
}