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
Super Dude
Jan 23, 2005
Do the Jew

UnfurledSails posted:

I have a standard listview and a "+" button that goes to a NewItemActivity in which the user enters the name of the new item and presses a "Done" button to create a new item. That works fine.

Instead of this I want a new item to appear when the user presses the "+" button without leaving the listview, and the user to be able to edit the title of the item in place. What's the best way to go on about implementing this? Are there any good tutorials for it?

That seems like a very odd UI decision. What happens if the list is almost at the bottom? It creates a new item, then scrolls the entire list up above the keyboard, then back down again? If you don't want it to switch the entire screen, why not bring up a modal dialog?

Adbot
ADBOT LOVES YOU

Super Dude
Jan 23, 2005
Do the Jew
I'm receiving the following Uri from the Photos app
code:
content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F21930/ACTUAL
What is the best way for me to decode it to get the correct characters back? The Uri returned from Gallery doesn't have %2F or %3A.

Super Dude fucked around with this message at 03:38 on Jun 2, 2015

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Super Dude posted:

I'm receiving the following Uri from the Photos app
code:
content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F21930/ACTUAL
What is the best way for me to decode it to get the correct characters back? The Uri returned from Gallery doesn't have %2F or %3A.

You don't. A content uri is an opaque string that you can use to manipulate a resource. If another app wants to put % characters in their content uris, that shouldn't affect your app at all.

What are you actually trying to do?

speng31b
May 8, 2010

Speaking of Android apps, I just released a new one for the first time in awhile (after a long cycle of maintaining big apps for corporate clients, it's refreshing):

http://wireflow.ludomade.com?projectId=7OOsMaON84
https://play.google.com/store/apps/details?id=com.ludomade.blueprint&referrer=utm_source%3D7OOsMaON84



It's a wireframing design tool that some of the designers I work with thought would be neat to have for themselves, and now we've released it. We're actually really looking for feedback right now and the tool is under active development. Some of our designers are using it internally as a dogfoody thing. If you feel like this might be the sort of thing you'd use/would like to help shape its development with suggestions, feel free to speak up or PM me - there's a strong chance I'll go ahead and implement your feature ideas with a really short turnaround time and then probably come back and complain about how your dumb feature caused me X many crashes.

Mostly it's just a bundle of custom view code, but one cool thing about this project is that I got to turn on app indexing and do deep linking properly on Android for the first time. Usually I have to support iOS parity and the web devs I'm working with can't get their stuff together for responsive delivery, so I'm stuck with an app-name:// URL scheme which violates all the rules and whatnot. This time I actually got to do a http scheme handler! The only weird and potentially hacky thing I'm doing right now is intercepting the analytics referrer broadcast on app install so you can get "install time" project sharing - basically if you click one of my project share links and follow through to install, it'll use the referrer to load in that project on startup so you can actually share projects from start to finish with a user who's never installed the app before.

kitten smoothie
Dec 29, 2001

speng31b posted:

The only weird and potentially hacky thing I'm doing right now is intercepting the analytics referrer broadcast on app install so you can get "install time" project sharing - basically if you click one of my project share links and follow through to install, it'll use the referrer to load in that project on startup so you can actually share projects from start to finish with a user who's never installed the app before.

I wouldn't call that hacky, you've basically implemented the exact same "receiver-side" code you'd use with Google's new app invite system -- you create an invite intent with a deep link, the framework does the rest, and your analytics referrer has the deep link for you to process.

https://developers.google.com/app-invites/

speng31b
May 8, 2010

kitten smoothie posted:

I wouldn't call that hacky, you've basically implemented the exact same "receiver-side" code you'd use with Google's new app invite system -- you create an invite intent with a deep link, the framework does the rest, and your analytics referrer has the deep link for you to process.

https://developers.google.com/app-invites/

Yeah, it just feels hacky because if you actually need the referrer for analytics (you know... its intended use case) you have to create a multiplexer for the broadcast and manually call onReceive on anything else that would normally receive the event. It doesn't feel built for it. But that's life with Android.

speng31b fucked around with this message at 15:44 on Jun 2, 2015

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Are there any must-have libraries that aren't part of the standard Android and Java libraries, but you're a clown if you aren't including them almost by default? I saw something about Guava being one of the most used libraries (with the proviso that you use Proguard to strip out what you don't use), and it made me wonder if there's a kind of shadow de facto standard library out there, that everyone basically uses

