Removed listview. Added favorites as simple layuts

This commit is contained in:
Denis 2014-11-12 12:29:38 +02:00
parent 9970816739
commit 8326878fce
3 changed files with 57 additions and 34 deletions

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp">
<ImageView android:id="@+id/icon"
android:layout_gravity="center_vertical"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_width="28dp"
android:layout_height="28dp"/>
<LinearLayout android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>

View file

@ -2,7 +2,7 @@
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:padding="6dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:orientation="vertical"
@ -86,7 +86,8 @@
android:visibility="gone"/>
</LinearLayout>
<LinearLayout android:background="@drawable/bg_cardui"
<LinearLayout android:id="@+id/favorites"
android:background="@drawable/bg_cardui"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -100,9 +101,6 @@
style="@style/DashboardGeneralButton"/>
</LinearLayout>
<ListView android:id="@+id/list_favorites"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>

View file

@ -1,5 +1,6 @@
package net.osmand.plus.activities;
import alice.tuprolog.event.LibraryEvent;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
@ -50,36 +51,33 @@ public class DashboardActivity extends SherlockFragmentActivity {
private void setupFavorites(){
final FavouritesDbHelper helper = getMyApplication().getFavorites();
final List<FavouritePoint> points = helper.getFavouritePoints();
ArrayAdapter<FavouritePoint> adapter = new ArrayAdapter<FavouritePoint>(this, R.layout.favourites_list_item, 0, points) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = getLayoutInflater();
view = inflater.inflate(R.layout.favourites_list_item, parent, false);
if (points.size() > 3){
while (points.size() != 3){
points.remove(3);
}
TextView label = (TextView) view.findViewById(R.id.favourite_label);
ImageView icon = (ImageView) view.findViewById(R.id.favourite_icon);
final FavouritePoint model = points.get(position);
}
LinearLayout favorites = (LinearLayout) findViewById(R.id.favorites);
for(int i =0; i<3; i++){
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.dash_fav_list, null, false);
TextView name = (TextView) view.findViewById(R.id.name);
TextView label = (TextView) view.findViewById(R.id.distance);
ImageView icon = (ImageView) view.findViewById(R.id.icon);
final FavouritePoint model = points.get(i);
view.setTag(model);
name.setText(model.getName());
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(DashboardActivity.this, model.getColor()));
LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " ";
label.setText(distance + model.getName(), TextView.BufferType.SPANNABLE);
label.setText(distance, TextView.BufferType.SPANNABLE);
label.setTypeface(Typeface.DEFAULT, model.isVisible() ? Typeface.NORMAL : Typeface.ITALIC);
((Spannable) label.getText()).setSpan(
new ForegroundColorSpan(getResources().getColor(R.color.color_distance)), 0, distance.length() - 1,
0);
final CheckBox ch = (CheckBox) view.findViewById(R.id.check_item);
view.findViewById(R.id.favourite_icon).setVisibility(View.VISIBLE);
ch.setVisibility(View.GONE);
return view;
favorites.addView(view);
}
};
((ListView) findViewById(R.id.list_favorites)).setAdapter(adapter);
}
private void setupButtons(){
@ -121,6 +119,7 @@ public class DashboardActivity extends SherlockFragmentActivity {
mapVectorLayer.setVisible(true);
}
private OsmandApplication getMyApplication() {
return (OsmandApplication) getApplication();
}