Skip to content

Commit

Permalink
[master] change: Add test app
Browse files Browse the repository at this point in the history
Change-Id: Ib671acaf012c2999f0d24b7b92119b09da4c4974
  • Loading branch information
yongce committed Nov 10, 2014
1 parent 7e634c6 commit fcace5a
Show file tree
Hide file tree
Showing 28 changed files with 632 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ proguard/

# Log Files
*.log

# Android Studio files
.idea/
*.iml

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

android {
compileSdkVersion 21
buildToolsVersion "21.1.1"

defaultConfig {
applicationId "me.ycdev.android.demo.servicestickytest"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
}
17 changes: 17 additions & 0 deletions 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 /home/pub/tools/android-sdk-linux/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 *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.ycdev.android.demo.servicestickytest;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
24 changes: 24 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.ycdev.android.demo.servicestickytest" >

<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="me.ycdev.android.demo.servicestickytest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".TestService" />
<service android:name=".AssistantService" android:exported="true" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package me.ycdev.android.demo.servicestickytest;

import android.app.Service;
import android.content.Intent;
import android.os.*;
import android.os.Process;

import me.ycdev.android.demo.servicestickytest.utils.AppLogger;

public class AssistantService extends Service {
private static final String TAG = "AssistantService";

private static final String ACTION_RUN_TEST = "me.ycdev.android.demo.servicestickytest.ACTION_RUN_TEST";

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
AppLogger.i(TAG, "onStartCommand: " + intent);
String action = null;
if (intent != null) {
action = intent.getAction();
}
if (ACTION_RUN_TEST.equals(action)) {
new Thread() {
@Override
public void run() {
SystemClock.sleep(15 * 1000); // 15 seconds
stopSelf();
Process.killProcess(Process.myPid());
}
}.start();
}
return super.onStartCommand(intent, flags, startId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package me.ycdev.android.demo.servicestickytest;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}


@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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.ycdev.android.demo.servicestickytest;

import android.app.Application;
import android.os.SystemClock;

import me.ycdev.android.demo.servicestickytest.utils.AppLogger;

public class MyApplication extends Application {
private static final String TAG = "MyApplication";

@Override
public void onCreate() {
super.onCreate();
AppLogger.i(TAG, "#onCreate");

new Thread() {
@Override
public void run() {
SystemClock.sleep(1000); // 1 seconds
TestService.onAppStart(getApplicationContext());
}
}.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package me.ycdev.android.demo.servicestickytest;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;

import me.ycdev.android.demo.servicestickytest.utils.AppLogger;

public class TestService extends IntentService {
private static final String TAG = "TestService";

private static final String ACTION_APP_START = "me.ycdev.android.demo.servicestickytest.ACTION_APP_START";

public TestService() {
super("TestService");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
AppLogger.i(TAG, "#onStartCommand: " + intent + ", startId: " + startId);
int result = super.onStartCommand(intent, flags, startId);
AppLogger.i(TAG, "#onStartcommand, startId: " + startId + ", result: " + result);
return result;
}

@Override
protected void onHandleIntent(Intent intent) {
String action = intent.getAction();
if (ACTION_APP_START.equals(action)) {
AppLogger.d(TAG, "onAppStart, begin...");
SystemClock.sleep(30 * 1000); // 30 seconds
AppLogger.d(TAG, "onAppStart, end.");
}
}

public static void onAppStart(Context cxt) {
Intent intent = new Intent(cxt, TestService.class);
intent.setAction(ACTION_APP_START);
cxt.startService(intent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package me.ycdev.android.demo.servicestickytest.utils;

import android.util.Log;

import java.io.PrintWriter;
import java.io.StringWriter;

public class AppLogger {
public static final String TAG = "ServiceStickyTest";

public static void d(String subTag, String msg) {
Log.d(TAG, getLogMsg(subTag, msg));
}

public static void i(String subTag, String msg) {
Log.i(TAG, getLogMsg(subTag, msg));
}

public static void w(String subTag, String msg) {
Log.w(TAG, getLogMsg(subTag, msg));
}

public static void w(String subTag, String msg, Throwable e) {
Log.w(TAG, getLogMsg(subTag, msg + " Exception: " + getExceptionMsg(e)));
}

public static void e(String subTag, String msg) {
Log.e(TAG, getLogMsg(subTag, msg));
}

public static void e(String subTag, String msg, Throwable e) {
Log.e(TAG, getLogMsg(subTag, msg + " Exception: " + getExceptionMsg(e)));
}

private static String getLogMsg(String subTag, String msg) {
return "[" + subTag + "] " + msg;
}

private static String getExceptionMsg(Throwable e) {
StringWriter sw = new StringWriter(1024);
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.close();
return sw.toString();
}
}
Binary file added app/src/main/res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</RelativeLayout>
10 changes: 10 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
6 changes: 6 additions & 0 deletions app/src/main/res/values-w820dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">ServiceStickyTest</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>

</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>

</resources>
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
}
}
18 changes: 18 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
Loading

0 comments on commit fcace5a

Please sign in to comment.