This commit is contained in:
mao
2019-12-19 00:34:14 +08:00
parent 3d2756f376
commit 82730d9e08

View File

@@ -893,9 +893,7 @@ public final class TerminalView extends View {
android.R.attr.textSelectHandleWindowStyle); android.R.attr.textSelectHandleWindowStyle);
mContainer.setSplitTouchEnabled(true); mContainer.setSplitTouchEnabled(true);
mContainer.setClippingEnabled(false); mContainer.setClippingEnabled(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mContainer.setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL);
mContainer.setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL);
}
mContainer.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); mContainer.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
mContainer.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); mContainer.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
@@ -910,14 +908,8 @@ public final class TerminalView extends View {
case LEFT: { case LEFT: {
if (mSelectHandleLeft == null) { if (mSelectHandleLeft == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mSelectHandleLeft = getContext().getDrawable( mSelectHandleLeft = getContext().getDrawable(
R.drawable.text_select_handle_left_material); R.drawable.text_select_handle_left_material);
} else {
mSelectHandleLeft = getContext().getResources().getDrawable(
R.drawable.text_select_handle_left_material);
}
} }
// //
mDrawable = mSelectHandleLeft; mDrawable = mSelectHandleLeft;
@@ -928,13 +920,8 @@ public final class TerminalView extends View {
case RIGHT: { case RIGHT: {
if (mSelectHandleRight == null) { if (mSelectHandleRight == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mSelectHandleRight = getContext().getDrawable( mSelectHandleRight = getContext().getDrawable(
R.drawable.text_select_handle_right_material); R.drawable.text_select_handle_right_material);
} else {
mSelectHandleRight = getContext().getResources().getDrawable(
R.drawable.text_select_handle_right_material);
}
} }
mDrawable = mSelectHandleRight; mDrawable = mSelectHandleRight;
handleWidth = mDrawable.getIntrinsicWidth(); handleWidth = mDrawable.getIntrinsicWidth();
@@ -1228,48 +1215,45 @@ public final class TerminalView extends View {
} }
}; };
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mActionMode = startActionMode(new ActionMode.Callback2() {
mActionMode = startActionMode(new ActionMode.Callback2() { @Override
@Override public boolean onCreateActionMode(ActionMode mode, Menu menu) {
public boolean onCreateActionMode(ActionMode mode, Menu menu) { return callback.onCreateActionMode(mode, menu);
return callback.onCreateActionMode(mode, menu); }
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return callback.onActionItemClicked(mode, item);
}
@Override
public void onDestroyActionMode(ActionMode mode) {
// Ignore.
}
@Override
public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
int x1 = Math.round(mSelX1 * mRenderer.mFontWidth);
int x2 = Math.round(mSelX2 * mRenderer.mFontWidth);
int y1 = Math.round((mSelY1 - mTopRow) * mRenderer.mFontLineSpacing);
int y2 = Math.round((mSelY2 + 1 - mTopRow) * mRenderer.mFontLineSpacing);
if (x1 > x2) {
int tmp = x1;
x1 = x2;
x2 = tmp;
} }
@Override outRect.set(x1, y1 + mHandleHeight, x2, y2 + mHandleHeight);
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { }
return false; }, ActionMode.TYPE_FLOATING);
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return callback.onActionItemClicked(mode, item);
}
@Override
public void onDestroyActionMode(ActionMode mode) {
// Ignore.
}
@Override
public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
int x1 = Math.round(mSelX1 * mRenderer.mFontWidth);
int x2 = Math.round(mSelX2 * mRenderer.mFontWidth);
int y1 = Math.round((mSelY1 - mTopRow) * mRenderer.mFontLineSpacing);
int y2 = Math.round((mSelY2 + 1 - mTopRow) * mRenderer.mFontLineSpacing);
if (x1 > x2) {
int tmp = x1;
x1 = x2;
x2 = tmp;
}
outRect.set(x1, y1 + mHandleHeight, x2, y2 + mHandleHeight);
}
}, ActionMode.TYPE_FLOATING);
} else {
mActionMode = startActionMode(callback);
}
} }
public void hide() { public void hide() {
@@ -1500,9 +1484,7 @@ public final class TerminalView extends View {
@Override @Override
public void run() { public void run() {
if (mActionMode != null) { if (mActionMode != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mActionMode.hide(0); // hide off.
mActionMode.hide(0); // hide off.
}
} }
} }
}; };
@@ -1510,9 +1492,7 @@ public final class TerminalView extends View {
void hideFloatingToolbar(int duration) { void hideFloatingToolbar(int duration) {
if (mActionMode != null) { if (mActionMode != null) {
removeCallbacks(mShowFloatingToolbar); removeCallbacks(mShowFloatingToolbar);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mActionMode.hide(duration);
mActionMode.hide(duration);
}
} }
} }