package com.ldci.stock.view;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import com.ldci.stock.handler.StockHandler;
import com.ldci.stock.info.StockInfo;
import com.ldci.stock.tools.Constant;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AutoCompleteTextView;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements Runnable {
ImageButton searchButton; // 声明对象
AutoCompleteTextView editTextView;// 声明对象
TextView stockId, stockName, priceTime, newPrice, stockIncrease, openPrice,
upDownPrice, lowestPrice, highestPrice, upDown, transactionVolume,
transactionVolumePrice, raceBuyPrice, raceSalePrice, delegation,
buy1, buy2, buy3, buy4, buy5, sale1, sale2, sale3, sale4, sale5;// 声明对象
String temp; // 临时存储数据
Constant constant; // 声明工具类对象
StockHandler stockHandler; // 解析时用的handler
URL url; //声明URL对象
StockInfo stockInfo;
ProgressDialog progressDialog; //对话框对象
public static String id; // 变量ID
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//强制竖屏
setContentView(R.layout.main);// 显示布局
findView();//找到组件
searchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) { // 按钮事件
brush();
}
});
}
public void brush(){
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setTitle("正在处理……");
progressDialog.setMessage("请稍等……");
progressDialog.setIcon(R.drawable.k);
progressDialog.show(); // 设置对话框内容,并显示
id = null; // id是空
Thread thread = new Thread(MainActivity.this); // 因为实现了 Runnable接口
thread.start(); // 启动
new Thread(new Runnable() {
int i = 0;
@Override
public void run() {
while(true){
i++;
if (stockHandler.isHanlderOK) {
progressDialog.dismiss();
handler.sendEmptyMessage(0);
stockHandler.isHanlderOK=false;
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(i == 5){
progressDialog.dismiss();
break;
}
}
}
}).start();
}
public void findView() { // 查找对象
searchButton = (ImageButton) findViewById(R.id.SearchButton);
editTextView = (AutoCompleteTextView) findViewById(R.id.autoTextView);
stockId = (TextView) findViewById(R.id.stockId);
stockName = (TextView) findViewById(R.id.stockName);
priceTime = (TextView) findViewById(R.id.priceTime);
newPrice = (TextView) findViewById(R.id.newPrice);
stockIncrease = (TextView) findViewById(R.id.stockIncrease);
openPrice = (TextView) findViewById(R.id.openPrice);
upDownPrice = (TextView) findViewById(R.id.upDownPrice);
lowestPrice = (TextView) findViewById(R.id.lowestPrice);
highestPrice = (TextView) findViewById(R.id.highestPrice);
upDown = (TextView) findViewById(R.id.upDown);
transactionVolume = (TextView) findViewById(R.id.transactionVolume);
transactionVolumePrice = (TextView) findViewById(R.id.transactionVolumePrice);
raceBuyPrice = (TextView) findViewById(R.id.raceBuyPrice);
raceSalePrice = (TextView) findViewById(R.id.raceSalePrice);
delegation = (TextView) findViewById(R.id.delegation);
buy1 = (TextView) findViewById(R.id.buy1);
buy2 = (TextView) findViewById(R.id.buy2);
buy3 = (TextView) findViewById(R.id.buy3);
buy4 = (TextView) findViewById(R.id.buy4);
buy5 = (TextView) findViewById(R.id.buy5);
sale1 = (TextView) findViewById(R.id.sale1);
sale2 = (TextView) findViewById(R.id.sale2);
sale3 = (TextView) findViewById(R.id.sale3);
sale4 = (TextView) findViewById(R.id.sale4);
sale5 = (TextView) findViewById(R.id.sale5);
}
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
setView();
id = stockHandler.str[0];
}
};
public void setView() {
// stockName.setText(stockHandler.str[1]);
Log.d("aaa", "" + stockHandler.str.length);
stockId.setText(stockHandler.str[0]);
stockName.setText(stockHandler.str[1]);
priceTime.setText("行情时间:" + stockHandler.str[2]);
newPrice.setText("最新价格:" + stockHandler.str[3]);
stockIncrease.setText("昨收盘:" + stockHandler.str[4]);
openPrice.setText("今开盘:" + stockHandler.str[5]);
upDownPrice.setText("涨跌额:" + stockHandler.str[6]);
lowestPrice.setText("最低:" + stockHandler.str[7]);
highestPrice.setText("最高:" + stockHandler.str[8]);
upDown.setText("涨跌幅:" + stockHandler.str[9]);
transactionVolume.setText("成交量:" + stockHandler.str[10]);
transactionVolumePrice.setText("成交额:" + stockHandler.str[11]);
raceBuyPrice.setText("竞买价:" + stockHandler.str[12]);
raceSalePrice.setText("竞卖价:" + stockHandler.str[13]);
delegation.setText("委比:" + stockHandler.str[14]);
buy1.setText("买1:" + stockHandler.str[15]);
buy2.setText("买2:" + stockHandler.str[16]);
buy3.setText("买3:" + stockHandler.str[17]);
buy4.setText("买4:" + stockHandler.str[18]);
buy5.setText("买5:" + stockHandler.str[19]);
sale1.setText("卖1:" + stockHandler.str[20]);
sale2.setText("卖2:" + stockHandler.str[21]);
sale3.setText("卖3:" + stockHandler.str[22]);
sale4.setText("卖4:" + stockHandler.str[23]);
sale5.setText("卖5:" + stockHandler.str[24]);
}
@Override
public void run() {
Log.d("url", "---------------------------------");
temp = editTextView.getText().toString(); // 从文本框中,输入的数据,放到temp中
try {
url = new URL(constant.URL + temp);
Log.d("url", constant.URL + temp);
// 1.得到一个SAX工厂
SAXParserFactory spf = SAXParserFactory.newInstance();
// 2.通过工厂获取SAX解析器对象
SAXParser sp = spf.newSAXParser();
// 3.通过解析器获取XMLReader
XMLReader xr = sp.getXMLReader();
// 4.创建Handler对象
stockHandler = new StockHandler();
xr.setContentHandler(stockHandler);
// 5.解析XML
InputStreamReader si = new InputStreamReader(url.openStream(),
"UTF-8"); // 创建给定字符集InputStreamReader(url.openStream( 打开到此
// URL 的连接并返回一个用于从该连接读入的 InputStrea))
InputSource is = new InputSource(si);
xr.parse(is);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
menu.add(1, 1, 1, "刷新").setIcon(R.drawable.s);
menu.add(1, 2, 2, "K线图").setIcon(R.drawable.k);
menu.add(1, 3, 3, "分时图").setIcon(R.drawable.f);
menu.add(1, 4, 4, "关于").setIcon(R.drawable.about)
没有合适的资源?快使用搜索试试~ 我知道了~
Android股票源码
共61个文件
class:31个
png:11个
java:7个
2星 需积分: 50 71 下载量 124 浏览量
2014-11-05
21:07:28
上传
评论 2
收藏 364KB RAR 举报
温馨提示
Android手机股票K线图查询系统源码Android手机上的股票K线图查询系统的源码,完整工程文件,可以显示K线图和分时图,可以正常编译运行,有完整注释。
资源推荐
资源详情
资源评论
收起资源包目录
stock.rar (61个子文件)
stock
bin
classes.dex 21KB
stock.apk 178KB
com
ldci
stock
handler
StockHandler.class 2KB
tools
Constant.class 576B
view
KAcitivity$2.class 2KB
MainActivity.class 10KB
MainActivity$7.class 875B
MainActivity$3.class 1KB
MainActivity$2.class 803B
KAcitivity$4.class 863B
KAcitivity$3.class 863B
MainActivity$1.class 904B
KAcitivity.class 4KB
FAcitivity$1.class 1001B
FAcitivity.class 4KB
R$layout.class 447B
R$id.class 1KB
R$drawable.class 637B
KAcitivity$6.class 863B
KAcitivity$1.class 1KB
R$attr.class 343B
R.class 538B
FAcitivity$2.class 2KB
MainActivity$4.class 875B
MainActivity$5.class 875B
MainActivity$6.class 1KB
FAcitivity$3.class 863B
R$string.class 430B
FAcitivity$4.class 863B
KAcitivity$5.class 1KB
FAcitivity$5.class 1KB
FAcitivity$6.class 863B
info
StockInfo.class 544B
resources.ap_ 167KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
a.png 12KB
h.png 8KB
f.png 8KB
about.png 8KB
icon.png 4KB
t.png 9KB
top.png 19KB
back.jpg 91KB
s.png 8KB
k.png 8KB
values
strings.xml 181B
drawable-mdpi
icon.png 3KB
layout
f.xml 806B
main.xml 10KB
k.xml 806B
assets
default.properties 364B
gen
com
ldci
stock
view
R.java 3KB
src
com
ldci
stock
handler
StockHandler.java 1KB
tools
Constant.java 329B
view
FAcitivity.java 5KB
MainActivity.java 10KB
KAcitivity.java 5KB
info
StockInfo.java 204B
.project 841B
.classpath 280B
AndroidManifest.xml 917B
共 61 条
- 1
资源评论
- yhengf_5202016-07-28接口已经不能用了!
昵称以被占用
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功