├── README.md ├── bin ├── classes.dex ├── resources.ap_ ├── SmileHelper.apk ├── 360FloatWindowDemo.apk ├── res │ ├── drawable-hdpi │ │ ├── bt.9.png │ │ ├── bg_big.png │ │ └── bg_small.png │ ├── drawable-xhdpi │ │ ├── bg_small.png │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ └── drawable-xxhdpi │ │ └── ic_launcher.png ├── classes │ └── org │ │ └── xdty │ │ └── smilehelper │ │ ├── R.class │ │ ├── R$attr.class │ │ ├── R$id.class │ │ ├── R$menu.class │ │ ├── R$dimen.class │ │ ├── R$layout.class │ │ ├── R$string.class │ │ ├── R$style.class │ │ ├── BuildConfig.class │ │ ├── R$drawable.class │ │ ├── MainActivity.class │ │ ├── DatabaseHelper.class │ │ ├── MainActivity$1.class │ │ ├── MainActivity$2.class │ │ ├── MainActivity$3.class │ │ ├── MyWindowManager.class │ │ ├── FloatWindowAddView.class │ │ ├── FloatWindowBigView.class │ │ ├── FloatWindowService.class │ │ ├── FloatWindowAddView$1.class │ │ ├── FloatWindowAddView$2.class │ │ ├── FloatWindowBigView$1.class │ │ ├── FloatWindowBigView$2.class │ │ ├── FloatWindowSmallView.class │ │ ├── FloatWindowService$RefreshTask.class │ │ ├── FloatWindowService$RefreshTask$1.class │ │ └── FloatWindowService$RefreshTask$2.class ├── jarlist.cache ├── dexedLibs │ ├── android-support-v4-2602aa5622b1fcbb6ab69027b3fe0d64.jar │ └── android-support-v4-a757ade5ca5d2e6d5a1e8548564b94d2.jar └── AndroidManifest.xml ├── ic_launcher-web.png ├── libs └── android-support-v4.jar ├── res ├── drawable-hdpi │ ├── bt.9.png │ ├── bg_big.png │ ├── bg_small.png │ └── ic_launcher.png ├── drawable-xhdpi │ ├── bg_small.png │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── values-sw600dp │ └── dimens.xml ├── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── menu │ └── main.xml ├── values-sw720dp-land │ └── dimens.xml ├── values-zh-rCN │ └── strings.xml └── layout │ ├── float_window_small.xml │ ├── float_window_add.xml │ ├── float_window_big.xml │ └── main.xml ├── gen └── org │ └── xdty │ └── smilehelper │ ├── BuildConfig.java │ └── R.java ├── .settings └── org.eclipse.jdt.core.prefs ├── project.properties ├── .classpath ├── proguard-project.txt ├── .project ├── AndroidManifest.xml └── src └── org └── xdty └── smilehelper ├── FloatWindowBigView.java ├── MainActivity.java ├── DatabaseHelper.java ├── FloatWindowSmallView.java ├── FloatWindowService.java ├── FloatWindowAddView.java └── MyWindowManager.java /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/README.md -------------------------------------------------------------------------------- /bin/classes.dex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes.dex -------------------------------------------------------------------------------- /bin/resources.ap_: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/resources.ap_ -------------------------------------------------------------------------------- /bin/SmileHelper.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/SmileHelper.apk -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/ic_launcher-web.png -------------------------------------------------------------------------------- /bin/360FloatWindowDemo.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/360FloatWindowDemo.apk -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/libs/android-support-v4.jar -------------------------------------------------------------------------------- /res/drawable-hdpi/bt.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/res/drawable-hdpi/bt.9.png -------------------------------------------------------------------------------- /bin/res/drawable-hdpi/bt.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/res/drawable-hdpi/bt.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/bg_big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/res/drawable-hdpi/bg_big.png -------------------------------------------------------------------------------- /res/drawable-hdpi/bg_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/res/drawable-hdpi/bg_small.png -------------------------------------------------------------------------------- /bin/res/drawable-hdpi/bg_big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/res/drawable-hdpi/bg_big.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/bg_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/res/drawable-xhdpi/bg_small.png -------------------------------------------------------------------------------- /bin/res/drawable-hdpi/bg_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/res/drawable-hdpi/bg_small.png -------------------------------------------------------------------------------- /bin/res/drawable-xhdpi/bg_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/res/drawable-xhdpi/bg_small.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/R.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/R.class -------------------------------------------------------------------------------- /bin/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/R$attr.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/R$attr.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/R$id.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/R$id.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/R$menu.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/R$menu.class -------------------------------------------------------------------------------- /bin/jarlist.cache: -------------------------------------------------------------------------------- 1 | # cache for current jar dependecy. DO NOT EDIT. 2 | # format is 3 | # Encoding is UTF-8 4 | -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/R$dimen.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/R$dimen.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/R$layout.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/R$layout.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/R$string.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/R$string.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/R$style.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/R$style.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/BuildConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/BuildConfig.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/R$drawable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/R$drawable.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/MainActivity.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/MainActivity.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/DatabaseHelper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/DatabaseHelper.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/MainActivity$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/MainActivity$1.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/MainActivity$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/MainActivity$2.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/MainActivity$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/MainActivity$3.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/MyWindowManager.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/MyWindowManager.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowAddView.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowAddView.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowBigView.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowBigView.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowService.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowAddView$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowAddView$1.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowAddView$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowAddView$2.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowBigView$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowBigView$1.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowBigView$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowBigView$2.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowSmallView.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowSmallView.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowService$RefreshTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowService$RefreshTask.class -------------------------------------------------------------------------------- /bin/dexedLibs/android-support-v4-2602aa5622b1fcbb6ab69027b3fe0d64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/dexedLibs/android-support-v4-2602aa5622b1fcbb6ab69027b3fe0d64.jar -------------------------------------------------------------------------------- /bin/dexedLibs/android-support-v4-a757ade5ca5d2e6d5a1e8548564b94d2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/dexedLibs/android-support-v4-a757ade5ca5d2e6d5a1e8548564b94d2.jar -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowService$RefreshTask$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowService$RefreshTask$1.class -------------------------------------------------------------------------------- /bin/classes/org/xdty/smilehelper/FloatWindowService$RefreshTask$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xdtianyu/SmileHelper/master/bin/classes/org/xdty/smilehelper/FloatWindowService$RefreshTask$2.class -------------------------------------------------------------------------------- /gen/org/xdty/smilehelper/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /** Automatically generated file. DO NOT MODIFY */ 2 | package org.xdty.smilehelper; 3 | 4 | public final class BuildConfig { 5 | public final static boolean DEBUG = true; 6 | } -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | -------------------------------------------------------------------------------- /res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | -------------------------------------------------------------------------------- /res/values-zh-rCN/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 表情浮窗 5 | 设置 6 | 开启悬表情浮窗 7 | 关闭悬表情浮窗 8 | 添加 9 | 点击浮窗中的添加按钮添加应用界面到浮窗,完成后将在下次进入应用界面时自动弹出浮窗。 10 | 完成 11 | 返回 12 | 已添加 13 | -------------------------------------------------------------------------------- /res/layout/float_window_small.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 18 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-16 15 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SmileHelper 5 | Settings 6 | start smile floating 7 | close smile floating 8 | add applation 9 | by touch add button on applation screen, then enter applation again the floating will show. 10 | finish 11 | return 12 | Added 13 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /res/layout/float_window_add.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 13 | 20 | 27 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /bin/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/org/xdty/smilehelper/FloatWindowBigView.java: -------------------------------------------------------------------------------- 1 | package org.xdty.smilehelper; 2 | 3 | import org.xdty.smilehelper.R; 4 | 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.widget.Button; 10 | import android.widget.LinearLayout; 11 | 12 | public class FloatWindowBigView extends LinearLayout { 13 | 14 | /** 15 | * 记录大悬浮窗的宽度 16 | */ 17 | public static int viewWidth; 18 | 19 | /** 20 | * 记录大悬浮窗的高度 21 | */ 22 | public static int viewHeight; 23 | 24 | public FloatWindowBigView(final Context context) { 25 | super(context); 26 | LayoutInflater.from(context).inflate(R.layout.float_window_big, this); 27 | View view = findViewById(R.id.big_window_layout); 28 | viewWidth = view.getLayoutParams().width; 29 | viewHeight = view.getLayoutParams().height; 30 | Button close = (Button) findViewById(R.id.close); 31 | Button back = (Button) findViewById(R.id.back); 32 | close.setOnClickListener(new OnClickListener() { 33 | @Override 34 | public void onClick(View v) { 35 | // 点击关闭悬浮窗的时候,移除所有悬浮窗,并停止Service 36 | MyWindowManager.removeBigWindow(context); 37 | MyWindowManager.removeSmallWindow(context); 38 | Intent intent = new Intent(getContext(), FloatWindowService.class); 39 | context.stopService(intent); 40 | } 41 | }); 42 | back.setOnClickListener(new OnClickListener() { 43 | @Override 44 | public void onClick(View v) { 45 | // 点击返回的时候,移除大悬浮窗,创建小悬浮窗 46 | MyWindowManager.removeBigWindow(context); 47 | MyWindowManager.createSmallWindow(context); 48 | } 49 | }); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/org/xdty/smilehelper/MainActivity.java: -------------------------------------------------------------------------------- 1 | package org.xdty.smilehelper; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.view.View.OnClickListener; 9 | import android.widget.Button; 10 | 11 | public class MainActivity extends Activity { 12 | 13 | private Context mContext; 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | mContext = this; 18 | setContentView(R.layout.main); 19 | Button startFloatWindow = (Button) findViewById(R.id.start_float_window); 20 | startFloatWindow.setOnClickListener(new OnClickListener() { 21 | @Override 22 | public void onClick(View arg0) { 23 | Intent intent = new Intent(MainActivity.this, FloatWindowService.class); 24 | startService(intent); 25 | FloatWindowSmallView.close = false; 26 | MyWindowManager.setAddState(false); 27 | finish(); 28 | } 29 | }); 30 | 31 | Button stopFloatWindow = (Button) findViewById(R.id.stop_float_window); 32 | stopFloatWindow.setOnClickListener(new OnClickListener() { 33 | @Override 34 | public void onClick(View arg0) { 35 | MyWindowManager.removeSmallWindow(getContext()); 36 | FloatWindowSmallView.close = true; 37 | } 38 | }); 39 | 40 | Button addFloatWindow = (Button) findViewById(R.id.add_float_window); 41 | addFloatWindow.setOnClickListener(new OnClickListener() { 42 | @Override 43 | public void onClick(View v) { 44 | Intent intent = new Intent(MainActivity.this, FloatWindowService.class); 45 | startService(intent); 46 | FloatWindowSmallView.close = false; 47 | MyWindowManager.setAddState(true); 48 | finish(); 49 | } 50 | }); 51 | } 52 | 53 | private Context getContext(){ 54 | return mContext; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/org/xdty/smilehelper/DatabaseHelper.java: -------------------------------------------------------------------------------- 1 | package org.xdty.smilehelper; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.database.sqlite.SQLiteOpenHelper; 8 | 9 | public class DatabaseHelper extends SQLiteOpenHelper { 10 | 11 | private static final String DB_NAME = "smile_helper"; 12 | private static final String TB_NAME = "app_list"; 13 | private static final String COLUMNS_ID = "id"; 14 | private static final String COLUMNS_INDEX = "indexed"; 15 | private static final String COLUMNS_NAME = "name"; 16 | private static final String COLUMNS_CHECK = "checked"; 17 | 18 | public DatabaseHelper(Context context) { 19 | super(context, DB_NAME, null, 1); 20 | } 21 | 22 | @Override 23 | public void onCreate(SQLiteDatabase db) { 24 | String sql = "CREATE TABLE IF NOT EXISTS " + TB_NAME + " (" + COLUMNS_ID 25 | + " INTEGER PRIMARY KEY AUTOINCREMENT," + COLUMNS_INDEX 26 | + " INTEGER," +COLUMNS_NAME+ " TEXT," +COLUMNS_CHECK 27 | + " BOOLEAN)"; 28 | 29 | db.execSQL(sql); 30 | } 31 | 32 | @Override 33 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 34 | db.execSQL("DROP TABLE IF EXISTS "+TB_NAME); 35 | onCreate(db); 36 | } 37 | /** 38 | * 返回所有数据 39 | * @return 40 | */ 41 | public Cursor selectAll() { 42 | SQLiteDatabase db = this.getReadableDatabase(); 43 | Cursor cursor = db.query(TB_NAME, null, null, null,null, null, "id desc"); 44 | return cursor; 45 | } 46 | /** 47 | * 根据条件查询 48 | * @param columnsName 49 | * @return 50 | */ 51 | public Cursor selectForChecked(boolean isChecked) { 52 | SQLiteDatabase db = this.getReadableDatabase(); 53 | String where = COLUMNS_CHECK+"=?"; 54 | int check = 0; 55 | if(isChecked){ 56 | check = 1; 57 | } 58 | String[] whereValue={Integer.toString(check)}; 59 | Cursor cursor = db.query(TB_NAME, null, where, whereValue,null, null, "id desc"); 60 | return cursor; 61 | } 62 | 63 | public long insert(int index,String name,boolean checked) { 64 | SQLiteDatabase db = this.getWritableDatabase(); 65 | ContentValues cv = new ContentValues(); 66 | cv.put(COLUMNS_INDEX, index); 67 | cv.put(COLUMNS_NAME, name); 68 | cv.put(COLUMNS_CHECK, checked); 69 | long row = db.insert(TB_NAME, null, cv); 70 | db.close(); 71 | return row; 72 | 73 | } 74 | 75 | public void delete(int index) { 76 | SQLiteDatabase db = this.getWritableDatabase(); 77 | String where=COLUMNS_INDEX+"=?"; 78 | String[] whereValue = {Integer.toString(index)}; 79 | db.delete(TB_NAME, where, whereValue); 80 | } 81 | 82 | public void update(int index,boolean check) { 83 | SQLiteDatabase db = this.getWritableDatabase(); 84 | String where=COLUMNS_INDEX+"=?"; 85 | String[] whereValue = {Integer.toString(index)}; 86 | ContentValues cv = new ContentValues(); 87 | cv.put(COLUMNS_CHECK, check); 88 | db.update(TB_NAME, cv, where, whereValue); 89 | } 90 | 91 | } -------------------------------------------------------------------------------- /gen/org/xdty/smilehelper/R.java: -------------------------------------------------------------------------------- 1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. 2 | * 3 | * This class was automatically generated by the 4 | * aapt tool from the resource data it found. It 5 | * should not be modified by hand. 6 | */ 7 | 8 | package org.xdty.smilehelper; 9 | 10 | public final class R { 11 | public static final class attr { 12 | } 13 | public static final class dimen { 14 | /** Default screen margins, per the Android Design guidelines. 15 | 16 | Customize dimensions originally defined in res/values/dimens.xml (such as 17 | screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here. 18 | 19 | */ 20 | public static final int activity_horizontal_margin=0x7f040000; 21 | public static final int activity_vertical_margin=0x7f040001; 22 | } 23 | public static final class drawable { 24 | public static final int bg_big=0x7f020000; 25 | public static final int bg_small=0x7f020001; 26 | public static final int bt=0x7f020002; 27 | public static final int ic_launcher=0x7f020003; 28 | } 29 | public static final class id { 30 | public static final int action_settings=0x7f08000a; 31 | public static final int add=0x7f080001; 32 | public static final int add_float_window=0x7f080009; 33 | public static final int add_window_layout=0x7f080000; 34 | public static final int back=0x7f080005; 35 | public static final int big_window_layout=0x7f080003; 36 | public static final int close=0x7f080004; 37 | public static final int finish=0x7f080002; 38 | public static final int small_window_layout=0x7f080006; 39 | public static final int start_float_window=0x7f080007; 40 | public static final int stop_float_window=0x7f080008; 41 | } 42 | public static final class layout { 43 | public static final int float_window_add=0x7f030000; 44 | public static final int float_window_big=0x7f030001; 45 | public static final int float_window_small=0x7f030002; 46 | public static final int main=0x7f030003; 47 | } 48 | public static final class menu { 49 | public static final int main=0x7f070000; 50 | } 51 | public static final class string { 52 | public static final int action_settings=0x7f050001; 53 | public static final int add_floating=0x7f050004; 54 | public static final int add_summary=0x7f050005; 55 | public static final int app_name=0x7f050000; 56 | public static final int close_floating=0x7f050003; 57 | public static final int start_floating=0x7f050002; 58 | public static final int string_added=0x7f050008; 59 | public static final int string_finish=0x7f050006; 60 | public static final int string_return=0x7f050007; 61 | } 62 | public static final class style { 63 | /** 64 | Base application theme, dependent on API level. This theme is replaced 65 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 66 | 67 | 68 | Theme customizations available in newer API levels can go in 69 | res/values-vXX/styles.xml, while customizations related to 70 | backward-compatibility can go here. 71 | 72 | */ 73 | public static final int AppBaseTheme=0x7f060000; 74 | /** Application theme. 75 | All customizations that are NOT specific to a particular API-level can go here. 76 | */ 77 | public static final int AppTheme=0x7f060001; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/org/xdty/smilehelper/FloatWindowSmallView.java: -------------------------------------------------------------------------------- 1 | package org.xdty.smilehelper; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | import org.xdty.smilehelper.R; 6 | 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.view.LayoutInflater; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | import android.view.WindowManager; 13 | import android.widget.LinearLayout; 14 | 15 | public class FloatWindowSmallView extends LinearLayout { 16 | 17 | public static boolean close = false; 18 | 19 | /** 20 | * 记录小悬浮窗的宽度 21 | */ 22 | public static int viewWidth; 23 | 24 | /** 25 | * 记录小悬浮窗的高度 26 | */ 27 | public static int viewHeight; 28 | 29 | /** 30 | * 记录系统状态栏的高度 31 | */ 32 | private static int statusBarHeight; 33 | 34 | /** 35 | * 用于更新小悬浮窗的位置 36 | */ 37 | private WindowManager windowManager; 38 | 39 | /** 40 | * 小悬浮窗的参数 41 | */ 42 | private WindowManager.LayoutParams mParams; 43 | 44 | /** 45 | * 记录当前手指位置在屏幕上的横坐标值 46 | */ 47 | private float xInScreen; 48 | 49 | /** 50 | * 记录当前手指位置在屏幕上的纵坐标值 51 | */ 52 | private float yInScreen; 53 | 54 | /** 55 | * 记录手指按下时在屏幕上的横坐标的值 56 | */ 57 | private float xDownInScreen; 58 | 59 | /** 60 | * 记录手指按下时在屏幕上的纵坐标的值 61 | */ 62 | private float yDownInScreen; 63 | 64 | /** 65 | * 记录手指按下时在小悬浮窗的View上的横坐标的值 66 | */ 67 | private float xInView; 68 | 69 | /** 70 | * 记录手指按下时在小悬浮窗的View上的纵坐标的值 71 | */ 72 | private float yInView; 73 | 74 | /** 75 | * 传入的上下文 76 | */ 77 | private Context mContext; 78 | 79 | public FloatWindowSmallView(Context context) { 80 | super(context); 81 | mContext = context; 82 | windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 83 | LayoutInflater.from(context).inflate(R.layout.float_window_small, this); 84 | View view = findViewById(R.id.small_window_layout); 85 | viewWidth = view.getLayoutParams().width; 86 | viewHeight = view.getLayoutParams().height; 87 | //TextView percentView = (TextView) findViewById(R.id.percent); 88 | //percentView.setText(MyWindowManager.getUsedPercentValue(context)); 89 | } 90 | 91 | @Override 92 | public boolean onTouchEvent(MotionEvent event) { 93 | switch (event.getAction()) { 94 | case MotionEvent.ACTION_DOWN: 95 | // 手指按下时记录必要数据,纵坐标的值都需要减去状态栏高度 96 | xInView = event.getX(); 97 | yInView = event.getY(); 98 | xDownInScreen = event.getRawX(); 99 | yDownInScreen = event.getRawY() - getStatusBarHeight(); 100 | xInScreen = event.getRawX(); 101 | yInScreen = event.getRawY() - getStatusBarHeight(); 102 | break; 103 | case MotionEvent.ACTION_MOVE: 104 | xInScreen = event.getRawX(); 105 | yInScreen = event.getRawY() - getStatusBarHeight(); 106 | // 手指移动的时候更新小悬浮窗的位置 107 | updateViewPosition(); 108 | break; 109 | case MotionEvent.ACTION_UP: 110 | // 如果手指离开屏幕时,xDownInScreen和xInScreen相等,且yDownInScreen和yInScreen相等,则视为触发了单击事件。 111 | if (Math.abs(xDownInScreen - xInScreen) < 3 && Math.abs(yDownInScreen - yInScreen) < 3) { 112 | //openBigWindow(); 113 | openSmileApp(); 114 | } 115 | break; 116 | default: 117 | break; 118 | } 119 | return true; 120 | } 121 | 122 | /** 123 | * 将小悬浮窗的参数传入,用于更新小悬浮窗的位置。 124 | * 125 | * @param params 126 | * 小悬浮窗的参数 127 | */ 128 | public void setParams(WindowManager.LayoutParams params) { 129 | mParams = params; 130 | } 131 | 132 | /** 133 | * 更新小悬浮窗在屏幕中的位置。 134 | */ 135 | private void updateViewPosition() { 136 | mParams.x = (int) (xInScreen - xInView); 137 | mParams.y = (int) (yInScreen - yInView); 138 | windowManager.updateViewLayout(this, mParams); 139 | } 140 | 141 | /** 142 | * 打开表情应用。 143 | */ 144 | private void openSmileApp() { 145 | //Toast.makeText(mContext, "test", Toast.LENGTH_LONG).show(); 146 | Intent smileIntent = new Intent(); 147 | smileIntent.setClassName("com.youba.emoticons", 148 | "com.youba.emoticons.Emoticons1Activity"); 149 | smileIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 150 | mContext.startActivity(smileIntent); 151 | } 152 | 153 | /** 154 | * 打开大悬浮窗,同时关闭小悬浮窗。 155 | */ 156 | private void openBigWindow() { 157 | MyWindowManager.createBigWindow(getContext()); 158 | MyWindowManager.removeSmallWindow(getContext()); 159 | } 160 | 161 | /** 162 | * 用于获取状态栏的高度。 163 | * 164 | * @return 返回状态栏高度的像素值。 165 | */ 166 | private int getStatusBarHeight() { 167 | if (statusBarHeight == 0) { 168 | try { 169 | Class c = Class.forName("com.android.internal.R$dimen"); 170 | Object o = c.newInstance(); 171 | Field field = c.getField("status_bar_height"); 172 | int x = (Integer) field.get(o); 173 | statusBarHeight = getResources().getDimensionPixelSize(x); 174 | } catch (Exception e) { 175 | e.printStackTrace(); 176 | } 177 | } 178 | return statusBarHeight; 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/org/xdty/smilehelper/FloatWindowService.java: -------------------------------------------------------------------------------- 1 | package org.xdty.smilehelper; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Timer; 6 | import java.util.TimerTask; 7 | 8 | import android.app.ActivityManager; 9 | import android.app.ActivityManager.RunningTaskInfo; 10 | import android.app.Service; 11 | import android.content.Context; 12 | import android.content.Intent; 13 | import android.content.pm.PackageManager; 14 | import android.content.pm.ResolveInfo; 15 | import android.database.Cursor; 16 | import android.os.Handler; 17 | import android.os.IBinder; 18 | import android.util.Log; 19 | import android.widget.Toast; 20 | 21 | public class FloatWindowService extends Service { 22 | 23 | /** 24 | * 用于在线程中创建或移除悬浮窗。 25 | */ 26 | private Handler handler = new Handler(); 27 | 28 | /** 29 | * 定时器,定时进行检测当前应该创建还是移除悬浮窗。 30 | */ 31 | private Timer timer; 32 | 33 | /** 34 | * 数据库存储 35 | */ 36 | private DatabaseHelper mDatabaseHelper; 37 | 38 | /** 39 | * 数据库信息保存到数组中 40 | */ 41 | private static ArrayList mAppList; 42 | 43 | @Override 44 | public IBinder onBind(Intent intent) { 45 | return null; 46 | } 47 | 48 | @Override 49 | public int onStartCommand(Intent intent, int flags, int startId) { 50 | 51 | // 获取数据库列表,保存到mAppList中 52 | mDatabaseHelper = new DatabaseHelper(getApplicationContext()); 53 | Cursor cursor = mDatabaseHelper.selectForChecked(true); 54 | mAppList = new ArrayList(); 55 | if (cursor.getCount()==0) { 56 | mAppList.add("null"); 57 | } else { 58 | while (cursor.moveToNext()) { 59 | mAppList.add(cursor.getString(2)); 60 | } 61 | } 62 | 63 | // 开启定时器,每隔0.5秒刷新一次 64 | if (timer == null) { 65 | timer = new Timer(); 66 | timer.scheduleAtFixedRate(new RefreshTask(), 0, 500); 67 | } 68 | new RefreshTask(); 69 | return super.onStartCommand(intent, flags, startId); 70 | } 71 | 72 | /** 73 | * 获取当前界面顶部的Acivity名称 74 | * @return 返回完整的类名 75 | */ 76 | private String getTopAppName() { 77 | ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 78 | List rti = mActivityManager.getRunningTasks(1); 79 | return rti.get(0).topActivity.getClassName(); 80 | } 81 | 82 | /** 83 | * 获取当前界面顶部的Acivity包名称 84 | * @return 返回包名 85 | */ 86 | private String getTopPackageName() { 87 | ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 88 | List rti = mActivityManager.getRunningTasks(1); 89 | return rti.get(0).topActivity.getPackageName(); 90 | } 91 | 92 | /** 93 | * 判断是否为被添加进appList 94 | */ 95 | private boolean isInList() { 96 | return mAppList.isEmpty() ? false : mAppList.contains(getTopAppName()); 97 | } 98 | 99 | @Override 100 | public void onDestroy() { 101 | super.onDestroy(); 102 | // Service被终止的同时也停止定时器继续运行 103 | timer.cancel(); 104 | timer = null; 105 | } 106 | 107 | class RefreshTask extends TimerTask { 108 | 109 | @Override 110 | public void run() { 111 | 112 | if (!isHome() && !MyWindowManager.isWindowShowing() && !isClose()) { 113 | handler.post(new Runnable() { 114 | @Override 115 | public void run() { 116 | if (MyWindowManager.getAddState()) { 117 | MyWindowManager.createAddWindow(getApplicationContext()); 118 | } else if (isInList()) { 119 | MyWindowManager.createSmallWindow(getApplicationContext()); 120 | } 121 | } 122 | }); 123 | } 124 | 125 | else if ((!isInList()||isHome()) && MyWindowManager.isWindowShowing()) { 126 | handler.post(new Runnable() { 127 | @Override 128 | public void run() { 129 | MyWindowManager.removeSmallWindow(getApplicationContext()); 130 | MyWindowManager.removeBigWindow(getApplicationContext()); 131 | if (isHome()) { 132 | MyWindowManager.removeAddWindow(getApplicationContext()); 133 | } 134 | } 135 | }); 136 | } 137 | //闪动效果 138 | // else { 139 | // MyWindowManager.removeSmallWindow(getApplicationContext()); 140 | // MyWindowManager.removeBigWindow(getApplicationContext()); 141 | // MyWindowManager.removeAddWindow(getApplicationContext()); 142 | // } 143 | // // 当前界面是桌面,且有悬浮窗显示,则更新内存数据。 144 | // else if (isHome() && MyWindowManager.isWindowShowing()) { 145 | // handler.post(new Runnable() { 146 | // @Override 147 | // public void run() { 148 | // MyWindowManager.updateUsedPercent(getApplicationContext()); 149 | // } 150 | // }); 151 | // } 152 | } 153 | 154 | } 155 | 156 | private boolean isClose() { 157 | return FloatWindowSmallView.close; 158 | } 159 | 160 | /** 161 | * 判断当前界面是否是桌面 162 | */ 163 | private boolean isHome() { 164 | return getHomes().contains(getTopPackageName()); 165 | } 166 | 167 | /** 168 | * 获得属于桌面的应用的应用包名称 169 | * 170 | * @return 返回包含所有包名的字符串列表 171 | */ 172 | private List getHomes() { 173 | List names = new ArrayList(); 174 | PackageManager packageManager = this.getPackageManager(); 175 | Intent intent = new Intent(Intent.ACTION_MAIN); 176 | intent.addCategory(Intent.CATEGORY_HOME); 177 | List resolveInfo = packageManager.queryIntentActivities(intent, 178 | PackageManager.MATCH_DEFAULT_ONLY); 179 | for (ResolveInfo ri : resolveInfo) { 180 | names.add(ri.activityInfo.packageName); 181 | } 182 | return names; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /src/org/xdty/smilehelper/FloatWindowAddView.java: -------------------------------------------------------------------------------- 1 | package org.xdty.smilehelper; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.List; 5 | 6 | import android.app.ActivityManager; 7 | import android.app.ActivityManager.RunningTaskInfo; 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.database.Cursor; 11 | import android.view.LayoutInflater; 12 | import android.view.MotionEvent; 13 | import android.view.View; 14 | import android.view.WindowManager; 15 | import android.widget.Button; 16 | import android.widget.LinearLayout; 17 | import android.widget.Toast; 18 | 19 | public class FloatWindowAddView extends LinearLayout { 20 | 21 | /** 22 | * 记录添加悬浮窗的宽度 23 | */ 24 | public static int viewWidth; 25 | 26 | /** 27 | * 记录添加悬浮窗的高度 28 | */ 29 | public static int viewHeight; 30 | 31 | /** 32 | * 用于更新添加悬浮窗的位置 33 | */ 34 | private WindowManager windowManager; 35 | 36 | /** 37 | * 数据库存储 38 | */ 39 | private DatabaseHelper mDatabaseHelper; 40 | 41 | /** 42 | * 添加悬浮窗的参数 43 | */ 44 | private WindowManager.LayoutParams mParams; 45 | 46 | /** 47 | * 记录系统状态栏的高度 48 | */ 49 | private static int statusBarHeight; 50 | 51 | /** 52 | * 记录当前手指位置在屏幕上的横坐标值 53 | */ 54 | private float xInScreen; 55 | 56 | /** 57 | * 记录当前手指位置在屏幕上的纵坐标值 58 | */ 59 | private float yInScreen; 60 | 61 | /** 62 | * 记录手指按下时在屏幕上的横坐标的值 63 | */ 64 | private float xDownInScreen; 65 | 66 | /** 67 | * 记录手指按下时在屏幕上的纵坐标的值 68 | */ 69 | private float yDownInScreen; 70 | 71 | /** 72 | * 记录手指按下时在添加悬浮窗的View上的横坐标的值 73 | */ 74 | private float xInView; 75 | 76 | /** 77 | * 记录手指按下时在添加悬浮窗的View上的纵坐标的值 78 | */ 79 | private float yInView; 80 | 81 | public FloatWindowAddView(final Context context) { 82 | super(context); 83 | windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 84 | LayoutInflater.from(context).inflate(R.layout.float_window_add, this); 85 | View view = findViewById(R.id.add_window_layout); 86 | viewWidth = view.getLayoutParams().width; 87 | viewHeight = view.getLayoutParams().height; 88 | Button add = (Button) findViewById(R.id.add); 89 | Button finish = (Button) findViewById(R.id.finish); 90 | add.setOnClickListener(new OnClickListener() { 91 | @Override 92 | public void onClick(View v) { 93 | // 点击添加后添加当前的activity到数据库 94 | String appName = getTopActivityName(context); 95 | mDatabaseHelper = new DatabaseHelper(context); 96 | Cursor cursor = mDatabaseHelper.selectAll(); 97 | boolean hasValue = false; 98 | while (cursor.moveToNext()) { 99 | if(cursor.getString(2).equals(appName)) { 100 | mDatabaseHelper.update(cursor.getInt(0), true); 101 | hasValue = true; 102 | break; 103 | } 104 | } 105 | if (!hasValue) { 106 | cursor.moveToLast(); 107 | int index = (cursor.getCount()==0)?1:cursor.getInt(1)+1; 108 | mDatabaseHelper.insert(index, appName, true); 109 | } 110 | Toast.makeText(context, R.string.string_added, Toast.LENGTH_LONG).show(); 111 | } 112 | }); 113 | finish.setOnClickListener(new OnClickListener() { 114 | @Override 115 | public void onClick(View v) { 116 | // 点击完成后返回到主界面 117 | MyWindowManager.removeAddWindow(context); 118 | MyWindowManager.removeBigWindow(context); 119 | Intent mIntent = new Intent(); 120 | mIntent.setClassName("org.xdty.smilehelper", 121 | "org.xdty.smilehelper.MainActivity"); 122 | mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 123 | context.startActivity(mIntent); 124 | MyWindowManager.removeAddWindow(context); 125 | MyWindowManager.setAddState(false); 126 | } 127 | }); 128 | } 129 | 130 | @Override 131 | public boolean onTouchEvent(MotionEvent event) { 132 | switch (event.getAction()) { 133 | case MotionEvent.ACTION_DOWN: 134 | // 手指按下时记录必要数据,纵坐标的值都需要减去状态栏高度 135 | xInView = event.getX(); 136 | yInView = event.getY(); 137 | xDownInScreen = event.getRawX(); 138 | yDownInScreen = event.getRawY() - getStatusBarHeight(); 139 | xInScreen = event.getRawX(); 140 | yInScreen = event.getRawY() - getStatusBarHeight(); 141 | break; 142 | case MotionEvent.ACTION_MOVE: 143 | xInScreen = event.getRawX(); 144 | yInScreen = event.getRawY() - getStatusBarHeight(); 145 | // 手指移动的时候更新添加悬浮窗的位置 146 | updateViewPosition(); 147 | break; 148 | case MotionEvent.ACTION_UP: 149 | // 如果手指离开屏幕时,xDownInScreen和xInScreen相等,且yDownInScreen和yInScreen相等,则视为触发了单击事件。 150 | if (Math.abs(xDownInScreen - xInScreen) < 3 && Math.abs(yDownInScreen - yInScreen) < 3) { 151 | //openBigWindow(); 152 | } 153 | break; 154 | default: 155 | break; 156 | } 157 | return true; 158 | } 159 | 160 | /** 161 | * 将添加悬浮窗的参数传入,用于更新添加悬浮窗的位置。 162 | * 163 | * @param params 164 | * 添加悬浮窗的参数 165 | */ 166 | public void setParams(WindowManager.LayoutParams params) { 167 | mParams = params; 168 | } 169 | 170 | /** 171 | * 更新添加悬浮窗在屏幕中的位置。 172 | */ 173 | private void updateViewPosition() { 174 | mParams.x = (int) (xInScreen - xInView); 175 | mParams.y = (int) (yInScreen - yInView); 176 | windowManager.updateViewLayout(this, mParams); 177 | } 178 | 179 | private String getTopActivityName(Context context) { 180 | ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 181 | List rti = mActivityManager.getRunningTasks(1); 182 | return rti.get(0).topActivity.getClassName(); 183 | } 184 | 185 | /** 186 | * 用于获取状态栏的高度。 187 | * 188 | * @return 返回状态栏高度的像素值。 189 | */ 190 | private int getStatusBarHeight() { 191 | if (statusBarHeight == 0) { 192 | try { 193 | Class c = Class.forName("com.android.internal.R$dimen"); 194 | Object o = c.newInstance(); 195 | Field field = c.getField("status_bar_height"); 196 | int x = (Integer) field.get(o); 197 | statusBarHeight = getResources().getDimensionPixelSize(x); 198 | } catch (Exception e) { 199 | e.printStackTrace(); 200 | } 201 | } 202 | return statusBarHeight; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /src/org/xdty/smilehelper/MyWindowManager.java: -------------------------------------------------------------------------------- 1 | package org.xdty.smilehelper; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | 7 | import android.app.ActivityManager; 8 | import android.content.Context; 9 | import android.graphics.PixelFormat; 10 | import android.view.Gravity; 11 | import android.view.WindowManager; 12 | import android.view.WindowManager.LayoutParams; 13 | 14 | public class MyWindowManager { 15 | 16 | /** 17 | * 小悬浮窗View的实例 18 | */ 19 | private static FloatWindowSmallView smallWindow; 20 | 21 | /** 22 | * 大悬浮窗View的实例 23 | */ 24 | private static FloatWindowBigView bigWindow; 25 | 26 | /** 27 | * 添加悬浮窗View的实例 28 | */ 29 | private static FloatWindowAddView addWindow; 30 | 31 | /** 32 | * 小悬浮窗View的参数 33 | */ 34 | private static LayoutParams smallWindowParams; 35 | 36 | /** 37 | * 大悬浮窗View的参数 38 | */ 39 | private static LayoutParams bigWindowParams; 40 | 41 | /** 42 | * 添加悬浮窗View的参数 43 | */ 44 | private static LayoutParams addWindowParams; 45 | 46 | /** 47 | * 用于控制在屏幕上添加或移除悬浮窗 48 | */ 49 | private static WindowManager mWindowManager; 50 | 51 | /** 52 | * 用于获取手机可用内存 53 | */ 54 | private static ActivityManager mActivityManager; 55 | 56 | /** 57 | * 当前添加悬浮窗显示的状态 58 | */ 59 | private static boolean addFloatViewState = false; 60 | 61 | /** 62 | * 创建一个小悬浮窗。初始位置为屏幕的右部中间位置。 63 | * 64 | * @param context 65 | * 必须为应用程序的Context. 66 | */ 67 | public static void createSmallWindow(Context context) { 68 | WindowManager windowManager = getWindowManager(context); 69 | int screenWidth = windowManager.getDefaultDisplay().getWidth(); 70 | int screenHeight = windowManager.getDefaultDisplay().getHeight(); 71 | if (smallWindow == null) { 72 | smallWindow = new FloatWindowSmallView(context); 73 | if (smallWindowParams == null) { 74 | smallWindowParams = new LayoutParams(); 75 | smallWindowParams.type = LayoutParams.TYPE_PHONE; 76 | smallWindowParams.format = PixelFormat.RGBA_8888; 77 | smallWindowParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL 78 | | LayoutParams.FLAG_NOT_FOCUSABLE; 79 | smallWindowParams.gravity = Gravity.LEFT | Gravity.TOP; 80 | smallWindowParams.width = FloatWindowSmallView.viewWidth; 81 | smallWindowParams.height = FloatWindowSmallView.viewHeight; 82 | smallWindowParams.x = screenWidth; 83 | smallWindowParams.y = screenHeight / 2; 84 | smallWindowParams.alpha = 150; 85 | } 86 | smallWindow.setParams(smallWindowParams); 87 | windowManager.addView(smallWindow, smallWindowParams); 88 | } 89 | } 90 | 91 | /** 92 | * 将小悬浮窗从屏幕上移除。 93 | * 94 | * @param context 95 | * 必须为应用程序的Context. 96 | */ 97 | public static void removeSmallWindow(Context context) { 98 | if (smallWindow != null) { 99 | WindowManager windowManager = getWindowManager(context); 100 | windowManager.removeView(smallWindow); 101 | smallWindow = null; 102 | } 103 | } 104 | 105 | /** 106 | * 创建一个大悬浮窗。位置为屏幕正中间。 107 | * 108 | * @param context 109 | * 必须为应用程序的Context. 110 | */ 111 | public static void createBigWindow(Context context) { 112 | WindowManager windowManager = getWindowManager(context); 113 | int screenWidth = windowManager.getDefaultDisplay().getWidth(); 114 | int screenHeight = windowManager.getDefaultDisplay().getHeight(); 115 | if (bigWindow == null) { 116 | bigWindow = new FloatWindowBigView(context); 117 | if (bigWindowParams == null) { 118 | bigWindowParams = new LayoutParams(); 119 | bigWindowParams.x = screenWidth / 2 - FloatWindowBigView.viewWidth / 2; 120 | bigWindowParams.y = screenHeight / 2 - FloatWindowBigView.viewHeight / 2; 121 | bigWindowParams.type = LayoutParams.TYPE_PHONE; 122 | bigWindowParams.format = PixelFormat.RGBA_8888; 123 | bigWindowParams.gravity = Gravity.LEFT | Gravity.TOP; 124 | bigWindowParams.width = FloatWindowBigView.viewWidth; 125 | bigWindowParams.height = FloatWindowBigView.viewHeight; 126 | } 127 | windowManager.addView(bigWindow, bigWindowParams); 128 | } 129 | } 130 | 131 | /** 132 | * 将大悬浮窗从屏幕上移除。 133 | * 134 | * @param context 135 | * 必须为应用程序的Context. 136 | */ 137 | public static void removeBigWindow(Context context) { 138 | if (bigWindow != null) { 139 | WindowManager windowManager = getWindowManager(context); 140 | windowManager.removeView(bigWindow); 141 | bigWindow = null; 142 | } 143 | } 144 | 145 | /** 146 | * 创建一个添加悬浮窗,位置位于屏幕正中间。 147 | * @param context 148 | * 必须为应用程序的Context. 149 | */ 150 | public static void createAddWindow(Context context) { 151 | WindowManager windowManager = getWindowManager(context); 152 | int screenWidth = windowManager.getDefaultDisplay().getWidth(); 153 | int screenHeight = windowManager.getDefaultDisplay().getHeight(); 154 | if (addWindow == null) { 155 | addWindow = new FloatWindowAddView(context); 156 | if (addWindowParams == null) { 157 | addWindowParams = new LayoutParams(); 158 | addWindowParams.x = screenWidth / 2 - FloatWindowBigView.viewWidth / 2; 159 | addWindowParams.y = screenHeight / 2 - FloatWindowAddView.viewHeight / 2; 160 | addWindowParams.type = LayoutParams.TYPE_PHONE; 161 | addWindowParams.format = PixelFormat.RGBA_8888; 162 | addWindowParams.gravity = Gravity.LEFT | Gravity.TOP; 163 | addWindowParams.width = FloatWindowAddView.viewWidth; 164 | addWindowParams.height = FloatWindowAddView.viewHeight; 165 | addWindowParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL 166 | | LayoutParams.FLAG_NOT_FOCUSABLE; 167 | } 168 | addWindow.setParams(addWindowParams); 169 | windowManager.addView(addWindow, addWindowParams); 170 | } 171 | } 172 | 173 | /** 174 | * 将添加悬浮窗从屏幕上移除。 175 | * 176 | * @param context 177 | * 必须为应用程序的Context. 178 | */ 179 | 180 | public static void removeAddWindow(Context context) { 181 | if (addWindow !=null) { 182 | WindowManager windowManager = getWindowManager(context); 183 | windowManager.removeView(addWindow); 184 | addWindow = null; 185 | } 186 | } 187 | 188 | /** 189 | * 更新小悬浮窗的TextView上的数据,显示内存使用的百分比。 190 | * 191 | * @param context 192 | * 可传入应用程序上下文。 193 | */ 194 | public static void updateUsedPercent(Context context) { 195 | // if (smallWindow != null) { 196 | // TextView percentView = (TextView) smallWindow.findViewById(R.id.percent); 197 | // percentView.setText(getUsedPercentValue(context)); 198 | // } 199 | } 200 | 201 | /** 202 | * 是否有悬浮窗(包括小悬浮窗和大悬浮窗)显示在屏幕上。 203 | * 204 | * @return 有悬浮窗显示在桌面上返回true,没有的话返回false。 205 | */ 206 | public static boolean isWindowShowing() { 207 | return smallWindow != null || bigWindow != null || addWindow != null; 208 | } 209 | 210 | /** 211 | * 如果WindowManager还未创建,则创建一个新的WindowManager返回。否则返回当前已创建的WindowManager。 212 | * 213 | * @param context 214 | * 必须为应用程序的Context. 215 | * @return WindowManager的实例,用于控制在屏幕上添加或移除悬浮窗。 216 | */ 217 | private static WindowManager getWindowManager(Context context) { 218 | if (mWindowManager == null) { 219 | mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 220 | } 221 | return mWindowManager; 222 | } 223 | 224 | /** 225 | * 如果ActivityManager还未创建,则创建一个新的ActivityManager返回。否则返回当前已创建的ActivityManager。 226 | * 227 | * @param context 228 | * 可传入应用程序上下文。 229 | * @return ActivityManager的实例,用于获取手机可用内存。 230 | */ 231 | private static ActivityManager getActivityManager(Context context) { 232 | if (mActivityManager == null) { 233 | mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 234 | } 235 | return mActivityManager; 236 | } 237 | 238 | /** 239 | * 计算已使用内存的百分比,并返回。 240 | * 241 | * @param context 242 | * 可传入应用程序上下文。 243 | * @return 已使用内存的百分比,以字符串形式返回。 244 | */ 245 | public static String getUsedPercentValue(Context context) { 246 | String dir = "/proc/meminfo"; 247 | try { 248 | FileReader fr = new FileReader(dir); 249 | BufferedReader br = new BufferedReader(fr, 2048); 250 | String memoryLine = br.readLine(); 251 | String subMemoryLine = memoryLine.substring(memoryLine.indexOf("MemTotal:")); 252 | br.close(); 253 | long totalMemorySize = Integer.parseInt(subMemoryLine.replaceAll("\\D+", "")); 254 | long availableSize = getAvailableMemory(context) / 1024; 255 | int percent = (int) ((totalMemorySize - availableSize) / (float) totalMemorySize * 100); 256 | return percent + "%"; 257 | } catch (IOException e) { 258 | e.printStackTrace(); 259 | } 260 | return "悬浮窗"; 261 | } 262 | 263 | /** 264 | * 获取当前可用内存,返回数据以字节为单位。 265 | * 266 | * @param context 267 | * 可传入应用程序上下文。 268 | * @return 当前可用内存。 269 | */ 270 | private static long getAvailableMemory(Context context) { 271 | ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); 272 | getActivityManager(context).getMemoryInfo(mi); 273 | return mi.availMem; 274 | } 275 | 276 | /** 277 | * 设置addFloatViewState的状态 278 | */ 279 | public static void setAddState(boolean use) { 280 | addFloatViewState = use; 281 | } 282 | 283 | /** 284 | * 获取addFloatViewState的状态 285 | */ 286 | public static boolean getAddState() { 287 | return addFloatViewState; 288 | } 289 | 290 | } 291 | --------------------------------------------------------------------------------