Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #66 from recruit-lifestyle/develop
Browse files Browse the repository at this point in the history
2.2.3
  • Loading branch information
YoshihideSogawa authored Oct 26, 2017
2 parents b1e4505 + 646c79e commit 1a715f6
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 35 deletions.
File renamed without changes.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To API Level 14 or later are supported
[SimpleFloating](http://youtu.be/nb8M2p0agF4)

## Requirements
Target Sdk Version : 25
Target Sdk Version : 26
Min Sdk Version : 14

## How to use
Expand All @@ -25,7 +25,7 @@ Min Sdk Version : 14
}

dependencies {
compile 'com.github.recruit-lifestyle:FloatingView:2.2.2'
compile 'com.github.recruit-lifestyle:FloatingView:2.2.3'
}
```

Expand Down Expand Up @@ -69,6 +69,7 @@ Describe the process (`onFinishFloatingView`) that is called when you exit the F
```

6) Define the Service to AndroidManifest

example)
```java
<application ...>
Expand All @@ -81,10 +82,26 @@ example)
</application>
```

7) Describe the process to start the Service (example of Fragment)
7) Describe the process to start the Service (run on foreground)
```java
final Activity activity = getActivity();
activity.startService(new Intent(activity, ChatHeadService.class));
final Intent intent = new Intent(activity, ChatHeadService.class);
ContextCompat.startForegroundService(activity, intent);
```

8) Create notification channel (targetSdkVersion >= 26)

example)
```java
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final String channelId = getString(R.string.default_floatingview_channel_id);
final String channelName = getString(R.string.default_floatingview_channel_name);
final NotificationChannel defaultChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN);
final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (manager != null) {
manager.createNotificationChannel(defaultChannel);
}
}

```

## Static Options
Expand Down
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -16,12 +17,13 @@ allprojects {
repositories {
maven { url "https://jitpack.io" }
jcenter()
google()
}
}

ext {
compileSdkVersion = 25
buildToolsVersion = '25.0.2'
targetSdkVersion = 25
compileSdkVersion = 26
buildToolsVersion = '26.0.2'
targetSdkVersion = 26
minSdkVersion = 14
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Jun 26 10:48:16 JST 2017
#Wed Sep 13 12:18:11 JST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
}

dependencies {
compile 'com.android.support:support-annotations:25.3.1'
compile 'com.android.support:support-compat:25.3.1'
compile 'com.android.support:support-annotations:26.1.0'
compile 'com.android.support:support-compat:26.1.0'
}

// build a jar with source files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class FloatingView extends FrameLayout implements ViewTreeObserver.OnPreDrawList
*/
static final int DEFAULT_HEIGHT = ViewGroup.LayoutParams.WRAP_CONTENT;

/**
* Overlay Type
*/
private static final int OVERLAY_TYPE;

/**
* WindowManager
*/
Expand Down Expand Up @@ -297,6 +302,14 @@ class FloatingView extends FrameLayout implements ViewTreeObserver.OnPreDrawList
*/
private int mRotation;

static {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) {
OVERLAY_TYPE = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
} else {
OVERLAY_TYPE = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
}
}

/**
* コンストラクタ
*
Expand All @@ -310,7 +323,7 @@ class FloatingView extends FrameLayout implements ViewTreeObserver.OnPreDrawList
mWindowManager.getDefaultDisplay().getMetrics(mMetrics);
mParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
mParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
mParams.type = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
mParams.type = OVERLAY_TYPE;
mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Expand Down Expand Up @@ -532,6 +545,11 @@ public boolean dispatchTouchEvent(@NonNull MotionEvent event) {
return true;
}

// Block while initial display animation is running
if (mIsInitialAnimationRunning) {
return true;
}

// 現在位置のキャッシュ
mScreenTouchX = event.getRawX();
mScreenTouchY = event.getRawY();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class FullscreenObserverView extends View implements ViewTreeObserver.OnGlobalLa
*/
static final int NO_LAST_VISIBILITY = -1;

/**
* Overlay Type
*/
private static final int OVERLAY_TYPE;

/**
* WindowManager.LayoutParams
*/
Expand All @@ -57,6 +62,13 @@ class FullscreenObserverView extends View implements ViewTreeObserver.OnGlobalLa
*/
private final Rect mWindowRect;

static {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) {
OVERLAY_TYPE = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
} else {
OVERLAY_TYPE = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
}
}

/**
* コンストラクタ
Expand All @@ -71,7 +83,7 @@ class FullscreenObserverView extends View implements ViewTreeObserver.OnGlobalLa
mParams = new WindowManager.LayoutParams();
mParams.width = 1;
mParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
mParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
mParams.type = OVERLAY_TYPE;
mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ class TrashView extends FrameLayout implements ViewTreeObserver.OnPreDrawListene
*/
private static final int LONG_PRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout();

/**
* Overlay Type
*/
private static final int OVERLAY_TYPE;

/**
* WindowManager
*/
Expand Down Expand Up @@ -180,6 +185,14 @@ class TrashView extends FrameLayout implements ViewTreeObserver.OnPreDrawListene
*/
private boolean mIsEnabled;

static {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) {
OVERLAY_TYPE = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
} else {
OVERLAY_TYPE = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
}
}

/**
* コンストラクタ
*
Expand All @@ -196,7 +209,7 @@ class TrashView extends FrameLayout implements ViewTreeObserver.OnPreDrawListene
mParams = new WindowManager.LayoutParams();
mParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
mParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
mParams.type = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
mParams.type = OVERLAY_TYPE;
mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Expand Down
3 changes: 1 addition & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v13:25.3.1'
compile 'com.android.support:preference-v14:25.3.1'
compile 'com.android.support:preference-v14:26.1.0'
compile project(':library')
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import android.app.Activity;
import android.app.FragmentTransaction;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import android.os.Bundle;

import jp.co.recruit.floatingview.R;
Expand All @@ -15,6 +18,17 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// create default notification channel
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final String channelId = getString(R.string.default_floatingview_channel_id);
final String channelName = getString(R.string.default_floatingview_channel_name);
final NotificationChannel defaultChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN);
final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (manager != null) {
manager.createNotificationChannel(defaultChannel);
}
}

if (savedInstanceState == null) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.container, FloatingViewControlFragment.newInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -111,13 +112,15 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
private void showChatHead(Context context, boolean isShowOverlayPermission) {
// API22以下かチェック
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
context.startService(new Intent(context, ChatHeadService.class));
final Intent intent = new Intent(context, ChatHeadService.class);
ContextCompat.startForegroundService(context, intent);
return;
}

// 他のアプリの上に表示できるかチェック
if (Settings.canDrawOverlays(context)) {
context.startService(new Intent(context, ChatHeadService.class));
final Intent intent = new Intent(context, ChatHeadService.class);
ContextCompat.startForegroundService(context, intent);
return;
}

Expand All @@ -138,13 +141,15 @@ private void showChatHead(Context context, boolean isShowOverlayPermission) {
private void showCustomFloatingView(Context context, boolean isShowOverlayPermission) {
// API22以下かチェック
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
context.startService(new Intent(context, CustomFloatingViewService.class));
final Intent intent = new Intent(context, CustomFloatingViewService.class);
ContextCompat.startForegroundService(context, intent);
return;
}

// 他のアプリの上に表示できるかチェック
if (Settings.canDrawOverlays(context)) {
context.startService(new Intent(context, CustomFloatingViewService.class));
final Intent intent = new Intent(context, CustomFloatingViewService.class);
ContextCompat.startForegroundService(context, intent);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void onClick(View v) {
mFloatingViewManager.addViewToWindow(iconView, options);

// 常駐起動
startForeground(NOTIFICATION_ID, createNotification());
startForeground(NOTIFICATION_ID, createNotification(this));

return START_REDELIVER_INTENT;
}
Expand Down Expand Up @@ -125,12 +125,12 @@ private void destroy() {
* 通知を表示します。
* クリック時のアクションはありません。
*/
private Notification createNotification() {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
private static Notification createNotification(Context context) {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, context.getString(R.string.default_floatingview_channel_id));
builder.setWhen(System.currentTimeMillis());
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle(getString(R.string.chathead_content_title));
builder.setContentText(getString(R.string.content_text));
builder.setContentTitle(context.getString(R.string.chathead_content_title));
builder.setContentText(context.getString(R.string.content_text));
builder.setOngoing(true);
builder.setPriority(NotificationCompat.PRIORITY_MIN);
builder.setCategory(NotificationCompat.CATEGORY_SERVICE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
Expand Down Expand Up @@ -87,7 +86,7 @@ public void onClick(View v) {
mFloatingViewManager.addViewToWindow(iconView, options);

// 常駐起動
startForeground(NOTIFICATION_ID, createNotification());
startForeground(NOTIFICATION_ID, createNotification(this));

return START_REDELIVER_INTENT;
}
Expand Down Expand Up @@ -145,19 +144,19 @@ private void destroy() {
/**
* 通知を表示します。
*/
private Notification createNotification() {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
private static Notification createNotification(Context context) {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, context.getString(R.string.default_floatingview_channel_id));
builder.setWhen(System.currentTimeMillis());
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle(getString(R.string.mail_content_title));
builder.setContentText(getString(R.string.content_text));
builder.setContentTitle(context.getString(R.string.mail_content_title));
builder.setContentText(context.getString(R.string.content_text));
builder.setOngoing(true);
builder.setPriority(NotificationCompat.PRIORITY_MIN);
builder.setCategory(NotificationCompat.CATEGORY_SERVICE);

// PendingIntent作成
final Intent notifyIntent = new Intent(this, DeleteActionActivity.class);
PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
final Intent notifyIntent = new Intent(context, DeleteActionActivity.class);
PendingIntent notifyPendingIntent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(notifyPendingIntent);

return builder.build();
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
<string name="touch_finished_position" formatted="false">Current position (%d,%d)</string>
<string name="deleted_soon">FloatingView will be deleted soon.</string>
<string name="finish_deleted">FloatingView has been deleted.</string>
<string name="default_floatingview_channel_id">default_floatingview_channel</string>
<string name="default_floatingview_channel_name">Default Channel</string>
</resources>

0 comments on commit 1a715f6

Please sign in to comment.