移动混合开发之android文件管理新建文件和删除文件
今天经过一天超过8小时的实践,有很多CSS上的细节需要注意:
1,
/*注意是对before的操作*/
.content ul li .icon-check-empty:before{
display: block;
/*webFont设置其width和height时无效,只有设置font-size*/
/*width: 3rem;*/
/*height: 3rem;*/
font-size: 1.5rem;
position: absolute;
top:0;
left: 0;
bottom: 0;
padding: .75rem;
}
2.选择器的优先级
/*估计这个优先级没有 .down a{}的高,所以根本没执行
a.btn{} > .down a{} > .down a.btn{}
*/
/*.down a.btn{*/
/*background: lavender;*/
/*border: solid 1px grey;*/
/*border-radius: 5px;*/
/*padding: 5px;*/
/*}*/
.opeator a{
/*使用felx:1让内容平均分布*/
flex:1;
-webkit-box-flex: 1;
/*把webFont当作字体处理,字体居中*/
text-align: center;
text-decoration: none;
display: block; }
3.动画的设置
需要设置一个初始状态和结束状态,
.opeator{
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 3rem;
/*容器使用 display:felx属性*/
display:flex;
display: -webkit-flex; /* */
/*注意是transform*/
transition:-webkit-transform 0.3s ease-in;
transform: translateY(0) translateZ(0);
} .opeator.down {
transform: translateY(3rem) translateZ(0);
}
全部代码:
1.index.html
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
Some notes:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta charset="utf-8">
<meta name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<!--引入webFont,fontello.css里面已经定义好font-family,只是需要设置类名,单独写css控制位置即可-->
<link rel="stylesheet" type="text/css" href="./css/css/fontello.css">
<link rel="stylesheet" type="text/css" href="css/index.css"><br>
<!----引入jQuery----!>
<!--引入滑动第三方库,让列表滑动-->
<script type="text/javascript" src="js/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="js/iscroll-lite.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<title>Hello World</title>
</head>
<body>
<div id="log"></div>
<div class="head">
极客浏览器
</div>
<!--自定义布局,没有使用第三方框架-->
<div class="content">
<div class="nav">
<div id="current-dir"></div>
<div id="upper">上一级</div>
</div>
<div class="list" id="file-list">
<ul >
<li class="t">
<div class="icon-check-empty" id="check"></div>
<div class="file-icon"></div>
<div class="file-name">This is file name1</div>
</li>
</ul>
</div>
<div class="opeator" id="operator-nocheck">
<!--写好类名,类名可查看fontello下载的demo-->
<a class="icon-plus">新建</a>
<a class="icon-info">详细</a>
</div>
<div class="opeator" id="operator-checked" style="display: none">
<!--写好类名,类名可查看fontello下载的demo-->
<a class="icon-move">移动</a>
<a class="icon-docs">复制</a>
<a class="icon-trash-empty">删除</a>
</div> <div class="opeator down" id="operator-down" >
<a class="btn" id="confirm">确定</a>
<a class="btn" id="cancel">取消</a>
</div>
</div>
<div id="dialog-overlay">
<div id="title"></div>
<div id="dialogContent">
<!--注意采用div布局-->
<div id="input-content">
<input type="text" id="file-name-input" placeholder="输入文件夹名">
</div>
<!--注意采用div布局,这样css会简写很多-->
<div id="btn-content">
<a class="btn" id="file-create">创建文件夹</a>
<a class="btn" id="file-cancel">取消</a>
</div>
</div>
</div>
</body>
</html>
2.index.css
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
* {
-webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
} .head{
position:absolute;
left:0;
right:0;
top:0;
height:2rem;
line-height: 2rem;
background-color:orange;
padding-left:.3rem;
color: white;
text-align: center;
} .content{
position:absolute;
top:2rem;
bottom:0;
left:0;
right:0;
overflow: hidden;
}
.content .nav{
position: absolute;
top: 0;
height: 1.5rem;
left: 0;
right: 0;
background: #efefef;
} .content .list{
position: absolute;
top: 1.5rem;
left: 0;
right: 0;
bottom: 3rem;
background: #adadad;
overflow: hidden;
} .opeator{
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 3rem;
/*容器使用 display:felx属性*/
display:flex;
display: -webkit-flex; /* */
/*注意是transform*/
transition:-webkit-transform 0.3s ease-in;
transform: translateY(0) translateZ(0);
} .opeator.down {
transform: translateY(3rem) translateZ(0);
} a{
-webkit-user-select: none;
user-select: none;
} a.touchInside{
background: lightgray;
color: whitesmoke;
} .opeator a{
/*使用felx:1让内容平均分布*/
flex:1;
-webkit-box-flex: 1;
/*把webFont当作字体处理,字体居中*/
text-align: center;
text-decoration: none;
display: block; } .content ul{
list-style: none;
padding: 0;
margin: 0;
} .content ul li{
position: relative;
height: 3rem;
border-bottom: 1px solid gray;
background: white;
} .content ul li.touchInside{
background: #efefef;
} /*注意是对before的操作*/
.content ul li .icon-check-empty:before{
display: block;
/*webFont设置其width和height时无效,只有设置font-size*/
/*width: 3rem;*/
/*height: 3rem;*/
font-size: 1.5rem;
position: absolute;
top:0;
left: 0;
bottom: 0;
padding: .75rem;
}
.content ul li .icon-ok-squared:before{
display: block;
/*webFont设置其width和height时无效,只有设置font-size*/
/*width: 3rem;*/
/*height: 3rem;*/
font-size: 1.5rem;
position: absolute;
top:0;
left: 0;
bottom: 0;
padding: .75rem;
color: greenyellow;
} .content ul li .file-icon{
position: absolute;
background: url("../img/file.png") no-repeat center;
background-size: 1.5rem 1.5rem;
width: 1.5rem;
height: 1.5rem;
left: 3rem;
top:.75rem;
} .content ul li .file-name{
position: absolute;
line-height: 3rem;
left: 5rem;
} .t{
display: none;
}
#upper{
position: absolute;
right: 15px;
top: 5px;
color: blue;
} #log{
width: 200px;
height: 30px;
color: red;
float: right;
} /*重新定义图标位置*/
.icon-plus:before{
display: block;
padding-top: 10px;
/*这个会使字体不居中,直接指定fontSize就好*/
/*width: .3rem;*/
font-size: 1.2rem;
} .icon-info:before{
display: block;
padding-top: 10px;
/*这个会使字体不居中,直接指定fontSize就好*/
font-size: 1.2rem;
} .icon-move:before{
display: block;
padding-top: 10px;
/*这个会使字体不居中,直接指定fontSize就好*/
font-size: 1.2rem;
}
.icon-docs:before{
display: block;
padding-top: 10px;
/*这个会使字体不居中,直接指定fontSize就好*/
font-size: 1.2rem;
} .icon-trash-empty:before{
display: block;
padding-top: 10px;
/*这个会使字体不居中,直接指定fontSize就好*/
font-size: 1.2rem;
} #dialog-overlay{
display: none;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.3);
} #title{
font-size: 1rem;
height: 1rem;
padding: .3rem;
text-align: center;
} #dialogContent{
text-align: center;
background: #efefef;
height: 8rem;
position: absolute;
left: 0;
bottom: 0;
right: 0;
} #input-content{
padding-top: 2rem;
padding-bottom: 1rem;
} #file-name-input{
width: 16rem;
padding: .3rem .4rem;
font-size: 1rem;
} /*估计这个优先级没有 .down a{}的高,所以根本没执行
a.btn{} > .down a{} > .down a.btn{}
*/
/*.down a.btn{*/
/*background: lavender;*/
/*border: solid 1px grey;*/
/*border-radius: 5px;*/
/*padding: 5px;*/
/*}*/ a#confirm {
line-height:3rem;
} a#cancel{
line-height: 3rem;
} a.btn{
background: lavender;
border: solid 1px grey;
border-radius: 5px;
padding: 5px;
} a.btn.touchInside{
background: lightgray;
color: whitesmoke;
} #btn-content{
text-align: center;
padding: .3rem;
}
3.index.js
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var app = {
// Application Constructor
initialize: function () {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function () {
// app.receivedEvent('deviceready');
$(function () {
myDeviceReady();
});
},
// Update DOM on a Received Event
receivedEvent: function (id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id);
}
}; app.initialize();
var myscroll = null; function myDeviceReady() {
var size = $(window).width() / 18
//设计字体宽度
$('html').css('font-size', size);
myscroll = new IScroll("#file-list");
//打开文件夹
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function (entry) {
fileDealer.openEntry(entry);
}, function () {
alert('fail');
}); //删除文件夹
$('.icon-trash-empty').bindtouch(function () {
var down = $('#operator-down');
down.data('action','delete');
down.removeClass('down');
}); //创建文件夹
$('.icon-plus').bindtouch(function () {
$('#dialog-overlay').css('display', 'block');
});
//fileDiolog
$('#file-create').bindtouch(function () {
// val获取value值
var fileName = $('#file-name-input').val();
if (fileName.length == 0 || fileName == undefined) {
return;
}
var curEntry = $('#current-dir').data('curEntry');
console.log(curEntry);
console.log(fileDealer);
fileDealer.createFile(curEntry, fileName);
}); $('#file-cancel').bindtouch(function () {
// alert('取消创建');
$('#dialog-overlay').css('display', 'none');
}); //confirm dialog
// 确定
$('#confirm').bindtouch(function () {
var down = $('#operator-down');
down.addClass('down');
var action = down.data('action');
console.log(action);
if (action == 'delete'){
$('.icon-ok-squared').each(function () {
var entry = $(this).parent().data('entry');
console.log(entry);
function success() {
console.log('文件删除成功!');
var curEntry = $('#current-dir').data('curEntry');
fileDealer.openEntry(curEntry);
}
function fail() {
alert('删除失败');
} if (entry.isFile) {
entry.remove(success, fail);
} else {
entry.removeRecursively(success, fail)
} });
}
});
// 取消
$('#cancel').bindtouch(function () {
$('#operator-down').addClass('down');
});
} function fileHander() { } /*--------------------创建文件夹-------------*/ fileHander.prototype.createFile = function (entry, filename) {
console.log(1);
entry.getDirectory('./' + filename, {create: true}, function (dirEntry) {
console.log('创建成功!');
$('#dialog-overlay').css('display', 'none');
var curEntry = $('#current-dir').data('curEntry');
fileDealer.openEntry(curEntry);
}, function () {
alert('创建失败!');
});
} /*-------------------打开文件夹---------------------*/
fileHander.prototype.openEntry = function (entry) {
//使用克隆方式时,重新更新页面不能用,$('#file-list ul ).html(");
$('#file-list ul li.item').remove();
var curren_dir = $('#current-dir');
curren_dir.text("当前目录:" + entry.name)
curren_dir.data("curEntry", entry); $('#upper').bindtouch(
function () {
entry.getParent(function (entry) {
fileDealer.openEntry(entry);
}, function () {
alert('get Parent Error');
}
);
}
); entry.createReader().readEntries(function (entries) {
sortEntrise(entries);
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
//采用克隆方式,比较方便
var jObjectLi = $('.t').clone().removeClass('t').addClass('item');
jObjectLi.find('.file-name').text(entry.name);
//注意绑定事件在这里,不然没反应....
jObjectLi.find('#check').bindtouch(function () {
changeCheckState.bind(this)();
changeOperatorState();
}, true);
jObjectLi.data('entry', entry);
$('.list ul').append(jObjectLi);
jObjectLi.bindtouch(function () {
var liEntry = $(this).data('entry');
if (!liEntry.isFile) {
fileDealer.openEntry(liEntry);
}
});
}
myscroll.refresh();
},
function (error) {
alert(error);
});
} var fileDealer = new fileHander(); function changeCheckState() {
var me = $(this);
if (me.hasClass('icon-check-empty')) {
me.removeClass('icon-check-empty');
me.addClass('icon-ok-squared');
} else {
me.addClass('icon-check-empty');
me.removeClass('icon-ok-squared');
}
} function changeOperatorState() {
var checkedOpera = $('#operator-checked');
var unChckOpera = $('#operator-nocheck'); if ($('.icon-ok-squared').length > 0) {
checkedOpera.show();
unChckOpera.hide();
} else {
checkedOpera.hide();
unChckOpera.show();
}
} //将文件和文件夹分离
function sortEntrise(entries) {
entries.sort(function (a, b) {
if (a.isFile && !b.isFile) {
return 1;
} else if (!a.isFile && b.isFile) {
return -1;
} else {
return a.name < b.name;
}
})
} /*------------添加点击事件--------------*/
//扩展为jQuery自定义函数 $.fn.bindtouch = function (cb, bubble) {
attachMyEvent($(this), cb, bubble);
}; function attachMyEvent(sr, cb, bubble) {
//click事件反应时间为300毫秒,因此取消click采用手动
//手指按下,若手指移动,则触发取消
sr.unbind();
var point_one = {};
var point_two = {};
sr.on('touchstart', function (event) {
var me = $(this)
me.data('touch', true);
var touch = event.originalEvent.targetTouches[0];
point_one.x = touch.pageX;
point_one.y = touch.pageY;
me.addClass('touchInside');
if (bubble) {
event.stopPropagation();
}
}); sr.on('touchend', function (event) {
var me = $(this);
if (me.data('touch') == true) {
//改变回调函数的this指针为sr
//触发回调函数
cb.bind(this)();
}
me.removeClass('touchInside')
me.data('touch', false);
if (bubble) {
event.stopPropagation();
}
}); sr.on('touchmove', function (event) {
var me = $(this);
var touch = event.originalEvent.targetTouches[0];
point_two.x = touch.pageX;
point_two.y = touch.pageY;
if (me.data('touch')) {
//华为手机测试,没有滑动也会触发touchmove,所以加测滑动距离,来判断是否滑动
var distane = getPointsDistance(point_one, point_two);
console.log(distane);
$('#log').text(distane);
if (distane > 4) {
me.data('touch', false);
me.removeClass('touchInside')
}
}
if (bubble) {
event.stopPropagation();
}
// alert(2);
});
}
//计算两点之间距离
function getPointsDistance(p1, p2) {
var xDistance = Math.abs(p1.x - p2.x);
var yDistance = Math.abs(p1.y - p2.y);
var distance = Math.sqrt(xDistance * xDistance + yDistance * yDistance);
return distance;
}
移动混合开发之android文件管理新建文件和删除文件的更多相关文章
- 移动混合开发之android文件管理-->flexbox,webFont。
增加操作栏,使用felxbox居中,felx相关参考网址:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html 使用webFont添加图标, ...
- 移动混合开发之android文件管理demo
框架采用cordova,android编译环境为android studio.系统为mac,cordova 环境搭建参考网址:http://cordova.apache.org/docs/en/5.0 ...
- Android混合开发之WebView与Javascript交互
前言: 最近公司的App为了加快开发效率选择了一部分功能采用H5开发,从目前市面的大部分App来讲,大致分成Native App.Web App.Hybrid App三种方式,个人觉得目前以Hybri ...
- Android混合开发之WebView使用总结
前言: 今天修改项目中一个有关WebView使用的bug,激起了我总结WebView的动机,今天抽空做个总结. 混合开发相关博客: Android混合开发之WebView使用总结 Android混合开 ...
- Android混合开发之WebViewJavascriptBridge实现JS与java安全交互
前言: 为了加快开发效率,目前公司一些功能使用H5开发,这里难免会用到Js与Java函数互相调用的问题,这个Android是提供了原生支持的,不过存在安全隐患,今天我们来学习一种安全方式来满足Js与j ...
- C#结合js 上传文件和删除文件(技术点有:asp.net mvc ,nhibernate,ajax等)
之前做项目的时候要用到上传文件的功能,现在我总结一下,上传文件和删除文件的代码,在以后的使用的过程中也更方便查找. [HttpPost] public ActionResult EditUser() ...
- ASP FSO操作文件(复制文件、重命名文件、删除文件、替换字符串)
ASP FSO操作文件(复制文件.重命名文件.删除文件.替换字符串)FSO的意思是FileSystemObject,即文件系统对象.FSO对象模型包含在Scripting 类型库 (Scrrun.Dl ...
- 无法为数据库 XXX 中的对象XXX 分配空间,因为 'PRIMARY' 文件组已满。请删除不需要的文件、删除文件组中的对象、将其他文件添加到文件组或为文件组中的现有文件启用自动增长,以便增加可用磁盘空间。
无法为数据库 XXX 中的对象XXX 分配空间,因为 'PRIMARY' 文件组已满.请删除不需要的文件.删除文件组中的对象.将其他文件添加到文件组或为文件组中的现有文件启用自动增长,以便增加可用磁盘 ...
- 深入理解linux关闭文件和删除文件
背景介绍 最近看了linux系统编程(linux system programming)一书,结合深入理解linux内核(understanding the linux kernel)一书,深入理解了 ...
随机推荐
- [分享] 封装工具ES4配置文件解释
[分享] 封装工具ES4配置文件解释 LiQiang 发表于 2015-2-3 14:41:21 https://www.itsk.com/thread-346132-1-4.html [分享] 封装 ...
- 【第1期】腾讯云的1001种玩法征集,Ipad mini和Kindle 等你拿!(文章评审中)
版权声明:本文由阁主的小跟班原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/695994001482226944 来源:腾云 ...
- 电子爱好者DIY篇
2016/7/15 电子爱好者DIY篇 一年和之前就想到了一些感悟,现在有些模糊的清晰起来了,但还是不够清晰,故写下来做个日志. 结论 首先把结论放在前面.目前随着电子集成电路的发展,电子DIY越来越 ...
- SPSS数据分析—两阶段最小二乘法
传统线性模型的假设之一是因变量之间相互独立,并且如果自变量之间不独立,会产生共线性,对于模型的精度也是会有影响的.虽然完全独立的两个变量是不存在的,但是我们在分析中也可以使用一些手段尽量减小这些问题产 ...
- React学习系列一
系列学习react 翻译地址 https://scotch.io/tutorials/learning-react-getting-started-and-concepts 我是初学者,英语也不是很好 ...
- 错误 java.lang.ClassCastException: com.ylpw.sms.YZZYSenderUtil cannot be cast to ResourceBundle
出现错误: java.lang.ClassCastException: com.ylpw.sms.YZZYSenderUtil cannot be cast to ResourceBundle 百度搜 ...
- Node.js的cluster模块——Web后端多进程服务
众所周知,Node.js是单线程的,一个单独的Node.js进程无法充分利用多核.Node.js从v0.6.0开始,新增cluster模块,让Node.js开发Web服务时,很方便的做到充分利用多核机 ...
- 深度讲解VIEWPORT和PX是什么?移动端单位px,em,rem
刚开始接触移动页面重构,是不是很迷惑应该按照多大的尺寸制作?320.640还是720?按照640的设计稿重构完页面,是不是还需要写其他尺寸来适配不同的屏幕大小?—— 这源于对viewport和px的不 ...
- Andriod SDK Manager 安装问题解决方法
(一)AndriodSDKManager无法自动下载安装包 无法访问dl-ssl-google.com 只需在hosts文件中增加 203.208.49.162 dl-ssl.google ...
- Tomcat内存优化参数
set JAVA_OPTS=-Xms512m -Xmx512m -XX:PermSize=128M -XX:MaxNewSize=128m -XX:MaxPermSize=128m 在catalina ...