[android-beginners] Saving Pictures from /drawable in a app to SD Card

2010-06-24 Thread Justin
I kind of confussed and hope one of you nice people will help me.

I have written a app, and I have pictures which are stored in the /
drawable directory.  My app makes a sliding gallery across the top,
(id gallery1) and as you select the picture in the gallery it load the
picture bigger underneath, (id image1). These a layed out in a XML
file.  What I would like to do is be able to is when the image1 is
pressed it gives the option to save the picture on the SD Card.

My Whole Code is:

*
public class PicViews extends Activity
{
//---the images to display---
Integer[] imageIDs = {
R.drawable.pic01,
R.drawable.pic02,
R.drawable.pic03,
R.drawable.pic04,
R.drawable.pic05


};

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.displayview);

Gallery gallery = (Gallery) findViewById(R.id.gallery1);

gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener()
{
 public void onItemClick(AdapterView parent,
View v, int position, long id)
{
//---display the images selected---
ImageView imageView = (ImageView)
findViewById(R.id.image1);
 
imageView.setImageResource(imageIDs[position]);
}
});
}

public class ImageAdapter extends BaseAdapter
{
private Context context;
private int itemBackground;

public ImageAdapter(Context c)
{
context = c;
//---setting the style---
TypedArray a =
obtainStyledAttributes(R.styleable.Gallery1);
itemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground,
0);
a.recycle();
}

//---returns the number of images---
public int getCount() {
return imageIDs.length;
}

//---returns the ID of an item---
public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}

//---returns an ImageView view---
public View getView(int position, View convertView, ViewGroup
parent) {
ImageView imageView = new ImageView(context);
imageView.setImageResource(imageIDs[position]);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(150,
120));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
}


*

The Section of code which pulls up the image and makes the bigger
picture show is:

*
 gallery.setOnItemClickListener(new OnItemClickListener()
{
 public void onItemClick(AdapterView parent,
View v, int position, long id)
{
//---display the images selected---
ImageView imageView = (ImageView)
findViewById(R.id.image1);
 
imageView.setImageResource(imageIDs[position]);
}
});
**

Its at this point I want to be able to have a option to save the
picture either by pressing a button or ideally pressing the picture
which will bring up options.

Also what alterations in the manifest do I need to make to be able to
access the SD Card Storage?

Please help, I'm only learning.



-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

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] Saving contents of a Spinner with onSaveInstanceState

2010-06-19 Thread -DC-
I've got an app that uses a Spinner tied to an Adapter. I want to be
able to save its contents when onSaveInstanceState is called, but am
not sure which put method of the Bundle class I can use to do this?

protected void onSaveInstanceState(Bundle outState) {
//TODO: Figure out how to save mDirectories (spinner)
outState.putString(mStatus, mStatus.getText().toString());
outState.putString(mPath, mPath.getText().toString());
//outState.putSerializable(mDirectories, mDirectories); --
Spinner object
outState.putStringArray(links, links);
outState.putInt(linksPointer, linksPointer);
super.onSaveInstanceState(outState);
}

-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

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


Re: [android-beginners] Saving contents of a Spinner with onSaveInstanceState

2010-06-19 Thread Mark Murphy
On Sat, Jun 19, 2010 at 1:36 PM, -DC- diskcras...@gmail.com wrote:
 I've got an app that uses a Spinner tied to an Adapter. I want to be
 able to save its contents when onSaveInstanceState is called, but am
 not sure which put method of the Bundle class I can use to do this?

    protected void onSaveInstanceState(Bundle outState) {
        //TODO: Figure out how to save mDirectories (spinner)
        outState.putString(mStatus, mStatus.getText().toString());
        outState.putString(mPath, mPath.getText().toString());
 //        outState.putSerializable(mDirectories, mDirectories); --
 Spinner object
        outState.putStringArray(links, links);
        outState.putInt(linksPointer, linksPointer);
        super.onSaveInstanceState(outState);
    }

You do not want to put a Spinner in the onSaveInstanceState() Bundle.
Besides the fact that it is impossible, doing so would cause your new
activity to hold onto a reference to that Spinner, which holds onto a
reference to your old activity, which will cause a substantial memory
leak.

Your Spinner's contents are set via some sort of Adapter. You should
be making sure your new Activity can re-create that Adapter. Then, put
either getItemSelectedId() or getItemSelectedPosition() in the Bundle,
so you can restore the selection in the new Activity.

-- 
Mark Murphy
CommonsWare
mmur...@commonsware.com
http://commonsware.com

-- 
You received this message because you are subscribed to the Google
Groups Android Beginners group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

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] Saving calculator result problem

2009-09-28 Thread bgoody

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] Saving

2009-08-13 Thread RustedApple

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

--~--~-~--~~~---~--~~
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] saving data to text file using eclipse

2009-08-11 Thread Saeed

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] Saving a preference isn't working

2009-06-22 Thread bear123434238


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] Saving images in database

2009-06-01 Thread Mahi

Hi Everyone ,

I have a problem that I want to capture images from device camera
using my own application (not the device camera application)and want
to store these images  in own application gallery ( These images
should not also be stored in device camera application gallery)


Please anybody help me


Regards :
Mahi.

--~--~-~--~~~---~--~~
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] Saving image to SD Card

2009-04-17 Thread jwesonga

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] Saving Files

2009-01-01 Thread Neelima

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
-~--~~~~--~~--~--~---