Android Open Source - disconnected-content-explorer-android Note Activity






From Project

Back to project page disconnected-content-explorer-android.

License

The source code is released under:

MIT License

If you think the Android project disconnected-content-explorer-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 mil.nga.dice.report;
// w  w w  .  j a  va  2 s .  co  m
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import mil.nga.dice.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class NoteActivity extends Activity {
  
  Report mReport;
  
  File root = Environment.getExternalStorageDirectory();
  File notesDirectory = new File(root.getPath() + "/DICE/notes");
  
  @Override
  public void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);
    setContentView(R.layout.activity_note);
    
    Bundle bundle = getIntent().getExtras();
    mReport = bundle.getParcelable("report");
    
    String notePath = notesDirectory.getPath() + "/" + mReport.getTitle() + ".txt";
    String noteText = readNote(notePath);
    TextView textView = (TextView)findViewById(R.id.noteTextArea);
    textView.setText(noteText);
  }

  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        saveNote();
        finish();
        return true;
      case R.id.save_note:
        saveNote();
        return true;
      case R.id.cancel_note:
        cancelNote();
        return true;
    }
    
    return super.onOptionsItemSelected(item);
  }
  
  
  private void saveNote() {
    // TODO Auto-generated method stub
    TextView textView = (TextView)findViewById(R.id.noteTextArea);
    
    File note= new File(notesDirectory.getPath() + "/" + mReport.getTitle() + ".txt");
    
    if (!notesDirectory.exists()) {
      notesDirectory.mkdir();
    }
    
    try {
      note.createNewFile();
      FileOutputStream fOut = new FileOutputStream(note);
      fOut.write(textView.getText().toString().getBytes());
      fOut.flush();
      fOut.close();
      Toast.makeText(getBaseContext(), "Note saved", Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      Toast.makeText(getBaseContext(), "Problem saving note", Toast.LENGTH_SHORT).show();
      e.printStackTrace();
    }
    finish();
  }


  private void cancelNote() {
    finish();
  }


  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.note_menu, menu);
      return true;
  }
  
  
  private String readNote(String path) {
    String noteText = "";
    
    File note = new File(path);
    if (note.exists()) {
      try {
        FileInputStream inputStream = new FileInputStream(note);
        
        if (inputStream != null) {
          InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
          BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
          String readString = "";
          StringBuilder stringBuilder = new StringBuilder();
          
          while ((readString = bufferedReader.readLine()) != null) {
            stringBuilder.append(readString).append("\n");
          }
          
          inputStream.close();
          noteText = stringBuilder.toString();
        }
        
      } catch (Exception e) {
        Toast.makeText(getBaseContext(), "Problem loading note", Toast.LENGTH_SHORT).show();  
      }
    }
    
    return noteText;
  }
}




Java Source Code List

mil.nga.dice.DICE.java
mil.nga.dice.gridview.CustomGrid.java
mil.nga.dice.gridview.ReportGridActivity.java
mil.nga.dice.gridview.ReportGridFragment.java
mil.nga.dice.jackson.deserializer.Deserializer.java
mil.nga.dice.jackson.deserializer.FeatureDeserializer.java
mil.nga.dice.jackson.deserializer.GeometryDeserializer.java
mil.nga.dice.listview.CustomList.java
mil.nga.dice.listview.ReportListActivity.java
mil.nga.dice.listview.ReportListFragment.java
mil.nga.dice.listview.ReportListItem.java
mil.nga.dice.map.BackgroundTileProvider.java
mil.nga.dice.map.OfflineMapLoader.java
mil.nga.dice.map.OfflineMap.java
mil.nga.dice.map.ReportMapActivity.java
mil.nga.dice.map.ReportMapFragment.java
mil.nga.dice.report.NoteActivity.java
mil.nga.dice.report.NoteFragment.java
mil.nga.dice.report.ReportDetailActivity.java
mil.nga.dice.report.ReportDetailFragment.java
mil.nga.dice.report.ReportDropbox.java
mil.nga.dice.report.ReportManager.java
mil.nga.dice.report.ReportUnzipRunnable.java
mil.nga.dice.report.Report.java