[android-developers] Error creating file on SD card

2009-04-01 Thread BJP

I would like to write a file to the SD card from my application, but
the following code throws an IOException when debugged on a T-Mobile
G1:

String p = Environment.getExternalStorageDirectory() + "/log.txt";
File recfile = new File(p);
recfile.createNewFile();

The last line throws an IOException with detailMessage = "Cannot
create: /sdcard/log.txt".  The MOUNT_UNMOUNT_FILESYSTEMS permission is
set in the manifest.  And yes, I really do want to write to the SD
card; I don't want to use the logging features Android includes for
this particular application.  The Android documentation does not seem
to give any specifics on how one might write files to removable
storage in "Data Storage" under "Framework Topics".  What am I doing
wrong, or where can I read more about this topic?

Thanks,
Ben

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



[android-developers] Re: Error creating file on SD card

2009-04-01 Thread BJP

Thanks Mark, but I'm debugging the application on a T-Mobile G1 with
installed SD card (real hardware) ~ no emulator, just the real thing.
Is there a permission needed that I'm not recognizing?  Or, is there a
special exclusive way to deal with files on the SD card?  Any help or
pointing in the right direction would be very helpful!

Thanks,
Ben

On Apr 1, 10:36 am, Mark Murphy  wrote:
> BJP wrote:
> > I would like to write a file to the SD card from my application, but
> > the following code throws an IOException when debugged on a T-Mobile
> > G1:
>
> > String p = Environment.getExternalStorageDirectory() + "/log.txt";
> > File recfile = new File(p);
> > recfile.createNewFile();
>
> > The last line throws an IOException with detailMessage = "Cannot
> > create: /sdcard/log.txt".  The MOUNT_UNMOUNT_FILESYSTEMS permission is
> > set in the manifest.  And yes, I really do want to write to the SD
> > card; I don't want to use the logging features Android includes for
> > this particular application.  The Android documentation does not seem
> > to give any specifics on how one might write files to removable
> > storage in "Data Storage" under "Framework Topics".  What am I doing
> > wrong, or where can I read more about this topic?
>
> If you are running this on the emulator, do you have an SD card image
> set up? The emulator does not have SD card storage by default -- you
> need to use mksdcard to create an image and then tell the emulator to
> use that image via a command-line switch at startup.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Warescription: Three Android Books, Plus Updates, $35/Year
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Start Intent from onResume?

2009-09-04 Thread BJP

I have a skeleton system of Activities that will eventually be filled
with GUI elements, but for now I just want to work on a particular
aspect of the project without developing the initial GUI parts first.
But, when I try to launch an Intent from onResume, I get a
RuntimeException in ActivityThread.performResumeActivity.  What is
wrong with the following code?

public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

public void onResume() {
Intent i = new Intent(this, SecondActivity.class);
this.startActivity(i);
}

public class SecondActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
}

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



[android-developers] Re: Start Intent from onResume?

2009-09-04 Thread BJP

Aha, you are indeed correct about registration in the manifest.

Is there a reason Google wouldn't want to automatically register any
class inheriting Activity in the manifest as an Activity?

As I wrote in my original message, the Activity equivalent to Test
will eventually have GUI elements (a Button, for example) whose events
will trigger SecondActivity; for now, I want to skip that and just
develop SecondActivity.  So the behavior you describe is exactly what
I'm after (for now).

Thanks again!
--Ben

On Sep 4, 5:52 pm, "Mark Murphy"  wrote:
> > I have a skeleton system of Activities that will eventually be filled
> > with GUI elements, but for now I just want to work on a particular
> > aspect of the project without developing the initial GUI parts first.
> > But, when I try to launch an Intent from onResume, I get a
> > RuntimeException in ActivityThread.performResumeActivity.  What is
> > wrong with the following code?
>
> > public class Test extends Activity {
> >     @Override
> >     public void onCreate(Bundle savedInstanceState) {
> >         super.onCreate(savedInstanceState);
> >         setContentView(R.layout.main);
> >     }
>
> >     public void onResume() {
> >            Intent i = new Intent(this, SecondActivity.class);
> >            this.startActivity(i);
> >     }
>
> >     public class SecondActivity extends Activity {
> >         @Override
> >         public void onCreate(Bundle savedInstanceState) {
> >             super.onCreate(savedInstanceState);
> >             setContentView(R.layout.main);
> >         }
> >     }
> > }
>
> What you are doing makes no sense.
>
> When the Test activity starts up, onResume() is called. At that point, you
> start SecondActivity, so the user is presented with SecondActivity right
> away. The user back-buttons out of SecondActivity, at which point
> onResume() on Test gets called...starting up SecondActivity again.
>
> Do not call startActivity() in onResume(). Do it based on user input
> (menu, button, list item click, etc.).
>
> Beyond that, look at your stack trace to find out the source of your
> exception (use adb logcat, DDMS, or the DDMS perspective in Eclipse to get
> the Java stack trace). Perhaps SecondActivity is not registered in your
> AndroidManifest.xml file?
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com
> Android App Developer Books:http://commonsware.com/books.html
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Help in the "HelloMapView " tuto

2009-09-07 Thread BJP

powerbyte, thanks for the tip.  This instruction is included in the
blue box on the Hello, MapActivity tutorial page, but it is easily
overlooked as the blue box appears to be a tip about how to get the
Google Maps library, not how to configure the development
environment.  If Google wanted their tutorial to be clearer, they
could add Step 1.5 to include your instructions.

--Ben

On Sep 1, 10:04 pm, powerbyte  wrote:
> Set project build target to "Google API" and try.
>
> Select your project in PackageExplorer and right mouse click, select
> properties.
> Select "Android" in left pane and now "Google APIs"
>
> to Verify Open default.properties and you see last line as
>
> target=Google Inc.:Google APIs:3
>
> On Sep 1, 6:29 pm, Zonakusu  wrote:
>
> > I have similar problems with the google maps. When I try to import
> > com.google.maps.MapActivityit tells me "MapActivitycannot be
> > resolved to a type". While i _have_ included the
> > com.google.android.maps in my XML file. When I use eclipse to search
> > through the available com.* packages I can't seem to find google.maps
> > anywhere.
>
> > Can you guys help me with this problem?
>
> > Thanks in advance!
>
> > On 24 jul, 16:53, Sujay Krishna Suresh 
> > wrote:
>
> > > Can u plz explain ur prob in detail? N if possible plz post ur code 
> > > snippet
> > > so that it'd be easier to identify ur prob.
>
> > > On Fri, Jul 24, 2009 at 7:40 PM, sweet  wrote:
>
> > > > It's seems like the Internet permission doesn't work.
>
> > > --
> > > Regards,
> > > Sujay
> > > Mike Ditka   
> > > -
> > > "If God had wanted man to play soccer, he wouldn't have given us arms."- 
> > > Hide quoted text -
>
> > - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] My Tracks GPX?

2009-09-15 Thread BJP

I'm trying to use the DDMS view to simulate GPS updates on an instance
of the Android Emulator, but the GPX I generated with My Tracks isn't
being accepted for an unknown reason.

I don't get any errors when I try to load the GPX file (using the Load
GPX... button in the Emulator Control), but it doesn't populate any
locations either.  The GPX file has a  object with a 
inside that with many 's inside that, just like the
documentation specifies here:
http://developer.android.com/guide/developing/tools/ddms.html

Anyone at Google want to tell us what the actual requirements for a
GPX are in order to be parsed correctly by the DDMS?

There are similar existing, unanswered questions here:
http://groups.google.com/group/android-developers/browse_thread/thread/8eb893742129fafd/a92bd4506d9509cd

Also, why doesn't the DDMS properly parse LineString objects from KML
files?  That seems like such a simple thing to do to make development
much easier; the only difference is that LineString 
contents have 3n numbers whereas single points have 3 numbers.

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



[android-developers] DDMS GPS triggers exactly once

2009-09-16 Thread BJP

I'm having a problem where I am able to update the location in the
Android Emulator from the Eclipse DDMS exactly once per time an
activity is loaded, but no more.

