框架采用cordova,android编译环境为android studio.系统为mac,cordova 环境搭建参考网址:http://cordova.apache.org/docs/en/5.0.0/cordova/plugins/pluginapis.html#Plugin%20APIs

1.index.html

  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10.  
  11. http://www.apache.org/licenses/LICENSE-2.0
  12.  
  13. Unless required by applicable law or agreed to in writing,
  14. software distributed under the License is distributed on an
  15. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. KIND, either express or implied. See the License for the
  17. specific language governing permissions and limitations
  18. under the License.
  19. -->
  20. <html>
  21. <head>
  22. <!--
  23. Customize this policy to fit your own app's needs. For more guidance, see:
  24. https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
  25. Some notes:
  26. * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
  27. * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
  28. * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
  29. * Enable inline JS: add 'unsafe-inline' to default-src
  30. -->
  31. <meta http-equiv="Content-Security-Policy"
  32. content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
  33. <meta name="format-detection" content="telephone=no">
  34. <meta name="msapplication-tap-highlight" content="no">
  35. <meta charset="utf-8">
  36. <meta name="viewport"
  37. content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
  38. <link rel="stylesheet" type="text/css" href="css/index.css"><br>
  39. <!----引入jQuery----!>
  40. <!--引入滑动第三方库,让列表滑动-->
  41. <script type="text/javascript" src="js/jquery-2.2.4.min.js"></script>
  42. <script type="text/javascript" src="js/iscroll-lite.js"></script>
  43. <script type="text/javascript" src="cordova.js"></script>
  44. <script type="text/javascript" src="js/index.js"></script>
  45. <title>Hello World</title>
  46. </head>
  47. <body>
  48. <div id="log"></div>
  49. <div class="head">
  50. 浏览器
  51. </div>
  52. <!--自定义布局,没有使用第三方框架-->
  53. <div class="content">
  54. <div class="nav">
  55. <div id="current-dir"></div>
  56. <div id="upper">上一级</div>
  57. </div>
  58. <div class="list" id="file-list">
  59. <ul >
  60. <li class="t">
  61. <div class="file-icon"></div>
  62. <div class="file-name">This is file name1</div>
  63. </li>
  64. </ul>
  65. </div>
  66. </div>
  67. </body>
  68. </html>

  

