Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
machine
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hooloo
android
machine
Commits
c2ad23a7
Commit
c2ad23a7
authored
Sep 05, 2022
by
wjg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add update
parent
3bf27115
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
73 deletions
+137
-73
app/src/main/java/com/ihaoin/hooloo/device/kds/adapter/ImagePagerAdapter.java
+62
-0
app/src/main/java/com/ihaoin/hooloo/device/kds/adapter/MachineStateAdapter.java
+3
-0
app/src/main/java/com/ihaoin/hooloo/device/kds/view/KdsPresentation.java
+51
-66
app/src/main/res/layout/kds_img.xml
+8
-0
app/src/main/res/layout/present_kds.xml
+13
-7
No files found.
app/src/main/java/com/ihaoin/hooloo/device/kds/adapter/ImagePagerAdapter.java
0 → 100644
View file @
c2ad23a7
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
);
}
}
}
app/src/main/java/com/ihaoin/hooloo/device/kds/adapter/MachineStateAdapter.java
View file @
c2ad23a7
...
...
@@ -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
;
}
...
...
app/src/main/java/com/ihaoin/hooloo/device/kds/view/KdsPresentation.java
View file @
c2ad23a7
...
...
@@ -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
i
magePager
;
private
LinearLayoutManager
layoutManag
er
;
private
RecyclerView
recyclerI
magePager
;
private
ImagePagerAdapter
imagePagerAdapt
er
;
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
);
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
);
}
};
recyclerImagePager
=
findViewById
(
R
.
id
.
image_pager
);
recyclerMachineState
=
findViewById
(
R
.
id
.
rec_machine_state
);
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
(
l
ayoutManager
);
recyclerMachineState
.
setLayoutManager
(
stateL
ayoutManager
);
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
;
}
i
magePager
.
removeAllViews
();
recyclerI
magePager
.
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
Integer
imagePosition
=
0
;
private
Integer
statePosition
=
3
;
private
void
s
moothMachineStat
e
()
{
p
osition
++;
recycler
MachineState
.
smoothScrollToPosition
(
p
osition
);
private
void
s
etNextImag
e
()
{
imageP
osition
++;
recycler
ImagePager
.
smoothScrollToPosition
(
imageP
osition
);
}
private
void
setNextImage
()
{
int
count
=
imagePager
.
getCount
();
if
(
count
<=
1
)
{
return
;
}
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
()
{
...
...
app/src/main/res/layout/kds_img.xml
0 → 100644
View file @
c2ad23a7
<?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
app/src/main/res/layout/present_kds.xml
View file @
c2ad23a7
...
...
@@ -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"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment