azou.note.Writer.java Source code

Java tutorial

Introduction

Here is the source code for azou.note.Writer.java

Source

/*  
 * <azou-notes is a note taking app that gives some stats of the users usage and a wordcloud>
Copyright (C) 2013 Anthony ou
    
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

package azou.note;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Calendar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/*/
 * this class is for taking in text input and managing in their
 * saving to file and sending them to other activites.
 * No particular issues except for notes being serial and parcelable
 */
public class Writer extends FragmentActivity {
    Button date;
    Calendar c;
    Intent i;
    EditText body, subject;

    //http://stackoverflow.com/questions/11967040/adding-action-bar 2013-9-27
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.writer);

        getActionBar().setDisplayShowTitleEnabled(false);
        c = Calendar.getInstance();
        date = (Button) findViewById(R.id.date);
        body = (EditText) findViewById(R.id.bodybox);
        subject = (EditText) findViewById(R.id.subjectbox);
        date = (Button) findViewById(R.id.date);

        Button newbutton = (Button) findViewById(R.id.newbutton);
        newbutton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                newnote();
            }
        });

        date.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                SelectDateFragment date = new SelectDateFragment();
                date.show(getSupportFragmentManager(), "datepicker");

            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        Note temp = NoteApplication.getCurrentNote();
        body.setText(temp.getBody());
        date.setText(temp.getDate());
        subject.setText(temp.getSubject());
    }

    public void newnote() {
        savecurrent();
        Note newnote = new Note();
        date.setText(newnote.getDate());
        subject.setText("");
        body.setText("");
        NoteApplication.setCurrentNote(newnote);
    }

    @Override
    public void onPause() {
        super.onPause();
        savecurrent();
    }

    public void savecurrent() {
        Note temp = NoteApplication.getCurrentNote();
        temp.setBody(body.getText().toString());
        temp.setDate(date.getText().toString());
        temp.setSubject(subject.getText().toString());
        NoteApplication.setCurrentNote(temp);
    }

    //http://stackoverflow.com/questions/14053702/android-click-on-actionbar-app-icon-create-new-activity-instance  2013-9-27
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            Intent intent = new Intent(this, Writer.class);
            startActivity(intent);
            return true;
        case R.id.logs:
            intent = new Intent(this, Logs.class);
            startActivity(intent);
            return true;
        case R.id.stats:
            intent = new Intent(this, Stats.class);
            startActivity(intent);
            return true;
        case R.id.wordcloud:
            intent = new Intent(this, Wordcloud.class);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

    //create the action bar menu items.
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}