本身設計了該應用程序的圖標。
android
改了佈局文件中的一些屬性來保持界面乾淨美觀。git
MainActivity
數據庫
該活動是本App進入後的第一個界面,界面主要是大體的介紹和一個跳轉按鈕。小程序
該活動是承接MainActivity活動的第二個界面,這個界面上半部分是對該APP功能的一個簡單說明。下方是具體三個板塊——紅箋小字,抒寫心情▶、日帳管家▶、生活計劃▶。這三個板塊分別在該活動上體現爲一個按鈕,經過選擇能夠進入不一樣的功能界面。app
public class AddNoteActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_note); } public void cancel(View view) { finish(); } public void addNote(View view) { String fileName = ((EditText) findViewById(R.id.noteTitle)) .getText().toString(); String body = ((EditText) findViewById(R.id.noteBody)) .getText().toString(); File parent = getFilesDir(); File file = new File(parent, fileName); PrintWriter writer = null; try { writer = new PrintWriter(file); writer.write(body); finish(); } catch (Exception e) { showAlertDialog("Error adding note", e.getMessage()); } finally { if (writer != null) { try { writer.close(); } catch (Exception e) { } } } } private void showAlertDialog(String title, String message) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle(title); alertDialog.setMessage(message); alertDialog.show(); } }
public class Second1Activity extends Activity { private String selectedItem; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second1); ListView listView = (ListView) findViewById(R.id.listView1); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); listView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { readNote(position); } }); } @Override public void onResume() { super.onResume(); refreshList(); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_add: startActivity(new Intent(this, AddNoteActivity.class)); return true; case R.id.action_delete: deleteNote(); return true; default: return super.onOptionsItemSelected(item); } } private void refreshList() { ListView listView = (ListView) findViewById( R.id.listView1); String[] titles = fileList(); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, titles); listView.setAdapter(arrayAdapter); } private void readNote(int position) { String[] titles = fileList(); if (titles.length > position) { selectedItem = titles[position]; File dir = getFilesDir(); File file = new File(dir, selectedItem); FileReader fileReader = null; BufferedReader bufferedReader = null; try { fileReader = new FileReader(file); bufferedReader = new BufferedReader(fileReader); StringBuilder sb = new StringBuilder(); String line = bufferedReader.readLine(); while (line != null) { sb.append(line); line = bufferedReader.readLine(); } ((TextView) findViewById(R.id.textView1)). setText(sb.toString()); } catch (IOException e) { } finally { if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException e) { } } if (fileReader != null) { try { fileReader.close(); } catch (IOException e) { } } } } } private void deleteNote() { if (selectedItem != null) { deleteFile(selectedItem); selectedItem = null; ((TextView) findViewById(R.id.textView1)).setText(""); refreshList(); } } }
Second1Activity活動使用一個ListView,它列出了系統中全部備忘的標題。Add啓動ADDNoteActivity活動,Delete刪除所選的備忘。
ide
value1 = Double.parseDouble(etvalue1.getText().toString()); value2 = Double.parseDouble(etvalue2.getText().toString()); value3 = Double.parseDouble(etvalue3.getText().toString()); value4 = Double.parseDouble(etvalue4.getText().toString()); value5 = Double.parseDouble(etvalue5.getText().toString()); value6 = Double.parseDouble(budget.getText().toString()); result = value1+ value2 + value3 + value4 + value5; textView.setText("" + result + ""); if(result > value6) { Toast.makeText(Second2Activity.this, "花銷已超出預算,請注意開支!(;′⌒`)", Toast.LENGTH_LONG).show(); } else { Toast.makeText(Second2Activity.this, "花銷合理有餘,請繼續保持哦。(* ̄︶ ̄)", Toast.LENGTH_LONG).show(); }
public class Second3Activity extends Activity { private EditText period; private int value; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second3); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected( MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } public void setAlarm(View view) { period = (EditText)findViewById(R.id.editText16); value = Integer.parseInt(period.getText().toString()); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR, value); Date hoursLater = calendar.getTime(); Toast.makeText(this, "The alarm will set off at " + hoursLater, Toast.LENGTH_LONG).show(); AlarmManager alarmMgr = (AlarmManager) getSystemService( Context.ALARM_SERVICE); Intent intent = new Intent(this, WakeUpActivity.class); PendingIntent sender = PendingIntent.getActivity( this, 0, intent, 0); alarmMgr.set(AlarmManager.RTC_WAKEUP, hoursLater.getTime(), sender); } }
該類中的setAlarm方法建立了一個Date實例,指向從如今開始的某一段時間,而後建立了一個PendingIntent封裝了一個意圖,該意圖將會啓動WakeUpActivity活動。而後,它訪問了AlarmManager,而且經過傳遞時間和PendingIntent來設置了一個鬧鐘。
佈局