Android Open Source - jpstrack.android Text Note Activity






From Project

Back to project page jpstrack.android.

License

The source code is released under:

/* * Copyright (c) 2006-2014 Ian F. Darwin, http://darwinsys.com * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following co...

If you think the Android project jpstrack.android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package jpstrack.android;
//from  ww  w . j  a va2 s . co  m
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import jpstrack.fileio.FileNameUtils;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;

public class TextNoteActivity extends Activity implements OnClickListener {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    if (!MainActivity.isSdWritable()) {
      Toast.makeText(this, "SD Card is not writable", Toast.LENGTH_LONG).show();
      finish();
      return;
    }
    
    setContentView(R.layout.textnote);
    View saver = findViewById(R.id.textnote_save_button);
    saver.setOnClickListener(this);
    View killer = findViewById(R.id.textnote_discard_button);
    killer.setOnClickListener(this);
  }
  
  @Override
  public void onClick(View v) {
    int source = v.getId();
    switch(source) {
    case R.id.textnote_save_button:
      doSave();
      finish();
      break;
    case R.id.textnote_discard_button:
      finish();
      break;
    default:
      break;
    }
  }

  private void doSave() {
    EditText tv = (EditText) findViewById(R.id.textnote_text);
    File f = new File(MainActivity.getDataDir(), FileNameUtils.getNextFilename("txt"));
    try {
      PrintWriter out = new PrintWriter(f);
      out.print(tv.getText().toString());
      out.close();
      Toast.makeText(this, "Saved text note into " + f, Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
      final String message = "Can't create text file " + f + "(" + e + ")";
      Log.e(MainActivity.TAG, message);
      Toast.makeText(this, message, Toast.LENGTH_LONG).show();
      // Don't finish! Let them try later
    }
  }
}




Java Source Code List

jpstrack.android.ActionBarActivity.java
jpstrack.android.ActionBarHelperBase.java
jpstrack.android.ActionBarHelperHoneycomb.java
jpstrack.android.ActionBarHelperICS.java
jpstrack.android.ActionBarHelper.java
jpstrack.android.AndroidApplication.java
jpstrack.android.ButtonSnazzler.java
jpstrack.android.MainActivity.java
jpstrack.android.OnboardingActivity.java
jpstrack.android.SettingsActivity.java
jpstrack.android.ShowWelcomePage.java
jpstrack.android.SimpleMenuItem.java
jpstrack.android.SimpleMenu.java
jpstrack.android.TextNoteActivity.java
jpstrack.android.ThreadUtils.java
jpstrack.android.TrackerName.java
jpstrack.android.VoiceNoteActivity.java