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
Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Search for "android ORM" and take your pick then. The first result for me was GreenDAO, which is a name I've heard before but I cannot give any recommendations.

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

Lutha Mahtin posted:

I just cannot deal with making this brittle "data structure" (if you can even call it that) where all these ints just sort of happen to correspond to some array over there. I know there is probably a really easy solution to this, but I'm blanking on it. Please remind me of the very obvious class or combo that does exactly what I'm looking for here :v:

I guess it's specifically to avoid this pattern of grossness


Java code:

textView.setText(cursor.getString(cursor.getColumnIndex(ButtTable.COLUMN_BUTT_TEXT)));


If you understandably hate that and want to keep the direct references I guess you could set them when you first open a database, updating them whenever a method that changes table structure is called? Still pretty bad and it's the kind of thing generated code is good at, at which point you might as well start looking at the DAO libraries

Fergus Mac Roich
Nov 5, 2008

Soiled Meat
Edit:Nm, my answer is worse anyway.

sausage king of Chicago
Jun 13, 2001
I'm writing my first android app. I'm trying to get my app to scrape a couple of web pages and as it scrapes, update a display with a link to some scraped data. The process to get the data takes more than a minute but less than five. Reading up on this, the best thing to do would be to create a service, is that right? And somehow as the service runs it can update the activity to display the data as it comes in?

Tunga
May 7, 2004

Grimey Drawer

sausage king of Chicago posted:

I'm writing my first android app. I'm trying to get my app to scrape a couple of web pages and as it scrapes, update a display with a link to some scraped data. The process to get the data takes more than a minute but less than five. Reading up on this, the best thing to do would be to create a service, is that right? And somehow as the service runs it can update the activity to display the data as it comes in?
If you want it to continue running in the background if you user closes the app or similar then a service is your own real choice*. You'll want to persist the data to something in case it finishes while your client is in the background or has been destroyed. You can additionally bind to the service to get immediate updates from it while the client is active, or you can just get updates directly from your data store.

There are certainly some nuances to this stuff and there isn't one single way to approach it.

*If you're targeting API 21 or newer (which in industry we don't generally have the luxury of doing but you may if this is just a personal project) you can use JobScheduler instead.

