My favorites
▼
|
Sign in
android-protips-location
Android Protips: A Deep Dive Into Location
Project Home
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
src
/
com
/
radioactiveyak
/
location_best_practices
/
UI
/
fragments
/
PlaceListFragment.java
r5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright 2011 Google Inc.
*
* 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.
*/
package com.radioactiveyak.location_best_practices.UI.fragments;
import com.radioactiveyak.location_best_practices.PlacesConstants;
import com.radioactiveyak.location_best_practices.UI.PlaceActivity;
import com.radioactiveyak.location_best_practices.content_providers.PlacesContentProvider;
import com.radioactiveyak.location_best_practices.services.PlaceDetailsUpdateService;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.widget.ListView;
// TODO Update this UI to show a better list of available venues. This could include
// TODO pictures, direction, more detailed text, etc. You will likely want to define
// TODO your own List Item Layout.
/**
* UI Fragment to show a list of venues near to the users current location.
*/
public class PlaceListFragment extends ListFragment implements LoaderCallbacks<Cursor> {
protected Cursor cursor = null;
protected SimpleCursorAdapter adapter;
protected PlaceActivity activity;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
activity = (PlaceActivity)getActivity();
// Create a new SimpleCursorAdapter that displays the name of each nearby
// venue and the current distance to it.
adapter = new SimpleCursorAdapter(
activity,
android.R.layout.two_line_list_item,
cursor,
new String[] {PlacesContentProvider.KEY_NAME, PlacesContentProvider.KEY_DISTANCE},
new int[] {android.R.id.text1, android.R.id.text2},
0);
// Allocate the adapter to the List displayed within this fragment.
setListAdapter(adapter);
// Populate the adapter / list using a Cursor Loader.
getLoaderManager().initLoader(0, null, this);
}
/**
* {@inheritDoc}
* When a venue is clicked, fetch the details from your server and display the detail page.
*/
@Override
public void onListItemClick(ListView l, View v, int position, long theid) {
super.onListItemClick(l, v, position, theid);
// Find the ID and Reference of the selected venue.
// These are needed to perform a lookup in our cache and the Google Places API server respectively.
Cursor c = adapter.getCursor();
c.moveToPosition(position);
String reference = c.getString(c.getColumnIndex(PlacesContentProvider.KEY_REFERENCE));
String id = c.getString(c.getColumnIndex(PlacesContentProvider.KEY_ID));
// Initiate a lookup of the venue details usign the PlacesDetailsUpdateService.
// Because this is a user initiated action (rather than a prefetch) we request
// that the Service force a refresh.
Intent serviceIntent = new Intent(activity, PlaceDetailsUpdateService.class);
serviceIntent.putExtra(PlacesConstants.EXTRA_KEY_REFERENCE, reference);
serviceIntent.putExtra(PlacesConstants.EXTRA_KEY_ID, id);
serviceIntent.putExtra(PlacesConstants.EXTRA_KEY_FORCEREFRESH, true);
activity.startService(serviceIntent);
// Request the parent Activity display the venue detail UI.
activity.selectDetail(reference, id);
}
/**
* {@inheritDoc}
* This loader will return the ID, Reference, Name, and Distance of all the venues
* currently stored in the {@link PlacesContentProvider}.
*/
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String[] projection = new String[] {PlacesContentProvider.KEY_ID,PlacesContentProvider.KEY_NAME, PlacesContentProvider.KEY_DISTANCE, PlacesContentProvider.KEY_REFERENCE};
return new CursorLoader(activity, PlacesContentProvider.CONTENT_URI,
projection, null, null, null);
}
/**
* {@inheritDoc}
* When the loading has completed, assign the cursor to the adapter / list.
*/
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
adapter.swapCursor(data);
}
/**
* {@inheritDoc}
*/
public void onLoaderReset(Loader<Cursor> loader) {
adapter.swapCursor(null);
}
}
Show details
Hide details
Change log
r1
by retome...@google.com on Jun 21, 2011
Diff
Initial Commit
Go to:
/trunk
/trunk/.classpath
/trunk/.project
/trunk/AndroidManifest.xml
/trunk/Readme.txt
/trunk/default.properties
/trunk/res
/trunk/res/anim-v11
...k/res/anim-v11/slide_in_left.xml
...res/anim-v11/slide_out_right.xml
/trunk/res/drawable-hdpi
/trunk/res/drawable-hdpi/icon.png
...i/powered_by_google_on_black.png
...i/powered_by_google_on_white.png
/trunk/res/drawable-ldpi
/trunk/res/drawable-ldpi/icon.png
...i/powered_by_google_on_black.png
...i/powered_by_google_on_white.png
/trunk/res/drawable-mdpi
/trunk/res/drawable-mdpi/icon.png
...i/powered_by_google_on_black.png
...i/powered_by_google_on_white.png
/trunk/res/layout
/trunk/res/layout-port
/trunk/res/layout-port/main.xml
/trunk/res/layout-xlarge-port
.../res/layout-xlarge-port/main.xml
/trunk/res/layout/checkin_box.xml
/trunk/res/layout/main.xml
/trunk/res/layout/place_detail.xml
/trunk/res/menu
/trunk/res/menu/main_menu.xml
/trunk/res/values
/trunk/res/values-v8
/trunk/res/values-v8/booleans.xml
/trunk/res/values/booleans.xml
/trunk/res/values/strings.xml
/trunk/src
/trunk/src/com
/trunk/src/com/radioactiveyak
...ctiveyak/location_best_practices
...practices/PlacesApplication.java
...practices/PlacesBackupAgent.java
...t_practices/PlacesConstants.java
...veyak/location_best_practices/UI
..._practices/UI/PlaceActivity.java
...tion_best_practices/UI/fragments
...I/fragments/CheckinFragment.java
...agments/PlaceDetailFragment.java
...fragments/PlaceListFragment.java
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 4968 bytes, 124 lines
View raw file
Powered by
Google Project Hosting