Skip to content

Commit

Permalink
Standalone battery info app
Browse files Browse the repository at this point in the history
Just a standalone battery info app that gives the health and percentage
of the battery of the phone. Will work on merging this into the main
RoboApp
  • Loading branch information
ZRTaylor committed Oct 18, 2016
1 parent 6eed58d commit 9b2fbd6
Show file tree
Hide file tree
Showing 33 changed files with 729 additions and 0 deletions.
9 changes: 9 additions & 0 deletions BatteryInformation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
22 changes: 22 additions & 0 deletions BatteryInformation/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions BatteryInformation/.idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions BatteryInformation/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions BatteryInformation/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions BatteryInformation/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions BatteryInformation/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions BatteryInformation/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions BatteryInformation/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions BatteryInformation/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
29 changes: 29 additions & 0 deletions BatteryInformation/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.roboapp.batteryinformation"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions BatteryInformation/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\Zach\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
20 changes: 20 additions & 0 deletions BatteryInformation/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.roboapp.batteryinformation">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.roboapp.batteryinformation;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity {
private Context mContext;

private TextView mTextViewInfo;
private TextView mTextViewPercentage;
private ProgressBar mProgressBar;

private int mProgressStatus = 0;

/*
BroadcastReceiver
Base class for code that will receive intents sent by sendBroadcast().
You can either dynamically register an instance of this class with
Context.registerReceiver() or statically publish an implementation through
the <receiver> tag in your AndroidManifest.xml.
*/
// Initialize a new BroadcastReceiver instance
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
/*
BatteryManager
The BatteryManager class contains strings and constants used for values in the
ACTION_BATTERY_CHANGED Intent, and provides a method for querying battery
and charging properties.
*/
/*
public static final String EXTRA_SCALE
Extra for ACTION_BATTERY_CHANGED: integer containing the maximum battery level.
Constant Value: "scale"
*/
// Get the battery scale
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE,-1);
// Display the battery scale in TextView
mTextViewInfo.setText("Battery Scale : " + scale);

/*
public static final String EXTRA_LEVEL
Extra for ACTION_BATTERY_CHANGED: integer field containing the current battery
level, from 0 to EXTRA_SCALE.
Constant Value: "level"
*/
// get the battery level
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
// Display the battery level in TextView
mTextViewInfo.setText(mTextViewInfo.getText() + "\nBattery Level : " + level);

// Calculate the battery charged percentage
float percentage = level/ (float) scale;
// Update the progress bar to display current battery charged percentage
mProgressStatus = (int)((percentage)*100);

// Show the battery charged percentage text inside progress bar
mTextViewPercentage.setText("" + mProgressStatus + "%");

// Show the battery charged percentage in TextView
mTextViewInfo.setText(mTextViewInfo.getText() +
"\nPercentage : "+ mProgressStatus + "%");

// Display the battery charged percentage in progress bar
mProgressBar.setProgress(mProgressStatus);
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
// Request window feature action bar
requestWindowFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Get the application context
mContext = getApplicationContext();

/*
IntentFilter
Structured description of Intent values to be matched. An IntentFilter can match
against actions, categories, and data (either via its type, scheme, and/or path) in
an Intent. It also includes a "priority" value which is used to order multiple
matching filters.
IntentFilter objects are often created in XML as part of a package's
AndroidManifest.xml file, using intent-filter tags.
*/
/*
public IntentFilter (String action)
New IntentFilter that matches a single action with no data. If no data
characteristics are subsequently specified, then the filter will only match intents
that contain no data.
Parameters
action : The action to match, i.e. Intent.ACTION_MAIN.
*/
// Initialize a new IntentFilter instance
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);

/*
public abstract Intent registerReceiver (BroadcastReceiver receiver, IntentFilter filter)
Register a BroadcastReceiver to be run in the main activity thread. The receiver will
be called with any broadcast Intent that matches filter, in the main application thread.
The system may broadcast Intents that are "sticky" -- these stay around after the
broadcast as finished, to be sent to any later registrations. If your IntentFilter
matches one of these sticky Intents, that Intent will be returned by this function
and sent to your receiver as if it had just been broadcast.
Parameters
receiver : The BroadcastReceiver to handle the broadcast.
filter : Selects the Intent broadcasts to be received.
Returns
The first sticky intent found that matches filter, or null if there are none.
*/
// Register the broadcast receiver
mContext.registerReceiver(mBroadcastReceiver,iFilter);

// Get the widgets reference from XML layout
mTextViewInfo = (TextView) findViewById(R.id.tv_info);
mTextViewPercentage = (TextView) findViewById(R.id.tv_percentage);
mProgressBar = (ProgressBar) findViewById(R.id.pb);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape
android:shape="oval">
<stroke
android:width="5dp"
android:color="#d0d4d7"
/>
<solid android:color="#eef2f5"/>
</shape>
</item>
<item android:id="@android:id/progress">
<clip android:clipOrientation="vertical" android:gravity="bottom">
<shape
android:shape="oval">
<stroke
android:width="5dp"
android:color="#ff0001"
/>
<gradient
android:startColor="#7fc97c"
android:endColor="#99f396"
android:centerColor="#89e386"
android:angle="270"
android:gradientRadius="50"
android:centerY=".50"
/>
</shape>
</clip>
</item>
</layer-list>
Loading

0 comments on commit 9b2fbd6

Please sign in to comment.