下面列出了怎么用android.support.v4.view.InputDeviceCompat的API类实例代码及写法,或者点击链接到github查看源代码。
private void readAttr(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.X8ValueSeakBarView);
this.accuracy = a.getInteger(R.styleable.X8ValueSeakBarView_x8_value_accuracy, 1);
this.title = a.getString(R.styleable.X8ValueSeakBarView_x8_value_title);
this.suffix = a.getString(R.styleable.X8ValueSeakBarView_x8_value_suffix);
this.closeColor = a.getColor(R.styleable.X8ValueSeakBarView_x8_value_close_color, -1);
this.openColor = a.getColor(R.styleable.X8ValueSeakBarView_x8_value_open_color, InputDeviceCompat.SOURCE_ANY);
this.seekBarMax = a.getFloat(R.styleable.X8ValueSeakBarView_x8_value_seekbar_max, 0.0f) * ((float) this.accuracy);
this.seekBarMin = a.getFloat(R.styleable.X8ValueSeakBarView_x8_value_seekbar_min, 0.0f) * ((float) this.accuracy);
this.seekBarDefault = a.getFloat(R.styleable.X8ValueSeakBarView_x8_value_seekbar_default, 0.0f);
this.isFloat = a.getBoolean(R.styleable.X8ValueSeakBarView_x8_value_seekbar_float, false);
a.recycle();
if (this.isFloat) {
this.MAX = (int) (this.seekBarMax - this.seekBarMin);
} else {
this.MAX = (int) (this.seekBarMax - this.seekBarMin);
}
}
private void readAttr(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.X8ValueSeakBarView);
this.accuracy = a.getInteger(R.styleable.X8ValueSeakBarView_x8_value_accuracy, 1);
this.title = a.getString(R.styleable.X8ValueSeakBarView_x8_value_title);
this.suffix = a.getString(R.styleable.X8ValueSeakBarView_x8_value_suffix);
this.closeColor = a.getColor(R.styleable.X8ValueSeakBarView_x8_value_close_color, -1);
this.openColor = a.getColor(R.styleable.X8ValueSeakBarView_x8_value_open_color, InputDeviceCompat.SOURCE_ANY);
this.seekBarMax = a.getFloat(R.styleable.X8ValueSeakBarView_x8_value_seekbar_max, 0.0f) * ((float) this.accuracy);
this.seekBarMin = a.getFloat(R.styleable.X8ValueSeakBarView_x8_value_seekbar_min, 0.0f) * ((float) this.accuracy);
this.seekBarDefault = a.getFloat(R.styleable.X8ValueSeakBarView_x8_value_seekbar_default, 0.0f);
this.isFloat = a.getBoolean(R.styleable.X8ValueSeakBarView_x8_value_seekbar_float, false);
a.recycle();
if (this.isFloat) {
this.MAX = (int) (this.seekBarMax - this.seekBarMin);
} else {
this.MAX = (int) (this.seekBarMax - this.seekBarMin);
}
}
public static byte decodeBinaryString(String byteStr) {
if (byteStr == null) {
return (byte) 0;
}
int len = byteStr.length();
if (len != 4 && len != 8) {
return (byte) 0;
}
int re;
if (len != 8) {
re = Integer.parseInt(byteStr, 2);
} else if (byteStr.charAt(0) == '0') {
re = Integer.parseInt(byteStr, 2);
} else {
re = Integer.parseInt(byteStr, 2) + InputDeviceCompat.SOURCE_ANY;
}
return (byte) re;
}
static MotionEvent create(int action, long downTime, int x, int y) {
MotionEvent event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), action, x, y,
1.0f,1.0f, 0, 1.0f, 1.0f, 0,
0);
event.setSource(InputDeviceCompat.SOURCE_TOUCHSCREEN);
return event;
}
public final void validateRequestPermissionsRequestCode(int requestCode) {
if (this.mRequestedPermissionsFromFragment) {
this.mRequestedPermissionsFromFragment = false;
} else if ((requestCode & InputDeviceCompat.SOURCE_ANY) != 0) {
throw new IllegalArgumentException("Can only use lower 8 bits for requestCode");
}
}
private void requestPermissionsFromFragment(Fragment fragment, String[] permissions, int requestCode) {
if (requestCode == -1) {
ActivityCompat.requestPermissions(this, permissions, requestCode);
} else if ((requestCode & InputDeviceCompat.SOURCE_ANY) != 0) {
throw new IllegalArgumentException("Can only use lower 8 bits for requestCode");
} else {
this.mRequestedPermissionsFromFragment = true;
ActivityCompat.requestPermissions(this, permissions, ((fragment.mIndex + 1) << 8) + (requestCode & 255));
}
}
public boolean onGenericMotionEvent(MotionEvent event) {
if ((MotionEventCompat.getSource(event) & InputDeviceCompat.SOURCE_CLASS_POINTER) != 0) {
switch (event.getAction()) {
case MotionEventCompat.ACTION_SCROLL: {
if (!mIsBeingDragged) {
final float vscroll = MotionEventCompat.getAxisValue(event,
MotionEventCompat.AXIS_VSCROLL);
if (vscroll != 0) {
final int delta = (int) (vscroll * getVerticalScrollFactorCompat());
final int range = getScrollRange();
int oldScrollY = getScrollY();
int newScrollY = oldScrollY - delta;
if (newScrollY < 0) {
newScrollY = 0;
} else if (newScrollY > range) {
newScrollY = range;
}
if (newScrollY != oldScrollY) {
super.scrollTo(getScrollX(), newScrollY);
return true;
}
}
}
}
}
}
return false;
}