实例介绍
【实例简介】
【实例截图】
【实例截图】
【核心代码】
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | package com.weiyoung.yourlifecircle; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.json.JSONObject; import com.baidu.mapapi.BMapManager; import com.baidu.mapapi.map.MKMapViewListener; import com.baidu.mapapi.map.MapController; import com.baidu.mapapi.map.MapPoi; import com.baidu.mapapi.map.MapView; import com.baidu.platform.comapi.basestruct.GeoPoint; import com.tencent.tauth.IUiListener; import com.tencent.tauth.Tencent; import com.tencent.tauth.UiError; import com.weiyoung.service.YLC_SAVEUSERSERVICE; import com.weiyoung.utils.YLC_HttpClient; import com.weiyoung.utils.YLC_SaveUserInfo; import com.weiyoung.variable.LoginInfo; import android.net.Uri; import android.os.Bundle; import android.os.StrictMode; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.view.Display; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.view.View.OnTouchListener; import android.view.Window; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; public class YLC_Main extends Activity implements OnTouchListener { private Tencent mtencent; private static final String AppID = "101027899" ; private static final String Scope = "all" ; private TextView nickname_textview; private ImageView imageView; private ImageView BDMapService_imageview; private ImageView BDMAPLocation_imageview; private ImageView BDSet_imageview; // 地图处理部分 private MapView mapView = null ; private MapController mapController = null ; private MKMapViewListener mkMapViewListener = null ; @Override protected void onCreate(Bundle savedInstanceState) { StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() // or .detectAll() for all detectable problems .penaltyLog() .build()); StrictMode.setVmPolicy( new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build()); YLC_APPLICATION ylc_Application = (YLC_APPLICATION) this .getApplication(); if (ylc_Application.bMapManager == null ) { ylc_Application.bMapManager = new BMapManager( this ); ylc_Application.bMapManager.init(YLC_APPLICATION.STR_KEY, new YLC_APPLICATION.MyMKGeneralListener()); ylc_Application.bMapManager.start(); } super .onCreate(savedInstanceState); setContentView(R.layout.activity_ylc__main); initMap(); mtencent = Tencent.createInstance(AppID, this .getApplicationContext()); findView(); } public void findView() { nickname_textview=(TextView) findViewById(R.id.nickname_textview); imageView = (ImageView) findViewById(R.id.imageView); BDMapService_imageview = (ImageView) findViewById(R.id.BDMapService_imageview); BDMAPLocation_imageview = (ImageView) findViewById(R.id.BDMAPLocation_imageview); BDSet_imageview = (ImageView) findViewById(R.id.BDSet_imageview); BDMapService_imageview.setOnTouchListener( this ); BDMAPLocation_imageview.setOnTouchListener( this ); BDSet_imageview.setOnTouchListener( this ); } @Override protected void onDestroy() { // TODO Auto-generated method stub super .onDestroy(); mapView.destroy(); } @Override protected void onPause() { // TODO Auto-generated method stub super .onPause(); mapView.onPause(); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { mapView.onRestoreInstanceState(savedInstanceState); // TODO Auto-generated method stub super .onRestoreInstanceState(savedInstanceState); } @Override protected void onResume() { // TODO Auto-generated method stub super .onResume(); mapView.onResume(); } @Override protected void onSaveInstanceState(Bundle outState) { // TODO Auto-generated method stub super .onSaveInstanceState(outState); mapView.onSaveInstanceState(outState); } public void initMap() { mapView = (MapView) findViewById(R.id.bmapView); mapController = mapView.getController(); mapController.enableClick( true ); mapController.setZoom( 12 ); /** * 将地图移动至指定点 * 使用百度经纬度坐标,可以通过http://api.map.baidu.com/lbsapi/getpoint/index * .html查询地理坐标 如果需要在百度地图上显示使用其他坐标系统的位置,请发邮件至mapapi@baidu.com申请坐标转换接口 */ GeoPoint p; double cLat = 39.945 ; double cLon = 116.404 ; Intent intent = getIntent(); if (intent.hasExtra( "x" ) && intent.hasExtra( "y" )) { // 当用intent参数时,设置中心点为指定点 Bundle b = intent.getExtras(); p = new GeoPoint(b.getInt( "y" ), b.getInt( "x" )); } else { // 设置中心点为天安门 p = new GeoPoint(( int ) (cLat * 1E6), ( int ) (cLon * 1E6)); } mapController.setCenter(p); /** * MapView的生命周期与Activity同步,当activity挂起时需调用MapView.onPause() */ mkMapViewListener = new MKMapViewListener() { @Override public void onMapMoveFinish() { /** * 在此处理地图移动完成回调 缩放,平移等操作完成后,此回调被触发 */ } @Override public void onClickMapPoi(MapPoi mapPoiInfo) { /** * 在此处理底图poi点击事件 显示底图poi名称并移动至该点 设置过: * mMapController.enableClick(true); 时,此回调才能被触发 * */ String title = "" ; if (mapPoiInfo != null ) { title = mapPoiInfo.strText; Toast.makeText(YLC_Main. this , title, Toast.LENGTH_SHORT) .show(); mapController.animateTo(mapPoiInfo.geoPt); } } @Override public void onGetCurrentMap(Bitmap b) { /** * 当调用过 mMapView.getCurrentMap()后,此回调会被触发 可在此保存截图至存储设备 */ } @Override public void onMapAnimationFinish() { /** * 地图完成带动画的操作(如: animationTo())后,此回调被触发 */ } /** * 在此处理地图载完成事件 */ @Override public void onMapLoadFinish() { Toast.makeText(YLC_Main. this , "地图加载完成" , Toast.LENGTH_SHORT) .show(); } }; mapView.regMapViewListener(YLC_APPLICATION.getInstance().bMapManager, mkMapViewListener); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.ylc__main, menu); return true ; } public void userLogin(View view) { mtencent.login(YLC_Main. this , Scope, new BaseUiListener()); // 登录 } private class BaseUiListener implements IUiListener { @Override public void onCancel() { // 取消登录 // TODO Auto-generated method stub } @Override public void onComplete(Object json) { // TODO Auto-generated method stub JSONObject jsonObject = (JSONObject) json; YLC_HttpClient ylc_HttpClient = new YLC_HttpClient(); Uri uri = ylc_HttpClient.getQQuserInfo(jsonObject); LoginInfo.LOGIN_STATE = true ; // 登录成功设置登录状态为true; nickname_textview.setText(LoginInfo.nickname); try { Bitmap bitmap = BitmapFactory .decodeStream(getImageViewInputStream(uri.toString())); imageView.setImageBitmap(bitmap); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //启动service,向服务器传递数据 Thread saveUserThread= new Thread( new Runnable() { @Override public void run() { // TODO Auto-generated method stub YLC_SaveUserInfo saveUserInfo= new YLC_SaveUserInfo(YLC_Main. this ); saveUserInfo.saveUser(); } }); saveUserThread.start(); } @Override public void onError(UiError ui) { // TODO Auto-generated method stub Toast.makeText(YLC_Main. this , "登录出错,请确认你的网络连接" ui, Toast.LENGTH_LONG).show(); } } /** * 2 * 从网络中获取图片,以流的形式返回 3 * @return 4 */ public static InputStream getImageViewInputStream(String URL_PATH) throws IOException { InputStream inputStream = null ; URL url = new URL(URL_PATH); // 服务器地址 if (url != null ) { // 打开连接 HttpURLConnection httpURLConnection = (HttpURLConnection) url .openConnection(); httpURLConnection.setConnectTimeout( 3000 ); // 设置网络连接超时的时间为3秒 httpURLConnection.setRequestMethod( "GET" ); // 设置请求方法为GET httpURLConnection.setDoInput( true ); // 打开输入流 int responseCode = httpURLConnection.getResponseCode(); // 获取服务器响应值 if (responseCode == HttpURLConnection.HTTP_OK) { // 正常连接 inputStream = httpURLConnection.getInputStream(); // 获取输入流 } } return inputStream; } @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub Color color = new Color(); switch (v.getId()) { case R.id.BDMapService_imageview: if (event.getAction() == MotionEvent.ACTION_DOWN) { BDMapService_imageview .setBackgroundColor(color.rgb( 14 , 49 , 55 )); BDMapService_imageview.setImageDrawable(getResources() .getDrawable(R.drawable.ylc_service_focus)); } else if (event.getAction() == MotionEvent.ACTION_UP) { BDMapService_imageview.setBackgroundColor(color.TRANSPARENT); BDMapService_imageview.setImageDrawable(getResources() .getDrawable(R.drawable.ylc_service)); /* * Intent intent=new Intent(YLC_Main.this, * LocationOverlayDemoTest.class); * YLC_Main.this.startActivity(intent); */ showYLCService(); } break; case R.id.BDMAPLocation_imageview: if (event.getAction() == MotionEvent.ACTION_DOWN) { BDMAPLocation_imageview.setBackgroundColor(color .rgb(14, 49, 55)); BDMAPLocation_imageview.setImageDrawable(getResources() .getDrawable(R.drawable.ylc_location_focus)); } else if (event.getAction() == MotionEvent.ACTION_UP) { BDMAPLocation_imageview.setBackgroundColor(color.TRANSPARENT); BDMAPLocation_imageview.setImageDrawable(getResources() .getDrawable(R.drawable.ylc_location)); Intent intent = new Intent(YLC_Main.this, YLC_SelfLocation.class); YLC_Main.this.startActivity(intent); } break; case R.id.BDSet_imageview: if (event.getAction() == MotionEvent.ACTION_DOWN) { BDSet_imageview.setBackgroundColor(color.rgb(14, 49, 55)); BDSet_imageview.setImageDrawable(getResources().getDrawable( R.drawable.ylc_set_hover)); } else if (event.getAction() == MotionEvent.ACTION_UP) { BDSet_imageview.setBackgroundColor(color.TRANSPARENT); BDSet_imageview.setImageDrawable(getResources().getDrawable( R.drawable.ylc_set)); Intent intent = new Intent(YLC_Main.this, YLC_Set.class); YLC_Main.this.startActivity(intent); } break; } return false; } /* * 菜单按钮的各个选项 */ public void showYLCService() { String[] items = getResources().getStringArray( R.array.ylc_string_service); AlertDialog dialogService = new AlertDialog.Builder( this ) .setTitle( "功能列表" ).setItems(items, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Intent intent = null ; switch (which) { case 0 : intent = new Intent(YLC_Main. this , YLC_POI_Search. class ); YLC_Main. this .startActivity(intent); break ; case 1 : intent = new Intent(YLC_Main. this , YLC_RoutePlan. class ); YLC_Main. this .startActivity(intent); break ; case 2 : intent = new Intent(YLC_Main. this , YLC_GeoCoder. class ); YLC_Main. this .startActivity(intent); break ; case 3 : intent = new Intent(YLC_Main. this , YLC_BusLine. class ); YLC_Main. this .startActivity(intent); break ; case 4 : intent = new Intent(YLC_Main. this , YLC_YourLifeCircle. class ); YLC_Main. this .startActivity(intent); break ; } } }).create(); WindowManager wm = getWindowManager(); Display d = wm.getDefaultDisplay(); WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); layoutParams.x = - 350 ; layoutParams.y = 120 ; layoutParams.gravity = Gravity.BOTTOM; layoutParams.width = ( int ) (d.getWidth() * 0.48 ); layoutParams.height = ( int ) (d.getHeight() * 0.50 ); layoutParams.alpha = 0 .6f; // 设置对话框的透明度 dialogService.setCanceledOnTouchOutside( true ); dialogService.show(); Window window = dialogService.getWindow(); window.setAttributes(layoutParams); // window.setGravity(Gravity.BOTTOM);//设置弹出对话框位置 } public void showUserInfo(View view){ if (LoginInfo.userinfo_state){ List<String> listItemTitle= null ; List<String> listItemContent= null ; if (LoginInfo.user_type== 1 ){ listItemTitle=getQQuserInfoTitle(); listItemContent=getQQuserInfoContent(); AlertDialog qquserDialog= new AlertDialog.Builder( this ) .setTitle( "QQ用户" ) .setAdapter( new UserInfoAdapter(listItemTitle,listItemContent), null ) .create(); qquserDialog.show(); } else if (LoginInfo.user_type== 2 ){ listItemTitle=getQQWBuserInfoTitle(); listItemContent=getQQWBuserInfoContent(); AlertDialog qqwbuserDialog= new AlertDialog.Builder( this ) .setTitle( "QQ微博用户" ) .setAdapter( new UserInfoAdapter(listItemTitle,listItemContent), null ) .create(); qqwbuserDialog.show(); } } else { Toast.makeText(YLC_Main. this , "数据正在更新,请稍后..." , Toast.LENGTH_LONG).show(); } } //从sharedpreference获取数据 public List<String> getQQuserInfoTitle(){ List<String> listItemTitle= new ArrayList<String>(); listItemTitle.add( "QQ昵称:" ); listItemTitle.add( "性别:" ); listItemTitle.add( "是否是黄钻:" ); listItemTitle.add( "是否是VIP:" ); listItemTitle.add( "黄钻等级:" ); listItemTitle.add( "VIP等级:" ); listItemTitle.add( "是否是年黄钻:" ); return listItemTitle; } public List<String> getQQuserInfoContent(){ List<String> listItemContent= new ArrayList<String>(); SharedPreferences share= this .getSharedPreferences( "qquser" , Context.MODE_PRIVATE); listItemContent.add(share.getString( "nickname" , "" )); listItemContent.add(share.getString( "gender" , "" )); if (share.getInt( "is_yellow_vip" , 10 )== 0 ){ listItemContent.add( "否" ); } else { listItemContent.add( "是" ); } if (share.getInt( "vip" , 10 )== 0 ){ listItemContent.add( "否" ); } else { listItemContent.add( "是" ); } if (share.getInt( "yellow_vip_level" , 10 )== 0 ){ listItemContent.add( "否" ); } else { listItemContent.add( "是" ); } if (share.getInt( "level" , 10 )== 0 ){ listItemContent.add( "否" ); } else { listItemContent.add( "是" ); } if (share.getInt( "is_yellow_year_vip" , 10 )== 0 ){ listItemContent.add( "否" ); } else { listItemContent.add( "是" ); } return listItemContent; } public List<String> getQQWBuserInfoTitle(){ List<String> listItemTitle= new ArrayList<String>(); listItemTitle.add( "QQ微博昵称:" ); listItemTitle.add( "QQ昵称:" ); listItemTitle.add( "微博账户:" ); listItemTitle.add( "性别:" ); listItemTitle.add( "是否是黄钻:" ); listItemTitle.add( "是否是VIP:" ); listItemTitle.add( "黄钻等级:" ); listItemTitle.add( "VIP等级:" ); listItemTitle.add( "是否是年黄钻:" ); listItemTitle.add( "出生日期:" ); listItemTitle.add( "所在地:" ); return listItemTitle; } public List<String> getQQWBuserInfoContent(){ List<String> listItemContent= new ArrayList<String>(); SharedPreferences share= this .getSharedPreferences( "qqwbuser" , Context.MODE_PRIVATE); listItemContent.add(share.getString( "nick" , "" )); listItemContent.add(share.getString( "nickname" , "" )); listItemContent.add(share.getString( "wbcount" , "" )); listItemContent.add(share.getString( "gender" , "" )); if (share.getInt( "is_yellow_vip" , 10 )== 0 ){ listItemContent.add( "否" ); } else { listItemContent.add( "是" ); } if (share.getInt( "vip" , 10 )== 0 ){ listItemContent.add( "否" ); } else { listItemContent.add( "是" ); } if (share.getInt( "yellow_vip_level" , 10 )== 0 ){ listItemContent.add( "否" ); } else { listItemContent.add( "是" ); } if (share.getInt( "level" , 10 )== 0 ){ listItemContent.add( "否" ); } else { listItemContent.add( "是" ); } if (share.getInt( "is_yellow_year_vip" , 10 )== 0 ){ listItemContent.add( "否" ); } else { listItemContent.add( "是" ); } listItemContent.add(share.getString( "birthday" , "" )); listItemContent.add(share.getString( "location" , "" )); return listItemContent; } class UserInfoAdapter extends BaseAdapter{ LayoutInflater layoutInflater; List<String> listItemTitle; List<String> listItemContent; public UserInfoAdapter(List<String> listItemTitle,List<String> listItemContent){ this .listItemTitle=listItemTitle; this .listItemContent=listItemContent; layoutInflater=(LayoutInflater) YLC_Main. this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { // TODO Auto-generated method stub return listItemTitle.size(); } @Override public Object getItem( int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId( int position) { // TODO Auto-generated method stub return position; } @Override public View getView( int position, View contentview, ViewGroup parent) { // TODO Auto-generated method stub UserInfoViewHolder viewholder; if (contentview== null ){ viewholder= new UserInfoViewHolder(); contentview=layoutInflater.inflate(R.layout.activity_ylc_userinfo, parent, false ); viewholder.tv1=(TextView) contentview.findViewById(R.id.textView_item); viewholder.tv2=(TextView) contentview.findViewById(R.id.textView_content); contentview.setTag(viewholder); } else { viewholder=(UserInfoViewHolder) contentview.getTag(); } viewholder.tv1.setText(listItemTitle.get(position)); viewholder.tv2.setText(listItemContent.get(position)); return contentview; } } static class UserInfoViewHolder{ TextView tv1; TextView tv2; } } |
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)