Mercurial > dwindows
comparison android/DWindows.kt @ 2496:3bf2f08fdc45
Android: Remove ugly workaround for initialization issues.
Solved by a change to AndroidManifest.xml to prevent recreation on
configuration changes. Add some code to detect the changes.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 03 May 2021 07:15:11 +0000 |
parents | 5664c91d03fb |
children | 7b210f156eef |
comparison
equal
deleted
inserted
replaced
2495:5664c91d03fb | 2496:3bf2f08fdc45 |
---|---|
2 | 2 |
3 import android.content.ClipData | 3 import android.content.ClipData |
4 import android.content.ClipboardManager | 4 import android.content.ClipboardManager |
5 import android.content.DialogInterface | 5 import android.content.DialogInterface |
6 import android.content.pm.ActivityInfo | 6 import android.content.pm.ActivityInfo |
7 import android.content.res.Configuration | |
7 import android.graphics.drawable.GradientDrawable | 8 import android.graphics.drawable.GradientDrawable |
8 import android.media.AudioManager | 9 import android.media.AudioManager |
9 import android.media.ToneGenerator | 10 import android.media.ToneGenerator |
10 import android.os.Bundle | 11 import android.os.Bundle |
11 import android.os.Handler | 12 import android.os.Handler |
55 super.onCreate(savedInstanceState) | 56 super.onCreate(savedInstanceState) |
56 | 57 |
57 // Turn on rotation | 58 // Turn on rotation |
58 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR) | 59 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR) |
59 | 60 |
60 // Get the Android app path | 61 // We only want to call this once when the app starts up |
61 val m = packageManager | 62 // By default Android will call onCreate for rotation and other |
62 var s = packageName | 63 // changes. This is incompatible with Dynamic Windows... |
63 val p = m.getPackageInfo(s!!, 0) | 64 // Make sure the following is in your AndroidManifest.xml |
64 s = p.applicationInfo.dataDir | 65 // android:configChanges="orientation|screenSize|screenLayout|keyboardHidden" |
65 | 66 if(savedInstanceState == null) { |
66 // Initialize the Dynamic Windows code... | 67 // Get the Android app path |
67 // This will start a new thread that calls the app's dwmain() | 68 val m = packageManager |
68 dwindowsInit(s) | 69 var s = packageName |
70 val p = m.getPackageInfo(s!!, 0) | |
71 s = p.applicationInfo.dataDir | |
72 | |
73 // Initialize the Dynamic Windows code... | |
74 // This will start a new thread that calls the app's dwmain() | |
75 dwindowsInit(s) | |
76 } | |
77 } | |
78 | |
79 override fun onConfigurationChanged(newConfig: Configuration) { | |
80 super.onConfigurationChanged(newConfig) | |
81 | |
82 // Checks the orientation of the screen | |
83 if (newConfig.orientation === Configuration.ORIENTATION_LANDSCAPE) { | |
84 Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show() | |
85 } else if (newConfig.orientation === Configuration.ORIENTATION_PORTRAIT) { | |
86 Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show() | |
87 } | |
69 } | 88 } |
70 | 89 |
71 /* | 90 /* |
72 * These are the Android calls to actually create the UI... | 91 * These are the Android calls to actually create the UI... |
73 * forwarded from the C Dynamic Windows API | 92 * forwarded from the C Dynamic Windows API |