好吧,这是下半部分==,上半部分请看《Android TTS实现简单阅读器(一)》。
3)公共工具
这个也贴出来吧==。
GlobalUtil.java
-
-
-
-
- public final class GlobalUtil {
-
-
- static class GlobalUtilHolder {
- static GlobalUtil instance = new GlobalUtil();
- }
-
-
- public static GlobalUtil getInstance() {
- return GlobalUtilHolder.instance;
- }
-
-
- public Display getDisplay(Context mContext) {
- WindowManager wm = (WindowManager) mContext
- .getSystemService(Context.WINDOW_SERVICE);
- return wm.getDefaultDisplay();
- }
-
-
- public enum AnimMode {
- UP_IN, UP_OUT, DOWN_IN, DOWN_OUT, LEFT_IN, LEFT_OUT, RIGHT_IN, RIGHT_OUT
- };
-
-
-
-
-
-
-
-
- public void startTransAnim(View v, AnimMode animMode, long durationMillis) {
- int w = v.getWidth(), h = v.getHeight();
- float fromXDelta = 0, toXDelta = 0, fromYDelta = 0, toYDelta = 0;
- switch (animMode) {
- case UP_IN:
- fromYDelta = -h;
- break;
- case UP_OUT:
- toYDelta = -h;
- break;
- case DOWN_IN:
- fromYDelta = h;
- break;
- case DOWN_OUT:
- toYDelta = h;
- break;
- case LEFT_IN:
- fromXDelta = -w;
- break;
- case LEFT_OUT:
- toXDelta = -w;
- break;
- case RIGHT_IN:
- fromXDelta = w;
- break;
- case RIGHT_OUT:
- toXDelta = w;
- break;
- }
- TranslateAnimation transAnim = new TranslateAnimation(fromXDelta,
- toXDelta, fromYDelta, toYDelta);
- transAnim.setDuration(durationMillis);
- v.startAnimation(transAnim);
- }
-
-
-
-
-
-
-
-
-
- public String is2Str(InputStream is, String encoding)
- throws UnsupportedEncodingException {
-
-
-
-
- InputStreamReader isReader = new InputStreamReader(is, encoding);
-
- StringBuffer out = new StringBuffer();
- try {
- char[] b = new char[4096];
- for (int n; (n = isReader.read(b)) != -1;) {
- out.append(b, 0, n);
- }
- return out.toString();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "";
- }
-
-
-
-
-
-
-
-
- public String is2Str(FileInputStream fis)
- throws UnsupportedEncodingException {
-
- BufferedInputStream bis = new BufferedInputStream(fis);
-
- String encoding = getIsEncoding(bis);
-
- BufferedReader reader = new BufferedReader(new InputStreamReader(bis,
- encoding));
-
- StringBuffer out = new StringBuffer();
- try {
- for (String s; (s = reader.readLine()) != null;) {
- out.append(s);
- out.append("\n");
- }
- return out.toString();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return "";
- }
-
-
-
-
-
-
-
-
-
-
-
- public String getIsEncoding(InputStream is) {
- String code = "GB2312";
-
- if (is.markSupported()) {
- try {
- is.mark(5);
- byte[] head = new byte[3];
- is.read(head);
- if (head[0] == -1 && head[1] == -2)
- code = "UTF-16";
- if (head[0] == -2 && head[1] == -1)
- code = "Unicode";
- if (head[0] == -17 && head[1] == -69 && head[2] == -65)
- code = "UTF-8";
- is.reset();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return code;
- }
-
- }
四、阅读器截图
1
)进入画面.png
![应用图标.png]()
2
)长按屏幕.png
![应用图标.png]()
3
)自带two.txt.png
![应用图标.png]()
4
)“浏览…
操作”的截图
![浏览...(1).png]()
浏览...(1).png
![浏览...(1).png]()
浏览...(2).png
![浏览...(1).png]()
浏览...(3).png
五、后记
直接读大文本,后果自负啊。(没做控制呢T^T)
ps:应用的入口图标
,可爱吧^^。
附件:http://down.51cto.com/data/2360079
本文转自winorlose2000 51CTO博客,原文链接:http://blog.51cto.com/vaero/809876,如需转载请自行联系原作者