Good afternoon! I have a question on the android where I am creating an app to evaluate the mood of the user.
IcreatethecodeinsuchawaythatonlyoneoptionperdayisacceptedSonowIneedtoincludeawindowstatingthathehasalreadyperformedthetestifhehasalreadydoneitandneedthatafterhehasansweredopenadialogboxtoincludepersonalinformationsuchasphonenameetc.Hereisthecodethathasbeendonesofar:
publicclassActPrincipalextendsActivity{privateImageButtonibMuitoSatisfeito,ibSatisfeito,ibNeutro,ibInsatisfeito,ibMuitoInsatisfeito;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){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(newView.OnLongClickListener(){@OverridepublicbooleanonLongClick(Viewv){salvarAvaliacao(1);returntrue;}});ibSatisfeito.setOnLongClickListener(newView.OnLongClickListener(){@OverridepublicbooleanonLongClick(Viewv){salvarAvaliacao(2);returntrue;}});ibNeutro.setOnLongClickListener(newView.OnLongClickListener(){@OverridepublicbooleanonLongClick(Viewv){salvarAvaliacao(3);returntrue;}});ibMuitoInsatisfeito.setOnLongClickListener(newView.OnLongClickListener(){@OverridepublicbooleanonLongClick(Viewv){salvarAvaliacao(5);returntrue;}});}publicvoidsalvarAvaliacao(intnro){Controladorcontrolador=newControlador(getBaseContext());Avaliacaoavaliacao=newAvaliacao();avaliacao.setDataAvaliacao(newSimpleDateFormat("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));
}
}