Skip to content

Commit

Permalink
v1.3 兼容MIUI
Browse files Browse the repository at this point in the history
  • Loading branch information
woxingxiao committed Dec 7, 2016
1 parent 5ccf3e9 commit 9a5165a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions bubbleseekbar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 3
versionName "1.2"
versionCode 4
versionName "1.3"
}

buildTypes {
Expand Down
43 changes: 40 additions & 3 deletions bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.os.Parcelable;
import android.support.annotation.IntDef;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
Expand All @@ -30,12 +31,15 @@

import com.xw.repo.bubbleseekbar.R;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.math.BigDecimal;

import static com.xw.repo.BubbleSeekBar.TextPosition.SIDES;
import static com.xw.repo.BubbleSeekBar.TextPosition.BOTTOM;
import static com.xw.repo.BubbleSeekBar.TextPosition.SIDES;

/**
* 气泡形式可视化的自定义SeekBar
Expand Down Expand Up @@ -272,7 +276,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
*/
mBubbleCenterRawSolidX = points[0] + mLeft - mBubbleView.getMeasuredWidth() / 2f;
mBubbleCenterRawX = mBubbleCenterRawSolidX + mTrackLength * (mProgress - mMin) / mDelta;
mBubbleCenterRawSolidY = points[1] - mBubbleView.getMeasuredHeight() - dp2px(24);
mBubbleCenterRawSolidY = points[1] - mBubbleView.getMeasuredHeight();
if (!isFxxkingMIUI()) {
mBubbleCenterRawSolidY -= dp2px(24);
}
}

@Override
Expand Down Expand Up @@ -469,7 +476,11 @@ private void showBubble() {
mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
mLayoutParams.type = WindowManager.LayoutParams.TYPE_TOAST;
if (isFxxkingMIUI()) { // MIUI禁止了开发者使用TYPE_TOAST
mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
} else {
mLayoutParams.type = WindowManager.LayoutParams.TYPE_TOAST;
}
}
mLayoutParams.x = (int) mBubbleCenterRawX;
mLayoutParams.y = (int) mBubbleCenterRawSolidY;
Expand All @@ -486,6 +497,32 @@ public void onAnimationStart(Animator animation) {
}).start();
}

/**
* 判断是否MIUI
*/
private boolean isFxxkingMIUI() {
String line;
BufferedReader input = null;
try {
Process p = Runtime.getRuntime().exec("getprop " + "ro.miui.ui.version.name");
input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
line = input.readLine();
input.close();
} catch (IOException ex) {
return false;
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

return !TextUtils.isEmpty(line);
}

/**
* 自动滚向最近的分段处
*/
Expand Down

0 comments on commit 9a5165a

Please sign in to comment.