HfztbAcitivity
package linpeng.ztb;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.opengl.Visibility;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.HorizontalScrollView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class HfztbActivity extends Activity implements OnClickListener {
private GridView xml_gridview;
private ListView xml_newslist;
private Button foot_loadmore, prepare_refresh, gotoright, up, down,
gotoother, gotoother2, gotoother3, gotoother4, gotoother5;
private TextView foot_text;
private ProgressBar foot_progressbar;
private HorizontalScrollView horizontalScrollView;
private SimpleAdapter listview_adapter;
private ProgressBar refresh;
private String list_button = "title1";
private int changenewslist = 1;
private int[][] location = new int[5][2];
private boolean fist_open_title1 = true, fist_open_title2 = true,
fist_open_title3 = true, fist_open_title4 = true,
fist_open_title5 = true, goto_other_visiably = false;//fist_open_title6 = true,
//fist_open_title7 = true,
private boolean is_first_open = true;
private final int FLINGDIS = 900;
private List> newslist = new ArrayList>();
private List> tempnewslist = new ArrayList>();
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.arg1 > -1) {
prepare_refresh.setVisibility(0);
refresh.setVisibility(8);
Log.i("list_button", new IntToStrong().getname(msg.arg1)
+ list_button);
changeFirstOpen(msg.arg1);
if (list_button.equals(new IntToStrong().getname(msg.arg1))) {
getNewsList(msg.arg1, false);
}
}
if (msg.arg1 == -1) {
prepare_refresh.setVisibility(0);
refresh.setVisibility(8);
Toast.makeText(HfztbActivity.this, "网络不通,请稍候再试",
Toast.LENGTH_SHORT).show();
}
}
private void changeFirstOpen(int arg1) {
if (arg1 == 0 && fist_open_title1) {
fist_open_title1 = false;
} else if (arg1 == 1 && fist_open_title2) {
fist_open_title2 = false;
} else if (arg1 == 2 && fist_open_title3) {
fist_open_title3 = false;
} else if (arg1 == 3 && fist_open_title4) {
fist_open_title4 = false;
} else if (arg1 == 4 && fist_open_title5) {
fist_open_title5 = false;
// } else if (arg1 == 5 && fist_open_title6) {
// fist_open_title6 = false;
// } else if (arg1 == 6 && fist_open_title7) {
// fist_open_title7 = false;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
xml_gridview = (GridView) findViewById(R.id.xml_gridview);
xml_gridview.setSelector(new ColorDrawable(Color.TRANSPARENT));
xml_newslist = (ListView) findViewById(R.id.newslist);
prepare_refresh = (Button) findViewById(R.id.prepare_refresh);
refresh = (ProgressBar) findViewById(R.id.refresh);
gotoright = (Button) findViewById(R.id.gotoright);
horizontalScrollView = (HorizontalScrollView) findViewById(R.id.horizontalScrollView);
up = (Button) findViewById(R.id.up);
down = (Button) findViewById(R.id.down);
gotoother = (Button) findViewById(R.id.gotoother);
gotoother2 = (Button) findViewById(R.id.gotoother2);
gotoother3 = (Button) findViewById(R.id.gotoother3);
gotoother4 = (Button) findViewById(R.id.gotoother4);
gotoother5 = (Button) findViewById(R.id.gotoother5);
LayoutInflater layoutInflater = getLayoutInflater();
View footView = layoutInflater.inflate(R.layout.foot, null);
xml_newslist.addFooterView(footView);
foot_loadmore = (Button) findViewById(R.id.foot_loadmore);
foot_text = (TextView) findViewById(R.id.foot_text);
foot_progressbar = (ProgressBar) findViewById(R.id.foot_progressbar);
foot_loadmore.setOnClickListener(this);
prepare_refresh.setOnClickListener(this);
gotoright.setOnClickListener(this);
up.setOnClickListener(this);
down.setOnClickListener(this);
gotoother.setOnClickListener(this);
gotoother2.setOnClickListener(this);
gotoother3.setOnClickListener(this);
gotoother4.setOnClickListener(this);
gotoother5.setOnClickListener(this);
getNewsList(0, false);
SimpleAdapter gridview_adapter = new SimpleAdapter(this,
new ListData().getGridviewdata(), R.layout.gridview,
new String[] { "grid_title" }, new int[] { R.id.grid_title });
listview_adapter = new SimpleAdapter(this, newslist,
R.layout.newslistdetails, new String[] { "news_isend",
"news_title", "news_time" }, new int[] {
R.id.news_isend, R.id.news_title, R.id.news_time });
is_first_open = false;
xml_gridview.setAdapter(gridview_adapter);
xml_gridview.setOnItemClickListener(new onGridViewItemClick());
xml_newslist.setOnItemClickListener(new onListViewItemClick());
xml_newslist.setAdapter(listview_adapter);
}
private void getloction() {
gotoother.getLocationOnScreen(location[0]);
gotoother2.getLocationOnScreen(location[1]);
gotoother3.getLocationOnScreen(location[2]);
gotoother4.getLocationOnScreen(location[3]);
gotoother5.getLocationOnScreen(location[4]);
Log.i("x", location[0][0] + " " + location[0][1]);
}
private void getNewsList(int table_number, boolean is_fresh) {
boolean has_fresh = false;
String table_name = new IntToStrong().getname(table_number);
DataBaseHelper dbh = new DataBaseHelper(this, table_name, null, 1);
SQLiteDatabase sql = dbh.getReadableDatabase();
Cursor cursor = sql.query(table_name, new String[] { "newsclass",
"newstitle", "newstime", "isread" }, "newsclass>?",
new String[] { "-1" }, null, null, null);
if (cursor.getCount() != 0 && is_fresh == false) {
newslist.clear();
getNewsListByDatabase(cursor);
prepare_refresh.setVisibility(0);
refresh.setVisibility(8);
if (!is_first_open) {
listview_adapter.notifyDataSetChanged();
xml_newslist.setSelection(0);
list_button = new IntToStrong().getname(table_number);
}
} else {
list_button = new IntToStrong().getname(table_number);
MyThread myThread = new MyThread(table_number, HfztbActivity.this);
has_fresh = true;
myThread.start();
}
if (!has_fresh) {
reFresh(table_name, table_number);
}
if (sql != null) {
sql.close();
}
if (dbh != null) {
dbh.close();
}
}
private void reFresh(String table_name, int table_number) {
if (fist_open_title1 && table_name == "title1") {
MyThread myThread = new MyThread(table_number, HfztbActivity.this);
myThread.start();
} else if (fist_open_title2 && table_name == "title2") {
MyThread myThread = new MyThread(table_number, HfztbActivity.this);
myThread.start();
} else if (fist_open_title3 && table_name == "title3") {
MyThread myThread = new MyThread(table_number, HfztbActivity.this);
myThread.start();
} else if (fist_open_title4 && table_name == "title4") {
MyThread myThread = new MyThread(table_number, HfztbActivity.this);
myThread.start();
} else if (fist_open_title5 && table_name == "title5") {
MyThread myThread = new MyThread(table_number, HfztbActivity.this);
myThread.start();
//} else if (fist_open_title6 && table_name == "title6") {
// MyThread myThread = new MyThread(table_number, HfztbActivity.this);
// myThread.start();
//} else if (fist_open_title7 && table_name == "title7") {
// MyThread myThread = new MyThread(table_number, HfztbActivity.this);
// myThread.start();
}
}
private void getNewsListByDatabase(Cursor cursor) {
newslist.clear();
while (cursor.moveToNext()) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("news_title",
cursor.getString(cursor.getColumnIndex("newstitle")));
map.put("news_time",
cursor.getString(cursor.getColumnIndex("newstime")));
map.put("news_isend",
cursor.getString(cursor.getColumnIndex("isread")));
newslist.add(map);
}
}
class onGridViewItemClick implements OnItemClickListener {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
int table_number = arg2;
TextView gridviewback = (TextView) arg1;
for (int i = 0; i < arg0.getCount(); i++) {
TextView gridview_text_temp = (TextView) arg0.getChildAt(i);
gridview_text_temp.setBackgroundDrawable(null);
gridview_text_temp.setTextColor(getResources().getColor(
R.color.grid_title_color));
}
gridviewback.setBackgroundResource(R.drawable.gridviewbackground);
gridviewback.setTextColor(Color.WHITE);
if (arg2 >= 0 && arg2 <= 6) {
getNewsList(table_number, false);
Log.i("after", "thread");
}
}
}
class onListViewItemClick implements OnItemClickListener {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
DataBaseHelper dbh = new DataBaseHelper(HfztbActivity.this,
list_button, null, 1);
SQLiteDatabase sq = dbh.getReadableDatabase();
Cursor cursor = sq.query(list_button, new String[] { "newsclass",
"newstitle", "newstime", "isread", "url" }, "newsclass=?",
new String[] { arg2 + "" }, null, null, null);
cursor.moveToNext();
Intent intent = new Intent(HfztbActivity.this, News.class);// ��ת������ҳ
if (!cursor.isAfterLast()) {
intent.putExtra("newsurl",
cursor.getString(cursor.getColumnIndex("url")));
intent.putExtra("newstitle",
cursor.getString(cursor.getColumnIndex("newstitle")));
intent.putExtra("newstime",
cursor.getString(cursor.getColumnIndex("newstime")));
intent.putExtra("type", list_button);
startActivity(intent);
}
if (dbh != null) {
dbh.close();
sq.close();
}
}
}
public class MyThread extends Thread {
private int table_number;
private Context context;
public MyThread(int table_number, Context context) {
this.table_number = table_number;
this.context = context;
}
@Override
public void run() {
getNewsList(table_number);
}
protected void getNewsList(int table_number) {
try {
Document doc;
String url = "http://ggzy.jiangxi.gov.cn/jxzbw/jyxx/002004/00200400"
+ (table_number + 1) + "/MoreInfo.aspx?CategoryNum=00200400"+ (table_number + 1);
doc = Jsoup.connect(url).get();
new ListData().getListData(doc, table_number, context, url);
Message msg = handler.obtainMessage();
msg.arg1 = table_number;
handler.sendMessage(msg);
} catch (IOException e) {
Log.i("tag", "error");
Message msg = handler.obtainMessage();
msg.arg1 = -1;
handler.sendMessage(msg);
e.printStackTrace();
}
}
}
public void onClick(View v) {
if (v.getId() == foot_loadmore.getId()) {
foot_loadmore.setVisibility(8);
foot_text.setVisibility(0);
foot_progressbar.setVisibility(0);
}
if (v.getId() == prepare_refresh.getId()) {
prepare_refresh.setVisibility(8);
refresh.setVisibility(0);
getNewsList(new IntToStrong().table_name_to_int(list_button), true);
}
if (v.getId() == gotoright.getId()) {
horizontalScrollView.fling(FLINGDIS);
Log.i("" + horizontalScrollView.getScrollY(),
horizontalScrollView.getScrollX() + "");
}
if (v.getId() == up.getId()) {
xml_newslist.setSelection(0);
}
if (v.getId() == down.getId()) {
Log.i("asff", xml_newslist.getScrollY() + "");
xml_newslist.setSelection(1000);
}
if (v.getId() == gotoother.getId()) {
getloction();
if (!goto_other_visiably) {
setVisiablyAndAnimation(false, -1);
} else {
Log.i("x", location[0][0] + " " + location[0][1]);
setVisiablyAndAnimation(true, 0);
}
}
if (v.getId() == gotoother2.getId()) {
setVisiablyAndAnimation(false, 0);
}
if (v.getId() == gotoother3.getId()) {
setVisiablyAndAnimation(false, 1);
}
if (v.getId() == gotoother4.getId()) {
setVisiablyAndAnimation(false, 2);
}
if (v.getId() == gotoother5.getId()) {
setVisiablyAndAnimation(false, 3);
}
}
private void setVisiablyAndAnimation(boolean b, int which) {
if (!b && which > -1) {
ScaleAnimation[] scaleAnimations = getScaleAnimation(which);
gotoother2.startAnimation(scaleAnimations[0]);
gotoother3.startAnimation(scaleAnimations[1]);
gotoother4.startAnimation(scaleAnimations[2]);
gotoother5.startAnimation(scaleAnimations[3]);
gotoother2.setVisibility(8);
gotoother3.setVisibility(8);
gotoother4.setVisibility(8);
gotoother5.setVisibility(8);
goto_other_visiably = false;
} else if (which == -1) {
TranslateAnimation[] translateAnimations = getTranslateAnimation(which);
gotoother2.startAnimation(translateAnimations[0]);
gotoother3.startAnimation(translateAnimations[1]);
gotoother4.startAnimation(translateAnimations[2]);
gotoother5.startAnimation(translateAnimations[3]);
gotoother2.setVisibility(0);
gotoother3.setVisibility(0);
gotoother4.setVisibility(0);
gotoother5.setVisibility(0);
goto_other_visiably = true;
} else {
TranslateAnimation[] translateAnimations = getTranslateAnimation(which);
gotoother2.startAnimation(translateAnimations[0]);
gotoother3.startAnimation(translateAnimations[1]);
gotoother4.startAnimation(translateAnimations[2]);
gotoother5.startAnimation(translateAnimations[3]);
gotoother2.setVisibility(8);
gotoother3.setVisibility(8);
gotoother4.setVisibility(8);
gotoother5.setVisibility(8);
goto_other_visiably = false;
}
}
private TranslateAnimation[] getTranslateAnimation(int which) {
TranslateAnimation[] translateAnimations = new TranslateAnimation[4];
if (which == -1) {
translateAnimations[0] = new TranslateAnimation(Animation.ABSOLUTE,
location[0][0] - location[1][0],
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][1] - location[1][1],
Animation.RELATIVE_TO_SELF, 0f);
translateAnimations[1] = new TranslateAnimation(Animation.ABSOLUTE,
location[0][0] - location[2][0],
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][1] - location[2][1],
Animation.RELATIVE_TO_SELF, 0f);
translateAnimations[2] = new TranslateAnimation(Animation.ABSOLUTE,
location[0][0] - location[3][0],
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][1] - location[3][1],
Animation.RELATIVE_TO_SELF, 0f);
translateAnimations[3] = new TranslateAnimation(Animation.ABSOLUTE,
location[0][0] - location[4][0],
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][1] - location[4][1],
Animation.RELATIVE_TO_SELF, 0f);
translateAnimations[0].setDuration(100);
translateAnimations[1].setDuration(150);
translateAnimations[2].setDuration(200);
translateAnimations[3].setDuration(250);
} else {
translateAnimations[0] = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][0] - location[1][0],
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][1] - location[1][1]);
translateAnimations[1] = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][0] - location[2][0],
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][1] - location[2][1]);
translateAnimations[2] = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][0] - location[3][0],
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][1] - location[3][1]);
translateAnimations[3] = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][0] - location[4][0],
Animation.RELATIVE_TO_SELF, 0f, Animation.ABSOLUTE,
location[0][1] - location[4][1]);
translateAnimations[0].setDuration(250);
translateAnimations[1].setDuration(200);
translateAnimations[2].setDuration(150);
translateAnimations[3].setDuration(100);
}
return translateAnimations;
}
private ScaleAnimation[] getScaleAnimation(int which) {
ScaleAnimation[] scaleAnimations = new ScaleAnimation[4];
scaleAnimations[0] = new ScaleAnimation(1, 0.1f, 1, 0.1f);
scaleAnimations[1] = new ScaleAnimation(1, 0.1f, 1, 0.1f);
scaleAnimations[2] = new ScaleAnimation(1, 0.1f, 1, 0.1f);
scaleAnimations[3] = new ScaleAnimation(1, 0.1f, 1, 0.1f);
scaleAnimations[which] = new ScaleAnimation(1, 1.7f, 1, 1.7f);
scaleAnimations[0].setDuration(150);
scaleAnimations[1].setDuration(150);
scaleAnimations[2].setDuration(150);
scaleAnimations[3].setDuration(150);
return scaleAnimations;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Builder builder = new Builder(this);
builder.setMessage("确定退出吗?");
builder.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
});
builder.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}
return true;
}
}
Listdata
package linpeng.ztb;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;
public class ListData {
public List> getGridviewdata() {
List> list = new ArrayList>();
HashMap hash = new HashMap();
hash.put("grid_title", "采购公告");
list.add(hash);
hash = new HashMap();
hash.put("grid_title", "变更公告");
list.add(hash);
hash = new HashMap();
hash.put("grid_title", "答疑澄清");
list.add(hash);
hash = new HashMap();
hash.put("grid_title", "结果公示");
list.add(hash);
hash = new HashMap();
hash.put("grid_title", "单一来源");
list.add(hash);
//hash = new HashMap();
//hash.put("grid_title", "标前公示ʾ");
//list.add(hash);
//hash = new HashMap();
//hash.put("grid_title", "巢湖");
//list.add(hash);
return list;
}
public void getListData(Document doc, int table_number, Context context,
String url) {
try {
Element ele = doc.select("td[height=500]").first();
Elements eles = ele.select("a");
int newsclass = 0;
String table_name = new IntToStrong().getname(table_number);
if (ele.text().length() > 1) {
DataBaseHelper dbh = new DataBaseHelper(context, table_name,
null, 1);
Log.i("shanchu", "ca");
dbh.dellAll();
}
if (table_number != 3 && table_number != 5) {
for (Element ele2 : eles) {
String inittext = ele2.text();
String isend = "报名结束";
String changetext = inittext.replace("【正在报名】", "");// 替换文中的【正在报名】
String newsurl = ele2.attr("abs:href");
if (changetext.length() != inittext.length()) {
isend = "正在报名";
} else {
changetext = changetext.replace("【报名结束】", "");// 替换文中的【报名结束】
}
if (ele2.text().replace("更多信息", "").length() >= 2) {
DataBaseHelper dbh = new DataBaseHelper(context,
table_name, null, 1);
SQLiteDatabase sqh = dbh.getWritableDatabase();
dbh.addnewslist(newsclass, changetext, ele2.parent()
.parent().select("td").last().text(), isend,
newsurl);
newsclass++;
}
}
} else {
for (Element ele2 : eles) {
String inittext = ele2.text();
String newsurl = ele2.attr("abs:href");
String name = new IntToStrong().getname(table_number);
if (ele2.text().replace("更多信息", "").length() >= 2) {
DataBaseHelper dbh = new DataBaseHelper(context, name,
null, 1);
SQLiteDatabase sqh = dbh.getWritableDatabase();
dbh.addnewslist(newsclass, inittext, ele2.parent()
.parent().select("td").last().text(), "",
newsurl);
newsclass++;
}
}
}
} catch (Exception e) {
Log.i("s", "网络不通");
// Toast.makeText(context, "网络不通,请稍候再试",Toast.LENGTH_SHORT).show();
}
}
}
NEWS
package linpeng.ztb;
import java.util.HashMap;
import java.util.Map;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.R.integer;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RemoteViews.ActionException;
import android.widget.TextView;
import android.widget.Toast;
public class News extends Activity {
private TextView news_details_text, news_details_title, news_details_time;
private ProgressBar news_details_progress;
private int flag = 1, arg2, text_size;// flag=1表示从网络获取数据=0表示从数据库获取数据
private String kind, url;
private String newsdetailstext = "", downloadtext = "",
downloadaddress = "", type;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.arg1) {
case 1:
if (newsdetailstext.length() > 3) {
putData();
} else {
Toast.makeText(News.this, "网络不通,请稍后再试", Toast.LENGTH_SHORT)
.show();
}
news_details_text.setText(newsdetailstext);
news_details_progress.setVisibility(8);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.news);
Intent intent = getIntent();
SharedPreferences s = getSharedPreferences("text_size", 0);
text_size = s.getInt("text_size", 20);
url = intent.getStringExtra("newsurl");
type = intent.getStringExtra("type");
String newstitle = intent.getStringExtra("newstitle");
String newstime = intent.getStringExtra("newstime");
news_details_text = (TextView) findViewById(R.id.news_details_text);
news_details_title = (TextView) findViewById(R.id.news_details_title);
news_details_time = (TextView) findViewById(R.id.news_details_time);
news_details_progress = (ProgressBar) findViewById(R.id.news_details_progress);
news_details_progress.setVisibility(0);
news_details_title.setText(newstitle);
news_details_time.setText(newstime);
news_details_text.setTextSize(text_size);
flag = 0;
DataBaseHelper dbh = new DataBaseHelper(this,
new IntToStrong().TypeToType(type), null, 1);
SQLiteDatabase sql = dbh.getReadableDatabase();
Cursor cursor = sql.query(new IntToStrong().TypeToType(type),
new String[] { "newsurl", "newstitle", "newstime",
"newsdetails", "newsdownloadtext1", "newsdownloadurl1",
"newsdownloadtext2", "newsdownloadurl2" }, "newsurl=?",
new String[] { url }, null, null, null);
cursor.moveToNext();
if (cursor.getCount() == 0) {
new NewsThread().start();
} else {
news_details_text.setText(cursor.getString(cursor
.getColumnIndex("newsdetails")));
news_details_progress.setVisibility(8);
}
if (sql != null) {
sql.close();
}
}
protected void putData() {
DataBaseHelper dbh = new DataBaseHelper(this,
new IntToStrong().TypeToType(type), null, 1);
SQLiteDatabase sql = dbh.getWritableDatabase();
dbh.addetails(url, news_details_title.getText().toString(),
news_details_time.getText().toString(), newsdetailstext, null,
null, null, null);
if (dbh != null) {
dbh.close();
sql.close();
}
}
private void getNews() {
try {
String host = android.net.Proxy.getDefaultHost();
int port = android.net.Proxy.getDefaultPort();
Document doc = Jsoup.connect(url).get();
Element ele = doc.getElementById("TDContent");
int j = 1;
if (ele.children().text().length() < 2) {
System.out.println(1);
newsdetailstext = newsdetailstext + ele.text();
}
for (Element ele2 : ele.children()) {
j++;
newsdetailstext = newsdetailstext + ele2.text();
newsdetailstext = newsdetailstext + "\n";
newsdetailstext = newsdetailstext + "\n";
}
if (j == 2) {
newsdetailstext = "";
for (Element ele2 : ele.children()) {
for (Element ele3 : ele2.children()) {
System.out.println(3);
newsdetailstext = newsdetailstext + ele3.text();
newsdetailstext = newsdetailstext + "\n";
newsdetailstext = newsdetailstext + "\n";
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private class NewsThread extends Thread {
@Override
public void run() {
getNews();
Message msg = handler.obtainMessage();
msg.arg1 = 1;
handler.sendMessage(msg);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(menu.NONE, 1, 1, "字体大小");
menu.add(menu.NONE, 2, 1, "使用浏览器打开此页面");
menu.add(menu.NONE, 3, 1, "拨打此页面中电话");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
Builder builder = new Builder(this);
builder.setTitle("字体大小");
builder.setSingleChoiceItems(new String[] { "大", "中", "小" },
new IntToStrong().text_size_to_order(text_size),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
news_details_text.setTextSize(24);
SharedPreferences sp = getSharedPreferences(
"text_size", 0);
sp.edit().putInt("text_size", 24).commit();
dialog.cancel();
} else if (which == 1) {
news_details_text.setTextSize(20);
SharedPreferences sp = getSharedPreferences(
"text_size", 0);
sp.edit().putInt("text_size", 20).commit();
dialog.cancel();
} else if (which == 2) {
news_details_text.setTextSize(16);
SharedPreferences sp = getSharedPreferences(
"text_size", 0);
sp.edit().putInt("text_size", 16).commit();
dialog.cancel();
}
}
});
builder.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
break;
case 2:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
break;
case 3:
Builder builder2=new Builder(this);
Map telephone=getTelePhone();
//LayoutInflater inflater=getLayoutInflater();
//View layout=inflater.inflate(R.layout.telephone,(ViewGroup)findViewById(R.id.news_tele));
Intent intent1 = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+ telephone.get("tele"+1)));
startActivity(intent1);
//builder2.setView(layout);
//builder2.show();
break;
default:
break;
}
return true;
}
private Map getTelePhone() {
Map telephone = new HashMap<String, String>();
if (news_details_text.length() > 5) {
int temp_index_telephone=1;
String text = news_details_text.getText().toString();
for (int i = 1; i <= text.length() - 1; i++) {
if (text.charAt(i) == '电' && text.charAt(i + 1) == '话'
|| text.charAt(i) == '电'
&& text.charAt(i + 2) == '话') {
int k = 3;
if(text.charAt(i+2)=='话'){
k=4;
}
String temp_telephone="";
while (text.charAt(i + k) == '1'
|| text.charAt(i + k) == '2'
|| text.charAt(i + k) == '3'
|| text.charAt(i + k) == '4'
|| text.charAt(i + k) == '5'
|| text.charAt(i + k) == '6'
|| text.charAt(i + k) == '7'
|| text.charAt(i + k) == '8'
|| text.charAt(i + k) == '9'
|| text.charAt(i + k) == '-'
|| text.charAt(i + k) == '0') {
temp_telephone=temp_telephone+text.charAt(i+k);
k++;
}
if(temp_telephone.length()>5){
temp_telephone=temp_telephone.replace("-","");
telephone.put("tele"+temp_index_telephone, temp_telephone);
Log.i("sasaa", "" + temp_telephone);
temp_index_telephone++;
temp_telephone="";
}
}
}
}
return telephone;
}
}