-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix fragment observation, replace contentprovider with initializer, m…
…odernization
- Loading branch information
Showing
26 changed files
with
174 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/src/debug/kotlin/com/pnuema/android/savestateobserver/app/AppInitializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.pnuema.android.savestateobserver.app | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import androidx.startup.Initializer | ||
import com.pnuema.android.savestateobserver.OversizeBundleRegistrar | ||
|
||
class AppInitializer: Initializer<Unit> { | ||
override fun create(context: Context) { | ||
OversizeBundleRegistrar.register { stringifyBundle -> | ||
Log.e( | ||
"AppBundleWorker", | ||
"OVERSIZE BUNDLE DETECTED: $stringifyBundle" | ||
) | ||
} | ||
} | ||
|
||
override fun dependencies(): MutableList<Class<out Initializer<*>>> = mutableListOf() | ||
|
||
} |
31 changes: 0 additions & 31 deletions
31
app/src/debug/kotlin/com/pnuema/android/savestateobserver/app/BaseActivity.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.pnuema.android.savestateobserver.app"> | ||
|
||
<application | ||
android:fullBackupContent="true" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
|
||
<activity android:name=".MainActivity" | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<provider | ||
android:name="androidx.startup.InitializationProvider" | ||
android:authorities="${applicationId}.androidx-startup" | ||
android:exported="false" | ||
tools:node="merge"> | ||
<meta-data | ||
android:name="com.pnuema.android.savestateobserver.app.AppInitializer" | ||
android:value="androidx.startup" /> | ||
</provider> | ||
</application> | ||
|
||
</manifest> |
29 changes: 29 additions & 0 deletions
29
app/src/main/kotlin/com/pnuema/android/savestateobserver/app/BundleGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.pnuema.android.savestateobserver.app | ||
|
||
import android.os.Bundle | ||
import java.util.* | ||
|
||
object BundleGenerator { | ||
/** | ||
* Generate oversize bundle | ||
*/ | ||
fun Bundle.generateOversizeBundle() = apply { | ||
putInt("Integer", 1234) | ||
putString("String", "StringTest") | ||
putFloat("Float", 12.34F) | ||
|
||
val innerBundle = Bundle() | ||
innerBundle.putInt("Integer", 5678) | ||
innerBundle.putString("String", "InnerStringTest") | ||
innerBundle.putFloat("Float", 56.78F) | ||
|
||
//generate 50k of data for the bundle | ||
var bigString = "" | ||
while (bigString.length < 50000) { | ||
bigString += UUID.randomUUID().toString() | ||
} | ||
innerBundle.putString("BigString", bigString) | ||
|
||
putBundle("innerBundle", innerBundle) | ||
} | ||
} |
34 changes: 11 additions & 23 deletions
34
app/src/main/kotlin/com/pnuema/android/savestateobserver/app/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,21 @@ | ||
package com.pnuema.android.savestateobserver.app | ||
|
||
import android.os.Bundle | ||
import java.util.* | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.commit | ||
import com.pnuema.android.savestateobserver.app.BundleGenerator.generateOversizeBundle | ||
|
||
class MainActivity : BaseActivity() { | ||
override fun onSaveInstanceState(outState: Bundle) { | ||
outState.putInt("Integer", 1234) | ||
outState.putString("String", "StringTest") | ||
outState.putFloat("Float", 12.34F) | ||
|
||
val innerBundle = Bundle() | ||
innerBundle.putInt("Integer", 5678) | ||
innerBundle.putString("String", "InnerStringTest") | ||
innerBundle.putFloat("Float", 56.78F) | ||
class MainActivity : AppCompatActivity(R.layout.activity_main) { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
//generate 50k of data for the bundle | ||
var bigString = "" | ||
while (bigString.length < 50000) { | ||
bigString += UUID.randomUUID().toString() | ||
supportFragmentManager.commit { | ||
replace(R.id.fragment_container_view, MainFragment.newInstance()) | ||
} | ||
innerBundle.putString("BigString", bigString) | ||
|
||
outState.putBundle("innerBundle", innerBundle) | ||
|
||
super.onSaveInstanceState(outState) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
override fun onSaveInstanceState(outState: Bundle) { | ||
outState.generateOversizeBundle() | ||
super.onSaveInstanceState(outState) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/kotlin/com/pnuema/android/savestateobserver/app/MainFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.pnuema.android.savestateobserver.app | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import com.pnuema.android.savestateobserver.app.BundleGenerator.generateOversizeBundle | ||
|
||
/** | ||
* A simple [Fragment] subclass. | ||
* Use the [MainFragment.newInstance] factory method to | ||
* create an instance of this fragment. | ||
*/ | ||
class MainFragment private constructor() : Fragment(R.layout.fragment_main) { | ||
companion object { | ||
fun newInstance() = MainFragment().apply { | ||
arguments = Bundle().generateOversizeBundle() //TODO detect oversize arguments | ||
} | ||
} | ||
|
||
override fun onSaveInstanceState(outState: Bundle) { | ||
outState.generateOversizeBundle() | ||
super.onSaveInstanceState(outState) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
<FrameLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/fragment_container_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
tools:context=".MainActivity"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/instructions"/> | ||
|
||
</LinearLayout> | ||
tools:context=".MainActivity" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainFragment"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/instructions" | ||
android:textSize="24sp" | ||
android:textAlignment="center" | ||
android:layout_gravity="center"/> | ||
|
||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<resources> | ||
<string name="app_name">SaveStateObserver</string> | ||
<string name="instructions">Minimize this app while watching the LogCat to see the results</string> | ||
<string name="instructions">Minimize this app while watching LogCat to see the results</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/src/release/kotlin/com/pnuema/android/savestateobserver/app/AppInitializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.pnuema.android.savestateobserver.app | ||
|
||
import android.content.Context | ||
import androidx.startup.Initializer | ||
|
||
class AppInitializer: Initializer<Unit> { | ||
override fun create(context: Context) = Unit | ||
override fun dependencies(): MutableList<Class<out Initializer<*>>> = mutableListOf() | ||
} |
5 changes: 0 additions & 5 deletions
5
app/src/release/kotlin/com/pnuema/android/savestateobserver/app/BaseActivity.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
savestateobserver/src/main/java/com/pnuema/android/savestateobserver/BaseContentProvider.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...ver/src/main/java/com/pnuema/android/savestateobserver/SaveStateLibraryContentProvider.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.