Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit e32c2f1

Browse files
authored
Fix non HW accelerated Android 8 hover issues (#3173)
1 parent f41255c commit e32c2f1

File tree

7 files changed

+110
-64
lines changed

7 files changed

+110
-64
lines changed

app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/BookmarkAdapter.java

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public int getItemViewType(int position) {
155155
return 0;
156156
}
157157

158-
@SuppressLint("ClickableViewAccessibility")
158+
@NonNull
159159
@Override
160160
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
161161
if (viewType == BookmarkNodeType.ITEM.ordinal()) {
@@ -166,15 +166,52 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
166166
binding.setCallback(mBookmarkItemCallback);
167167
binding.setIsHovered(false);
168168
binding.setIsNarrow(mIsNarrowLayout);
169+
170+
return new BookmarkViewHolder(binding);
171+
172+
} else if (viewType == BookmarkNodeType.FOLDER.ordinal()) {
173+
BookmarkItemFolderBinding binding = DataBindingUtil
174+
.inflate(LayoutInflater.from(parent.getContext()), R.layout.bookmark_item_folder,
175+
parent, false);
176+
binding.setCallback(mBookmarkItemFolderCallback);
177+
178+
return new BookmarkFolderViewHolder(binding);
179+
180+
} else if (viewType == BookmarkNodeType.SEPARATOR.ordinal()) {
181+
BookmarkSeparatorBinding binding = DataBindingUtil
182+
.inflate(LayoutInflater.from(parent.getContext()), R.layout.bookmark_separator,
183+
parent, false);
184+
185+
return new BookmarkSeparatorViewHolder(binding);
186+
}
187+
188+
throw new IllegalArgumentException("Invalid view Type");
189+
}
190+
191+
@SuppressLint("ClickableViewAccessibility")
192+
@Override
193+
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
194+
Bookmark item = mDisplayList.get(position);
195+
196+
if (holder instanceof BookmarkViewHolder) {
197+
BookmarkViewHolder bookmarkHolder = (BookmarkViewHolder) holder;
198+
BookmarkItemBinding binding = bookmarkHolder.binding;
199+
binding.setItem(item);
200+
binding.setIsNarrow(mIsNarrowLayout);
169201
binding.layout.setOnHoverListener((view, motionEvent) -> {
170202
int ev = motionEvent.getActionMasked();
171203
switch (ev) {
172204
case MotionEvent.ACTION_HOVER_ENTER:
173205
binding.setIsHovered(true);
206+
view.getBackground().setState(new int[]{android.R.attr.state_hovered});
207+
view.postInvalidate();
174208
return false;
175209

210+
case MotionEvent.ACTION_CANCEL:
176211
case MotionEvent.ACTION_HOVER_EXIT:
212+
view.getBackground().setState(new int[]{android.R.attr.state_active});
177213
binding.setIsHovered(false);
214+
view.postInvalidate();
178215
return false;
179216
}
180217

@@ -245,40 +282,27 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
245282
return false;
246283
});
247284

248-
return new BookmarkViewHolder(binding);
249-
250-
} else if (viewType == BookmarkNodeType.FOLDER.ordinal()) {
251-
BookmarkItemFolderBinding binding = DataBindingUtil
252-
.inflate(LayoutInflater.from(parent.getContext()), R.layout.bookmark_item_folder,
253-
parent, false);
254-
binding.setCallback(mBookmarkItemFolderCallback);
255-
256-
return new BookmarkFolderViewHolder(binding);
257-
258-
} else if (viewType == BookmarkNodeType.SEPARATOR.ordinal()) {
259-
BookmarkSeparatorBinding binding = DataBindingUtil
260-
.inflate(LayoutInflater.from(parent.getContext()), R.layout.bookmark_separator,
261-
parent, false);
262-
263-
return new BookmarkSeparatorViewHolder(binding);
264-
}
265-
266-
throw new IllegalArgumentException("Invalid view Type");
267-
}
268-
269-
@Override
270-
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
271-
Bookmark item = mDisplayList.get(position);
272-
273-
if (holder instanceof BookmarkViewHolder) {
274-
BookmarkViewHolder bookmarkHolder = (BookmarkViewHolder) holder;
275-
bookmarkHolder.binding.setItem(item);
276-
bookmarkHolder.binding.setIsNarrow(mIsNarrowLayout);
277-
278285
} else if (holder instanceof BookmarkFolderViewHolder) {
279286
BookmarkFolderViewHolder bookmarkHolder = (BookmarkFolderViewHolder) holder;
280287
bookmarkHolder.binding.setItem(item);
281288
bookmarkHolder.binding.executePendingBindings();
289+
bookmarkHolder.binding.layout.setOnHoverListener((view, motionEvent) -> {
290+
int ev = motionEvent.getActionMasked();
291+
switch (ev) {
292+
case MotionEvent.ACTION_HOVER_ENTER:
293+
view.getBackground().setState(new int[]{android.R.attr.state_hovered});
294+
view.postInvalidate();
295+
return false;
296+
297+
case MotionEvent.ACTION_CANCEL:
298+
case MotionEvent.ACTION_HOVER_EXIT:
299+
view.getBackground().setState(new int[]{android.R.attr.state_active});
300+
view.postInvalidate();
301+
return false;
302+
}
303+
304+
return false;
305+
});
282306

283307
} else if (holder instanceof BookmarkSeparatorViewHolder) {
284308
BookmarkSeparatorViewHolder bookmarkHolder = (BookmarkSeparatorViewHolder) holder;

app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/DownloadsAdapter.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public int getItemPosition(long id) {
120120
return 0;
121121
}
122122

123-
@SuppressLint("ClickableViewAccessibility")
123+
@NonNull
124124
@Override
125125
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
126126
DownloadItemBinding binding = DataBindingUtil
@@ -129,15 +129,31 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
129129
binding.setCallback(mDownloadItemCallback);
130130
binding.setIsHovered(false);
131131
binding.setIsNarrow(mIsNarrowLayout);
132+
133+
return new DownloadItemViewHolder(binding);
134+
}
135+
136+
@SuppressLint("ClickableViewAccessibility")
137+
@Override
138+
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
139+
DownloadItemViewHolder item = (DownloadItemViewHolder) holder;
140+
DownloadItemBinding binding = item.binding;
141+
item.binding.setItem(mDownloadsList.get(position));
142+
item.binding.setIsNarrow(mIsNarrowLayout);
132143
binding.layout.setOnHoverListener((view, motionEvent) -> {
133144
int ev = motionEvent.getActionMasked();
134145
switch (ev) {
135146
case MotionEvent.ACTION_HOVER_ENTER:
136147
binding.setIsHovered(true);
148+
view.getBackground().setState(new int[]{android.R.attr.state_hovered});
149+
view.postInvalidate();
137150
return false;
138151

152+
case MotionEvent.ACTION_CANCEL:
139153
case MotionEvent.ACTION_HOVER_EXIT:
154+
view.getBackground().setState(new int[]{android.R.attr.state_active});
140155
binding.setIsHovered(false);
156+
view.postInvalidate();
141157
return false;
142158
}
143159

@@ -207,15 +223,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
207223
}
208224
return false;
209225
});
210-
211-
return new DownloadItemViewHolder(binding);
212-
}
213-
214-
@Override
215-
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
216-
DownloadItemViewHolder item = (DownloadItemViewHolder) holder;
217-
item.binding.setItem(mDownloadsList.get(position));
218-
item.binding.setIsNarrow(mIsNarrowLayout);
219226
}
220227

221228
@Override

app/src/common/shared/org/mozilla/vrbrowser/ui/adapters/HistoryAdapter.java

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public int getItemPosition(long id) {
127127
return 0;
128128
}
129129

130-
@SuppressLint("ClickableViewAccessibility")
130+
@NonNull
131131
@Override
132132
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
133133
if (viewType == TYPE_ITEM) {
@@ -137,15 +137,44 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
137137
binding.setCallback(mHistoryItemCallback);
138138
binding.setIsHovered(false);
139139
binding.setIsNarrow(mIsNarrowLayout);
140+
141+
return new HistoryItemViewHolder(binding);
142+
143+
} else if (viewType == TYPE_HEADER){
144+
HistoryItemHeaderBinding binding = DataBindingUtil
145+
.inflate(LayoutInflater.from(parent.getContext()), R.layout.history_item_header,
146+
parent, false);
147+
148+
return new HistoryItemViewHeaderHolder(binding);
149+
}
150+
151+
throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly");
152+
}
153+
154+
@SuppressLint("ClickableViewAccessibility")
155+
@Override
156+
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
157+
VisitInfo item = mHistoryList.get(position);
158+
159+
if (holder instanceof HistoryItemViewHolder) {
160+
HistoryItemViewHolder historyHolder = (HistoryItemViewHolder) holder;
161+
HistoryItemBinding binding = historyHolder.binding;
162+
binding.setItem(item);
163+
binding.setIsNarrow(mIsNarrowLayout);
140164
binding.layout.setOnHoverListener((view, motionEvent) -> {
141165
int ev = motionEvent.getActionMasked();
142166
switch (ev) {
143167
case MotionEvent.ACTION_HOVER_ENTER:
144168
binding.setIsHovered(true);
169+
view.getBackground().setState(new int[]{android.R.attr.state_hovered});
170+
view.postInvalidate();
145171
return false;
146172

173+
case MotionEvent.ACTION_CANCEL:
147174
case MotionEvent.ACTION_HOVER_EXIT:
175+
view.getBackground().setState(new int[]{android.R.attr.state_active});
148176
binding.setIsHovered(false);
177+
view.postInvalidate();
149178
return false;
150179
}
151180

@@ -216,29 +245,9 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
216245
return false;
217246
});
218247

219-
return new HistoryItemViewHolder(binding);
220-
221-
} else if (viewType == TYPE_HEADER){
222-
HistoryItemHeaderBinding binding = DataBindingUtil
223-
.inflate(LayoutInflater.from(parent.getContext()), R.layout.history_item_header,
224-
parent, false);
225-
226-
return new HistoryItemViewHeaderHolder(binding);
227-
}
228-
229-
throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly");
230-
}
231-
232-
@Override
233-
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
234-
if (holder instanceof HistoryItemViewHolder) {
235-
HistoryItemViewHolder item = (HistoryItemViewHolder) holder;
236-
item.binding.setItem(mHistoryList.get(position));
237-
item.binding.setIsNarrow(mIsNarrowLayout);
238-
239248
} else if (holder instanceof HistoryItemViewHeaderHolder) {
240-
HistoryItemViewHeaderHolder item = (HistoryItemViewHeaderHolder) holder;
241-
item.binding.setTitle(mHistoryList.get(position).getTitle());
249+
HistoryItemViewHeaderHolder historyHolder = (HistoryItemViewHeaderHolder) holder;
250+
historyHolder.binding.setTitle(item.getTitle());
242251
}
243252
}
244253

app/src/main/res/layout/bookmark_item.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
android:layout_centerVertical="true"
5353
android:gravity="center_vertical"
5454
android:layout_toStartOf="@id/buttons_container"
55+
android:addStatesFromChildren="true"
5556
android:orientation="@{isNarrow ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL}">
5657

5758
<TextView

app/src/main/res/layout/bookmark_item_folder.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</data>
1616

1717
<LinearLayout
18+
android:id="@+id/layout"
1819
android:layout_width="match_parent"
1920
android:layout_height="@dimen/library_item_row_height"
2021
android:orientation="vertical"
@@ -23,6 +24,8 @@
2324
app:leftMargin="@{item.level*100}"
2425
android:paddingStart="10dp"
2526
android:background="@drawable/library_item_background_color"
27+
android:clickable="true"
28+
android:focusable="true"
2629
android:onClick="@{(view) -> callback.onClick(view, item)}">
2730

2831
<TextView

app/src/main/res/layout/download_item.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
android:layout_centerVertical="true"
5454
android:layout_toStartOf="@id/time_buttons"
5555
android:gravity="center_vertical"
56+
android:addStatesFromChildren="true"
5657
android:orientation="@{isNarrow ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL}">
5758

5859
<TextView

app/src/main/res/layout/history_item.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
android:layout_centerVertical="true"
5353
android:layout_toStartOf="@id/time_buttons"
5454
android:gravity="center_vertical"
55+
android:addStatesFromChildren="true"
5556
android:orientation="@{isNarrow ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL}">
5657

5758
<TextView

0 commit comments

Comments
 (0)