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 ...@@ -85,6 +85,9 @@ public class MachineStateAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
@Override @Override
public int getItemCount() { public int getItemCount() {
if (msg == null) {
return 0;
}
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
......
...@@ -14,8 +14,6 @@ import android.os.Message; ...@@ -14,8 +14,6 @@ import android.os.Message;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.Display; import android.view.Display;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -24,32 +22,30 @@ import androidx.annotation.NonNull; ...@@ -24,32 +22,30 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller; import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import com.ihaoin.hooloo.device.HLApplication; import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R; import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.base.Base; 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.MainData;
import com.ihaoin.hooloo.device.data.vo.KDSMsg; import com.ihaoin.hooloo.device.data.vo.KDSMsg;
import com.ihaoin.hooloo.device.data.vo.KDSOrder; import com.ihaoin.hooloo.device.data.vo.KDSOrder;
import com.ihaoin.hooloo.device.kds.KDSSocket; 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.kds.adapter.MachineStateAdapter;
import com.ihaoin.hooloo.device.util.CollectionUtils; import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.StringUtils; import com.ihaoin.hooloo.device.util.StringUtils;
import com.ihaoin.hooloo.device.util.Utils; import com.ihaoin.hooloo.device.util.Utils;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class KdsPresentation extends Presentation { public class KdsPresentation extends Presentation {
private KDSMsg mKdsMsg; private KDSMsg mKdsMsg;
private IntroViewPager imagePager; private RecyclerView recyclerImagePager;
private LinearLayoutManager layoutManager; private ImagePagerAdapter imagePagerAdapter;
private RecyclerView recyclerMachineState; private RecyclerView recyclerMachineState;
private MachineStateAdapter machineStateAdapter; private MachineStateAdapter machineStateAdapter;
...@@ -79,28 +75,17 @@ public class KdsPresentation extends Presentation { ...@@ -79,28 +75,17 @@ public class KdsPresentation extends Presentation {
private void initViews() { private void initViews() {
imgAvatar = findViewById(R.id.img_avatar); 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 imageLayoutManager.setOrientation(RecyclerView.HORIZONTAL);
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { imagePagerAdapter = new ImagePagerAdapter(getContext(), null);
LinearSmoothScroller smoothScroller = recyclerImagePager.setAdapter(imagePagerAdapter);
new LinearSmoothScroller(recyclerView.getContext()) { recyclerImagePager.setLayoutManager(imageLayoutManager);
// 返回:滑过1px时经历的时间(ms)。
@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return 10;
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
};
machineStateAdapter = new MachineStateAdapter(getContext(), null); machineStateAdapter = new MachineStateAdapter(getContext(), null);
recyclerMachineState = findViewById(R.id.rec_machine_state);
recyclerMachineState.setAdapter(machineStateAdapter); recyclerMachineState.setAdapter(machineStateAdapter);
recyclerMachineState.setLayoutManager(layoutManager); recyclerMachineState.setLayoutManager(stateLayoutManager);
progressViews.add(findViewById(R.id.progress1)); progressViews.add(findViewById(R.id.progress1));
progressViews.add(findViewById(R.id.progress2)); progressViews.add(findViewById(R.id.progress2));
...@@ -125,40 +110,48 @@ public class KdsPresentation extends Presentation { ...@@ -125,40 +110,48 @@ public class KdsPresentation extends Presentation {
AnimationDrawable anim = (AnimationDrawable) getContext().getDrawable(R.drawable.menu_avatar); AnimationDrawable anim = (AnimationDrawable) getContext().getDrawable(R.drawable.menu_avatar);
imgAvatar.setBackground(anim); imgAvatar.setBackground(anim);
anim.start(); anim.start();
}
try { LinearLayoutManager stateLayoutManager = new LinearLayoutManager(getContext()) {
Field field = ViewPager.class.getDeclaredField("mScroller"); @Override
field.setAccessible(true); public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
FixedSpeedScroller scroller = new FixedSpeedScroller(imagePager.getContext(), new LinearInterpolator()); LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
field.set(imagePager, scroller); // 返回:滑过1px时经历的时间(ms)。
scroller.setmDuration(500); @Override
} catch (Exception e) { protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
e.printStackTrace(); 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() { private void showImages() {
MainData mainData = HLApplication.getMainData(); MainData mainData = HLApplication.getMainData();
if (mainData == null || mainData.getImages() == null) { if (mainData == null || mainData.getImages() == null) {
return; return;
} }
imagePager.removeAllViews(); recyclerImagePager.removeAllViews();
if (CollectionUtils.isEmpty(mainData.getImages().getLeft())) { if (CollectionUtils.isEmpty(mainData.getImages().getLeft())) {
return; return;
} }
List<View> introViews = new ArrayList<>(); imagePagerAdapter.setImages(mainData.getImages().getLeft().stream().filter(x -> !StringUtils.isEmpty(x)).collect(Collectors.toList()));
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;
} }
private void startSocket() { private void startSocket() {
...@@ -207,25 +200,17 @@ public class KdsPresentation extends Presentation { ...@@ -207,25 +200,17 @@ public class KdsPresentation extends Presentation {
} }
} }
private Integer position = 3; private Integer imagePosition = 0;
private Integer statePosition = 3;
private void smoothMachineState() { private void setNextImage() {
position++; imagePosition++;
recyclerMachineState.smoothScrollToPosition(position); recyclerImagePager.smoothScrollToPosition(imagePosition);
} }
private void setNextImage() { private void smoothMachineState() {
int count = imagePager.getCount(); statePosition++;
if (count <= 1) { recyclerMachineState.smoothScrollToPosition(statePosition);
return;
}
int index = imagePager.getCurrentItem();
if (index + 1 >= count) {
index = 0;
} else {
index++;
}
imagePager.setCurrentItem(index, true);
} }
public void mainDataChanged() { 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 @@ ...@@ -6,18 +6,23 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
<com.ihaoin.hooloo.device.component.IntroViewPager
android:id="@+id/image_pager" android:id="@+id/image_pager"
android:layout_width="@dimen/menu_left" android:layout_width="0dp"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:layout_weight="0.73125"
android:descendantFocusability="afterDescendants"
android:orientation="horizontal"
android:overScrollMode="never" />
<LinearLayout <LinearLayout
android:layout_width="@dimen/menu_right" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="0.26875"
android:orientation="vertical"> android:orientation="vertical">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" 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:background="@color/menu_order_bg"
android:paddingStart="@dimen/menu_content_padding_hor" android:paddingStart="@dimen/menu_content_padding_hor"
android:paddingTop="@dimen/menu_content_padding_top"> android:paddingTop="@dimen/menu_content_padding_top">
...@@ -246,7 +251,8 @@ ...@@ -246,7 +251,8 @@
</RelativeLayout> </RelativeLayout>
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" 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:background="@color/menu_state_bg"
android:paddingLeft="@dimen/menu_state_padding_hor" android:paddingLeft="@dimen/menu_state_padding_hor"
android:paddingTop="@dimen/menu_state_padding_ver" 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