Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change name of CustomSpinner to ScrolledToTopSpinner (#1935)
- Loading branch information
1 parent
0343d95
commit 62e30dc
Showing
4 changed files
with
75 additions
and
63 deletions.
There are no files selected for viewing
60 changes: 0 additions & 60 deletions
60
collect_app/src/main/java/org/odk/collect/android/views/CustomSpinner.java
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
collect_app/src/main/java/org/odk/collect/android/views/ScrolledToTopSpinner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters