Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Ulysses S. Grant posted:

Nothing wrong with just calling rawQuery on a SQLiteDatabase object until you start to have more complex queries. The CommonsWare library is ace for asynchronous SQLite queries, but you may not actually need it.
Oh yeah, making the queries and processing the returned results isn't the issue. I was just looking for a simple way to do all of the queries in a separate thread so I don't freeze the app's UI thread. I'll try and do everything in the main thread for now - with luck I'll be able to get away with it.

Adbot
ADBOT LOVES YOU

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Oh yeah, making the queries and processing the returned results isn't the issue. I was just looking for a simple way to do all of the queries in a separate thread so I don't freeze the app's UI thread. I'll try and do everything in the main thread for now - with luck I'll be able to get away with it.

Use the commonsware library. It's only slightly overkill, not massive overkill like providers.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
Someone finally explained CursorLoader to me in a way I could understand. I promptly realized that I never "got" them because I'd been trying to cram a square peg into a round hole.

I'm creating a database app and need to be able to query the database with whatever word the user is looking up. My understanding of how CursorLoader works is that you need one for each query you want to make, and that each query is set in stone the moment you set up the loader. I switch between three possible queries based on whatever word is entered in the search box, so I need to be able to cycle through them freely. My end goal is simply to move the querying into a separate thread to keep the UI responsive. Is that possible?

Doctor w-rw-rw- posted:

Use the commonsware library. It's only slightly overkill, not massive overkill like providers.
I tried using LoaderEx but it has the same limitations above as regular CursorLoader.

In addition to all that, while trying to diagnose some skipped frames, I turned on STRICT MODE and was presented with some errors like this telling me about my improper cursor usage:

quote:

03-01 14:14:49.403: E/StrictMode(18678): Finalizing a Cursor that has not been deactivated or closed.

If I set a cursor to close after I finish setting it to a ListView, the app crashes with the following error:

quote:

03-01 14:33:11.833: E/AndroidRuntime(19099): java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteQuery: <query here>

I was trying to address this issue with CursorLoaders but obviously that failed so now I'm double stuck. Where the hell do I go from here? I spent most of the day trying to figure these two problems out and now I'm feeling way overwhelmed by all of this :sigh:

zeekner
Jul 14, 2007

Karthe posted:

Someone finally explained CursorLoader to me in a way I could understand. I promptly realized that I never "got" them because I'd been trying to cram a square peg into a round hole.

I'm creating a database app and need to be able to query the database with whatever word the user is looking up. My understanding of how CursorLoader works is that you need one for each query you want to make, and that each query is set in stone the moment you set up the loader. I switch between three possible queries based on whatever word is entered in the search box, so I need to be able to cycle through them freely. My end goal is simply to move the querying into a separate thread to keep the UI responsive. Is that possible?

I tried using LoaderEx but it has the same limitations above as regular CursorLoader.

In addition to all that, while trying to diagnose some skipped frames, I turned on STRICT MODE and was presented with some errors like this telling me about my improper cursor usage:
An easy way to change query arguments with CursorLoaders is to just call restartLoader, and it'll call the onCreateLoader method again where you can return a new CursorLoader with the new query.

Karthe posted:

If I set a cursor to close after I finish setting it to a ListView, the app crashes with the following error:

I was trying to address this issue with CursorLoaders but obviously that failed so now I'm double stuck. Where the hell do I go from here? I spent most of the day trying to figure these two problems out and now I'm feeling way overwhelmed by all of this :sigh:
You need to close the cursor when you are completely finished with it. It's still in use as long as the listadapter has control over it. If you are manually managing the cursor, you just need to close the cursor at the opposite point in the lifecycle from where you created it. CursorLoaders simplify this a lot, since you can just call destroyLoader in onDestroy, then put adapter.swapCursor(null) in the onLoaderReset callback.

It's critical that you remove the cursor from the adapter before you close it.

Doctor w-rw-rw-
Jun 24, 2008
The swapCursor(null) advice is correct to my recollection, but are you sure you're supposed to close it?

http://stackoverflow.com/questions/8864813/if-and-when-to-close-the-database-when-using-commonsware-loaderex-sqlitecursorlo?rq=1

zeekner
Jul 14, 2007

Sorry, I should have been more specific. I was saying he should only close it if he was managing the cursor himself (no loaders, ect).

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Salvador Dalvik posted:

An easy way to change query arguments with CursorLoaders is to just call restartLoader, and it'll call the onCreateLoader method again where you can return a new CursorLoader with the new query.
I had no idea I could do that. I imagine I could just pass in the new query as a String within the expected Bundle. If restartLoader calls onCreateLoader again, should I set up onCreateLoader to grab the query out of the Bundle, or do it in restartLoader? This is assuming that restartLoader knows to pass the Bundle to onCreateLoader. And it looks as though, so long as I keep the loader ID the same, I could reuse the loader as many times as I want and it will always update the listView I've pointed it at - is that right?

Fluue
Jan 2, 2008
I'm building a simple app that queries my site, gets the json response, then displays data in a view. I'm having trouble grasping how to pass data to a view, though. I'll be taking several fields from each response, and I assume I need to use a listview.

Does anyone have a guide that helped you understand passing data to views?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Fluue posted:

I'm building a simple app that queries my site, gets the json response, then displays data in a view. I'm having trouble grasping how to pass data to a view, though. I'll be taking several fields from each response, and I assume I need to use a listview.

Does anyone have a guide that helped you understand passing data to views?

What kind of data are you displaying? Listviews are meant for lists, and you'll want an adapter to use them properly. Is it sufficient to just have a plain old TextView? If so, then it's as simple as calling setText.

Fluue
Jan 2, 2008

Volmarias posted:

What kind of data are you displaying? Listviews are meant for lists, and you'll want an adapter to use them properly. Is it sufficient to just have a plain old TextView? If so, then it's as simple as calling setText.

I'm making an app "clone" of my website http://randompokemongenerator.com

I'm assuming ListView is best because I'm looping rows (up to 6 max). I have a JSON response page setup that I'll use to take url GET values in the app based on user selections (same as on the website).

kitten smoothie
Dec 29, 2001

Trying to get some numbers together to do my taxes. I love how the payout & sales reports in the Google Play publisher console totally do not agree in any way with the payout and sales reports in the Google Checkout console.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
How can I solve this issue I'm having with transitioning an app from one-column mode to two-column mode on rotation? When I'm holding my device in portrait mode, my app brings up Fragment B with additional entry information when I tap on a listView item in Fragment A:

pre:
-----                -----
|   |                |   |
| A |   -> tap ->    | B |
|   |                |   |
-----                -----
I want my app to transition into two-column mode when I rotate the device 90 degrees while preserving the contents of Fragment A and Fragment B:

pre:
---------
| A | B |
---------
Right now, so long as Fragment B isn't visible in portrait mode, I can rotate the device and the contents of Fragment A will be preserved. However, if I rotate from portrait into landscape while Fragment B is displayed, I get the following error:
pre:
03-06 11:01:54.953: E/AndroidRuntime(2947): FATAL EXCEPTION: main
03-06 11:01:54.953: E/AndroidRuntime(2947): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.dict/com.test.dict.ActivityStartScreen}: 
				android.view.InflateException: Binary XML file line #10: Error inflating class fragment
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3692)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.ActivityThread.access$700(ActivityThread.java:141)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1240)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.os.Looper.loop(Looper.java:137)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.ActivityThread.main(ActivityThread.java:5041)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at java.lang.reflect.Method.invokeNative(Native Method)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at java.lang.reflect.Method.invoke(Method.java:511)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at dalvik.system.NativeStart.main(Native Method)
03-06 11:01:54.953: E/AndroidRuntime(2947): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.Activity.setContentView(Activity.java:1881)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at com.test.dict.ActivityStartScreen.onCreate(ActivityStartScreen.java:21)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.Activity.performCreate(Activity.java:5104)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	... 12 more
03-06 11:01:54.953: E/AndroidRuntime(2947): Caused by: java.lang.IllegalStateException: Fragment com.test.dict.FragmentSearch did not create a view.
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.app.Activity.onCreateView(Activity.java:4740)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-06 11:01:54.953: E/AndroidRuntime(2947): 	... 22 more
Is this something a fragment transaction could solve? I use it right now to bring up Fragment B in one-column mode, but as I write out this post I'm starting to think that I should dynamically load up fragments with FragmentTransactions in lieu of setting up my fragments statically in the activity's layout file...

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Is this something a fragment transaction could solve? I use it right now to bring up Fragment B in one-column mode, but as I write out this post I'm starting to think that I should dynamically load up fragments with FragmentTransactions in lieu of setting up my fragments statically in the activity's layout file...

Yeah, pretty much. Load them up in FragmentTransactions. Also, remember that fragment state on the backstack is thrown away completely on configuration changes (such as orientation), though the backstack isn't destroyed. Just the state.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Doctor w-rw-rw- posted:

Yeah, pretty much. Load them up in FragmentTransactions. Also, remember that fragment state on the backstack is thrown away completely on configuration changes (such as orientation), though the backstack isn't destroyed. Just the state.
So you're saying that fragments are restarted from scratch on things like orientation change? I tinkered around with FragmentTransactions in a test app and observed that changes I made to a fragment were cleared on rotation, so I think I'm understanding you correctly. If a fragment's state is tossed out on rotation and I'm not using something like a loader to automatically repopulate the fragment with information, how can I restore its contents? Do I need to pass a bundle to the parent Activity during the fragment's onDestroyView, and then pass the bundle back to the fragment after fragmentTransaction.commit()?

And everything I've read about fragmentTransaction.add()/replace()/etc... says to attach it to a ViewGroup in the activity's layout XML file. I've been getting along fine with this activity XML file in my test app:
XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:id="@+id/FragmentContainer">

</LinearLayout>
During add() or replace() I just point it to R.id.FragmentContainer. I want to set up a two-column layout dynamically, but I can't figure out what I'm supposed to add to the layout to make that possible. Just add two more LinearLayouts within the existing one and assign them ID's?

Doctor w-rw-rw-
Jun 24, 2008
It's been a while so the stuff is fading from memory. I do remember a few things:
  • LinearLayout is a ViewGroup. ViewGroup is abstract. I think you're OK.
  • Look at https://github.com/jfeinstein10/SlidingMenu <--the example there i think shows a decent way to show a double-column layout on tablets.
  • Fragments let you save and restore their state from bundles. I'm hazy on this since I haven't touched android in a couple of months.
  • Don't nest fragments.

Glimm
Jul 27, 2005

Time is only gonna pass you by

Doctor w-rw-rw- posted:

  • Fragments let you save and restore their state from bundles. I'm hazy on this since I haven't touched android in a couple of months.
I think you want to use onSaveInstanceState, then you can rely on that Bundle in onActivityCreated to setup the Fragment state.

quote:

  • Don't nest fragments.

Actually, this should be okay now:
http://developer.android.com/about/versions/android-4.2.html#NestedFragments

As far as I know nested Fragment support works in the support library as well.

It looks like the person who made this StackOverflow post was having a similar issue and solved it:
http://stackoverflow.com/questions/7707032/illegalstateexception-when-replacing-a-fragment

Glimm fucked around with this message at 03:29 on Mar 9, 2013

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
What's the best way to close a foreground activity and pass info back to the parent activity after rotating the screen? My app displays two columns in landscape mode and one column in portrait mode. When the device is in portrait mode, tapping on a listView item in Activity A starts up Activity B and displays additional information about that entry.

I ultimately want to pass Activity B's current entry ID back to Activity A when the device is rotated into landscape mode while Activity B is active. Right now I've got the following set up in Activity B's onStop():

Java code:
@Override
protected void onStop()
{
    super.onStop();
    Log.i("ActivityEntryDetails", "onStop - " + entryID);
    Intent i = new Intent(this, ActivityStartScreen.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.putExtra("entryID", entryID);
    startActivity(i);
    finish();
}
While this does what I want, I feel as though I'm doing something wrong; after rotating into landscape mode a copy of Activity A disappears into the background over top of the actual Activity A using the same animation as though I'd tapped the Back button to go to the previous activity (that's a lovely description of the issue but it's hard to put into words). What's a better way to do this?

Glimm
Jul 27, 2005

Time is only gonna pass you by

Karthe posted:

What's the best way to close a foreground activity and pass info back to the parent activity after rotating the screen? My app displays two columns in landscape mode and one column in portrait mode. When the device is in portrait mode, tapping on a listView item in Activity A starts up Activity B and displays additional information about that entry.

Maybe use one Activity with a landscape orientation containing two Fragment containers and a portrait orientation with only one, and just maintain state within the single Activity?

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Glimm posted:

Maybe use one Activity with a landscape orientation containing two Fragment containers and a portrait orientation with only one, and just maintain state within the single Activity?
I tried using FragmentTransaction's earlier to do the whole two-column-landscape/one-column-portrait but it got real messy, or at least was beyond my ability.

Here's a video of the strange activity I'm seeing with my current code:
https://www.youtube.com/watch?v=yhKeoNMPV-8

Glimm
Jul 27, 2005

Time is only gonna pass you by

Karthe posted:

I tried using FragmentTransaction's earlier to do the whole two-column-landscape/one-column-portrait but it got real messy, or at least was beyond my ability.

Here's a video of the strange activity I'm seeing with my current code:
https://www.youtube.com/watch?v=yhKeoNMPV-8

Maybe check out the Master Detail View sample that comes with the SDK? Create a new project within Eclipse (target SDK 11+) and select the Master Detail View template and try to match what you're doing with the sample.

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

What's the best way to close a foreground activity and pass info back to the parent activity after rotating the screen? My app displays two columns in landscape mode and one column in portrait mode. When the device is in portrait mode, tapping on a listView item in Activity A starts up Activity B and displays additional information about that entry.

I ultimately want to pass Activity B's current entry ID back to Activity A when the device is rotated into landscape mode while Activity B is active. Right now I've got the following set up in Activity B's onStop():

Java code:
@Override
protected void onStop()
{
    super.onStop();
    Log.i("ActivityEntryDetails", "onStop - " + entryID);
    Intent i = new Intent(this, ActivityStartScreen.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.putExtra("entryID", entryID);
    startActivity(i);
    finish();
}
While this does what I want, I feel as though I'm doing something wrong; after rotating into landscape mode a copy of Activity A disappears into the background over top of the actual Activity A using the same animation as though I'd tapped the Back button to go to the previous activity (that's a lovely description of the issue but it's hard to put into words). What's a better way to do this?

Use startActivityForResult/onActivityResult.
stuff your data into an intent. Parcelable is better than Serializable when possible (Serializable uses reflection, and is slow; Parcelable requires you to implement a builder/parceler

Protip: rather than calling startActivity or startActivityForResult, I usually make a class method that resembles: static void start(Activity activity, String arg1, SomeObject arg2) - or startForResult to indicate that it returns a result. It's much easier to find where an activity is launched from when all you have to do is find where a function is called from.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Doctor w-rw-rw- posted:

Use startActivityForResult/onActivityResult.
stuff your data into an intent. Parcelable is better than Serializable when possible (Serializable uses reflection, and is slow; Parcelable requires you to implement a builder/parceler
startActivityForResult worked out well except for one thing. In landscape mode, Activity A looks like this:


When you rotate to portrait, Activity A only shows the listView. Tapping one of those entries pulls up Activity B with additional information:


When I rotate to landscape while Activity B is in the foreground, it displays nothing, probably because I've called finishActivity() in its onCreate intending to dismiss this activity and return to Activity A. Unfortunately Activity B sticks around until I hit the back button:


How can I get Activity B to disappear automatically instead of sticking around as in that last picture? I thought finishActivity() would do that, but apparently it does everything BUT dismiss the activity.

Doctor w-rw-rw-
Jun 24, 2008
Don't do activity life cycle stuff in onCreate IMO. I don't really understand what you want to do. You want orientation changes to back out of an activity? If that happened to me I would consider it a bug. What if someone is in a bumpy train ride and the orientation changes? What if you later decide to launch that activity from some other place where it doesn't make sense to close it?

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Doctor w-rw-rw- posted:

Don't do activity life cycle stuff in onCreate IMO. I don't really understand what you want to do. You want orientation changes to back out of an activity? If that happened to me I would consider it a bug. What if someone is in a bumpy train ride and the orientation changes? What if you later decide to launch that activity from some other place where it doesn't make sense to close it?
I'm simply trying to design an app that gracefully switches between a one-column layout and a two-column layout depending on orientation of the device. The reason I'm going for something this fancy is because a two-column layout in portrait mode on a Nexus 7 (the only physical device I have to test on) suffers from columns that are a bit too small to appreciably display listView items. Based on all the trouble I've had thus far, though, I think I'll abandon this for now and just make a two-column layout for sw600dp+ tablets, and use a one-column for everything smaller than that.

NoDamage
Dec 2, 2000

Karthe posted:

I'm simply trying to design an app that gracefully switches between a one-column layout and a two-column layout depending on orientation of the device. The reason I'm going for something this fancy is because a two-column layout in portrait mode on a Nexus 7 (the only physical device I have to test on) suffers from columns that are a bit too small to appreciably display listView items. Based on all the trouble I've had thus far, though, I think I'll abandon this for now and just make a two-column layout for sw600dp+ tablets, and use a one-column for everything smaller than that.
You should almost certainly use fragments for this. I've done the exact same thing for the Nexus 7 (2 columns in landscape, 1 column in portrait), it's not too hard if you're using fragments for each column. Use layout aliases to specify which layout to use depending on the width of your screen.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

NoDamage posted:

You should almost certainly use fragments for this. I've done the exact same thing for the Nexus 7 (2 columns in landscape, 1 column in portrait), it's not too hard if you're using fragments for each column. Use layout aliases to specify which layout to use depending on the width of your screen.

That's the thing, I've been using fragments since the beginning. What I haven't been able to do is figure out how to make those fragments work in a way that gives me that flexible of a layout. I kept having issues loading information into a fragment in portrait single-column mode and then reloading the information in that fragment when it gets reloaded in a landscape layout that contains it.

I've given up on that for now and just made the two-column layout the default layout for all tablets, including the Nexus 7.

admiraldennis
Jul 22, 2003

I am the stone that builder refused
I am the visual
The inspiration
That made lady sing the blues
Is there some kind of updated go-to guide to dealing with assets for Android? Things like resolution, etc.

Very recently I've somehow become lead developer on an in-progress barely-beta Android app that is targeting -8 and above, all smartphone screen sizes (but bigger/newer phones are priority), horizontal and vertical. And I'm going crazy working with our designer and trying to figure out how to handle resources and screen sizes. I want to be able to tell him "give me x, y and z, designed for these resolutions, proportioned for these sizes" but I don't even know what to ask for when it comes to deliverables, or the best way to manage it on my end.

The designs are very graphics heavy, and kind of iOS-like.

zeekner
Jul 14, 2007

admiraldennis posted:

Is there some kind of updated go-to guide to dealing with assets for Android? Things like resolution, etc.

Very recently I've somehow become lead developer on an in-progress barely-beta Android app that is targeting -8 and above, all smartphone screen sizes (but bigger/newer phones are priority), horizontal and vertical. And I'm going crazy working with our designer and trying to figure out how to handle resources and screen sizes. I want to be able to tell him "give me x, y and z, designed for these resolutions, proportioned for these sizes" but I don't even know what to ask for when it comes to deliverables, or the best way to manage it on my end.

The designs are very graphics heavy, and kind of iOS-like.

Get to know 9-patch really well. They are a major timesaver, and it's pretty easy to convert existing PNG files to 9patch. Ignore Google's 9patch utility, just use Paint.net or something to resize for one extra pixel border, then save the file with .9.png.

Since you are in control of asset creation, you can have the designer target all three major DPI levels (MDPI/HDPI/XDPI). The other DPI levels aren't really worth targeting, MDPI can scale down to LDPI without issue and I don't think the 480dpi level (XXHDPI) will matter for a long time. I haven't even been able to find a XXHDPI phone to see the difference.

Honestly, in a pinch you can usually get away with targeting XHDPI and let the scaling handle it, but that can leave noticeable artifacts for XHDPI->HDPI. If you need a quick and dirty iOS to Android port, converting @2x resources is pretty handy. Just make sure to convert stretchable resources (buttons, backgrounds, ect) to 9patch.

jkyuusai
Jun 26, 2008

homegrown man milk
FYI, someone has the latest release of AQuery set up in Maven Central now and is offering to help keep it current. (Maven is wacky, but we use it at work, so....)

Just set it up in my current project - works like a charm! Now to clean up all these loving calls to findViewById :suicide:

Glimm
Jul 27, 2005

Time is only gonna pass you by

Has ActiveAndroid come up before? Can I gush over this library for a bit?

https://github.com/pardom/ActiveAndroid

ActiveAndroid posted:

ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to save and retrieve SQLite database records without ever writing a single SQL statement. Each database record is wrapped neatly into a class with methods like save() and delete().

ActiveAndroid does so much more than this though. Accessing the database is a hassle, to say the least, in Android. ActiveAndroid takes care of all the setup and messy stuff, and all with just a few simple steps of configuration.

Examples pulled from the GitHub page:

Create some model classes

code:
@Table(name = "Categories")
public class Category extends Model { 
	@Column(name = "Name")
	public String name;
}

@Table(name = "Items")
public class Item extends Model {
	@Column(name = "Name")
	public String name;
 
	@Column(name = "Category")
	public Category category;
}
Query the db
code:
public static List<Item> getAll(Context context, Category category) {
	return new Select()
		.from(Item.class)
		.where("Category = ?", category.getId())
		.orderBy("Name ASC")
		.execute();
}
It also has a ContentProvider built in!
https://github.com/pardom/ActiveAndroid/blob/master/src/com/activeandroid/content/ContentProvider.java

Haven't used it much, just set it up today for a new project. But so far, so good.

Glimm fucked around with this message at 14:59 on Mar 23, 2013

Glimm
Jul 27, 2005

Time is only gonna pass you by

Anyone else looking for a mobile focused dev conference to goto? I didn't win the I/O lottery so I've been looking at a few options.

AnDevCon Boston (28-31st May) looks fairly promising, kind of pricey at $1395 a ticket.

Droidcon London (24-27th October 2013) seems awesome. Much cheaper (£100 ~ $152 USD). The ticket+flight will actually be cheaper for me if I go this route, and hey - it's in London!

I'm not really sure what to expect out of training sessions/classes/talks as I haven't been to either conference or any major dev conference. Anyone checked these out before?

kitten smoothie
Dec 29, 2001

Glimm posted:

AnDevCon Boston (28-31st May) looks fairly promising, kind of pricey at $1395 a ticket.
Yeah, my 3-year-long streak of I/O attendance has been broken this year.

This AnDevCon looks like it could be pretty good, at least considering Jake Wharton and Mark from Commonsware are on the speakers list. I might have to consider this one.

Murodese
Mar 6, 2007

Think you've got what it takes?
We're looking for fine Men & Women to help Protect the Australian Way of Life.

Become part of the Legend. Defence Jobs.

Glimm posted:

Has ActiveAndroid come up before? Can I gush over this library for a bit?

Haven't used it much, just set it up today for a new project. But so far, so good.

I bought a copy a few years ago when I started doing Android dev, and it worked pretty well. Had a few minor bugs here and there (which I'm sure they've fixed long since).

Glimm
Jul 27, 2005

Time is only gonna pass you by

Murodese posted:

I bought a copy a few years ago when I started doing Android dev, and it worked pretty well. Had a few minor bugs here and there (which I'm sure they've fixed long since).

Are we talking about the same library?

https://github.com/pardom/ActiveAndroid

This is released under the Apache license and appears to have only been under development for 4 months or so.

Murodese
Mar 6, 2007

Think you've got what it takes?
We're looking for fine Men & Women to help Protect the Australian Way of Life.

Become part of the Legend. Defence Jobs.
Same library, he's obviously made it free. It was originally a paid library (maybe $10?).

Small White Dragon
Nov 23, 2007

No relation.
Hey Android peeps.

I'm unclear on this.

When I'm working with, say, a Canvas, are there any device-independent pixel density (like iOS does for retina displays) or is everything in actual pixels?

Slanderer
May 6, 2007
I'll probably post in one of the IYG android megathreads about this, but maybe someone here might know better:

I'm trying to track down an issue with my phone (droid razr hd maxx, android 4.1.2) and my new car stereo's bluetooth interface. Specifically, there is some weird interaction between the two. When it starts up, it seems to be sending the Play command (or play/pause? I'm actually not sure), causing Android to (eventually) launch the registered application and resume playback. However, a good portion of the time it immediately skips to the next track (which is a problem when listening to a podcast, or just to audible). I can work around it by launching Pandora right before I start the radio, which I use as a meatshield, but sometimes it ignores that (even though it should have then been registered) and launches a different application anyway.

Now my question: Is there any way for me to debug what exactly is going on in android.media.AudioManager? I think that is where all of this is handled, so I'm hoping it might hold clues about (a)why this is happening and (b) why it doesn't always happen. I also need to figure out why it didn't behave this way using my previous Bluetooth audio adapter, but I don't even know where to start looking for that.

Any ideas?

GenJoe
Sep 15, 2010


Rehabilitated?


That's just a bullshit word.
Is there a way to programatically disable the android WebView from loading the mobile version of a website? It seems that the WebView defaults to loading mobile versions, but for my purposes I pretty much need it to load the default version of the website.

Glimm
Jul 27, 2005

Time is only gonna pass you by

GenJoe posted:

Is there a way to programatically disable the android WebView from loading the mobile version of a website? It seems that the WebView defaults to loading mobile versions, but for my purposes I pretty much need it to load the default version of the website.

Maybe try using WebSettings:

http://developer.android.com/reference/android/webkit/WebSettings.html#setUserAgentString%28java.lang.String%29

code:
webView.getSettings().setUserAgentString("Some user agent that represents itself as a desktop?")

Adbot
ADBOT LOVES YOU

GenJoe
Sep 15, 2010


Rehabilitated?


That's just a bullshit word.

Glimm posted:

Maybe try using WebSettings:

http://developer.android.com/reference/android/webkit/WebSettings.html#setUserAgentString%28java.lang.String%29

code:
webView.getSettings().setUserAgentString("Some user agent that represents itself as a desktop?")

Thanks, that worked pretty well.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply