-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now that LeakCanary 2.0 is stable it's time we simplified things. I thought about keeping two separate modules for each of the versions, but I figure while DebugDrawer isn't 1.0 yet we can take the hit of the breaking change. Also this PR bumps a few dependencies. It's been a while!
- Loading branch information
1 parent
65c9381
commit 226d8a6
Showing
17 changed files
with
69 additions
and
147 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
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,18 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="au.com.gridstone.debugdrawer.leakcanary" | ||
> | ||
|
||
<application> | ||
|
||
<!-- Prevent LeakCanary from creating a launcher icon. The debug drawer will provide access. --> | ||
<activity android:name="com.squareup.leakcanary.internal.DisplayLeakActivity"> | ||
<intent-filter tools:node="removeAll"/> | ||
</activity> | ||
|
||
</application> | ||
|
||
</manifest> | ||
<manifest package="au.com.gridstone.debugdrawer.leakcanary"/> |
44 changes: 31 additions & 13 deletions
44
...er-leakcanary/src/main/kotlin/au/com/gridstone/debugdrawer/leakcanary/LeakCanaryModule.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,27 +1,45 @@ | ||
package au.com.gridstone.debugdrawer.leakcanary | ||
|
||
import android.content.Intent | ||
import android.content.Context | ||
import android.content.Context.MODE_PRIVATE | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import android.widget.Switch | ||
import au.com.gridstone.debugdrawer.DebugDrawerModule | ||
import com.squareup.leakcanary.internal.DisplayLeakActivity | ||
import leakcanary.LeakCanary | ||
|
||
/** | ||
* Displays a button in the drawer to open LeakCanary's leak list activity. Note that including this | ||
* module in your project removes the LeakCanary launcher icon, effectively making the debug | ||
* drawer the main entry point into your leak list. | ||
*/ | ||
class LeakCanaryModule : DebugDrawerModule { | ||
object LeakCanaryModule : DebugDrawerModule { | ||
|
||
private const val SHARED_PREFS_NAME = "DebugDrawer_LeakCanary" | ||
private const val KEY_ENABLE_HEAP_DUMPS = "enableHeapDumps" | ||
|
||
override fun onAttach(context: Context) { | ||
val sharedPrefs = context.getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE) | ||
val enableHeapDumps = sharedPrefs.getBoolean(KEY_ENABLE_HEAP_DUMPS, true) | ||
LeakCanary.config = LeakCanary.config.copy(dumpHeap = enableHeapDumps) | ||
} | ||
|
||
override fun onCreateView(parent: ViewGroup): View { | ||
val button = Button(parent.context) | ||
button.setText(R.string.drawer_leakcanaryButton) | ||
val inflater = LayoutInflater.from(parent.context) | ||
val view: View = inflater.inflate(R.layout.drawer_leakcanary, parent, false) | ||
|
||
val sharedPrefs = parent.context.getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE) | ||
val enableHeapDumps = sharedPrefs.getBoolean(KEY_ENABLE_HEAP_DUMPS, true) | ||
|
||
val toggle: Switch = view.findViewById(R.id.drawer_leakcanaryToggle) | ||
toggle.isChecked = enableHeapDumps | ||
toggle.setOnCheckedChangeListener { _, checked -> | ||
LeakCanary.config = LeakCanary.config.copy(dumpHeap = checked) | ||
sharedPrefs.edit().putBoolean(KEY_ENABLE_HEAP_DUMPS, checked).apply() | ||
} | ||
|
||
val button: Button = view.findViewById(R.id.drawer_leakcanaryViewButton) | ||
button.setOnClickListener { | ||
val intent = Intent(parent.context, DisplayLeakActivity::class.java) | ||
parent.context.startActivity(intent) | ||
parent.context.startActivity(LeakCanary.newLeakDisplayActivityIntent()) | ||
} | ||
|
||
return button | ||
return view | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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,5 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<resources> | ||
<string name="drawer_leakcanaryButton">Leak analysis</string> | ||
<string name="drawer_leakcanaryButton">View leaks</string> | ||
<string name="drawer_leakcanaryToggleLabel">Enable heap dumps</string> | ||
</resources> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
...r-leakcanary2/src/main/kotlin/au/com/gridstone/debugdrawer/leakcanary/LeakCanaryModule.kt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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