各种调用代码

百度地图

<com.baidu.mapapi.map.MapView  
        android:id="@+id/bmapView"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:clickable="true"
        android:layout_weight="1"
        />
 
  

 

异步任务

public class MyAsynctask extends AsyncTask<String, Integer, String> {
//定义变量
HttpURLConnection connection;
protected String doInBackground(String... params){
StringBuffer buffer=null;
try {
URL url = new URL(params[0]);
//打开连接
connection = (HttpURLConnection) url.openConnection();
//超时
connection.setConnectTimeout(10*1000);
//判断返回值是否正确
if(connection.getResponseCode()==200){
InputStream is= connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
buffer = new StringBuffer();
String str;
while((str=reader.readLine())!=null){
buffer.append(str);
}
is.close();
reader.close();
connection.disconnect();
System.out.println("-----------请求到的数据:::"+buffer.toString());
}
} catch (MalformedURLException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return buffer.toString();
}
}

 
  

网络请求数据http

public static String getJSONStr(String urlStr) {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(urlStr);
try {
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == 200) {
return EntityUtils.toString(response.getEntity(),"utf-8");
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

 
  

imageloader图片加载

public class ImageUtils {

public void imageUrl(final ImageView imageView,String path) {
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_launcher)
.showImageOnFail(R.drawable.ic_launcher)
.showImageOnLoading(R.drawable.ic_launcher)
.cacheInMemory(true)
.cacheOnDisk(true)
.build();
ImageSize imageSize = new ImageSize(100, 100);
ImageLoader.getInstance().loadImage(path, imageSize, options, new SimpleImageLoadingListener(){
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
imageView.setImageBitmap(loadedImage);
}
}) ;
}
}
public class ImageApplication extends Application{

@Override
public void onCreate() {
ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this).build();
ImageLoader.getInstance().init(configuration);
}
}

 
  

分享

//分享
private UMSocialService mController;
mController = UMServiceFactory.getUMSocialService("com.umeng.login");
//设置新浪SSO handler
mController.getConfig().setSsoHandler(new SinaSsoHandler());
//参数1为当前Activity, 参数2为开发者在QQ互联申请的APP ID,参数3为开发者在QQ互联申请的APP kEY.
UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(this, "100424468",
"c7394704798a158208a74ab60104f0ba");
qqSsoHandler.addToSocialSDK();
//参数1为当前Activity, 参数2为开发者在QQ互联申请的APP ID,参数3为开发者在QQ互联申请的APP kEY.
QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(this, "100424468",
"c7394704798a158208a74ab60104f0ba");
qZoneSsoHandler.addToSocialSDK();
mController.openShare(InfoActivity.this, false);

Intent intent = getIntent();
String des = intent.getStringExtra("des");
Log.i("url", des);
WebView web =(WebView) findViewById(R.id.webView);
web.loadUrl(des);
web.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
return super.shouldOverrideUrlLoading(view, url);
}
});
Button share = (Button) findViewById(R.id.share);
Button qq = (Button) findViewById(R.id.qq);
Button xinlang = (Button) findViewById(R.id.xinlang);
Button qqkong = (Button) findViewById(R.id.qqkong);
share.setOnClickListener(this);
qq.setOnClickListener(this);
xinlang.setOnClickListener(this);
qqkong.setOnClickListener(this);
switch (v.getId()) {
case R.id.share:
LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
ll.setVisibility(View.VISIBLE);
break;
case R.id.qq:
shareData(SHARE_MEDIA.QQ);
break;
case R.id.xinlang:
shareData(SHARE_MEDIA.SINA);
break;
case R.id.qqkong:
shareData(SHARE_MEDIA.QZONE);
break;
default:
break;
}
private void shareData(SHARE_MEDIA platform) {

mController.doOauthVerify(InfoActivity.this, platform, new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA platform) {
Toast.makeText(InfoActivity.this, "授权开始", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(SocializeException e, SHARE_MEDIA platform) {
Toast.makeText(InfoActivity.this, "授权错误", Toast.LENGTH_SHORT).show();
}
@Override
public void onComplete(Bundle value, SHARE_MEDIA platform) {
Toast.makeText(InfoActivity.this, "授权完成", Toast.LENGTH_SHORT).show();
//获取相关授权信息
mController.getPlatformInfo(InfoActivity.this, platform, new UMDataListener() {
@Override
public void onStart() {
Toast.makeText(InfoActivity.this, "获取平台数据开始...", Toast.LENGTH_SHORT).show();
}
@Override
public void onComplete(int status, Map<String, Object> info) {
if(status == 200 && info != null){
StringBuilder sb = new StringBuilder();
Set<String> keys = info.keySet();
for(String key : keys){
sb.append(key+"="+info.get(key).toString()+"\r\n");
}
Log.d("TestData",sb.toString());
}else{
Log.d("TestData","发生错误:"+status);
}
}
});
}
@Override
public void onCancel(SHARE_MEDIA platform) {
Toast.makeText(InfoActivity.this, "授权取消", Toast.LENGTH_SHORT).show();
}
} );
//设置分享内容
mController.setShareContent("友盟社会化组件(SDK)让移动应用快速整合社交分享功能, http://www.umeng.com/social");
//设置分享图片
mController.setShareMedia(new UMImage(InfoActivity.this, "http://www.umeng.com/images/pic/banner_module_social.png"));
//直接分享
mController.directShare(InfoActivity.this, platform,
new SnsPostListener() {
@Override
public void onStart() {
Toast.makeText(InfoActivity.this, "分享开始",Toast.LENGTH_SHORT).show();
}
@Override
public void onComplete(SHARE_MEDIA platform,int eCode, SocializeEntity entity) {
if(eCode == StatusCode.ST_CODE_SUCCESSED){
Toast.makeText(InfoActivity.this, "分享成功",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(InfoActivity.this, "分享失败",Toast.LENGTH_SHORT).show();
}
}

});
}

 
  

xml解析

public class ParseXML {

private static Tweet tweet;

public static List<Tweet> getData(InputStream is) {

List<Tweet> list = new ArrayList<Tweet>();
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(is, "utf-8");
int eventType = parser.getEventType();
String tagName = null;
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
// 开始解析文档
case XmlPullParser.START_DOCUMENT:
break;
// 解析到开始标签
case XmlPullParser.START_TAG:
// 得到正在解析的元素标签名
tagName = parser.getName();
// 判断正在解析的元素标签名是否是person
if (tagName.equals("tweet")) {// 标签名是person
// 创建Person的对象
tweet = new Tweet();
}
break;
// 解析到文本
case XmlPullParser.TEXT:
// 得到当前正在解析的文本内容
String text = parser.getText();
// 判断正在解析的文本内容是哪个元素节点里的
if (tagName.equals("id")) {
tweet.setId(Integer.parseInt(text));
} else if (tagName.equals("portrait")) {
tweet.setPortrait(text);
} else if (tagName.equals("author")) {
tweet.setAuthor(text);
} else if (tagName.equals("body")) {
tweet.setBody(text);
} else if (tagName.equals("pubDate")) {
tweet.setPubDate(text);
}else if (tagName.equals("imgSmall")) {
tweet.setImgSmall(text);
}
break;
// 解析到结束标签
case XmlPullParser.END_TAG:
// 得到正在解析的元素标签名
tagName = parser.getName();
// 判断正在解析的元素标签名是否是person
if (tagName.equals("tweet")) {// 如果结束标签解析到了person,说明解析完了
// 把person对象装进集合
list.add(tweet);
tweet = null;
}
tagName = "";
break;
// 文档解析结束
case XmlPullParser.END_DOCUMENT:
break;
}
// 本次事件处理完毕,进入下一个节点:下一个事件
eventType = parser.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
}

 
  

设置圆角图片

DisplayImageOptions options = new DisplayImageOptions.Builder()
.displayer(new RoundedBitmapDisplayer(90)) // 设置成圆角图片
.build();

 
  

进度条显示请求网络的过程

1、声明变量
private Handler handler = new Handler();
private ProgressDialog progressDialog = null;

   2、在开始进行网络连接时显示进度条对话框
   progressDialog = ProgressDialog.show(MyActivity.this, "请稍等...", "获取数据中...", true);

   3、在handler.post中进行界面更新
public void setListAdapter(){
handler.post(new Runnable() {
public void run() {
//将获取到的数据更新到列表中
MyListView.setAdapter(saImageItems);
}
}
});

4、开个新的线程进行网络连接获取数据
new Thread(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
//向服务器请求数据
mapList=MyAPI.getAllDatas();
setListAdapter(mapList);
//更新完列表数据,则关闭对话框
progressDialog.dismiss();
}}).start();

 
  

转载于:https://www.cnblogs.com/nanze/p/5403704.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值