Quantcast
Channel: xda-developers - Android Software and Hacking General [Developers Only]
Viewing all articles
Browse latest Browse all 3614

[DEV] [SMALI] A Few Custom Views

$
0
0
Hey XDA,

I've been making a number of custom Views for my own use, and figured I'd share a few of them, in case anyone else finds them useful. These are all ready-made smali files, that can be dropped into any app you'd like to use them in, no IDs or anything needed. You're welcome to use them for personal use, but if you use any of them in any other release, please send me a PM with a link to the release, and be sure to give appropriate credit. ;)

Anyway, what's included:

CPUFrequency
  • Extends TextView.
  • Shows current CPU frequency and unit (MHz or GHz, depending on the current value).
  • Updates once per second.

CPUTemperature
  • Extends TextView.
  • Shows current CPU temperature and unit.
  • Click to toggle between Fahrenheit and Celsius.
  • Updates once per second.

BatteryVoltage
  • Extends TextView.
  • Shows current battery voltage in mV.
  • Updates once per second.

BatteryTemperature
  • Extends TextView.
  • Shows current battery temperature and unit.
  • Click to toggle between Fahrenheit and Celsius.
  • Updates once per second.

CurrentNetwork
  • Extends TextView.
  • Shows SSID of currently connected WiFi network.
  • If WiFi is off or disconnected, shows carrier name.
  • If no WiFi or mobile network is connected, shows "Network Unavailable".
  • Updates whenever connection status changes.
  • This View requires two permissions: android.permission.ACCESS_WIFI_STATE and android.permission.ACCESS_NETWORK_STATE (These permissions already exist in framework-res andSystemUI).

SelfAnimatingImageView
  • Extends ImageView.
  • Automatically begins any XML frame animation or vector animation (set with android:src) when they come into focus, without any additional code required.

These Views only animate/update themselves while the screen is on and they are visible/in focus, so there shouldn't be any memory leaks or anything. The above descriptions pretty much explain them, but if you want to see them, you can download a sample app here:
Quote:

sample.apk
md5: 9225d2ad828830de2bfd45f936fb3352
***Note: The sample apk asks for two permissions. These are for the CurrentNetwork View, as explained above. Also, it is for Lollipop only, due to the inclusion of an animated-vector example.

Usage
To use, simply copy the smali files into your decompiled apk (preserving the folder structure), and use them in any layout, like this:
Code:

<com.android.morningstar.NameOfCustomView android:layout_width="wrap_content" android:layout_height="wrap_content" etc... />
All standard TextView and ImageView attributes still work, though for the extended TextViews, android:text isn't needed.

Here's part of a layout where I'm using all the TextViews ('thumper' is the WiFi SSID):


Download
All of the Views are in a single zip file, and any that you don't use can be deleted.
Quote:

Custom Views.zip
md5: 80c2cd01fd65a7733e538303a5ecab60

Attached Files
File Type: zip Custom Views.zip - [Click for QR Code] (20.0 KB)

Viewing all articles
Browse latest Browse all 3614

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>