Android Open Source - SNET Text Edition






From Project

Back to project page SNET.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project SNET 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 com.snet.textedit;
// w  ww .  j  av  a 2s .  c  o m
import java.io.*;

import com.snet.R;
import com.snet.R.id;
import com.snet.R.layout;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.*;


public class TextEdition extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_textedition);
    }
    public void popup(boolean r)
    {
        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle("Sauvergarde");
        if(r)
        {
            alertDialog.setMessage("Sauvegarde russi");
        }
        else
        {
            alertDialog.setMessage("chec de la sauvegarde ");
        }
        alertDialog.setButton("OK", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int which)
            {
                // TODO Add your code for the button here.
            }
        });
        // Set the Icon for the Dialog
        //alertDialog.setIcon(R.drawable.icon);
        alertDialog.show();
        // see http://androidsnippets.com/simple-alert-dialog-popup-with-title-message-icon-and-button
    }

    /* Checks if external storage is available for read and write */
    public boolean isExternalStorageWritable()
    {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state))
        {
            return true;
        }
        return false;
    }

    /* Checks if external storage is available to at least read */
    public boolean isExternalStorageReadable()
    {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state) ||
                Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))
        {
            return true;
        }
        return false;
    }


    public void save(View v)
    {

        EditText titre = (EditText)findViewById(R.id.TitreNoteEdition);
        String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath();
        File directory = new File(sdcard+ "/MesLivres");
        directory.mkdirs();

        EditText note = (EditText)findViewById(R.id.NoteEdition);
        String contenu = note.getText().toString();
        boolean reussi = true;
        FileOutputStream outputStream;
        try
        {
            File myFile = new File(sdcard+ "/MesLivres",titre.getText().toString());
            myFile.createNewFile();
            outputStream =   new FileOutputStream(myFile);
            OutputStreamWriter osw = new OutputStreamWriter(outputStream);
            osw.write(contenu);
            osw.flush();
            osw.close();
            outputStream.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            reussi = false;
            //popup(false);
            Toast.makeText(this, "chec de la sauvegarde ", Toast.LENGTH_LONG).show();
        }

        if (reussi)
        {
            //popup(true);
            Toast.makeText(this, "Sauvegarde russi", Toast.LENGTH_LONG).show();
        }

    }

    public void open(View v)
    {

        //Find the directory for the SD Card using the API
        //*Don't* hardcode "/sdcard"
        File sdcard = Environment.getExternalStorageDirectory();

        String filename = new String("file.txt");
        //Get the text file
        File file = new File(sdcard,filename);

        //Read text from file
        StringBuilder text = new StringBuilder();

        try
        {
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line;

            while ((line = br.readLine()) != null)
            {
                text.append(line);
                text.append('\n');
            }
        }
        catch (IOException e)
        {
            //You'll need to add proper error handling here
        }

        //Find the view by its id
        EditText content = (EditText)findViewById(R.id.FileContentEdition);

        //Set the text
        content.setText("Google is your friend.\n" + text, TextView.BufferType.EDITABLE);


        TextView titre = (TextView)findViewById(R.id.Filename);
        titre.append(" : " + filename);
    }
}




Java Source Code List

com.snet.MainActivity.java
com.snet.notepad.NoteEdition.java
com.snet.notepad.NoteMain.java
com.snet.notepad.Note.java
com.snet.notepad.NotesBDD.java
com.snet.notepad.Preference.java
com.snet.notepad.SQLiteBase.java
com.snet.textedit.TextEdition.java