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

Commit

Permalink
Fix unable to select items in a multi-picklist #953 (#1001)
Browse files Browse the repository at this point in the history
* Fix unable to select items in a multi-picklist #953

* Create a constant for the listview item height
  • Loading branch information
MortimerGoro authored and bluemarvin committed Mar 14, 2019
1 parent 9027410 commit f76a9d8
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.mozilla.vrbrowser.ui.views;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListView;

import org.mozilla.vrbrowser.R;

public class CustomListView extends ListView {
public CustomListView(Context context) {
super(context);
initialize();
}

public CustomListView(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}

public CustomListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize();
}

public CustomListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initialize();
}

void initialize() {
setVerticalScrollBarEnabled(false);
setFastScrollAlwaysVisible(false);
}

@Override
public boolean isInTouchMode() {
// Fixes unable to select items after scrolling. See https://github.com/MozillaReality/FirefoxReality/issues/953.
return true;
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);

boolean scrollVisible = false;

if (getChildCount() > 0) {
View first = getChildAt(0);
View last = getChildAt(getChildCount() - 1);
if (first.getTop() < 0 || last.getBottom() > getHeight()) {
scrollVisible = true;
}
}

setVerticalScrollBarEnabled(scrollVisible);
setFastScrollAlwaysVisible(scrollVisible);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.graphics.Typeface;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.MotionEvent;
Expand All @@ -20,6 +21,7 @@
import org.mozilla.geckoview.GeckoSession.PromptDelegate.Choice;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -29,6 +31,7 @@
public class ChoicePromptWidget extends PromptWidget {

private static final int DIALOG_CLOSE_DELAY = 250;
private static final int LISTVIEW_ITEM_HEIGHT = 20;

private AudioEngine mAudio;
private ListView mList;
Expand Down Expand Up @@ -149,8 +152,7 @@ protected void onDismiss() {

@Override
public void show() {
super.show();

show(true);
for (int i = 0; i < mListItems.length; i++) {
mList.setItemChecked(i, mListItems[i].mChoice.selected);
}
Expand All @@ -165,6 +167,10 @@ public void setChoices(Choice[] choices) {
mListItems = getWrappedChoices(choices);
mAdapter = new ChoiceAdapter(getContext(), R.layout.prompt_choice_item, mListItems);
mList.setAdapter(mAdapter);
int height = WidgetPlacement.dpDimension(getContext(), R.dimen.prompt_choice_min_height);
height += choices.length * LISTVIEW_ITEM_HEIGHT;
height = Math.min(height, WidgetPlacement.dpDimension(getContext(), R.dimen.prompt_choice_max_height));
mWidgetPlacement.height = height;
}

public void setMenuType(int type) {
Expand Down
176 changes: 84 additions & 92 deletions app/src/main/res/layout/prompt_choice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,100 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content"
android:background="@drawable/prompt_background"
android:orientation="vertical">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout"
<TextView
android:id="@+id/promptTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/prompt_background">
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:gravity="center_horizontal"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />

<TextView
android:id="@+id/promptTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:gravity="center_horizontal"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
<TextView
android:id="@+id/promptMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:ellipsize="end"
android:gravity="top|start"
android:scrollbars="vertical"
android:singleLine="true"
android:textAlignment="viewStart"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/promptTitle"
tools:text="Message" />

<TextView
android:id="@+id/promptMessage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:ellipsize="end"
android:gravity="top|start"
android:scrollbars="vertical"
android:singleLine="true"
android:textAlignment="viewStart"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/promptTitle"
tools:text="Message" />
<org.mozilla.vrbrowser.ui.views.CustomListView
android:id="@+id/choiceslist"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="100"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:divider="@android:color/transparent"
android:smoothScrollbar="true"
android:overScrollMode="never"
android:dividerHeight="4dp" />

<LinearLayout
android:id="@+id/listContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxHeight="@dimen/prompt_content_max_height"
app:layout_constraintBottom_toTopOf="@+id/buttonsLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/promptMessage">
<LinearLayout
android:id="@+id/buttonsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">

<ListView
android:id="@+id/choiceslist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:divider="@android:color/transparent"
android:dividerHeight="4dp" />
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="100" />

<LinearLayout
android:id="@+id/buttonsLayout"
<Button
android:id="@+id/negativeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/listContainer">

<Button
android:id="@+id/negativeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/prompt_button_background"
android:fontFamily="sans-serif"
android:padding="10dp"
android:scaleType="fitCenter"
android:text="@string/cancel_button"
android:textAllCaps="true"
android:textColor="@drawable/prompt_button_text_color"
android:textSize="10pt"
android:textStyle="bold" />
android:background="@drawable/prompt_button_background"
android:fontFamily="sans-serif"
android:padding="10dp"
android:scaleType="fitCenter"
android:text="@string/cancel_button"
android:textAllCaps="true"
android:textColor="@drawable/prompt_button_text_color"
android:textSize="10pt"
android:textStyle="bold"
android:layout_weight="1"/>

<Button
android:id="@+id/positiveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/prompt_button_background"
android:fontFamily="sans-serif"
android:padding="10dp"
android:scaleType="fitCenter"
android:text="@string/ok_button"
android:textAllCaps="true"
android:textColor="@drawable/prompt_button_text_color"
android:textSize="10pt"
android:textStyle="bold" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/positiveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/prompt_button_background"
android:fontFamily="sans-serif"
android:padding="10dp"
android:scaleType="fitCenter"
android:text="@string/ok_button"
android:textAllCaps="true"
android:textColor="@drawable/prompt_button_text_color"
android:textSize="10pt"
android:textStyle="bold"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
<!-- Prompts -->
<dimen name="prompt_height">800dp</dimen>
<dimen name="prompt_content_max_height">450dp</dimen>
<dimen name="prompt_choice_min_height">300dp</dimen>
<dimen name="prompt_choice_max_height">520dp</dimen>

<!-- Crash Dialog prompt -->
<dimen name="crash_dialog_width">640dp</dimen>
Expand Down

0 comments on commit f76a9d8

Please sign in to comment.