I discovered the problem in my application where Activity2 (which
accesses the GPS) is started by Activity1 (which doesn't do anything
particularly interesting); when Activity2 is started, I can update the
GPS position using the Manual input in Location Controls in the DDMS
and everything works fine.  However, then I get a LogCat message
"TTFF: " where  is an apparently random number, and then the
GPS will no longer update.  However, if I click the Back button in the
emulator to return to Activity1, and then use Activity1 to restart
Activity2, I can enter a new GPS location.  But, I can't enter a
second one; tries to do so result in no apparent action.  My
application works perfectly well on a real device with a real GPS
signal.

To test things further, I closed and reopened the emulator,
immediately closed my application (from Activity1, which doesn't do
anything besides load an XML layout and attach an onClick listener to
a button), and loaded Google Maps.  I observed the same behavior here;
I could send one position that Google Maps would respond to, but any
subsequent attempts to update position fail.  When I close Google Maps
and reopen it, I am able to send exactly one more location update from
DDMS.

The distance between my subsequent location updates is usually 0.02
degrees, but I have tried it with up to 5 degrees also.  My
application does not use ACCESS_MOCK_LOCATION because I want to switch
back and forth between testing on a physical device and testing on the
emulator without having to update the manifest for each build, plus it
seems like setting a permission for my application shouldn't have
anything to do with Google Maps on the emulator.

Any ideas?  I would try loading up a GPX path, but the DDMS seems
broken there too:
http://groups.google.com/group/android-developers/browse_thread/thread/b1d0e29b704d51ab

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



[android-developers] Re: DDMS GPS triggers exactly once

2009-09-16 Thread BJP

Update: Google hasn't bothered to fix this open issue from April:
http://code.google.com/p/android/issues/detail?id=2545

The workaround may be found in Comment 38.

--Ben

On Sep 16, 12:34 am, BJP  wrote:
> I'm having a problem where I am able to update the location in the
> Android Emulator from the Eclipse DDMS exactly once per time an
> activity is loaded, but no more.
>
> I discovered the problem in my application where Activity2 (which
> accesses the GPS) is started by Activity1 (which doesn't do anything
> particularly interesting); when Activity2 is started, I can update the
> GPS position using the Manual input in Location Controls in the DDMS
> and everything works fine.  However, then I get a LogCat message
> "TTFF: " where  is an apparently random number, and then the
> GPS will no longer update.  However, if I click the Back button in the
> emulator to return to Activity1, and then use Activity1 to restart
> Activity2, I can enter a new GPS location.  But, I can't enter a
> second one; tries to do so result in no apparent action.  My
> application works perfectly well on a real device with a real GPS
> signal.
>
> To test things further, I closed and reopened the emulator,
> immediately closed my application (from Activity1, which doesn't do
> anything besides load an XML layout and attach an onClick listener to
> a button), and loaded Google Maps.  I observed the same behavior here;
> I could send one position that Google Maps would respond to, but any
> subsequent attempts to update position fail.  When I close Google Maps
> and reopen it, I am able to send exactly one more location update from
> DDMS.
>
> The distance between my subsequent location updates is usually 0.02
> degrees, but I have tried it with up to 5 degrees also.  My
> application does not use ACCESS_MOCK_LOCATION because I want to switch
> back and forth between testing on a physical device and testing on the
> emulator without having to update the manifest for each build, plus it
> seems like setting a permission for my application shouldn't have
> anything to do with Google Maps on the emulator.
>
> Any ideas?  I would try loading up a GPX path, but the DDMS seems
> broken there 
> too:http://groups.google.com/group/android-developers/browse_thread/threa...
>
> Thanks,
> Ben
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: My Tracks GPX?

2009-09-16 Thread BJP

Update: Google has not responded to this open issue from April:
http://code.google.com/p/android/issues/detail?id=2528

Furthermore, this Topograpfix sample GPX cannot be loaded either:
http://www.topografix.com/fells_loop.gpx

--Ben

On Sep 15, 8:28 pm, BJP  wrote:
> I'm trying to use the DDMS view to simulate GPS updates on an instance
> of the Android Emulator, but the GPX I generated with My Tracks isn't
> being accepted for an unknown reason.
>
> I don't get any errors when I try to load the GPX file (using the Load
> GPX... button in the Emulator Control), but it doesn't populate any
> locations either.  The GPX file has a  object with a 
> inside that with many 's inside that, just like the
> documentation specifies 
> here:http://developer.android.com/guide/developing/tools/ddms.html
>
> Anyone at Google want to tell us what the actual requirements for a
> GPX are in order to be parsed correctly by the DDMS?
>
> There are similar existing, unanswered questions 
> here:http://groups.google.com/group/android-developers/browse_thread/threa...
>
> Also, why doesn't the DDMS properly parse LineString objects from KML
> files?  That seems like such a simple thing to do to make development
> much easier; the only difference is that LineString 
> contents have 3n numbers whereas single points have 3 numbers.
>
> --Ben
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Earning a living on Android - personal experiences

2009-09-16 Thread BJP

I can testify to NitroDesk's successful commitment to customers --
very impressive response time and quality.  Thanks for the article!

--Ben

On Sep 16, 2:26 pm, NitroDesk  wrote:
> (moving to the right group) Hope this resonates with your experiences
> as well.
>
> Part 1http://nitrodesk.blogspot.com/2009/09/earning-living-on-android-part-...
>
> Part 2http://nitrodesk.blogspot.com/2009/09/earning-living-on-android-part-...
>
> regards
> -g
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: HTTP Connections?

2009-09-16 Thread BJP

To read a file from a standard internet connection protocol, just
create a new java.net.URL and access its openStream() method:

import java.io.InputStream;
import java.net.URL;

String url = "http://www.yoursite.com/filename.html";;
InputStream s = new URL(url).openStream();

...then just read it like a normal IO stream (one of the read()
methods)

How to do the search is a much more complicated, general question
probably not suitable specifically to the Android forums -- do you
have more specifics about how the search will work?

--Ben

On Sep 16, 8:22 pm, MarQuel Middleton  wrote:
> Hello im trying to make a application where you can search for
> something and download load it for example i want it to be
> connected to my website and you can type one of my ROM names and it
> will show a list view of all my ROMs or themes then i can select one
> and download it
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Parser XML return table

2009-09-16 Thread BJP

What will the XML file look like, and what will the resulting table of
strings contain?  Generally speaking, to use a SAX parser, you might
create a class that extends org.xml.sax.helpers.DefaultHandler.  Then,
you execute the parser passing an instance of your handler class --
the parser reads the file and notifies your class whenever certain
things are encountered (like, a start element like , an end
element like , character data, white space, etc).  The code to
execute the parser might look something like this if you've stored the
URL of the KML file in a string called url:

import java.io.InputStream;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

SAXParserFactory spf = SAXParserFactory.newInstance();
YourSpecialHandler yourhandler = new YourSpecialHandler();
SAXParser sp = spf.newSAXParser();
InputStream s = new URL(url).openStream();
sp.parse(s, yourhandler);
result = yourhandler.getResult();

public class YourSpecialParser extends DefaultHandler {
public void startDocument() { }
public void startElement(String uri, String localName, String
qName, Attributes attributes) { }
//etc; see documentation for DefaultHandler
}

--Ben

On Sep 16, 5:04 am, sweet  wrote:
> Hello I'm new to android dev and I'd like to make a Parser xml which
> return a table of string, i've try to find a tuto in the net but
> without success. I know i should use SAX parser but i don't understand
> his working if anybody can explain to me it will be very nice or if
> anybody know a tutorial about this.
> Thanks a lot
> Sweet
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: HTTP Connections?

2009-09-17 Thread BJP

Android is probably not the ideal language to learn how to program
generally ~ there are many other languages better suited to that.  I
personally recommend VB.NET -- it's free and easy and structured very
similar to Java, so most general knowledge acquired there will
transfer easily back to Java.  If you still want to try Android first,
it would help to describe exactly what you want your program to do.

