开源项目之Android Panoramio

简介

Panoramio 是 Android 手机平台上的一个应用程序将告诉您附近的照片和兴趣点。项目如图:

开源项目之Android Panoramio_第1张图片

效果如图(google地图没出来):

开源项目之Android Panoramio_第2张图片


开源项目之Android Panoramio_第3张图片开源项目之Android Panoramio_第4张图片

分析

public class BitmapUtils {//从一个URL加载位图
public class ImageAdapter extends BaseAdapter {	//适配器显示分享的照片
public class ViewMap extends MapActivity { // 显示自定义地图
public class ViewImage extends Activity { // 单个图片展示
public class PanoramioItem implements Parcelable { //服务器返回数据封装
public class Panoramio extends MapActivity implements OnClickListener {	//用户选择搜索区域
public class ImageManager {	//管理 负责下载和解析的搜索结果 关键操作如下:
	public void run() {	//线程获取数据

			String url = THUMBNAIL_URL;
			url = String.format(url, mMinLat, mMinLong, mMaxLat, mMaxLong);
			try {
				URI uri = new URI("http", url, null);
				HttpGet get = new HttpGet(uri);

				HttpClient client = new DefaultHttpClient();
				HttpResponse response = client.execute(get);
				HttpEntity entity = response.getEntity();
				String str = convertStreamToString(entity.getContent());
				JSONObject json = new JSONObject(str);
				parse(json);
			} catch (Exception e) {
				Log.e(TAG, e.toString());
			}
		}
		private void parse(JSONObject json) {	//分析数据
			try {
				JSONArray array = json.getJSONArray("photos");
				int count = array.length();
				for (int i = 0; i < count; i++) {
					JSONObject obj = array.getJSONObject(i);
					long id = obj.getLong("photo_id");
					String title = obj.getString("photo_title");
					String owner = obj.getString("owner_name");
					String thumb = obj.getString("photo_file_url");
					String ownerUrl = obj.getString("owner_url");
					String photoUrl = obj.getString("photo_url");
					double latitude = obj.getDouble("latitude");
					double longitude = obj.getDouble("longitude");
					Bitmap b = BitmapUtils.loadBitmap(thumb);
					if (title == null) {
						title = mContext.getString(R.string.untitled);
					}

					final PanoramioItem item = new PanoramioItem(id, thumb, b,
							(int) (latitude * Panoramio.MILLION),
							(int) (longitude * Panoramio.MILLION), title,
							owner, ownerUrl, photoUrl);
					final boolean done = i == count - 1;
					mHandler.post(new Runnable() {
						public void run() {

							sInstance.mLoading = !done;
							sInstance.add(item);
						}
					});
				}
			} catch (JSONException e) {
				Log.e(TAG, e.toString());
			}
		}
		private String convertStreamToString(InputStream is) {	//转换
			BufferedReader reader = new BufferedReader(
					new InputStreamReader(is), 8 * 1024);
			StringBuilder sb = new StringBuilder();

			String line = null;
			try {
				while ((line = reader.readLine()) != null) {
					sb.append(line + "\n");
				}
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			return sb.toString();
		}

下载

项目下载!


你可能感兴趣的:(开源项目之Android Panoramio)