Skip to content

Commit

Permalink
修改 heads-up 上的图标为圆形,
Browse files Browse the repository at this point in the history
修改 heads-up 上的图标为圆形,在5.0上使用自身的 notification
  • Loading branch information
zzz40500 committed Feb 4, 2015
1 parent 38e4168 commit c99181d
Show file tree
Hide file tree
Showing 11 changed files with 385 additions and 73 deletions.
16 changes: 0 additions & 16 deletions .idea/misc.xml

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

42 changes: 0 additions & 42 deletions app/src/main/java/com/mingle/headsupdemo/Distance.java

This file was deleted.

18 changes: 16 additions & 2 deletions app/src/main/java/com/mingle/headsupdemo/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.mingle.headsupdemo;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RemoteViews;
import android.widget.ScrollView;

import com.mingle.headsUp.HeadsUp;
Expand All @@ -21,12 +27,16 @@ public class MainActivity extends ActionBarActivity {
private int code=1;


private Context context;



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

findViewById(R.id.l0).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -41,7 +51,7 @@ public void onClick(View v) {
.setSmallIcon(R.drawable.icon)
//2.3 一定要设置这个参数,负责会报错
.setContentIntent(pendingIntent)

.setFullScreenIntent(pendingIntent,false)
.setContentText("你有新的消息");

HeadsUp headsUp = builder.buildHeadUp();
Expand All @@ -63,8 +73,9 @@ public void onClick(View v) {
//要显示通知栏通知,这个一定要设置
.setSmallIcon(R.drawable.icon)
.setContentText("你有新的消息")
//2.3 一定要设置这个参数,负责会报错
//2.3 一定要设置这个参数,负责会报错
.setContentIntent(pendingIntent)
.setFullScreenIntent(pendingIntent, false)
//设置是否显示 action 按键
.setUsesChronometer(true)
.addAction(R.drawable.ic_cloud_queue_black_24dp, "查看", pendingIntent);
Expand Down Expand Up @@ -117,6 +128,9 @@ public void onClick(View v) {
HeadsUpManager.getInstant(MainActivity.this).cancelAll();





}
});

Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ dependencies {
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.joooonho:selectableroundedimageview:1.0.0'
}
1 change: 1 addition & 0 deletions library/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="selectableroundedimageview-1.0.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-21.0.3" level="project" />
Expand Down
5 changes: 3 additions & 2 deletions library/src/main/java/com/mingle/headsUp/FloatView.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public boolean onTouchEvent(MotionEvent event) {
}else{
toX= (int) (preLeft-Math.abs(dis));
}
Log.e("toX"," "+toX);
if (toX <= -validWidth) {
float preAlpha=1-Math.abs(preLeft)/validWidth;
preAlpha=preAlpha>=0?preAlpha:0;
Expand Down Expand Up @@ -260,7 +259,9 @@ public void setNotification(final HeadsUp headsUp) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
HeadsUpManager.getInstant(getContext()).silencerNotify(headsUp);
if(headsUp.isActivateStatusBar()) {
HeadsUpManager.getInstant(getContext()).silencerNotify(headsUp);
}
HeadsUpManager.getInstant(getContext()).animDismiss(headsUp);
}
};
Expand Down
26 changes: 21 additions & 5 deletions library/src/main/java/com/mingle/headsUp/HeadsUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class HeadsUp {
/**
* 出现时间 单位是 second
*/
private long duration= 8;
private long duration= 9;
/**
*
*/
Expand All @@ -33,6 +33,10 @@ public class HeadsUp {

private boolean isSticky=false;


private boolean activateStatusBar=true;


/**
*
*/
Expand All @@ -59,7 +63,6 @@ private HeadsUp(Context context) {

public static class Builder extends NotificationCompat.Builder {

private Context context;
private List<NotificationCompat.Action> actions=new ArrayList<NotificationCompat.Action>();
private HeadsUp headsUp;

Expand Down Expand Up @@ -97,6 +100,10 @@ public Builder setSmallIcon(int icon) {
// super.setSmallIcon(icon);
return this;
}
protected Builder setIcon(int icon){
super.setSmallIcon(icon);
return this;
}



Expand Down Expand Up @@ -126,7 +133,7 @@ public HeadsUp buildHeadUp(){
return headsUp;
}

private Notification silencerNotifcation(){
private Notification silencerNotification(){
super.setSmallIcon(headsUp.getIcon());
setDefaults(0);
return this.build();
Expand Down Expand Up @@ -462,12 +469,12 @@ protected void setExpand(boolean isExpand) {
}

protected Notification getSilencerNotification() {
return getBuilder().silencerNotifcation();
return getBuilder().silencerNotification();
}



private Builder getBuilder() {
protected Builder getBuilder() {
return builder;
}

Expand All @@ -483,4 +490,13 @@ public boolean isSticky() {
public void setSticky(boolean isSticky) {
this.isSticky = isSticky;
}


protected boolean isActivateStatusBar() {
return activateStatusBar;
}

public void setActivateStatusBar(boolean activateStatusBar) {
this.activateStatusBar = activateStatusBar;
}
}
17 changes: 13 additions & 4 deletions library/src/main/java/com/mingle/headsUp/HeadsUpManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import android.view.Gravity;
import android.view.WindowManager;

Expand Down Expand Up @@ -86,8 +87,17 @@ private synchronized void poll() {
if (!msgQueue.isEmpty()) {
HeadsUp headsUp = msgQueue.poll();
map.remove(headsUp.getCode());
isPolling = true;
show(headsUp);


if ( Build.VERSION.SDK_INT < 21 || headsUp.getCustomView() != null || !headsUp.isActivateStatusBar()){
isPolling = true;
show(headsUp);
}else {
//当 系统是 lollipop 以上,并且没有自定义布局以后,调用系统自己的 notification
isPolling = false;
notificationManager.notify(headsUp.getCode(),headsUp.getBuilder().setIcon(headsUp.getIcon()).build());

}
} else {
isPolling = false;
}
Expand All @@ -97,7 +107,6 @@ private synchronized void poll() {
private void show(HeadsUp headsUp) {

floatView = new FloatView(context, 20);

WindowManager.LayoutParams params = FloatView.winParams;
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_FULLSCREEN
Expand All @@ -115,7 +124,7 @@ private void show(HeadsUp headsUp) {
a.setDuration(600);
a.start();
floatView.setNotification(headsUp);
if(headsUp.getNotification()!=null){
if(headsUp.getNotification()!=null ){
notificationManager.notify(headsUp.getCode(), headsUp.getNotification());
}

Expand Down
Loading

0 comments on commit c99181d

Please sign in to comment.