Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yhaowa committed Nov 14, 2017
0 parents commit 26ffcb2
Show file tree
Hide file tree
Showing 51 changed files with 1,290 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
19 changes: 19 additions & 0 deletions .idea/gradle.xml

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

33 changes: 33 additions & 0 deletions .idea/misc.xml

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

10 changes: 10 additions & 0 deletions .idea/modules.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

29 changes: 29 additions & 0 deletions build.gradle
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
}
1 change: 1 addition & 0 deletions fixedfloatwindow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions fixedfloatwindow/build.gradle
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'
21 changes: 21 additions & 0 deletions fixedfloatwindow/proguard-rules.pro
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
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());
}
}
11 changes: 11 additions & 0 deletions fixedfloatwindow/src/main/AndroidManifest.xml
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>
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;
}
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);
}
}
Loading

0 comments on commit 26ffcb2

Please sign in to comment.