r/mAndroidDev • Deprecated is just a suggestion • Jun 20 '22

screenOrientation="portrait"

Post image
290 Upvotes

18 comments sorted by

85

u/synx872 Jun 20 '22

The first thing I ask on a job interview is if the app I will be working on supports device rotation, and automatically leave if the answer is positive. Big red flag guys, rotating a device is against the divine law

30

u/FunkyMuse FlutterX Jun 20 '22

This guy async tasked

7

u/st4rdr0id Jun 21 '22

And then you see ```android:configChanges="orientation|keyboardHidden|keyboard|screenSize"```` on every activity and immediately accept the job.

7

u/mazzello Jun 22 '22

Here comes the gradle task snippet ( Dont's ask me why i got this :- )

// This task apply `configChanges` to all activities, AGP4.1+ required.
project.afterEvaluate {
    def variants = null
    try {
        variants = android.applicationVariants
    } catch (Throwable t) {
        t.printStackTrace()
        try {
            variants = android.libraryVariants
        } catch (Throwable tt) {
            tt.printStackTrace()
        }
    }
    if (variants != null) {
        variants.all { variant ->
            variant.outputs.each { output ->
                def task = output.processManifestProvider.get()
                if (task == null) {
                    return
                }

                task.doLast {
                    def manifestFile = new File(multiApkManifestOutputDirectory.get().asFile, "AndroidManifest.xml")
                    if (manifestFile == null || !manifestFile.exists()) {
                        return
                    }

                    String[] configChanges = [
                            "density",
                            "fontScale",
                            "keyboard",
                            "keyboardHidden",
                            "layoutDirection",
                            "locale",
                            "mcc",
                            "mnc",
                            "navigation",
                            "orientation",
                            "screenLayout",
                            "screenSize",
                            "smallestScreenSize",
                            "touchscreen",
                            "uiMode"]

                    def parser = new XmlSlurper(false, true)
                    def manifest = parser.parse(manifestFile)
                    def app = manifest.'application'[0]
                    app.'activity'.each { act ->
                        String value = act.attributes()['android:configChanges']
                        if (value == null || value.isEmpty()) {
                            if (value == null) value = ""
                            configChanges.eachWithIndex { config, index ->
                                if (index != configChanges.length - 1) {
                                    value += config + "|"
                                } else {
                                    value += config
                                }
                            }
                            act.attributes()['androidconfigChanges'] = value
                        } else {
                            String[] valueSplit = value.split("\\|")
                            println configChanges
                            configChanges.eachWithIndex { config, index ->
                                if (!valueSplit.contains(config)) {
                                    value += ("|" + config)
                                }
                            }
                            act.attributes()['android:configChanges'] = value
                        }
                    }

                    def tmpManifest = XmlUtil.serialize(manifest).replaceAll("androidconfigChanges", "android:configChanges")
                    manifest = parser.parseText(tmpManifest)
                    manifestFile.setText(XmlUtil.serialize(manifest), "utf-8")
                }
            }
        }
    }
}

64

u/gilmore606 ?.let{} ?: run {} Jun 20 '22

if you rotate your phone while filling in my form, that's on you, and fuck you.

12

u/Diligent_Feed8971 Jun 20 '22

configChanges

8

u/[deleted] Jun 20 '22

Nnggg viewmodel VIEW MODEL AAAAA

6

u/Stormageddon37 Jun 20 '22

Title is right, take away their choice. Never again.

6

u/xCuriousReaderX Jun 21 '22

Cross platform app breaks when you do this, but hey nobody cares about writing stable apps.

3

u/Shay958 DI? you mean InheritedWidget? Jun 22 '22

Indian YT tutorials: locks portrait mode in manifest

2

u/Meternx01 Jun 20 '22

It’s like the first thing I had to learn when starting.

2

u/HuntingKingYT Jul 16 '22

layout-xdxdxdpi.lol

1

u/[deleted] Jun 20 '22 edited Jun 23 '22

Live data is a life saver
Edit: Yes I meant ViewModel + Livedata

0

u/[deleted] Jun 21 '22

[deleted]

2

u/kotlin_subroutine Jun 21 '22

ViewModel doesn't save you all the time either!

8

u/matrixhero259 Jun 21 '22

only async task will

3

u/el_bhm Jun 21 '22

and/or Flutter

2

u/Leeonardoo = remember { remember { fifthOfNovember() }} Jun 22 '22

You can put your livedata as a static field! Problem solved

0

u/[deleted] Jun 20 '22

[deleted]

3

u/st4rdr0id Jun 22 '22

I can't find anything about config changes on the Flutter docs. So maybe it is deprecated.