package com.example.martin.projetv5; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.Collections; /** * Created by martin on 12/04/2017. */ public class ModifMedocActivity extends AppCompatActivity implements PriseAdapterMedoc.PriseAdapterListener { ArrayList listPrises = new ArrayList<>(); PriseAdapterMedoc adapter = null; ListView list = null; StringBDD eventBDD = null; Medicament medicament = null; void supElementList(Prise2 p, ArrayList listP){ listP.remove(p); adapter.notifyDataSetChanged(); } void supList(ArrayList listP){ listP.clear(); adapter.notifyDataSetChanged(); } void addElementList(Prise2 p, ArrayList listP){ listP.add(p); } public void onClickDelete(final Prise2 item, int position){ AlertDialog.Builder builder = new AlertDialog.Builder(this); DialogInterface.OnClickListener onClickYes = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { supElementList(item, listPrises); eventBDD.removePriseWithID(item.getId()); } }; builder.setMessage(R.string.modif8); builder.setPositiveButton(R.string.oui,onClickYes); builder.setNegativeButton(R.string.non,null); builder.show(); } void gestionPrises(){ for(int w=0; w 2 || decoupe[0].equals("")) Toast.makeText(view.getContext(), R.string.modif9, Toast.LENGTH_SHORT).show(); else { h = Integer.parseInt(decoupe[0]); if (size == 1) m = 0; else m = Integer.parseInt(decoupe[1]); String s; if (h >= 24 || h < 0) Toast.makeText(view.getContext(), R.string.modif9, Toast.LENGTH_SHORT).show(); else { if (m >= 60 || m < 0) Toast.makeText(view.getContext(), R.string.modif9, Toast.LENGTH_SHORT).show(); else { if (m == 0) s = h.toString() + "h" + "0" + m.toString(); else s = h.toString() + "h" + m.toString(); int w=1; boolean out = false; while(w <= eventBDD.getIndiceMaxPrise() && !out){ Prise2 p = eventBDD.getPriseWithId(w); if(p == null) out = true; else w++; } Prise2 p = new Prise2(w, medicament.getIdM(), "false", s); eventBDD.insertPrise(p); Intent i = new Intent(ModifMedocActivity.this, ServiceInitAlarme.class); i.putExtra("heure", p.getHeure()); startService(i); supList(listPrises); gestionPrises(); } } } }catch (Exception e){ Toast.makeText(ModifMedocActivity.this,R.string.modif9,Toast.LENGTH_SHORT).show(); } } }; builder.setPositiveButton(R.string.enregistrer,onClickYes); builder.setNegativeButton(R.string.annuler,null); builder.show(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.modif_layout); eventBDD = new StringBDD(this); eventBDD.open(); Intent intent = getIntent(); Integer idMedoc = intent.getIntExtra("id",0); medicament = eventBDD.getMedocWithId(idMedoc); ImageView logo = (ImageView) findViewById(R.id.logo); Bitmap bitmap = BitmapFactory.decodeFile(medicament.getLogo()); logo.setImageBitmap(bitmap); TextView nom1 = (TextView) findViewById(R.id.nom1); nom1.setText(medicament.getNom1()); TextView nom2 = (TextView) findViewById(R.id.nom2); nom2.setText(medicament.getNom2()); } @Override protected void onResume() { eventBDD.open(); super.onResume(); adapter = new PriseAdapterMedoc(this,listPrises); adapter.addListener(this); list = (ListView)findViewById(R.id.listePrises); list.setAdapter(adapter); gestionPrises(); } @Override protected void onPause() { super.onPause(); adapter = new PriseAdapterMedoc(this,listPrises); adapter.addListener(this); list = (ListView)findViewById(R.id.listePrises); list.setAdapter(adapter); eventBDD.close(); supList(listPrises); } }