2.index.js

  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. var app = {
  20. // Application Constructor
  21. initialize: function () {
  22. this.bindEvents();
  23. },
  24. // Bind Event Listeners
  25. //
  26. // Bind any events that are required on startup. Common events are:
  27. // 'load', 'deviceready', 'offline', and 'online'.
  28. bindEvents: function () {
  29. document.addEventListener('deviceready', this.onDeviceReady, false);
  30. },
  31. // deviceready Event Handler
  32. //
  33. // The scope of 'this' is the event. In order to call the 'receivedEvent'
  34. // function, we must explicitly call 'app.receivedEvent(...);'
  35. onDeviceReady: function () {
  36. // app.receivedEvent('deviceready');
  37. $(function () {
  38. myDeviceReady();
  39. });
  40. },
  41. // Update DOM on a Received Event
  42. receivedEvent: function (id) {
  43. var parentElement = document.getElementById(id);
  44. var listeningElement = parentElement.querySelector('.listening');
  45. var receivedElement = parentElement.querySelector('.received');
  46. listeningElement.setAttribute('style', 'display:none;');
  47. receivedElement.setAttribute('style', 'display:block;');
  48.  
  49. console.log('Received Event: ' + id);
  50. }
  51. };
  52.  
  53. app.initialize();
  54. var myscroll = null;
  55.  
  56. function myDeviceReady() {
  57. var size = $(window).width() / 18
  58. //设计字体宽度
  59. $('html').css('font-size', size);
  60. myscroll = new IScroll("#file-list");
  61. //打开文件夹
  62. window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function (entry) {
  63. openEntry(entry);
  64. }, function () {
  65. alert('fail');
  66. });
  67. }
  68.  
  69. /*<li>
  70. <div class="file-icon"></div>
  71. <div class="file-name">This is file name1</div>
  72. </li>*/
  73.  
  74. function openEntry(entry) {
  75. //使用克隆方式时,重新更新页面不能用,$('#file-list ul ).html(");
  76. $('#file-list ul li.item').remove();
  77. $('#current-dir').text("当前目录:" + entry.name);
  78. $('#upper').bindtouch(
  79. function () {
  80. entry.getParent(function (entry) {
  81. openEntry(entry);
  82. }, function () {
  83. alert('get Parent Error');
  84. });
  85. }
  86. );
  87.  
  88. entry.createReader().readEntries(function (entries) {
  89. sortEntrise(entries);
  90. for (var i = 0; i < entries.length; i++) {
  91. var entry = entries[i];
  92. //采用克隆方式,比较方便
  93. var jObjectLi = $('.t').clone().removeClass('t').addClass('item');
  94. jObjectLi.find('.file-name').text(entry.name);
  95. jObjectLi.data('entry', entry);
  96. $('.list ul').append(jObjectLi);
  97. jObjectLi.bindtouch(function () {
  98. var liEntry = $(this).data('entry');
  99. if (!liEntry.isFile) {
  100. openEntry(liEntry);
  101. }
  102. });
  103. }
  104. myscroll.refresh();
  105. },
  106. function (error) {
  107. alert(error);
  108. });
  109. }
  110.  
  111. //将文件和文件夹分离
  112. function sortEntrise(entries) {
  113. entries.sort(function (a, b) {
  114. if (a.isFile && !b.isFile) {
  115. return 1;
  116. } else if (!a.isFile && b.isFile) {
  117. return -1;
  118. } else {
  119. return a.name < b.name;
  120. }
  121. })
  122. }
  123.  
  124. //扩展为jQuery自定义函数
  125.  
  126. $.fn.bindtouch = function (cb) {
  127. attachMyEvent($(this), cb);
  128. };
  129.  
  130. var timeID = null;
  131.  
  132. function attachMyEvent(sr, cb) {
  133. //click事件反应时间为300毫秒,因此取消click采用手动
  134. //手指按下,若手指移动,则触发取消
  135. sr.unbind();
  136. clearTimeout(timeID);
  137. var point_one = {};
  138. var point_two = {};
  139. sr.on('touchstart', function (event) {
  140. var me = $(this)
  141. me.data('touch', true);
  142. var touch = event.originalEvent.targetTouches[0];
  143. point_one.x = touch.pageX;
  144. point_one.y = touch.pageY;
  145. //设计timeID如果点下时滑动就不用触发
  146. timeID = setTimeout(function () {
  147. me.addClass('touchInside');
  148. }, 100);
  149. });
  150.  
  151. sr.on('touchend', function () {
  152. clearTimeout(timeID);
  153. var me = $(this);
  154. if (me.data('touch') == true) {
  155. //改变回调函数的this指针为sr
  156. //触发回调函数
  157. cb.bind(this)();
  158. }
  159. me.removeClass('touchInside')
  160. me.data('touch', false);
  161. });
  162.  
  163. sr.on('touchmove', function (event) {
  164. var me = $(this);
  165. var touch = event.originalEvent.targetTouches[0];
  166. point_two.x = touch.pageX;
  167. point_two.y = touch.pageY;
  168. if (me.data('touch')) {
  169. //华为手机测试,没有滑动也会触发touchmove,所以加测滑动距离,来判断是否滑动
  170. var distane = getPointsDistance(point_one, point_two);
  171. console.log(distane);
  172. $('#log').text(distane);
  173. if (distane > 4) {
  174. me.data('touch', false);
  175. clearTimeout(timeID);
  176. me.removeClass('touchInside')
  177. }
  178. }
  179.  
  180. // alert(2);
  181. });
  182. }
  183. //计算两点之间距离
  184. function getPointsDistance(p1, p2) {
  185. var xDistance = Math.abs(p1.x - p2.x);
  186. var yDistance = Math.abs(p1.y - p2.y);
  187. var distance = Math.sqrt(xDistance * xDistance + yDistance * yDistance);
  188. return distance;
  189. }

  

3.index.css

  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. * {
  20. -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
  21. }
  22.  
  23. .head{
  24. position:absolute;
  25. left:0;
  26. right:0;
  27. top:0;
  28. height:2rem;
  29. line-height: 2rem;
  30. background-color:orange;
  31. padding-left:.3rem;
  32. color: white;
  33. text-align: center;
  34. }
  35.  
  36. .content{
  37. position:absolute;
  38. top:2rem;
  39. bottom:0;
  40. left:0;
  41. right:0
  42. }
  43. .content .nav{
  44. position: absolute;
  45. top: 0;
  46. height: 1.5rem;
  47. left: 0;
  48. right: 0;
  49. background: #efefef;
  50. }
  51.  
  52. .content .list{
  53. position: absolute;
  54. top: 1.5rem;
  55. left: 0;
  56. right: 0;
  57. bottom: 0;
  58. background: #adadad;
  59. overflow: hidden;
  60. }
  61.  
  62. .content ul{
  63. list-style: none;
  64. padding: 0;
  65. margin: 0;
  66. }
  67.  
  68. .content ul li{
  69. position: relative;
  70. height: 4rem;
  71. line-height: 2rem;
  72. padding-left: .5rem ;
  73. border-bottom: 1px solid gray;
  74. background: white;
  75. }
  76. .content ul li.touchInside{
  77. background: #efefef;
  78. }
  79. .content ul li .file-icon{
  80. position: absolute;
  81. background: url("../img/file.png") no-repeat center;
  82. background-size: 1.2rem 1.2rem;
  83. width: 1.2rem;
  84. height: 1.2rem;
  85. left: 1rem;
  86. top:.3rem;
  87. }
  88. .content ul li .file-name{
  89. position: absolute;
  90. line-height: 2rem;
  91. left: 3.2rem;
  92. }
  93.  
  94. .t{
  95. display: none;
  96. }
  97. #upper{
  98. position: absolute;
  99. right: 15px;
  100. top: 5px;
  101. color: blue;
  102. }
  103.  
  104. #log{
  105. width: 200px;
  106. height: 30px;
  107. color: red;
  108. float: right;
  109. }

 在html编写之前,先在终端下载好cordova-file插件,同时注意开起真机设备的或模拟器的 文件存储权限,具体路径为:设置-->应用管理->高级 ->应用权限->存储,  这个要千万注意,不然打不开sdk内容。

