android:update snapshot control api

This commit is contained in:
pengfei.zhou 2021-07-13 17:24:48 +08:00 committed by osborn
parent 227cc09824
commit cf116dbb31
5 changed files with 84 additions and 35 deletions

View File

@ -7,7 +7,7 @@
<uses-permission android:name="android.permission.BLUETOOTH" />
<application>
<activity android:name=".ui.DoricDevActivity" />
<activity android:name=".ui.DoricDevActivity" android:exported="true"/>
<activity android:name=".qrcode.activity.CaptureActivity" />
</application>
</manifest>

View File

@ -0,0 +1,63 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pub.doric.devkit.ui;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.MotionEvent;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
/**
* @Description: pub.doric.devkit.ui
* @Author: pengfei.zhou
* @CreateDate: 2021/7/13
*/
public class DoricFloatingView extends FrameLayout {
private int lastX;
private int lastY;
public DoricFloatingView(@NonNull Context context) {
super(context);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
lastX = x;
lastY = y;
break;
case MotionEvent.ACTION_MOVE:
int offsetX = x - lastX;
int offsetY = y - lastY;
FrameLayout.LayoutParams layoutParams = (LayoutParams) getLayoutParams();
layoutParams.leftMargin += offsetX;
layoutParams.topMargin += offsetY;
requestLayout();
break;
default:
break;
}
return true;
}
}

View File

@ -21,10 +21,8 @@ import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
@ -50,10 +48,7 @@ import pub.doric.utils.ThreadMode;
* @CreateDate: 2021/7/9
*/
@SuppressLint("ViewConstructor")
public class DoricSnapshotView extends FrameLayout {
private int lastX;
private int lastY;
public class DoricSnapshotView extends DoricFloatingView {
private final DoricContext doricContext;
private int snapNo = -1;
private int snapSize = 0;
@ -65,7 +60,7 @@ public class DoricSnapshotView extends FrameLayout {
super(context);
this.doricContext = doricContext;
initView(context);
this.setAlpha(0.5f);
this.setAlpha(0.8f);
}
private void initView(Context context) {
@ -131,31 +126,9 @@ public class DoricSnapshotView extends FrameLayout {
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
lastX = x;
lastY = y;
break;
case MotionEvent.ACTION_MOVE:
int offsetX = x - lastX;
int offsetY = y - lastY;
layout(getLeft() + offsetX, getTop() + offsetY, getRight() + offsetX, getBottom() + offsetY);
break;
default:
break;
}
return true;
}
private void rollupSnapshot(int index) {
spanPre.setVisibility(index <= 0 ? View.INVISIBLE : View.VISIBLE);
spanNext.setVisibility(index >= snapSize ? View.INVISIBLE : View.VISIBLE);
spanPre.setImageAlpha(index <= 0 ? 0x7f : 0xff);
spanNext.setImageAlpha(index >= snapSize ? 0x7f : 0xff);
snapIndex.setText(String.valueOf(index));
doricContext.callEntity("__restoreRenderSnapshot__", index).setCallback(new AsyncResult.Callback<JSDecoder>() {
@Override

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

@ -5,18 +5,29 @@
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="255dp"
android:layout_height="70dp"
android:layout_marginTop="5dp"
android:background="#ecf0f1"
android:gravity="center"
android:orientation="horizontal"
android:padding="15dp">
android:paddingLeft="0dp"
android:paddingTop="15dp"
android:paddingRight="5dp"
android:paddingBottom="15dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="5dp"
android:scaleType="fitXY"
android:src="@drawable/icon_doricdev_move" />
<ImageView
android:id="@+id/snap_pre"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="fitXY"
android:src="@drawable/icon_doricdev_prev" />
<TextView
@ -34,6 +45,7 @@
android:id="@+id/snap_next"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="fitXY"
android:src="@drawable/icon_doricdev_next" />
<ImageView
@ -41,6 +53,7 @@
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:scaleType="fitXY"
android:src="@drawable/icon_doricdev_close" />
</LinearLayout>