public void tampilkanNotifikasiPeringatan(Peringatan peringatan) { int icon = R.drawable.pelanggaran; CharSequence tickerText = ""; CharSequence contentTitle = ""; long when = System.currentTimeMillis(); DatabaseManagerOrtu databaseManager = new DatabaseManagerOrtu(context); DataMonitoring dataMonitoring = databaseManager.getDataMonitoringByIdMonitoring(peringatan.getIdMonitoring(), true, true); Anak anak = dataMonitoring.getAnak(); if (peringatan.getTipe() == TipePesanMonak.PERINGATAN_TERLARANG) { tickerText = anak.getNamaAnak() + " melakukan pelanggaran..." + "!!!PERINGATAN TERLARANG" + "!!!"; contentTitle = "PERINGATAN TERLARANG"; } else { tickerText = anak.getNamaAnak() + " melakukan pelanggaran..." + "!!!PERINGATAN SEHARUSNYA" + "!!!"; contentTitle = "PERINGATAN SEHARUSNYA"; } Notification notification = new Notification(icon, tickerText, when); CharSequence contentText = "anak : " + anak.getNamaAnak() + "\n" + "click disini untuk lihat lokasi"; Intent notificationIntent = new Intent(context, Peta.class); notificationIntent.putExtra(Peta.EXTRA_ACTION, Peta.EXTRA_PELANGGARAN); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); mNotificationManager.notify(PELANGGARAN_NOTIFIKASI, notification); }
@Override public void handleMessage(Message msg) { if (msg.what == Status.SUCCESS) { Bundle data = msg.getData(); // cek apakah anak ini yang mau di update datanya... String idMonitoring = data.getString("idMonitoring"); // ................................................. LogMonakFileManager.debug("handler di invoke"); if (daftarMonitoring.dataMonitorings != null && daftarMonitoring.dataMonitorings.size() > 0) { boolean all = false; if (idMonitoring.equals(daftarMonitoring.anak.getIdAnak())) { all = true; } LogMonakFileManager.debug("dapat dataMonitoring dengan idMonitoring : " + idMonitoring); for (DataMonitoring dataMonitoring : daftarMonitoring.dataMonitorings) { LogMonakFileManager.debug( "dapat for dengan id datamonitoring for : " + dataMonitoring.getIdMonitoring()); if (all) { dataMonitoring.setAktif(data.getBoolean("aktif")); continue; } if (dataMonitoring.getIdMonitoring().equals(idMonitoring)) { dataMonitoring.setAktif(data.getBoolean("aktif")); } } daftarMonitoring.daftarMonitoringAdapter.notifyDataSetChanged(); } } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { DataMonitoring dataMonitoring = null; if (resultCode == RESULT_OK) { Bundle bundle = data.getExtras(); dataMonitoring = EntityBundleMaker.getDataMonitoringFromBundle(bundle); dataMonitoring = databaseManager.getDataMonitoringByIdMonitoring( dataMonitoring.getIdMonitoring(), false, false); switch (requestCode) { case Operation.ADD: { break; } case Operation.EDIT: { for (DataMonitoring forDataMonitoring : dataMonitorings) { if (forDataMonitoring.getIdMonitoring().equals(dataMonitoring.getIdMonitoring())) { dataMonitorings.remove(forDataMonitoring); break; } } break; } } dataMonitorings.add(dataMonitoring); daftarMonitoringAdapter.notifyDataSetChanged(); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (dataMonitorings != null && dataMonitorings.size() > 0) { DataMonitoring dataMonitoring = dataMonitorings.get(position); if (dataMonitoring == null) return null; LayoutInflater inflater = (LayoutInflater) daftarMonitoring.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(resource, parent, false); TextView keterangan = (TextView) rowView.findViewById(R.id.daftarMonitoringText); keterangan.setText(dataMonitoring.getKeterangan()); rowView.setOnClickListener(new DaftarMonitoringClick(daftarMonitoring, dataMonitoring)); if (!daftarMonitoring.justView) { rowView.setOnLongClickListener( new DaftarMonitoringLongClick(daftarMonitoring, dataMonitoring)); } LinearLayout llBackground = (LinearLayout) rowView.findViewById(R.id.background); Button btnAktifMonitoring = (Button) rowView.findViewById(R.id.daftarMonitoringButtonStart); btnAktifMonitoring.setOnClickListener( new BtnStartOnClick(daftarMonitoring, dataMonitoring)); Button btnDeAktifMonitoring = (Button) rowView.findViewById(R.id.daftarMonitoringButtonStop); btnDeAktifMonitoring.setOnClickListener( new BtnStopOnClick(daftarMonitoring, dataMonitoring)); LinearLayout llAktifMonitoring = (LinearLayout) rowView.findViewById(R.id.daftarMonitoringStatusAktif); LinearLayout llDeAktifMonitoring = (LinearLayout) rowView.findViewById(R.id.daftarMonitoringStatusDeaktif); if (dataMonitoring.isAktif()) { llBackground.setBackgroundResource(R.drawable.back_menu_green); llDeAktifMonitoring.setVisibility(View.GONE); llAktifMonitoring.setVisibility(View.VISIBLE); } else { llBackground.setBackgroundResource(R.drawable.back_menu); llAktifMonitoring.setVisibility(View.GONE); llDeAktifMonitoring.setVisibility(View.VISIBLE); } return rowView; } else { return null; } }
private void stopMonitoring(DataMonitoring dataMonitoring) { SenderStopMonitoring sender = new SenderStopMonitoring(this); dataMonitoring = databaseManager.getDataMonitoringByIdMonitoring( dataMonitoring.getIdMonitoring(), true, true); sender.sendStopMonitoring(dataMonitoring); Toast.makeText( this, "monitoring:" + dataMonitoring.getKeterangan() + " akan dinonaktifkan", Toast.LENGTH_SHORT) .show(); }
public void deleteSave(Bundle bundle) { DataMonitoring dataMonitoring = EntityBundleMaker.getDataMonitoringFromBundle(bundle); dataMonitoring = databaseManager.getDataMonitoringByIdMonitoring( dataMonitoring.getIdMonitoring(), true, true); if (dataMonitoring == null) { return; } databaseManager.deleteDataMonitoring(dataMonitoring); for (DataMonitoring dataMonitoringFor : dataMonitorings) { if (dataMonitoringFor.getIdMonitoring().equals(dataMonitoring.getIdMonitoring())) { dataMonitorings.remove(dataMonitoringFor); break; } } daftarMonitoringAdapter.notifyDataSetChanged(); }