移动混合开发之android文件管理demo的更多相关文章

  1. 移动混合开发之android文件管理新建文件和删除文件

    今天经过一天超过8小时的实践,有很多CSS上的细节需要注意: 1, /*注意是对before的操作*/ .content ul li .icon-check-empty:before{ display ...

  2. 移动混合开发之android文件管理-->flexbox,webFont。

    增加操作栏,使用felxbox居中,felx相关参考网址:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html 使用webFont添加图标, ...

  3. Android混合开发之WebView与Javascript交互

    前言: 最近公司的App为了加快开发效率选择了一部分功能采用H5开发,从目前市面的大部分App来讲,大致分成Native App.Web App.Hybrid App三种方式,个人觉得目前以Hybri ...

  4. Android混合开发之WebViewJavascriptBridge实现JS与java安全交互

    前言: 为了加快开发效率,目前公司一些功能使用H5开发,这里难免会用到Js与Java函数互相调用的问题,这个Android是提供了原生支持的,不过存在安全隐患,今天我们来学习一种安全方式来满足Js与j ...

  5. Android混合开发之WebView使用总结

    前言: 今天修改项目中一个有关WebView使用的bug,激起了我总结WebView的动机,今天抽空做个总结. 混合开发相关博客: Android混合开发之WebView使用总结 Android混合开 ...

  6. 基于xmpp openfire smack开发之Android客户端开发[3]

    在上两篇文章中,我们依次介绍openfire部署以及smack常用API的使用,这一节中我们着力介绍如何基于asmack开发一个Android的客户端,本篇的重点在实践,讲解和原理环节,大家可以参考前 ...

  7. Android开发之AsyncTask示例Demo

    今天做了一个AsyncTask的小Demo,内含注释,通过此Demo,可以对AsyncTask有一个详细的了解 已经将项目上传到了GitHub上(程序有一个小bug,在第一次提交有说明,有解决方法请留 ...

  8. 混合开发之DSBridge(同时支持Android和iOS)

    什么是 Javascript bridge 随着h5的不断普及及优化,以及移动端对动态化的需求越来越大,开发者经常需要在app中嵌入一些网页,然后会在web和native之间进行交互,如传递数据,调用 ...

  9. Android 开发之Android 应用程序如何调用支付宝接口

    1.到支付宝官网,下载支付宝集成开发包 由于android设备一般用的都是无线支付,所以我们申请的就是支付宝无线快捷支付接口.下面是申请的地址以及下载接口开发包的网址:https://b.alipay ...

随机推荐

  1. 推荐两本学习linux的经典书籍

  2. Rdseed与SAC的安装

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  3. iOS —— 字典遍历排序

    字典NSDictionary一般的遍历方法都是: NSArray* arr = [yourdictonary allKeys]; for(NSString* str in arr) { NSLog(& ...

  4. TortoiseGit编辑全局变量支持https

    在windows,右键,进入tortoisegit的设置窗口,在左边树形菜单选Git,然后店"编辑全局.gid/config"按钮 输入以下文字 [http] sslVerify ...

  5. java 简单数组元素的增删改查

    public class Test { static int[] a = new int[20]; static int n; public static void main(String[] arg ...

  6. WinForm 公共控件

    一.窗体属性: 1.AcceptButton - 窗体的“接受”按钮.如果设置该属性,每次用户按“Enter”键都相当于“单击”了该按钮. 需要设置哪个键,就在后面选择. 2.CancelButton ...

  7. Windows 10系统更换Windows 7系统磁盘分区注意事项一

    新买的电脑预装系统是WIN10,考虑到兼容性问题,打算更换为WIN7,但在新机上不能直接装WIN7系统,需要在BIOS启动中做一点小改动. 原因分析:由于Windows 8采用的是UEFI引导和GPT ...

  8. category - junit用例分组执行

    一.category 和 testSuite的比较 (1)testSuite是类级分组(xx.class) (2)category是用例级分组(@Test) (3)category是testSuite ...

  9. github上面建立分支

    首先是有一个github的账户,然后随便开个项目. 好了,现在把git命令行打开,输入下面几行代码. git clone https://github.com/user/repository.git ...

  10. 1476. Lunar Code

    http://acm.timus.ru/problem.aspx?space=1&num=1476 由于前一列对后一列有影响,所以需要保持前一列的状态, 但无需用状态压缩来保存(也保存不了) ...