This repository has been archived by the owner on Apr 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yhaowa
committed
Nov 14, 2017
0 parents
commit 26ffcb2
Showing
51 changed files
with
1,290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
|
||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.0.0' | ||
|
||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
|
||
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
} | ||
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
|
||
|
||
|
||
defaultConfig { | ||
minSdkVersion 19 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
implementation 'com.android.support:appcompat-v7:26.1.0' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.1' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' | ||
} | ||
|
||
// JitPack Maven | ||
apply plugin: 'com.github.dcendents.android-maven' | ||
// Your Group | ||
group='com.github.yhaolpz' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# 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 |
26 changes: 26 additions & 0 deletions
26
...loatwindow/src/androidTest/java/com/example/fixedfloatwindow/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.fixedfloatwindow; | ||
|
||
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.*; | ||
|
||
/** | ||
* Instrumented 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.example.fixedfloatwindow.test", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.fixedfloatwindow"> | ||
<application> | ||
<activity | ||
android:name=".FixedFloatActivity" | ||
android:configChanges="keyboardHidden|orientation|screenSize" | ||
android:launchMode="standard" | ||
android:theme="@style/permission_PermissionActivity" | ||
android:windowSoftInputMode="stateHidden|stateAlwaysHidden"/> | ||
</application> | ||
</manifest> |
50 changes: 50 additions & 0 deletions
50
fixedfloatwindow/src/main/java/com/example/fixedfloatwindow/FixedFloatActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.example.fixedfloatwindow; | ||
|
||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.provider.Settings; | ||
import android.support.annotation.RequiresApi; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
/** | ||
* 用于在内部自动申请权限 | ||
*/ | ||
|
||
public class FixedFloatActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
requestAlertWindowPermission(); | ||
} | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.M) | ||
private void requestAlertWindowPermission() { | ||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); | ||
intent.setData(Uri.parse("package:" + getPackageName())); | ||
startActivityForResult(intent, 1); | ||
} | ||
|
||
|
||
@RequiresApi(api = Build.VERSION_CODES.M) | ||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (Settings.canDrawOverlays(this)) { | ||
mPermissionListener.onSuccess(); | ||
} else { | ||
mPermissionListener.onFail(); | ||
} | ||
finish(); | ||
} | ||
|
||
public static void setPermissionListener(PermissionListener permissionListener) { | ||
mPermissionListener = permissionListener; | ||
} | ||
|
||
private static PermissionListener mPermissionListener; | ||
} |
94 changes: 94 additions & 0 deletions
94
fixedfloatwindow/src/main/java/com/example/fixedfloatwindow/FixedFloatPhone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.example.fixedfloatwindow; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.view.View; | ||
import android.view.WindowManager; | ||
|
||
/** | ||
* Created by yhao on 17-11-14. | ||
* 7.1及以上需申请权限 | ||
*/ | ||
|
||
class FixedFloatPhone implements FixedFloatView { | ||
|
||
private final Context mContext; | ||
|
||
private int mWidth = FixedFloatWindow.WRAP_CONTENT; | ||
private int mHeight = FixedFloatWindow.WRAP_CONTENT; | ||
|
||
private final WindowManager mWindowManager; | ||
private final WindowManager.LayoutParams mLayoutParams; | ||
private View mView; | ||
|
||
private boolean mAutoReqPermission; | ||
|
||
|
||
public FixedFloatPhone(Context applicationContext, boolean autoReqPermission) { | ||
mContext = applicationContext; | ||
mAutoReqPermission = autoReqPermission; | ||
mWindowManager = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE); | ||
mLayoutParams = new WindowManager.LayoutParams(); | ||
} | ||
|
||
|
||
@Override | ||
public void setView(View view, int width, int height) { | ||
mWidth = width; | ||
mHeight = height; | ||
setView(view); | ||
} | ||
|
||
@Override | ||
public void setView(View view) { | ||
mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | ||
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; | ||
mLayoutParams.width = mWidth; | ||
mLayoutParams.height = mHeight; | ||
mLayoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; | ||
mView = view; | ||
} | ||
|
||
@Override | ||
public void setGravity(int gravity, int xOffset, int yOffset) { | ||
mLayoutParams.gravity = gravity; | ||
mLayoutParams.x = xOffset; | ||
mLayoutParams.y = yOffset; | ||
} | ||
|
||
@Override | ||
public void show() { | ||
if (FixedFloatWindow.hasPermission(mContext)) { | ||
mWindowManager.addView(mView, mLayoutParams); | ||
} else { | ||
if (mAutoReqPermission) { | ||
FixedFloatActivity.setPermissionListener(new PermissionListener() { | ||
@Override | ||
public void onSuccess() { | ||
mWindowManager.addView(mView, mLayoutParams); | ||
if (FixedFloatWindow.mPermissionListener != null) { | ||
FixedFloatWindow.mPermissionListener.onSuccess(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFail() { | ||
if (FixedFloatWindow.mPermissionListener != null) { | ||
FixedFloatWindow.mPermissionListener.onFail(); | ||
} | ||
} | ||
}); | ||
Intent intent = new Intent(mContext, FixedFloatActivity.class); | ||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
mContext.startActivity(intent); | ||
}else{ | ||
throw new IllegalArgumentException("请将 FixedFloatWindow 设置为自动申请权限,或自行申请权限!"); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void hide() { | ||
mWindowManager.removeView(mView); | ||
} | ||
} |
Oops, something went wrong.