If you don't care about it running while the app isn't visible (which seems like a bad idea if it takes several minutes to run but maybe you don't care) then you can just use an AsyncTask or spin your own solutions to do that on another thread.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Worth also suggesting, if you're doing this quick and dirty, you don't need to bind to the service. Because the service runs in the same process, you could just have it publish it's results to some singleton, and notify the activity when something new is there. The activity refreshes it's view from that singleton in onResume or when it's notified. This way you don't need to worry about whether the callbacks are parcelable or anything.

There's a lot of ways to do this, it really depends on your use case, whether you'll ever show this off, and how much you hate yourself.

Tunga
May 7, 2004

Grimey Drawer

Volmarias posted:

publish it's results to some singleton, and notify the activity when something new is there.
Keeping a reference to an activity in a sington sounds like a pretty good way to create a horrible memory leak. Unless I'm not understanding you.

Volmarias
Dec 31, 2002

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

Tunga posted:

Keeping a reference to an activity in a sington sounds like a pretty good way to create a horrible memory leak. Unless I'm not understanding you.

You are. I'm suggesting publishing (:airquote: "publishing" :airquote:) the data to a singleton that the activity can query, and which listens for broadcast intents. Otherwise, yeah, add/remove a listener as part of the life cycle of something but don't just straight up jam an activity in there.

Doctor w-rw-rw-
Jun 24, 2008

Volmarias posted:

You are. I'm suggesting publishing (:airquote: "publishing" :airquote:) the data to a singleton that the activity can query, and which listens for broadcast intents. Otherwise, yeah, add/remove a listener as part of the life cycle of something but don't just straight up jam an activity in there.

I preferred app-scoped or some-notion-of-session-scoped properties on a class, and calling that a Manager, Coordinator, or Controller (i.e. "FooManager", "FooCoordinator", or "FooController"), or maybe Listener or Announcer, depending on the specific thing it's doing. The broadcast intents method seems not unreasonable.

kitten smoothie
Dec 29, 2001

edit: nvm covered up-thread

Karate Bastard
Jul 31, 2007

Soiled Meat
Hi! I thought I'd try my hand at making an Android app. I'm decent enough with python but know jack squat about Android/Java. I've started out and got a few of the basics down, and I'm looking for a few pointers to where to go from here. Here's basically what I'm trying to do (but implemented as an Android app):

https://chrome.google.com/webstore/detail/play-to-kodi/fncjhcjfnnooidlkijollckpakkebden?hl=en

My idea is to make the app such that you'd be able to "Share" browser urls with it, which it then converts something kodi can understand (that part is dirt simple), and then tells a preconfigured kodi server to play using a few jsonrpc calls (1: get playlist id, 2: check if currently playing something, 3: if so stop it, 4: add url to right playlist, 5: start playing again from the right playlist). Hella straightforward.

Or so I thought, before I looked here:

https://developer.android.com/training/basics/network-ops/connecting.html

Such bullshit! Then I found this:

https://square.github.io/retrofit/

which seems to do roughly what I want.

My questions:
* Is retrofit any good? Is it still what the kids use these days?
* How do I make a series of jsonrpc calls, where return values from one is input to the next? Do I make them all in series in a worker thread? How? Using AsyncTask? And retrofit?
* How can I offer the user a way to cancel the operation, eg if it takes too long or they change their mind?
* How can I update the main thread with status in between calls?
* How do I easily make a simplistic gui with preferences config? I need a Main Activity I guess, and maybe a popup that displays status, and a preferences activity where you can set address, port, username and password to the kodi server. Do I design my own in Android Studio? I feel this should be so super common that there should be some shortcuts available that I'm not seeing.

Thanks you guys!

Tunga
May 7, 2004

Grimey Drawer
Retrofit is an excellent choice and Square have a strong track record of supporting and updating it and Jack Wharton is the poster child of Android developers.

Because some idiot made a terrible decision two years ago my current project is still using Robospice so I'm not in much of a position to answer the more specific questions as I haven't used Retrofit for ages now and can't remember much about how it works. I'm sure someone else will be able to help though as it's a really popular library.

For the last part check out PreferenceFragment or PreferenceFragmentCompat (or PreferenceActivity if you want to keep it old school).

kitten smoothie
Dec 29, 2001

Tunga posted:

(or PreferenceActivity if you want to keep it old school).

I'm pretty sure you'll get deprecation warnings all over the place if you try using a PreferenceActivity in tyool 2017. I'd just use the PreferenceFragmentCompat like you said.

It looks like someone's already built a library that talks to the json-rpc end of XBMC/Kodi so maybe worth giving it a try first. I didn't look at the code or anything to know for sure but it looks like they've generated types for all the various commands and responses. You'd need to do that yourself if you were talking to their API using Retrofit.

Karate Bastard
Jul 31, 2007

Soiled Meat
Neat, thanks! I now have a server settings Activity with a PreferenceFragment in it, accessible from a top-right dotted Menu. Surprisingly painless.

That XBMC JSON-RPC library for Android looks interesting, but it says in the description that it's "autogenerated" plus nobody touched it in 3 years? I might give it a spin to try it out, but really, isn't jsonrpc simple enough to just do, without a specialized lib for one service? Given that I'll just need a handfull calls, and am not trying to provide any kind of extensive functionality?

Karate Bastard fucked around with this message at 09:53 on Jan 15, 2017

Volmarias
Dec 31, 2002

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

Tunga posted:

Jack Wharton

Jake

Tunga
May 7, 2004

Grimey Drawer
Haha, whoops. Apparently my Android phone thinks he is called Jack and who am I argue with Google's magnificent keyboard?

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

Kind of a vague question, but are there any issues with Sqlite where it needs... warming up or something?

There's a startup check in the Awful app, where it pulls the timestamp column from the first row in a table to see how old the data is. If it's too old then there's an update that ends up replacing the data. If the timestamp fetch returns null then the same thing happens

The weird thing is, sometimes it returns null and sometimes it doesn't. The timestamp is always there, you can start the app and it will read fine and realise it doesn't need to update. Then another time you start it, with the exact same data in the db, it returns null (this is logged) which triggers an unnecessary update

Anyone have any idea why it might be doing this? I'm probably going to just stick the timestamp in the app's preferences to fix it, but I'd like to know why it's breaking

Volmarias
Dec 31, 2002

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

baka kaba posted:

Kind of a vague question, but are there any issues with Sqlite where it needs... warming up or something?

There's a startup check in the Awful app, where it pulls the timestamp column from the first row in a table to see how old the data is. If it's too old then there's an update that ends up replacing the data. If the timestamp fetch returns null then the same thing happens

The weird thing is, sometimes it returns null and sometimes it doesn't. The timestamp is always there, you can start the app and it will read fine and realise it doesn't need to update. Then another time you start it, with the exact same data in the db, it returns null (this is logged) which triggers an unnecessary update

Anyone have any idea why it might be doing this? I'm probably going to just stick the timestamp in the app's preferences to fix it, but I'd like to know why it's breaking

That sounds like an exceptionally exciting bug if you can even partly reliably reproduce it. Is it device/OEM specific? I wouldn't be shocked by a vendor "improving" SQLite.

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

Hold that thought, I think something else might be loving with the table :negative:

Mezzanine
Aug 23, 2009
I'll ask later on Stack Overflow, but I thought I'd try here first.

I have a Java project (all gradle) that I'm trying to add an Android Library module to in order to use Android-specific classes like Context, Activity, etc. I've run into a bunch of snags, and I think I'm close to getting it to work, but now I'm stuck.

Building the Android module gives me "Duplicate file found: ../../../debug/R.java" and "Duplicate file found: ../../../debug/BuildConfig/BuildConfig.java" in the "generated" directory. Is there any way to prevent this? Perhaps disabling flavors and build types (since I only need one)?

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

I don't actually know at all, but if you've tried cleaning your project and rebuilding, maybe you copied in some previously generated files when you added the module? The build process generates those files automatically, but if you have other copies in there (or in another source folder) you might get a conflict. It might be as easy as deleting them from those folders, but from googling around it could be a bunch of things

Taffer
Oct 15, 2010


Mezzanine posted:

I'll ask later on Stack Overflow, but I thought I'd try here first.

I have a Java project (all gradle) that I'm trying to add an Android Library module to in order to use Android-specific classes like Context, Activity, etc. I've run into a bunch of snags, and I think I'm close to getting it to work, but now I'm stuck.

Building the Android module gives me "Duplicate file found: ../../../debug/R.java" and "Duplicate file found: ../../../debug/BuildConfig/BuildConfig.java" in the "generated" directory. Is there any way to prevent this? Perhaps disabling flavors and build types (since I only need one)?

Are you using Android studio? Post your gradle file.

Mezzanine
Aug 23, 2009

Taffer posted:

Are you using Android studio? Post your gradle file.

Nope, it's a multi-module project in Intellij IDEA. I'm starting to think it's more to do with the module settings and such, but here's the relevant gradle stuff.

top level settings.gradle
code:
rootProject.name = 'root-project-name'

include ':android-module-name'
include ':other-module-name'
build.gradle for the android module:
code:
apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main {
            java {
                java.srcDirs = ['src/main']
            }
        }
    }
}

task sourcesJar(type: Jar) {
    from 'build/intermediates/classes/release/'
}

artifacts {
    archives sourcesJar
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    testCompile 'junit:junit:4.12'
}
Not much changes from the default here, except for having it put the classes into a jar (as the other modules are all plain Java).

I've tried various combinations of "excluding" everything in the "build/generated" and "build/intermediates" directories of the Android module, but it either gives me the "Duplicate class found: R.java" error or a vague "Error: 0".

joebuddah
Jan 30, 2005
I have a three page app, a main page then two child pages which shows product pictures and descriptions. Page one works, so I copied the XML to page two. That worked. However when I started to change the image names on page two, none of the images are showing up when I build the APK.But they are displayed in Gradle. Any clue what would cause this funky behivaor?

Edit:


All images are in the drawable folder

joebuddah fucked around with this message at 04:23 on Mar 18, 2017

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

Hard to know without seeing any code, but maybe you're using the same IDs on the ImageViews or whatever, and there's a conflict? Try making sure your second page ones have unique ID names

But really it could be a bunch of things depending on what you're actually doing. Seeing the XML and the code in the Activity and any Fragments would help

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

I guess I should mention it here in case anyone lurking doesn't know: Jack's dead, baby

Volmarias
Dec 31, 2002

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

joebuddah posted:

I have a three page app, a main page then two child pages which shows product pictures and descriptions. Page one works, so I copied the XML to page two. That worked. However when I started to change the image names on page two, none of the images are showing up when I build the APK.But they are displayed in Gradle. Any clue what would cause this funky behivaor?

Edit:


All images are in the drawable folder

Without more details we really can't tell you. What are the "pages"? Fragments? Activities? When you change the "image name" what are you changing, and are you changing it in code or in the XML or...

Taffer
Oct 15, 2010


I started using kotlin and it is amazing. You should all use kotlin.

Vesi
Jan 12, 2005

pikachu looking at?

Taffer posted:

I started using kotlin and it is amazing. You should all use kotlin.

brap
Aug 23, 2004

Grimey Drawer
Is the debugger more reliable than it used to be? I would get crashes when hitting breakpoints and stuff.

Taffer
Oct 15, 2010


fleshweasel posted:

Is the debugger more reliable than it used to be? I would get crashes when hitting breakpoints and stuff.

I haven't had that issue. It's had some problems with being aware of when something is null, and some problems detecting anonymous inner classes, but it's still better than using java. Those problems are also probably made worse by me using the canary build of Android Studio.

joebuddah
Jan 30, 2005
It was an image size issue. Once I resized the image it worked. Thanks

Yaoi Gagarin
Feb 20, 2014

Is there anywhere I can find documentation about Android's libc implementation? I've gathered that it's called bionic and found its git repository, but an actual searchable manual like glibc has would be pretty nice...

Vesi
Jan 12, 2005

pikachu looking at?

VostokProgram posted:

Is there anywhere I can find documentation about Android's libc implementation? I've gathered that it's called bionic and found its git repository, but an actual searchable manual like glibc has would be pretty nice...

What do you need it for? It's not like you can develop against it or do you work for a device vendor?

Sereri
Sep 30, 2008

awwwrigami

So the O preview is out apparently?

https://developer.android.com/preview/api-overview.html

A couple of nice features I can't wait to start using in 3 years.

Volmarias
Dec 31, 2002

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

Vesi posted:

What do you need it for? It's not like you can develop against it or do you work for a device vendor?

You're aware of the NDK, yes?

The NDK documentation (online and in the downloaded NDK itself) is as good as you're going to get, at least as far as guaranteed promises.

Yaoi Gagarin
Feb 20, 2014

Vesi posted:

What do you need it for? It's not like you can develop against it or do you work for a device vendor?

I can't say much but yes, we're doing some stuff that an Android OEM would normally do and I'm looking at ways we can test that serial ports, Ethernet, etc all work. Nothing I wrote would be shipped to customers, just used internally

Vesi
Jan 12, 2005

pikachu looking at?

Volmarias posted:

You're aware of the NDK, yes?

The NDK documentation (online and in the downloaded NDK itself) is as good as you're going to get, at least as far as guaranteed promises.

NDK uses its own libc, I recall in a recent blog post they told developers not to rely on any system libraries to prevent conflicts.

For OEM it's different of course, I'd just look at the source. It's mostly POSIX anyway with some platform-irrelevant stuff missing.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Yeah, it wasn't clear from the original question, sorry.

Adbot
ADBOT LOVES YOU

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

OKay, this one is wacky and I apologize in advance if this isn't the right place to ask/is a dumb question.

The goal: Get an arbitrary (e.g. already compiled, not made by me) Android app to display Chinese characters

Background:
I have an industrial/commercial coffee machine here that basically runs a modified tablet that runs an android app for the interface. I can customize this app by editing text files on an SD card. There are already several languages pre-defined, so what I'm doing is trying to copy how a language "works" in the existing app, and applying that to Chinese. I've hacked in the extra language, and am able to select it inside the app. The problem? The characters show up as what looks like Finnish gobblygook.

There's a /FONT folder in the app, with a text file that lists which languages need custom fonts (existing ones being RUS and JPN). There's a sub-folder for each language in that /FONT folder. Inside the language folder (e.g. JPN) there are 4 .xbf files:
code:
XBF_JPN_0.xbf
XBF_JPN_1.xbf
XBF_JPN_2.xbf
XBF_JPN_3.xbf
They range in size from around 800k - 2mb

Based on some Googling, an XBF is apparently a binary of a XAML file, which I obviously don't have since I'm not the developer of the app. Is there a way for me to generate these XBF files in Chinese?

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