If you think the Android project Go2-Rennes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*******************************************************************************
* Copyright (c) 2011 Michel DAVID mimah35-at-gmail.com
* /*www.java2s.com*/
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/package fr.gotorennes.view;
import java.util.Comparator;
import android.content.Context;
import android.location.Location;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import fr.gotorennes.AbstractMapActivity;
import fr.gotorennes.R;
import fr.gotorennes.domain.Localisable;
import fr.gotorennes.util.LocationUtils;
publicclass FilterSortBar extends FilterBar<Localisable> {
privateboolean triAlpha = true;
private Location location;
private ImageView tri;
public FilterSortBar(Context context) {
this(context, null);
}
public FilterSortBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public FilterSortBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
tri = (ImageView) findViewById(R.id.tri);
tri.setOnClickListener(new OnClickListener() {
@Override
publicvoid onClick(View v) {
if(triAlpha) {
triLocation();
}
else {
triAlpha();
}
}
});
}
protectedvoid triAlpha() {
tri.setImageResource(android.R.drawable.ic_menu_sort_alphabetically);
arrayAdapter.sort(null);
triAlpha = true;
}
protectedvoid triLocation() {
tri.setImageResource(android.R.drawable.ic_menu_sort_by_size);
location = LocationUtils.getLocation(getContext());
if(location != null) {
arrayAdapter.sort(locationComparator);
}
triAlpha = false;
}
privatefinal Comparator<Localisable> locationComparator = new Comparator<Localisable>() {
@Override
publicint compare(Localisable station1, Localisable station2) {
Double distance1 = AbstractMapActivity.getDistance(location.getLatitude(), location.getLongitude(), station1.latitude, station1.longitude);
Double distance2 = AbstractMapActivity.getDistance(location.getLatitude(), location.getLongitude(), station2.latitude, station2.longitude);
return distance1.compareTo(distance2);
}
};
protectedint getLayout() {
return R.layout.filter_sort_bar;
}
}