I was copying a file and enjoying the fact there's no standard call to do this, and doing the usual wrangling of streams and try-catch-finally-try-catch nonsense to close the things, and thinking 'there's got to be a better way!' Any no-brainer libraries for really common tasks?


Also if anyone knows how to stop Android Studio from regularly adding duplicate Git roots in vcs.xml, that would be cool too
XML code:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="VcsDirectoryMappings">
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
  </component>
</project>
Thanks!

speng31b
May 8, 2010

baka kaba posted:

Are there any must-have libraries that aren't part of the standard Android and Java libraries, but you're a clown if you aren't including them almost by default? I saw something about Guava being one of the most used libraries (with the proviso that you use Proguard to strip out what you don't use), and it made me wonder if there's a kind of shadow de facto standard library out there, that everyone basically uses

I was copying a file and enjoying the fact there's no standard call to do this, and doing the usual wrangling of streams and try-catch-finally-try-catch nonsense to close the things, and thinking 'there's got to be a better way!' Any no-brainer libraries for really common tasks?


Also if anyone knows how to stop Android Studio from regularly adding duplicate Git roots in vcs.xml, that would be cool too
XML code:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="VcsDirectoryMappings">
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
  </component>
</project>
Thanks!

I wouldn't say there are de-facto libraries for every project, but for some specific tasks there are. For example, anything other than some sort of purely on-device tool will probably need some sort of networking. If that network endpoint conforms to a REST API, you'll want to use Retrofit by Square. OkHttp if not. For image loading you'll use either Picasso or Glide. If you have heavyweight clientside persistence needs there are a bunch of ORM solutions out there, one of which you will use instead of manually interacting with SQLite. For cross-component but intra-app messaging, you'll use something like Otto by Square (an in-app event bus) rather than writing your own custom observer patterns all over the place (or built-in broadcast behavior, which is typically too heavyweight for simple intra-app messaging). For injecting your view dependencies from XML you'll want to at the very least use something like Butterknife, if you're not going with a full-bore dependency injection container like Dagger or Dagger2.

speng31b fucked around with this message at 20:35 on Jun 8, 2015

Space Kablooey
May 6, 2009


Any specific ORM recommendations?

I'm using Sugar ORM in my projects, but there are some things that I quite didn't like. Namely that in the first run, the ORM auto-creates the tables, which is cool, but it hangs the application for quite a few seconds until it finishes.

speng31b
May 8, 2010

HardDisk posted:

Any specific ORM recommendations?

I'm using Sugar ORM in my projects, but there are some things that I quite didn't like. Namely that in the first run, the ORM auto-creates the tables, which is cool, but it hangs the application for quite a few seconds until it finishes.

I'm on the fence about this. Personally I think ORMs are overused; clientside persistence has been made out as some sort of holy grail when in actuality most apps are adding a huge level of unneeded complexity by keeping their entire serverside object graph replicated on the clientside when they really just need a few objects.

That said, greenDAO is the one recommended most if blazing fast performance is your primary concern. In exchange for that you get a lot of cruft you have to maintain to make greenDAO work. If blazing fast performance is not your primary concern, use the one with with the API that feels the most friendly to you or fits your needs the best. For example, some DAOs require that you extend their base object type. Others let you use any object as long as you use their Bean-style annotations. Maybe your foresee refactoring being an issue so you won't subject your project to a specific base type need for all model objects. Maybe you'd rather not have the clutter/obscurity of library-specific annotations scattered throughout your code. There are a lot of DAOs and as long as you do a bit of research before picking yours, your results will probably be pretty similar.

