Commit c2ad23a7 by wjg

add update

parent 3bf27115
package com.ihaoin.hooloo.device.kds.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.Utils;
import java.util.List;
public class ImagePagerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private List<String> images;
private LayoutInflater inflater;
public ImagePagerAdapter(Context context, List<String> images) {
this.context = context;
this.images = images;
inflater = LayoutInflater.from(context);
}
public void setImages(List<String> images) {
this.images = images;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new BaseViewHolder(inflater.inflate(R.layout.kds_img, parent, false));
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder h, int position) {
BaseViewHolder holder = (BaseViewHolder) h;
String url = images.get(position % images.size());
Utils.getGlide(context).load(url).into(holder.image);
}
@Override
public int getItemCount() {
if (CollectionUtils.isEmpty(images)) {
return 0;
}
return Integer.MAX_VALUE;
}
protected static class BaseViewHolder extends RecyclerView.ViewHolder {
public ImageView image;
public BaseViewHolder(View itemView) {
super(itemView);
image = itemView.findViewById(R.id.image);
}
}
}
......@@ -85,6 +85,9 @@ public class MachineStateAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
@Override
public int getItemCount() {
if (msg == null) {
return 0;
}
return Integer.MAX_VALUE;
}
......
......@@ -14,8 +14,6 @@ import android.os.Message;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
......@@ -24,32 +22,30 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.base.Base;
import com.ihaoin.hooloo.device.component.FixedSpeedScroller;
import com.ihaoin.hooloo.device.component.IntroViewPager;
import com.ihaoin.hooloo.device.data.MainData;
import com.ihaoin.hooloo.device.data.vo.KDSMsg;
import com.ihaoin.hooloo.device.data.vo.KDSOrder;
import com.ihaoin.hooloo.device.kds.KDSSocket;
import com.ihaoin.hooloo.device.kds.adapter.ImagePagerAdapter;
import com.ihaoin.hooloo.device.kds.adapter.MachineStateAdapter;
import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.StringUtils;
import com.ihaoin.hooloo.device.util.Utils;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class KdsPresentation extends Presentation {
private KDSMsg mKdsMsg;
private IntroViewPager imagePager;
private LinearLayoutManager layoutManager;
private RecyclerView recyclerImagePager;
private ImagePagerAdapter imagePagerAdapter;
private RecyclerView recyclerMachineState;
private MachineStateAdapter machineStateAdapter;
......@@ -79,28 +75,17 @@ public class KdsPresentation extends Presentation {
private void initViews() {
imgAvatar = findViewById(R.id.img_avatar);
imagePager = findViewById(R.id.image_pager);
recyclerImagePager = findViewById(R.id.image_pager);
recyclerMachineState = findViewById(R.id.rec_machine_state);
layoutManager = new LinearLayoutManager(getContext()) {
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
LinearSmoothScroller smoothScroller =
new LinearSmoothScroller(recyclerView.getContext()) {
// 返回:滑过1px时经历的时间(ms)。
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return 10;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
};
imageLayoutManager.setOrientation(RecyclerView.HORIZONTAL);
imagePagerAdapter = new ImagePagerAdapter(getContext(), null);
recyclerImagePager.setAdapter(imagePagerAdapter);
recyclerImagePager.setLayoutManager(imageLayoutManager);
machineStateAdapter = new MachineStateAdapter(getContext(), null);
recyclerMachineState = findViewById(R.id.rec_machine_state);
recyclerMachineState.setAdapter(machineStateAdapter);
recyclerMachineState.setLayoutManager(layoutManager);
recyclerMachineState.setLayoutManager(stateLayoutManager);
progressViews.add(findViewById(R.id.progress1));
progressViews.add(findViewById(R.id.progress2));
......@@ -125,40 +110,48 @@ public class KdsPresentation extends Presentation {
AnimationDrawable anim = (AnimationDrawable) getContext().getDrawable(R.drawable.menu_avatar);
imgAvatar.setBackground(anim);
anim.start();
}
try {
Field field = ViewPager.class.getDeclaredField("mScroller");
field.setAccessible(true);
FixedSpeedScroller scroller = new FixedSpeedScroller(imagePager.getContext(), new LinearInterpolator());
field.set(imagePager, scroller);
scroller.setmDuration(500);
} catch (Exception e) {
e.printStackTrace();
LinearLayoutManager stateLayoutManager = new LinearLayoutManager(getContext()) {
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
// 返回:滑过1px时经历的时间(ms)。
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return 10;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
};
LinearLayoutManager imageLayoutManager = new LinearLayoutManager(getContext()) {
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
// 返回:滑过1px时经历的时间(ms)。
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return 0.3f;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
};
private void showImages() {
MainData mainData = HLApplication.getMainData();
if (mainData == null || mainData.getImages() == null) {
return;
}
imagePager.removeAllViews();
recyclerImagePager.removeAllViews();
if (CollectionUtils.isEmpty(mainData.getImages().getLeft())) {
return;
}
List<View> introViews = new ArrayList<>();
mainData.getImages().getLeft().stream().filter(x -> !StringUtils.isEmpty(x)).forEach(url -> introViews.add(getLeftImage(url)));
imagePager.setIntroViews(introViews);
}
private ImageView getLeftImage(String url) {
ImageView image = new ImageView(getContext());
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
image.setLayoutParams(layoutParams);
image.setAdjustViewBounds(true);
image.setScaleType(ImageView.ScaleType.CENTER_CROP);
Utils.getGlide(getContext()).load(url).into(image);
return image;
imagePagerAdapter.setImages(mainData.getImages().getLeft().stream().filter(x -> !StringUtils.isEmpty(x)).collect(Collectors.toList()));
}
private void startSocket() {
......@@ -207,25 +200,17 @@ public class KdsPresentation extends Presentation {
}
}
private Integer position = 3;
private void smoothMachineState() {
position++;
recyclerMachineState.smoothScrollToPosition(position);
}
private Integer imagePosition = 0;
private Integer statePosition = 3;
private void setNextImage() {
int count = imagePager.getCount();
if (count <= 1) {
return;
imagePosition++;
recyclerImagePager.smoothScrollToPosition(imagePosition);
}
int index = imagePager.getCurrentItem();
if (index + 1 >= count) {
index = 0;
} else {
index++;
}
imagePager.setCurrentItem(index, true);
private void smoothMachineState() {
statePosition++;
recyclerMachineState.smoothScrollToPosition(statePosition);
}
public void mainDataChanged() {
......
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
\ No newline at end of file
......@@ -6,18 +6,23 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.ihaoin.hooloo.device.component.IntroViewPager
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/image_pager"
android:layout_width="@dimen/menu_left"
android:layout_height="match_parent" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.73125"
android:descendantFocusability="afterDescendants"
android:orientation="horizontal"
android:overScrollMode="never" />
<LinearLayout
android:layout_width="@dimen/menu_right"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.26875"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/menu_right_top"
android:layout_height="0dp"
android:layout_weight="0.70185"
android:background="@color/menu_order_bg"
android:paddingStart="@dimen/menu_content_padding_hor"
android:paddingTop="@dimen/menu_content_padding_top">
......@@ -246,7 +251,8 @@
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/menu_right_bottom"
android:layout_height="0dp"
android:layout_weight="0.29815"
android:background="@color/menu_state_bg"
android:paddingLeft="@dimen/menu_state_padding_hor"
android:paddingTop="@dimen/menu_state_padding_ver"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment