[android] MWM-API, show all articles on the map.

This commit is contained in:
vng 2013-08-09 11:24:17 +03:00
parent 1f9a4d0cc5
commit a748e7fdf1
4 changed files with 61 additions and 3 deletions

View file

@ -12,3 +12,4 @@
# Project target.
target=android-18
android.library.reference.1=../3rdparty/android-mwm

View file

@ -11,6 +11,17 @@
android:layout_height="@dimen/search_bar"
android:background="@color/dark_grey" >
<ImageView
android:id="@+id/about"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/top_bar_selector"
android:paddingLeft="@dimen/pad_small"
android:paddingRight="@dimen/pad_small"
android:src="@drawable/ic_info" />
<TextView
style="@android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
@ -21,7 +32,7 @@
android:textStyle="bold" />
<ImageView
android:id="@+id/about"
android:id="@+id/showMapForAll"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
@ -29,7 +40,7 @@
android:background="@drawable/top_bar_selector"
android:paddingLeft="@dimen/pad_small"
android:paddingRight="@dimen/pad_small"
android:src="@drawable/ic_info" />
android:src="@android:drawable/ic_dialog_map" />
</RelativeLayout>
<LinearLayout

View file

@ -3,8 +3,12 @@ package com.example.travelguide;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import com.example.travelguide.article.ArticleInfo;
import com.example.travelguide.cpp.Storage;
import com.mapswithme.maps.api.MWMPoint;
import com.mapswithme.maps.api.MWMResponse;
/**
* An activity representing a list of ArticleInfos. This activity has different
@ -25,6 +29,7 @@ import com.example.travelguide.article.ArticleInfo;
public class ArticleInfoListActivity extends FragmentActivity implements ArticleInfoListFragment.Callbacks,
ArticleInfoListFragment.OnListIconClickedListener, ArticleInfoListFragment.OnFirstLoadListener
{
private static final String TAG = ArticleInfoListActivity.class.getSimpleName();
/**
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
@ -58,6 +63,21 @@ public class ArticleInfoListActivity extends FragmentActivity implements Article
.add(R.id.articleinfo_detail_container, mArtInfoDetailFragment)
.commit();
}
handleIntent(getIntent());
}
private void handleIntent(Intent intent)
{
final MWMResponse mwmResponse = MWMResponse.extractFromIntent(this, intent);
final MWMPoint point = mwmResponse.getPoint();
if (point.getId() != null)
{
final String id = point.getId();
Log.d(TAG, id);
onItemSelected(Storage.getArticleInfoByUrl(id));
}
}
/**

View file

@ -4,7 +4,9 @@ import static com.example.travelguide.util.Utils.hideIf;
import static com.example.travelguide.util.Utils.hideView;
import static com.example.travelguide.util.Utils.showView;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
@ -26,6 +28,8 @@ import com.example.travelguide.article.ArticleInfo;
import com.example.travelguide.async.QueryResultLoader;
import com.example.travelguide.cpp.Storage;
import com.example.travelguide.widget.StorageArticleInfoAdapter;
import com.mapswithme.maps.api.MWMPoint;
import com.mapswithme.maps.api.MapsWithMeApi;
/**
* A list fragment representing a list of ArticleInfos. This fragment also
@ -39,6 +43,7 @@ import com.example.travelguide.widget.StorageArticleInfoAdapter;
public class ArticleInfoListFragment extends ListFragment implements LoaderCallbacks<Storage>, TextWatcher,
OnClickListener, LocationListener
{
private static final String TAG = ArticleInfoListFragment.class.getSimpleName();
public interface OnListIconClickedListener
{
@ -69,6 +74,7 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
private View mProgressContainer;
private View mHeader;
private View mAbout;
private View mShowMapForAll;
// Location
private LocationManager mLocationManager;
@ -218,10 +224,13 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
mProgressContainer = mRootView.findViewById(R.id.progressContainer);
mHeader = mRootView.findViewById(R.id.header);
mAbout = mRootView.findViewById(R.id.about);
mShowMapForAll = mRootView.findViewById(R.id.showMapForAll);
// setup listeners
mSearchText.addTextChangedListener(this);
mCross.setOnClickListener(this);
mAbout.setOnClickListener(this);
mShowMapForAll.setOnClickListener(this);
return mRootView;
}
@ -271,7 +280,6 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
{
hideView(mProgressContainer);
showView(mListContainer);
}
private void search(CharSequence s)
@ -306,6 +314,24 @@ public class ArticleInfoListFragment extends ListFragment implements LoaderCallb
{
// TODO: show about dialog
}
else if (v.getId() == mShowMapForAll.getId())
{
final int count = Storage.getResultSize();
MWMPoint points[] = new MWMPoint[count];
for (int i = 0; i < count; ++i)
{
final ArticleInfo info = Storage.getArticleInfoByIndex(i);
final String url = info.getArticleId();
final String id = url.substring(0, url.lastIndexOf('.'));
points[i] = new MWMPoint(info.getLat(), info.getLon(), info.getName(), id);
}
final Activity a = getActivity();
final Intent intent = new Intent(a, ArticleInfoListActivity.class);
final PendingIntent pi = PendingIntent.getActivity(a, 0, intent, 0);
MapsWithMeApi.showPointsOnMap(a, "Hello, my articles!", pi, points);
}
}
private Location getLocation()