BMapApiDemoMain主窗口

package baidumapsdk.demo;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.baidu.mapapi.VersionInfo;

public class BMapApiDemoMain extends Activity {
	
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

		ListView mListView = (ListView)findViewById(R.id.listView); 
		// 添加ListItem,设置事件响应
		/*
		1.DemoListAdapter继承了BaseAdapter类
		2.Adapter类是UI类和数据源之间的桥梁
		3.DemoListAdapter主要是要实现getView函数
		4.这个函数就可以从数据源中获取数据来显示到view上
		*/
        mListView.setAdapter(new DemoListAdapter());
		//对于ListView中的item被点击注册事件,就是重新启动一个activity。
        mListView.setOnItemClickListener(new OnItemClickListener() {  
            public void onItemClick(AdapterView<?> arg0, View v, int index, long arg3) {  
            	onListItemClick(index);
            }  
        });  
    }

	//就是一点击出来一个新的activity
    void onListItemClick(int index) {
		Intent intent = null;
		intent = new Intent(BMapApiDemoMain.this, demos[index].demoClass);
		this.startActivity(intent);
    }
	
	private static final DemoInfo[] demos = {
		new DemoInfo(R.string.demo_title_basemap, R.string.demo_desc_basemap,
				     BaseMapDemo.class),
        new DemoInfo(R.string.demo_title_layers, R.string.demo_desc_layers,
				     LayersDemo.class),
        new DemoInfo(R.string.demo_title_control, R.string.demo_desc_control,
				     MapControlDemo.class),
        new DemoInfo(R.string.demo_title_ui, R.string.demo_desc_ui,
				     UISettingDemo.class),
        new DemoInfo(R.string.demo_title_location, R.string.demo_desc_location,
				     LocationOverlayDemo.class),
        new DemoInfo(R.string.demo_title_geometry, R.string.demo_desc_geometry,
				     GeometryDemo.class),
        new DemoInfo(R.string.demo_title_overlay, R.string.demo_desc_overlay,
				     OverlayDemo.class),
        new DemoInfo(R.string.demo_title_poi, R.string.demo_desc_poi,
				     PoiSearchDemo.class),
        new DemoInfo(R.string.demo_title_geocode, R.string.demo_desc_geocode,
				     GeoCoderDemo.class),
        new DemoInfo(R.string.demo_title_route, R.string.demo_desc_route,
				     RoutePlanDemo.class),
        new DemoInfo(R.string.demo_title_bus, R.string.demo_desc_bus,
				     BusLineSearchDemo.class),
        new DemoInfo(R.string.demo_title_offline, R.string.demo_desc_offline,
				     OfflineDemo.class),
        new DemoInfo(R.string.demo_title_navi, R.string.demo_desc_navi,
				     NaviDemo.class),
        new DemoInfo(R.string.demo_title_cloud, R.string.demo_desc_cloud,
				     CloudSearchDemo.class),
	    new DemoInfo(R.string.demo_title_share, R.string.demo_desc_share,
						     ShareDemo.class)
	};
	

	//这个方法就是在当前activity失去焦点之后再次获取焦点时调用的方法
	//这时候可以重新刷新一下当前窗口
	@Override
	protected void onResume() {
	    DemoApplication app = (DemoApplication)this.getApplication();
	    TextView text = (TextView)findViewById(R.id.text_Info);
		if (!app.m_bKeyRight) {
            text.setText(R.string.key_error);
            text.setTextColor(Color.RED);
		}
		else{
			text.setTextColor(Color.YELLOW);
			text.setText("欢迎使用百度地图Android SDK v"+VersionInfo.getApiVersion());
		}
		super.onResume();
	}

	@Override
	// 建议在APP整体退出之前调用MapApi的destroy()函数,不要在每个activity的OnDestroy中调用,
    // 避免MapApi重复创建初始化,提高效率
	protected void onDestroy() {
	    DemoApplication app = (DemoApplication)this.getApplication();
		if (app.mBMapManager != null) {
			app.mBMapManager.destroy();
			app.mBMapManager = null;
		}
		super.onDestroy();
		System.exit(0);
	}
	
	
	
	private  class DemoListAdapter extends BaseAdapter {
		public DemoListAdapter() {
			super();
		}

		@Override
		public View getView(int index, View convertView, ViewGroup parent) {
			convertView = View.inflate(BMapApiDemoMain.this, R.layout.demo_info_item, null);
			TextView title = (TextView)convertView.findViewById(R.id.title);
			TextView desc = (TextView)convertView.findViewById(R.id.desc);
			if ( demos[index].demoClass == NaviDemo.class  
					|| demos[index].demoClass == CloudSearchDemo.class 
					|| demos[index].demoClass == ShareDemo.class 
					){
				title.setTextColor(Color.YELLOW);
				desc.setTextColor(Color.YELLOW);
			}
			title.setText(demos[index].title);
			desc.setText(demos[index].desc);
			return convertView;
		}
		@Override
		public int getCount() {
			return demos.length;
		}
		@Override
		public Object getItem(int index) {
			return  demos[index];
		}

		@Override
		public long getItemId(int id) {
			return id;
		}
	}
	
   private static class DemoInfo{
		private final int title;
		private final int desc;
		private final Class<? extends android.app.Activity> demoClass;

		public DemoInfo(int title , int desc,Class<? extends android.app.Activity> demoClass) {
			this.title = title;
			this.desc  = desc;
			this.demoClass = demoClass;
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值