Back to project page Points.
The source code is released under:
GNU General Public License
If you think the Android project Points listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package se.frusunnanbo.points; /*ww w.j a v a 2 s . com*/ import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; import java.text.DateFormat; import java.util.Date; import java.util.Locale; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; public class DailyPointsActivity extends Activity { private TextView dateView; private CheckBox checkBoxTask1; private CheckBox checkBoxTask2; private Storage storage; private Date dateCreated; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_daily_points); dateView = (TextView) findViewById(R.id.date_view); checkBoxTask1 = (CheckBox) findViewById(R.id.task1_chkbox); checkBoxTask2 = (CheckBox) findViewById(R.id.task2_chkbox); Prefs prefs = new Prefs(this); if (!prefs.valid()) { openSettingsActivity("Var god fyll i."); } } @Override protected void onResume() { super.onResume(); // The activity has become visible (it is now "resumed"). Prefs prefs = new Prefs(this); storage = new Storage(prefs); dateCreated = new Date(); DateFormat formattedDate = DateFormat.getDateInstance(DateFormat.LONG, new Locale("sv", "SE")); dateView.setText(formattedDate.format(dateCreated) + ":"); checkBoxTask1.setText(prefs.getTask1Name()); checkBoxTask2.setText(prefs.getTask2Name()); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.daily_points, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.action_settings: openSettingsActivity("Varsgod och ndra."); return true; default: return super.onOptionsItemSelected(item); } } public void saveDailyResult(View view) { int task1Points = checkBoxTask1.isChecked() ? 1 : 0; int task2Points = checkBoxTask2.isChecked() ? 1 : 0; try { storage.save(this, dateCreated, task1Points, task2Points); Toast.makeText(this, "Sparade " + task1Points + " + " + task2Points + " = " + (task1Points + task2Points) + " pong.", Toast.LENGTH_SHORT).show(); } catch (MalformedURLException e) { openSettingsActivity("Din URI r inte en URI. Fixa."); } catch (FileNotFoundException e) { openSettingsActivity("Servern knner inte till din URI. Skriv om."); } catch (IOException e) { Toast.makeText(this, "Ett ovntat fel: " + e.toString(), Toast.LENGTH_SHORT).show(); } finish(); } private void openSettingsActivity(String why) { Intent intent = new Intent(this, SettingsActivity.class); intent.putExtra("se.frusunnanbo.points.whySettings", why); startActivity(intent); } }