My main piece of advice is to make sure you really need an ORM lib before using one at all. It may sound silly, but SharedPreferences are actually pretty much fine for most apps clientside storage needs.

speng31b fucked around with this message at 22:06 on Jun 8, 2015

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

speng31b posted:

I wouldn't say there are de-facto libraries for every project, but for some specific tasks there are. For example, anything other than some sort of purely on-device tool will probably need some sort of networking. If that network endpoint conforms to a REST API, you'll want to use Retrofit by Square. OkHttp if not. For image loading you'll use either Picasso or Glide. If you have heavyweight clientside persistence needs there are a bunch of ORM solutions out there, one of which you will use instead of manually interacting with SQLite. For cross-component but intra-app messaging, you'll use something like Otto by Square (an in-app event bus) rather than writing your own custom observer patterns all over the place (or built-in broadcast behavior, which is typically too heavyweight for simple intra-app messaging). For injecting your view dependencies from XML you'll want to at the very least use something like Butterknife, if you're not going with a full-bore dependency injection container like Dagger or Dagger2.

Hmm cheers, that's a lot of stuff! I started using Picasso in a project recently, it's very nice. I'll definitely have a look at those and see what makes sense for what I'm doing

How about things like that streams example though? I mean I know it's Java, but it's like 90% boilerplate and I feel like everyone's getting basic functionality from somewhere else, as part of a general utility library they're already using (like Guava), if not a specific IO library like IOUtils

speng31b
May 8, 2010

baka kaba posted:

Hmm cheers, that's a lot of stuff! I started using Picasso in a project recently, it's very nice. I'll definitely have a look at those and see what makes sense for what I'm doing

How about things like that streams example though? I mean I know it's Java, but it's like 90% boilerplate and I feel like everyone's getting basic functionality from somewhere else, as part of a general utility library they're already using (like Guava), if not a specific IO library like IOUtils

Yeah you shouldn't be manually looping over streams. I actually mentioned in an earlier post in this thread that my personal litmus test for "when it's time to introduce a dependency" is usually when I find myself looping over streams. For network stuff it's pretty clear-cut, because I can just recommend Retrofit, Picasso/Glide, and OkHttp. For file access it's a little murkier, since typically things like SharedPreferences and ORM SQLite wrappers will remove the need for a "File library," since the sort of things you'd do with file system access (even at a higher level) are typically better accomplished in an Android app by ORMs wrapping around a SQLite db or simple key-value pair storage.

What's your use case for writing/reading specific files?

Tunga
May 7, 2004

Grimey Drawer
Paceler is a neat library that I discovered recently, means you don't have to write stupid parcel/unparcel boiler plate code on every class you write as part of your object model.

http://parceler.org/

You can combine Retrofit and Parceler together and your classes become super clean and tidy, I love it.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

speng31b posted:

Yeah you shouldn't be manually looping over streams. I actually mentioned in an earlier post in this thread that my personal litmus test for "when it's time to introduce a dependency" is usually when I find myself looping over streams. For network stuff it's pretty clear-cut, because I can just recommend Retrofit, Picasso/Glide, and OkHttp. For file access it's a little murkier, since typically things like SharedPreferences and ORM SQLite wrappers will remove the need for a "File library," since the sort of things you'd do with file system access (even at a higher level) are typically better accomplished in an Android app by ORMs wrapping around a SQLite db or simple key-value pair storage.

What's your use case for writing/reading specific files?

I'm handling user-provided asset and config files, basically arranged in subfolders held in a main data folder. So I've basically got:
  • Reading and writing to the config files (just JSON)
  • Copying asset files (mostly images)
  • Zipping and unzipping the subfolders for import and export
which all involve various kinds of streams, and the input sources can be local or over the network.

I have a SQL database handling this library, basically holding a bunch of metadata and references to the subfolders, to act as a browser and an entry point to the files' location for actually working with them. The DB is pretty simple (just a few fields) but if you have any recommendations for an ORM that would be useful, I'd like to hear it! The whole cursor.getString(cursor.getColumnIndex(MyDatabase.SOME_COLUMN_ID))) thing really rubs me up the wrong way

