本身设计了该应用程序的图标。
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来设置了一个闹钟。
布局