cwac-strictmodeex


Source link: https://github.com/commonsguy/cwac-strictmodeex

CWAC StrictModeEx: Punishment for the Bad Code In Your App

StrictMode is a handy feature in API Level 9 and higher, telling you where your Android application is doing things it probably should not on the main application thread.

In the spirit of StrictMode, the StrictModeEx project offers classes to help you diagnose similar sorts of problems beyond what StrictMode itself offers.

Right now, that consists of one class: StrictAdapter. This ListAdapter wrapper will log slow-running getView() calls, plus optionally give you an overall performance view on how your Adapter is doing in the code you control.

Installation

This Android library project is available as a JAR. If you wish to use the JAR, you will need to also add the JAR from the CWAC-Adapter project to your project.

NOTE: The JAR name, as of v0.3.1, has a cwac- prefix, to help distinguish it from other JARs.

Also note that if you plan to use this as an Android library project in source form, you will also need to download the CWAC-Adapter project (and, if needed, modify this project's configuration to point to your copy of CWAC-Adapter's library project). Alternatively, download the CWAC-Adapter JAR into the libs/ directory of your clone of this project and remove the dependency on the CWAC-Adapter library project.

This project is also available as an artifact for use with Gradle. To use that, add the following blocks to your build.gradle file:

repositories {

  maven {

url "https://s3.amazonaws.com/repo.commonsware.com"
  
}
 
}
  dependencies {

  compile 'com.commonsware.cwac:strictmodeex:0.3.+' 
}

Or, if you cannot use SSL, use http://repo.commonsware.com for the repository URL. This should automatically pull down the CWAC-Adapter dependency.

Usage: StrictAdapter

Normally, you create your own ListAdapter (e.g., an ArrayAdapter) and give that to your AdapterView (e.g., setListAdapter() on a ListFragment).

Now, you create your own ListAdapter, wrap it in a StrictAdapter, and put the StrictAdapter in the AdapterView. To do this, just use the StrictAdapter constructor, which takes your regular ListAdapter as a parameter.

By default, the StrictAdapter will log all calls to getView() that take longer than 1ms (1000000ns). You can alter this by calling setThreshold(), which takes the desired threshold time in nanoseconds.

Any getView() call that takes longer than the threshold is logged with error severity to LogCat. By default, the tag will be StrictAdapter, though you can change this via a call to setLogTag().

If you want, you can dump the overall performance metrics to LogCat (debug severity) via a call to dumpResultsToLog(). This will report the total number of getView() calls, the number that were penalized (i.e., exceeded the threshold), the total time across all the calls, and the mean time per call. A call to reset() clears the statistics.

Even on production hardware with a trivial ListAdapter (such as the one in the demo/ sub-project), you will find getView() calls that exceed the default 1ms threshold. It should only be a few percent of the total number of calls, and it could easily represent background work from other processes that happened to steal a time slice while your getView() was running.

Version

This is version v0.3.2 of this module, meaning it is brand-spankin' new.

Demo

In the demo/ sub-project you will find a sample activity that demonstrates the use of StrictAdapter.

License

The code in this project is licensed under the Apache Software License 2.0, per the terms of the included LICENSE file.

Questions

If you have questions regarding the use of this code, please post a question on StackOverflow tagged with commonsware-cwac and android after searching to see if there already is an answer. Be sure to indicate what CWAC module you are having issues with, and be sure to include source code and stack traces if you are encountering crashes.

If you have encountered what is clearly a bug, or a feature request, please post an issue. Be certain to include complete steps for reproducing the issue.

Do not ask for help via Twitter.

Also, if you plan on hacking on the code with an eye for contributing something back, please open an issue that we can use for discussing implementation details. Just lobbing a pull request over the fence may work, but it may not.

Who Made This?

Release Notes

  • v0.3.2: updated for Android Studio 1.0 and new AAR publishing system
  • v0.3.1: Gradle updates, fixed manifest for merging, added cwac- to JAR
  • v0.3.0: migrated to Gradle, published AAR
  • v0.1.0: initial release

Resources

This library is inspired from Chris Banes' Done Discard bar. It has material design already.

WebRTC Live Streaming

An Android client for ProjectRTC.

It is designed to demonstrate WebRTC video calls between androids and/or desktop browsers, but WebRtcClient could be used in other scenarios.

reflection-no-reflection is a proof on concept to create an API that is 100% compatible reflection API, but without any reflection. Performance stuff for Android and Java.

AKA VectorDrawableCompat: A 14+ backport of VectorDrawable.

Create useful .gitignore files for your project.

adk-toolkit exposes an AdkManager to manage UsbManager and UsbAccessory. In this way you don't need to fully understand some background concept about how ADK works but, as soon as possible, you should read ADK official documentation.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes