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...

brand engager posted:

We have a multi-process app, and recently we found out that a bunch of classes that implement Parcelable were being stored to the filesystem and in a database in the marshalled form. Don't do this, it really sucks to fix

... Parcelable's documentation is pretty explicit that this is a bad idea and that you should never do this. I'm impressed that someone did it anyway. You'd think whoever had this idea would have at least gone with serializable...

Adbot
ADBOT LOVES YOU

FAT32 SHAMER
Aug 16, 2012



Volmarias posted:

... Parcelable's documentation is pretty explicit that this is a bad idea and that you should never do this. I'm impressed that someone did it anyway. You'd think whoever had this idea would have at least gone with serializable...
reading docs is for yeller bellies

real coding heroes figure everything out by stackoverflow questions and scrolling through function lists on objects that sound like they may do what they want

brand engager
Mar 23, 2011

Does DataStore<Preferences> not work across processes? Getting the feeling that google really wants people to stop using multiple processes for a single app

FAT32 SHAMER
Aug 16, 2012



brand engager posted:

Does DataStore<Preferences> not work across processes? Getting the feeling that google really wants people to stop using multiple processes for a single app

wasn't the point of DataStore to be asynchronous vs doing it directly on the UI thread?

according to the docs (https://developer.android.com/topic...cB&gclsrc=aw.ds) you can run it synchronously and either scope the coroutine as blocking or scope it to the lifecycle of your current view. If you wanted to you could probably do withContext(Dispatchers.IO) { ... } inside of your launch lambda

Volmarias
Dec 31, 2002

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

brand engager posted:

Does DataStore<Preferences> not work across processes? Getting the feeling that google really wants people to stop using multiple processes for a single app

I know it's not an answer, but I'm genuinely curious what your reason is for multiple processes in your application.

brand engager
Mar 23, 2011

Volmarias posted:

I know it's not an answer, but I'm genuinely curious what your reason is for multiple processes in your application.

We have one of those apps that runs other apps in a container. Other apps get spawned as separate processes. But in this case I was trying to use datastore from the normal app process and a second process we have a bunch of our backend code running in.

E: anyways I ended up putting the datastore access in a content provider and writing the boilierplate stuff to do contentresolver calls interacting with it

FAT32 SHAMER
Aug 16, 2012



That sounds horrifying to maintain lol

brand engager
Mar 23, 2011

Cool if you try to dismiss a DialogFragment from an activity's onStop the dialog throws a runtime exception. loving clown OS

Volmarias
Dec 31, 2002

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

brand engager posted:

Cool if you try to dismiss a DialogFragment from an activity's onStop the dialog throws a runtime exception. loving clown OS

dismissAllowingStateLoss :colbert:

Clown developer, not reading docs, smh

And, as the first stack overflow post notes, if you need to cancel after onStop, you might want a plain old dialog instead.

Jolly Jumbuck
Mar 14, 2006

Cats like optical fibers.
Hello Goons - I wrote out an idea for a turn-based boardgame-style game and was interested in converting it into an App for a small audience. While I have done lots of scripting, particularly in Python with a bit in C++, I've never really touched graphics before. Are there any easy game-making templates to have pre-made graphical pieces assigned to various spaces on the board that I could script or would most any app have to take a lot of graphics and background coding from scratch?

FAT32 SHAMER
Aug 16, 2012



Your best bet is probably unity, which uses C#

There’s probably other frameworks but Unity is the most common one I see

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Unity also gives the benefit of allowing you to build for iOS as well.

It depends on the type of game too, it may be simpler to throw together a UI from basic components than to learn Unity, but that's unlikely.

FAT32 SHAMER
Aug 16, 2012



does anyone remember how to make a material slider have discrete values but not multiple thumb thingos? i started out with Slider, but all you could do is set valueFrom and valueTo, while RangeSlider allows you to set a list of possible values such as listOf(1f, 2f, 5f, 10f, 25f), but then you have a thumb controller for each point, and i just want/need one

Volmarias
Dec 31, 2002

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

FAT32 SHAMER posted:

does anyone remember how to make a material slider have discrete values but not multiple thumb thingos? i started out with Slider, but all you could do is set valueFrom and valueTo, while RangeSlider allows you to set a list of possible values such as listOf(1f, 2f, 5f, 10f, 25f), but then you have a thumb controller for each point, and i just want/need one

I'm not sure what you mean by multiple thumb controllers? Stopping at certain points? It sounds like you want a continuous slider with an interpolator for what to map that value to.

Anne Bonny
Feb 26, 2019
I'm trying to setup Crashlytics for Android NDK such that in my Crashlytics console, I receive a stack trace, instead what I have now...

code:
Crashed: Thread: SIGABRT  0x0000000000000000
#00 pc 0x6b97c libc.so 
#01 pc 0x1e060 libc.so 
#02 pc 0x951f8 libmy-library.so 
#03 pc 0x95350 libmy-library.so 
#04 pc 0x92240 libmy-library.so 
#05 pc 0x9186c libmy-library.so 
#06 pc 0x917c8 libmy-library.so 
#07 pc 0x4652c libmy-library.so 
build.gradle (project):

code:
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.2"
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
build.gradle (app):

code:
plugins {
    id 'com.android.application'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

dependencies {
    //...
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-crashlytics-ndk'
    implementation 'com.google.firebase:firebase-analytics'
}


android {
    compileSdkVersion 30
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.mycompany.myapplication"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
        externalNativeBuild {
            cmake {
                cppFlags "-frtti -fexceptions"
                abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
                arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            // Add this extension
            firebaseCrashlytics {
                // Enable processing and uploading of native symbols to Firebase servers.
                // By default, this is disabled to improve build speeds.
                // This flag must be enabled to see properly-symbolicated native
                // stack traces in the Crashlytics dashboard.
                nativeSymbolUploadEnabled true
            }
        }
    }

    packagingOptions {
        pickFirst '**/*.so'
    }

    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            version "3.10.2"
        }
    }
    sourceSets {
        main {
            jni {
                'src/main/jniLibs'
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
CMakeLists.txt...

code:
cmake_minimum_required(VERSION 3.4.1)

include_directories(${OpenCV_DIR}/jni/include)
add_library( lib_opencv SHARED IMPORTED )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${OpenCV_DIR}/libs/${ANDROID_ABI}/libopencv_java4.so)

add_library( # Sets the name of the library.
        my-library

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        my-library.cpp)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log )

target_link_libraries( # Specifies the target library.
        my-library

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib} lib_opencv) #EDIT

According to https://firebase.google.com/docs/crashlytics/ndk-reports I need to "explicitly invoke the uploadCrashlyticsSymbolFileBUILD_VARIANT task after each build of your NDK library." for method names to appear in my stack traces....

code:
>./gradlew app:assembleBUILD_VARIANT\
           app:uploadCrashlyticsSymbolFileBUILD_VARIANT
But I don't understand the build process well enough to know how to do this . I know neither where to call this command or what to call it with.

I would appreciate any guidance.

Vesi
Jan 12, 2005

pikachu looking at?

Anne Bonny posted:

According to https://firebase.google.com/docs/crashlytics/ndk-reports I need to "explicitly invoke the uploadCrashlyticsSymbolFileBUILD_VARIANT task after each build of your NDK library." for method names to appear in my stack traces....

code:
>./gradlew app:assembleBUILD_VARIANT\
           app:uploadCrashlyticsSymbolFileBUILD_VARIANT
But I don't understand the build process well enough to know how to do this . I know neither where to call this command or what to call it with.

I would appreciate any guidance.

there's gradlew and gradlew.bat in the project directory (same as the toplevel build.gradle)

you don't have any variants so you'd be running from the commandline:

gradlew assembleRelease uploadCrashlyticsSymbolFileRelease

or Debug instead of Release for debug build

FAT32 SHAMER
Aug 16, 2012



Volmarias posted:

I'm not sure what you mean by multiple thumb controllers? Stopping at certain points? It sounds like you want a continuous slider with an interpolator for what to map that value to.

yes, exactly that

the range slider has like n number of thumb slider thingos that lets you set a range (as the name should have implied to me!!), but i havent found anything that suggests how to do what you just described

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Use a Slider with a step size of 1, and give it a LabelFormatter to map that to your custom values for display.

This has the extra upside of making your tick marks evenly spaced out so it's easy to hit them, instead of being all bunched together at one end and really far apart at the other.

Infomaniac
Jul 3, 2007
Support Cartographers Without Borders
Just getting back into Android Dev things and Compose is pretty neat.

Any overall opinions or trip reports about using Composables?

Any warnings or advice I should keep in mind while migrating view based uis to the new way?

I'm looking for general sentiments if anyone cares to share their experiences here.

FAT32 SHAMER
Aug 16, 2012



Based on what I’ve read, Compose is a great opportunity to begin migrating away from fragments, so brace urself for that

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
I've used compose a bit, and think it's pretty neat. However, I haven't had much call to use it since there haven't been any particularly new UI flows to work on, so my experience is limited. I do recommend using it though, unless you have a reason not to.

Anne Bonny
Feb 26, 2019

Anne Bonny posted:

I'm trying to setup Crashlytics for Android NDK such that in my Crashlytics console, I receive a stack trace, instead what I have now...

Vesi posted:

there's gradlew and gradlew.bat in the project directory (same as the toplevel build.gradle)

you don't have any variants so you'd be running from the commandline:

gradlew assembleRelease uploadCrashlyticsSymbolFileRelease

or Debug instead of Release for debug build

I finally got around to testing this. On a native crash, in Crashlytics, instead of:

code:
Crashed: Thread: SIGABRT  0x0000000000000000
#00 pc 0x6b97c libc.so 
#01 pc 0x1e060 libc.so 
#02 pc 0x951f8 libmy-library.so 
#03 pc 0x95350 libmy-library.so 
#04 pc 0x92240 libmy-library.so 
#05 pc 0x9186c libmy-library.so 
#06 pc 0x917c8 libmy-library.so 
#07 pc 0x4652c libmy-library.so 
I get:
code:
Crashed: Thread: SIGSEGV  0x0000000000000001
#00 pc 0x461f4 libmy-library.so 
#01 pc 0x46198 libmy-library.so 
along with logs for 30 other similar, but non-crashed threads (I didn't think I was using this many threads in my application?).

What's the error? This crash is caused by an OpenCV function within a Native function.

Also, is it possible to surround certain sections of my native code with a try catch and the say something like Crashlytics::log()?

Anne Bonny
Feb 26, 2019
Here's another question:

I'm trying to rotate a RelativeLayout, such that it looks exactly like it would when the device orientation is changed. Essentially, I want to rotate my RelativeLayout, such that after a call to rotate(), it retains its original boundaries. It's very similar to this question...

https://stackoverflow.com/questions/21355784/android-rotate-whole-layout

But the accepted solutions do not work, because my RelativeLayout is not the root layout. If I attempt to rotate, translate, and scale to the RelativeLayout's previous boundaries, it sometimes works but often times refuses to scale down beyond a certain amount.

How can I make this work? Seems like a very straightforward kind of thing, but I haven't been able to hack it.

PokeJoe
Aug 24, 2004

hail cgatan


is it one layout inside more of them that aren't rotated? i tried to do something similar for a fullscreen video player and i ended up just programmatically swapping to landscape and portrait mode

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If I was doing this, I would just write a "wrapper" viewgroup that handles the rotation. Just have it measure and lay out its one child according to the specific rotation you want it to have.

Volmarias
Dec 31, 2002

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

Anne Bonny posted:

Also, is it possible to surround certain sections of my native code with a try catch and the say something like Crashlytics::log()?

Not within the Java end of things at least, who knows what C allows you to do. At this point it's the runtime sending a message that the JVM (or whatever it's called now, ART?) is unable to continue correctly and deliberately aborting. You might have more help looking here: https://source.android.com/devices/tech/debug/native-crash but I think the real answer is "you need to be able to transform the release binary info into something you can use, when you made your build hopefully the symbol list library that you stripped was saved somewhere" but it's been a very long time since I had to think about this

PokeJoe
Aug 24, 2004

hail cgatan


My phone updated to android api 31 and now the widget i've been working on doesn't seem to respect visibility changes in the remoteviews. It still works on older devices :(. Anyone else notice this? theres not much online I've found.

PokeJoe fucked around with this message at 13:11 on Jan 7, 2022

Anne Bonny
Feb 26, 2019
When I load images into my grid-based RecyclerView, such that there are more images that can fit on the screen at one time, the RecyclerView scrolls to show the image it is loading.

If I remove any of the following things, this error does not occur...
  • GridLayoutManager's setReverseLayout(true)
  • The RecyclerView's height: WRAP_CONENT
  • The RecyclerView's parent (a RelativeLayout) is layout ABOVE another element (and height is MATCH_PARENT)
  • Glide loads images.
I'm not sure why this is happening. I know it isn't default behavior. Any insight into this problem is appreciated, it's driving me insane. (the orientation of my RecyclerView is vertical)

Thanks.

PokeJoe
Aug 24, 2004

hail cgatan


What do you mean scrolls, does it center over the view? Are you using a snap helper?

smiling giraffe
Nov 12, 2015
It could be a bunch of things. Have you got a git repo to look at?

As a general point Ive been loving Compose after years of recyclerview bullshit. I appreciate it’s probably not practical to switch for whatever you’re working on now, but seriously consider it for future stuff.

Anne Bonny
Feb 26, 2019



https://github.com/kraftski/RecyclerViewError

Here we go. I made a small project that demonstrates the error. There are some screenshots in the readme. You press the center button to load some images from your device and the program loads the images into two recyclerviews, the one on the left which loads properly, and the one on the right which scrolls up as new images are loaded into it. You'll see that I've made it so that the later images are in the dataset, the more of a green tint they have to them. You can see what I mean in the error screenshot, which also demonstrates the error kind of. It's not that the recyclerview on the right simply scrolls a little bit once after you load your images, it continually scrolls at any time images are loaded. Very frustrating and confusing.

The files which are of interest here are: MainActivity.java, activity_main.xml, ImageAdapter.java.

smiling giraffe
Nov 12, 2015

Anne Bonny posted:

https://github.com/kraftski/RecyclerViewError

Here we go. I made a small project that demonstrates the error. There are some screenshots in the readme. You press the center button to load some images from your device and the program loads the images into two recyclerviews, the one on the left which loads properly, and the one on the right which scrolls up as new images are loaded into it. You'll see that I've made it so that the later images are in the dataset, the more of a green tint they have to them. You can see what I mean in the error screenshot, which also demonstrates the error kind of. It's not that the recyclerview on the right simply scrolls a little bit once after you load your images, it continually scrolls at any time images are loaded. Very frustrating and confusing.

The files which are of interest here are: MainActivity.java, activity_main.xml, ImageAdapter.java.

Got it to work by replacing the right hand RelativeLayout with a ConstraintLayout, like this:

code:
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <View
                android:id="@+id/lower"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:background="@color/purple_700"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/right"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@id/lower"
                android:background="@color/purple_200"
                app:layout_constraintBottom_toTopOf="@+id/lower"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:reverseLayout="true" />
        </androidx.constraintlayout.widget.ConstraintLayout>
However my experience of the problem was different to how you describe. I only saw the scroll immediately after the images were loaded, and it seemed to be related to that bottom purple padding view... because if you set the height of that to 0dp then the problem disapeared. It was like the recycler thought it had the whole screen height to work with, but then had to compensate for the bottom padding so it shrunk itself without adjusting it's viewport. I saw this behaviour regardless of whether the item was an image or just a empty view.

ConstraintLayouts are generally better then RelativeLayouts though, they are more powerful and you don't need to nest views so much, which is bad for performance.

Anne Bonny
Feb 26, 2019
Thank you! This solves my problem. However, now the end of the RecyclerView spills offscreen (The last row (or more?) of images is chopped in half).

This should be prevented by the constraints but it isn't. I haven't been able to find a good solution to this, as I need by RecyclerView to only wrap it's contents, not fill the screen no matter what (say, if there was only one image loaded). Any ideas?

FAT32 SHAMER
Aug 16, 2012



Anne Bonny posted:

Thank you! This solves my problem. However, now the end of the RecyclerView spills offscreen (The last row (or more?) of images is chopped in half).

This should be prevented by the constraints but it isn't. I haven't been able to find a good solution to this, as I need by RecyclerView to only wrap it's contents, not fill the screen no matter what (say, if there was only one image loaded). Any ideas?

I get this problem all the time, and usually what I have to do is give it a moderately sized marginBottom with a constraint to parent bottom

Anne Bonny
Feb 26, 2019
Unfortunately, this doesn't seem to work. Neither does any other solution I tried. It appears that when the RecyclerView is rendered, it for whatever reason calculates it's height without considering either the bottom margins or the bottom constraints I put on it, thus making it bigger than needed, and THEN shifts it up. I'm not really sure how to work around this.

I also don't understand what's wrong with my problem solving approach because this seems like a very simple thing I'm trying to do and Android is determined to make it impossible.

smiling giraffe
Nov 12, 2015
Java and RecyclerView are old hat in the Android world now.

I don't know what time/cost constraints you are operating under, but long term, adopting kotlin and compose will make your Android dev experience a lot more enjoyable.

FAT32 SHAMER
Aug 16, 2012



we're eventually going to switch to compose, but we're not too keen on the conversion process being convert xml -> compose with fragment, get all screens converted, then eventually convert all fragments to one activity that hosts all composables. and the refactor time on simply converting xml -> composables w/ single activity composable host is too big to justify rn and based on what i've read, doesnt play very nicely with having the activty manage both composables and fragments, and it breaks the poo poo out of everything if you use jetpack navigation

Volmarias
Dec 31, 2002

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

FAT32 SHAMER posted:

we're eventually going to switch to compose, but we're not too keen on the conversion process being convert xml -> compose with fragment, get all screens converted, then eventually convert all fragments to one activity that hosts all composables. and the refactor time on simply converting xml -> composables w/ single activity composable host is too big to justify rn and based on what i've read, doesnt play very nicely with having the activty manage both composables and fragments, and it breaks the poo poo out of everything if you use jetpack navigation

Definitely a concern I've had with this, I really do wish there was a nicer way to handle fragments but I guess there's only so much that can be done.

FAT32 SHAMER
Aug 16, 2012



compose navigation on the surface looks super promising since it's just a map of composables for the activity to begin displaying, and it would make sense that it would be more stable, especially for deeplinking, than the current xml jetpack navigation that does blackbox bullshit with fragment transactions

that being said though, im not at all a fan of what as far as i understand is the use of URIs to handle deeplinking versus just keys, and i think the only really proper way to force developers off of xml would be to have an API update that deprecates Fragment and forces devs to compose, but i also would be willing to be that this wont happen at any point in the future due to the level of effort currently required. If they were to come up with a migration tool to convert layout files to composables, it would help, and if i understand the foldable api correctly, theyve made it a shitshow to do using xml.

Speaking of the foldable lib, how hard is Android going into that? i think i saw docs saying that supporting foldables will be mandatory for all new apps, but it strikes me as yet another feature that nobody actually wants and not many people will have. Has anyone dug into that much?

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

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

FAT32 SHAMER posted:

i think the only really proper way to force developers off of xml would be to have an API update that deprecates Fragment and forces devs to compose, but i also would be willing to be that this wont happen at any point in the future due to the level of effort currently required.

The change from MVC to MVI is a pretty rough one to try to shoehorn in, and I get the feeling that any generated results would be hideous at best.

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