-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathNoteInfoActivity.java
More file actions
57 lines (48 loc) · 1.72 KB
/
NoteInfoActivity.java
File metadata and controls
57 lines (48 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.ulan.timetable.activities;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;
import com.ulan.timetable.model.Note;
import com.ulan.timetable.R;
import com.ulan.timetable.utils.DbHelper;
public class NoteInfoActivity extends AppCompatActivity {
private DbHelper db;
private Note note;
private EditText text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_info);
setupIntent();
}
private void setupIntent() {
db = new DbHelper(NoteInfoActivity.this);
note = (Note) getIntent().getSerializableExtra(NotesActivity.KEY_NOTE);
text = findViewById(R.id.edittextNote);
if(note.getText() != null) {
text.setText(note.getText());
}
}
@Override
public void onBackPressed() {
note.setText(text.getText().toString());
db.updateNote(note);
Toast.makeText(NoteInfoActivity.this, getResources().getString(R.string.saved), Toast.LENGTH_SHORT).show();
super.onBackPressed();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
note.setText(text.getText().toString());
db.updateNote(note);
Toast.makeText(NoteInfoActivity.this, getResources().getString(R.string.saved), Toast.LENGTH_SHORT).show();
super.onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}