Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfeng committed Sep 5, 2017
0 parents commit 8c6b4c5
Show file tree
Hide file tree
Showing 40 changed files with 1,429 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .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
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
30 changes: 30 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.cfryan.notificationsample"
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'
}
}
}

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:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
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/chenfeng-weidian/android-studio-sdk-macosx/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 *;
#}

# 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 com.cfryan.notificationsample;

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("com.cfryan.notificationsample", appContext.getPackageName());
}
}
33 changes: 33 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cfryan.notificationsample">

<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:parentActivityName=".Main2Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main2Activity"
android:excludeFromRecents="true"/>
<activity android:name=".Main3Activity"
android:excludeFromRecents="true"/>

<receiver android:name=".MainActivity$AlarmReceiver">
<intent-filter>
<action android:name="com.android.alarm"/>
</intent-filter>
</receiver>
</application>

</manifest>
143 changes: 143 additions & 0 deletions app/src/main/java/com/cfryan/notificationsample/BaseConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package com.cfryan.notificationsample;

import android.app.Notification;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.app.NotificationCompat;

/**
* 通知系统默认样式下的配置
*
* @author chenfeng
* @since 2017-09-01 14:16
*/

public abstract class BaseConfig {
/**
* 默认小图标
*
* @return
*/
public abstract int getSmallIcon();

public abstract Bitmap getLargeIcon(Context context);

public int getPriority() {
return NotificationCompat.PRIORITY_DEFAULT;
}

/**
* 最大进度条数值
* @return
*/
public int getProgressMax() {
return 100;
}

/**
* 时间显示在N以下默认显示,N开始需要设置setShowWhen
*
* @return
*/
public boolean getShowWhen() {
return true;
}

/**
* 默认显示当前时间
*
* @return
*/
public long getWhen() {
return System.currentTimeMillis();
}

/**
* VISIBILITY_PUBLIC 显示通知的完整内容。
* VISIBILITY_SECRET 不会在锁定屏幕上显示此通知的任何部分。
* VISIBILITY_PRIVATE 显示通知图标和内容标题等基本信息,但是隐藏通知的完整内容。
*
* @return
*/
public @NotificationCompat.NotificationVisibility int getNotificationVisibility() {
return NotificationCompat.VISIBILITY_PUBLIC;
}

/**
* 设置 VISIBILITY_PRIVATE 后,还可以通过 setPublicVersion() 提供其中隐藏了某些详细信息的替换版本通知内容。
*
* @return
*/
public Notification getPublicVersion() {
return null;
}

/**
* <p>Must be one of the predefined notification categories (see the <code>CATEGORY_*</code>
* constants in {@link Notification}) that best describes this notification.
* May be used by the system for ranking and filtering.
*
* @return
*/
public String getNotificationCategory() {
return null;
}

/**
* 点击自动显示,必须设置了contentIntent才有效果
* @return
*/
public boolean getAutoCancel() {
return true;
}

/**
* Set whether this is an ongoing notification.
*
* <p>Ongoing notifications differ from regular notifications in the following ways:
* <ul>
* <li>Ongoing notifications are sorted above the regular notifications in the
* notification panel.</li>
* <li>Ongoing notifications do not have an 'X' close button, and are not affected
* by the "Clear all" button.
* </ul>
* @return
*/
public abstract boolean getOngoing();

/**
*
* @return
*/
public boolean getOnlyAlertOnce() {
return true;
}

/**
* Show the {@link Notification#when} field as a stopwatch(count up).
*
* Instead of presenting <code>when</code> as a timestamp, the notification will show an
* automatically updating display of the minutes and seconds since <code>when</code>.
*
* Useful when showing an elapsed time (like an ongoing phone call).
* @return
*/
public boolean getUsesChronometer() {
return false;
}

public NotificationCompat.Builder getBaseBuilder(Context context) {
return new NotificationCompat.Builder(context)
.setSmallIcon(getSmallIcon())
.setLargeIcon(getLargeIcon(context))
.setShowWhen(getShowWhen())
.setWhen(getWhen())
.setPriority(getPriority())
.setVisibility(getNotificationVisibility())
.setPublicVersion(getPublicVersion())
.setAutoCancel(getAutoCancel())
.setOngoing(getOngoing())
.setOnlyAlertOnce(getOnlyAlertOnce());
}

}
36 changes: 36 additions & 0 deletions app/src/main/java/com/cfryan/notificationsample/DefaultConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.cfryan.notificationsample;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat;

/**
* 文件描述
*
* @author chenfeng
* @since 2017-09-01 17:35
*/

public class DefaultConfig extends BaseConfig {

@Override
public int getSmallIcon() {
return R.mipmap.ic_launcher;
}

@Override
public Bitmap getLargeIcon(Context context) {
return BitmapFactory.decodeResource(context.getResources(),R.mipmap.ic_launcher);
}

@Override
public boolean getOngoing() {
return false;
}

@Override
public int getPriority() {
return NotificationCompat.PRIORITY_HIGH;
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/cfryan/notificationsample/Main2Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cfryan.notificationsample;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Main2Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/com/cfryan/notificationsample/Main3Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cfryan.notificationsample;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.cfryan.notificationsample.R;

public class Main3Activity extends AppCompatActivity {

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

0 comments on commit 8c6b4c5

Please sign in to comment.