I'm looking at these libraries you guys are mentioning too, they look real nice. Badly reinventing the wheel is a habit I need to break, so I'm gonna get adding some of these as soon as I get the chance

speng31b
May 8, 2010

baka kaba posted:

I'm handling user-provided asset and config files, basically arranged in subfolders held in a main data folder. So I've basically got:
  • Reading and writing to the config files (just JSON)
  • Copying asset files (mostly images)
  • Zipping and unzipping the subfolders for import and export
which all involve various kinds of streams, and the input sources can be local or over the network.

I have a SQL database handling this library, basically holding a bunch of metadata and references to the subfolders, to act as a browser and an entry point to the files' location for actually working with them. The DB is pretty simple (just a few fields) but if you have any recommendations for an ORM that would be useful, I'd like to hear it! The whole cursor.getString(cursor.getColumnIndex(MyDatabase.SOME_COLUMN_ID))) thing really rubs me up the wrong way

I'm looking at these libraries you guys are mentioning too, they look real nice. Badly reinventing the wheel is a habit I need to break, so I'm gonna get adding some of these as soon as I get the chance

You could possibly model the config files as DAOs with some ORM lib as a wrapper so you wouldn't need to be manually handling that, just have a Config model POJO that gets automatically persisted for you. For the other stuff I do think your approach is probably correct. It's sort of outside the box for what an app would typically be doing clientside (typically you'd see that sort of stuff handled on the backend and you'd just be asking for it when needed, maybe with some aggressive caching, rather than managing a local repository of images and zip directories for users), but if that's your use case you'll probably need to be doing a lot of manual file management. Just using the built ins for it should be fine.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Ok cool, so long as I'm not needlessly complicating things. Thanks!

Doghouse
Oct 22, 2004

I was playing Harvest Moon 64 with this kid who lived on my street and my cows were not doing well and I got so raged up and frustrated that my eyes welled up with tears and my friend was like are you crying dude. Are you crying because of the cows. I didn't understand the feeding mechanic.
So for our final college project, our 3-person group, for some reason, decided to do an Android application, which none of us have ever worked on. So we are in a bit over our heads.

But basically the first iteration is going to be close to the "Tabata HIIT Timer" app - just a few screens, where you pick a workout routine and then when you start it, there is a timer for each exercise.

Kind of a random question, but does anyone have any general suggestions on how to break up the work among three people? I think the way the group lead proposed might not make any sense.

Volmarias
Dec 31, 2002

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

Doghouse posted:

So for our final college project, our 3-person group, for some reason, decided to do an Android application, which none of us have ever worked on. So we are in a bit over our heads.

But basically the first iteration is going to be close to the "Tabata HIIT Timer" app - just a few screens, where you pick a workout routine and then when you start it, there is a timer for each exercise.

Kind of a random question, but does anyone have any general suggestions on how to break up the work among three people? I think the way the group lead proposed might not make any sense.

While you have an android app, it may make more sense to ask this in the general programming problems thread. You can always decide what your app skeleton structure is and assign parts to people to fill in the blanks.

speng31b
May 8, 2010

Doghouse posted:

So for our final college project, our 3-person group, for some reason, decided to do an Android application, which none of us have ever worked on. So we are in a bit over our heads.

But basically the first iteration is going to be close to the "Tabata HIIT Timer" app - just a few screens, where you pick a workout routine and then when you start it, there is a timer for each exercise.

Kind of a random question, but does anyone have any general suggestions on how to break up the work among three people? I think the way the group lead proposed might not make any sense.

For Android in general it's best if you have developers working on different activities or fragments. If you really only have one big activity, which it sounds like might be your case, maybe have one guy do all the ui xml and just pair program the rest if you need to tick a box saying "everyone in the group worked on this." For a project of that scale having 3 people doing equal parts each independently isn't feasible. You'll step all over each other. Just do your due diligence research on "how does baby first Android", then plan a few longish sessions to all sit together and hammer it out.

kitten smoothie
Dec 29, 2001

It looks to me like one activity where you select from a list of workout routines, and another activity where you just have a timer that counts down and resets.

I'd say one person could work on the latter, and the former would be a good candidate for pairing. I'm imagining maybe bundling the workout list as a json file in the app bundle and then rendering it in recyclerview/listview.

Doghouse
Oct 22, 2004

I was playing Harvest Moon 64 with this kid who lived on my street and my cows were not doing well and I got so raged up and frustrated that my eyes welled up with tears and my friend was like are you crying dude. Are you crying because of the cows. I didn't understand the feeding mechanic.
Thanks for the input.

FAILS AT EVERYTHING
Jan 2, 2006

Finally, I've escaped!
Hey guys, I've got a quick question about doing an http POST in Java using this library: http://loopj.com/android-async-http/

For an app that I'm working on, I have to do an http POST request that contains some images. There is already an iOS app built to send images to a back end api that was written in PHP. The PHP code is looping through an images array in the POST data and saving these files as images. I've tried taking the images and reading them with an InputStream to pass them as a $_POST value, but I suspect I'm having character encoding issues because the server isn't recognizing these files as actual images. I have tried to read the files using the IOUtils.toByteArray method to convert the image to a byte array then post the images that way, but they get put into the $_FILES variable rather than as a $_POST parameter. If I try to convert them to a String using IOUtils.toString, I believe that's where I'm having character encoding issues. I've tried to convert the images to a string using ISO-8859-1, which I thought would clear up any encoding issues, but it still doesn't work. I thought maybe someone here has had experience with converting a jpg image to a string and passing it via $_POST. I think this is a weird way to do submit the images, but the back end developer will not change the API to just read the $_FILES variable, so I'm stuck with trying to come up with a solution. I'm not tied to the loopj async library, I can use whatever recommendations you guys might have for doing this. Thanks.

speng31b
May 8, 2010

FAILS AT EVERYTHING posted:

Hey guys, I've got a quick question about doing an http POST in Java using this library: http://loopj.com/android-async-http/

For an app that I'm working on, I have to do an http POST request that contains some images. There is already an iOS app built to send images to a back end api that was written in PHP. The PHP code is looping through an images array in the POST data and saving these files as images. I've tried taking the images and reading them with an InputStream to pass them as a $_POST value, but I suspect I'm having character encoding issues because the server isn't recognizing these files as actual images. I have tried to read the files using the IOUtils.toByteArray method to convert the image to a byte array then post the images that way, but they get put into the $_FILES variable rather than as a $_POST parameter. If I try to convert them to a String using IOUtils.toString, I believe that's where I'm having character encoding issues. I've tried to convert the images to a string using ISO-8859-1, which I thought would clear up any encoding issues, but it still doesn't work. I thought maybe someone here has had experience with converting a jpg image to a string and passing it via $_POST. I think this is a weird way to do submit the images, but the back end developer will not change the API to just read the $_FILES variable, so I'm stuck with trying to come up with a solution. I'm not tied to the loopj async library, I can use whatever recommendations you guys might have for doing this. Thanks.

Could you post some code? Sounds like the problem might be specific to that HTTP library, which I've never used before or heard of another Android dev recommending, but either way code is going to be needed to really help you out.

If it's a widely used library you should be able to just Google how to POST images with it since that's a pretty common task.

speng31b fucked around with this message at 01:13 on Jun 22, 2015

kitten smoothie
Dec 29, 2001

Also never heard of that library. Okhttp's github repo includes a nice example of doing a multipart post from the contents of a File, so I'd just probably start there.