--Ben

On Sep 16, 11:44 pm, MarQuel Middleton  wrote:
> Yea i mean this is my first actual applications and im really confused
> do i have to make a xml layout to read the open stream?
>
> On Sep 16, 11:58 pm, BJP  wrote:
>
> > To read a file from a standard internet connection protocol, just
> > create a new java.net.URL and access its openStream() method:
>
> > import java.io.InputStream;
> > import java.net.URL;
>
> > String url = "http://www.yoursite.com/filename.html";;
> > InputStream s = new URL(url).openStream();
>
> > ...then just read it like a normal IO stream (one of the read()
> > methods)
>
> > How to do the search is a much more complicated, general question
> > probably not suitable specifically to the Android forums -- do you
> > have more specifics about how the search will work?
>
> > --Ben
>
> > On Sep 16, 8:22 pm, MarQuel Middleton  wrote:
>
> > > Hello im trying to make a application where you can search for
> > > something and download load it for example i want it to be
> > > connected to my website and you can type one of my ROM names and it
> > > will show a list view of all my ROMs or themes then i can select one
> > > and download it
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Best practice for implementing watchdog

2009-09-17 Thread BJP

I'm writing an application where real-time knowledge of the GPS state
is critical to convey to the user.  I request GPS updates at 1000 ms
intervals -- when I haven't received another update 1500 ms past the
most recent update, I want to display a yellow icon, and 5000 ms after
the most recent update I want to display a red icon.  Currently, I'm
doing it like this:

private CountDownTimer gpstimeout;

public void onLocationChanged(Location location) {
if (gpstimeout != null) gpstimeout.cancel();
gpstimeout = new CountDownTimer(5000, 1500) {
public void onTick(long m) { setYellow(); }
public void onFinish() { setRed(); }
};
gpstimeout.start();
}

This works well (except that onTick appears to be called immediately
on creation of the new CountDownTimer), but it seems like creating and
destroying a new thread every second wouldn't be the best way to do
things.  Is there a better approach to this?

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



[android-developers] Re: Best practice for implementing watchdog

2009-09-18 Thread BJP

Thanks for the tip; it resulted in much more code, but I think the
demands on the system should be smaller now.  For others who might
read this, my implementation looks like this (Mark, feel free to
correct mistakes):

private Handler mGPSTimeOut;
private Runnable mGPSCallback = null;
private long mLastFix = 0;

protected void onCreate() {
mGPSTimeOut = new Handler();
}

protected void onResume() {
mGPSCallback = getGPSTimeOutHandler();
mGPSTimeOut.postDelayed(mGPSCallback, 500);
}

protected void onPause() {
if (mGPSCallback != null) mGPSTimeOut.removeCallbacks
(mGPSCallback); //Not sure if this is necessary
}

private Runnable getGPSTimeOutHandler() {
return new Runnable() {
public void run() {
if (System.currentTimeMillis() - mLastFix > 4500) {
mglvArrow.setColor(Arrow.ColorOptions.RED);
mGPSCallback = null;
} else if (System.currentTimeMillis() - mLastFix > 1300) {
mglvArrow.setColor(Arrow.ColorOptions.YELLOW);
mGPSCallback = getGPSTimeOutHandler();
mGPSTimeOut.postDelayed(mGPSCallback, 500);
}
}
};
}

public void onLocationChanged(Location location) {
mLastFix = location.getTime();
if (mGPSCallback == null) {
mGPSCallback = getGPSTimeOutHandler();
mGPSTimeOut.postDelayed(mGPSCallback, 500);
}
}

--Ben

On Sep 17, 3:08 am, Mark Murphy  wrote:
> BJP wrote:
> > I'm writing an application where real-time knowledge of the GPS state
> > is critical to convey to the user.  I request GPS updates at 1000 ms
> > intervals -- when I haven't received another update 1500 ms past the
> > most recent update, I want to display a yellow icon, and 5000 ms after
> > the most recent update I want to display a red icon.  Currently, I'm
> > doing it like this:
>
> > private CountDownTimer gpstimeout;
>
> > public void onLocationChanged(Location location) {
> >     if (gpstimeout != null) gpstimeout.cancel();
> >     gpstimeout = new CountDownTimer(5000, 1500) {
> >         public void onTick(long m) { setYellow(); }
> >         public void onFinish() { setRed(); }
> >     };
> >     gpstimeout.start();
> > }
>
> > This works well (except that onTick appears to be called immediately
> > on creation of the new CountDownTimer), but it seems like creating and
> > destroying a new thread every second wouldn't be the best way to do
> > things.  Is there a better approach to this?
>
> Here is how I would approach it, FWIW:
>
> Step #1: Have a private long data member named lastFix in your activity.
>
> Step #2: Update lastFix to be the current time in onLocationChanged().
>
> Step #3: Use postDelayed() on View to set up a periodic quasi-loop
> (i.e., the Runnable to postDelayed() calls postDelayed() to reschedule
> the same Runnable after your desired period)
>
> Step #4: The Runnable from Step #3 can then look at lastFix and update
> your UI as needed if your fix gets stale
>
> I would not go *too* tight on this quasi-loop. I have used a one-second
> loop this way with no ill effects, but I would be nervous about it
> being, say, every 100ms.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> _Android Programming Tutorials_ Version 1.0 In Print!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Start Intent from onResume?

2009-09-18 Thread BJP

@Agus: Sure, I'll probably want to register some intent filters some
time (actually, all my applications so far have been such that just
using the SpecificActivity.class Intent constructor has been
appropriate...so no intent filters), but how would automatic Activity
registration impede the creation of intent filters in the future?

@Andrew: Thanks, I'll keep AliasActivity in mind.

@Joba: That does sound like a good tool (all the features you
mentioned specifically) but I think I would be hesitant to try to
learn a new dev environment; getting all the idiosyncrasies of Android
in Eclipse was a respectable learning curve for me.  And, once
learned, it seems to be quite a good platform...currently minus
maddening difficulties with trying to load GPX files in the DDMS view:
http://groups.google.com/group/android-developers/browse_thread/thread/b1d0e29b704d51ab/6f908be1b4ee7fea

--Ben

On Sep 5, 10:50 am, Joba Chamberlain  wrote:
> > Is there a reason Google wouldn't want to automatically register any
> > class inheriting Activity in the manifest as an Activity?
>
> > As I wrote in my original message, the Activity equivalent to Test
> > will eventually have GUI elements (a Button, for example) whose events
> > will trigger SecondActivity; for now, I want to skip that and just
> > develop SecondActivity.  So the behavior you describe is exactly what
> > I'm after (for now).
>
> Have you tried using motodevstudio for Android? It is built on Eclipse
> and customized for Android. When you add a new activity it is
> automatically referenced in the Manifest. You will still have to
> specify intent-filters and whatnot, but it will prevent simple errors
> like the one above.
>
>  You can also easily on run/debug a specific activity, rather than the
> main, with motodev.
>
> Try it out. It works great for me (outside of frequent emulator issues
> - which I barely use).
>
> Paul
>
> On Sep 4, 9:05 pm, BJP  wrote:
>
> > Aha, you are indeed correct about registration in the manifest.
>
> > Is there a reason Google wouldn't want to automatically register any
> > class inheriting Activity in the manifest as an Activity?
>
> > As I wrote in my original message, the Activity equivalent to Test
> > will eventually have GUI elements (a Button, for example) whose events
> > will trigger SecondActivity; for now, I want to skip that and just
> > develop SecondActivity.  So the behavior you describe is exactly what
> > I'm after (for now).
>
> > Thanks again!
> > --Ben
>
> > On Sep 4, 5:52 pm, "Mark Murphy"  wrote:
>
> > > > I have a skeleton system of Activities that will eventually be filled
> > > > with GUI elements, but for now I just want to work on a particular
> > > > aspect of the project without developing the initial GUI parts first.
> > > > But, when I try to launch an Intent from onResume, I get a
> > > > RuntimeException in ActivityThread.performResumeActivity.  What is
> > > > wrong with the following code?
>
> > > > public class Test extends Activity {
> > > >     @Override
> > > >     public void onCreate(Bundle savedInstanceState) {
> > > >         super.onCreate(savedInstanceState);
> > > >         setContentView(R.layout.main);
> > > >     }
>
> > > >     public void onResume() {
> > > >            Intent i = new Intent(this, SecondActivity.class);
> > > >            this.startActivity(i);
> > > >     }
>
> > > >     public class SecondActivity extends Activity {
> > > >         @Override
> > > >         public void onCreate(Bundle savedInstanceState) {
> > > >             super.onCreate(savedInstanceState);
> > > >             setContentView(R.layout.main);
> > > >         }
> > > >     }
> > > > }
>
> > > What you are doing makes no sense.
>
> > > When the Test activity starts up, onResume() is called. At that point, you
> > > start SecondActivity, so the user is presented with SecondActivity right
> > > away. The user back-buttons out of SecondActivity, at which point
> > > onResume() on Test gets called...starting up SecondActivity again.
>
> > > Do not call startActivity() in onResume(). Do it based on user input
> > > (menu, button, list item click, etc.).
>
> > > Beyond that, look at your stack trace to find out the source of your
> > > exception (use adb logcat, DDMS, or the DDMS perspective in Eclipse to get
> > > the Java stack trace). Perhaps SecondActivity is not registered in your
> > > AndroidManifest.xml file?
>
> > > --
> > > Mark Murphy (a Commons Guy)http://commonsware.com
> > > Android App Developer Books:http://commonsware.com/books.html
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: How to make a button/drawable remain clicked

