Skip to content

Commit

Permalink
Make the touch area rect symmetric around the splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Oct 22, 2023
1 parent c96a2e3 commit adf173f
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions src/main/java/de/blau/android/views/SplitPaneLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,17 @@ private void extractAttributes(@NonNull Context context, @Nullable AttributeSet
}
value = a.peekValue(R.styleable.SplitPaneLayout_splitterBackground);
if (value != null) {
if (value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING) {
if (isStringOrReferenceResource(value)) {
mSplitterDrawable = a.getDrawable(R.styleable.SplitPaneLayout_splitterBackground);
} else if (value.type == TypedValue.TYPE_INT_COLOR_ARGB8 || value.type == TypedValue.TYPE_INT_COLOR_ARGB4
|| value.type == TypedValue.TYPE_INT_COLOR_RGB8 || value.type == TypedValue.TYPE_INT_COLOR_RGB4) {
} else if (isColorResource(value)) {
mSplitterDrawable = new PaintDrawable(a.getColor(R.styleable.SplitPaneLayout_splitterBackground, DEFAULT_COLOR));
}
}
value = a.peekValue(R.styleable.SplitPaneLayout_splitterDraggingBackground);
if (value != null) {
if (value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING) {
if (isStringOrReferenceResource(value)) {
mSplitterDraggingDrawable = a.getDrawable(R.styleable.SplitPaneLayout_splitterDraggingBackground);
} else if (value.type == TypedValue.TYPE_INT_COLOR_ARGB8 || value.type == TypedValue.TYPE_INT_COLOR_ARGB4
|| value.type == TypedValue.TYPE_INT_COLOR_RGB8 || value.type == TypedValue.TYPE_INT_COLOR_RGB4) {
} else if (isColorResource(value)) {
mSplitterDraggingDrawable = new PaintDrawable(a.getColor(R.styleable.SplitPaneLayout_splitterDraggingBackground, DEFAULT_DRAGGING_COLOR));
}
} else {
Expand All @@ -185,20 +183,18 @@ private void extractAttributes(@NonNull Context context, @Nullable AttributeSet

value = a.peekValue(R.styleable.SplitPaneLayout_handleBackground);
if (value != null) {
if (value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING) {
if (isStringOrReferenceResource(value)) {
mHandleDrawable = a.getDrawable(R.styleable.SplitPaneLayout_handleBackground);
} else if (value.type == TypedValue.TYPE_INT_COLOR_ARGB8 || value.type == TypedValue.TYPE_INT_COLOR_ARGB4
|| value.type == TypedValue.TYPE_INT_COLOR_RGB8 || value.type == TypedValue.TYPE_INT_COLOR_RGB4) {
} else if (isColorResource(value)) {
((ShapeDrawable) mHandleDrawable).getPaint().setColor(a.getColor(R.styleable.SplitPaneLayout_handleBackground, DEFAULT_COLOR));
((ShapeDrawable) mHandleDrawable).getPaint().setStrokeWidth(mSplitterSize);
}
}
value = a.peekValue(R.styleable.SplitPaneLayout_handleDraggingBackground);
if (value != null) {
if (value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING) {
if (isStringOrReferenceResource(value)) {
mHandleDraggingDrawable = a.getDrawable(R.styleable.SplitPaneLayout_handleDraggingBackground);
} else if (value.type == TypedValue.TYPE_INT_COLOR_ARGB8 || value.type == TypedValue.TYPE_INT_COLOR_ARGB4
|| value.type == TypedValue.TYPE_INT_COLOR_RGB8 || value.type == TypedValue.TYPE_INT_COLOR_RGB4) {
} else if (isColorResource(value)) {
((ShapeDrawable) mHandleDraggingDrawable).getPaint()
.setColor(a.getColor(R.styleable.SplitPaneLayout_handleDraggingBackground, DEFAULT_DRAGGING_COLOR));
((ShapeDrawable) mHandleDraggingDrawable).getPaint().setStrokeWidth(mSplitterSize);
Expand All @@ -207,6 +203,27 @@ private void extractAttributes(@NonNull Context context, @Nullable AttributeSet
a.recycle();
}

/**
* Check if value is a string or reference resource
*
* @param value the value
* @return true if it is a string or reference resource
*/
private boolean isStringOrReferenceResource(TypedValue value) {
return value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING;
}

/**
* Check if value is a color resource
*
* @param value the value
* @return true if it is a color resource
*/
private boolean isColorResource(@NonNull TypedValue value) {
return value.type == TypedValue.TYPE_INT_COLOR_ARGB8 || value.type == TypedValue.TYPE_INT_COLOR_ARGB4 || value.type == TypedValue.TYPE_INT_COLOR_RGB8
|| value.type == TypedValue.TYPE_INT_COLOR_RGB4;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Expand Down Expand Up @@ -264,7 +281,9 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
int cX = mSplitterRect.centerX();
int cY = mSplitterRect.centerY();
Rect handleBounds = mHandleDrawable.getBounds();
mHandleRect.set(cX, cY, cX + handleBounds.width(), cY + handleBounds.height());
final int handleW2 = handleBounds.width() / 2;
final int handleH2 = handleBounds.height() / 2;
mHandleRect.set(cX - handleW2, cY - handleH2, cX + handleW2, cY + handleH2);
}

@Override
Expand Down

0 comments on commit adf173f

Please sign in to comment.