Skip to content

Commit

Permalink
shields
Browse files Browse the repository at this point in the history
  • Loading branch information
chaogefeng committed Jun 21, 2019
0 parents commit 9400401
Show file tree
Hide file tree
Showing 168 changed files with 2,410 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
language: android
jdk: oraclejdk8
sudo: false

env:
global:
- ANDROID_API_LEVEL=25
- ANDROID_BUILD_TOOLS_VERSION=25.0.2
- ANDROID_ABI=armeabi-v7a
- ANDROID_TAG=google_apis
- ADB_INSTALL_TIMEOUT=20 # minutes (2 minutes by default)

android:
components:
- platform-tools
- tools # to install Android SDK tools 25.1.x
- build-tools-$ANDROID_BUILD_TOOLS_VERSION
- android-$ANDROID_API_LEVEL
- sys-img-armeabi-v7a-google_apis-$ANDROID_API_LEVEL

licenses:
- android-sdk-license-.+
- '.+'

before_install:
- chmod +x gradlew
- mkdir "$ANDROID_HOME/licenses" || true
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
- echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"

before_script:
# Create and start emulator
- echo no | android create avd --force -n test -t "android-"$ANDROID_API_LEVEL --abi $ANDROID_ABI --tag $ANDROID_TAG
- emulator -avd test -no-skin -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &

script:
- ./gradlew assembleRelease
- ./gradlew :app:createDebugAndroidTestCoverageReport --info --stacktrace

after_success:
- bash <(curl -s https://codecov.io/bash)
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BSD 2-Clause License

Copyright (c) 2017, 孤独狂饮
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
621 changes: 621 additions & 0 deletions README.md

Large diffs are not rendered by default.

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

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "gdky005.androidbadge"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug{
testCoverageEnabled true
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile 'com.android.support:design:25.1.0'
compile 'com.github.gdky005:AndroidBadge:v1.0.1'

//Jacoco 生成报告的依赖
androidTestCompile('com.android.support.test:runner:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// Set this dependency to use JUnit 4 rules
androidTestCompile('com.android.support.test:rules:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.android.support', module: 'recyclerview-v7'
})
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/WangQing/Android_SDK/android-sdk-macosx/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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gdky005.androidbadge;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("gdky005.androidbadge", appContext.getPackageName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package gdky005.androidbadge;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertTrue;

/**
* Created by WangQing on 2017/4/25.
*/
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
private static final String TAG = "MainActivityTest";

@Test
public void onCreate() throws Exception {
assertTrue(true);
}

@Test
public void testActivities(){
Context targetContext = InstrumentationRegistry.getTargetContext();
PackageManager pm = targetContext.getPackageManager();
PackageInfo info = null;
try{
info = pm.getPackageInfo(targetContext.getPackageName(), PackageManager.GET_ACTIVITIES);
} catch(PackageManager.NameNotFoundException e) {
Log.e(TAG, "testActivities: ", e);
}

ActivityInfo[] activities = info.activities;

for(int i =0, length = activities.length; i < length; i++) {
ActivityInfo aInfo = activities[i];
Log.i(TAG, "["+ i +"] Try launch activity:"+ aInfo.name);
try{
tryStartActivity(targetContext, aInfo.name);
} catch(Exception e) {
Log.w(TAG, "Error in "+ aInfo.name +" : "+ e.getMessage());
}
}
}

private void tryStartActivity(Context targetContext, String name) {
try {
Intent intent = new Intent(targetContext, Class.forName(name));
targetContext.startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
24 changes: 24 additions & 0 deletions app/src/androidTest/java/gdky005/androidbadge/MyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gdky005.androidbadge;

import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Created by WangQing on 2017/4/25.
*/
@RunWith(AndroidJUnit4.class)
public class MyTest {
private static final String TAG = "MyTest";

@Test
public void testLog() {
L.i("testLog");
}

@Test
public void test() {
L.getInstance();
}
}
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="gdky005.androidbadge">

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

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

</manifest>
37 changes: 37 additions & 0 deletions app/src/main/java/gdky005/androidbadge/L.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gdky005.androidbadge;

import android.util.Log;

/**
* Created by WangQing on 2017/4/25.
*/

public class L {
private static final String TAG = "L";

private static L instance = null;

private L() {
}

public static L getInstance() {
return new L(); //这里为了玩玩 百分百的 代码覆盖率,随便写的。

//正确写法
// if (instance == null) {
// synchronized (L.class) {
// L temp = instance;
// if (temp == null) {
// temp = new L();
// instance = temp;
// }
// }
// }
// return instance;
}


public static void i(String msg) {
Log.i(TAG, "i: " + msg);
}
}
58 changes: 58 additions & 0 deletions app/src/main/java/gdky005/androidbadge/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package gdky005.androidbadge;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import gdky005.badge.Utils;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});

Toast.makeText(this, "badge 的版本是:" + Utils.getVersion(),
Toast.LENGTH_SHORT).show();
}

@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);
}
}
Loading

0 comments on commit 9400401

Please sign in to comment.