├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── libs └── color-picker │ ├── build.gradle │ ├── proguard-project.txt │ ├── proguard.cfg │ └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── att │ │ └── preference │ │ └── colorpicker │ │ ├── AlphaPatternDrawable.java │ │ ├── ColorPickerDialog.java │ │ ├── ColorPickerPanelView.java │ │ ├── ColorPickerPreference.java │ │ ├── ColorPickerView.java │ │ └── Test.java │ └── res │ ├── drawable-hdpi │ └── icon.png │ ├── drawable-ldpi │ └── icon.png │ ├── drawable-mdpi │ └── icon.png │ ├── layout-land │ └── dialog_color_picker.xml │ ├── layout │ └── dialog_color_picker.xml │ ├── values │ ├── integer.xml │ └── strings.xml │ └── xml │ └── settings.xml ├── moss ├── .gitignore ├── build.gradle ├── proguard.cfg └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ ├── config.html │ ├── default.conf │ ├── ebuprof.conf │ ├── error.conf │ ├── full.conf │ ├── help.css │ ├── help.html │ ├── network.conf │ ├── objects.html │ └── process.conf │ ├── java │ └── org │ │ └── mosspaper │ │ ├── Common.java │ │ ├── Config.java │ │ ├── ConfigException.java │ │ ├── DataService.java │ │ ├── Env.java │ │ ├── HelpActivity.java │ │ ├── Layout.java │ │ ├── MossException.java │ │ ├── OverridesActivity.java │ │ ├── PackageDatabase.java │ │ ├── PackageListActivity.java │ │ ├── ParseException.java │ │ ├── Parser.java │ │ ├── SettingsActivity.java │ │ ├── WallPaper.java │ │ ├── objects │ │ ├── AbsAlign.java │ │ ├── AbsBarObject.java │ │ ├── AbsGraphObject.java │ │ ├── AbsMossObject.java │ │ ├── AbsTop.java │ │ ├── AlignC.java │ │ ├── AlignR.java │ │ ├── Battery.java │ │ ├── BatteryBar.java │ │ ├── BatteryPercent.java │ │ ├── BatteryReceiver.java │ │ ├── BatteryTime.java │ │ ├── Color.java │ │ ├── Cpu.java │ │ ├── CpuBar.java │ │ ├── CpuFreqProvider.java │ │ ├── CpuGraph.java │ │ ├── DataProvider.java │ │ ├── DevName.java │ │ ├── DownSpeed.java │ │ ├── DownSpeedGraph.java │ │ ├── Entropy.java │ │ ├── FSBar.java │ │ ├── FSFree.java │ │ ├── FSJni.java │ │ ├── FSSize.java │ │ ├── FSUsed.java │ │ ├── FSUsedPerc.java │ │ ├── Font.java │ │ ├── Freq.java │ │ ├── Goto.java │ │ ├── Graphable.java │ │ ├── HRule.java │ │ ├── Image.java │ │ ├── Interval.java │ │ ├── Kernel.java │ │ ├── Length.java │ │ ├── LoadAvg.java │ │ ├── Machine.java │ │ ├── Mem.java │ │ ├── MemBar.java │ │ ├── MemMax.java │ │ ├── MemPerc.java │ │ ├── MossObject.java │ │ ├── Nodename.java │ │ ├── Offset.java │ │ ├── PortMon.java │ │ ├── PortMonProvider.java │ │ ├── Printf.java │ │ ├── ProcEntropy.java │ │ ├── ProcList.java │ │ ├── ProcLoadAvg.java │ │ ├── ProcMemInfo.java │ │ ├── ProcNetDev.java │ │ ├── Processes.java │ │ ├── ProcsRunning.java │ │ ├── Realtime.java │ │ ├── StippledHRule.java │ │ ├── Swap.java │ │ ├── SwapBar.java │ │ ├── SwapMax.java │ │ ├── SwapPerc.java │ │ ├── SysName.java │ │ ├── TextObjects.java │ │ ├── Time.java │ │ ├── Top.java │ │ ├── TopMem.java │ │ ├── TotalDown.java │ │ ├── TotalUp.java │ │ ├── UnameProvider.java │ │ ├── UpSpeed.java │ │ ├── UpSpeedGraph.java │ │ ├── UpdateManager.java │ │ ├── Uptime.java │ │ ├── VGoto.java │ │ └── VOffset.java │ │ ├── prefs │ │ ├── IntervalPreference.java │ │ ├── PrefUtils.java │ │ └── SizePreference.java │ │ └── util │ │ ├── Bar.java │ │ ├── Graph.java │ │ └── RRDList.java │ ├── jni │ ├── Android.mk │ ├── native_functions.c │ └── portmon.c │ └── res │ ├── drawable-hdpi │ └── icon.png │ ├── drawable-mdpi │ └── icon.png │ ├── drawable │ ├── ex_icon.xml │ └── white_box.xml │ ├── layout │ ├── act_help.xml │ ├── act_packages.xml │ ├── dia_errors.xml │ ├── dia_interval.xml │ ├── item_config.xml │ ├── item_device.xml │ └── pref_color_block.xml │ ├── menu │ └── settings_menu.xml │ ├── values │ ├── arrays.xml │ ├── attrs.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ ├── mosspaper.xml │ ├── prefs_menu.xml │ └── prefs_overrides.xml ├── scripts └── gendocs.pl └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | local.properties 3 | libprojects/abs 4 | libprojects/facebook-android-sdk-3.0 5 | gen 6 | bin 7 | keys 8 | .idea 9 | *.swp 10 | *.pyc 11 | *.db 12 | *.so 13 | TODO 14 | *.log 15 | .classpath 16 | .settings 17 | .project 18 | *.keystore 19 | usercontext.properties 20 | keys.xml 21 | 22 | .gradle 23 | /local.properties 24 | /.idea/workspace.xml 25 | .DS_Store 26 | 27 | # built application files 28 | *.apk 29 | *.ap_ 30 | 31 | # files for the dex VM 32 | *.dex 33 | 34 | # Java class files 35 | *.class 36 | 37 | # generated files 38 | bin/ 39 | gen/ 40 | 41 | # Local configuration file (sdk path, etc) 42 | local.properties 43 | 44 | # Eclipse project files 45 | .classpath 46 | .project 47 | 48 | # Android Studio 49 | .idea/ 50 | .gradle 51 | /*/local.properties 52 | /*/out 53 | /*/*/build 54 | /*/*/production 55 | *.iml 56 | *.iws 57 | 58 | AirBitz/airbitz/src/main/res/values/com_crashlytics_export_strings.xml 59 | all_keys.xml 60 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "jni/tcp-portmon"] 2 | path = moss/src/main/jni/tcp-portmon 3 | url = git://github.com/teneighty/tcp-portmon.git 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Moss 2 | ==== 3 | 4 | Moss is a [Conky][conky] like live wallpaper for android. It provides system statistics 5 | such as uptime, cpu usage, network usage, top processes, and battery level. 6 | It is highly configurable. Configuration tries to closely follow [Conky's][conky] syntax. 7 | 8 | For example configurations please see [the samples on the Moss site][samples]. 9 | 10 | # Build from Command Line 11 | 12 | Be sure you have jdk1.7, android-ndk-r10 and android-sdk SDK 21 and 21.0.+ build tools. 13 | 14 | # setup your ndk patch 15 | echo ndk.dir=${ANDROID_NDK} > local.properties 16 | 17 | # Sorry about the submodules 18 | git submodule init && git submodule update 19 | 20 | # build and install 21 | ./gradlew installDebug 22 | 23 | [conky]: http://www.conky.com 24 | [samples]: http://teneighty.github.com/moss/samples.html 25 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | ext { 2 | compileSdkVersion = 21 3 | buildToolsVersion = "21.1.1" 4 | } 5 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Settings specified in this file will override any Gradle settings 5 | # configured through the IDE. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teneighty/moss/9a9eb84c97eea905be30aaff152b31e964ffa135/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jun 09 09:34:28 PDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /libs/color-picker/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:1.3.0' 7 | } 8 | } 9 | apply plugin: 'android-library' 10 | 11 | android { 12 | compileSdkVersion rootProject.ext.compileSdkVersion 13 | buildToolsVersion rootProject.ext.buildToolsVersion 14 | 15 | defaultConfig { 16 | minSdkVersion 8 17 | targetSdkVersion 21 18 | versionCode 1 19 | versionName "0.1" 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /libs/color-picker/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /libs/color-picker/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class com.android.vending.licensing.ILicensingService 14 | 15 | -keepclasseswithmembernames class * { 16 | native ; 17 | } 18 | 19 | -keepclasseswithmembernames class * { 20 | public (android.content.Context, android.util.AttributeSet); 21 | } 22 | 23 | -keepclasseswithmembernames class * { 24 | public (android.content.Context, android.util.AttributeSet, int); 25 | } 26 | 27 | -keepclassmembers enum * { 28 | public static **[] values(); 29 | public static ** valueOf(java.lang.String); 30 | } 31 | 32 | -keep class * implements android.os.Parcelable { 33 | public static final android.os.Parcelable$Creator *; 34 | } 35 | -------------------------------------------------------------------------------- /libs/color-picker/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /libs/color-picker/src/main/java/com/att/preference/colorpicker/AlphaPatternDrawable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Daniel Nilsson 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.att.preference.colorpicker; 18 | 19 | import android.graphics.Bitmap; 20 | import android.graphics.Canvas; 21 | import android.graphics.ColorFilter; 22 | import android.graphics.Paint; 23 | import android.graphics.Rect; 24 | import android.graphics.Bitmap.Config; 25 | import android.graphics.drawable.Drawable; 26 | 27 | /** 28 | * This drawable that draws a simple white and gray chessboard pattern. 29 | * It's pattern you will often see as a background behind a 30 | * partly transparent image in many applications. 31 | * @author Daniel Nilsson 32 | */ 33 | public class AlphaPatternDrawable extends Drawable { 34 | 35 | private int mRectangleSize = 10; 36 | 37 | private Paint mPaint = new Paint(); 38 | private Paint mPaintWhite = new Paint(); 39 | private Paint mPaintGray = new Paint(); 40 | 41 | private int numRectanglesHorizontal; 42 | private int numRectanglesVertical; 43 | 44 | /** 45 | * Bitmap in which the pattern will be cahched. 46 | */ 47 | private Bitmap mBitmap; 48 | 49 | public AlphaPatternDrawable(int rectangleSize) { 50 | mRectangleSize = rectangleSize; 51 | mPaintWhite.setColor(0xffffffff); 52 | mPaintGray.setColor(0xffcbcbcb); 53 | } 54 | 55 | @Override 56 | public void draw(Canvas canvas) { 57 | canvas.drawBitmap(mBitmap, null, getBounds(), mPaint); 58 | } 59 | 60 | @Override 61 | public int getOpacity() { 62 | return 0; 63 | } 64 | 65 | @Override 66 | public void setAlpha(int alpha) { 67 | throw new UnsupportedOperationException("Alpha is not supported by this drawwable."); 68 | } 69 | 70 | @Override 71 | public void setColorFilter(ColorFilter cf) { 72 | throw new UnsupportedOperationException("ColorFilter is not supported by this drawwable."); 73 | } 74 | 75 | @Override 76 | protected void onBoundsChange(Rect bounds) { 77 | super.onBoundsChange(bounds); 78 | 79 | int height = bounds.height(); 80 | int width = bounds.width(); 81 | 82 | numRectanglesHorizontal = (int) Math.ceil((width / mRectangleSize)); 83 | numRectanglesVertical = (int) Math.ceil(height / mRectangleSize); 84 | 85 | generatePatternBitmap(); 86 | 87 | } 88 | 89 | /** 90 | * This will generate a bitmap with the pattern 91 | * as big as the rectangle we were allow to draw on. 92 | * We do this to chache the bitmap so we don't need to 93 | * recreate it each time draw() is called since it 94 | * takes a few milliseconds. 95 | */ 96 | private void generatePatternBitmap(){ 97 | 98 | if(getBounds().width() <= 0 || getBounds().height() <= 0){ 99 | return; 100 | } 101 | 102 | mBitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888); 103 | Canvas canvas = new Canvas(mBitmap); 104 | 105 | Rect r = new Rect(); 106 | boolean verticalStartWhite = true; 107 | for (int i = 0; i <= numRectanglesVertical; i++) { 108 | 109 | boolean isWhite = verticalStartWhite; 110 | for (int j = 0; j <= numRectanglesHorizontal; j++) { 111 | 112 | r.top = i * mRectangleSize; 113 | r.left = j * mRectangleSize; 114 | r.bottom = r.top + mRectangleSize; 115 | r.right = r.left + mRectangleSize; 116 | 117 | canvas.drawRect(r, isWhite ? mPaintWhite : mPaintGray); 118 | 119 | isWhite = !isWhite; 120 | } 121 | 122 | verticalStartWhite = !verticalStartWhite; 123 | 124 | } 125 | 126 | } 127 | 128 | } -------------------------------------------------------------------------------- /libs/color-picker/src/main/java/com/att/preference/colorpicker/ColorPickerDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Daniel Nilsson 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.att.preference.colorpicker; 18 | 19 | import android.app.Dialog; 20 | import android.content.Context; 21 | import android.graphics.PixelFormat; 22 | import android.view.LayoutInflater; 23 | import android.view.View; 24 | import android.widget.LinearLayout; 25 | 26 | public class ColorPickerDialog 27 | extends 28 | Dialog 29 | implements 30 | ColorPickerView.OnColorChangedListener, 31 | View.OnClickListener { 32 | 33 | private ColorPickerView mColorPicker; 34 | 35 | private ColorPickerPanelView mOldColor; 36 | private ColorPickerPanelView mNewColor; 37 | 38 | private OnColorChangedListener mListener; 39 | 40 | public interface OnColorChangedListener { 41 | public void onColorChanged(int color); 42 | } 43 | 44 | public ColorPickerDialog(Context context, int initialColor) { 45 | super(context); 46 | 47 | init(initialColor); 48 | } 49 | 50 | private void init(int color) { 51 | // To fight color branding. 52 | getWindow().setFormat(PixelFormat.RGBA_8888); 53 | 54 | setUp(color); 55 | 56 | } 57 | 58 | private void setUp(int color) { 59 | 60 | LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 61 | 62 | View layout = inflater.inflate(R.layout.dialog_color_picker, null); 63 | 64 | setContentView(layout); 65 | 66 | setTitle(R.string.dialog_color_picker); 67 | 68 | mColorPicker = (ColorPickerView) layout.findViewById(R.id.color_picker_view); 69 | mOldColor = (ColorPickerPanelView) layout.findViewById(R.id.old_color_panel); 70 | mNewColor = (ColorPickerPanelView) layout.findViewById(R.id.new_color_panel); 71 | 72 | ((LinearLayout) mOldColor.getParent()).setPadding( 73 | Math.round(mColorPicker.getDrawingOffset()), 74 | 0, 75 | Math.round(mColorPicker.getDrawingOffset()), 76 | 0 77 | ); 78 | 79 | mOldColor.setOnClickListener(this); 80 | mNewColor.setOnClickListener(this); 81 | mColorPicker.setOnColorChangedListener(this); 82 | mOldColor.setColor(color); 83 | mColorPicker.setColor(color, true); 84 | 85 | } 86 | 87 | @Override 88 | public void onColorChanged(int color) { 89 | 90 | mNewColor.setColor(color); 91 | 92 | /* 93 | if (mListener != null) { 94 | mListener.onColorChanged(color); 95 | } 96 | */ 97 | 98 | } 99 | 100 | public void setAlphaSliderVisible(boolean visible) { 101 | mColorPicker.setAlphaSliderVisible(visible); 102 | } 103 | 104 | /** 105 | * Set a OnColorChangedListener to get notified when the color 106 | * selected by the user has changed. 107 | * @param listener 108 | */ 109 | public void setOnColorChangedListener(OnColorChangedListener listener){ 110 | mListener = listener; 111 | } 112 | 113 | public int getColor() { 114 | return mColorPicker.getColor(); 115 | } 116 | 117 | @Override 118 | public void onClick(View v) { 119 | if (v.getId() == R.id.old_color_panel) { 120 | return; 121 | } else if (v.getId() == R.id.new_color_panel) { 122 | if (mListener != null) { 123 | mListener.onColorChanged(mNewColor.getColor()); 124 | } 125 | } 126 | dismiss(); 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /libs/color-picker/src/main/java/com/att/preference/colorpicker/ColorPickerPanelView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Daniel Nilsson 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.att.preference.colorpicker; 18 | 19 | import android.content.Context; 20 | import android.graphics.Canvas; 21 | import android.graphics.Paint; 22 | import android.graphics.RectF; 23 | import android.util.AttributeSet; 24 | import android.view.View; 25 | 26 | /** 27 | * This class draws a panel which which will be filled with a color which can be set. 28 | * It can be used to show the currently selected color which you will get from 29 | * the {@link ColorPickerView}. 30 | * @author Daniel Nilsson 31 | * 32 | */ 33 | public class ColorPickerPanelView extends View { 34 | 35 | /** 36 | * The width in pixels of the border 37 | * surrounding the color panel. 38 | */ 39 | private final static float BORDER_WIDTH_PX = 1; 40 | 41 | private float mDensity = 1f; 42 | 43 | private int mBorderColor = 0xff6E6E6E; 44 | private int mColor = 0xff000000; 45 | 46 | private Paint mBorderPaint; 47 | private Paint mColorPaint; 48 | 49 | private RectF mDrawingRect; 50 | private RectF mColorRect; 51 | 52 | private AlphaPatternDrawable mAlphaPattern; 53 | 54 | 55 | public ColorPickerPanelView(Context context){ 56 | this(context, null); 57 | } 58 | 59 | public ColorPickerPanelView(Context context, AttributeSet attrs){ 60 | this(context, attrs, 0); 61 | } 62 | 63 | public ColorPickerPanelView(Context context, AttributeSet attrs, int defStyle) { 64 | super(context, attrs, defStyle); 65 | init(); 66 | } 67 | 68 | private void init(){ 69 | mBorderPaint = new Paint(); 70 | mColorPaint = new Paint(); 71 | mDensity = getContext().getResources().getDisplayMetrics().density; 72 | } 73 | 74 | 75 | @Override 76 | protected void onDraw(Canvas canvas) { 77 | 78 | final RectF rect = mColorRect; 79 | 80 | if(BORDER_WIDTH_PX > 0){ 81 | mBorderPaint.setColor(mBorderColor); 82 | canvas.drawRect(mDrawingRect, mBorderPaint); 83 | } 84 | 85 | if(mAlphaPattern != null){ 86 | mAlphaPattern.draw(canvas); 87 | } 88 | 89 | mColorPaint.setColor(mColor); 90 | 91 | canvas.drawRect(rect, mColorPaint); 92 | } 93 | 94 | @Override 95 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 96 | 97 | int width = MeasureSpec.getSize(widthMeasureSpec); 98 | int height = MeasureSpec.getSize(heightMeasureSpec); 99 | 100 | setMeasuredDimension(width, height); 101 | } 102 | 103 | @Override 104 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 105 | super.onSizeChanged(w, h, oldw, oldh); 106 | 107 | mDrawingRect = new RectF(); 108 | mDrawingRect.left = getPaddingLeft(); 109 | mDrawingRect.right = w - getPaddingRight(); 110 | mDrawingRect.top = getPaddingTop(); 111 | mDrawingRect.bottom = h - getPaddingBottom(); 112 | 113 | setUpColorRect(); 114 | 115 | } 116 | 117 | private void setUpColorRect(){ 118 | final RectF dRect = mDrawingRect; 119 | 120 | float left = dRect.left + BORDER_WIDTH_PX; 121 | float top = dRect.top + BORDER_WIDTH_PX; 122 | float bottom = dRect.bottom - BORDER_WIDTH_PX; 123 | float right = dRect.right - BORDER_WIDTH_PX; 124 | 125 | mColorRect = new RectF(left,top, right, bottom); 126 | 127 | mAlphaPattern = new AlphaPatternDrawable((int)(5 * mDensity)); 128 | 129 | mAlphaPattern.setBounds( 130 | Math.round(mColorRect.left), 131 | Math.round(mColorRect.top), 132 | Math.round(mColorRect.right), 133 | Math.round(mColorRect.bottom) 134 | ); 135 | 136 | } 137 | 138 | /** 139 | * Set the color that should be shown by this view. 140 | * @param color 141 | */ 142 | public void setColor(int color){ 143 | mColor = color; 144 | invalidate(); 145 | } 146 | 147 | /** 148 | * Get the color currently show by this view. 149 | * @return 150 | */ 151 | public int getColor(){ 152 | return mColor; 153 | } 154 | 155 | /** 156 | * Set the color of the border surrounding the panel. 157 | * @param color 158 | */ 159 | public void setBorderColor(int color){ 160 | mBorderColor = color; 161 | invalidate(); 162 | } 163 | 164 | /** 165 | * Get the color of the border surrounding the panel. 166 | */ 167 | public int getBorderColor(){ 168 | return mBorderColor; 169 | } 170 | 171 | } -------------------------------------------------------------------------------- /libs/color-picker/src/main/java/com/att/preference/colorpicker/Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Sergey Margaritov 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.att.preference.colorpicker; 18 | 19 | import android.os.Bundle; 20 | import android.preference.Preference; 21 | import android.preference.Preference.OnPreferenceChangeListener; 22 | import android.preference.PreferenceActivity; 23 | 24 | public class Test extends PreferenceActivity { 25 | /** Called when the activity is first created. */ 26 | @Override 27 | public void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | addPreferencesFromResource(R.xml.settings); 30 | ((ColorPickerPreference)findPreference("color2")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { 31 | 32 | @Override 33 | public boolean onPreferenceChange(Preference preference, Object newValue) { 34 | preference.setSummary(ColorPickerPreference.convertToARGB(Integer.valueOf(String.valueOf(newValue)))); 35 | return true; 36 | } 37 | 38 | }); 39 | ((ColorPickerPreference)findPreference("color2")).setAlphaSliderEnabled(true); 40 | } 41 | } -------------------------------------------------------------------------------- /libs/color-picker/src/main/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teneighty/moss/9a9eb84c97eea905be30aaff152b31e964ffa135/libs/color-picker/src/main/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /libs/color-picker/src/main/res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teneighty/moss/9a9eb84c97eea905be30aaff152b31e964ffa135/libs/color-picker/src/main/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /libs/color-picker/src/main/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teneighty/moss/9a9eb84c97eea905be30aaff152b31e964ffa135/libs/color-picker/src/main/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /libs/color-picker/src/main/res/layout-land/dialog_color_picker.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 24 | 25 | 31 | 32 | 37 | 38 | 49 | 50 | 56 | 57 | 66 | 67 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /libs/color-picker/src/main/res/layout/dialog_color_picker.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 24 | 25 | 32 | 33 | 43 | 44 | 50 | 51 | 57 | 58 | 67 | 68 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /libs/color-picker/src/main/res/values/integer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0xff000000 4 | 0xff00ff00 5 | -------------------------------------------------------------------------------- /libs/color-picker/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World, Main! 5 | ColorPickerPreference 6 | 7 | 8 | Color Picker 9 | Press on Color to apply 10 | 11 | 12 | Category 13 | Color 1 14 | black color by default, set by reference 15 | Color 2 16 | not persistent color\nalpha slider added via code 17 | Color 3 18 | picker with alpha slider 19 | Color 4 20 | color set with HEX code in xml 21 | 22 | -------------------------------------------------------------------------------- /libs/color-picker/src/main/res/xml/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 17 | 24 | 31 | 32 | -------------------------------------------------------------------------------- /moss/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /moss/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:1.3.0' 7 | } 8 | } 9 | apply plugin: 'android' 10 | 11 | android { 12 | compileSdkVersion rootProject.ext.compileSdkVersion 13 | buildToolsVersion rootProject.ext.buildToolsVersion 14 | 15 | defaultConfig { 16 | minSdkVersion 8 17 | targetSdkVersion 21 18 | versionCode 6 19 | versionName "0.6" 20 | } 21 | } 22 | 23 | dependencies { 24 | compile project(':libs:color-picker') 25 | } 26 | 27 | -------------------------------------------------------------------------------- /moss/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /moss/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 62 | 63 | 65 | 66 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /moss/src/main/assets/config.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Config Variables 4 | 5 | 6 | 7 |
8 |

