Skip to content

Commit

Permalink
2018.1.30
Browse files Browse the repository at this point in the history
multi-language 
softkeyboard detection
intent to add setting widget of softkeyboard detection
  • Loading branch information
etet2007 committed Jan 30, 2018
1 parent 8562e12 commit 6888b35
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.chenyee.stephenlau.floatingball;

import android.accessibilityservice.AccessibilityService;
import android.animation.Animator;
import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
Expand Down Expand Up @@ -34,8 +33,8 @@

public class BallView extends View {
public static final String TAG="lqt";
private final int gestureMoveDistance = 18;

private final int ballMoveDistance = 18;
private Paint mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Paint mBallPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private boolean isFirstEvent=false;
Expand Down Expand Up @@ -87,6 +86,13 @@ public enum GESTURE_STATE {
private float mLastTouchEventX;
private float mOffsetToParentY;
private WindowManager.LayoutParams mLayoutParams;
private int mLayoutParamsY;
private int getMLayoutParamsY(){
return mLayoutParams.y;
}
private void setMLayoutParamsY(int y){
mLayoutParams.y=y;
}

private GESTURE_STATE lastGestureSTATE = GESTURE_STATE.NONE;

Expand Down Expand Up @@ -327,7 +333,37 @@ public void performRemoveAnimator() {
.start();
}

@Override

public void performUpAnimator(int moveUpDistance) {
ObjectAnimator animation = ObjectAnimator.ofInt (this, "mLayoutParamsY", getMLayoutParamsY(), getMLayoutParamsY()- moveUpDistance); // see this max value coming back here, we animale towards that value
animation.setDuration (200); //in milliseconds
animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mWindowManager.updateViewLayout(BallView.this, mLayoutParams);

}
});
animation.start();
// mLayoutParams.y = mLayoutParams.y-120;
// mWindowManager.updateViewLayout(BallView.this, mLayoutParams);
}


public void performDownAnimator(int moveUpDistance) {
ObjectAnimator animation = ObjectAnimator.ofInt (this, "mLayoutParamsY", getMLayoutParamsY(), getMLayoutParamsY()+moveUpDistance); // see this max value coming back here, we animale towards that value
animation.setDuration (200); //in milliseconds
animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mWindowManager.updateViewLayout(BallView.this, mLayoutParams);
}
});
animation.start();
// mLayoutParams.y = mLayoutParams.y+120;
// mWindowManager.updateViewLayout(BallView.this, mLayoutParams);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

Expand Down Expand Up @@ -473,18 +509,18 @@ private void moveFloatBall() {
switch (currentGestureSTATE){
case UP:
ballCenterX=0;
ballCenterY=-ballMoveDistance;
ballCenterY=-gestureMoveDistance;
break;
case DOWN:
ballCenterY= ballMoveDistance;
ballCenterY= gestureMoveDistance;
ballCenterX=0;
break;
case LEFT:
ballCenterX=-ballMoveDistance;
ballCenterX=-gestureMoveDistance;
ballCenterY=0;
break;
case RIGHT:
ballCenterX= ballMoveDistance;
ballCenterX= gestureMoveDistance;
ballCenterY=0;
break;
case NONE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static FloatBallManager getInstance() {
private boolean isOpenBall;
private boolean useBackground;

int moveUpDistance=130;
//创建BallView
public void addBallView(Context context) {
if (mBallView == null) {
Expand Down Expand Up @@ -141,7 +142,7 @@ public void saveFloatBallData(){
}

SharedPreferences.Editor editor = defaultSharedPreferences.edit();
editor.putBoolean(KEY_HAS_Added_Ball,isOpenBall);
editor.putBoolean(KEY_HAS_ADDED_BALL,isOpenBall);

LayoutParams params = mBallView.getLayoutParams();
editor.putInt(KEY_PARAM_X,params.x);
Expand Down Expand Up @@ -175,5 +176,17 @@ public void updateBallViewData() {
mBallView.invalidate();
}
}

public void moveBallViewUp() {
if(mBallView!=null){
mBallView.performUpAnimator(130);
}
}

public void moveBallViewDown() {
if(mBallView!=null){
mBallView.performDownAnimator(130);
}
}
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.chenyee.stephenlau.floatingball;

import android.accessibilityservice.AccessibilityService;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.inputmethod.InputMethodManager;

import java.lang.reflect.Method;
import java.util.List;


/**
Expand All @@ -29,6 +36,7 @@ public class FloatBallService extends AccessibilityService {

private FloatBallManager mFloatBallManager;

private boolean hasSoftKeyboardShow=false;
@Override
protected void onServiceConnected() {
super.onServiceConnected();
Expand All @@ -42,38 +50,61 @@ protected void onServiceConnected() {
public void onAccessibilityEvent(AccessibilityEvent event) {
// Log.d(TAG, "onAccessibilityEvent "+event);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {

if(event.getEventType()==AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED){
// if (event.getPackageName().toString().contains("om.sohu.inputmethod.sogou")) {
inputMethodSate(getApplicationContext());
}

// }
/**
* 软键盘状态判断
* @param context
*/
public void inputMethodSate(Context context) {
//得到默认输入法包名
String defaultInputName = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
defaultInputName = defaultInputName.substring(0, defaultInputName.indexOf("/"));
boolean isInputing = false;
if(android.os.Build.VERSION.SDK_INT > 20) {
try{
InputMethodManager imm = (InputMethodManager) context.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Class clazz = imm.getClass();
Method method = clazz.getMethod("getInputMethodWindowVisibleHeight", null);
method.setAccessible(true);
int height = (Integer) method.invoke(imm, null);
Log.d("LOG", "height == "+height);
if(height > 100) {
isInputing = true;
}
}catch(Exception e) {
e.printStackTrace();
}
}else {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();

for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
if(appProcess.processName.equals(defaultInputName)) {
isInputing = true;
break;
}
}
}
}
//Not work
// InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//
// if (imm.isAcceptingText()) {
// Log.d(TAG, "Software Keyboard was shown");
// } else {
// Log.d(TAG, "Software Keyboard was not shown");
// }


SoftKeyboardController softKeyboardController= null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
softKeyboardController = getSoftKeyboardController();
int showMode =softKeyboardController.getShowMode();
Log.d(TAG, "ShowMode" + showMode);
// softKeyboardController.setShowMode(SHOW_MODE_AUTO);
// Log.d(TAG, "ShowMode" + showMode);

}
if(isInputing) {
Log.d(TAG, "软键盘显示中");
if (!hasSoftKeyboardShow)
mFloatBallManager.moveBallViewUp();
hasSoftKeyboardShow=true;
}else {
Log.d(TAG, "软键盘隐藏中");
if(hasSoftKeyboardShow)
mFloatBallManager.moveBallViewDown();
hasSoftKeyboardShow=false;

}
}



@Override
public void onInterrupt() {
Log.d(TAG, "onInterrupt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.CardView;
import android.support.v7.widget.SwitchCompat;
import android.util.Log;
import android.view.View;
Expand Down Expand Up @@ -198,7 +197,7 @@ private void initContentViews() {

//获取悬浮球参数
prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean hasAddedBall = prefs.getBoolean(KEY_HAS_Added_Ball, false);
boolean hasAddedBall = prefs.getBoolean(KEY_HAS_ADDED_BALL, false);
Log.d(TAG, "hasAddedBall: "+hasAddedBall);
int opacity = prefs.getInt(KEY_OPACITY, 125);
int ballSize = prefs.getInt(KEY_SIZE, 25);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class SharedPreferencesUtil {
public static final String KEY_OPACITY = "opacity";
public static final String KEY_SIZE = "size";
public static final String KEY_USE_BACKGROUND = "useBackground";
public static final String KEY_HAS_Added_Ball = "hasAddedBall";
public static final String KEY_HAS_ADDED_BALL = "hasAddedBall";
public static final String KEY_PARAM_X ="paramsX";
public static final String KEY_PARAM_Y ="paramsY";
public static final String KEY_MOVE_UP_DISTANCE ="moveUpDistance";
}
4 changes: 3 additions & 1 deletion app/src/main/res/layout/activity_material_up_concept.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:text="Start: "
android:text="@string/on_off"
/>

<android.support.v7.widget.SwitchCompat
android:id="@+id/start_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Base.Theme.AppCompat.Light"
/>
</LinearLayout>
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/list_item_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Opacity"
android:text="@string/opacity"
android:layout_marginBottom="20dp"
/>
<org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
Expand All @@ -48,7 +48,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Size"
android:text="@string/size"
android:layout_marginBottom="20dp"
/>
<org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
Expand Down Expand Up @@ -88,7 +88,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Use background picture?"
android:text="@string/use_background_picture"
android:layout_marginBottom="10dp"
/>
<android.support.v7.widget.SwitchCompat
Expand All @@ -100,7 +100,7 @@
android:id="@+id/choosePic_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose picture"
android:text="@string/choose_picture"
android:layout_marginTop="20dp"
/>
</android.support.v7.widget.LinearLayoutCompat>
Expand All @@ -117,12 +117,12 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_margin="10dp">

</android.support.v7.widget.LinearLayoutCompat>

</android.support.v7.widget.CardView>
</android.support.v7.widget.LinearLayoutCompat>

Expand Down
16 changes: 8 additions & 8 deletions app/src/main/res/menu/activity_main_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">

<group android:checkableBehavior="single">
<!--<group android:checkableBehavior="single">-->
<!--<item-->
<!--android:id="@+id/nav_camera"-->
<!--android:icon="@drawable/ic_menu_camera"-->
Expand All @@ -16,18 +16,18 @@
<!--android:id="@+id/nav_slideshow"-->
<!--android:icon="@drawable/ic_menu_slideshow"-->
<!--android:title="Slideshow"/>-->
<item
android:id="@+id/nav_manage"
android:icon="@drawable/ic_menu_manage"
android:title="Tools"/>
</group>
<!--<item-->
<!--android:id="@+id/nav_manage"-->
<!--android:icon="@drawable/ic_menu_manage"-->
<!--android:title="Tools"/>-->
<!--</group>-->

<item android:title="Communicate">
<item android:title="@string/communicate">
<menu>
<item
android:id="@+id/nav_share"
android:icon="@drawable/ic_menu_share"
android:title="Share"/>
android:title="@string/share"/>

</menu>
</item>
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">悬浮球</string>

<string name="navigation_drawer_open">打开导航抽屉</string>
<string name="navigation_drawer_close">关闭导航抽屉</string>


<string name="accessibility">开启悬浮球辅助功能</string>
<string name="on_off">开/关:</string>
<string name="opacity">透明度</string>
<string name="size">大小</string>
<string name="use_background_picture">是否使用背景图片</string>
<string name="choose_picture">选择图片</string>
<string name="communicate">交流</string>
<string name="share">分享下载地址</string>
</resources>
Loading

0 comments on commit 6888b35

Please sign in to comment.