private void update(int type, String contents, Date reminderDate) { realm.beginTransaction(); addMemo.setContents(contents); addMemo.setReminderDate(reminderDate); if (type == 1) { addMemo.setHasPhoto(true); } else if (type == 2) { addMemo.setHasVoice(true); } realm.copyToRealm(addMemo); realm.commitTransaction(); }
private void refresh() { if (addMemo == null || !addMemo.isValid()) { Toast.makeText(AddMemoActivity.this, "您尚未添加图片", Toast.LENGTH_SHORT).show(); return; } List<Photo> photoList = realm .where(Photo.class) .equalTo("source", "memo") .equalTo("relationId", addMemo.getId()) .findAll(); adapter = new PhotoAdapter(AddMemoActivity.this, R.layout.photo_item, photoList, true); listView.setAdapter(adapter); }
private void savePhotos() { try { saveMemo(1); realm.beginTransaction(); Photo photo = new Photo(); photo.setId(getPhotoId()); photo.setSource("memo"); photo.setCreateTime(new Date()); photo.setCreateUser(ConstUtils.USER_NAME); photo.setMyPosition(ConstUtils.MY_POSITION); photo.setRelationId(addMemo.getId()); Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri)); Log.d("AddMemoActivity", "width: " + bitmap.getWidth()); Log.d("AddMemoActivity", "height: " + bitmap.getHeight()); if (bitmap.getWidth() < bitmap.getHeight()) { bitmap = ThumbnailUtils.extractThumbnail(bitmap, 660, 1173); } else { bitmap = ThumbnailUtils.extractThumbnail(bitmap, 1173, 660); } ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 95, bos); // 参数100表示不压缩 byte[] photoBytes = bos.toByteArray(); photo.setPhoto(photoBytes); realm.copyToRealm(photo); realm.commitTransaction(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
private void save(int type, String contents, Date reminderDate) { realm.beginTransaction(); addMemo = new Memo(); addMemo.setId(getMemoId()); addMemo.setContents(contents); addMemo.setReminderDate(reminderDate); addMemo.setRepeat(((SpinnerItem) repeat.getSelectedItem()).getKey()); addMemo.setCreateTime(new Date()); addMemo.setCreateUser(ConstUtils.USER_NAME); if (type == 1) { addMemo.setHasPhoto(true); } else if (type == 2) { addMemo.setHasVoice(true); } realm.copyToRealm(addMemo); realm.commitTransaction(); }
private void saveMemo(int type) { String contents = memoEditText.getText().toString(); String[] selectDateArray = selectDate.getText().toString().split("-"); String[] selectTimeArray = selectTime.getText().toString().split(":"); Calendar calendar = Calendar.getInstance(); calendar.set( ParseUtils.convertToInt(selectDateArray[0], 0), ParseUtils.convertToInt(selectDateArray[1], 0) - 1, ParseUtils.convertToInt(selectDateArray[2], 0), ParseUtils.convertToInt(selectTimeArray[0], 0), ParseUtils.convertToInt(selectTimeArray[1], 0)); Date reminderDate = calendar.getTime(); if (addMemo != null) { addMemo = realm.where(Memo.class).equalTo("id", addMemo.getId()).findFirst(); if (addMemo == null) { save(type, contents, reminderDate); return; } update(type, contents, reminderDate); return; } save(type, contents, reminderDate); }
private void save() { saveMemo(0); setDefault(); AlarmUtils.setAlarm(addMemo.getReminderDate().getTime(), "我的备忘", addMemo.getContents()); Toast.makeText(AddMemoActivity.this, "添加完成", Toast.LENGTH_SHORT).show(); }