Settings

9 | 10 |
11 |

color_add

12 |

13 | Added or override colors to color dictionary 14 | 15 |

16 |
17 |
18 | 19 |
20 |

alignment

21 |

22 | Set the alignment the layout 23 | 24 |

25 |
26 |
27 | 28 |
29 |

background_color

30 |

31 | The background color for the wallpaper. 32 | 33 |

34 |
35 |
36 | 37 |
38 |

background_image

39 |

40 | An absolute path to a background image. /sdcard/moss/bg-fav.png 41 | 42 |

43 |
44 |
45 | 46 |
47 |

background_mod

48 |

49 | Like xsetroot's mod parameter, allows the user to create a plaid like 50 | pattern. 51 | 52 |

53 |
54 |
55 | 56 |
57 |

default_color

58 |

59 | Set the default color of the paint. 60 | 61 |

62 |
63 |
64 | 65 |
66 |

default_outline_color

67 |

68 | default outline color. 69 | 70 |

71 |
72 |
73 | 74 |
75 |

default_shade_color

76 |

77 | default shade color. 78 | 79 |

80 |
81 |
82 | 83 |
84 |

uppercase

85 |

86 | All text in uppercase 87 | 88 |

89 |
90 |
91 | 92 |
93 |

disable_auto_reload

94 |

95 | Enable to disable file observer (inotify) based auto config reload. 96 | 97 |

98 |
99 |
100 | 101 |
102 |

font

103 |

104 | Sets the default font for the display. 105 | 106 |

107 |
108 |
109 | 110 |
111 |

gap_x

112 |

113 | Additional horizonal spacing 114 | 115 |

116 |
117 |
118 | 119 |
120 |

gap_y

121 |

122 | Additional vertical spacing 123 | 124 |

125 |
126 |
127 | 128 |
129 |

update_interval

130 |

131 | Determines how frequently the data, and display are updated. 132 | 133 |

134 |
135 |
136 | 137 | 138 |
139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /moss/src/main/assets/default.conf: -------------------------------------------------------------------------------- 1 | # default.conf 2 | 3 | update_interval 1.0 4 | background_mod #333333 #555555 5 | alignment top_middle 6 | 7 | # Custom colors using colorN 8 | color_add alertHigh #ddaa00 9 | color_add alertMid #ddaa66 10 | color_add alertLow #ddaabb 11 | color_add myBlue #336699 12 | 13 | default_color white 14 | default_shade_color myBlue 15 | default_outline_color white 16 | 17 | gap_y 40.0 18 | gap_x 0.0 19 | 20 | TEXT 21 | $kernel on $machine 22 | ${voffset 10}$hr 23 | ${color lightgrey}Uptime:$color $uptime ${color lightgrey} - Realtime: $color$realtime 24 | ${color lightgrey}CPU Usage:${color} ${cpu}% ${cpubar} 25 | ${color lightgrey}Battery:$color $battery 26 | ${color lightgrey}Load:$color $loadavg 27 | ${color lightgrey}RAM Usage:$color ${printf "%-20.20s" ${printf "%s/%s - %s%%" $mem $memmax $memperc}} 28 | ${color lightgrey}Swap Usage:$color ${printf "%-19.19s" ${printf "%s/%s - %s%%" $swap $swapmax $swapperc}} 29 | ${color lightgrey}Processes:$color $processes ${color grey}Running:$color $running_processes 30 | ${voffset 10}$color$stippled_hr 31 | ${color white}Networking: 32 | ${color lightgrey}${printf "%-10s" ${devname dev0}} Down:${color #8844ee} ${downspeed dev0} ${color lightgrey} Up:${color #22ccff} ${upspeed dev0} 33 | ${color lightgrey}${printf "%-10s" ${devname dev1}} Down:${color #8844ee} ${downspeed dev1} ${color lightgrey} Up:${color #22ccff} ${upspeed dev1} 34 | ${color lightgrey}File systems: 35 | /sdcard $color${printf "%5.5s/%-7.7s" ${fs_used /sdcard} ${fs_size /sdcard}} ${fs_bar /sdcard} 36 | ${voffset 10}$color$stippled_hr 37 | ${color}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" Name PID CPU% MEM%} 38 | ${color alertHigh}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}} 39 | ${color alertMid}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}} 40 | ${color alertLow}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}} 41 | ${color lightgrey}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}} 42 | ${color lightgrey}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 5} ${top pid 5} ${top cpu 5} ${top mem 5}} 43 | 44 | # vim:set ft=mossrc: 45 | -------------------------------------------------------------------------------- /moss/src/main/assets/ebuprof.conf: -------------------------------------------------------------------------------- 1 | background_color #222222 2 | 3 | font Droid Sans:size=12 4 | update_interval 1.0 5 | default_color white 6 | default_shade_color white 7 | default_outline_color green 8 | alignment top_right 9 | uppercase yes 10 | gap_x 12 11 | gap_y 50 12 | 13 | TEXT 14 | ${color white}SYSTEM ${hr 1}${color} 15 | 16 | Hostname: $alignr$nodename 17 | Kernel: $alignr$kernel 18 | Uptime: $alignr$uptime 19 | 20 | CPU: ${alignr}${freq} MHz 21 | Processes: ${alignr}$processes ($running_processes running) 22 | Load: ${alignr}$loadavg 23 | 24 | CPU ${alignr}${cpu}% 25 | ${cpubar 8} 26 | 27 | Entropy: ${alignr}$entropy_avail / $entropy_poolsize ($entropy_perc) 28 | Ram ${alignr}$mem / $memmax ($memperc%) 29 | ${membar 8} 30 | Swap ${alignr}$swap / $swapmax ($swapperc%) 31 | ${swapbar 8} 32 | 33 | Highest CPU${alignr}CPU% MEM% 34 | ${length 18 18 ${top name 1}}${alignr}${length 4 4 ${top cpu 1}} ${length 4 4 ${top mem 1}} 35 | ${length 18 18 ${top name 2}}${alignr}${length 4 4 ${top cpu 2}} ${length 4 4 ${top mem 2}} 36 | ${length 18 18 ${top name 3}}${alignr}${length 4 4 ${top cpu 3}} ${length 4 4 ${top mem 3}} 37 | 38 | Highest MEM${alignr}CPU% MEM% 39 | ${length 18 18 ${top_mem name 1}}${alignr}${length 4 4 ${top_mem cpu 1}} ${length 4 4 ${top_mem mem 1}} 40 | ${length 18 18 ${top_mem name 2}}${alignr}${length 4 4 ${top_mem cpu 2}} ${length 4 4 ${top_mem mem 2}} 41 | ${length 18 18 ${top_mem name 3}}${alignr}${length 4 4 ${top_mem cpu 3}} ${length 4 4 ${top_mem mem 3}} 42 | 43 | ${color white}Filesystem ${hr 1}${color} 44 | 45 | System: ${alignr}${fs_free /system} / ${fs_size /system} 46 | ${fs_bar 8 /system} 47 | Data: ${alignr}${fs_free /data} / ${fs_size /data} 48 | ${fs_bar 8 /data} 49 | 50 | ${color white}NETWORK ${hr 1}${color} 51 | 52 | ${color lightgrey}${devname dev0}${color} 53 | Down ${downspeed dev0} k/s ${alignr}Up ${upspeed dev0} k/s 54 | ${downspeedgraph dev0 50,200 #ffffff #ffffff} ${alignr}${upspeedgraph dev0 50,200 #ffffff #ffffff} 55 | Total ${totaldown dev0} ${alignr}Total ${totalup dev0} 56 | 57 | ${color lightgrey}${devname dev1}${color} 58 | Down ${downspeed dev1} k/s ${alignr}Up ${upspeed dev1} k/s 59 | ${downspeedgraph dev1 50,200 #ffffff #ffffff} ${alignr}${upspeedgraph dev1 50,200 #ffffff #ffffff} 60 | Total ${totaldown dev1} ${alignr}Total ${totalup dev1} 61 | 62 | IP${alignr}RPORT 63 | ${tcp_portmon 1 65535 rip 0}${alignr}${tcp_portmon 1 65535 rport 0} 64 | ${tcp_portmon 1 65535 rip 1}${alignr}${tcp_portmon 1 65535 rport 1} 65 | ${tcp_portmon 1 65535 rip 2}${alignr}${tcp_portmon 1 65535 rport 2} 66 | ${tcp_portmon 1 65535 rip 3}${alignr}${tcp_portmon 1 65535 rport 3} 67 | ${tcp_portmon 1 65535 rip 4}${alignr}${tcp_portmon 1 65535 rport 4} 68 | -------------------------------------------------------------------------------- /moss/src/main/assets/error.conf: -------------------------------------------------------------------------------- 1 | # Default update stats every 5 seconds 2 | update_interval 1.0 3 | background_mod #333333 #555555 4 | 5 | alignment middle_middle 6 | 7 | font Droid Sans:size=14 8 | 9 | default_color white 10 | default_shade_color MyBlue 11 | default_outline_color white 12 | 13 | gap_y 0.0 14 | gap_x 0.0 15 | 16 | color2 #999999 17 | color3 #666666 18 | colorAlert #ff0000 19 | 20 | TEXT 21 | ${colorAlert}${font Droid Sans:bold:size=40}Error: ${color}${font Droid Sans:size=20}No config file!${font}$color 22 | ${font Droid Sans:size=30}${color2}${time %T}${color3} ${font Droid Sans:size=25}${time %a %d %b %Y}${font}${color} 23 | $hr 24 | $sysname - $kernel on $machine 25 | Battery: ${voffset 4}${battery_bar 8,200}${voffset -4} 26 | /sdcard: ${voffset 4}${fs_bar 8,200 /sdcard}${voffset -4} 27 | CPU: ${voffset 4}${cpubar 8,200}${voffset -4} 28 | RAM: ${voffset 4}${membar 8,200}${voffset -4} 29 | 30 | # vim:set ft=conkyrc: 31 | -------------------------------------------------------------------------------- /moss/src/main/assets/full.conf: -------------------------------------------------------------------------------- 1 | update_interval 1.0 2 | background_mod #333333 #555555 3 | 4 | font_size 12 5 | 6 | alignment top_middle 7 | 8 | default_color white 9 | default_shade_color white 10 | default_outline_color colorBlue 11 | 12 | # Custom colors using colorN 13 | colorHigh #ddaa00 14 | colorMid #ddaa66 15 | colorLow #ddaabb 16 | colorBlue #336699 17 | 18 | gap_y 50.0 19 | gap_x 0.0 20 | 21 | TEXT 22 | 23 | $sysname - $kernel on $machine 24 | ${voffset 5} 25 | $hr 26 | ${color lightgrey}Uptime:$color $realtime ($uptime) ${color lightgrey} 27 | ${color lightgrey}Load:$color $loadavg 28 | ${color lightgrey}CPU Usage:${color} ${cpu}% ${cpubar} 29 | ${color black}${cpugraph 50,400 #000000 #ffffff} 30 | ${color lightgrey}Battery:$color $battery 31 | ${color lightgrey}RAM Usage:$color ${printf "%-20.20s" ${printf "%s/%s - %s%%" $mem $memmax $memperc}} $membar 32 | ${color lightgrey}Swap Usage:$color ${printf "%-19.19s" ${printf "%s/%s - %s%%" $swap $swapmax $swapperc}} $swapbar 33 | ${color lightgrey}Processes:$color $processes ${color grey}Running:$color $running_processes 34 | ${voffset 5} 35 | $color$stippled_hr 36 | ${color lightgrey}Networking: 37 | ${printf "%-10s" ${devname dev0}} Down:${color #8844ee} ${downspeed dev0} ${color lightgrey} Up:${color #22ccff} ${upspeed dev0}${color lightgrey} 38 | ${downspeedgraph dev0 50,200 #000000 #ffffff} ${upspeedgraph dev0 50,200 #000000 #ffffff} 39 | ${printf "%-10s" ${devname dev1}} Down:${color #8844ee} ${downspeed dev1} ${color lightgrey} Up:${color #22ccff} ${upspeed dev1}${color lightgrey} 40 | ${downspeedgraph dev1 50,200 #000000 #ffffff} ${upspeedgraph dev1 50,200 #000000 #ffffff} 41 | ${color lightgrey}File systems: 42 | /system $color${printf "%5.5s/%-7.7s" ${fs_used /system} ${fs_size /system}} ${fs_bar /system}${color lightgrey} 43 | /data $color${printf "%5.5s/%-7.7s" ${fs_used /data} ${fs_size /data}} ${fs_bar /data}${color lightgrey} 44 | /sdcard $color${printf "%5.5s/%-7.7s" ${fs_used /sdcard} ${fs_size /sdcard}} ${fs_bar /sdcard} 45 | ${voffset 5} 46 | ${color}${stippled_hr} 47 | ${color}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" Name PID CPU% MEM%} 48 | ${colorHigh}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}} 49 | ${colorMid}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}} 50 | ${colorLow}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}} 51 | ${color lightgrey}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}} 52 | ${color lightgrey}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 5} ${top pid 5} ${top cpu 5} ${top mem 5}} 53 | 54 | ${color}Mem usage 55 | ${colorHigh}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top_mem name 1} ${top_mem pid 1} ${top_mem cpu 1} ${top_mem mem 1}} 56 | ${colorMid}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top_mem name 2} ${top_mem pid 2} ${top_mem cpu 2} ${top_mem mem 2}} 57 | ${colorLow}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top_mem name 3} ${top_mem pid 3} ${top_mem cpu 3} ${top_mem mem 3}} 58 | ${color lightgrey}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top_mem name 4} ${top_mem pid 4} ${top_mem cpu 4} ${top_mem mem 4}} 59 | ${color lightgrey}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top_mem name 5} ${top_mem pid 5} ${top_mem cpu 5} ${top_mem mem 5}} 60 | 61 | # vim:set ft=conkyrc: 62 | -------------------------------------------------------------------------------- /moss/src/main/assets/help.css: -------------------------------------------------------------------------------- 1 | body { background-color: #000; color: #eee; } 2 | ul { list-style-type: none; margin: 0; padding: 0 0 0 10px; } 3 | h2 { color: #fff; } 4 | h3 { font-size: 12pt; color: #fff; } 5 | 6 | pre, code { font: 10pt Courier, monospace; } 7 | blockquote { margin: 0.9em; padding: 0 0 0 10px; font-size: 10pt; } 8 | hr { background-color: #fff; } 9 | a { color: #ccc; font-size: 1.2em; } 10 | -------------------------------------------------------------------------------- /moss/src/main/assets/help.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Help 4 | 5 | 6 | 7 |

8 | Moss is highly configurable live wall paper modeled after the *nix 9 | utility Conky. This install comes with a few default 10 | configurations, but a custom configuration can be built as well. 11 |

12 |

13 | A list of configuration options and layout objects are provided at 14 | the following links. These same lists can also be found on 15 | Moss's site. 16 |

