package com.example.zxc.demoapplication;
import android.content.Context;
import android.graphics.PixelFormat;
import android.util.Log;
import android.view.Gravity;
import android.view.WindowManager;
/**
* Created by zxc on 17/1/21.
*/
public class FloatWindowManager {
private static final String TAG = FloatWindowManager.class.getSimpleName();
private WindowManager mWindowManger;
private static FloatWindowManager floatWindowManager;
private FloatLayout floatLayout;
private WindowManager.LayoutParams smallLayoutParams;
private Context context;
private FloatWindowManager() {
}
private FloatWindowManager(Context context) {
this.context = context;
}
public static FloatWindowManager instance(Context context) {
if (floatWindowManager == null) floatWindowManager = new FloatWindowManager(context);
return floatWindowManager;
}
private MenuLayout menuLayout;
private WindowManager.LayoutParams menuLayoutParams;
public void createFloatMenu() {
if (menuLayout != null) return;
Log.d(TAG, "create float menu");
WindowManager windowManager = getWindowManger(context);
if (menuLayout == null){
menuLayout = new MenuLayout(context);
menuLayoutParams = new WindowManager.LayoutParams();
menuLayoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
menuLayoutParams.format = PixelFormat.RGBA_8888;
}
windowManager.addView(menuLayout,menuLayoutParams);
}
public void createFloatWindow() {
if (isWindowShowing()) return;
WindowManager windowManager = getWindowManger(context);
int screenWidth = windowManager.getDefaultDisplay().getWidth();
int screenHeight = windowManager.getDefaultDisplay().getHeight();
if (floatLayout == null) {
floatLayout = new FloatLayout(context);
if (smallLayoutParams == null) {
smallLayoutParams = new WindowManager.LayoutParams();
smallLayoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
smallLayoutParams.format = PixelFormat.RGBA_8888;
smallLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
smallLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
smallLayoutParams.width = FloatLayout.viewWidth;
smallLayoutParams.height = FloatLayout.viewHeight;
smallLayoutParams.x = screenWidth;
smallLayoutParams.y = screenHeight / 2;
}
}
windowManager.addView(floatLayout,smallLayoutParams);
}
private WindowManager getWindowManger(Context context) {
if (mWindowManger == null) {
mWindowManger = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
}
return mWindowManger;
}
public boolean isWindowShowing() {
return floatLayout != null;
}
public void removeMenuLayout() {
if (menuLayout == null) return;
getWindowManger(context).removeView(menuLayout);
menuLayout = null;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
悬浮窗口及菜单demo
共98个文件
xml:40个
ds_store:20个
png:7个
需积分: 2 8 下载量 110 浏览量
2017-01-21
17:02:19
上传
评论
收藏 694KB ZIP 举报
温馨提示
资源推荐
资源详情
资源评论
收起资源包目录
DemoApplication.zip (98个子文件)
DemoApplication
.gitignore 118B
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 233B
local.properties 432B
build.gradle 498B
gradlew.bat 2KB
gradlew 5KB
app
.gitignore 7B
build.gradle 879B
proguard-rules.pro 661B
app.iml 13KB
libs
src
test
java
com
example
zxc
demoapplication
ExampleUnitTest.java 409B
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
main
AndroidManifest.xml 819B
java
com
example
zxc
demoapplication
FloatWindowService.java 884B
MenuLayout.java 688B
MainActivity.java 650B
FloatLayout.java 1KB
FloatWindowManager.java 3KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
res
values
styles.xml 383B
colors.xml 208B
strings.xml 78B
dimens.xml 211B
mipmap-xxhdpi
ic_launcher.png 8KB
layout
activity_main.xml 463B
views
small_layout.xml 457B
transparent_layout.xml 839B
.DS_Store 6KB
mipmap-xhdpi
ic_launcher.png 5KB
mipmap-hdpi
ic_launcher.png 3KB
drawable
bg_big.png 4KB
bg_small.png 458B
mipmap-mdpi
ic_launcher.png 2KB
values-w820dp
dimens.xml 358B
.DS_Store 8KB
mipmap-xxxhdpi
ic_launcher.png 10KB
.DS_Store 6KB
androidTest
java
com
example
zxc
demoapplication
ExampleInstrumentedTest.java 766B
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
DemoApplication.iml 869B
.gradle
2.14.1
tasks
_app_compileDebugJavaWithJavac
localJarClasspathSnapshot
localJarClasspathSnapshot.bin 21KB
localJarClasspathSnapshot.lock 17B
localClassSetAnalysis
localClassSetAnalysis.lock 17B
localClassSetAnalysis.bin 121KB
taskArtifacts
fileSnapshotsToTreeSnapshotsIndex.bin 29KB
cache.properties 30B
fileSnapshots.bin 3.39MB
cache.properties.lock 17B
fileHashes.bin 145KB
taskArtifacts.bin 138KB
gradle.properties 730B
.idea
libraries
jsr305_2_0_1.xml 322B
javax_annotation_api_1_2.xml 350B
rules_0_5.xml 724B
support_media_compat_24_2_1.xml 975B
runner_0_5.xml 730B
javax_inject_1.xml 316B
support_core_utils_24_2_1.xml 782B
support_compat_24_2_1.xml 933B
support_annotations_24_2_1.xml 519B
espresso_core_2_2_2.xml 633B
support_v4_24_2_1.xml 411B
appcompat_v7_24_2_1.xml 764B
javawriter_2_1_1.xml 322B
hamcrest_integration_1_3.xml 346B
animated_vector_drawable_24_2_1.xml 651B
hamcrest_library_1_3.xml 334B
espresso_idling_resource_2_2_2.xml 688B
support_fragment_24_2_1.xml 947B
exposed_instrumentation_api_publish_0_5.xml 706B
support_vector_drawable_24_2_1.xml 646B
support_core_ui_24_2_1.xml 940B
hamcrest_core_1_3.xml 516B
junit_4_12.xml 467B
runConfigurations.xml 564B
workspace.xml 166KB
encodings.xml 159B
misc.xml 2KB
modules.xml 367B
copyright
profiles_settings.xml 74B
compiler.xml 686B
gradle.xml 705B
.DS_Store 6KB
settings.gradle 15B
共 98 条
- 1
资源评论
自在时刻
- 粉丝: 20
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功