Skip to content

Commit

Permalink
Change name of CustomSpinner to ScrolledToTopSpinner (#1935)
Browse files Browse the repository at this point in the history
  • Loading branch information
iammvaibhav committed Mar 1, 2018
1 parent 0343d95 commit 62e30dc
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 63 deletions.

This file was deleted.

@@ -0,0 +1,72 @@
package org.odk.collect.android.views;

import android.content.Context;
import android.support.v7.widget.AppCompatSpinner;
import android.util.AttributeSet;

/**
* Copyright 2018 Vaibhav Maheshwari
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

public class ScrolledToTopSpinner extends AppCompatSpinner {

private boolean spinnerClicked = false;

public ScrolledToTopSpinner(Context context, AttributeSet attrs,
int defStyle, int mode) {
super(context, attrs, defStyle, mode);
}

public ScrolledToTopSpinner(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}

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

public ScrolledToTopSpinner(Context context, int mode) {
super(context, mode);
}

public ScrolledToTopSpinner(Context context) {
super(context);
}

@Override
public int getSelectedItemPosition() {
// this toggle is required because this method will get called in other
// places too, the most important being called for the
// OnItemSelectedListener
if (spinnerClicked && super.getSelectedItemPosition() == getAdapter().getCount() - 1) {
return 0; // get us to the first element
}
return super.getSelectedItemPosition();
}

@Override
public boolean performClick() {
// this method shows the list of elements from which to select one.
// we have to make the getSelectedItemPosition to return 0 so you can
// fool the Spinner and let it think that the selected item is the first
// element
spinnerClicked = true;
boolean result = super.performClick();
spinnerClicked = false;
return result;
}

}
Expand Up @@ -37,7 +37,7 @@
import org.odk.collect.android.R;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.external.ExternalDataUtil;
import org.odk.collect.android.views.CustomSpinner;
import org.odk.collect.android.views.ScrolledToTopSpinner;
import org.odk.collect.android.widgets.interfaces.MultiChoiceWidget;

import java.util.List;
Expand All @@ -52,7 +52,7 @@
@SuppressLint("ViewConstructor")
public class SpinnerWidget extends QuestionWidget implements MultiChoiceWidget {
List<SelectChoice> items;
CustomSpinner spinner;
ScrolledToTopSpinner spinner;
String[] choices;

public SpinnerWidget(Context context, FormEntryPrompt prompt) {
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/spinner_layout.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<org.odk.collect.android.views.CustomSpinner xmlns:android="http://schemas.android.com/apk/res/android"
<org.odk.collect.android.views.ScrolledToTopSpinner xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner"
style="@style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
Expand Down

0 comments on commit 62e30dc

Please sign in to comment.