From eeb81ca24556dff53c8a8765aa9d4457a90763ce Mon Sep 17 00:00:00 2001 From: punchdrunker Date: Sat, 31 Oct 2015 18:35:30 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=82=B5=E3=83=BC=E3=83=93=E3=82=B9?= =?UTF-8?q?=E3=81=A7=E3=82=BF=E3=82=B9=E3=82=AF=E3=82=92=E5=B8=B8=E9=A7=90?= =?UTF-8?q?=E3=81=95=E3=81=9B=E3=81=A6=E3=81=BF=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.name | 1 + .idea/compiler.xml | 22 +++ .idea/copyright/profiles_settings.xml | 3 + .idea/gradle.xml | 18 ++ .idea/misc.xml | 46 +++++ .idea/modules.xml | 9 + .idea/runConfigurations.xml | 12 ++ .idea/vcs.xml | 6 + app/.gitignore | 1 + app/build.gradle | 26 +++ app/proguard-rules.pro | 17 ++ .../batterystatus/ApplicationTest.java | 13 ++ app/src/main/AndroidManifest.xml | 23 +++ .../batterystatus/BatteryWatchService.java | 56 ++++++ .../example/batterystatus/MainActivity.java | 56 ++++++ app/src/main/res/layout/activity_main.xml | 20 +++ app/src/main/res/menu/menu_main.xml | 6 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes app/src/main/res/values-w820dp/dimens.xml | 6 + app/src/main/res/values/dimens.xml | 5 + app/src/main/res/values/strings.xml | 6 + app/src/main/res/values/styles.xml | 8 + .../batterystatus/ExampleUnitTest.java | 15 ++ build.gradle | 19 ++ gradle.properties | 18 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 49896 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 164 ++++++++++++++++++ gradlew.bat | 90 ++++++++++ settings.gradle | 1 + 33 files changed, 673 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/example/batterystatus/ApplicationTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/example/batterystatus/BatteryWatchService.java create mode 100644 app/src/main/java/com/example/batterystatus/MainActivity.java create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/menu/menu_main.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/values-w820dp/dimens.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/example/batterystatus/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..a2ebf14 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +BatteryStatus \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..9a8b7e5 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..1bbc21d --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6a1e020 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8cc58c5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..22210a8 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" + + defaultConfig { + applicationId "com.example.batterystatus" + minSdkVersion 17 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:22.2.1' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..59a59ac --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/nanao/Library/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 *; +#} diff --git a/app/src/androidTest/java/com/example/batterystatus/ApplicationTest.java b/app/src/androidTest/java/com/example/batterystatus/ApplicationTest.java new file mode 100644 index 0000000..32bb904 --- /dev/null +++ b/app/src/androidTest/java/com/example/batterystatus/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.example.batterystatus; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d95e168 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/example/batterystatus/BatteryWatchService.java b/app/src/main/java/com/example/batterystatus/BatteryWatchService.java new file mode 100644 index 0000000..63412a7 --- /dev/null +++ b/app/src/main/java/com/example/batterystatus/BatteryWatchService.java @@ -0,0 +1,56 @@ +package com.example.batterystatus; + +import android.app.Service; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.BatteryManager; +import android.os.IBinder; +import android.util.Log; + +import java.util.Timer; +import java.util.TimerTask; + +public class BatteryWatchService extends Service { + static String TAG = "TAG"; + private Timer timer; + + public BatteryWatchService() { + } + + @Override + public IBinder onBind(Intent intent) { + Log.d(TAG, "onBind"); + return null; + } + @Override public void onCreate() { + super.onCreate(); + Log.d(TAG, "onCreate"); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Log.d(TAG, "onStartCommand"); + timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + Log.i(TAG, "WORKING"); + + IntentFilter intentfilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + Intent batteryStatus = registerReceiver(null, intentfilter ); + + int batteryLevel = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); + Log.d("Battery", "Level: " + String.valueOf(batteryLevel)); + } + }, 0, 3000); + + return START_STICKY; + } + + @Override public void onDestroy() { + super.onDestroy(); + + Log.d(TAG, "onDestroy"); + timer.cancel(); + } +} diff --git a/app/src/main/java/com/example/batterystatus/MainActivity.java b/app/src/main/java/com/example/batterystatus/MainActivity.java new file mode 100644 index 0000000..189747c --- /dev/null +++ b/app/src/main/java/com/example/batterystatus/MainActivity.java @@ -0,0 +1,56 @@ +package com.example.batterystatus; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Button startButton = (Button) findViewById(R.id.start_button); + Button stopButton = (Button) findViewById(R.id.stop_button); + + startButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startService(new Intent(getApplicationContext(), BatteryWatchService.class)); + } + }); + stopButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + stopService(new Intent(getApplicationContext(), BatteryWatchService.class)); + } + }); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b0f553a --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,20 @@ + + +