[android-beginners] Re: Saving calculator result problem

2009-09-29 Thread bgoody

I couldn't get that one to work so I'm trying something else.

Here's where the button is pressed:

btnMP.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
memNum = memNum + 
Double.parseDouble(txtCalc.getText().toString());
operator = 0;   }
});

Here's a thingie I hammered together from parts:

// Save MEMORY
public void WriteMemory(OnClickListener onClickListener, double
memNum){
File sdcard = Environment.getExternalStorageDirectory();
File destinationdir = new File(sdcard,/download/calculator);
destinationdir.mkdir();
File destinationfile = new File(destinationdir,memory.dat);
  FileOutputStream fOut = null;
  OutputStreamWriter osw = null;

  try{
  destinationfile.createNewFile();
  fOut =  new FileOutputStream(destinationfile);
  osw = new OutputStreamWriter(fOut);
  osw.write((int) memNum);
  osw.flush();
  Toast.makeText((Context) onClickListener, Memory
saved,Toast.LENGTH_SHORT).show();
  }
  catch (Exception e) {
  e.printStackTrace();
//Toast.makeText((Context) onClickListener, Memory not
saved,Toast.LENGTH_SHORT).show();
  }
  finally {
 try {
osw.close();
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
  }
 }

This is called by inserting WriteMemory(this,memNum); in the button
routine thusly:

btnMP.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
memNum = memNum + 
Double.parseDouble(txtCalc.getText().toString());
operator = 0;   }
WriteMemory(this,memNum);
});

The file is created but nothing is written in it. What's missing?
Brian

On Sep 28, 3:38 pm, Yusuf Saib (T-Mobile USA) yusuf.s...@t-
Mobile.com wrote:
 txt is declared inside your if (hasChanged) { scope. Then you use it
 after the corresponding }.

 Yusuf Saib
 Android
 ·T· · ·Mobile· stick together
 The views, opinions and statements in this email are those of the
 author solely in their individual capacity, and do not necessarily
 represent those of T-Mobile USA, Inc.

 On Sep 27, 10:02 am, bgoody bgoody...@gmail.com wrote:

  Hi. I am trying to hack this bit of code tosavethe results of a
  calculation to disk but it says that the variable (txt) cannot be
  resolved.
  Any ideas!

  private void handleEquals(int newOperator) {
  if (hasChanged) {
  switch (operator) {
  case 1:
  num = num +Double.parseDouble(txtCalc.getText().toString());
  break;
  case 2:
  num = num -Double.parseDouble(txtCalc.getText().toString());
  break;
  case 3:
  num = num *Double.parseDouble(txtCalc.getText().toString());
  break;
  case 4:
  num = num /Double.parseDouble(txtCalc.getText().toString());
  break;

  }

  String txt =Double.toString(num);
  txtCalc.setText(txt);
  txtCalc.setSelection(txt.length());

  readyToClear = true;
  hasChanged = false;

  }

  FileOutputStream fOut = openFileOutput
  (samplefile.txt,MODE_WORLD_READABL E);
  OutputStreamWriter osw = new OutputStreamWriter(fOut);
  osw.write(txt);
  osw.flush();
  fOut.close();
  osw.close();
  operator = newOperator;

  }


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Saving calculator result problem

2009-09-28 Thread Yusuf Saib (T-Mobile USA)

txt is declared inside your if (hasChanged) { scope. Then you use it
after the corresponding }.


Yusuf Saib
Android
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.



On Sep 27, 10:02 am, bgoody bgoody...@gmail.com wrote:
 Hi. I am trying to hack this bit of code to save the results of a
 calculation to disk but it says that the variable (txt) cannot be
 resolved.
 Any ideas!

 private void handleEquals(int newOperator) {
 if (hasChanged) {
 switch (operator) {
 case 1:
 num = num + Double.parseDouble(txtCalc.getText().toString());
 break;
 case 2:
 num = num - Double.parseDouble(txtCalc.getText().toString());
 break;
 case 3:
 num = num * Double.parseDouble(txtCalc.getText().toString());
 break;
 case 4:
 num = num / Double.parseDouble(txtCalc.getText().toString());
 break;

 }

 String txt = Double.toString(num);
 txtCalc.setText(txt);
 txtCalc.setSelection(txt.length());

 readyToClear = true;
 hasChanged = false;

 }

 FileOutputStream fOut = openFileOutput
 (samplefile.txt,MODE_WORLD_READABL E);
 OutputStreamWriter osw = new OutputStreamWriter(fOut);
 osw.write(txt);
 osw.flush();
 fOut.close();
 osw.close();
 operator = newOperator;



 }
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Saving

2009-08-13 Thread Michael Leung
Can you explain more about what you are trying to do?

On Fri, Aug 14, 2009 at 6:09 AM, RustedApple kim00...@gmail.com wrote:


 I am trying to understand what data is saved when I change the phone's
 orientation.
 For instance, I have a couple guys walking around and when I flip the
 orientation, they are still there walking.
 However, in a different part of code, I also spawn more guys, but this
 time, they wont be there when I flip the orientation.

 So how would one be saved while the other isn't?

 Thanks

 



-- 
Regards,
Michael Leung
http://www.itblogs.info
http://www.michaelleung.info

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: saving data to text file using eclipse

2009-08-12 Thread Saeed

Thank you Jack,
It works.


On Aug 11, 5:16 pm, Jack Ha jack...@t-mobile.com wrote:
 Context.openFileOutput() opens a private file associated with this
 Context's application package for writing and the name of the file to
 open can not contain path separators.

 Try this:

        try {
            File root = Environment.getExternalStorageDirectory();
            if (root.canWrite()){
                File f = new File(root, test.txt);
                FileWriter fw = new FileWriter(f);
                BufferedWriter out = new BufferedWriter(fw);
                out.write(Hello world);
                out.close();
            }
        } catch (IOException e) {
        }

 --
 Jack Ha
 Open Source Development Center
 ・T・ ・ ・Mobile・ stick together

 The views, opinions and statements in this email are those of
 the author solely in their individual capacity, and do not
 necessarily represent those of T-Mobile USA, Inc.

 On Aug 11, 1:57 pm, Saeed saeed.pourbagh...@gmail.com wrote:

  Hi everyone,

  I am trying to save data to my google phone G1. I am able to create
  the text file in sdcard by using the following code in eclipse :

  //++
  try {
                  FileWriter f = new FileWriter(/sdcard/test.txt);
          } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
          }
  //+

  but I am not able to save any data to the created file. I found this
  code from http://www.anddev.org/working_with_files-t115.html; which
  says I can write to text file by running this code.

  //+++
  try { // catches IOException below
            final String TESTSTRING = new String(hello);

            FileOutputStream fOut = openFileOutput(/sdcard/test.txt,

  MODE_WORLD_READABLE);
            OutputStreamWriter osw = new OutputStreamWriter(fOut);

            // Write the string to the file
            osw.write(TESTSTRING);
            // ensure that everything is
            // really written out and close
            osw.flush();
            osw.close();

        } catch (IOException ioe) {
            ioe.printStackTrace();
       }
  //+

  I run it but I do not see any change in my file.
  first, I thought my problem is permission to file. The permission
  setting on my phone is:

  data        :   drwxrwx--x
  sdcard    :   d---rwxrwx
  system    :   drwxr-xr-x

  would you please help me in either in correcting the code or finding a
  way to save data into text file (saved in sdcard or the phone) in
  eclipse environment

  thanks in advance
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: saving data to text file using eclipse

2009-08-11 Thread Jack Ha

Context.openFileOutput() opens a private file associated with this
Context's application package for writing and the name of the file to
open can not contain path separators.

Try this:

   try {
   File root = Environment.getExternalStorageDirectory();
   if (root.canWrite()){
   File f = new File(root, test.txt);
   FileWriter fw = new FileWriter(f);
   BufferedWriter out = new BufferedWriter(fw);
   out.write(Hello world);
   out.close();
   }
   } catch (IOException e) {
   }

--
Jack Ha
Open Source Development Center
・T・ ・ ・Mobile・ stick together

The views, opinions and statements in this email are those of
the author solely in their individual capacity, and do not
necessarily represent those of T-Mobile USA, Inc.


On Aug 11, 1:57 pm, Saeed saeed.pourbagh...@gmail.com wrote:
 Hi everyone,

 I am trying to save data to my google phone G1. I am able to create
 the text file in sdcard by using the following code in eclipse :

 //++
 try {
                 FileWriter f = new FileWriter(/sdcard/test.txt);
         } catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
         }
 //+

 but I am not able to save any data to the created file. I found this
 code from http://www.anddev.org/working_with_files-t115.html; which
 says I can write to text file by running this code.

 //+++
 try { // catches IOException below
           final String TESTSTRING = new String(hello);

           FileOutputStream fOut = openFileOutput(/sdcard/test.txt,

 MODE_WORLD_READABLE);
           OutputStreamWriter osw = new OutputStreamWriter(fOut);

           // Write the string to the file
           osw.write(TESTSTRING);
           // ensure that everything is
           // really written out and close
           osw.flush();
           osw.close();

       } catch (IOException ioe) {
           ioe.printStackTrace();
      }
 //+

 I run it but I do not see any change in my file.
 first, I thought my problem is permission to file. The permission
 setting on my phone is:

 data        :   drwxrwx--x
 sdcard    :   d---rwxrwx
 system    :   drwxr-xr-x

 would you please help me in either in correcting the code or finding a
 way to save data into text file (saved in sdcard or the phone) in
 eclipse environment

 thanks in advance
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Saving a preference isn't working

2009-06-22 Thread Balwinder Kaur (T-Mobile)

You need to get an instance of the SharedPreferences.Editor and carry
out all your operations on it.

Try this.

SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
editor.putString( DrinkName , chai);
editor.commit();

SharedPreferences prefs = getPreferences(MODE_PRIVATE);
String favdrink = prefs.getString( DrinkName ,  ); //it should
return chai