17 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /moss/src/main/assets/network.conf: -------------------------------------------------------------------------------- 1 | update_interval 1.0 2 | alignment top_middle 3 | 4 | font_size 16 5 | 6 | default_color white 7 | default_shade_color white 8 | default_outline_color #999999 9 | 10 | background_mod #336699 #336666 11 | 12 | gap_y 60.0 13 | gap_x 0.0 14 | 15 | TEXT 16 | ${color lightgrey}Sysname: ${color}$sysname 17 | ${color lightgrey}Kernel: ${color}$kernel 18 | ${color lightgrey}Machine: ${color}$machine 19 | 20 | $hr 21 | ${color lightgrey}Uptime:$color $uptime 22 | ${color lightgrey}Realtime:$color $realtime 23 | ${color lightgrey}Load:$color $loadavg 24 | ${color lightgrey}CPU Usage:${color} ${cpu}% ${cpubar} 25 | ${color black}${cpugraph 25,300 #000000 #ffffff} 26 | 27 | $color$hr 28 | ${color lightgrey}Networking: 29 | ${printf "%-10s" ${devname dev0}} Down:${color white} ${downspeed dev0} ${color lightgrey} ${alignr}Up:${color white} ${upspeed dev0}${color lightgrey} 30 | ${downspeedgraph dev0 25,150 #000000 #ffffff} ${upspeedgraph dev0 25,150 #000000 #ffffff} 31 | ${printf "%-10s" ${devname dev1}} Down:${color white} ${downspeed dev1} ${color lightgrey} ${alignr}Up:${color white} ${upspeed dev1}${color lightgrey} 32 | ${downspeedgraph dev1 25,150 #000000 #ffffff} ${upspeedgraph dev1 25,150 #000000 #ffffff} 33 | ${printf "%-10s" ${devname dev2}} Down:${color white} ${downspeed dev2} ${color lightgrey} ${alignr}Up:${color white} ${upspeed dev2}${color lightgrey} 34 | ${downspeedgraph dev2 25,150 #000000 #ffffff} ${upspeedgraph dev2 25,150 #000000 #ffffff} 35 | 36 | ${color lightgrey}${printf "%-16.16s %-16.16s %-10.10s" Service IP DPORT} 37 | ${printf "%-16.16s %-16.16s %-10.10s" ${tcp_portmon 1 65535 rservice 0} ${tcp_portmon 1 65535 rip 0} ${tcp_portmon 1 65535 rport 0} } 38 | ${printf "%-16.16s %-16.16s %-10.10s" ${tcp_portmon 1 65535 rservice 1} ${tcp_portmon 1 65535 rip 1} ${tcp_portmon 1 65535 rport 1}} 39 | ${printf "%-16.16s %-16.16s %-10.10s" ${tcp_portmon 1 65535 rservice 2} ${tcp_portmon 1 65535 rip 2} ${tcp_portmon 1 65535 rport 2}} 40 | ${printf "%-16.16s %-16.16s %-10.10s" ${tcp_portmon 1 65535 rservice 3} ${tcp_portmon 1 65535 rip 3} ${tcp_portmon 1 65535 rport 3}} 41 | ${printf "%-16.16s %-16.16s %-10.10s" ${tcp_portmon 1 65535 rservice 4} ${tcp_portmon 1 65535 rip 4} ${tcp_portmon 1 65535 rport 4}} 42 | ${printf "%-16.16s %-16.16s %-10.10s" ${tcp_portmon 1 65535 rservice 5} ${tcp_portmon 1 65535 rip 5} ${tcp_portmon 1 65535 rport 5}} 43 | ${printf "%-16.16s %-16.16s %-10.10s" ${tcp_portmon 1 65535 rservice 6} ${tcp_portmon 1 65535 rip 6} ${tcp_portmon 1 65535 rport 6}} 44 | ${printf "%-16.16s %-16.16s %-10.10s" ${tcp_portmon 1 65535 rservice 7} ${tcp_portmon 1 65535 rip 7} ${tcp_portmon 1 65535 rport 7}} 45 | ${printf "%-16.16s %-16.16s %-10.10s" ${tcp_portmon 1 65535 rservice 8} ${tcp_portmon 1 65535 rip 8} ${tcp_portmon 1 65535 rport 8}} 46 | ${printf "%-16.16s %-16.16s %-10.10s" ${tcp_portmon 1 65535 rservice 9} ${tcp_portmon 1 65535 rip 9} ${tcp_portmon 1 65535 rport 9}} 47 | 48 | # vim:set ft=conkyrc: 49 | -------------------------------------------------------------------------------- /moss/src/main/assets/process.conf: -------------------------------------------------------------------------------- 1 | update_interval 1.0 2 | alignment top_middle 3 | background_color #333333 4 | 5 | default_color white 6 | 7 | font_size 16 8 | 9 | # Custom colors using colorN 10 | color_add alertHigh #ddaa00 11 | color_add alertMid #ddaa00 12 | color_add alertLow #ddaabb 13 | 14 | gap_y 50.0 15 | 16 | TEXT 17 | $kernel on $machine 18 | 19 | $hr 20 | ${color lightgrey}Uptime:$color $uptime ${color lightgrey} 21 | ${color lightgrey}Realtime: $color$realtime 22 | ${color lightgrey}CPU Usage:${color} ${cpu}% ${cpubar} 23 | ${color lightgrey}${cpugraph #333333 #336699} 24 | 25 | $color$stippled_hr 26 | ${color}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" Name PID CPU% MEM%} 27 | ${color alertHigh}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}} 28 | ${color alertMid}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}} 29 | ${color alertLow}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}} 30 | ${color lightgrey}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}} 31 | ${color lightgrey}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top name 5} ${top pid 5} ${top cpu 5} ${top mem 5}} 32 | 33 | ${color}Mem usage 34 | ${color alertHigh}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top_mem name 1} ${top_mem pid 1} ${top_mem cpu 1} ${top_mem mem 1}} 35 | ${color alertMid}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top_mem name 2} ${top_mem pid 2} ${top_mem cpu 2} ${top_mem mem 2}} 36 | ${color alertLow}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top_mem name 3} ${top_mem pid 3} ${top_mem cpu 3} ${top_mem mem 3}} 37 | ${color lightgrey}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top_mem name 4} ${top_mem pid 4} ${top_mem cpu 4} ${top_mem mem 4}} 38 | ${color lightgrey}${printf "%-20.20s %-7.7s %-7.7s %-7.7s" ${top_mem name 5} ${top_mem pid 5} ${top_mem cpu 5} ${top_mem mem 5}} 39 | 40 | # vim:set ft=conkyrc: 41 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/Common.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.InputStreamReader; 5 | import java.io.File; 6 | import java.io.InputStream; 7 | import java.io.FileInputStream; 8 | import java.io.IOException; 9 | 10 | public class Common { 11 | 12 | public static void drawText(final Env env, String txt) { 13 | if (null == txt || txt.length() == 0) { 14 | return; 15 | } 16 | if (env.getConfig().getUppercase()) { 17 | txt = txt.toUpperCase(); 18 | } 19 | 20 | float x = env.getX(); 21 | float width = env.getPaint().measureText(txt, 0, txt.length()); 22 | env.setLineHeight(env.getPaint().getTextSize()); 23 | env.getCanvas().drawText(txt, x, env.getY() + env.getLineHeight(), env.getPaint()); 24 | env.setX(x + width); 25 | } 26 | 27 | public static String formatSeconds(long seconds) { 28 | long days; 29 | int hours, minutes; 30 | 31 | days = seconds / 86400; 32 | seconds %= 86400; 33 | hours = (int) (seconds / 3600); 34 | seconds %= 3600; 35 | minutes = (int) (seconds / 60); 36 | seconds %= 60; 37 | 38 | if (days > 0) { 39 | return String.format("%dd, %dh %dm %ds", days, hours, minutes, seconds); 40 | } else { 41 | return String.format("%dh %dm %ds", hours, minutes, seconds); 42 | } 43 | } 44 | 45 | public static String formatSecondsShort(long seconds) { 46 | long days; 47 | int hours, minutes; 48 | 49 | days = seconds / 86400; 50 | seconds %= 86400; 51 | hours = (int) (seconds / 3600); 52 | seconds %= 3600; 53 | minutes = (int) (seconds / 60); 54 | seconds %= 60; 55 | 56 | if (days > 0) { 57 | return String.format("%dd, %dh", days, hours); 58 | } else if (hours > 0) { 59 | return String.format("%dh %dm", hours, minutes); 60 | } else { 61 | return String.format("%dm %ds", minutes, seconds); 62 | } 63 | } 64 | 65 | public static String humanReadble(long num) { 66 | int is = 0; 67 | while (num / 1024 >= 1 && is < suffixes.length) { 68 | num /= 1024; 69 | is++; 70 | } 71 | float fnum = (float) num; 72 | return String.format("%.0f%s", fnum, suffixes[is]); 73 | } 74 | 75 | public static int hexToInt(final String hex, int i) { 76 | if (hex == null) { 77 | return i; 78 | } 79 | String h = hex.replaceAll("(?i)\\d*x", ""); 80 | h = h.replaceAll("#", ""); 81 | try { 82 | return Integer.parseInt(h, 16); 83 | } catch (NumberFormatException e) { 84 | return i; 85 | } 86 | } 87 | 88 | public static long toLong(String s) { 89 | return new Long(s).longValue(); 90 | } 91 | 92 | public static float toFloat(String s) { 93 | return new Float(s).floatValue(); 94 | } 95 | 96 | public static String slurp(File file) throws IOException { 97 | String body = ""; 98 | InputStream is = null; 99 | try { 100 | is = new FileInputStream(file); 101 | body = slurp(is); 102 | } finally { 103 | if (is != null) { 104 | is.close(); 105 | } 106 | } 107 | return body; 108 | } 109 | 110 | public static String slurp(InputStream is) throws IOException { 111 | String line; 112 | BufferedReader reader = null; 113 | StringBuffer buf = new StringBuffer(""); 114 | try { 115 | reader = new BufferedReader(new InputStreamReader(is)); 116 | 117 | while ((line = reader.readLine()) != null) { 118 | if (line.indexOf("#") == 0) { 119 | buf.append("\n"); 120 | continue; 121 | } 122 | buf.append(line).append("\n"); 123 | } 124 | } finally { 125 | if (null != is) { 126 | is.close(); 127 | } 128 | if (null != reader) { 129 | reader.close(); 130 | } 131 | } 132 | return buf.toString(); 133 | } 134 | 135 | 136 | static String[] suffixes = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", ""}; 137 | } 138 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/ConfigException.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper; 2 | 3 | public class ConfigException extends MossException { 4 | 5 | public ConfigException(String msg) { 6 | super(msg); 7 | type = ERROR; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/DataService.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper; 2 | 3 | import org.mosspaper.objects.DataProvider; 4 | import org.mosspaper.objects.UpdateManager; 5 | 6 | import android.app.Service; 7 | import android.content.Intent; 8 | import android.os.Binder; 9 | import android.os.Handler; 10 | import android.os.IBinder; 11 | import android.util.Log; 12 | 13 | import java.util.List; 14 | import java.util.ArrayList; 15 | import java.util.Map; 16 | 17 | public class DataService extends Service { 18 | 19 | public class State { 20 | public boolean isVisible() { 21 | return visible; 22 | } 23 | boolean visible; 24 | } 25 | 26 | class DataBinder extends Binder { 27 | DataService getService() { 28 | return DataService.this; 29 | } 30 | } 31 | 32 | @Override 33 | public void onCreate() { 34 | handler.post(handlerCallback); 35 | visible = false; 36 | } 37 | 38 | @Override 39 | public int onStartCommand(Intent intent, int flags, int startId) { 40 | return START_STICKY; 41 | } 42 | 43 | @Override 44 | public void onDestroy() { 45 | handler.removeCallbacks(handlerCallback); 46 | destroyProviders(); 47 | } 48 | 49 | @Override 50 | public IBinder onBind(Intent intent) { 51 | return mBinder; 52 | } 53 | 54 | public synchronized void setDataProviders(Map providers) { 55 | destroyProviders(); 56 | this.dataProviders = providers; 57 | startupProviders(); 58 | } 59 | 60 | public synchronized void setPaperVisible(boolean visible) { 61 | this.visible = visible; 62 | } 63 | 64 | void startupProviders() { 65 | if (null == dataProviders) { 66 | return; 67 | } 68 | for (DataProvider d : dataProviders.keySet()) { 69 | d.startup(this); 70 | } 71 | } 72 | 73 | void destroyProviders() { 74 | if (null == dataProviders) { 75 | return; 76 | } 77 | for (DataProvider d : dataProviders.keySet()) { 78 | d.destroy(this); 79 | } 80 | } 81 | 82 | void updateProviders() { 83 | Long nextRun = 250L; 84 | if (null != dataProviders) { 85 | final State state = new State(); 86 | state.visible = visible; 87 | 88 | nextRun = null; 89 | 90 | List threads = new ArrayList(); 91 | for (final UpdateManager m : dataProviders.values()) { 92 | /* determine when to update again */ 93 | if (null == nextRun || nextRun > m.getInterval()) { 94 | nextRun = m.getInterval(); 95 | } 96 | Thread t = new Thread(new Runnable() { 97 | public void run() { 98 | m.update(state); 99 | } 100 | }); 101 | t.start(); 102 | threads.add(t); 103 | } 104 | try { 105 | for (Thread t : threads) { 106 | t.join(); 107 | } 108 | } catch (InterruptedException e) { 109 | Log.e(TAG, "", e); 110 | } 111 | } 112 | if (nextRun == null) { 113 | nextRun = 1L; 114 | } 115 | handler.postDelayed(handlerCallback, nextRun); 116 | } 117 | 118 | private final Runnable handlerCallback = new Runnable() { 119 | public void run() { 120 | new Thread(new Runnable() { 121 | public void run() { 122 | updateProviders(); 123 | } 124 | }).start(); 125 | } 126 | }; 127 | 128 | private Map dataProviders; 129 | private Boolean visible; 130 | 131 | private final IBinder mBinder = new DataBinder(); 132 | private final Handler handler = new Handler(); 133 | 134 | static final int DEFAULT_INTERVAL = 1000; 135 | static final String TAG = "DataService"; 136 | } 137 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/HelpActivity.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.webkit.WebView; 6 | import android.view.KeyEvent; 7 | 8 | public class HelpActivity extends Activity { 9 | @Override 10 | protected void onCreate(Bundle icicle) { 11 | super.onCreate(icicle); 12 | this.setContentView(R.layout.act_help); 13 | 14 | webview = (WebView) findViewById(R.id.help_webview); 15 | webview.loadUrl("file:///android_asset/help.html"); 16 | } 17 | 18 | @Override 19 | public boolean onKeyDown(int keyCode, KeyEvent event) { 20 | if ((keyCode == KeyEvent.KEYCODE_BACK && webview.canGoBack())) { 21 | webview.goBack(); 22 | return true; 23 | } 24 | return super.onKeyDown(keyCode, event); 25 | } 26 | 27 | private WebView webview; 28 | } 29 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/Layout.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper; 2 | 3 | import android.graphics.Canvas; 4 | 5 | import org.mosspaper.objects.MossObject; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class Layout extends ArrayList implements List { 11 | 12 | public void draw(Canvas c, Env env) { 13 | List objs = this; 14 | for (MossObject o : objs) { 15 | o.preDraw(env); 16 | } 17 | for (MossObject o : objs) { 18 | o.draw(env); 19 | } 20 | for (MossObject o : objs) { 21 | o.postDraw(env); 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/MossException.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper; 2 | 3 | public class MossException extends Exception { 4 | 5 | public MossException(String msg) { 6 | super(msg); 7 | type = ERROR; 8 | } 9 | 10 | public void setIdent(String ident) { 11 | this.ident = ident; 12 | } 13 | 14 | public String getIdent() { 15 | return ident; 16 | } 17 | 18 | public void setLineNo(int n) { 19 | this.lineNo = n; 20 | } 21 | 22 | public void setColNo(int n) { 23 | this.colNo = n; 24 | } 25 | 26 | public String getBrief() { 27 | return String.format("Line %d:%d: %s", lineNo, colNo, ident); 28 | } 29 | 30 | public String getSummary() { 31 | return getMessage(); 32 | } 33 | 34 | public void setErrType(int type) { 35 | this.type = type; 36 | } 37 | 38 | public int getErrType() { 39 | return type; 40 | } 41 | 42 | String ident; 43 | int lineNo; 44 | int colNo; 45 | int type; 46 | 47 | public static final int ERROR = 1; 48 | public static final int WARNING = 2; 49 | } 50 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/OverridesActivity.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper; 2 | 3 | import android.app.Dialog; 4 | import android.app.ProgressDialog; 5 | import android.content.Context; 6 | import android.content.SharedPreferences; 7 | import android.os.AsyncTask; 8 | import android.os.Bundle; 9 | import android.preference.Preference; 10 | import android.preference.PreferenceActivity; 11 | import android.preference.Preference.OnPreferenceClickListener; 12 | import android.view.ContextMenu; 13 | import android.view.LayoutInflater; 14 | import android.view.Menu; 15 | import android.view.MenuItem; 16 | import android.view.MenuItem.OnMenuItemClickListener; 17 | import android.view.MenuInflater; 18 | import android.view.View; 19 | import android.widget.AdapterView; 20 | 21 | import org.mosspaper.prefs.PrefUtils; 22 | 23 | import java.io.File; 24 | 25 | public class OverridesActivity extends PreferenceActivity 26 | implements SharedPreferences.OnSharedPreferenceChangeListener { 27 | 28 | @Override 29 | protected void onCreate(Bundle icicle) { 30 | super.onCreate(icicle); 31 | getPreferenceManager().setSharedPreferencesName(WallPaper.SHARED_PREFS_NAME); 32 | addPreferencesFromResource(R.xml.prefs_overrides); 33 | 34 | prefs = getPreferenceManager().getSharedPreferences(); 35 | prefs.registerOnSharedPreferenceChangeListener(this); 36 | 37 | this.registerForContextMenu(this.getListView()); 38 | this.inflater = LayoutInflater.from(this); 39 | 40 | Preference reset = (Preference) findPreference("config_reset"); 41 | if (null != reset) { 42 | reset.setOnPreferenceClickListener(new OnPreferenceClickListener() { 43 | public boolean onPreferenceClick(Preference pref) { 44 | PrefUtils.resetPrefs(currentEnv.env, prefs); 45 | PrefUtils.defaultPrefs(currentEnv.env, prefs); 46 | 47 | return true; 48 | } 49 | }); 50 | } 51 | 52 | onSharedPreferenceChanged(prefs, null); 53 | } 54 | 55 | @Override 56 | protected void onResume() { 57 | PrefUtils.updatePrefs(this); 58 | super.onResume(); 59 | } 60 | 61 | @Override 62 | protected void onDestroy() { 63 | getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener( 64 | this); 65 | super.onDestroy(); 66 | } 67 | 68 | @Override 69 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 70 | if ("config_file".equals(key)) { 71 | Preference pref = this.findPreference(key); 72 | if (null == prefs.getString(key, null)) { 73 | pref.setSummary(getString(R.string.path_to_config)); 74 | } else { 75 | File file = new File(prefs.getString(key, "")); 76 | if (file.exists()) { 77 | pref.setSummary(file.toString()); 78 | startReloadTask(); 79 | } else { 80 | pref.setSummary(getString(R.string.does_not_exist, file.toString())); 81 | } 82 | } 83 | } else { 84 | PrefUtils.updatePrefs(this); 85 | } 86 | } 87 | 88 | @Override 89 | public void onCreateContextMenu(ContextMenu menu, final View view, 90 | ContextMenu.ContextMenuInfo menuInfo) { 91 | AdapterView.AdapterContextMenuInfo info = 92 | (AdapterView.AdapterContextMenuInfo) menuInfo; 93 | 94 | final Preference pref = (Preference) this.getListView().getItemAtPosition(info.position);; 95 | menu.setHeaderTitle(pref.getTitle()); 96 | 97 | 98 | if (!PrefUtils.isDefaultable(pref.getKey())) { 99 | return; 100 | } 101 | 102 | MenuItem reset = menu.add(R.string.reset); 103 | reset.setEnabled(true); 104 | reset.setOnMenuItemClickListener(new OnMenuItemClickListener() { 105 | public boolean onMenuItemClick(MenuItem item) { 106 | SharedPreferences.Editor edit = prefs.edit(); 107 | edit.remove(pref.getKey()); 108 | edit.commit(); 109 | 110 | PrefUtils.defaultPrefs(currentEnv.env, prefs); 111 | PrefUtils.updatePrefs(OverridesActivity.this); 112 | 113 | return true; 114 | } 115 | }); 116 | } 117 | 118 | private void startReloadTask() { 119 | pdialog = new ProgressDialog(this); 120 | pdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 121 | pdialog.setMessage(getString(R.string.reloading)); 122 | pdialog.show(); 123 | 124 | new ReloadTask().execute(); 125 | } 126 | 127 | class ReloadTask extends AsyncTask { 128 | 129 | protected Long doInBackground(String... s) { 130 | Env.reload(OverridesActivity.this); 131 | 132 | return 0L; 133 | } 134 | 135 | protected void onPostExecute(Long result) { 136 | OverridesActivity.this.pdialog.dismiss(); 137 | } 138 | } 139 | 140 | private Env.Current currentEnv = Env.Current.INSTANCE; 141 | private ProgressDialog pdialog; 142 | private SharedPreferences prefs; 143 | private LayoutInflater inflater = null; 144 | 145 | static final String TAG = "OverridesActivity"; 146 | } 147 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/ParseException.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper; 2 | 3 | public class ParseException extends MossException { 4 | 5 | public ParseException(String msg) { 6 | super(msg); 7 | type = ERROR; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/AbsAlign.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.Layout; 5 | import org.mosspaper.Parser.NewLine; 6 | 7 | public abstract class AbsAlign implements MossObject { 8 | 9 | public void preDraw(Env env) { } 10 | 11 | protected Env buildEnv(Env env) { 12 | Env tmpEnv = env.dummyClone(); 13 | /* Draw from here to end of line */ 14 | Layout objs = env.getLayout(); 15 | if (objs == null) { 16 | return null; 17 | } 18 | int start = objs.indexOf(this); 19 | for (int i = start;; i++) { 20 | MossObject m = objs.get(i); 21 | if (m instanceof NewLine) { 22 | break; 23 | } 24 | m.draw(tmpEnv); 25 | } 26 | return tmpEnv; 27 | } 28 | 29 | public void postDraw(Env env) { } 30 | 31 | public DataProvider getDataProvider() { 32 | return null; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/AbsBarObject.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.util.Bar; 5 | 6 | abstract class AbsBarObject { 7 | 8 | /** 9 | * TODO: Add error checking 10 | */ 11 | AbsBarObject() { 12 | this.height = 10f; 13 | this.width = 150f; 14 | } 15 | 16 | AbsBarObject(String hw) { 17 | String[] hwarr = hw.split(","); 18 | if (hwarr.length == 2) { 19 | this.height = new Float(hwarr[0]).floatValue(); 20 | this.width = new Float(hwarr[1]).floatValue(); 21 | } else { 22 | this.height = new Float(hwarr[0]).floatValue(); 23 | this.width = -1.0f; 24 | } 25 | } 26 | 27 | protected void doDraw(Env env, float perc) { 28 | Bar b = new Bar(); 29 | b.drawBar(env, perc, height, width); 30 | } 31 | 32 | protected float height; 33 | protected float width; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/AbsGraphObject.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.util.Graph; 5 | 6 | import java.util.List; 7 | 8 | abstract class AbsGraphObject { 9 | 10 | AbsGraphObject(String color1, String color2) { 11 | this.height = 32f; 12 | this.width = 150f; 13 | this.colorLeft = Color.lookupColor(color1); 14 | this.colorRight = Color.lookupColor(color2); 15 | } 16 | 17 | AbsGraphObject(String hw, String color1, String color2) { 18 | String[] hwarr = hw.split(","); 19 | this.height = new Float(hwarr[0]).floatValue(); 20 | this.width = new Float(hwarr[1]).floatValue(); 21 | this.colorLeft = Color.lookupColor(color1); 22 | this.colorRight = Color.lookupColor(color2); 23 | } 24 | 25 | public void draw(Env env) { 26 | Graph g = new Graph(); 27 | g.setHeight(height); 28 | g.setWidth(width); 29 | g.setScale(scale); 30 | g.setColorLeft(colorLeft); 31 | g.setColorRight(colorRight); 32 | g.setData(history); 33 | g.draw(env); 34 | } 35 | 36 | protected Integer colorLeft; 37 | protected Integer colorRight; 38 | protected float height; 39 | protected float width; 40 | protected int scale; 41 | protected List history; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/AbsMossObject.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.Common; 5 | 6 | public abstract class AbsMossObject implements MossObject { 7 | 8 | public void preDraw(Env env) { } 9 | 10 | public void draw(Env env) { 11 | Common.drawText(env, toString()); 12 | } 13 | 14 | public void postDraw(Env env) { } 15 | 16 | public DataProvider getDataProvider() { 17 | return null; 18 | } 19 | 20 | public abstract String toString(); 21 | } 22 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/AbsTop.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.objects.ProcList.Proc; 5 | 6 | import java.util.List; 7 | import java.util.Collections; 8 | import java.util.Comparator; 9 | 10 | public abstract class AbsTop extends AbsMossObject implements MossObject { 11 | 12 | public AbsTop(String var, String num) { 13 | this.var = var; 14 | this.num = Integer.parseInt(num) - 1; 15 | } 16 | 17 | public abstract Comparator getComparator(); 18 | public abstract void setList(List ls); 19 | public abstract List getList(); 20 | 21 | public DataProvider getDataProvider() { 22 | return this.procList; 23 | } 24 | 25 | @Override 26 | public void preDraw(Env env) { 27 | if (getList() != null) { 28 | return; 29 | } 30 | setList(procList.getProcesses()); 31 | Collections.sort(getList(), getComparator()); 32 | Collections.reverse(getList()); 33 | } 34 | 35 | @Override 36 | public void postDraw(Env env) { 37 | setList(null); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | if (null == getList()) { 43 | return ""; 44 | } 45 | if (getList().size() <= num) { 46 | return ""; 47 | } 48 | Proc e = getList().get(num); 49 | if (null == e) { 50 | return ""; 51 | } 52 | if ("name".equals(var)) { 53 | return e.name; 54 | } else if ("package".equals(var)) { 55 | return e.packageName; 56 | } else if ("pid".equals(var)) { 57 | return e.pid; 58 | } else if ("cpu".equals(var)) { 59 | return String.format("%.2f", e.cpuPerc); 60 | } else if ("mem".equals(var)) { 61 | return String.format("%.2f", e.memPerc); 62 | } else { 63 | return ""; 64 | } 65 | } 66 | 67 | protected String var; 68 | protected int num; 69 | 70 | static ProcList procList = ProcList.INSTANCE; 71 | } 72 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/AlignC.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | 5 | public class AlignC extends AbsAlign implements MossObject { 6 | 7 | /** 8 | * Align the text to center. 9 | */ 10 | public AlignC() { } 11 | 12 | public void draw(Env env) { 13 | 14 | if (curX != null && curX == lastX) { 15 | env.setX(curX); 16 | return; 17 | } 18 | 19 | Env tmpEnv = buildEnv(env); 20 | if (tmpEnv == null) { 21 | return; 22 | } 23 | 24 | float delta = tmpEnv.getX() - env.getX(); 25 | 26 | lastX = curX; 27 | curX = (env.getMaxX() / 2.0f) - (delta / 2.0f); 28 | env.setX(curX); 29 | } 30 | 31 | Float curX; 32 | Float lastX; 33 | } 34 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/AlignR.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | 5 | public class AlignR extends AbsAlign implements MossObject { 6 | 7 | /** 8 | * Align the text to the right. 9 | */ 10 | public AlignR() { } 11 | 12 | public void draw(Env env) { 13 | 14 | if (curX != null && curX == lastX) { 15 | env.setX(curX); 16 | return; 17 | } 18 | 19 | Env tmpEnv = buildEnv(env); 20 | if (tmpEnv == null) { 21 | return; 22 | } 23 | 24 | float delta = tmpEnv.getX() - env.getX(); 25 | 26 | if (env.getMaxX() > delta 27 | && env.getX() < env.getMaxX() - delta) { 28 | lastX = curX; 29 | curX = env.getMaxX() - delta; 30 | env.setX(curX); 31 | } 32 | } 33 | 34 | Float curX; 35 | Float lastX; 36 | } 37 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Battery.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class Battery extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Display current battery status and level. 7 | */ 8 | public Battery() { } 9 | 10 | public DataProvider getDataProvider() { 11 | return battInfo; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return String.format("%s %.2f%%", 17 | battInfo.getStatusDesc(), battInfo.getLevelFrac() * 100.0f); 18 | } 19 | 20 | private BatteryReceiver battInfo = BatteryReceiver.INSTANCE; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/BatteryBar.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.Common; 5 | import org.mosspaper.ParseException; 6 | import org.mosspaper.util.Bar; 7 | 8 | public class BatteryBar extends AbsBarObject implements MossObject { 9 | 10 | /** 11 | * Display a bar of the current battery level. 12 | */ 13 | public BatteryBar(String hw) throws ParseException { 14 | super(hw); 15 | } 16 | 17 | public DataProvider getDataProvider() { 18 | return battInfo; 19 | } 20 | 21 | public void preDraw(Env env) { } 22 | 23 | public void draw(Env env) { 24 | doDraw(env, battInfo.getLevelFrac()); 25 | } 26 | 27 | public void postDraw(Env env) { } 28 | 29 | private BatteryReceiver battInfo = BatteryReceiver.INSTANCE; 30 | private float barHeight; 31 | private float barWidth; 32 | } 33 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/BatteryPercent.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class BatteryPercent extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Display current battery level. 7 | */ 8 | public BatteryPercent() { } 9 | 10 | public DataProvider getDataProvider() { 11 | return battInfo; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return String.format("%.2f%%", battInfo.getLevelFrac() * 100.0f); 17 | } 18 | 19 | private BatteryReceiver battInfo = BatteryReceiver.INSTANCE; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/BatteryReceiver.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.DataService.State; 4 | import org.mosspaper.util.RRDList; 5 | 6 | import android.content.BroadcastReceiver; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.content.IntentFilter; 10 | import android.os.BatteryManager; 11 | import android.util.Log; 12 | 13 | import java.util.List; 14 | import java.util.Iterator; 15 | 16 | public enum BatteryReceiver implements DataProvider { 17 | INSTANCE; 18 | 19 | class BattInfo { 20 | int level; 21 | long sysTime; 22 | float lossPerMilli; 23 | } 24 | 25 | BatteryReceiver() { 26 | level = 0; 27 | statusDesc = ""; 28 | battInfo = new RRDList(MAX_HISTORY); 29 | } 30 | 31 | public void startup(Context context) { 32 | context.registerReceiver(this.receiver, 33 | new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); 34 | } 35 | 36 | public void update(State state) { } 37 | 38 | public void destroy(Context context) { 39 | try { 40 | context.unregisterReceiver(this.receiver); 41 | } catch (Exception e) { 42 | Log.e(TAG, "unregisterReceiver", e); 43 | } 44 | } 45 | 46 | public boolean runWhenInvisible() { 47 | return false; 48 | } 49 | 50 | public synchronized float getLevelFrac() { 51 | if (scale == 0) { 52 | return 0.0f; 53 | } else { 54 | return level / (float) scale; 55 | } 56 | } 57 | 58 | public synchronized int getLevel() { 59 | return level; 60 | } 61 | 62 | public synchronized int getScale() { 63 | return scale; 64 | } 65 | 66 | public synchronized int getTemp() { 67 | return temp; 68 | } 69 | 70 | public synchronized int getVoltage() { 71 | return voltage; 72 | } 73 | 74 | public synchronized long getTimeRemaining() { 75 | return timeRemaining; 76 | } 77 | 78 | public synchronized String getStatusDesc() { 79 | return statusDesc; 80 | } 81 | 82 | private BroadcastReceiver receiver = new BroadcastReceiver() { 83 | @Override 84 | public void onReceive(Context context, Intent intent) { 85 | synchronized (BatteryReceiver.this) { 86 | level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); 87 | scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); 88 | temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1); 89 | voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1); 90 | status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); 91 | 92 | switch (status) { 93 | // case BatteryManager.BATTERY_PLUGGED_AC: 94 | // case BatteryManager.BATTERY_PLUGGED_USB: 95 | case BatteryManager.BATTERY_STATUS_CHARGING: 96 | statusDesc = "Charging"; 97 | break; 98 | case BatteryManager.BATTERY_STATUS_DISCHARGING: 99 | statusDesc = "Discharging"; 100 | break; 101 | case BatteryManager.BATTERY_STATUS_FULL: 102 | statusDesc = "Full"; 103 | break; 104 | case BatteryManager.BATTERY_STATUS_NOT_CHARGING: 105 | statusDesc = "Not Charging"; 106 | break; 107 | default: 108 | statusDesc = "Unknown"; 109 | } 110 | 111 | if (true) { 112 | BattInfo info = new BattInfo(); 113 | info.level = level; 114 | info.sysTime = System.currentTimeMillis(); 115 | 116 | if (battInfo.size() > 0) { 117 | BattInfo prev = battInfo.get(0); 118 | info.lossPerMilli = (info.level - prev.level) / (float) (info.sysTime - prev.sysTime); 119 | } 120 | battInfo.add(info); 121 | } 122 | 123 | /* calc avg loss of level per milli */ 124 | float lossAvgPerMilli = 0.0f; 125 | for (Iterator i = battInfo.iterator(); i.hasNext();) { 126 | BattInfo info = i.next(); 127 | lossAvgPerMilli += info.lossPerMilli; 128 | } 129 | lossAvgPerMilli /= battInfo.size(); 130 | if (lossAvgPerMilli <= 0.0) { 131 | timeRemaining = -1; 132 | } else { 133 | timeRemaining = (long) (level / (lossAvgPerMilli * 1000.0)); 134 | } 135 | } 136 | } 137 | }; 138 | 139 | private List battInfo; 140 | private int level; 141 | private int scale; 142 | private int temp; 143 | private int voltage; 144 | private int status; 145 | private long timeRemaining; 146 | private String statusDesc; 147 | 148 | static final int MAX_HISTORY = 10; 149 | static final String TAG = "BatteryReceiver"; 150 | } 151 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/BatteryTime.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | public class BatteryTime extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the amount of time left on battery. 9 | */ 10 | public BatteryTime() { } 11 | 12 | public DataProvider getDataProvider() { 13 | return battInfo; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | if (battInfo.getTimeRemaining() < 0) { 19 | return "Unknown"; 20 | } else { 21 | return Common.formatSeconds(battInfo.getTimeRemaining()); 22 | } 23 | } 24 | 25 | private BatteryReceiver battInfo = BatteryReceiver.INSTANCE; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Color.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.Common; 5 | import org.mosspaper.ParseException; 6 | 7 | import java.util.Map; 8 | import java.util.HashMap; 9 | 10 | public class Color implements MossObject { 11 | 12 | /** 13 | * Change the current paint color to the default color. 14 | */ 15 | public Color() { } 16 | 17 | /** 18 | * Change the current paint color to the value of color. 19 | * 20 | * @param color a color name or hexadecimal value 21 | */ 22 | public Color(String color) throws ParseException { 23 | this.color = lookupColor(color); 24 | if (this.color < 0) { 25 | throw new ParseException(String.format("Invalid color format: '%s'", color)); 26 | } 27 | } 28 | 29 | public void preDraw(Env env) { } 30 | 31 | public void draw(Env env) { 32 | int c = -1; 33 | if (null == this.color || this.color < 0) { 34 | c = env.getConfig().getDefaultColor(); 35 | } else { 36 | c = this.color; 37 | } 38 | if (c > -1) { 39 | env.getPaint().setColor(c); 40 | env.getPaint().setAlpha(0xFF); 41 | } 42 | } 43 | 44 | public void postDraw(Env env) { } 45 | 46 | public DataProvider getDataProvider() { 47 | return null; 48 | } 49 | 50 | public static int lookupColor(String c) { 51 | Integer color = colorMap.get(c); 52 | if (null == color) { 53 | color = Common.hexToInt(c, -1); 54 | } 55 | return color; 56 | } 57 | 58 | public static void addColorObject(String alias, String color) { 59 | TextObjects.TEXT_OBJECTS.put(alias, new TextObjects.ColorArgs(color)); 60 | } 61 | 62 | private Integer color; 63 | 64 | public static Map colorMap; 65 | static { 66 | colorMap = new HashMap(); 67 | colorMap.put("red", 0xff0000); 68 | colorMap.put("green", 0x00ff00); 69 | colorMap.put("yellow", 0xffff00); 70 | colorMap.put("blue", 0x0000ff); 71 | colorMap.put("magenta", 0x800080); 72 | colorMap.put("cyan", 0x00ffff); 73 | colorMap.put("black", 0x000000); 74 | colorMap.put("white", 0xffffff); 75 | colorMap.put("grey", 0x808080); 76 | colorMap.put("lightgrey", 0xc0c0c0); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Cpu.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class Cpu extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Display the percentage of cpu usage. 7 | */ 8 | public Cpu() { } 9 | 10 | public DataProvider getDataProvider() { 11 | return cpuInfo; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return String.format("%.0f", 100.0f * cpuInfo.getCpuUsage()); 17 | } 18 | 19 | private ProcList cpuInfo = ProcList.INSTANCE; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/CpuBar.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.util.Bar; 5 | 6 | public class CpuBar extends AbsBarObject implements MossObject { 7 | 8 | /** 9 | * Display the percentage of cpu usage in a bar. 10 | */ 11 | public CpuBar() { 12 | super(); 13 | } 14 | 15 | /** 16 | * Display the percentage of cpu usage in a bar. 17 | */ 18 | public CpuBar(String hw) { 19 | super(hw); 20 | } 21 | 22 | public DataProvider getDataProvider() { 23 | return cpuInfo; 24 | } 25 | 26 | public void preDraw(Env env) { } 27 | 28 | public void draw(Env env) { 29 | doDraw(env, cpuInfo.getCpuUsage()); 30 | } 31 | 32 | public void postDraw(Env env) { } 33 | 34 | private ProcList cpuInfo = ProcList.INSTANCE; 35 | } 36 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/CpuFreqProvider.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import org.mosspaper.DataService.State; 7 | import org.mosspaper.ParseException; 8 | 9 | import java.util.Map; 10 | import java.util.HashMap; 11 | import java.io.BufferedReader; 12 | import java.io.FileReader; 13 | import java.io.IOException; 14 | import java.util.regex.Matcher; 15 | import java.util.regex.Pattern; 16 | 17 | public enum CpuFreqProvider implements DataProvider { 18 | 19 | INSTANCE; 20 | 21 | static final String TAG = "CpuFreqProvider"; 22 | static final String CPUFREQ_PREFIX = "/sys/devices/system/cpu"; 23 | static final String CPUFREQ_POSTFIX = "cpufreq/scaling_cur_freq"; 24 | 25 | class Cpu { 26 | long freq; 27 | } 28 | 29 | private Map cpus; 30 | 31 | public void registerCpu(int cpuNum) throws ParseException { 32 | int adjNum = cpuNum - 1; 33 | if (cpus == null) { 34 | cpus = new HashMap(); 35 | } 36 | 37 | java.io.File file = new java.io.File(makeFilename(adjNum)); 38 | if (file.exists()) { 39 | if (null == cpus.get(adjNum)) { 40 | cpus.put(adjNum, new Cpu()); 41 | } 42 | } else { 43 | throw new ParseException("Invalid CPU number " + cpuNum); 44 | } 45 | } 46 | 47 | public void startup(Context context) { } 48 | 49 | public synchronized void update(State state) { 50 | for (Map.Entry entry : cpus.entrySet()) { 51 | 52 | String freqStr; 53 | try { 54 | BufferedReader reader = 55 | new BufferedReader( 56 | new FileReader(makeFilename(entry.getKey())), 32); 57 | try { 58 | entry.getValue().freq = Long.parseLong(reader.readLine()); 59 | } catch (NumberFormatException ne) { 60 | Log.e(TAG, "", ne); 61 | } finally { 62 | reader.close(); 63 | } 64 | } catch (IOException e) { 65 | Log.e(TAG, "IO Exception getting cpu freq", e); 66 | } 67 | } 68 | } 69 | 70 | public void destroy(Context context) { } 71 | 72 | public boolean runWhenInvisible() { 73 | return false; 74 | } 75 | 76 | private String makeFilename(int cpuNum) { 77 | return String.format("%s/cpu%d/%s", CPUFREQ_PREFIX, cpuNum, CPUFREQ_POSTFIX); 78 | } 79 | 80 | public synchronized float getFreq(int cpuNum) { 81 | cpuNum = cpuNum - 1; 82 | Cpu c = cpus.get(cpuNum); 83 | if (c != null) { 84 | return c.freq / 1000.0f; 85 | } else { 86 | return 0.0f; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/CpuGraph.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | 5 | public class CpuGraph extends AbsGraphObject implements MossObject { 6 | 7 | /** 8 | * Display a historical graph of cpu usage. 9 | * 10 | * @param color1 left most color of graph 11 | * @param color2 right most color of graph 12 | */ 13 | public CpuGraph(String color1, String color2) { 14 | super(color1, color2); 15 | this.scale = 100; 16 | } 17 | 18 | /** 19 | * Display a historical graph of cpu usage. 20 | * 21 | * @param hw height,width of the graph such as 32,120 22 | * @param color1 left most color of graph 23 | * @param color2 right most color of graph 24 | */ 25 | public CpuGraph(String hw, String color1, String color2) { 26 | super(hw, color1, color2); 27 | } 28 | 29 | public DataProvider getDataProvider() { 30 | return cpuInfo; 31 | } 32 | 33 | public void preDraw(Env env) { 34 | if (null == history) { 35 | history = cpuInfo.getCpuHistory(); 36 | } 37 | } 38 | 39 | public void postDraw(Env env) { 40 | history = null; 41 | } 42 | 43 | private ProcList cpuInfo = ProcList.INSTANCE; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/DataProvider.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.content.Context; 4 | 5 | import org.mosspaper.DataService.State; 6 | 7 | public interface DataProvider { 8 | 9 | public void startup(Context context); 10 | 11 | public void update(State state); 12 | 13 | public void destroy(Context context); 14 | 15 | public boolean runWhenInvisible(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/DevName.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | public class DevName extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the device name 9 | * 10 | * @param device network device such as eth0 or wlan0 11 | */ 12 | public DevName(String device) { 13 | this.device = device; 14 | netDevInfo.registerDevice(device); 15 | } 16 | 17 | public DataProvider getDataProvider() { 18 | return netDevInfo; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return netDevInfo.getDevName(device); 24 | } 25 | 26 | private String device; 27 | private ProcNetDev netDevInfo = ProcNetDev.INSTANCE; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/DownSpeed.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | public class DownSpeed extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the download speed for a network interface. 9 | * 10 | * @param device network device such as eth0 or wlan0 11 | */ 12 | public DownSpeed(String device) { 13 | this.device = device; 14 | netDevInfo.registerDevice(device); 15 | } 16 | 17 | public DataProvider getDataProvider() { 18 | return netDevInfo; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return Common.humanReadble(netDevInfo.getDownSpeed(device)); 24 | } 25 | 26 | private String device; 27 | private ProcNetDev netDevInfo = ProcNetDev.INSTANCE; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/DownSpeedGraph.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | 5 | public class DownSpeedGraph extends AbsGraphObject implements MossObject { 6 | 7 | /** 8 | * Display a historical graph of download speeds for a device. 9 | * 10 | * @param device network device such as eth0 or wlan0 11 | * @param hw height,width of the graph 12 | * @param color1 left most color of graph 13 | * @param color2 right most color of graph 14 | */ 15 | public DownSpeedGraph(String device, String hw, String color1, String color2) { 16 | super(hw, color1, color2); 17 | this.device = device; 18 | this.scale = 1024 * 10; 19 | netDevInfo.registerDevice(device, Math.round(width)); 20 | } 21 | 22 | public DataProvider getDataProvider() { 23 | return netDevInfo; 24 | } 25 | 26 | public void preDraw(Env env) { 27 | if (null == history) { 28 | history = netDevInfo.getDownHistory(device); 29 | if (null == history) { 30 | return; 31 | } 32 | } 33 | } 34 | 35 | public void postDraw(Env env) { 36 | history = null; 37 | } 38 | 39 | private String device; 40 | private ProcNetDev netDevInfo = ProcNetDev.INSTANCE; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Entropy.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | import org.mosspaper.Env; 5 | import org.mosspaper.ParseException; 6 | 7 | public class Entropy { 8 | 9 | public static class PoolSize extends AbsMossObject implements MossObject { 10 | 11 | /** 12 | * Display entropy pool size 13 | */ 14 | public PoolSize() { } 15 | 16 | public DataProvider getDataProvider() { 17 | return entropy; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return Common.humanReadble(entropy.getPoolSize()); 23 | } 24 | 25 | private ProcEntropy entropy = ProcEntropy.INSTANCE; 26 | } 27 | 28 | public static class Available extends AbsMossObject implements MossObject { 29 | 30 | /** 31 | * Display entropy available 32 | */ 33 | public Available() { } 34 | 35 | public DataProvider getDataProvider() { 36 | return entropy; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return Common.humanReadble(entropy.getAvailable()); 42 | } 43 | 44 | private ProcEntropy entropy = ProcEntropy.INSTANCE; 45 | } 46 | 47 | public static class Percent extends AbsMossObject implements MossObject { 48 | 49 | /** 50 | * Display percent of entropy available 51 | */ 52 | public Percent() { } 53 | 54 | public DataProvider getDataProvider() { 55 | return entropy; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return String.format("%.2f%%", entropy.getPerc() * 100.0f); 61 | } 62 | 63 | private ProcEntropy entropy = ProcEntropy.INSTANCE; 64 | } 65 | 66 | public static class Bar extends AbsBarObject implements MossObject { 67 | 68 | /** 69 | * Display a bar of the entropy avail / poolsize 70 | */ 71 | public Bar(String hw) throws ParseException { 72 | super(hw); 73 | } 74 | 75 | public DataProvider getDataProvider() { 76 | return battInfo; 77 | } 78 | 79 | public void preDraw(Env env) { } 80 | 81 | public void draw(Env env) { 82 | doDraw(env, battInfo.getPerc()); 83 | } 84 | 85 | public void postDraw(Env env) { } 86 | 87 | private ProcEntropy battInfo = ProcEntropy.INSTANCE; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/FSBar.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.objects.FSJni.StatFS; 5 | 6 | public class FSBar extends AbsBarObject implements MossObject { 7 | 8 | /** 9 | * Display current file system usage in a usage bar. 10 | * 11 | * @param mountPoint Mount point such as /sdcard, /system or /data 12 | */ 13 | 14 | public FSBar(String mountPoint) { 15 | super(); 16 | fs.registerPath(mountPoint); 17 | this.mountPoint = mountPoint; 18 | } 19 | 20 | public FSBar(String hw, String mountPoint) { 21 | super(hw); 22 | fs.registerPath(mountPoint); 23 | this.mountPoint = mountPoint; 24 | } 25 | 26 | public DataProvider getDataProvider() { 27 | return fs; 28 | } 29 | 30 | public void preDraw(Env env) { } 31 | 32 | public void draw(Env env) { 33 | StatFS stat = fs.getStatFS(mountPoint); 34 | float frac = stat.usedBytes / (float) stat.totalBytes; 35 | 36 | doDraw(env, frac); 37 | } 38 | 39 | public void postDraw(Env env) { } 40 | 41 | private FSJni fs = FSJni.INSTANCE; 42 | private String mountPoint; 43 | } 44 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/FSFree.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | import org.mosspaper.objects.FSJni.StatFS; 5 | 6 | public class FSFree extends AbsMossObject implements MossObject { 7 | 8 | /** 9 | * Display available diskspace. 10 | * 11 | * @param mountPoint Mount point such as /sdcard, /system or /data 12 | */ 13 | public FSFree(String mountPoint) { 14 | fs.registerPath(mountPoint); 15 | this.mountPoint = mountPoint; 16 | } 17 | 18 | public DataProvider getDataProvider() { 19 | return fs; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | StatFS stat = fs.getStatFS(mountPoint); 25 | return Common.humanReadble(stat.freeBytes); 26 | } 27 | 28 | private FSJni fs = FSJni.INSTANCE; 29 | private String mountPoint; 30 | } 31 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/FSJni.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.content.Context; 4 | 5 | import org.mosspaper.DataService.State; 6 | 7 | import java.util.Map; 8 | import java.util.HashMap; 9 | 10 | public enum FSJni implements DataProvider { 11 | 12 | INSTANCE; 13 | 14 | public class StatFS { 15 | public String path; 16 | public long f_type; 17 | public long f_bsize; 18 | public long f_blocks; 19 | public long f_bfree; 20 | public long f_bavail; 21 | 22 | public long freeBytes; 23 | public long usedBytes; 24 | public long totalBytes; 25 | } 26 | 27 | public native void getFsInfo(String path, StatFS statFS); 28 | 29 | public synchronized void registerPath(String path) { 30 | if (null == stats) { 31 | stats = new HashMap(); 32 | } 33 | if (null == stats.get(path)) { 34 | StatFS fs = new StatFS(); 35 | fs.path = path; 36 | stats.put(path, fs); 37 | } 38 | } 39 | 40 | public void startup(Context context) { } 41 | 42 | public synchronized void update(State state) { 43 | for (StatFS fs : stats.values()) { 44 | getFsInfo(fs.path, fs); 45 | 46 | fs.freeBytes = fs.f_bsize * fs.f_bfree; 47 | fs.totalBytes = fs.f_bsize * fs.f_blocks; 48 | fs.usedBytes = fs.totalBytes - fs.freeBytes; 49 | } 50 | } 51 | 52 | public void destroy(Context context) { } 53 | 54 | public boolean runWhenInvisible() { 55 | return false; 56 | } 57 | 58 | public synchronized StatFS getStatFS(String path) { 59 | return stats.get(path); 60 | } 61 | 62 | private Map stats; 63 | 64 | static { 65 | System.loadLibrary("moss"); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/FSSize.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | import org.mosspaper.objects.FSJni.StatFS; 5 | 6 | public class FSSize extends AbsMossObject implements MossObject { 7 | 8 | /** 9 | * Display disk size. 10 | * 11 | * @param mountPoint Mount point such as /sdcard, /system or /data 12 | */ 13 | public FSSize(String mountPoint) { 14 | fs.registerPath(mountPoint); 15 | this.mountPoint = mountPoint; 16 | } 17 | 18 | public DataProvider getDataProvider() { 19 | return fs; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | StatFS stat = fs.getStatFS(mountPoint); 25 | return Common.humanReadble(stat.totalBytes); 26 | } 27 | 28 | private FSJni fs = FSJni.INSTANCE; 29 | private String mountPoint; 30 | } 31 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/FSUsed.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | import org.mosspaper.objects.FSJni.StatFS; 5 | 6 | public class FSUsed extends AbsMossObject implements MossObject { 7 | 8 | /** 9 | * Display the amount of disk usage. 10 | * 11 | * @param mountPoint Mount point such as /sdcard, /system or /data 12 | */ 13 | public FSUsed(String mountPoint) { 14 | fs.registerPath(mountPoint); 15 | this.mountPoint = mountPoint; 16 | } 17 | 18 | public DataProvider getDataProvider() { 19 | return fs; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | StatFS stat = fs.getStatFS(mountPoint); 25 | return Common.humanReadble(stat.usedBytes); 26 | } 27 | 28 | private FSJni fs = FSJni.INSTANCE; 29 | private String mountPoint; 30 | } 31 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/FSUsedPerc.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.objects.FSJni.StatFS; 4 | 5 | public class FSUsedPerc extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the amount of disk usage. 9 | * 10 | * @param mountPoint Mount point such as /sdcard, /system or /data 11 | */ 12 | public FSUsedPerc(String mountPoint) { 13 | fs.registerPath(mountPoint); 14 | this.mountPoint = mountPoint; 15 | } 16 | 17 | public DataProvider getDataProvider() { 18 | return fs; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | StatFS stat = fs.getStatFS(mountPoint); 24 | float frac = 100.0f * (stat.usedBytes / (float) stat.totalBytes); 25 | 26 | return String.format("%.2f", frac); 27 | } 28 | 29 | private FSJni fs = FSJni.INSTANCE; 30 | private String mountPoint; 31 | } 32 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Font.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.graphics.Typeface; 4 | 5 | import org.mosspaper.Env; 6 | import org.mosspaper.Config; 7 | import org.mosspaper.ParseException; 8 | 9 | import java.io.File; 10 | import java.util.Map; 11 | import java.util.HashMap; 12 | 13 | public class Font implements MossObject { 14 | 15 | private FontInfo mFontInfo; 16 | 17 | static class FontInfo { 18 | String family; 19 | int size; 20 | int style; 21 | 22 | @Override 23 | public String toString() { 24 | return family + ":" + size; 25 | } 26 | } 27 | 28 | /** 29 | * Reset to the current font. 30 | */ 31 | public Font() { 32 | this.mFontInfo = null; 33 | } 34 | 35 | /** 36 | * Change to the font described in font 37 | * 38 | * @param font The font to switch to for drawing 39 | */ 40 | public Font(String font) throws ParseException { 41 | this(); 42 | if (null != fontMap.get(font)) { 43 | this.mFontInfo = fontMap.get(font); 44 | } else { 45 | this.mFontInfo = parseFont(font); 46 | } 47 | if (ttfMap.get(mFontInfo.family) == null) { 48 | Typeface t = Typeface.create(mFontInfo.family, mFontInfo.style); 49 | ttfMap.put(mFontInfo.family, t); 50 | } 51 | } 52 | 53 | public void preDraw(Env env) { } 54 | 55 | public void draw(Env env) { 56 | if (mFontInfo == null) { 57 | env.getPaint().setTextSize(env.getFontSize()); 58 | env.getPaint().setTypeface(Typeface.MONOSPACE); 59 | } else { 60 | Typeface t = ttfMap.get(mFontInfo.family); 61 | if (t != null) { 62 | env.getPaint().setTypeface(t); 63 | } 64 | env.getPaint().setTextSize(mFontInfo.size); 65 | } 66 | env.setLineHeight(env.getPaint().getTextSize()); 67 | } 68 | 69 | public void postDraw(Env env) { } 70 | 71 | public DataProvider getDataProvider() { 72 | return null; 73 | } 74 | 75 | public static int getDefaultFontSize() { 76 | return fontMap.get("default").size; 77 | } 78 | 79 | public static void loadFont(String alias, String font) throws ParseException { 80 | fontMap.put(alias, parseFont(font)); 81 | } 82 | 83 | public static void addFontObject(String alias, String font) throws ParseException { 84 | TextObjects.TEXT_OBJECTS.put(alias, new TextObjects.FontArgs(font)); 85 | } 86 | 87 | public static void loadTypeface(Env env, String family, String path) throws ParseException { 88 | try { 89 | Typeface t = null; 90 | File f = new File(path); 91 | if (f.isAbsolute()) { 92 | t = Typeface.createFromFile(path); 93 | } else { 94 | if (null != env && env.getConfigFile() != null) { 95 | File parentFile = env.getConfigFile().getParentFile(); 96 | if (parentFile != null) { 97 | File fullpath = new File(parentFile, path); 98 | t = Typeface.createFromFile(fullpath.toString()); 99 | } 100 | } 101 | } 102 | if (t != null) { 103 | ttfMap.put(family, t); 104 | } else { 105 | throw new ParseException("Unable to load " + path); 106 | } 107 | } catch (RuntimeException e) { 108 | throw new ParseException("Unable to load " + path); 109 | } 110 | } 111 | 112 | static FontInfo parseFont(String font) throws ParseException { 113 | 114 | FontInfo f = new FontInfo(); 115 | String[] arr = font.split(":"); 116 | f.family = arr[0]; 117 | 118 | try { 119 | f.size = new Integer(font.replaceAll(".*size=(\\d+).*", "$1")); 120 | } catch (NumberFormatException e) { 121 | throw new ParseException("Unable to parse font!"); 122 | } 123 | parseStyle(f, font); 124 | 125 | return f; 126 | } 127 | 128 | static void parseStyle(FontInfo fi, String font) { 129 | String style = null == font ? "" : font.toLowerCase(); 130 | if (style.contains("bold")) { 131 | fi.style = Typeface.BOLD; 132 | } else if (style.contains("bold_italic")) { 133 | fi.style = Typeface.BOLD_ITALIC; 134 | } else if (style.contains("bold_italic")) { 135 | fi.style = Typeface.BOLD_ITALIC; 136 | } else { 137 | fi.style = Typeface.NORMAL; 138 | } 139 | } 140 | 141 | public static Map ttfMap; 142 | public static Map fontMap; 143 | 144 | static { 145 | FontInfo fi = new FontInfo(); 146 | fi.family = "Droid Sans Mono"; 147 | fi.size = (int) Config.CONF_FONT_SIZE_VALUE; 148 | 149 | fontMap = new HashMap(); 150 | fontMap.put("default", fi); 151 | 152 | ttfMap = new HashMap(); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Freq.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.ParseException; 4 | 5 | public class Freq extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Returns firts CPU's frequency in MHz. 9 | */ 10 | public Freq() throws ParseException { 11 | this.cpuNum = 1; 12 | freqInfo.registerCpu(cpuNum); 13 | } 14 | 15 | /** 16 | * Returns CPU n's frequency in MHz. 17 | * 18 | * @param cpuNum the cpu number 19 | */ 20 | public Freq(String cpuNum) throws ParseException { 21 | try { 22 | this.cpuNum = Integer.parseInt(cpuNum); 23 | } catch (NumberFormatException e) { 24 | throw new ParseException("Invalid cpu number"); 25 | } 26 | freqInfo.registerCpu(this.cpuNum); 27 | } 28 | 29 | public DataProvider getDataProvider() { 30 | return freqInfo; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return String.format("%.2f", freqInfo.getFreq(cpuNum) / 1000.0); 36 | } 37 | 38 | private CpuFreqProvider freqInfo = CpuFreqProvider.INSTANCE; 39 | private int cpuNum; 40 | } 41 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Goto.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.ParseException; 5 | 6 | public class Goto implements MossObject { 7 | 8 | /** 9 | * Change current horizontal location to postition 10 | * 11 | * @param position the new position 12 | */ 13 | public Goto(String pixels) throws ParseException { 14 | try { 15 | this.mPosition = Integer.parseInt(pixels); 16 | } catch (NumberFormatException e) { 17 | throw new ParseException(String.format("Invalid pixels: '%s'", pixels)); 18 | } 19 | } 20 | 21 | public void preDraw(Env env) { } 22 | 23 | public void draw(Env env) { 24 | env.setX(mPosition); 25 | } 26 | 27 | public void postDraw(Env env) { } 28 | 29 | public DataProvider getDataProvider() { 30 | return null; 31 | } 32 | 33 | private int mPosition; 34 | } 35 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Graphable.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public interface Graphable { 4 | 5 | public long getValue(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/HRule.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.graphics.Paint; 4 | import android.graphics.Paint.Style; 5 | 6 | import org.mosspaper.Env; 7 | import org.mosspaper.ParseException; 8 | 9 | public class HRule implements MossObject { 10 | 11 | /** 12 | * Draw a horizontal rule using the default line height. 13 | */ 14 | public HRule() { 15 | lineHeight = DEF_HEIGHT; 16 | } 17 | 18 | /** 19 | * Draw a horizontal rule using a line height of lh. 20 | * 21 | * @param lh a number, used as the new line height 22 | */ 23 | public HRule(String lh) throws ParseException { 24 | try { 25 | lineHeight = new Float(lh).floatValue(); 26 | } catch (NumberFormatException e) { 27 | throw new ParseException(String.format("Invalid line height: '%s'", lh)); 28 | } 29 | } 30 | 31 | public void preDraw(Env env) { } 32 | 33 | public void draw(Env env) { 34 | final Paint p = env.getPaint(); 35 | Style s = p.getStyle(); 36 | p.setStyle(Style.FILL); 37 | 38 | /* move cursor to bottom of text and draw up */ 39 | float y = env.getY() + env.getLineHeight(); 40 | env.getCanvas().drawRect( 41 | env.getX(), y, 42 | env.getMaxX(), y - lineHeight, 43 | env.getPaint()); 44 | 45 | p.setStyle(s); 46 | // env.setX(env.getMaxX()); 47 | } 48 | 49 | public void postDraw(Env env) { } 50 | 51 | public DataProvider getDataProvider() { 52 | return null; 53 | } 54 | 55 | private float lineHeight; 56 | static final float DEF_HEIGHT = 1f; 57 | } 58 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Image.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | 6 | import org.mosspaper.Env; 7 | import org.mosspaper.ParseException; 8 | 9 | import java.io.File; 10 | 11 | public class Image implements MossObject { 12 | 13 | /** 14 | * Draw the image specified by the path. The cursor position will not be 15 | * changed. 16 | */ 17 | public Image(String imagePath) { 18 | this.imagePath = imagePath; 19 | } 20 | 21 | public void preDraw(Env env) { 22 | if (bitmap != null) { 23 | return; 24 | } 25 | File image = new File(imagePath); 26 | if (image.isAbsolute()) { 27 | bitmap = 28 | BitmapFactory.decodeFile(imagePath); 29 | } else { 30 | File parentFile = env.getConfigFile().getParentFile(); 31 | bitmap = 32 | BitmapFactory.decodeFile(new File(parentFile, imagePath).toString()); 33 | } 34 | } 35 | 36 | public void draw(Env env) { 37 | if (bitmap != null) { 38 | env.getCanvas().drawBitmap( 39 | bitmap, env.getX(), env.getY(), env.getPaint()); 40 | } 41 | } 42 | 43 | public void postDraw(Env env) { } 44 | 45 | public DataProvider getDataProvider() { 46 | return null; 47 | } 48 | 49 | private Bitmap bitmap; 50 | private String imagePath; 51 | } 52 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Interval.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.ParseException; 4 | 5 | public class Interval extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Changed the current update interval. 9 | */ 10 | public Interval(String i) throws ParseException { 11 | try { 12 | float tmp = new Float(i).floatValue(); 13 | this.interval = (long) (tmp * 1000.0f); 14 | } catch (NumberFormatException e) { 15 | throw new ParseException("Invalid interval"); 16 | } 17 | } 18 | 19 | public DataProvider getDataProvider() { 20 | return null; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return null; 26 | } 27 | 28 | public long getInterval() { 29 | return interval; 30 | } 31 | 32 | private long interval; 33 | } 34 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Kernel.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class Kernel extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Display the kernel version. 7 | */ 8 | public Kernel() { } 9 | 10 | public DataProvider getDataProvider() { 11 | return uname; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return uname.getRelease(); 17 | } 18 | 19 | private UnameProvider uname = UnameProvider.INSTANCE; 20 | } 21 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Length.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.util.Log; 4 | 5 | import org.mosspaper.Env; 6 | import org.mosspaper.ParseException; 7 | 8 | import java.util.IllegalFormatException; 9 | 10 | public class Length extends AbsMossObject implements MossObject { 11 | 12 | /** 13 | * Limit an objects output to a certain number of characters. 14 | * 15 | * @param minLength minimum length of the string 16 | * @param maxLength max length of the string 17 | * @param object a text object whose output will be limited to N characters 18 | */ 19 | public Length(String minLength, String maxLength, MossObject object) throws ParseException { 20 | try { 21 | this.min = Integer.parseInt(minLength); 22 | } catch (NumberFormatException e) { 23 | throw new ParseException(String.format("Incorrect length attribute %s", minLength)); 24 | } 25 | try { 26 | this.max = Integer.parseInt(maxLength); 27 | } catch (NumberFormatException e) { 28 | throw new ParseException(String.format("Incorrect length attribute %s", maxLength)); 29 | } 30 | this.object = object; 31 | if (!(this.object instanceof AbsMossObject)) { 32 | throw new ParseException("Incorrect type"); 33 | } 34 | } 35 | 36 | public DataProvider getDataProvider() { 37 | return null; 38 | } 39 | 40 | public void preDraw(Env env) { 41 | object.preDraw(env); 42 | } 43 | 44 | public void postDraw(Env env) { 45 | object.postDraw(env); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | String v = object.toString(); 51 | if (null == v) { 52 | v = ""; 53 | } 54 | return String.format("%-" + min + "." + max + "s", v); 55 | } 56 | 57 | private MossObject object; 58 | private int min; 59 | private int max; 60 | } 61 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/LoadAvg.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.ParseException; 4 | 5 | public class LoadAvg extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the 1, 5 and 15 minute load avgerage of jobs in the run queue. 9 | */ 10 | public LoadAvg() { 11 | this.idx = -1; 12 | } 13 | 14 | /** 15 | * Display either 1, 5 or 15 minute load avgerage of jobs in the run queue. 16 | * 17 | * @param idx An integer value, 1 >e; idx <e; 3. 18 | */ 19 | public LoadAvg(String idx) throws ParseException { 20 | try { 21 | this.idx = Integer.parseInt(idx); 22 | if (this.idx < 1 || this.idx > 3) { 23 | throw new ParseException(String.format("Invalid index: '%s'", idx)); 24 | } 25 | } catch (NumberFormatException e) { 26 | throw new ParseException(String.format("Invalid index: '%s'", idx)); 27 | } 28 | } 29 | 30 | public DataProvider getDataProvider() { 31 | return ProcLoadAvg.INSTANCE; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | String[] loadAvg = ProcLoadAvg.INSTANCE.getLoadAvg(); 37 | if (idx == -1 && loadAvg.length == 3) { 38 | return String.format("%s %s %s", loadAvg[0], loadAvg[1], loadAvg[2]); 39 | } else if (idx < loadAvg.length) { 40 | return String.format("%s", loadAvg[idx]); 41 | } else { 42 | return "Unavailable"; 43 | } 44 | } 45 | 46 | private int idx; 47 | } 48 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Machine.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class Machine extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Display the machine name 7 | */ 8 | public Machine() { } 9 | 10 | public DataProvider getDataProvider() { 11 | return uname; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return uname.getMachine(); 17 | } 18 | 19 | private UnameProvider uname = UnameProvider.INSTANCE; 20 | } 21 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Mem.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | public class Mem extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display memory used. 9 | */ 10 | public Mem() { 11 | } 12 | 13 | public DataProvider getDataProvider() { 14 | return memInfo; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return Common.humanReadble(memInfo.getMemTotal() - memInfo.getMemFree()); 20 | } 21 | 22 | private ProcMemInfo memInfo = ProcMemInfo.INSTANCE; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/MemBar.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | 5 | public class MemBar extends AbsBarObject implements MossObject { 6 | 7 | /** 8 | * Display memory used in a bar graph. 9 | */ 10 | public MemBar() { 11 | super(); 12 | } 13 | 14 | /** 15 | * Display memory used in a bar graph. 16 | * 17 | * @param hw comma delimited string of height and width 18 | */ 19 | public MemBar(String hw) { 20 | super(hw); 21 | } 22 | 23 | public DataProvider getDataProvider() { 24 | return memInfo; 25 | } 26 | 27 | public void preDraw(Env env) { } 28 | 29 | public void draw(Env env) { 30 | float perc = 0.0f; 31 | if (memInfo.getMemTotal() > 0) { 32 | perc = (memInfo.getMemTotal() - memInfo.getMemFree()) 33 | / (float) memInfo.getMemTotal(); 34 | } 35 | doDraw(env, perc); 36 | } 37 | 38 | public void postDraw(Env env) { } 39 | 40 | private ProcMemInfo memInfo = ProcMemInfo.INSTANCE; 41 | } 42 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/MemMax.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | public class MemMax extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the maximum available memory. 9 | */ 10 | public MemMax() { 11 | } 12 | 13 | public DataProvider getDataProvider() { 14 | return memInfo; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return Common.humanReadble(memInfo.getMemTotal()); 20 | } 21 | 22 | private ProcMemInfo memInfo = ProcMemInfo.INSTANCE; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/MemPerc.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class MemPerc extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Display the percentage of memory being used. 7 | */ 8 | public MemPerc() { } 9 | 10 | public DataProvider getDataProvider() { 11 | return memInfo; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | double perc = 0.0; 17 | if (memInfo.getMemTotal() > 0) { 18 | perc = (double) (memInfo.getMemTotal() - memInfo.getMemFree()) 19 | / (double) memInfo.getMemTotal(); 20 | } 21 | return String.valueOf(Math.ceil(perc * 100.0)); 22 | } 23 | 24 | private ProcMemInfo memInfo = ProcMemInfo.INSTANCE; 25 | } 26 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/MossObject.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | 5 | public interface MossObject { 6 | 7 | public void preDraw(Env env); 8 | 9 | public void draw(Env env); 10 | 11 | public void postDraw(Env env); 12 | 13 | public DataProvider getDataProvider(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Nodename.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class Nodename extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Display the system name 7 | */ 8 | public Nodename() { } 9 | 10 | public DataProvider getDataProvider() { 11 | return uname; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return uname.getNodename(); 17 | } 18 | 19 | private UnameProvider uname = UnameProvider.INSTANCE; 20 | } 21 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Offset.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.ParseException; 5 | 6 | public class Offset implements MossObject { 7 | 8 | /** 9 | * Move text horizontally by N pixels 10 | * 11 | * @param pixels the number of pixels 12 | */ 13 | public Offset(String pixels) throws ParseException { 14 | try { 15 | this.mPixels = Integer.parseInt(pixels); 16 | } catch (NumberFormatException e) { 17 | throw new ParseException(String.format("Invalid pixels: '%s'", pixels)); 18 | } 19 | } 20 | 21 | public void preDraw(Env env) { } 22 | 23 | public void draw(Env env) { 24 | env.setX(env.getX() + mPixels); 25 | } 26 | 27 | public void postDraw(Env env) { } 28 | 29 | public DataProvider getDataProvider() { 30 | return null; 31 | } 32 | 33 | private int mPixels; 34 | } 35 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/PortMon.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.ParseException; 5 | import org.mosspaper.objects.ProcList.Proc; 6 | 7 | import java.util.List; 8 | import java.util.Collections; 9 | import java.util.Comparator; 10 | 11 | public class PortMon extends AbsMossObject implements MossObject { 12 | 13 | public PortMon(String startPort, String endPort, String var, String num) throws ParseException { 14 | this.var = var; 15 | this.num = Integer.parseInt(num); 16 | try { 17 | this.sp = Integer.parseInt(startPort); 18 | this.ep = Integer.parseInt(endPort); 19 | 20 | this.item = portMon.registerMonitor(var, sp, ep); 21 | } catch (NumberFormatException e) { 22 | new ParseException("Invalid port range"); 23 | } 24 | } 25 | 26 | public DataProvider getDataProvider() { 27 | return this.portMon; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | if (item > 0) { 33 | return portMon.monpeek(sp, ep, item, num); 34 | } else { 35 | return ""; 36 | } 37 | } 38 | 39 | protected String var; 40 | protected int num; 41 | protected int item; 42 | protected int sp; 43 | protected int ep; 44 | 45 | static PortMonProvider portMon = PortMonProvider.INSTANCE; 46 | } 47 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/PortMonProvider.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.content.Context; 4 | 5 | import org.mosspaper.DataService.State; 6 | 7 | import java.util.List; 8 | import java.util.ArrayList; 9 | 10 | public enum PortMonProvider implements DataProvider { 11 | 12 | INSTANCE; 13 | 14 | class Range { 15 | public Range(int s, int e) { 16 | this.s = s; 17 | this.e = e; 18 | } 19 | int s; 20 | int e; 21 | } 22 | 23 | PortMonProvider() { 24 | this.started = false; 25 | this.ranges = new ArrayList(); 26 | } 27 | 28 | public int registerMonitor(String var, int startPort, int endPort) { 29 | addRange(new Range(startPort, endPort)); 30 | return monitemlookup(var); 31 | } 32 | 33 | private void addRange(Range r) { 34 | for (Range ra : ranges) { 35 | if (ra.s == r.s && ra.e == r.e) { 36 | return; 37 | } 38 | } 39 | ranges.add(r); 40 | } 41 | 42 | @Override 43 | public void startup(Context context) { 44 | if (!started) { 45 | moninit(); 46 | for (Range r : ranges) { 47 | monadd(r.s, r.e); 48 | } 49 | started = true; 50 | } 51 | /* set the initial state */ 52 | update(null); 53 | } 54 | 55 | @Override 56 | public void update(State state) { 57 | monupdate(); 58 | } 59 | 60 | @Override 61 | public void destroy(Context context) { 62 | mondestroy(); 63 | started = false; 64 | } 65 | 66 | @Override 67 | public boolean runWhenInvisible() { 68 | return false; 69 | } 70 | 71 | private List ranges; 72 | private boolean started = false; 73 | private native void moninit(); 74 | private native void monupdate(); 75 | private native void mondestroy(); 76 | private native int monitemlookup(String str); 77 | private native boolean monadd(int startPort, int endPort); 78 | public native String monpeek(int startPort, int endPort, int item, int index); 79 | 80 | static { 81 | System.loadLibrary("moss"); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Printf.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.util.Log; 4 | 5 | import org.mosspaper.Env; 6 | import org.mosspaper.ParseException; 7 | 8 | import java.util.IllegalFormatException; 9 | 10 | public class Printf extends AbsMossObject implements MossObject { 11 | 12 | static final String TAG = "Printf"; 13 | 14 | /** 15 | * Accepts a format string and other text objects. 16 | * 17 | * @param format a format string as describe in... 18 | * @param objects a variable list of text objects 19 | */ 20 | public Printf(String format, Object... objects) throws ParseException { 21 | this.format = format; 22 | this.objects = objects; 23 | for (Object o : objects) { 24 | if (o instanceof MossObject 25 | && !(o instanceof AbsMossObject)) { 26 | throw new ParseException("Incorrect type"); 27 | } 28 | } 29 | } 30 | 31 | public DataProvider getDataProvider() { 32 | /* XXX: this only works for one */ 33 | for (Object o : objects) { 34 | if (o instanceof MossObject) { 35 | MossObject ms = (MossObject)o; 36 | if (ms.getDataProvider() != null) { 37 | return ms.getDataProvider(); 38 | } 39 | } 40 | } 41 | return null; 42 | } 43 | 44 | public void preDraw(Env env) { 45 | for (Object o : objects) { 46 | if (o instanceof MossObject) { 47 | ((MossObject) o).preDraw(env); 48 | } 49 | } 50 | } 51 | 52 | public void postDraw(Env env) { 53 | for (Object o : objects) { 54 | if (o instanceof MossObject) { 55 | ((MossObject) o).postDraw(env); 56 | } 57 | } 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | String[] strs = new String[objects.length]; 63 | for (int i = 0; i < objects.length; i++) { 64 | if (null != objects[i]) { 65 | strs[i] = nvl(objects[i].toString(), ""); 66 | } else { 67 | strs[i] = ""; 68 | } 69 | } 70 | try { 71 | return String.format(format, (Object[]) strs); 72 | } catch (IllegalFormatException e) { 73 | Log.e(TAG, "", e); 74 | } catch (NullPointerException e) { 75 | Log.e(TAG, "", e); 76 | } 77 | return ""; 78 | } 79 | 80 | private String nvl(String s1, String s2) { 81 | if (null == s1) { 82 | return s2; 83 | } else { 84 | return s1; 85 | } 86 | } 87 | 88 | private String format; 89 | private Object[] objects; 90 | } 91 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/ProcEntropy.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import org.mosspaper.DataService.State; 7 | 8 | import java.io.BufferedReader; 9 | import java.io.FileReader; 10 | import java.io.IOException; 11 | 12 | public enum ProcEntropy implements DataProvider { 13 | 14 | INSTANCE; 15 | 16 | ProcEntropy() { } 17 | 18 | public void startup(Context context) { } 19 | 20 | private long slurp(String filePath) throws IOException { 21 | StringBuffer buf = new StringBuffer(""); 22 | BufferedReader reader = 23 | new BufferedReader(new FileReader(filePath), INIT_BUFFER); 24 | try { 25 | String str; 26 | while ((str = reader.readLine()) != null) { 27 | buf.append(str).append("\n"); 28 | } 29 | } finally { 30 | reader.close(); 31 | } 32 | return Long.parseLong(buf.toString().trim()); 33 | } 34 | 35 | public synchronized void update(State state) { 36 | String devStr; 37 | try { 38 | available = slurp("/proc/sys/kernel/random/entropy_avail"); 39 | poolSize = slurp("/proc/sys/kernel/random/poolsize"); 40 | } catch (Exception e) { 41 | Log.e(TAG, "IO Exception getting entropy", e); 42 | } 43 | } 44 | 45 | public synchronized long getAvailable() { 46 | return available; 47 | } 48 | 49 | public synchronized long getPoolSize() { 50 | return poolSize; 51 | } 52 | 53 | public synchronized float getPerc() { 54 | if (poolSize == 0) { 55 | return 0.0f; 56 | } else { 57 | return available / (float) poolSize; 58 | } 59 | } 60 | 61 | public void destroy(Context context) { } 62 | 63 | public boolean runWhenInvisible() { 64 | return false; 65 | } 66 | 67 | static long available = 0; 68 | static long poolSize = 0; 69 | 70 | static final int INIT_BUFFER = 64; 71 | static final String TAG = "ProcEntropy"; 72 | } 73 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/ProcLoadAvg.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import org.mosspaper.DataService.State; 7 | 8 | import java.io.BufferedReader; 9 | import java.io.FileReader; 10 | import java.io.IOException; 11 | import java.util.regex.Matcher; 12 | import java.util.regex.Pattern; 13 | 14 | public enum ProcLoadAvg implements DataProvider { 15 | 16 | INSTANCE; 17 | 18 | static final String TAG = "ProcLoadAvg"; 19 | 20 | private String[] loadAvg; 21 | private Pattern regex; 22 | 23 | ProcLoadAvg() { 24 | final String LOAD_AVG_REGEX = "^(.+?) (.+?) (.+?) .*$"; 25 | this.loadAvg = new String[] {"", "", ""}; 26 | this.regex = Pattern.compile(LOAD_AVG_REGEX);; 27 | } 28 | 29 | public void startup(Context context) { } 30 | 31 | public synchronized void update(State state) { 32 | String loadAvgStr; 33 | try { 34 | BufferedReader reader = new BufferedReader(new FileReader("/proc/loadavg"), 256); 35 | try { 36 | loadAvgStr = reader.readLine(); 37 | } finally { 38 | reader.close(); 39 | } 40 | 41 | Matcher m = regex.matcher(loadAvgStr); 42 | 43 | if (!m.matches()) { 44 | Log.e(TAG, "Regex did not match on /proc/version: " + loadAvgStr); 45 | } else { 46 | loadAvg[0] = m.group(1); 47 | loadAvg[1] = m.group(2); 48 | loadAvg[2] = m.group(3); 49 | 50 | return; 51 | } 52 | } catch (IOException e) { 53 | Log.e(TAG, "IO Exception getting /proc/loadavg", e); 54 | } 55 | } 56 | 57 | public void destroy(Context context) { } 58 | 59 | public boolean runWhenInvisible() { 60 | return false; 61 | } 62 | 63 | public synchronized String[] getLoadAvg() { 64 | return loadAvg; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/ProcMemInfo.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import org.mosspaper.DataService.State; 7 | 8 | import java.io.BufferedReader; 9 | import java.io.FileReader; 10 | import java.io.IOException; 11 | 12 | public enum ProcMemInfo implements DataProvider { 13 | 14 | INSTANCE; 15 | 16 | static final String TAG = "ProcMemInfo"; 17 | 18 | public void startup(Context context) { } 19 | 20 | public synchronized void update(State state) { 21 | String loadAvgStr; 22 | try { 23 | BufferedReader reader = new BufferedReader(new FileReader("/proc/meminfo"), 1024); 24 | try { 25 | while ((loadAvgStr = reader.readLine()) != null) { 26 | /* 0: label, 1: value, 2: human readable */ 27 | String[] split = loadAvgStr.split("\\s+"); 28 | if (split.length == 3) { 29 | long value = 0; 30 | try { 31 | value = new Long(split[1]).longValue(); 32 | if ("kB".equals(split[2])) { 33 | value = value * 1024; 34 | } 35 | } catch (NumberFormatException e) { 36 | Log.e(TAG, "", e); 37 | } 38 | if ("MemTotal:".equals(split[0])) { 39 | memTotal = value; 40 | } else if ("MemFree:".equals(split[0])) { 41 | memFree = value; 42 | } else if ("Buffers:".equals(split[0])) { 43 | buffers = value; 44 | } else if ("Cached:".equals(split[0])) { 45 | cached = value; 46 | } else if ("SwapTotal:".equals(split[0])) { 47 | swapTotal = value; 48 | } else if ("SwapFree:".equals(split[0])) { 49 | swapFree = value; 50 | } 51 | } 52 | } 53 | } finally { 54 | reader.close(); 55 | } 56 | } catch (IOException e) { 57 | Log.e(TAG, "IO Exception getting /proc/meminfo", e); 58 | } 59 | } 60 | 61 | public void destroy(Context context) { } 62 | 63 | public boolean runWhenInvisible() { 64 | return false; 65 | } 66 | 67 | public synchronized long getMemTotal() { 68 | return memTotal; 69 | } 70 | 71 | public synchronized long getMemFree() { 72 | return memFree; 73 | } 74 | 75 | public synchronized long getSwapTotal() { 76 | return swapTotal; 77 | } 78 | 79 | public synchronized long getSwapFree() { 80 | return swapFree; 81 | } 82 | 83 | public synchronized long getBuffers() { 84 | return buffers; 85 | } 86 | 87 | public synchronized long getCached() { 88 | return cached; 89 | } 90 | 91 | protected long memTotal; 92 | protected long memFree; 93 | protected long swapTotal; 94 | protected long swapFree; 95 | protected long buffers; 96 | protected long cached; 97 | } 98 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Processes.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class Processes extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Display the total number of forks since boot. 7 | */ 8 | public Processes() { } 9 | 10 | public DataProvider getDataProvider() { 11 | return stat; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return String.valueOf(stat.getProcessCount()); 17 | } 18 | 19 | private ProcList stat = ProcList.INSTANCE; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/ProcsRunning.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class ProcsRunning extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Number of processes in runnable state. 7 | */ 8 | public ProcsRunning() { } 9 | 10 | public DataProvider getDataProvider() { 11 | return stat; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return String.valueOf(stat.getProcsRunning()); 17 | } 18 | 19 | private ProcList stat = ProcList.INSTANCE; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Realtime.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | import android.os.SystemClock; 6 | 7 | public class Realtime extends AbsMossObject implements MossObject { 8 | 9 | /** 10 | * Display the systems time since the system was booted, including deep 11 | * sleep. 12 | */ 13 | public Realtime() { } 14 | 15 | @Override 16 | public String toString() { 17 | return Common.formatSeconds(SystemClock.elapsedRealtime() / 1000); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/StippledHRule.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.ParseException; 5 | 6 | import android.graphics.Paint; 7 | import android.graphics.Paint.Style; 8 | import android.graphics.DashPathEffect; 9 | 10 | public class StippledHRule extends HRule implements MossObject { 11 | 12 | /** 13 | * Draw a stippled horizontal rule with the default spacing. 14 | */ 15 | public StippledHRule() { 16 | super(); 17 | space = DEF_SPACE; 18 | } 19 | 20 | /** 21 | * Draw a stippled horizontal rule with the default spacing. 22 | * 23 | * @param spacing a number to specify the size of the dashes. 24 | */ 25 | public StippledHRule(String spacing) throws ParseException { 26 | super(); 27 | try { 28 | space = new Float(spacing).floatValue(); 29 | } catch (NumberFormatException e) { 30 | throw new ParseException(String.format("Invalid spacing: '%s'", spacing)); 31 | } 32 | } 33 | 34 | public void preDraw(Env env) { } 35 | 36 | public void draw(Env env) { 37 | final Paint p = env.getPaint(); 38 | Style s = p.getStyle(); 39 | p.setStyle(Paint.Style.STROKE); 40 | p.setPathEffect( 41 | new DashPathEffect(new float[] {space, space}, 0)); 42 | 43 | env.getCanvas().drawLine( 44 | env.getX(), env.getY(), 45 | env.getMaxX(), env.getY(), 46 | env.getPaint()); 47 | env.setY(env.getY() + env.getPaint().getTextSize()); 48 | 49 | p.setPathEffect(null); 50 | p.setStyle(s); 51 | } 52 | 53 | public void postDraw(Env env) { } 54 | 55 | private float space; 56 | 57 | static final float DEF_SPACE = 10f; 58 | } 59 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Swap.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | public class Swap extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the amount of swap memory being used. 9 | */ 10 | public Swap() { } 11 | 12 | public DataProvider getDataProvider() { 13 | return memInfo; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return Common.humanReadble(memInfo.getSwapTotal() - memInfo.getSwapFree()); 19 | } 20 | 21 | private ProcMemInfo memInfo = ProcMemInfo.INSTANCE; 22 | } 23 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/SwapBar.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.util.Bar; 5 | 6 | public class SwapBar extends AbsBarObject implements MossObject { 7 | 8 | /** 9 | * Display swap memory used in a bar graph. 10 | */ 11 | public SwapBar() { } 12 | 13 | /** 14 | * Display swap used in a bar graph. 15 | * 16 | * @param hw comma delimited string of height and width 17 | */ 18 | public SwapBar(String hw) { 19 | super(hw); 20 | } 21 | 22 | public DataProvider getDataProvider() { 23 | return memInfo; 24 | } 25 | 26 | public void preDraw(Env env) { } 27 | 28 | public void draw(Env env) { 29 | float perc = 0.0f; 30 | if (memInfo.getSwapTotal() > 0) { 31 | perc = (memInfo.getSwapTotal() - memInfo.getSwapFree()) 32 | / (float) memInfo.getSwapTotal(); 33 | } 34 | doDraw(env, perc); 35 | } 36 | 37 | public void postDraw(Env env) { } 38 | 39 | private ProcMemInfo memInfo = ProcMemInfo.INSTANCE; 40 | } 41 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/SwapMax.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | public class SwapMax extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the maximum swap memory available. 9 | */ 10 | public SwapMax() { 11 | this.memInfo = ProcMemInfo.INSTANCE; 12 | } 13 | 14 | public DataProvider getDataProvider() { 15 | return memInfo; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return Common.humanReadble(memInfo.getSwapTotal()); 21 | } 22 | 23 | private ProcMemInfo memInfo; 24 | } 25 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/SwapPerc.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class SwapPerc extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Display the percentage of swap memory being used. 7 | */ 8 | public SwapPerc() { 9 | this.memInfo = ProcMemInfo.INSTANCE; 10 | } 11 | 12 | public DataProvider getDataProvider() { 13 | return memInfo; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | double perc = 0.0; 19 | if (memInfo.getSwapTotal() > 0) { 20 | perc = (double) (memInfo.getSwapTotal() - memInfo.getSwapFree()) 21 | / (double) memInfo.getSwapTotal(); 22 | } 23 | return String.format("%.2f", perc * 100.0); 24 | } 25 | 26 | private ProcMemInfo memInfo; 27 | } 28 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/SysName.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class SysName extends AbsMossObject implements MossObject { 4 | 5 | /** 6 | * Display the system name 7 | */ 8 | public SysName() { } 9 | 10 | public DataProvider getDataProvider() { 11 | return uname; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return uname.getSysname(); 17 | } 18 | 19 | private UnameProvider uname = UnameProvider.INSTANCE; 20 | } 21 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Time.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | public class Time extends AbsMossObject { 4 | 5 | /** 6 | * Prints the local time formatted according to parameter. 7 | * 8 | * @param format uses C's strftime format to specify time format. 9 | */ 10 | public Time(String format) { 11 | this.mFormat = format; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return strftime(mFormat); 17 | } 18 | 19 | private native String strftime(String format); 20 | 21 | private String mFormat; 22 | 23 | static { 24 | System.loadLibrary("moss"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Top.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.objects.ProcList.Proc; 4 | 5 | import java.util.List; 6 | import java.util.Comparator; 7 | 8 | public class Top extends AbsTop implements MossObject { 9 | 10 | /** 11 | * Display information about the top running processes. For example to 12 | * display the top three processes, and their cpu usage: 13 | *

14 |      *  ${top name 1}${top cpu 1}
15 |      *  ${top name 2}${top cpu 2}
16 |      *  ${top name 3}${top cpu 3}
17 |      * 
18 | * 19 | * @param var The name of the variable to display 20 | * @param num An integer, >e; 1 21 | */ 22 | public Top(String var, String num) { 23 | super(var, num); 24 | } 25 | 26 | public Comparator getComparator() { 27 | return new Comparator() { 28 | public int compare(Proc p1, Proc p2) { 29 | if (p1 == p2 || p1.cpuPerc == p2.cpuPerc) { 30 | return 0; 31 | } else if (p1.cpuPerc < p2.cpuPerc) { 32 | return -1; 33 | } else { 34 | return 1; 35 | } 36 | } 37 | }; 38 | } 39 | 40 | public void setList(List ls) { 41 | this.ps = ls; 42 | } 43 | 44 | public List getList() { 45 | return this.ps; 46 | } 47 | 48 | protected static List ps; 49 | } 50 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/TopMem.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.objects.ProcList.Proc; 4 | 5 | import java.util.List; 6 | import java.util.Comparator; 7 | 8 | public class TopMem extends AbsTop implements MossObject { 9 | 10 | /** 11 | * Display information about the top memory consuming processes. For 12 | * example to display the top three processes, and their mem usage: 13 | *

14 |      *  ${top name 1}${top mem 1}
15 |      *  ${top name 2}${top mem 2}
16 |      *  ${top name 3}${top mem 3}
17 |      * 
18 | * 19 | * @param var The name of the variable to display 20 | * @param num An integer, >e; 1 21 | */ 22 | public TopMem(String var, String num) { 23 | super(var, num); 24 | } 25 | 26 | public Comparator getComparator() { 27 | return new Comparator() { 28 | public int compare(Proc p1, Proc p2) { 29 | if (p1 == p2 || p1.memPerc == p2.memPerc) { 30 | return 0; 31 | } else if (p1.memPerc < p2.memPerc) { 32 | return -1; 33 | } else { 34 | return 1; 35 | } 36 | } 37 | }; 38 | } 39 | 40 | public void setList(List ls) { 41 | this.ps = ls; 42 | } 43 | 44 | public List getList() { 45 | return this.ps; 46 | } 47 | 48 | protected static List ps; 49 | } 50 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/TotalDown.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | public class TotalDown extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the download speed for a network interface. 9 | * 10 | * @param device network device such as eth0 or wlan0 11 | */ 12 | public TotalDown(String device) { 13 | this.device = device; 14 | netDevInfo.registerDevice(device); 15 | } 16 | 17 | public DataProvider getDataProvider() { 18 | return netDevInfo; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return Common.humanReadble(netDevInfo.getTotalDown(device)); 24 | } 25 | 26 | private String device; 27 | private ProcNetDev netDevInfo = ProcNetDev.INSTANCE; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/TotalUp.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | public class TotalUp extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the download speed for a network interface. 9 | * 10 | * @param device network device such as eth0 or wlan0 11 | */ 12 | public TotalUp(String device) { 13 | this.device = device; 14 | netDevInfo.registerDevice(device); 15 | } 16 | 17 | public DataProvider getDataProvider() { 18 | return netDevInfo; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return Common.humanReadble(netDevInfo.getTotalUp(device)); 24 | } 25 | 26 | private String device; 27 | private ProcNetDev netDevInfo = ProcNetDev.INSTANCE; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/UnameProvider.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.content.Context; 4 | 5 | import org.mosspaper.DataService.State; 6 | 7 | public enum UnameProvider implements DataProvider { 8 | INSTANCE; 9 | 10 | private String sysname; 11 | private String nodename; 12 | private String release; 13 | private String version; 14 | private String machine; 15 | 16 | public native void setUname(); 17 | 18 | public void startup(Context context) { } 19 | 20 | public synchronized void update(State state) { 21 | /* We only need to gather this information once */ 22 | if (sysname != null) { 23 | return; 24 | } 25 | setUname(); 26 | } 27 | 28 | public void destroy(Context context) { } 29 | 30 | public boolean runWhenInvisible() { 31 | return false; 32 | } 33 | 34 | public String getSysname() { 35 | return sysname; 36 | } 37 | 38 | public String getNodename() { 39 | return nodename; 40 | } 41 | 42 | public String getRelease() { 43 | return release; 44 | } 45 | 46 | public String getMachine() { 47 | return machine; 48 | } 49 | 50 | static { 51 | System.loadLibrary("moss"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/UpSpeed.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | public class UpSpeed extends AbsMossObject implements MossObject { 6 | 7 | /** 8 | * Display the upload speed for a network interface. 9 | * 10 | * @param device network device such as eth0 or wlan0 11 | */ 12 | public UpSpeed(String device) { 13 | this.device = device; 14 | netDevInfo.registerDevice(device); 15 | } 16 | 17 | public DataProvider getDataProvider() { 18 | return netDevInfo; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return Common.humanReadble(netDevInfo.getUpSpeed(device)); 24 | } 25 | 26 | private String device; 27 | private ProcNetDev netDevInfo = ProcNetDev.INSTANCE; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/UpSpeedGraph.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | 5 | public class UpSpeedGraph extends AbsGraphObject implements MossObject { 6 | 7 | /** 8 | * Display a historical graph of upload speeds for a device. 9 | * 10 | * @param device network device such as eth0 or wlan0 11 | * @param hw height,width of the graph 12 | * @param color1 left most color of graph 13 | * @param color2 right most color of graph 14 | */ 15 | public UpSpeedGraph(String device, String hw, String color1, String color2) { 16 | super(hw, color1, color2); 17 | this.device = device; 18 | this.scale = 1024 * 10; 19 | netDevInfo.registerDevice(device, Math.round(width)); 20 | } 21 | 22 | public DataProvider getDataProvider() { 23 | return netDevInfo; 24 | } 25 | 26 | public void preDraw(Env env) { 27 | if (null == history) { 28 | history = netDevInfo.getUpHistory(device); 29 | if (null == history) { 30 | return; 31 | } 32 | int i = 0; 33 | } 34 | } 35 | 36 | public void postDraw(Env env) { 37 | history = null; 38 | } 39 | 40 | private String device; 41 | private ProcNetDev netDevInfo = ProcNetDev.INSTANCE; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/UpdateManager.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import android.util.Log; 4 | 5 | import org.mosspaper.DataService.State; 6 | 7 | public class UpdateManager { 8 | 9 | public UpdateManager(DataProvider data) { 10 | this.data = data; 11 | reset(); 12 | } 13 | 14 | public void setInterval(long newinterval) { 15 | if (interval == -1) { 16 | this.interval = newinterval; 17 | } else { 18 | this.interval = Math.min(this.interval, newinterval); 19 | } 20 | } 21 | 22 | public long getInterval() { 23 | return this.interval; 24 | } 25 | 26 | public void reset() { 27 | this.interval = -1; 28 | this.lastUpdate = 0L; 29 | } 30 | 31 | public void update(State state) { 32 | if (!state.isVisible() && !data.runWhenInvisible()) { 33 | return; 34 | } 35 | long now = System.currentTimeMillis(); 36 | if (Math.abs(now - lastUpdate) > interval) { 37 | data.update(state); 38 | lastUpdate = now; 39 | } 40 | } 41 | 42 | private DataProvider data; 43 | private long lastUpdate; 44 | private long interval; 45 | 46 | static final String TAG = "UpdateManager"; 47 | } 48 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/Uptime.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Common; 4 | 5 | import android.os.SystemClock; 6 | 7 | public class Uptime extends AbsMossObject implements MossObject { 8 | 9 | /** 10 | * Display the systems uptime. On android this does not include when the 11 | * system enters deep sleep. @see Realtime. 12 | */ 13 | public Uptime() { } 14 | 15 | @Override 16 | public String toString() { 17 | return Common.formatSeconds(SystemClock.uptimeMillis() / 1000); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/VGoto.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.ParseException; 5 | 6 | public class VGoto implements MossObject { 7 | 8 | /** 9 | * Change current vertical location to postition 10 | * 11 | * @param position the new position 12 | */ 13 | public VGoto(String position) throws ParseException { 14 | try { 15 | this.mPosition = Integer.parseInt(position); 16 | } catch (NumberFormatException e) { 17 | throw new ParseException(String.format("Invalid position: '%s'", position)); 18 | } 19 | } 20 | 21 | public void preDraw(Env env) { } 22 | 23 | public void draw(Env env) { 24 | env.setY(mPosition); 25 | } 26 | 27 | public void postDraw(Env env) { } 28 | 29 | public DataProvider getDataProvider() { 30 | return null; 31 | } 32 | 33 | private int mPosition; 34 | } 35 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/objects/VOffset.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.objects; 2 | 3 | import org.mosspaper.Env; 4 | import org.mosspaper.ParseException; 5 | 6 | public class VOffset implements MossObject { 7 | 8 | /** 9 | * Move text vertically by N pixels 10 | * 11 | * @param pixels the number of pixels 12 | */ 13 | public VOffset(String pixels) throws ParseException { 14 | try { 15 | this.mPixels = Integer.parseInt(pixels); 16 | } catch (NumberFormatException e) { 17 | throw new ParseException(String.format("Invalid pixels: '%s'", pixels)); 18 | } 19 | } 20 | 21 | public void preDraw(Env env) { } 22 | 23 | public void draw(Env env) { 24 | env.setY(env.getY() + mPixels); 25 | } 26 | 27 | public void postDraw(Env env) { } 28 | 29 | public DataProvider getDataProvider() { 30 | return null; 31 | } 32 | 33 | private int mPixels; 34 | } 35 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/prefs/IntervalPreference.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.prefs; 2 | 3 | import org.mosspaper.Config; 4 | import org.mosspaper.R; 5 | 6 | import android.content.Context; 7 | import android.content.res.Resources; 8 | import android.content.SharedPreferences; 9 | import android.preference.DialogPreference; 10 | import android.util.AttributeSet; 11 | import android.view.View; 12 | import android.widget.ArrayAdapter; 13 | import android.widget.AdapterView; 14 | import android.widget.AdapterView.OnItemSelectedListener; 15 | import android.widget.Spinner; 16 | import android.widget.EditText; 17 | 18 | public class IntervalPreference extends DialogPreference { 19 | 20 | static final String TAG = "IntervalPreference"; 21 | private EditText mText; 22 | private Spinner mSpinner; 23 | private int[] typeValues; 24 | private int intervalType; 25 | 26 | public IntervalPreference(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | setupLayout(context, attrs); 29 | } 30 | 31 | public IntervalPreference(Context context, AttributeSet attrs, int defStyle) { 32 | super(context, attrs, defStyle); 33 | setupLayout(context, attrs); 34 | } 35 | 36 | private void setupLayout(Context context, AttributeSet attrs) { 37 | Resources r = getContext().getResources(); 38 | typeValues = r.getIntArray(R.array.interval_values); 39 | 40 | setPersistent(true); 41 | setDialogLayoutResource(R.layout.dia_interval); 42 | } 43 | 44 | @Override 45 | protected View onCreateDialogView() { 46 | View view = super.onCreateDialogView(); 47 | 48 | float val = getPersistedFloat(1.0f); 49 | int idx = 0; // seconds 50 | if (val >= 3600) { 51 | idx = 2; // hours 52 | val /= 3600.0f; 53 | } else if (val >= 60) { 54 | idx = 1; // minutes 55 | val /= 60.0f; 56 | } 57 | 58 | mText = (EditText) view.findViewById(R.id.interval_string); 59 | mText.setText(String.valueOf(val)); 60 | 61 | mSpinner = (Spinner) view.findViewById(R.id.interval_spinner); 62 | ArrayAdapter adapter = ArrayAdapter.createFromResource( 63 | getContext(), R.array.interval_types, android.R.layout.simple_spinner_item); 64 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 65 | mSpinner.setAdapter(adapter); 66 | mSpinner.setSelection(idx); 67 | mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { 68 | 69 | public void onItemSelected(AdapterView parent, View view, int pos, long id) { 70 | intervalType = typeValues[pos]; 71 | } 72 | 73 | public void onNothingSelected(AdapterView parent) { 74 | } 75 | 76 | }); 77 | return view; 78 | } 79 | 80 | @Override 81 | protected void onDialogClosed(boolean positiveResult) { 82 | if (positiveResult) { 83 | try { 84 | float interval = Float.parseFloat(mText.getText().toString()); 85 | persistFloat(interval * intervalType); 86 | } catch (NumberFormatException e) { 87 | android.util.Log.e(TAG, "", e); 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/prefs/PrefUtils.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.prefs; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.preference.CheckBoxPreference; 6 | import android.preference.ListPreference; 7 | import android.preference.PreferenceActivity; 8 | import android.preference.Preference; 9 | 10 | import org.mosspaper.Common; 11 | import org.mosspaper.Env; 12 | 13 | public class PrefUtils { 14 | 15 | public static void updatePrefs(PreferenceActivity activity) { 16 | SharedPreferences prefs = activity.getPreferenceManager().getSharedPreferences(); 17 | for (String key : prefs.getAll().keySet()) { 18 | Preference p = activity.findPreference(key); 19 | 20 | if (p == null) { 21 | continue; 22 | } 23 | 24 | if (p instanceof CheckBoxPreference 25 | || p instanceof ListPreference) { 26 | continue; 27 | } 28 | CharSequence value = null; 29 | if ("font_size".equals(key) || "gap_x".equals(key) || "gap_y".equals(key)) { 30 | value = String.format("%.0f", prefs.getFloat(key, -1.0f)); 31 | } else if ("update_interval".equals(key)) { 32 | value = Common.formatSecondsShort((long) prefs.getFloat(key, -1.0f)); 33 | } else if ("background_color".equals(key) || "mod_color".equals(key)) { 34 | int c = prefs.getInt(key, -1); 35 | if (-1 != c) { 36 | value = String.format("#%x", c); 37 | } else { 38 | value = "No color"; 39 | } 40 | } else { 41 | value = prefs.getString(key, ""); 42 | } 43 | if (null != value) { 44 | p.setSummary(value); 45 | } 46 | } 47 | } 48 | 49 | public static void resetPrefs(Env env, SharedPreferences prefs) { 50 | SharedPreferences.Editor edit = prefs.edit(); 51 | for (String k : defaultable) { 52 | edit.remove(k); 53 | } 54 | edit.commit(); 55 | } 56 | 57 | public static void defaultPrefs(Env env, SharedPreferences prefs) { 58 | SharedPreferences.Editor edit = prefs.edit(); 59 | if (-1.0f == prefs.getFloat("update_interval", -1.0f)) { 60 | edit.putFloat("update_interval", env.getConfig().getUpdateInterval()); 61 | } 62 | if (-1.0f == prefs.getFloat("font_size", -1.0f)) { 63 | edit.putFloat("font_size", env.getConfig().getFontSize()); 64 | } 65 | if (-1.0f == prefs.getFloat("gap_x", -1.0f)) { 66 | edit.putFloat("gap_x", env.getGapX()); 67 | } 68 | if (-1.0f == prefs.getFloat("gap_y", -1.0f)) { 69 | edit.putFloat("gap_y", env.getGapY()); 70 | } 71 | if (-1 == prefs.getInt("background_color", -1)) { 72 | int c = env.getConfig().getBackgroundColor(); 73 | if (-1 != c) { 74 | c |= 0xFF000000; 75 | edit.putInt("background_color", c); 76 | } 77 | } 78 | if (-1 == prefs.getInt("mod_color", -1)) { 79 | int c = env.getConfig().getModColor(); 80 | if (-1 != c) { 81 | c |= 0xFF000000; 82 | edit.putInt("mod_color", c); 83 | } 84 | } 85 | edit.commit(); 86 | } 87 | 88 | 89 | public static boolean isDefaultable(String key) { 90 | for (String k : defaultable) { 91 | if (k.equals(key)) { 92 | return true; 93 | } 94 | } 95 | return false; 96 | } 97 | 98 | static String[] defaultable = new String[] { 99 | "background_image", 100 | "background_color", "mod_color", "font_size" 101 | }; 102 | } 103 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/prefs/SizePreference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ConnectBot: simple, powerful, open-source SSH client for Android 3 | * Copyright 2007 Kenny Root, Jeffrey Sharkey 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.mosspaper.prefs; 19 | 20 | import org.mosspaper.Config; 21 | 22 | import android.content.Context; 23 | import android.content.res.TypedArray; 24 | import android.preference.DialogPreference; 25 | import android.util.AttributeSet; 26 | import android.view.View; 27 | import android.view.ViewGroup; 28 | import android.widget.LinearLayout; 29 | import android.widget.SeekBar.OnSeekBarChangeListener; 30 | import android.widget.SeekBar; 31 | import android.widget.TextView; 32 | 33 | import org.mosspaper.R; 34 | 35 | /** 36 | * @author kenny 37 | * 38 | */ 39 | public class SizePreference extends DialogPreference implements OnSeekBarChangeListener { 40 | 41 | private TextView mText; 42 | private int mProgress; 43 | /** 44 | * @param context 45 | * @param attrs 46 | */ 47 | public SizePreference(Context context, AttributeSet attrs) { 48 | super(context, attrs); 49 | 50 | setupLayout(context, attrs); 51 | } 52 | 53 | public SizePreference(Context context, AttributeSet attrs, int defStyle) { 54 | super(context, attrs, defStyle); 55 | 56 | setupLayout(context, attrs); 57 | } 58 | 59 | private void setupLayout(Context context, AttributeSet attrs) { 60 | setPersistent(true); 61 | TypedArray a = context.obtainStyledAttributes(attrs, 62 | R.styleable.SizePreference); 63 | 64 | mMin = a.getInteger(R.styleable.SizePreference_min, mMin); 65 | mMax = a.getInteger(R.styleable.SizePreference_max, mMax); 66 | } 67 | 68 | @Override 69 | protected View onCreateDialogView() { 70 | LinearLayout layout = new LinearLayout(getContext()); 71 | layout.setOrientation(LinearLayout.VERTICAL); 72 | layout.setLayoutParams( 73 | new ViewGroup.LayoutParams( 74 | ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); 75 | 76 | mText = new TextView(getContext()); 77 | mText.setPadding(10, 10, 10, 10); 78 | mText.setTextAppearance(getContext(), android.R.attr.textAppearanceLarge); 79 | layout.addView(mText); 80 | 81 | mProgress = (int) (getPersistedFloat(Config.CONF_FONT_SIZE_VALUE)); 82 | SeekBar sb = new SeekBar(getContext()); 83 | sb.setMax(mMax - mMin); 84 | sb.setProgress(mProgress - mMin); 85 | sb.setPadding(10, 10, 10, 10); 86 | sb.setOnSeekBarChangeListener(this); 87 | layout.addView(sb); 88 | 89 | mText.setText(String.valueOf(mProgress)); 90 | 91 | return layout; 92 | } 93 | 94 | @Override 95 | protected void onDialogClosed(boolean positiveResult) { 96 | if (positiveResult) { 97 | persistFloat(mProgress); 98 | } 99 | } 100 | 101 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 102 | this.mProgress = adjustProgress(progress); 103 | if (mText != null) { 104 | mText.setText(String.valueOf(mProgress)); 105 | } 106 | } 107 | 108 | private int adjustProgress(int progress) { 109 | return progress + mMin; 110 | } 111 | 112 | public void onStartTrackingTouch(SeekBar seekBar) { } 113 | 114 | public void onStopTrackingTouch(SeekBar seekBar) { } 115 | 116 | private int mMin = 8; 117 | private int mMax = 100; 118 | } 119 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/util/Bar.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.util; 2 | 3 | import android.graphics.Paint; 4 | import android.graphics.Paint.Style; 5 | 6 | import org.mosspaper.Env; 7 | 8 | public class Bar { 9 | 10 | public Bar() { } 11 | 12 | public void drawBar(final Env env, final float perc) { 13 | drawBar(env, perc, env.getLineHeight(), env.getMaxX() - env.getX()); 14 | } 15 | 16 | public void drawBar(final Env env, final float perc, final float height, final float width) { 17 | final Paint p = env.getPaint(); 18 | final int origColor = p.getColor(); 19 | final Style origStyle = p.getStyle(); 20 | 21 | if (-1 != env.getConfig().getOutlineColor()) { 22 | int c = env.getConfig().getOutlineColor(); 23 | c |= 0xFF000000; 24 | p.setColor(c); 25 | } 26 | p.setStyle(Style.STROKE); 27 | 28 | float boxWidth = (width == -1.0f) ? env.getMaxX() : width; 29 | float barWidth = boxWidth * perc; 30 | 31 | float x = env.getX(); 32 | float top = env.getY() + PADDING; 33 | float y = top + height; 34 | env.setLineHeight(height); 35 | 36 | /* Draw Outline */ 37 | env.getCanvas().drawRect(x, top, x + boxWidth, y, p); 38 | 39 | if (-1 != env.getConfig().getShadeColor()) { 40 | int c = env.getConfig().getShadeColor(); 41 | c |= 0xFF000000; 42 | p.setColor(c); 43 | } 44 | 45 | p.setStyle(Style.FILL); 46 | 47 | /* Draw Bar */ 48 | env.getCanvas().drawRect(x, top, x + barWidth, y, env.getPaint()); 49 | 50 | p.setStyle(origStyle); 51 | p.setColor(origColor); 52 | env.setX(x + boxWidth); 53 | } 54 | 55 | static float PADDING = 2.0f; 56 | } 57 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/util/Graph.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.util; 2 | 3 | import android.graphics.Paint; 4 | import android.graphics.Paint.Style; 5 | 6 | import org.mosspaper.Env; 7 | import org.mosspaper.objects.Graphable; 8 | 9 | import java.util.List; 10 | 11 | public class Graph { 12 | 13 | public Graph() { 14 | this.colorLeft = 0x000000; 15 | this.colorRight = 0x5000a0; 16 | } 17 | 18 | public Graph setData(List data) { 19 | this.data = data; 20 | return this; 21 | } 22 | 23 | public Graph setHeight(float height) { 24 | this.height = height; 25 | return this; 26 | } 27 | 28 | public Graph setWidth(float width) { 29 | this.width = width; 30 | return this; 31 | } 32 | 33 | public Graph setScale(int scale) { 34 | this.scale = scale; 35 | return this; 36 | } 37 | 38 | public Graph setColorLeft(int colorLeft) { 39 | this.colorLeft = colorLeft; 40 | return this; 41 | } 42 | 43 | public Graph setColorRight(int colorRight) { 44 | this.colorRight = colorRight; 45 | return this; 46 | } 47 | 48 | public void draw(Env env) { 49 | final Paint p = env.getPaint(); 50 | final int origColor = p.getColor(); 51 | final Style origStyle = p.getStyle(); 52 | 53 | if (-1 != env.getConfig().getOutlineColor()) { 54 | int c = env.getConfig().getOutlineColor(); 55 | c |= 0xFF000000; 56 | p.setColor(c); 57 | } 58 | p.setStyle(Style.STROKE); 59 | 60 | float x = env.getX(); 61 | float y = env.getY(); 62 | 63 | if (width <= 0) { 64 | width = env.getMaxX() - x; 65 | } 66 | float maxX = x + (width > 0 ? width : env.getMaxX()); 67 | float maxY = y + height; 68 | env.setLineHeight(height); 69 | 70 | /* Draw Outline */ 71 | env.getCanvas().drawRect(x, y, maxX, maxY, p); 72 | 73 | p.setStyle(Style.FILL); 74 | 75 | /* Move inside border */ 76 | maxX -= 1.0f; 77 | maxY -= 1.0f; 78 | width -= 2.0f; 79 | 80 | /* Start from right */ 81 | if (null != data) { 82 | long max = 0L; 83 | int count = 0; 84 | if (scale > 0) { 85 | max = scale; 86 | } else { 87 | for (Graphable g : data) { 88 | if (count > width) { 89 | break; 90 | } 91 | max = Math.max(max, g.getValue()); 92 | count++; 93 | } 94 | } 95 | count = 0; 96 | int nextColor = colorRight; 97 | for (Graphable g : data) { 98 | float currx = maxX - count; 99 | float curry = maxY; 100 | if (max > 0f) { 101 | float frac = Math.min(1.0f, g.getValue() / (float) max); 102 | float diff = maxY - y; 103 | curry = maxY - (frac * diff); 104 | } 105 | if (curry < 0 || curry > maxY) { 106 | curry = maxY; 107 | } 108 | p.setColor(nextColor); 109 | p.setAlpha(0xff); 110 | env.getCanvas().drawLine(currx, curry, currx, maxY, p); 111 | nextColor = calcNextColor((int) width - count, colorLeft, nextColor); 112 | if (count > width) { 113 | break; 114 | } 115 | count++; 116 | } 117 | } 118 | 119 | p.setStyle(origStyle); 120 | p.setColor(origColor); 121 | env.setX(maxX); 122 | } 123 | 124 | int calcNextColor(int width, int cl, int cr) { 125 | if (cl == cr || width <= 0) { 126 | return cl; 127 | } 128 | 129 | /* mask off and shift each channel */ 130 | int redl = (cl & 0xff0000) >> 0x10; 131 | int greenl = (cl & 0xff00) >> 0x08; 132 | int bluel = cl & 0xff; 133 | 134 | int redr = (cr & 0xff0000) >> 0x10; 135 | int greenr = (cr & 0xff00) >> 0x08; 136 | int bluer = cr & 0xff; 137 | 138 | int red = redr - ((redr - redl) / width); 139 | int green = greenr - ((greenr - greenl) / width); 140 | int blue = bluer - ((bluer - bluel) / width); 141 | 142 | int v = (red << 16) + (green << 8) + blue; 143 | return v; 144 | } 145 | 146 | private List data; 147 | private float height; 148 | private float width; 149 | private int scale; 150 | private int colorLeft; 151 | private int colorRight; 152 | } 153 | -------------------------------------------------------------------------------- /moss/src/main/java/org/mosspaper/util/RRDList.java: -------------------------------------------------------------------------------- 1 | package org.mosspaper.util; 2 | 3 | import java.util.List; 4 | import java.util.LinkedList; 5 | 6 | public class RRDList extends LinkedList implements List { 7 | 8 | public RRDList(int maxCapacity) { 9 | this.mMaxCapacity = maxCapacity; 10 | } 11 | 12 | public void setMaxCapacity(int maxCapacity) { 13 | this.mMaxCapacity = maxCapacity; 14 | } 15 | 16 | @Override 17 | public boolean add(E o) { 18 | super.addFirst(o); 19 | /* Trim the fat */ 20 | for (int i = mMaxCapacity; i < this.size(); i++) { 21 | this.remove(i); 22 | } 23 | return true; 24 | } 25 | 26 | private int mMaxCapacity; 27 | } 28 | -------------------------------------------------------------------------------- /moss/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | LOCAL_SRC_FILES := native_functions.c 4 | LOCAL_SRC_FILES := portmon.c tcp-portmon/libtcp-portmon.c 5 | 6 | -------------------------------------------------------------------------------- /moss/src/main/jni/native_functions.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void 9 | Java_org_mosspaper_objects_FSJni_getFsInfo(JNIEnv* env, 10 | jobject obj, 11 | jstring jpath, 12 | jobject fs_obj) 13 | { 14 | jfieldID type_fid, bsize_fid, blocks_fid, bfree_fid, bavail_fid; 15 | 16 | const jbyte *path = (*env)->GetStringUTFChars(env, jpath, NULL); 17 | if (NULL == path) { 18 | return; 19 | } 20 | jclass fs_cls = (*env)->GetObjectClass(env, fs_obj); 21 | 22 | type_fid = (*env)->GetFieldID(env, fs_cls, "f_type", "J"); 23 | bsize_fid = (*env)->GetFieldID(env, fs_cls, "f_bsize", "J"); 24 | blocks_fid = (*env)->GetFieldID(env, fs_cls, "f_blocks", "J"); 25 | bfree_fid = (*env)->GetFieldID(env, fs_cls, "f_bfree", "J"); 26 | bavail_fid = (*env)->GetFieldID(env, fs_cls, "f_bavail", "J"); 27 | 28 | struct statfs f; 29 | if (statfs(path, &f) == 0) { 30 | if (NULL != type_fid) { 31 | (*env)->SetLongField(env, fs_obj, type_fid, f.f_type); 32 | } 33 | if (NULL != bsize_fid) { 34 | (*env)->SetLongField(env, fs_obj, bsize_fid, f.f_bsize); 35 | } 36 | if (NULL != blocks_fid) { 37 | (*env)->SetLongField(env, fs_obj, blocks_fid, f.f_blocks); 38 | } 39 | if (NULL != bfree_fid) { 40 | (*env)->SetLongField(env, fs_obj, bfree_fid, f.f_bfree); 41 | } 42 | if (NULL != bavail_fid) { 43 | (*env)->SetLongField(env, fs_obj, bavail_fid, f.f_bavail); 44 | } 45 | } 46 | (*env)->ReleaseStringUTFChars(env, jpath, path); 47 | } 48 | 49 | void 50 | Java_org_mosspaper_objects_UnameProvider_setUname(JNIEnv* env, 51 | jobject obj) 52 | { 53 | jstring jstr; 54 | jfieldID sysname, nodename, release, version, machine; 55 | 56 | jclass cls = (*env)->GetObjectClass(env, obj); 57 | sysname = (*env)->GetFieldID(env, cls, "sysname", "Ljava/lang/String;"); 58 | nodename = (*env)->GetFieldID(env, cls, "nodename", "Ljava/lang/String;"); 59 | release = (*env)->GetFieldID(env, cls, "release", "Ljava/lang/String;"); 60 | version = (*env)->GetFieldID(env, cls, "version", "Ljava/lang/String;"); 61 | machine = (*env)->GetFieldID(env, cls, "machine", "Ljava/lang/String;"); 62 | 63 | struct utsname u; 64 | if (uname(&u) == 0) { 65 | jstr = (*env)->NewStringUTF(env, u.sysname); 66 | if (NULL != sysname && NULL != jstr) { 67 | (*env)->SetObjectField(env, obj, sysname, jstr); 68 | } 69 | jstr = (*env)->NewStringUTF(env, u.nodename); 70 | if (NULL != nodename && NULL != jstr) { 71 | (*env)->SetObjectField(env, obj, nodename, jstr); 72 | } 73 | jstr = (*env)->NewStringUTF(env, u.release); 74 | if (NULL != release && NULL != jstr) { 75 | (*env)->SetObjectField(env, obj, release, jstr); 76 | } 77 | jstr = (*env)->NewStringUTF(env, u.version); 78 | if (NULL != version && NULL != jstr) { 79 | (*env)->SetObjectField(env, obj, version, jstr); 80 | } 81 | jstr = (*env)->NewStringUTF(env, u.machine); 82 | if (NULL != machine && NULL != jstr) { 83 | (*env)->SetObjectField(env, obj, machine, jstr); 84 | } 85 | } 86 | } 87 | 88 | jstring 89 | Java_org_mosspaper_objects_Time_strftime(JNIEnv* env, 90 | jobject obj, 91 | jstring jformat) 92 | { 93 | char buf[128]; 94 | const jbyte *format = (*env)->GetStringUTFChars(env, jformat, NULL); 95 | if (NULL == format) { 96 | return; 97 | } 98 | time_t t = time(NULL); 99 | struct tm *tm = localtime(&t); 100 | setlocale(LC_TIME, ""); 101 | strftime(buf, 128, format, tm); 102 | 103 | (*env)->ReleaseStringUTFChars(env, jformat, format); 104 | return (*env)->NewStringUTF(env, buf); 105 | } 106 | 107 | -------------------------------------------------------------------------------- /moss/src/main/jni/portmon.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "tcp-portmon/libtcp-portmon.h" 4 | 5 | #define PEEK_BUF 50 6 | 7 | tcp_port_monitor_collection_t *p_coll = NULL; 8 | 9 | void 10 | Java_org_mosspaper_objects_PortMonProvider_moninit(JNIEnv* env, 11 | jobject obj) { 12 | p_coll = create_tcp_port_monitor_collection(); 13 | } 14 | 15 | jboolean 16 | Java_org_mosspaper_objects_PortMonProvider_monadd(JNIEnv* env, 17 | jobject obj, 18 | jint startPort, 19 | jint endPort) { 20 | 21 | tcp_port_monitor_t *p_mon; 22 | tcp_port_monitor_args_t args; 23 | 24 | p_mon = find_tcp_port_monitor(p_coll, startPort, endPort); 25 | if (NULL == p_mon) { 26 | args.max_port_monitor_connections = 100; 27 | p_mon = create_tcp_port_monitor(startPort, endPort, &args); 28 | if (0 == insert_tcp_port_monitor_into_collection(p_coll, p_mon)) { 29 | return JNI_TRUE; 30 | } 31 | } 32 | return JNI_FALSE; 33 | } 34 | 35 | jint 36 | Java_org_mosspaper_objects_PortMonProvider_monitemlookup(JNIEnv *env, 37 | jobject obj, 38 | jstring jstr) { 39 | jint item = -1; 40 | const jbyte *itembuf = (*env)->GetStringUTFChars(env, jstr, NULL); 41 | 42 | if (strncmp(itembuf, "count", 31) == 0) { 43 | item = COUNT; 44 | } else if (strncmp(itembuf, "rip", 31) == 0) { 45 | item = REMOTEIP; 46 | } else if (strncmp(itembuf, "rhost", 31) == 0) { 47 | item = REMOTEHOST; 48 | } else if (strncmp(itembuf, "rport", 31) == 0) { 49 | item = REMOTEPORT; 50 | } else if (strncmp(itembuf, "rservice", 31) == 0) { 51 | item = REMOTESERVICE; 52 | } else if (strncmp(itembuf, "lip", 31) == 0) { 53 | item = LOCALIP; 54 | } else if (strncmp(itembuf, "lhost", 31) == 0) { 55 | item = LOCALHOST; 56 | } else if (strncmp(itembuf, "lport", 31) == 0) { 57 | item = LOCALPORT; 58 | } else if (strncmp(itembuf, "lservice", 31) == 0) { 59 | item = LOCALSERVICE; 60 | } 61 | (*env)->ReleaseStringUTFChars(env, jstr, itembuf); 62 | return item; 63 | } 64 | 65 | jstring 66 | Java_org_mosspaper_objects_PortMonProvider_monpeek(JNIEnv* env, 67 | jobject obj, 68 | jint startPort, 69 | jint endPort, 70 | jint item, 71 | jint index) { 72 | 73 | tcp_port_monitor_t *p_mon; 74 | /* limited to PEEK_BUF...lame. */ 75 | char buf[PEEK_BUF]; 76 | memset(buf, 0, PEEK_BUF); 77 | 78 | p_mon = find_tcp_port_monitor(p_coll, startPort, endPort); 79 | if (NULL != p_mon) { 80 | peek_tcp_port_monitor(p_mon, item, index, buf, PEEK_BUF); 81 | return (*env)->NewStringUTF(env, buf); 82 | } 83 | return (*env)->NewStringUTF(env, buf); 84 | } 85 | 86 | void 87 | Java_org_mosspaper_objects_PortMonProvider_monupdate(JNIEnv* env, 88 | jobject obj) { 89 | if (NULL != p_coll) { 90 | update_tcp_port_monitor_collection(p_coll); 91 | } 92 | } 93 | 94 | void 95 | Java_org_mosspaper_objects_PortMonProvider_mondestroy(JNIEnv* env, 96 | jobject obj) { 97 | if (NULL != p_coll) { 98 | destroy_tcp_port_monitor_collection(p_coll); 99 | } 100 | p_coll = NULL; 101 | } 102 | -------------------------------------------------------------------------------- /moss/src/main/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teneighty/moss/9a9eb84c97eea905be30aaff152b31e964ffa135/moss/src/main/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /moss/src/main/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teneighty/moss/9a9eb84c97eea905be30aaff152b31e964ffa135/moss/src/main/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /moss/src/main/res/drawable/ex_icon.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /moss/src/main/res/drawable/white_box.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /moss/src/main/res/layout/act_help.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /moss/src/main/res/layout/act_packages.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /moss/src/main/res/layout/dia_errors.xml: -------------------------------------------------------------------------------- 1 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /moss/src/main/res/layout/dia_interval.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | 15 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /moss/src/main/res/layout/item_config.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 22 | 23 | 30 | 31 | 32 | 37 | 38 | 44 | 45 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /moss/src/main/res/layout/item_device.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 19 | 20 | 28 | 29 | 38 | 39 | 40 | 41 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /moss/src/main/res/layout/pref_color_block.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /moss/src/main/res/menu/settings_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /moss/src/main/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Default 6 | Network Emphasis 7 | Process Emphasis 8 | Large Configuration 9 | Custom 10 | 11 | 12 | 13 | default.conf 14 | network.conf 15 | process.conf 16 | full.conf 17 | CUSTOM 18 | 19 | 20 | 21 | 6.0 22 | 8.0 23 | 10.0 24 | 12.0 25 | 14.0 26 | 27 | 28 | 29 | Seconds 30 | Minutes 31 | Hours 32 | 33 | 34 | 35 | 1 36 | 60 37 | 3600 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /moss/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /moss/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Moss 8 | Moss Data Service 9 | Settings 10 | System monitor wallpaper, in the likeness of Conky. 11 | 12 | 13 | Custom 14 | Custom File 15 | 16 | Update Interval 17 | 18 | Background 19 | Image 20 | Color 21 | Mod Color 22 | 23 | Font 24 | Font Size 25 | Font Family 26 | 27 | Gap 28 | X 29 | Y 30 | 31 | Select a color: 32 | Configuration Errors 33 | 34 | Moss Viewer 35 | Configurations 36 | Select from a list of configurations. 37 | Custom Config File 38 | 39 | Reloading 40 | Reload 41 | Force Moss to reload your configuration. 42 | Overrides 43 | Override different configuration settings. 44 | Reset 45 | Reset all preferences and reload the default values from the configuration file. 46 | Help 47 | Display the Moss help pages. 48 | 49 | 50 | Miscellaneous 51 | Empty List 52 | 53 | Basic Configuration 54 | A small and simple configuration. 55 | 56 | Network Emphasis 57 | Focuses on network usage and devices. 58 | 59 | Process Emphasis 60 | Focuses on displaying process information. 61 | 62 | Large Configuration 63 | Includes many different objects. 64 | 65 | Ebuprof 66 | Ebuprof take from http://hundone.deviantart.com/art/My-Conky-Config-1-3-60095106. 67 | 68 | Remove 69 | 70 | Beginning download 71 | Loading... 72 | Processing %1$s 73 | Switching to %1$s 74 | Error during lookup 75 | Path to configuration file. 76 | %1$s does not exist. 77 | 78 | Removing %1$s from database 79 | Removing %1$s from filesystem 80 | 81 | Available Configurations 82 | Current Configuration 83 | 84 | Download Results 85 | Okay 86 | Your download finished. 87 | An error occured. 88 | local 89 | 90 | 91 | Moss data gathering service 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /moss/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFFFF 4 | 5 | -------------------------------------------------------------------------------- /moss/src/main/res/xml/mosspaper.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /moss/src/main/res/xml/prefs_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 21 | 22 | 28 | 29 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /moss/src/main/res/xml/prefs_overrides.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 16 | 17 | 22 | 23 | 28 | 29 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 51 | 52 | 59 | 60 | 61 | 62 | 63 | 64 | 69 | 70 | 71 | 72 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':moss', ':libs:color-picker' 2 | --------------------------------------------------------------------------------