[android-developers] Bluetooth (RFComm) and broken phones
I'm modifying a board game app to allow play via Bluetooth. I'm testing on a stack of devices from Samsung, Kyocera, Motorola and HTC. Consistently the HTC phone (Sensation) gets into a state where it won't accept connections (BluetoothServerSocket.accept() never returns though the logs show that ACTION_ACL_CONNECTED was received.) I'm new to BT on Android (not on Linux or PalmOS, though), so it could be my mistake, but that it works on the other devices *and* that the SDK BluetoothChat sample app also fails on the Sensation makes me suspect the phone. There are also a lot of complaints online about HTC's Bluetooth stack Assuming I can't get this to work on the Sensation, I'm going to want to find a nice way to tell owners of that phone not to bother downloading. Those of you who have some experience with Android Bluetooth: how do you play nice in a world where some of your users are going to have a really bad experience with your software? Do BT- savvy users know to stay away from certain brands or models? That the problem manifests as accept() never returning means the broken device is the last to know; I can't just put up a message suggesting you uninstall. What I'm doing so far is putting up Toasts Failed for the nth time to connect to device EricsSensation. When you have a table full of devices all pointing the finger at one of their number it's pretty clear, but most users have only one phone. What's the collective wisdom on this? Thanks! --Eric -- 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 ensure my root Activity is never duplicated?
Thanks -- but I'm not sure what you're suggesting. I don't see a startActivity(Activity,Class) in the docs. If I'm missing it or the signature's different, when are you suggesting I call it? After the OS launches a second instance of my root Activity on top of the browser? I could see this working if I could transmit the Intent that second instance is passed back to the first instance *and* if I could then force that instance to come to the front (on top of the task the browser's in that the user's interacting with). But I've tried that already -- calling into the first instance via private methods -- but am stuck on how to bring it to the front. Android doesn't want me to do that, so I keep thinking there has to be an easier way to do this, one that the APIs anticipate. Thanks, --Eric On Dec 14, 9:17 pm, damodhar meshram damodhar.meshram...@gmail.com wrote: when u call second activity from first one please finish first then call second one used following code : startactivity(this,yourclassname.class); finish(); On Thu, Dec 15, 2011 at 10:42 AM, eehouse ho...@gmail.com wrote: I'm writing a board game that follows a common pattern: main Activity is a list of games, and if you tap on one it opens into a second Activity in which the game is played. You close one game to play another. Games can also be launched over the network, which happens when the user goes to a .php page in the browser that redirects to a custom URL scheme for which one of my Activities has an intent-filter. I want to ensure three things * If user opens the app, then launches a game into an Activity on top of the list Activity, then taps the home button and launches the app again, he'll be taken back to the second Activity with the game in progress, just as it was. (This is standard behavior on Android.) * If he browses to the .php page and triggers a new game, the app will display the new game in its own Activity on top of the list Activity, first closing any other game Activity that might be open. * If this happens while the app is already running, whether in the same task as the browser or not, the new game will be launched on top of the existing game list Activity -- no new game list Activity will be created. This last one's the problem. The way things are working now, with the game list Activity's launchMode set to singleTop, if the game's already running in a different task and the user browses to the .php page that triggers new game creation, a second instance of the game list Activity is created with the new game Activity on top of it. This is fixed if I make launchMode be singleTask, but then my first goal fails: If the user hits the home button while a game is open then relaunches the app it comes back not to the existing game Activity but to a new root game list Activity. I'm beginning to work toward a solution that has the root Activity registering with a static class so that I can tell it's running (and can have it finish() if the OS insists on launching a duplicate), and the child game Activities registering with their parent so the parent can kill them if it needs to. But it's going to be pretty complex, and probably racy. It seems this scenario should have been anticipated, that there's probably a simple way to do it using launch modes and Intent flags I'm not finding. Suggestions? Thanks, --Eric -- 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 -- Thanks and Regards, Damodhar Meshram Sr Android Developer -- 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] How to ensure my root Activity is never duplicated?
I'm writing a board game that follows a common pattern: main Activity is a list of games, and if you tap on one it opens into a second Activity in which the game is played. You close one game to play another. Games can also be launched over the network, which happens when the user goes to a .php page in the browser that redirects to a custom URL scheme for which one of my Activities has an intent-filter. I want to ensure three things * If user opens the app, then launches a game into an Activity on top of the list Activity, then taps the home button and launches the app again, he'll be taken back to the second Activity with the game in progress, just as it was. (This is standard behavior on Android.) * If he browses to the .php page and triggers a new game, the app will display the new game in its own Activity on top of the list Activity, first closing any other game Activity that might be open. * If this happens while the app is already running, whether in the same task as the browser or not, the new game will be launched on top of the existing game list Activity -- no new game list Activity will be created. This last one's the problem. The way things are working now, with the game list Activity's launchMode set to singleTop, if the game's already running in a different task and the user browses to the .php page that triggers new game creation, a second instance of the game list Activity is created with the new game Activity on top of it. This is fixed if I make launchMode be singleTask, but then my first goal fails: If the user hits the home button while a game is open then relaunches the app it comes back not to the existing game Activity but to a new root game list Activity. I'm beginning to work toward a solution that has the root Activity registering with a static class so that I can tell it's running (and can have it finish() if the OS insists on launching a duplicate), and the child game Activities registering with their parent so the parent can kill them if it needs to. But it's going to be pretty complex, and probably racy. It seems this scenario should have been anticipated, that there's probably a simple way to do it using launch modes and Intent flags I'm not finding. Suggestions? Thanks, --Eric -- 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: second call to setListAdapter() ignored
On Nov 20, 11:43 pm, Kostya Vasilyev kmans...@gmail.com wrote: It seems that the only way to rebuild the fast scroll section data is to toggle fast scrolling off and on again. I tried this (in my modified version of Mark's example code.) The old data is wiped out, but now the indices/section headers are drawn in the upper-left corner rather than in the center of the list. That's on 2.2. On 3.2, the headers are drawn in the usual place -- and it is new data -- but without the frame. --Eric -- 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: second call to setListAdapter() ignored
On Nov 18, 4:15 am, Mark Murphy mmur...@commonsware.com wrote: On Thu, Nov 17, 2011 at 10:01 PM, eehouse ho...@gmail.com wrote: As far as I can tell, a second call tosetListAdapter( new MyCustomAdapter() ) has no effect: the adapter I originally installed in my ListActivity subclass's onCreate() method continues to get called. Is this a known problem/feature? No. Here is an example of an application that successfully callssetListAdapter() multiple times, based on the user choosing a Reset option menu choice: https://github.com/commonsguy/cw-android/tree/master/Menus/Inflation Thanks Mark. I took a look at your code, then modified it to duplicate the situation I described: added a custom Adapter extending BaseAdapter and implementing SectionIndexer. As you said, when I create a new instance of the Adapter and pass it into setListAdapter() the new instance is used. So the problem I described does not exist. However, the problem that led to my mistaken assumption is duplicated in your code (as I've modified it): only the first instance of my custom Adapter ever gets its getSections() method called. So though the new Adapter has replaced the original, the Object[] of sections returned by the original continues to be used. Does anybody know if there's a way to force the framework to call getSections() when a new Adapter replaces the one that was called originally? I've worked around this problem by creating a new ListActivity instance each time my data set changes. It's a bit heavy handed but does the trick. Thanks, --Eric PS I'll append my diffs below for the sake of completeness. The reset menu is what triggers new data. diff --git a/Menus/Inflation/src/com/commonsware/android/inflation/ InflationDemo.java b/Menus/Inflation/src/com/commonsware/android/ inflation/InflationDemo.java index 0e182ba..b55a84f 100644 --- a/Menus/Inflation/src/com/commonsware/android/inflation/ InflationDemo.java +++ b/Menus/Inflation/src/com/commonsware/android/inflation/ InflationDemo.java @@ -1,3 +1,5 @@ +/* -*- compile-command: cd ../../../../../; ant debug install; -*- */ + /*** Copyright (c) 2008-2011 CommonsWare, LLC @@ -24,23 +26,73 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; +import android.widget.TextView; +import android.widget.SectionIndexer; + +import android.widget.BaseAdapter; public class InflationDemo extends ListActivity { - private static final String[] items={lorem, ipsum, dolor, - sit, amet, consectetuer, adipiscing, elit, - morbi, vel, ligula, vitae, arcu, aliquet, - mollis, etiam, vel, erat, placerat, ante, - porttitor, sodales, pellentesque, augue, purus}; - private ArrayListString words=null; +private static final int NUM_WORDS = 1000; +private static final int NUM_INDICES = 10; +private int m_counter = 1; + + private class MyListAdapter extends BaseAdapter + implements SectionIndexer { + private ArrayListString m_words; + + public MyListAdapter() { + super(); + } + + public int getCount() { return NUM_WORDS; } + + public Object getItem( int position ) + { + TextView text = new TextView( InflationDemo.this ); + text.setText( String.format( %d, + position + (NUM_WORDS * m_counter) ) ); + return text; + } + + public View getView( int position, View convertView, ViewGroup parent ) { + return (View)getItem( position ); + } + + public long getItemId( int position ) { return position; } + + public int getPositionForSection( int section ) + { + return section * NUM_WORDS / NUM_INDICES; + } + + public int getSectionForPosition( int position ) + { + return position * NUM_INDICES / NUM_WORDS; + } + + public Object[] getSections() + { + String[] sections = new String[NUM_INDICES]; + for ( int ii = 0; ii NUM_INDICES; ++ii ) { + int section = (NUM_WORDS * m_counter) + + (ii * (NUM_WORDS/NUM_INDICES)); + sections[ii] = String.format( %d, section ); + } + return sections; + } + + } @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); initAdapter(); +getListView().setFastScrollEnabled( true ); registerForContextMenu(getListView()); } @@ -59,55 +111,22 @@ public class InflationDemo extends ListActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { -switch (item.getItemId()) { + switch (item.getItemId()) { case R.id.add: -add(); -return(true); + add(); + return(true); case R.id.reset: -initAdapter
[android-developers] second call to setListAdapter() ignored
As far as I can tell, a second call to setListAdapter( new MyCustomAdapter() ) has no effect: the adapter I originally installed in my ListActivity subclass's onCreate() method continues to get called. Is this a known problem/feature? MyCustomAdapter extends BaseAdapter, as I've read it must if it's going to implement the SectionIndexer interface. What I'm doing: My list activity displays a huge (up to 2.7M) list of words, and allows the user to change the subset displayed, e.g. to include only words four letters long. When a filter like that is specified, I need to force SectionIndexer.getSections() to be called again since the section indices may be different or fewer. I've tried calling notifyDataSetChanged, but it has no effect. I'm now trying to instantiate a new MyCustomAdapter and pass it to setListAdapter(). The setListAdapter() call doesn't raise any errors, but calls continue to come into the original instance of MyCustomAdapter. As far as I can tell, the second instance is ignored. Suggestions for debugging this or working around the problem? Thanks, --Eric -- 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] Uri.fromFile() returning different results on identical phones
I've tracked a crash in my app that's only reproducible on one phone (that I've seen) to a strange return from Uri.fromFile(). I have two identical T-Mobile LG G2X devices. They were purchased at the same time. Software version strings in Settings/About phone are identical. I've hard-reset both to eliminate config differences. When I run my app on one, it crashes immediately 100% of the time. Run on the other it's fine (as it is on every other device I've tested on.) The function that shows the problem looks like this, after I add logging: public static void launchGame( Activity activity, String path ) { File file = new File( path ); Utils.logf( file: %s, file.getPath() ); Uri uri = Uri.fromFile( file ); Utils.logf( Uri.fromFile=%s, uri.toString() ); [...] } On the device where there's no crash the logs look like this: D/XW4 ( 7107): [22:59:40]-1-file: Game 1.xwg D/XW4 ( 7107): [22:59:40]-1-Uri.fromFile=file:///Game%201.xwg while on the device that's about to crash I see this: D/XW4 ( 4234): [23:00:36]-1-file: Game 1.xwg D/XW4 ( 4234): [23:00:36]-1-Uri.fromFile=file:///data/data/ com.lge.providers.flex/databases/Game%201.xwg Has anybody seen this before? Is there any chance that it's other than a weird bug in the phone itself? Thanks, --Eric -- 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: Uri.fromFile() returning different results on identical phones
Thanks for the suggestion. It's provided the clue that will let me work around the problem. But for the record, calling getAbsolutePath() isn't changing the result: I still get different paths on the two (identical) devices: Code: Utils.logf( launchGame(%s), path ); File file = new File( path ); Utils.logf( file: %s, file.getAbsolutePath() ); One log: D/XW4 (25851): [09:57:35]-1-launchGame(Game 1.xwg) D/XW4 (25851): [09:57:35]-1-file: /Game 1.xwg The other log: D/XW4 ( 5102): [09:56:26]-1-launchGame(Game 1.xwg) D/XW4 ( 5102): [09:56:26]-1-file: /data/data/ com.lge.providers.flex/databases/Game 1.xwg It's the same if I use getCanonicalPath(). Thanks, --Eric On Jun 5, 5:21 am, Kostya Vasilyev kmans...@gmail.com wrote: The path you're feeding to Uri.fromFile is not absolute. Make it so (by calling file.getAbsolutePath or file.getCanonicalPath) and you should get consistent, predictable results. -- Kostya 2011/6/5 eehouse ho...@gmail.com I've tracked a crash in my app that's only reproducible on one phone (that I've seen) to a strange return from Uri.fromFile(). I have two identical T-Mobile LG G2X devices. They were purchased at the same time. Software version strings in Settings/About phone are identical. I've hard-reset both to eliminate config differences. When I run my app on one, it crashes immediately 100% of the time. Run on the other it's fine (as it is on every other device I've tested on.) The function that shows the problem looks like this, after I add logging: public static void launchGame( Activity activity, String path ) { File file = new File( path ); Utils.logf( file: %s, file.getPath() ); Uri uri = Uri.fromFile( file ); Utils.logf( Uri.fromFile=%s, uri.toString() ); [...] } On the device where there's no crash the logs look like this: D/XW4 ( 7107): [22:59:40]-1-file: Game 1.xwg D/XW4 ( 7107): [22:59:40]-1-Uri.fromFile=file:///Game%201.xwg while on the device that's about to crash I see this: D/XW4 ( 4234): [23:00:36]-1-file: Game 1.xwg D/XW4 ( 4234): [23:00:36]-1-Uri.fromFile=file:///data/data/ com.lge.providers.flex/databases/Game%201.xwg Has anybody seen this before? Is there any chance that it's other than a weird bug in the phone itself? Thanks, --Eric -- 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 -- 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] Can an app get invoked on both mime-type *and* file extension?
I'm trying to figure out how to get my app to handle browser-initiated downloads for BOTH of two scenarios. The files are identical in both cases, and have names that end in .xwd. In scenario #1 I control the http server and can send the file with a custom mime type. In scenario #2 the user gets the .xwd file from some random website. For the first, I want my app to get the file without user interaction. In the second, because .xwd has multiple meanings, the user should get a choice between my app and others that handle it. I can get each of these to work individually, but not both at the same time. I've messed around with intent-filters in my AndroidManifest.xml, and I've even gone so far as to implement two Activity subclasses, one for each scenario and each with its own intent-filter. What happens is that the mime-type filter (or class) only works if the pathPattern filter (or class) is not present. As soon as they're both there the user's always asked to pick which app should handle the download even if it's coming from my server with my custom mime type. (Which would be fine except that some users do the wrong thing, or even set the wrong thing as their default. You know how that goes) Is there any way to do this? I can provide some .xml, but the fact that it doesn't work even with two separate Activity subclasses makes me think that better .xml isn't the solution. Thanks, --Eric -- 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] Excessive JNI global references seen on 1.5 but not 2.1; my bug or Android 1.5's?
There's a bug in my network code so that when the server's not available the Android client tries over and over to connect. On 1.5 (emulator) this results, within a minute, in an Excessive JNI global references error where the leaked object is a small (20 byte) boolean array. The same code on emulated 2.1 runs for as long as my patience lasts. Is there any possibility the leak is in my code and not an Android bug that's been fixed since 1.5? Thanks, --Eric -- 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] Any way to make localized resources separate downloads?
It's looking as if my first app will be about 200K in size, English- only. Each localization adds about 12K. So far it's only available on sourceforge where it has a few hundred downloads and already volunteers have contributed three translations, so it seems possible that once it's on the android marketplace translations will nearly double its size. That seems wasteful of users' phone storage when most of them want only one language. In the PocketPC version the translations are separately downloadable .dll files -- which sucks for lots of reasons but does allow users to manage how much space the app consumes. Is there any way to mimic this behavior on Android? For example, could I have the full-sized app offer to download a one- language version of itself that would then replace the larger version? Or is there a mechanism I've missed close to what .dlls provide? Thanks, --Eric -- 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: Default Paint size too small on new device; is there a better source?
Thanks everybody. I'm using the following, inspired by the replies above, that seems to work on 1.5 as well without reflection. I define MIN_FONT_DIPS to be 14.0f. final float scale = getResources().getDisplayMetrics().density; m_defaultFontHt = (int)(MIN_FONT_DIPS * scale + 0.5f); So I can initialize a Paint() to a font size I set in a resource? That would be cool; I'll look for examples. On Jun 2, 3:31 pm, Dianne Hackborn hack...@android.com wrote: It's not a bug; you need to go through the Context/Resource to find the correct app scaling, and a plain constructor does not have this so can not take such things into account. You should define attributes like text sizes in resources, where you can use units like dp and use those values to set your size. This is essentially how TextView works, where it gets a style array of the attributes (size, color, etc) it uses to initialize its paint. On Wed, Jun 2, 2010 at 8:30 AM, String sterling.ud...@googlemail.comwrote: I think it is a bug, personally. Paint has a similar problem with measureText(); it doesn't account for different screen densities correctly. My solution is similar to Kostya's: I handle it manually using the reported density of the display. String On Jun 2, 1:38 pm, Kostya Vasilyev kmans...@gmail.com wrote: Eric, I ran into same issues with my app. First of all, small text can be made more readable by calling paint.setAntiAlias(true); Second, I do my own text scaling based on the device's screen density. Something like: textSize = unscaledSize * screenDensity / 160.0f. Note that default density for pre-1.6 devices is 160 dpi. Screen density is available as canvas.getDensity(), which first appeared in API 4 (Android 1.6). Since I want my app run on Android 1.5, I wrote a simple helper method using Java reflection that works on all versions of Android. public static int getScreenDensity(Canvas canvas) { if (gScreenDensity == 0) { gScreenDensity = 160; Class? extends Object canvasClass = canvas.getClass(); try { Method getDensityMethod = canvasClass.getMethod(getDensity); gScreenDensity = (Integer) getDensityMethod.invoke(canvas); } catch (NoSuchMethodException x) { } catch (InvocationTargetException x) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } return gScreenDensity; } static int gScreenDensity = 0; Hope this helps. 02.06.2010 16:24, eehouse пишет: My app uses a custom View that does a lot of text drawing. To ensure my text is always readable I've been using the result of calling getTextSize() on a newly-created Paint() instance as the minimum size. Docs say calling 'new Paint()' sets attributes like text size to default values. One of my European users just got a Motorola Milestone phone and reports that some text is unreadably small. I believe I've duplicated this using the WVGA854 skin in a 2.1 emulator. Run in that emulator my app's smallest TextViews look fine, but the text I'm drawing myself using Paint instances where I haven't changed the text size from the default is too small. I confirmed this by commenting out all setTextSize() calls in my View subclass: the text becomes too small to read comfortably. It feels like a bug to me that the default text size on Paint can be significantly smaller than default TextView size on some devices. Is it a known bug? In the meantime, can someone suggest a way to size Paint text so that it's readable on any device regardless of screen resolution? I believe there are APIs to translate inches to pixels, so perhaps I could hard-code a size in inches. Or I could measure the laid-out height of a TextView and store that as an invisible preference. But is there a better way, say an API I haven't found? (I suspect it'd be enough if Paint were like TextView in allowing you to specify the units in which text size is set, but it doesn't.) Thanks, --Eric -- Kostya Vasilev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com -- 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.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you
[android-developers] Default Paint size too small on new device; is there a better source?
My app uses a custom View that does a lot of text drawing. To ensure my text is always readable I've been using the result of calling getTextSize() on a newly-created Paint() instance as the minimum size. Docs say calling 'new Paint()' sets attributes like text size to default values. One of my European users just got a Motorola Milestone phone and reports that some text is unreadably small. I believe I've duplicated this using the WVGA854 skin in a 2.1 emulator. Run in that emulator my app's smallest TextViews look fine, but the text I'm drawing myself using Paint instances where I haven't changed the text size from the default is too small. I confirmed this by commenting out all setTextSize() calls in my View subclass: the text becomes too small to read comfortably. It feels like a bug to me that the default text size on Paint can be significantly smaller than default TextView size on some devices. Is it a known bug? In the meantime, can someone suggest a way to size Paint text so that it's readable on any device regardless of screen resolution? I believe there are APIs to translate inches to pixels, so perhaps I could hard-code a size in inches. Or I could measure the laid-out height of a TextView and store that as an invisible preference. But is there a better way, say an API I haven't found? (I suspect it'd be enough if Paint were like TextView in allowing you to specify the units in which text size is set, but it doesn't.) Thanks, --Eric -- 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] Can I mark a Preference in xml and detect the mark inside its containing PreferenceActivity?
I want most, but not all, of my non-CheckBox Preferences to show their current values as summaries when displayed in a PreferenceActivity. I've implemented this by overriding onSharedPreferenceChanged() in my PreferenceActivity subclass. For each SharedPreferences instance passed in, onSharedPreferenceChanged() checks if the key is in a hard-coded list and if so sets the summary from the current value of the Preference. It's a gross violation of OOP principles, but it works. What I'd rather do is somehow mark individual Preference subclasses in my xml file as desiring that behaviour. I've read how to create custom xml tags, but I can't figure out how to get at them from inside a PreferenceActivity. It seems the only access to a View's AttributeSet comes in its constructor, and I don't have access to that since I'm only overriding the Activity that contains these Views. I could accomplish the same thing by overriding every Preference subclass I use, adding nothing but an 'implements SomeEmptyInterface' statement. I'd then test inside onSharedPreferenceChanged() whether instances passed in implement that interface. But adding a simple xml attribute seems much cleaner. Is it possible? Thanks, --Eric -- 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] Can my app's main Activity be bypassed on launch?
Are there any scenarios on Android where a process can be instantiated (classes loaded, etc.) and a non-main activity launched without going through the main activity? Background: my app has a single main activity (android:name=android.intent.action.MAIN and android:name=android.intent.category.LAUNCHER), some secondary activities, and a preferences class providing static methods meant to be called from anywhere. These static methods' implementations require a Context, and so the class has a static Context member s_context; the static methods assert that s_context is non-null before using it. The very first thing I do in my main activity's onCreate() method is pass getApplicationContext() into the preferences class so it can set s_context. The main activity launches a secondary activity that calls the preference class's static methods. Sometimes -- never in an emulator, and only after my app's been running for a while and moved to the background several times -- those asserts fail. This indicates that somehow the secondary activity is running but that the main activity never ran. (Or that the preferences class was gc'd and reloaded, but java doesn't work that way AFAIK.) Is it possible that Android is launching my app directly into the secondary activity, e.g. because that's that activity that was running when it was killed? Alternatively, is there a way my main activity can be launched and its onCreate() not called? I'm just beginning to read about singleTop and other alternative launch modes. I'm not setting these at the moment... Thanks, --Eric -- 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 get ListView behavior inside a ScrollView?
The first direction worked out. All it took was to set the TextView subclass's background to the built-in background used by list items. Makes sense once you know it's a possibility. android:background=@android:drawable/list_selector_background The file and code to use it are checked into sourceforge if anybody finds that useful: http://xwords.svn.sourceforge.net/viewvc/xwords/branches/android_branch/xwords4/android/XWords4/res/layout/list_item.xml?revision=3323view=markup Thanks, --Eric On Apr 25, 9:14 am, eehouse ho...@gmail.com wrote: I'm writing the configuration activity for a game that can have a variable number of players. Players are listed in the activity and can be added and removed dynamically. Users click on players to open a player-details dialog. The natural way to display the players list is in a ListView, but the activity's layout has to be a ScrollView since it's too big to fit on a screen. Because of that -- because you can't have one scrolling element inside another -- I can't use ListView for the list of players. But I want the list of players to have all the ListView-like behaviors that users expect. Is there an accepted recipe for doing this? I've tried going in two directions, each of which might work but has a ways to go still. First, I tried using a simple LinearLayout, inserting TextViews as players are added and adding a custom divider view in between them so the whole thing looks like a ListView. This lays out correctly, including dynamically resizing as I add/delete players, but doesn't behave like a list w.r.t. details like showing focus. Second, I've tried subclassing ListView with an implementation that lays itself out tall enough that there's no scrolling. This shows focus correctly, but I can't get it to redo the layout when I add/delete players and, more strangely, OnItemClickListeners aren't firing. (I haven't exhausted options for either approach, but neither will be easy. And this seems like something that should be easy so I suspect there's a better approach.) BTW, the obvious solution to this is to use a ListView with scrolling diabled -- forced to always lay itself out full-height. Have I missed that feature in the documentation? Thanks, --Eric -- 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 athttp://groups.google.com/group/android-developers?hl=en -- 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 get ListView behavior inside a ScrollView?
That would work but wouldn't be a good user interface. There can only be from one to four players. Their names and ordering matter and should be visible on the main game config screen. There must be a way to do this right. Just a matter of figuring out how. --Eric On Apr 27, 10:14 am, TreKing treking...@gmail.com wrote: On Sun, Apr 25, 2010 at 11:14 AM, eehouse ho...@gmail.com wrote: I've tried going in two directions, each of which might work but has a ways to go still. How about option 3: don't use a listview in that same activity. Instead, provide a button or something the user can click to see the players that are currently available. That list, then, will be a listview on it's own. - TreKing - Chicago transit tracking app for Android-powered deviceshttp://sites.google.com/site/rezmobileapps/treking -- 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 athttp://groups.google.com/group/android-developers?hl=en -- 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] How to get ListView behavior inside a ScrollView?
I'm writing the configuration activity for a game that can have a variable number of players. Players are listed in the activity and can be added and removed dynamically. Users click on players to open a player-details dialog. The natural way to display the players list is in a ListView, but the activity's layout has to be a ScrollView since it's too big to fit on a screen. Because of that -- because you can't have one scrolling element inside another -- I can't use ListView for the list of players. But I want the list of players to have all the ListView-like behaviors that users expect. Is there an accepted recipe for doing this? I've tried going in two directions, each of which might work but has a ways to go still. First, I tried using a simple LinearLayout, inserting TextViews as players are added and adding a custom divider view in between them so the whole thing looks like a ListView. This lays out correctly, including dynamically resizing as I add/delete players, but doesn't behave like a list w.r.t. details like showing focus. Second, I've tried subclassing ListView with an implementation that lays itself out tall enough that there's no scrolling. This shows focus correctly, but I can't get it to redo the layout when I add/delete players and, more strangely, OnItemClickListeners aren't firing. (I haven't exhausted options for either approach, but neither will be easy. And this seems like something that should be easy so I suspect there's a better approach.) BTW, the obvious solution to this is to use a ListView with scrolling diabled -- forced to always lay itself out full-height. Have I missed that feature in the documentation? Thanks, --Eric -- 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