| Talking Reminder this project is intenfed for people who are not tech savvy

ReminderReceiveActivity.java
1 package com.sudogeeks.talking_reminder;
2
3 import android.content.Context;
4 import android.content.Intent;
5 import android.net.Uri;
6 import android.os.Bundle;
7 import android.view.Menu;
8 import android.view.MenuItem;
9 import android.widget.EditText;
10 import android.widget.TextView;
11 import android.widget.Toast;
12
13 import androidx.appcompat.app.AppCompatActivity;
14 import androidx.appcompat.widget.Toolbar;
15
16 import org.json.JSONObject;
17
18 import java.io.InputStream;
19 import java.util.Calendar;
20
21
25 public class ReminderReceiveActivity extends AppCompatActivity {
26 private static final long milMinute = 60000L;
27 private static final long milHour = 3600000L;
28 private static final long milDay = 86400000L;
29 private static final long milWeek = 604800000L;
30 private static final long milMonth = 2592000000L;
31 private Toolbar mToolbar;
32 private EditText mTitleText;
33 private TextView mDateText, mTimeText, mRepeatText, mRepeatNoText, mRepeatTypeText;
34 private String mRepeat;
35 private String mRepeatType;
36 private String mRepeatNo;
37 private Calendar mCalendar;
38 private int mYear, mMonth, mHour, mMinute, mDay;
39 private long mRepeatTime;
40 private String mActive;
41
42 @Override
43 protected void onCreate(Bundle savedInstanceState) {
44 super.onCreate(savedInstanceState);
45 setContentView(R.layout.activity_receive_reminder);
46 Context context = this;
47
48 mCalendar = Calendar.getInstance();
49 mHour = mCalendar.get(Calendar.HOUR_OF_DAY);
50 mMinute = mCalendar.get(Calendar.MINUTE);
51 mYear = mCalendar.get(Calendar.YEAR);
52 mMonth = mCalendar.get(Calendar.MONTH) + 1;
53 mDay = mCalendar.get(Calendar.DATE);
54
55 //by default
56 mActive = "true";
57 // Setup Toolbar
58 mToolbar = findViewById(R.id.toolbar);
59 setSupportActionBar(mToolbar);
60 getSupportActionBar().setTitle(R.string.activity_add_reminder_label);
61
62 //Get the file from intent
63 Intent intent = getIntent();
64 Uri fileUri = intent.getData();
65 StringBuilder reminderJson = new StringBuilder();
66 if (intent.getType().equals("text/" + Utility.FILE_EXTENSION)) {
67 try {
68 InputStream in = getContentResolver().openInputStream(fileUri);
69 int i;
70
71 while ((i = in.read()) != -1)
72 reminderJson.append((char) i);
73 //System.out.println("******************************************************************");
74 //System.out.println(sb.toString());
75 //System.out.println("******************************************************************");
76 } catch (Exception e) {
77 e.printStackTrace();
78 }
79
80 try {
81 JSONObject obj = new JSONObject(reminderJson.toString());
82 //ReminderDO talkingReminder=new ReminderDO();
83 mTitleText = findViewById(R.id.reminder_title);
84 mDateText = findViewById(R.id.set_date);
85 mTimeText = findViewById(R.id.set_time);
86 mRepeatText = findViewById(R.id.set_repeat);
87 mRepeatNoText = findViewById(R.id.set_repeat_no);
88 mRepeatTypeText = findViewById(R.id.set_repeat_type);
89
90 mRepeat = obj.getString("mRepeat");
91 mRepeatType = obj.getString("mRepeatType");
92 mRepeatNo = obj.getString("mRepeatNo");
93
94 mTitleText.setText(obj.getString("mTitle"));
95 mDateText.setText(obj.getString("mDate"));
96 mTimeText.setText(obj.getString("mTime"));
97 mRepeatText.setText("Every " + obj.getString("mRepeatNo") + " " + obj.getString("mRepeatType") + "(s)");
98 mRepeatNoText.setText(obj.getString("mRepeatNo"));
99 mRepeatTypeText.setText(obj.getString("mRepeatType"));
100
101
102 } catch (Throwable t) {
103 t.printStackTrace();
104 }
105
106
107 /*Intent senderIntent = new Intent(context, ReminderEditActivity.class);
108 senderIntent.putExtra("received", true);
109 senderIntent.putExtra("mTitle", "First Receive ReminderDO test");
110 startActivity(senderIntent);*/
111 }
112 }
113
117 public void saveSendReminder() {
118 ReminderDatabase rb = new ReminderDatabase(this);
119
120 // Creating ReminderDO
121 int ID = rb.addReminder(new ReminderDO(mTitleText.getText().toString(), mDateText.getText().toString(), mTimeText.getText().toString(), mRepeat, mRepeatNoText.getText().toString(), mRepeatTypeText.getText().toString(), mActive));
122
123
124 // Set up calender for creating the notification
125 mCalendar.set(Calendar.MONTH, --mMonth);
126 mCalendar.set(Calendar.YEAR, mYear);
127 mCalendar.set(Calendar.DAY_OF_MONTH, mDay);
128 mCalendar.set(Calendar.HOUR_OF_DAY, mHour);
129 mCalendar.set(Calendar.MINUTE, mMinute);
130 mCalendar.set(Calendar.SECOND, 0);
131
132 // Check repeat type
133 if (mRepeatType.equals("Minute")) {
134 mRepeatTime = Integer.parseInt(mRepeatNo) * milMinute;
135 } else if (mRepeatType.equals("Hour")) {
136 mRepeatTime = Integer.parseInt(mRepeatNo) * milHour;
137 } else if (mRepeatType.equals("Day")) {
138 mRepeatTime = Integer.parseInt(mRepeatNo) * milDay;
139 } else if (mRepeatType.equals("Week")) {
140 mRepeatTime = Integer.parseInt(mRepeatNo) * milWeek;
141 } else if (mRepeatType.equals("Month")) {
142 mRepeatTime = Integer.parseInt(mRepeatNo) * milMonth;
143 }
144
145 // Create a new notification
146 if (mActive.equals("true")) {
147 if (mRepeat.equals("true")) {
148 new AlarmReceiver().setRepeatAlarm(getApplicationContext(), mCalendar, ID, mRepeatTime);
149 } else if (mRepeat.equals("false")) {
150 new AlarmReceiver().setAlarm(getApplicationContext(), mCalendar, ID);
151 }
152 }
153
154 // Create toast to confirm new reminder
155 Toast.makeText(getApplicationContext(), "Saved",
156 Toast.LENGTH_SHORT).show();
157
158 onBackPressed();
159 }
160
161 // Creating the menu
162 @Override
163 public boolean onCreateOptionsMenu(Menu menu) {
164 getMenuInflater().inflate(R.menu.menu_receive_reminder, menu);
165 return true;
166 }
167
168 @Override
169 public boolean onOptionsItemSelected(MenuItem item) {
170 switch (item.getItemId()) {
171
172 // On clicking the back arrow
173 // Discard any changes
174 case android.R.id.home:
175 onBackPressed();
176 return true;
177
178 // On clicking save reminder button
179 // Update reminder
180 case R.id.save_reminder:
181 saveSendReminder();
182
183
184 default:
185 return super.onOptionsItemSelected(item);
186 }
187 }
188
189 }
com.sudogeeks.talking_reminder.AlarmReceiver.setAlarm
void setAlarm(Context context, Calendar calendar, int ID)
Definition: AlarmReceiver.java:73
com.sudogeeks.talking_reminder.ReminderReceiveActivity.saveSendReminder
void saveSendReminder()
Definition: ReminderReceiveActivity.java:117
com.sudogeeks.talking_reminder.ReminderDO
Data Object class for Reminder This class conatins all the attributes of reminder.
Definition: ReminderDO.java:15
com.sudogeeks.talking_reminder.ReminderReceiveActivity
Class to read and parse reminder Data after receiving This class parse the received reminder object a...
Definition: ReminderReceiveActivity.java:25
com.sudogeeks.talking_reminder.ReminderDatabase
Class to manage database This class is for managing the database.
Definition: ReminderDatabase.java:15
com.sudogeeks.talking_reminder.Utility
Definition: Utility.java:3
com.sudogeeks.talking_reminder.AlarmReceiver
A class implementing basic alarm functions This class includes very basic features for an alarm.
Definition: AlarmReceiver.java:21
com.sudogeeks.talking_reminder.ReminderDatabase.addReminder
int addReminder(ReminderDO reminderDO)
Definition: ReminderDatabase.java:83
com.sudogeeks.talking_reminder.AlarmReceiver.setRepeatAlarm
void setRepeatAlarm(Context context, Calendar calendar, int ID, long RepeatTime)
Definition: AlarmReceiver.java:107