Every call to getPreferences( MODE_PRIVATE ).edit() is returning a new
instance of the SharedPreferences.Editor object which is never being
committed, hence you don't see your values being saved.


For more details, check out 
http://developer.android.com/reference/android/content/SharedPreferences.Editor.html

Hope this helps,

Balwinder Kaur
Open Source Development Center
·T· · ·Mobile· stick together

The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.


On Jun 22, 8:15 pm, bear123434...@comcast.net wrote:
 I have a screen where a user can enter information about a Favorite drink.  I 
 want to save it to be recalled in the current an future sessions, but the 
 save doesn't seem to be working.  Here is my code where I do the save.

 getPreferences( MODE_PRIVATE ).edit().putString( DrinkName , FavName);

 getPreferences( MODE_PRIVATE ).edit().putFloat( Volume , ( float ) AlcVol);

 getPreferences( MODE_PRIVATE ).edit().putFloat( Percent , ( float ) 
 AlcPerc);

 getPreferences( MODE_PRIVATE ).edit().commit(); MODE_PRIVATE 
 ).edit().putString( DrinkName , FavName);

 getPreferences( MODE_PRIVATE ).edit().putFloat( Volume , ( float ) AlcVol);

 getPreferences( MODE_PRIVATE ).edit().putFloat( Percent , ( float ) 
 AlcPerc);

 getPreferences( MODE_PRIVATE ).edit().commit(); MODE_PRIVATE 
 ).edit().putFloat( Volume , ( float ) AlcVol);

 getPreferences( MODE_PRIVATE ).edit().putFloat( Percent , ( float ) 
 AlcPerc);

 getPreferences( MODE_PRIVATE ).edit().commit(); MODE_PRIVATE 
 ).edit().putFloat( Percent , ( float ) AlcPerc);

 getPreferences( MODE_PRIVATE ).edit().commit(); MODE_PRIVATE 
 ).edit().commit();

 Here is the code where I try to retrieve the saved infromation.

 String strName = getPreferences( MODE_PRIVATE ).getString( DrinkName ,  );

 float fVolume = getPreferences( MODE_PRIVATE ).getFloat( Volume , ( float ) 
 0.0);

 float fPercent = getPreferences( MODE_PRIVATE ).getFloat( Precent , ( float 
 ) 0.0); MODE_PRIVATE ).getString( DrinkName ,  );

 float fVolume = getPreferences( MODE_PRIVATE ).getFloat( Volume , ( float ) 
 0.0);

 float fPercent = getPreferences( MODE_PRIVATE ).getFloat( Precent , ( float 
 ) 0.0); float fVolume = getPreferences( MODE_PRIVATE ).getFloat( Volume , ( 
 float ) 0.0);

 float fPercent = getPreferences( MODE_PRIVATE ).getFloat( Precent , ( float 
 ) 0.0); float fPercent = getPreferences( MODE_PRIVATE ).getFloat( Precent , 
 ( float ) 0.0);

 When I retrieve the information, I always end up with the Default values.

 Does anyone have any ideas?

 Kevin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Saving image to SD Card

2009-04-17 Thread jwesonga

I changed my code to :
FileOutputStream fos = new FileOutputStream(filepath + / +
filename);

This allowed me to save the image, I loaded the device using DDMS and
noticed the image had been saved. I've tried using the
MediaScannerConnection to refresh the sd card so that I can view the
image, I need some help with that..

On Apr 17, 2:17 pm, jwesonga crazylun...@gmail.com wrote:
 I'm using Android SDK-1.0_rc2 on windows, I've emulated the sd card
 and created on my D:\ drive as sdcard1.iso. My code for saving to the
 SD card is as follows:

 try
              {
                  Log.e(filename,filename);
                  String filepath=Environment.getExternalStorageDirectory
 ().getAbsolutePath();
                  Log.e(FilePath,filepath);
                  FileOutputStream fos = openFileOutput(filepath +
 filename, MODE_APPEND);
                  BufferedOutputStream bos = new BufferedOutputStream
 (fos);
                  b.compress(CompressFormat.JPEG, 100, fos);
                  bos.flush();
                  bos.close();

              }
 When I view the Logcat I see the following error:
 java.lang.IllegalArgumentException: File /sdcardobama.jpg contains a
 path separator

 So I changed the code to:
 FileOutputStream fos = openFileOutput(filepath + / + filename,
 MODE_APPEND);

 The error is still occuring, so I tried to push the image using the
 command:

 adb push obama.jpg /sdcard/obama.jpg

 I noticed 0 bytes are being pushed, any idea where I'm going wrong?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: Saving Files

2009-01-06 Thread g1port.com

Search for SharedPreferences class.

http://code.google.com/android/reference/android/content/SharedPreferences.html

Cheers.



On Dec 31 2008, 4:53 am, Neelima neelima.neelu...@gmail.com wrote:
 Hi..

 Is it possible to store application specific data in android phone.
 Please help if anyone knows.
 Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---