在好例子网,分享、交流、成长!
您当前所在位置:首页Java 开发实例Android平台开发 → android ebup电子书阅读 例子源码

android ebup电子书阅读 例子源码

Android平台开发

下载此实例
  • 开发语言:Java
  • 实例大小:24.75M
  • 下载次数:27
  • 浏览次数:352
  • 发布时间:2016-10-30
  • 实例类别:Android平台开发
  • 发 布 人:lijiao
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 电子书 阅读

实例介绍

【实例简介】

【实例截图】

【核心代码】

package com.lj.filenamager;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.lj.filenamager.util.ClearEditText;
import com.lj.filenamager.util.GetImgName;
import com.lj.filenamager.util.MyAdspter;
import com.lj.filenamager.util.sql.DBHelper;
import com.lj.filenamager.util.sql.DBManager;
import com.lj.filenamager.util.tree.Bean;
import com.lj.filenamager.util.tree.FileBean;
import com.lj.filenamager.util.tree.TreeListViewAdapter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
	private List<Bean> mDatas = new ArrayList<Bean>();
	private List<FileBean> mDatas2 = new ArrayList<FileBean>();
	private ListView mTree;
	private TreeListViewAdapter<FileBean> mAdapter;
	private String infopath;
	private int fi = 0;
	private int i = 0;
	private ListView listView = null;
	List<Map<String, Object>> list = null;
	EditText editText = null;
	DBHelper dbHelper = null;
	DBManager dbManager=null;
	private SQLiteDatabase database;
	private ClearEditText inputsearch;
	public Handler mHandler = null;
	public List<Map<String, Object>> searchList = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) { 
		super.onCreate(savedInstanceState);

		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_main);
		listView = (ListView) findViewById(R.id.id_tree);
		editText = (EditText) findViewById(R.id.inputsearch);
		MyApplication myapplicaton = (MyApplication) getApplication();
		list = getData(((MyApplication) getApplication()).getInfopath());
		listView.setAdapter(new MyAdspter(this, list));
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				String name = list.get(arg2).get("title").toString();
				String end = name.substring(name.lastIndexOf(".")   1,
						name.length()).toLowerCase();
				if (end.equals("epub")) {
					Intent intent = new Intent();
					intent.setClass(MainActivity.this, EputActivity2.class);
					Bundle bundle = new Bundle();
					bundle.putString("pathfile",
							((MyApplication) getApplication()).getInfopath()
									  name);
					intent.putExtras(bundle);
					startActivity(intent);
				} else if (end.equals("doc")) {
					Intent intent = new Intent();
					intent.setClass(MainActivity.this, InformationScanViewFile.class);
				} else if(name.indexOf(".")==-1){
					((MyApplication) getApplication())
							.setInfopath(((MyApplication) getApplication())
									.getInfopath()   name   "/");
					((MyApplication) getApplication()).setFilepath(name   "/");
					Intent intent = new Intent();
					intent.setClass(MainActivity.this, MainActivity2.class);
					startActivity(intent);
				}else{
					
				}
			}
		});
		dbHelper = new DBHelper(this);
		mHandler = new Handler() {
			public void handleMesage(Message msg) {
				switch (msg.what) {
				case 1:
					editText.setFocusable(true);
					editText.setEnabled(true);
					break;
				case 2:
					listView.setAdapter(new MyAdspter(MainActivity.this, list));
					// 取回Adapter对象,用于调用notifyDataSetChanged方法。
					MyAdspter sAdapter = (MyAdspter) listView.getAdapter();
					sAdapter.notifyDataSetChanged();
					break;
				default:
					break;
				}
				super.handleMessage(msg);
			}
		};
		startThreadForData();
		searInputChangeListener();
	}

	/**
	 * 输入框搜索事件
	 */

	public void searInputChangeListener() {
		inputsearch = (ClearEditText) this.findViewById(R.id.inputsearch);
		inputsearch.addTextChangedListener(new TextWatcher() {
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// 当输入框里面的值为空,更新为原来的列表,否则为过滤数据列表
				if (s != null && !"".equals(s.toString())) {
					Intent intent = new Intent();
					intent.setClass(MainActivity.this, SearchActivity.class);
					Bundle bundle = new Bundle();
					bundle.putString("filename", s.toString());
					intent.putExtras(bundle);
					startActivity(intent);
				} else {
//					System.out.println("输入框为空");
				}

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
			}
		});
	}

	public void startThreadForData() {
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					dbHelper.createDataBase();
					dbHelper.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
				Message message = new Message();
				message.what = 1;
				mHandler.sendMessage(message);
			}
		}).start();
	}

	public List<Map<String, Object>> getData(String infopath) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		File file = new File(infopath);
		File[] files = file.listFiles();
		if (files != null && files.length > 0) {
			for (File f : files) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("title", f.getName());
				String imgName=GetImgName.getPropertiesURL(MainActivity.this, f.getName());
				if(imgName!=""){
					map.put("image", GetImgName.getImageResourceId(imgName));
				}else{
					map.put("image", R.drawable.p34);
				}
				list.add(map);
			}
		} else {
			Toast toast = Toast.makeText(MainActivity.this, "没有找到文件",
					Toast.LENGTH_SHORT);
			toast.show();
		}
		return list;
	}

}

标签: 电子书 阅读

实例下载地址

android ebup电子书阅读 例子源码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警