2009-09-18 Thread BJP

For whatever reason, this is a pet peeve of some of the core Android
development team.  There have been a number of posts where developers
have requested the ability to programmatically highlight objects as if
the track ball was used to select them but the answer is that this is
impossible in "touch mode" which is entered whenever the user touches
the screen.  The core Android developers claim that highlighting
objects programmatically will present a confusing user experience, so
they're not going to let developers do it.  As far as I know, your
only alternative is to make your own View that behaves like you want
it to, but that will be frowned upon:
http://groups.google.com/group/android-developers/browse_thread/thread/70535c9e36337aab

--Ben

On Sep 17, 12:05 pm, k_pip_k  wrote:
> Hello all,
>
> I have a GridView with a BaseAdapter that cycles through the elements
> making views for each element or cell in the grid.
>
> What I would like to do is create a clickable image/button, and when
> the user clicks or touches it, for it to remain clicked and
> highlighted so that they make click on several if they so choose.
>
> I have tried, ImageButtons, Buttons, ImageViews, LayerDrawables(with a
> swapable background color drawable), ToggleButtons, CheckBoxes,
> derived my own CompoundButton, but nothing seems to work.
>
> I was a teeny bit successful with a ImageButton where I could create
> it selected, but if the user clicked on it, I couldn't get that visual
> state back.
>
> Any help is appreciated.  I can post code if you like.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] SoundPool play() fails with no indication

2011-02-27 Thread BJP
I'm having a problem where SoundPool crashes, but gives no
programmatic indication that is has crashed.  After it crashes, it
will not play any more sounds until the application is reloaded
(exiting via back button then restarting is not sufficient).  LogCat
gives me these error messages:

AudioFlinger: no more track names availlable [sic]
AudioTrack: AudioFlinger could not create track, status: -12
SoundPool: Error creating AudioTrack

Yet, despite these errors, SoundPool.play() still returns a positive
integer that increments for each new play request which, according to
the documentation, indicates that there was not an error.  Someone
else started an Issue for this problem:
http://code.google.com/p/android/issues/detail?id=13453

...however, there have been no responses.  The code below is a
minimalist Activity to consistently recreate this issue.  Just create
a new Android project, set the ID of the LinearLayout to main_bg, set
the ID of the TextView to main_tv, and add a sound file named ding to
res/raw.  The sound file needs to be long enough to click on the
screen four times before the first sound completes; mine is a 1.7-
second 22050 Hz mono MP3 @ 96kbps.  After a brief pause, the fifth
click will generate the error messages above via LogCat.  Or, you can
just click a bunch of times until sounds stop playing.

I have tested the error messages to occur on a T-Mobile G1 running
Android 1.6 and a DroidX running Android 2.2, but they do not occur on
a 1.6 emulator, a 2.1 emulator, or a 2.2 emulator.

Does anyone know how to fix this problem, or is SoundPool just
worthless for coincident sound effects?

public class SoundTestActivity extends Activity implements
OnClickListener {
   private  SoundPool mSoundPool;
   private  HashMap mSoundPoolMap;
   private  int index = 0;

   @Override
   public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
 
findViewById(R.id.main_bg).setOnClickListener((OnClickListener)this);

  initSounds();
  mSoundPoolMap.put(index,
mSoundPool.load(getApplicationContext(), R.raw.ding, 1));
   }

   public void initSounds() {
  mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
  mSoundPoolMap = new HashMap();
   }

   @Override
   public void onClick(View v) {
  int result = mSoundPool.play(mSoundPoolMap.get(index), 0.99f,
0.99f, 1, 0, 1f);
 
((TextView)findViewById(R.id.main_tv)).setText(Integer.toString(result));
   }
}

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


[android-developers] Re: SoundPool play() fails with no indication

2011-03-01 Thread BJP
Bump.  Is SoundPool just broken?

On Feb 27, 11:30 pm, BJP  wrote:
> I'm having a problem where SoundPool crashes, but gives no
> programmatic indication that is has crashed.  After it crashes, it
> will not play any more sounds until the application is reloaded
> (exiting via back button then restarting is not sufficient).  LogCat
> gives me these error messages:
>
> AudioFlinger: no more track names availlable [sic]
> AudioTrack: AudioFlinger could not create track, status: -12
> SoundPool: Error creating AudioTrack
>
> Yet, despite these errors, SoundPool.play() still returns a positive
> integer that increments for each new play request which, according to
> the documentation, indicates that there was not an error.  Someone
> else started an Issue for this 
> problem:http://code.google.com/p/android/issues/detail?id=13453
>
> ...however, there have been no responses.  The code below is a
> minimalist Activity to consistently recreate this issue.  Just create
> a new Android project, set the ID of the LinearLayout to main_bg, set
> the ID of the TextView to main_tv, and add a sound file named ding to
> res/raw.  The sound file needs to be long enough to click on the
> screen four times before the first sound completes; mine is a 1.7-
> second 22050 Hz mono MP3 @ 96kbps.  After a brief pause, the fifth
> click will generate the error messages above via LogCat.  Or, you can
> just click a bunch of times until sounds stop playing.
>
> I have tested the error messages to occur on a T-Mobile G1 running
> Android 1.6 and a DroidX running Android 2.2, but they do not occur on
> a 1.6 emulator, a 2.1 emulator, or a 2.2 emulator.
>
> Does anyone know how to fix this problem, or is SoundPool just
> worthless for coincident sound effects?
>
> public class SoundTestActivity extends Activity implements
> OnClickListener {
>    private  SoundPool mSoundPool;
>    private  HashMap mSoundPoolMap;
>    private  int index = 0;
>
>    @Override
>    public void onCreate(Bundle savedInstanceState) {
>       super.onCreate(savedInstanceState);
>       setContentView(R.layout.main);
>
> findViewById(R.id.main_bg).setOnClickListener((OnClickListener)this);
>
>       initSounds();
>       mSoundPoolMap.put(index,
> mSoundPool.load(getApplicationContext(), R.raw.ding, 1));
>    }
>
>    public void initSounds() {
>       mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
>       mSoundPoolMap = new HashMap();
>    }
>
>    @Override
>    public void onClick(View v) {
>       int result = mSoundPool.play(mSoundPoolMap.get(index), 0.99f,
> 0.99f, 1, 0, 1f);
>
> ((TextView)findViewById(R.id.main_tv)).setText(Integer.toString(result));
>    }
>
> }

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