hooah
Feb 6, 2006
WTF?
My adviser wants me to build a simple Android app that logs the accelerometer and location data. I copied the layout and main activity code from here (please tell me if that's horrible code to start with), so now I have start and stop buttons. I know I want to do the logging and sensor polling off the UI thread, but I don't really have any idea how to separate them. I think once I know that, I can read the documentation for polling sensors, and I can probably figure out how to write to a text file in Java.

Volmarias
Dec 31, 2002

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

hooah posted:

My adviser wants me to build a simple Android app that logs the accelerometer and location data. I copied the layout and main activity code from here (please tell me if that's horrible code to start with), so now I have start and stop buttons. I know I want to do the logging and sensor polling off the UI thread, but I don't really have any idea how to separate them. I think once I know that, I can read the documentation for polling sensors, and I can probably figure out how to write to a text file in Java.

Check the documentation, but I think that the Location and Sensor callbacks occur off of the UI thread anyway. You said "polling". Is that what you want to do, or do you want your callbacks to just update your UI as appropriate?

hooah
Feb 6, 2006
WTF?

Volmarias posted:

Check the documentation, but I think that the Location and Sensor callbacks occur off of the UI thread anyway. You said "polling". Is that what you want to do, or do you want your callbacks to just update your UI as appropriate?

I guess I wasn't aware there's a difference. I'd like to have the UI display the data at first (and maybe always), before I start the logging.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

As far as I remember SensorManager does call back on the main thread, but one of the register listener methods lets you pass the Handler you want it to use instead. So you can just spin up a HandlerThread and run it in there - I'm not sure if that's the best solution, but I've used it and it suits my needs

I used it for polling too, basically letting the callback update a set of current values (you can do some filtering and averaging if you like) and synchronising access so the other thread can dip in whenever it needs an update. Just don't forget to turn the sensors off when you don't need them! (App pausing etc.)

e- oh the polling thing - sensors like the accelerometer update when they sense a change, and you can tweak how often they update and how quickly they respond (with the registerListener methods). So if you lay the phone flat you won't get any accelerometer callbacks. Polling is where you request the current state, so you can get regular updates when you want them instead of when the sensor system provides them

baka kaba fucked around with this message at 15:15 on Jun 22, 2015

hooah
Feb 6, 2006
WTF?
There doesn't seem to be a SensorManager anymore - it looks like it's all done through the Fit APIs.

I think I'll do polling, since I believe this is just going to be something used only in the foreground, and there's basically no UI to speak of going on.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Say what?

http://developer.android.com/reference/android/hardware/SensorManager.html

If the Fit APIs are what you need then great (I haven't even looked at them) but I don't see any signs that they're deprecating SensorManager.

And the polling thing isn't about foreground and background - if you poll for updates then your code is constantly asking 'now what's the state... now what's the state... now what's the state'. Using callbacks is a different approach - the system decides when a state change has occurred, and tells your app about it, and then you react to the state change when the event takes place.

Which is best really depends on what your app's doing. It would be a bad idea to constantly bug the sensor service with 'are we there yet' checks non-stop, you could keep it in a high-power state and drain the battery a lot quicker. The approach I was talking about (that I used) was to have the sensor manager update some state variables whenever there was a change, and then the polling thread can just keep looking at those variables whenever it wonders 'now what's happening'. You might want to poll constantly (say you're drawing a graph or recording some data over a time period), or you might be happy with just waiting until you hear there's a change to deal with

But if you do use SensorManager, you just need to make sure you unregister your listeners when your app doesn't need them anymore, that's all. In most cases that's when your app is no longer visible, unless you need to do some background work. If you keep them registered you'll keep the sensors running and then everyone will get super mad. Fit might be cool too, I just wanted to help since this is actually something I've used for once :thumbsup:

hooah
Feb 6, 2006
WTF?
I do appreciate the help. I'd just used the search box at developers.google.com/android, since I didn't realize there's also developer.android.com. Which is annoying.

Volmarias
Dec 31, 2002

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

hooah posted:

I do appreciate the help. I'd just used the search box at developers.google.com/android, since I didn't realize there's also developer.android.com. Which is annoying.

... How did you download the SDK? :psyduck:

hooah
Feb 6, 2006
WTF?
I don't even remember; it's been a while. Probably by following instructions from somewhere.

authwiggidywack
Oct 29, 2013


Just getting into Android development, specificity around games because why the hell not.

I have something stupid put together, blue background for the sky, green foreground for "ground" and a flag pole.

Hoping over the weekend I can get some kind of ball control going so i can knock a ball around the 'map' a bit./

As a .NET guy this is quite foreign for me.

Suran37
Feb 28, 2009
I'm working on an audio player app, because the few I have used in the past were slowly becoming buggy or have annoying "features".
Anyway, what would be the best way to manage the MediaPlayer object? I was tempted at first to use a singleton, but my research seems to suggest that it would be a bad idea to do so for various reasons. Any tips would be appreciated.

Suran37 fucked around with this message at 03:08 on Jun 26, 2015

speng31b
May 8, 2010

Suran37 posted:

I'm working on an audio player app, because the few I have used in the past were slowly becoming buggy or have annoying "features".
Anyway, what would be the best way to manage the MediaPlayer object? I was tempted at first to use a singleton, but my research seems to suggest that it would be a bad idea to do so for various reasons. Any tips would be appreciated.

Manage it how? If you're using multiple activities each should have its own mediaplayer that follows the activity's life cycle. If you just mean sharing one activity's media player amongst various classes, just pass it to constructors or include it as a param on any method calls that need it (i.e., dependency injection). Long story short to make sure resources are initialized and freed properly an activity should own a mediaplayer and then the instance should be passed around to other stuff as needed.

speng31b fucked around with this message at 03:31 on Jun 26, 2015

Volmarias
Dec 31, 2002

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

Suran37 posted:

I'm working on an audio player app, because the few I have used in the past were slowly becoming buggy or have annoying "features".
Anyway, what would be the best way to manage the MediaPlayer object? I was tempted at first to use a singleton, but my research seems to suggest that it would be a bad idea to do so for various reasons. Any tips would be appreciated.

Are you sure that MediaPlayer is going to be sufficient? If it is, why were you mucking with 3rd party libraries? Consider whether you're going to have to mess with AudioTrack at some point.

Use a Service to manage your player, or whatever you use to play audio, along with setting the service as a foreground service if it's long lived. Bind to your service from your activities for controls, etc.

hooah
Feb 6, 2006
WTF?
I want to (for the time being) display the accelerometer data on the phone's screen. However, I don't know what to search for on the developer website. I thought "text", but that seems to find things related to input. I tried browsing through the API guide, but the User Interface portion didn't have anything about displaying information or output. What am I looking for?

kitten smoothie
Dec 29, 2001

hooah posted:

I want to (for the time being) display the accelerometer data on the phone's screen. However, I don't know what to search for on the developer website. I thought "text", but that seems to find things related to input. I tried browsing through the API guide, but the User Interface portion didn't have anything about displaying information or output. What am I looking for?

Look into putting a TextView in your layout, and setting the text on it.

Adbot
ADBOT LOVES YOU

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Honestly you probably want to go through the tutorials first
https://developer.android.com/training/basics/firstapp/building-ui.html
That and the next page go through the basics of adding UI elements to a layout, taking input values, opening a new activity with intents, and displaying data on the screen

Also generally it can be a good idea to search the reference section specifically (the actual docs, where you end up when you click on a class name like Activity) because that might turn up something you can use directly, or it might point you to a tutorial section on the general concept. The problem with the developer site is a lot of information seems to be spread among different sections, and trying to find something you know you saw before can be pretty frustrating

I don't know if anyone uses this, but Roman Nurik (one of the Android devs) made this chrome extension:
https://chrome.google.com/webstore/detail/android-sdk-search/hgcbffeicehlpmgmnhnkjbjoldkfhoin


It gives you an omnibox keyword, and when you type it you get a live search filter for the SDK. So you can start typing 'TextView', and when it comes up as a suggestion (with its fully qualified name) you can select that and go straight to the doc page instead of doing a search. It's good!

e- oh poo poo, I didn't realise that was adding the 'View Source' link to the doc pages. I thought they just added that to the site recently. That's the poo poo when you're investigating crashes

baka kaba fucked around with this message at 18:17 on Jun 30, 2015

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