首页 文章 精选 留言 我的

精选列表

搜索[c 11],共10000篇文章
优秀的个人博客,低调大师

Django 搭建CMDB系统完整[11](服务器)

templates/add_server.html edit_server.html search_server.html <!DOCTYPE html> <html> <head> <title>CMDB</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/javascript" src="/static/scripts/jquery/jquery-1.7.1.js"></script> <link href="/static/style/authority/basic_layout.css" rel="stylesheet" type="text/css"> <link href="/static/style/authority/common_style.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="/static/scripts/authority/commonAll.js"></script> <script type="text/javascript" src="/static/scripts/jquery/jquery-1.4.4.min.js"></script> <script src="/static/scripts/My97DatePicker/WdatePicker.js" type="text/javascript" defer="defer"></script> <script type="text/javascript" src="/static/scripts/artDialog/artDialog.js?skin=default"></script> </head> <body> <form id="addserverform" name="addserverform" action="add_server.html" method="post"> <div id="container"> <div id="nav_links"> 当前位置:服务器资产管理><span style="color: #1A5CC6;">新增服务器</span> <div id="page_close"> <a href="javascript:parent.$.fancybox.close();"> <img src="/static/images/common/page_close.png" width="20" height="20" style="vertical-align: text-top;"/> </a> </div> </div> <div class="ui_content"> <table cellspacing="0" cellpadding="0" width="100%" align="left" border="0"> <tr> <td class="ui_text_rt">主机名字</td> <td class="ui_text_lt"> <input type="text" id="serverhostname" name="serverhostname" value="" class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">制造商/型号</td> <td class="ui_text_lt"> <input type="text" id="servermodel" name="servermodel" value="" class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">IP</td> <td class="ui_text_lt"> <input type="text" id="serverip" name="serverip" value="" class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">操作系统</td> <td class="ui_text_lt"> <input type="text" id="serveros" name="serveros" value="" class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">CPU</td> <td class="ui_text_lt"> <input type="text" id="servercpu" name="servercpu" value="" class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">内存</td> <td class="ui_text_lt"> <input type="text" id="servermemory" name="servermemory" value="" class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">硬盘</td> <td class="ui_text_lt"> <input type="text" id="serverdisk" name="serverdisk" value="" class="ui_input_txt02" /> </td> </tr> <tr> </tr> <tr> <td class="ui_text_rt">状态</td> <td class="ui_text_lt"> <select name="serverstatus" id="serverstatus" class="ui_select01" > <option value=0>在线</option> <option value=1>已下线</option> <option value=2>未知</option> <option value=3>故障</option> <option value=4>备用</option> </select> </td> </tr> <tr> <td class="ui_text_rt">所属机房</td> <td class="ui_text_lt"> <select name="servermachinaroom" id="servermachinaroom" class="ui_select01"> {% for mr in machinaroomlist %} <option value={{ mr.id }}>{{ mr.name }}</option> {% endfor %} </select> </td> </tr> <tr> <td>&nbsp;</td> <td class="ui_text_lt"> &nbsp;<input id="submitbutton" type="submit" value="提交" class="ui_input_btn01"/> &nbsp;<input id="cancelbutton" type="cancel" value="取消" class="ui_input_btn01"/> </td> </tr> </table> </div> </div> </form> </body> </html> <!DOCTYPE html> <html> <head> <title>CMDB</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/javascript" src="/static/scripts/jquery/jquery-1.7.1.js"></script> <link href="/static/style/authority/basic_layout.css" rel="stylesheet" type="text/css"> <link href="/static/style/authority/common_style.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="/static/scripts/authority/commonAll.js"></script> <script type="text/javascript" src="/static/scripts/jquery/jquery-1.4.4.min.js"></script> <script src="/static/scripts/My97DatePicker/WdatePicker.js" type="text/javascript" defer="defer"></script> <script type="text/javascript" src="/static/scripts/artDialog/artDialog.js?skin=default"></script> </head> <body> <form id="editserverform" name="editserverform" action="edit_server.html" method="post"> <div id="container"> <div id="nav_links"> 当前位置:服务器资产管理><span style="color: #1A5CC6;">编辑服务器</span> <div id="page_close"> <a href="javascript:parent.$.fancybox.close();"> <img src="/static/images/common/page_close.png" width="20" height="20" style="vertical-align: text-top;"/> </a> </div> </div> <div class="ui_content"><input style="visibility:hidden" value={{ server.id }} type="text" name="id" id="id" /> <table cellspacing="0" cellpadding="0" width="100%" align="left" border="0"> <tr> <td class="ui_text_rt">主机名字</td> <td class="ui_text_lt"> <input type="text" id="serverhostname" name="serverhostname" value={{ server.hostname }} class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">制造商/型号</td> <td class="ui_text_lt"> <input type="text" id="servermodel" name="servermodel" value={{ server.model }} class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">IP</td> <td class="ui_text_lt"> <input type="text" id="serverip" name="serverip" value={{ server.ip }} class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">操作系统</td> <td class="ui_text_lt"> <input type="text" id="serveros" name="serveros" value={{ server.os }} class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">CPU</td> <td class="ui_text_lt"> <input type="text" id="servercpu" name="servercpu" value={{ server.cpu }} class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">内存</td> <td class="ui_text_lt"> <input type="text" id="servermemory" name="servermemory" value={{ server.memory }} class="ui_input_txt02" /> </td> </tr> <tr> <td class="ui_text_rt">硬盘</td> <td class="ui_text_lt"> <input type="text" id="serverdisk" name="serverdisk" value={{ server.disk }} class="ui_input_txt02" /> </td> </tr> <tr> </tr> <tr> <td class="ui_text_rt">状态</td> <td class="ui_text_lt"> <select name="serverstatus" id="serverstatus" class="ui_select01" > <option value=0>在线</option> <option value=1>已下线</option> <option value=2>未知</option> <option value=3>故障</option> <option value=4>备用</option> </select> </td> </tr> <tr> <td class="ui_text_rt">所属机房</td> <td class="ui_text_lt"> <select name="servermachinaroom" id="servermachinaroom" class="ui_select01"> {% for mr in machinaroomlist %} <option value={{ mr.id }}>{{ mr.name }}</option> {% endfor %} </select> </td> </tr> <tr> <td>&nbsp;</td> <td class="ui_text_lt"> &nbsp;<input id="submitbutton" type="submit" value="提交" class="ui_input_btn01"/> &nbsp;<input id="cancelbutton" type="cancel" value="取消" class="ui_input_btn01"/> </td> </tr> </table> </div> </div> </form> </body> </html> {% extends 'base.html' %} {% block title %} <script type="text/javascript" src="/static/scripts/jquery/jquery-1.7.1.js"></script> <link href="/static/style/authority/basic_layout.css" rel="stylesheet" type="text/css"> <link href="/static/style/authority/common_style.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="/static/scripts/authority/commonAll.js"></script> <script type="text/javascript" src="/static/scripts/fancybox/jquery.fancybox-1.3.4.js"></script> <script type="text/javascript" src="/static/scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script> <link rel="stylesheet" type="text/css" href="/static/style/authority/jquery.fancybox-1.3.4.css" media="screen"></link> <script type="text/javascript" src="/static/scripts/artDialog/artDialog.js?skin=default"></script> <div id="container"> <div class="ui_content"> <div class="ui_text_indent"> <div id="box_border"> <div id="box_top">搜索</div> 机房名字<input type="text" id="mname" name="mname" value="{{ mname }}" class="ui_input_txt03" /> 主机名字<input type="text" id="sname" name="sname" value="{{ sname }}" class="ui_input_txt03" /> ip地址<input type="text" id="ip" name="ip" value="{{ ip }}" class="ui_input_txt03" /> 操作系统<input type="text" id="os" name="os" value="{{ os }}" class="ui_input_txt03" /> 状态 <select id="status" name="status" class="ui_select02"> <option value=100 selected = "selected">所有</option> <option value=0 {% if status == 0 %} selected = "selected" {% endif %}>在线</option> <option value=1 {% if status == 1 %} selected = "selected" {% endif %}>已下线</option> <option value=2 {% if status == 2 %} selected = "selected" {% endif %}>未知</option> <option value=3 {% if status == 3 %} selected = "selected" {% endif %}>故障</option> <option value=4 {% if status == 4 %} selected = "selected" {% endif %}>备用</option> </select> </div> <div id="box_bottom"> <div class="pagination"> <span class="current"> {% if serverlist.has_previous %} <a href="javascript:void(0)" onclick="search_server({{ serverlist.previous_page_number }});">上一页</a> {% endif %} <span class="current"> Page {{ serverlist.number }} of {{ serverlist.paginator.num_pages }}. </span> {% if serverlist.has_next %} <a href="javascript:void(0)" onclick="search_server({{ serverlist.next_page_number }});">下一页</a> {% endif %} </span> </div> <input type="button" value="查询" class="ui_input_btn01" onclick="search_server(1);"/> <input type="button" value="新增" class="ui_input_btn01" onclick="add_server();" /> <input type="button" value="删除" class="ui_input_btn01" onclick="batdel_server();" /> <input type="button" value="导出EXCEL" class="ui_input_btn01" onclick="excel_server();" /> </div> </form> </div> </div> {% endblock %} {% block content %} <div class="ui_content"> <div class="ui_tb"> <table class="table" cellspacing="0" cellpadding="0" width="100%" align="center" border="0"> <tr> <th width="30"><input type="checkbox" id="id" name="id" /> </th> <th>主机名字</th> <th>制造商/型号</th> <th>IP</th> <th>操作系统</th> <th>CPU</th> <th>内存</th> <th>硬盘</th> <th>状态</th> <th>机房</th> <th>操作</th> </tr> {% for s in serverlist.object_list %} <tr> <td><input type="checkbox" name="idcheck" value={{ s.id }} class="acb" /></td> <td>{{ s.hostname }}</td> <td>{{ s.model }}</td> <td>{{ s.ip }}</td> <td>{{ s.os }}</td> <td>{{ s.cpu }}</td> <td>{{ s.memory }}</td> <td>{{ s.disk }}</td> <td>{% if s.status == 0 %} 在线 {% elif s.status == 1 %} 已下线 {% elif s.status == 2 %} 未知 {% elif s.status == 3 %} 故障 {% elif s.status == 4 %} 备用 {% endif %} </td> <td>{{ s.machinaroom.name }}</td> <td> <a href="javascript:void(0)" onclick="edit_server('{{ s.id }}')" class="edit">编辑</a> <a href="javascript:void(0)" onclick="del_server({{ s.id }},{{ serverlist.number }});">删除</a> </td> </tr> {% endfor %} </table> </div> </div> </div> <script type="text/javascript"> function search_server(page){ var mname = document.getElementById("mname").value; var sname = document.getElementById("sname").value; var ip= document.getElementById("ip").value; var os= document.getElementById("os").value; var status = document.getElementById("status").value; var myurl="search_server.html"+"?"+"mname="+mname+"&&sname="+sname+"&&ip="+ip+"&&os="+os+"&&status="+status+"&&page="+page; window.location.assign(encodeURI(myurl)) } function add_server(){ var width = 400; var height = 500; var left = parseInt((screen.availWidth/2) - (width/2));//屏幕居中 var top = parseInt((screen.availHeight/2) - (height/2)); var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top; newWindow = window.open("add_server.html", "subWind", windowFeatures); } function edit_server(id){ var width = 400; var height = 500; var left = parseInt((screen.availWidth/2) - (width/2));//屏幕居中 var top = parseInt((screen.availHeight/2) - (height/2)); var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top; newWindow = window.open("edit_server.html?id="+id, "subWind", windowFeatures); } function del_server(id,page){ if(window.confirm('确定要删除该记录吗?')){ var text1= document.getElementById("mname").value; var sname=document.getElementById("sname").value; var ip=document.getElementById("ip").value; var os=document.getElementById("os").value; var status=document.getElementById("status").value; var myurl="del_server.html"+"?"+"id="+id+"&&mname="+text1+"&&page="+page+"&&ip="+ip+"&&os="+os+"&&status="+status+"&&sname="+sname; window.location.assign(encodeURI(myurl)) return true; }else{ //alert("取消"); return false; } } function batdel_server(){ if(window.confirm('确定要删除记录吗?')){ obj = document.getElementsByName("idcheck"); var text1= document.getElementById("mname").value; var sname=document.getElementById("sname").value; var ip=document.getElementById("ip").value; var os=document.getElementById("os").value; var status=document.getElementById("status").value; check_val = []; for(k in obj){ if(obj[k].checked) check_val.push(obj[k].value); } var myurl="batdel_server.html"+"?"+"ids="+check_val+"&&mname="+text1+"&&ip="+ip+"&&os="+os+"&&status="+status+"&&sname="+sname; window.location.assign(encodeURI(myurl)) return true; }else{ return false; } } function excel_server(){ var text1 = document.getElementById("mname").value; var sname=document.getElementById("sname").value; var ip=document.getElementById("ip").value; var os=document.getElementById("os").value; var status=document.getElementById("status").value; var myurl="excel_server.html"+"?mname="+text1+"&&ip="+ip+"&&os="+os+"&&status="+status+"&&sname="+sname; window.location.assign(encodeURI(myurl)) } </script> {% endblock %} cmdbapp/serverviews.py -- coding: utf-8 -- from future import unicode_literals from django.shortcuts import render,render_to_response from django.core.paginator import Paginator,InvalidPage,EmptyPage from cmdbapp.models import * from django.http import HttpResponse from django.http import HttpResponseRedirect from xlwt import * import StringIO def search_server(request): error = False each_page = 8 mname=request.GET.get('mname','').strip() sname=request.GET.get('sname','').strip() ip=request.GET.get('ip','').strip() os=request.GET.get('os','').strip() status=int(request.GET.get('status',100)) if mname=='' and sname=='' and ip=='' and os=='' and status==100: record_list = Server.objects.all() paginator = Paginator(record_list,each_page) try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 try: contacts = paginator.page(page) except (EmptyPage, InvalidPage): contacts = paginator.page(paginator.num_pages) return render_to_response('search_server.html',{'serverlist':contacts,"mname":mname,"sname":sname,"ip":ip,"os":os,"status":status}) else: q={} if mname!='' and sname=='' and ip=='' and os=='' and status==100: a=Machinaroom.objects.filter(name__icontains=mname).values("id") q['machinaroom__in']=a if sname!='': q['hostname__icontains']=sname if ip!='': q['ip__icontains']=ip if os!='': q['os__icontains']=os if status!=100: q['status']=status record_list = Server.objects.filter(**q) paginator = Paginator(record_list,each_page) try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 try: contacts = paginator.page(page) except (EmptyPage, InvalidPage): contacts = paginator.page(paginator.num_pages) return render_to_response('search_server.html',{'serverlist':contacts,"mname":mname,"sname":sname,"ip":ip,"os":os,"status":status}) def add_server(request): if request.method=='GET': objs=Machinaroom.objects.all() return render_to_response("add_server.html",{"machinaroomlist":objs}) else: hostname=request.POST.get("serverhostname","") model=request.POST.get("servermodel","") ip=request.POST.get("serverip","") os=request.POST.get("serveros","") cpu=request.POST.get("servercpu","") memory=request.POST.get("servermemory","") disk=request.POST.get("serverdisk","") status=request.POST.get("serverstatus",0) machinaroomid=request.POST.get("servermachinaroom") machinaroom=Machinaroom.objects.get(id=int(machinaroomid)) uu=Server(hostname=hostname,model=model,ip=ip,os=os,cpu=cpu,memory=memory,disk=disk,status=status,machinaroom=machinaroom) uu.save() return HttpResponseRedirect("add_server.html") def edit_server(request): if request.method=='GET': obj=Server.objects.get(id=int(request.GET.get('id'))) objs=Machinaroom.objects.all() return render_to_response('edit_server.html',{'server':obj,'machinaroomlist':objs}) else: id=request.POST.get("id") hostname=request.POST.get("serverhostname","") model=request.POST.get("servermodel","") ip=request.POST.get("serverip","") os=request.POST.get("serveros","") cpu=request.POST.get("servercpu","") memory=request.POST.get("servermemory","") disk=request.POST.get("serverdisk","") status=request.POST.get("serverstatus",0) machinaroomid=request.POST.get("servermachinaroom") machinaroom=Machinaroom.objects.get(id=int(machinaroomid)) uu=Server.objects.filter(id=id).update(hostname=hostname,model=model,ip=ip,os=os,cpu=cpu,memory=memory,disk=disk,status=status,machinaroom=machinaroom) return HttpResponseRedirect("edit_server.html?id="+id) def del_server(request): id=request.GET.get('id') iid=int(id) Server.objects.filter(id=iid).delete() mname=request.GET.get('mname','').strip() sname=request.GET.get('sname','').strip() ip=request.GET.get('ip','').strip() os=request.GET.get('os','').strip() status=request.GET.get('status',100) page=request.GET.get('page','1') return HttpResponseRedirect('search_server.html?mname='+mname+"&&page="+page+"&&sname="+sname+"&&ip="+ip+"&&os="+os+"&&status="+status) def batdel_server(request): ids=request.GET.get('ids') b=ids.split(',') arr = map(int,b) for aaa in arr: Server.objects.filter(id=aaa).delete() mname=request.GET.get('mname') sname=request.GET.get('sname','').strip() ip=request.GET.get('ip','').strip() os=request.GET.get('os','').strip() status=request.GET.get('status',100) return HttpResponseRedirect('search_server.html?mname='+mname+"&&sname="+sname+"&&ip="+ip+"&&os="+os+"&&status="+status) def excel_server(request): mname=request.GET.get('mname','').strip() sname=request.GET.get('sname','').strip() ip=request.GET.get('ip','').strip() os=request.GET.get('os','').strip() status=int(request.GET.get('status',100)) if mname=='' and sname=='' and ip=='' and os=='' and status==100: list_obj = Server.objects.all() else: q={} if mname!='' and sname=='' and ip=='' and os=='' and status==100: a=Machinaroom.objects.filter(name__icontains=mname).values("id") q['machinaroom__in']=a if sname!='': q['hostname__icontains']=sname if ip!='': q['ip__icontains']=ip if os!='': q['os__icontains']=os if status!=100: q['status']=status list_obj = Server.objects.filter(**q) if list_obj: # 创建工作薄 ws = Workbook(encoding='utf-8') w = ws.add_sheet(u"服务器清单") w.write(0, 0, "id") w.write(0, 1, u"主机名字") w.write(0, 2, u"制造商/型号") w.write(0, 3, u"IP") w.write(0, 4, u"操作系统") w.write(0,5,u"CPU") w.write(0,6,u"内存") w.write(0,7,u"硬盘") w.write(0,8,u"状态") w.write(0,9,u"机房") # 写入数据 excel_row = 1 for obj in list_obj: data_id = obj.id data_hostname = obj.hostname data_model = obj.model data_ip = obj.ip data_os = obj.os data_cpu=obj.cpu data_memory=obj.memory data_disk=obj.disk if obj.status == 0: data_status='在线' elif obj.status == 1: data_status='已下线' elif obj.status == 2: data_status='未知' elif obj.status == 3: data_status='故障' else: data_status='备用' data_machinaroom=obj.machinaroom.name w.write(excel_row, 0, data_id) w.write(excel_row, 1, data_hostname) w.write(excel_row, 2, data_model) w.write(excel_row, 3, data_ip) w.write(excel_row, 4, data_os) w.write(excel_row, 5, data_cpu) w.write(excel_row, 6, data_memory) w.write(excel_row, 7, data_disk) w.write(excel_row, 8, data_status) w.write(excel_row, 9, data_machinaroom) excel_row += 1 sio = StringIO.StringIO() ws.save(sio) sio.seek(0) response = HttpResponse(sio.getvalue(), content_type='application/vnd.ms-excel') response['Content-Disposition'] = 'attachment; filename=服务器清单-'+mname+sname+ip+os+'.xls' response.write(sio.getvalue()) return response

优秀的个人博客,低调大师

Flutter 11: 图解底部状态栏小尝试

小菜今天来整理一下在学习测试 Flutter 时需用到的底部导航栏 BottomNavigationBar,使用方式很简单,小菜感觉效果比原生的 Android 要好一些。 何为 BottomNavigationBar ? BottomNavigationBar 为底部导航栏控件,可以包含文字标签和图标等基本信息,通常在三到五个之间;据了解,iOS 的规范底部导航栏最多可设置五个,所以大部分应用均在五个以内;现在很多应用都是以底部导航栏 + 中部主内容 Content 方式来展示。 官网建议,BottomNavigationBar 底部导航栏通常与 Scaffold 一起使用,其中它作为Scaffold.bottomNavigationBar 参数提供。 如何应用 BottomNavigationBar ? 与 body 同级的位置添加 BottomNavigationBar,BottomNavigationBarItem 中可以添加文字标签或图标 (Icons/Image) 等,若图片不存在时会显示空白;这样就可以添加底部状态栏内容,文字和图标的样式也可以随意调整;如下: bottomNavigationBar: new BottomNavigationBar( type: BottomNavigationBarType.fixed, items: [ BottomNavigationBarItem( icon: new Icon(Icons.category), title: new Text('签到')), BottomNavigationBarItem( icon: new Icon(Icons.account_circle), title: new Text('我')), ], ), 只有底部状态栏是不够的,还需要对应的中间展示内容块,可以跟 Android 的思路一样,添加几个 Page() 页作为 Fragment,小菜因为测试内容相对简单,尝试使用了 PageView,即对应 Android 中的 ViewPager,小菜会在今后的测试中详细说明,今天主要是使用基本方法展示主模块内容;如下: body: new PageView.builder( itemBuilder: (BuildContext context, int index) { var str = (index == 0) ? "这里是【HomePage】->【签到】页面" : "这里是【HomePage】->【我】页面"; return new Center( child: new Container( width: 340.0, child: new Card( color: Colors.blue, elevation: 16.0, child: new FlatButton( child: new Text(str, style: new TextStyle(color: Colors.white)), )), )); }, itemCount: 2, ), 此时主模块 PageView 可以滑动切换内容,但是对应的底部状态栏不会变化;因为目前没有绑定对应的点击事件等;此时需要添加 PageController 和 状态栏的 onTap 点击事件;如下: int _currentIndex = 0; var _pageController = new PageController(initialPage: 0); void _pageChange(int index) { if (_currentIndex != index) { _currentIndex = index; } } // 添加 PageView 的 PageController body: new PageView.builder( onPageChanged: _pageChange, controller: _pageController, itemBuilder: (BuildContext context, int index) { ... } ), // 添加 BottomNavigationBar 的 onTap bottomNavigationBar: new BottomNavigationBar( type: BottomNavigationBarType.fixed, items: [ ... ], //设置当前的索引 currentIndex: _currentIndex, //tabBottom的点击监听 onTap: (int index) { _pageController.animateToPage(index, duration: new Duration(seconds: 2), curve: new ElasticOutCurve(0.8)); _pageChange(index); _currentIndex = index; }, ), 此时,点击底部状态栏对应的 PageView 会切换内容,但是底部状态栏并没有改变样式,因为目前用的时固定的图标和文字,此时需要处理图标和文字切换时的样式,如下: var _bottomText = ['签到', '我']; var _bottomIcons = [ [ new Icon(Icons.category, color: Colors.grey), new Icon(Icons.category, color: Colors.blue), ], [ new Icon(Icons.account_circle, color: Colors.grey), new Icon(Icons.account_circle, color: Colors.blue), ] ]; Icon changeIconStyle(int curIndex) { if (curIndex == _currentIndex) { return _bottomIcons[curIndex][1]; } return _bottomIcons[curIndex][0]; } Text changeTextStyle(int curIndex) { if (curIndex == _currentIndex) { return new Text(_bottomText[curIndex], style: new TextStyle(color: Colors.blue)); } else { return new Text(_bottomText[curIndex], style: new TextStyle(color: Colors.grey)); } } bottomNavigationBar: new BottomNavigationBar( type: BottomNavigationBarType.fixed, items: [ new BottomNavigationBarItem( icon: changeIconStyle(0), title: changeTextStyle(0)), new BottomNavigationBarItem( icon: changeIconStyle(1), title: changeTextStyle(1)), ], ... ), 然而小菜添加了更改状态时的样式,点击底部状态栏时依旧不会变色;小菜查了很久突然发现,小菜的 HomePage() 继承的是 StatelessWidget 无状态样式,此时更换为 StatefulWidget 有状态样式,并实现对应方法;如下: class HomePage extends StatefulWidget { String result; HomePage(this.result); @override State<StatefulWidget> createState() { // TODO: implement createState return new HomePageState(); } } class HomePageState extends State<HomePage> { int _currentIndex = 0; ... } 至此,底部状态栏 BottomNavigationBar 配合滑动 PageView 的基本功能已经完成。 实用小贴士 通过点击 BottomNavigationBar 对 PageView 切换过程中,可以设置动画过程,也可以直接跳转到对应页面,需要设置 animateToPage 或 jumpToPage;如下: onTap: (int index) { // 切换时没有动画效果 // _pageController.jumpToPage(index); // 切换时添加动画效果 _pageController.animateToPage(index, duration: new Duration(seconds: 2), curve: new ElasticOutCurve(0.8)); _pageChange(index); _currentIndex = index; }, BottomNavigationBar 有两种样式分别为 shifting 和 fixed;直接效果图,shifting 样式时会突出显示选中的 item,其他的 item 文字隐藏;fixed 样式均分,没有突出效果;如下: type: BottomNavigationBarType.shifting, shifting shifting type: BottomNavigationBarType.fixed, fixed fixed GitHub Demo 小菜刚接触 Flutter 时间不长,还有很多不清楚和不理解的地方,如果又不对的地方还希望多多指出。以下是小菜公众号,欢迎闲来吐槽~ 公众号

优秀的个人博客,低调大师

docker学习系列11 多阶段镜像构建

本篇文章是转载,原文 从Docker版本 17.05.0-ce 开始,就支持了一种新的构建镜像的方法,叫做:多阶段构建(Multi-stage builds),旨在解决Docker构建应用容器中的一些痛点。在日常构建容器的场景中,经常会遇到在同一个容器中进行源码的获取,编译和生成,最终才构建为镜像。这样做的劣势在于: 不得不在容器中安装构建程序所必须的运行时环境 不得不在同一个容器中,获取程序的源码和构建所需的一些生态工具 构建出的镜像甚至包含了程序源码和一些不必要的文件,导致容器镜像尺寸偏大 当然,还有一种稍微优雅的方式,就是我们事先在外部将项目及其依赖库编译测试打包好后,再将其拷贝到构建目录中,这种虽然可以很好地规避第一种方式存在的风险点,但是也需要考虑不同镜像运行时,对于程序运行兼容性所带来的差异。 其实,这些痛点,Docker也想到了,官方提供了简便的多阶段构建 (multi-stage build) 方案。所谓多阶段构建,也即将构建过程分为多个阶段,在同一个Dockerfile中,通过不同的阶段来构建和生成所需要的应用文件,最终将这些应用文件添加到一个release的镜像中。这样做能完全规避上面所遇到的一系列问题。实现多阶段构建,主要依赖于新提供的关键字:from 和 as 。 下面举个栗子: FROM muninn/glide:alpine AS build-env ADD . /go/src/my-proj WORKDIR /go/src/my-proj RUN go get -v RUN go build -o /go/src/my-proj/my-server FROM alpine RUN apk add -U tzdata RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime COPY --from=build-env /go/src/my-proj/my-server /my-server EXPOSE 80 CMD ["my-server"] 多阶段构建的Dockerfile看起来像是把两个或者更多的Dockerfile合并在了一起,这也即多阶段的意思。as 关键字用来为构建阶段赋予一个别名,这样,在另外一个构建阶段中,可以通过 from 关键字来引用和使用对应关键字阶段的构建输出,并打包到容器中。 在多阶段构建完成之后,输出的镜像仅仅包含了最终输出的my-server应用,没有其他的源码文件和第三方源码包,非常的干净和简洁。因为 build-env 阶段只是一个构建的中间过程而已。 甚至,我们还可以使用更多的构建阶段来构建不同的应用,最终将这些构建产出的应用,合并到一个最终需要发布的镜像中。我们可以看一个更复杂一点的栗子: from debian as build-essential arg APT_MIRROR run apt-get update run apt-get install -y make gcc workdir /src from build-essential as foo copy src1 . run make from build-essential as bar copy src2 . run make from alpine copy --from=foo bin1 . copy --from=bar bin2 . cmd ... 再来一个Laravel项目的多阶段构建( 自己加的内容) 第一阶段:使用compose安装PHP依赖 第二阶段:安装node,并安装前端依赖然后生成编译后的文件 第三阶段:拷贝PHP依赖及前端build后的文件到项目运行目录 # # PHP Dependencies # FROM composer:1.7 as vendor COPY database/ database/ COPY composer.json composer.json COPY composer.lock composer.lock RUN composer install \ --ignore-platform-reqs \ --no-interaction \ --no-plugins \ --no-scripts \ --prefer-dist # # Frontend # FROM node:8.11 as frontend RUN mkdir -p /app/public COPY package.json webpack.mix.js yarn.lock /app/ COPY resources/assets/ /app/resources/assets/ WORKDIR /app RUN yarn install && yarn production # # Application # FROM php:7.2-apache-stretch COPY . /var/www/html COPY --from=vendor /app/vendor/ /var/www/html/vendor/ COPY --from=frontend /app/public/js/ /var/www/html/public/js/ COPY --from=frontend /app/public/css/ /var/www/html/public/css/ COPY --from=frontend /app/mix-manifest.json /var/www/html/mix-manifest.json 多阶段构建的好处不言而喻,既可以很方便地将多个彼此依赖的项目通过一个Dockerfile就可轻松构建出期望的容器镜像,并且不用担心镜像太大、源码泄露等风险。不得不说,这是一个非常不错的改进。 参考: https://docs.docker.com/develop/develop-images/multistage-build/https://yq.aliyun.com/articles/181178https://laravel-news.com/multi-stage-docker-builds-for-laravel

优秀的个人博客,低调大师

2018-05-11 第五天

一、条件运算符: java 中唯一的一个三目运算符。 需要三个操作数(三个表达式)。 语法:表达式-1 ? 表达式-2 :表达式-3 ; 表达式-1: 必须是一个boolean 表达式(返回值是boolean值的表达式)。 表达式-2,3 是java 任意的表达式,但是两个表达式的返回值的类型要兼容。 执行过程: 1:计算表达式-1的返回值。 2:根据表达式-1 的返回值 ,如果是true,那么就执行表达式-2 并返回该值作为整个条件表达式的返回值。 3:如果 表达式-1 的返回值 是 false,那么就跳过表达式-2 ,执行并返回表达式-3 的值。 //条件运算符 public class TestThree{ public static void main(String[] args){ // 随机得到两个随机数,[10-30],打印结果。 // 将两个随机数中比较大的值输出。 //定义区间 final int MIN = 10,MAX = 31; int num1 = (int)(Math.random()*(MAX-MIN)+MIN); int num2 = (int)(Math.random()*(MAX-MIN)+MIN); int num3 = (int)(Math.random()*(MAX-MIN)+MIN); System.out.println("num1 = "+ num1 + "\tnum2 = "+num2 + "\tnum3 = "+num3); int max = 0; // max = num1 > num2 ? num1 : num2; // max = max > num3 ? max : num3; max = num1 > num2 ? (num1 > num3 ? num1 : num3) : (num2 > num3 ? num2 : num3); System.out.println("max = "+max); } } 二、 运算符优先级 规律: 1:乘除取余 优先级大于 加减 2:同级优先级 根据结合性结合。 3:小括号优先级最高。 4:一元运算符大于二元的,二元的大于三元,赋值运算符优先级最低。 口诀:单目算术为关系,逻辑条件后赋值。 单目:单目运算符! + –(负数) ++ --等 乘除:算数单目运算符* / % + - 为:位移二目运算符<< >> 关系:关系二目运算符> < >= <= == != 逻辑:逻辑二目运算符&& || & | ^ 条件:唯一的三目运算符A > B ? X : Y 后:无意义,仅仅为了凑字数 赋值:赋值= 三、 算术运算时数据类型的转换 注意:java 不支持不同类型的数据之间的运算。 如果是不同类型的数据进行运算,那么编译器会对不同的类型的数据进行类型的统一的转换。转换为统一类型之后才能做运算。 自动类型转换的规则:因为这种转换是安全的。 1:如果操作数 的类型 是 byte,char ,short ,int 中的一个或者几个。那么这些操作数的类型要被自动转换为 int 类型然后再做运算。结果也是int。这种转换不会修改数据的大小,只是数据使用内存空间的大小的变换。 2:如果操作数 的类型 是 byte,char ,short ,int,long 中的一个或者几个,而且有long类型的数据存在。那么这些操作数的类型要被自动转换为long类型然后再做运算。结果也是long。 3:如果所有的操作数的类型中,最大的类型是float,那么所有的操作数的类型都向float转,结果也是float。 float 类型表示的范围大于 long。 4:如果所有的操作数的类型中,最大的类型是double,那么所有的操作数的类型都向double转,结果也是double。 double 类型表示的范围最大。 自动类型转换: 从 int 到 float,有可能损失精度。 int 到 float 可能损失精度,int 最大 2147483647, float 有效数字个数是 6-7, 会失去有效数字个数引起的精度。float 到 int 会失去小数部分,也就损失精度了。另外, float允许数值范围大于int,超出int允许范围。 四、 赋值时转换 赋值的时候的类型的转换。 1:自动向上类型转换:可以将一个小类型的数据直接赋值给一个大类型的变量。因为安全。小类型向大类型自动转换,因为安全。 2:强制向下类型转换: 整数的强制向下;直接将高位砍掉。 浮点数 到 整数 强转;先直接砍掉小数点。然后再按照整数的规则砍。 强制转换不能确保是安全的。 public class TestChangeType{ public static void main(String[] args){ int age = 10; byte value = 10; int num = value; System.out.println(num); byte value1 = 12; byte value2 = 10 + 23;//没有问题 // 在编译期,是不知道变量的值的。但是对于常量值,编译器是可以判断赋值 是否安全。 byte value3 = (byte)(value1 + value2); System.out.println((short)128.349329329);//-128 1000 0000 0111 1111 } } 字符串连接时的数据转换: "123" + 123:字符串和其他的类型也是不能直接连接的,其他的类型需要转换为字符串才能和字符串做连接。这个基本数据类型的数据到字符串的转换,是由底层的方法调用来完成。 例1: import java.util.Random; /*得到一个随机字符[A-Z]or[a-z] (大小写也要随机),并打印。*/ public class TestRandomBoolean{ public static void main(String[] args){ Random ran = new Random(); //定义区间[A-Z][65-90][a-z][97-122] final int MIN_1 = 65,MAX_1 = 90,MIN_2 = 97,MAX_2 = 122; System.out.println(ran.nextBoolean() ? (char)(Math.random()*(MAX_1 - MIN_1) + MIN_1) : (char)(Math.random()*(MAX_2 - MIN_2) + MIN_2)); } } 例2: import java.util.Random; /*随机生成两个数,[0-100],然后输出,然后实现用一个int类型的变量num 保存两个数的算法.*/ public class TestMemory{ public static void main(String[] args){ Random ran = new Random(); //定义区间[10-100] final int MIN = 10,MAX = 101; int num1 = (int)(Math.random()*(MAX - MIN) + MIN); //获得的随机数可能为负,>>> 1 转换成 正整数; int num2 = (ran.nextInt() >>> 1) % (MAX - MIN) + MIN; System.out.println("第一个数 = " + num1 + "\t第二个数 = " + num2 ); int num3 = num1 << 16; int num4 = num2 | num3; System.out.println("存储的int型 = " + num4 ); int num5 = num4 & 0b1111111111111111; int num6 = num3 >> 16; System.out.println("==========================================\n解出来第一个数 = " + num6 + "\t解出来第二个数 = " + num5 ); } }

优秀的个人博客,低调大师

leetcode算法题解(Java版)-11-贪心大法

一、全排列变式(递归) 题目描述 Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[2,1,1]. 思路 多了一个条件,就是有重复数字出现。那可以考虑先排序,然后递归选择在相应位置放置数字的时候,可以添加判断是否被用过,也就是和前面那个比较一下:如果前面那个数和它一样值,而且目前的used 显示false那说明这个数已经在这个位置被用过了,而且已经计入了结果res中。 代码 import java.util.ArrayList; import java.util.Arrays; public class Solution { public ArrayList<ArrayList<Integer>> permuteUnique(int[] num) { ArrayList<ArrayList<Integer>> res=new ArrayList<>(); int len=num.length; if(num==null||len==0){ return res; } boolean [] used=new boolean[len]; ArrayList<Integer> list=new ArrayList<>(); Arrays.sort(num); dfs(list,num,used,res); return res; } public void dfs(ArrayList<Integer> list,int [] num,boolean [] used,ArrayList<ArrayList<Integer>> res){ if(list.size()==num.length){ res.add(new ArrayList<Integer>(list)); return ; } for(int i=0;i<num.length;i++){ if(i>0&&num[i]==num[i-1]&&!used[i-1]){//如果它前一个和它一样的数现在没有被用过,那就跳过, //说明之前那个数已经形成过结果list之一了,目前这个分支处于回溯阶段。。。有点绕,希望能明白 continue; } if(!used[i]){ used[i]=true; list.add(num[i]); dfs(list,num,used,res); list.remove(list.size()-1); used[i]=false; } } } } 二、贪心 题目描述 Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index. For example:A =[2,3,1,1,4], returntrue. A =[3,2,1,0,4], returnfalse 思路 贪心的题,每走一步,跟新一下从当前这个位置所能到达的最大距离。这就是这题的贪心,贪心一般证明很难,但是可以逻辑简单想一下,肯定是能走的距离越大越好,越有可能到达终点,再说,如果最大距离都不能到终点,那其他情况更加不可能了。 代码 public class Solution { public boolean canJump(int[] A) { int maxlen=A[0]; for(int i=1;i<A.length;i++){ if(maxlen==0){ return false; } maxlen-=1; maxlen=Math.max(maxlen,A[i]); //if(maxlen+i==A.length-1){//剪枝 // return true; // } } return true; } } 三、动态规划or贪心 题目描述 Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps. For example:Given array A =[2,3,1,1,4] The minimum number of jumps to reach the last index is2. (Jump1step from index 0 to 1, then3steps to the last index 思路 dp解法: 题目想考察的是贪心,想了一下,思绪有点乱。先看一下动态规划的解法。 首先,满足dp的条件:1.子问题的最优解也是全局的最优解,有最优子结构;2.当前状态只依赖于它上一个状态,与怎么到达它上一个状态的路径无关。 代码 public class Solution { public int jump(int[] A) { int [] dp=new int[A.length];//存放起点到各点的最小步数 for(int i=0;i<A.length;i++){ int maxpos=Math.min(i+A[i],A.length-1); for(int j=i+1;j<=maxpos;j++){ if(dp[j]==0){ dp[j]=dp[i]+1; } } if(dp[A.length-1]!=0){ break; } } return dp[A.length-1]; } } 思路二 贪心解法: 贪心大法好,但真的难想明白。。首先,要设置三个值:当前位置(是一个区域:从i~furthest_pre中,区域中的点中能到达的最大位置)所能到达的最大位置(furthest_cur),当前位置的上一个位置(也是区域)所能到达的最大位置(furthest_pre),还有就是所走的步数。 有一点可能有点会懵,furthest_cur是还没有step++的时候,具体结合代码,也就是是一个预判能走到的但还没走的状态。 感觉讲的还是有点乱,现在抛开代码,想象我们站在题目给的数组的开头位置:从开始位置到开始位置能走到的最大距离(furthest_pre)之间构成了一块区域,然后我们开始一格一格走,每走一下刷新一下当前这块区域能到的最大位置(furthest_cur),如果走到从开始位置走到了furthest_pre那我们也刷新出了最大的furthest_cur,如果furthest_cur比终点大,那恭喜!再跳一不就到终点了!可以开始跳一步咯!然后重复上述的动作,直到到达终点。 如果能一步到最大位置furthest_pre,那肯定能到一步到它前面那块区域的某一位置,实行下一步跳,跳到furthest_cur。 给一个测试用例,可以在纸上画画: 4 1 6 9 7 4 5 0 6 8 1 2 3 5 8 0 2 1 2 代码 public class Solution { public int jump(int[] A) { int len=A.length; if(len==0||A==null){ return 0; } int furthest_cur=0; int furthest_pre=0; int steps=0; for(int i=0;i<len;i++){ if(furthest_pre>=len){ return steps; } if(i>furthest_pre){ furthest_pre=furthest_cur; steps++; } furthest_cur=Math.max(furthest_cur,A[i]+i); } return steps; } }

优秀的个人博客,低调大师

第 11 章 Scrapy - Python web scraping and crawling framework

目录 11.1. 安装 scrapy 开发环境 11.1.1. Mac 11.1.2. Ubuntu 11.1.3. 使用 pip 安装 scrapy 11.1.4. 测试 scrapy 11.2. scrapy 命令 11.2.1. 11.2.2. 新建 spider 11.2.3. 列出可用的 spiders 11.2.4. 运行 spider 11.3. Scrapy Shell 11.3.1. response 11.3.1.1. 当前URL地址 11.3.1.2. status HTTP 状态 11.3.1.3. text 正文 11.3.1.4. css 11.3.1.4.1. 获取 html 属性 11.3.1.5. xpath 11.3.1.6. headers 11.4. 爬虫项目 11.4.1. 创建项目 11.4.2. Spider 11.4.2.1. 翻页操作 11.4.2.2. 采集内容保存到文件 11.4.3. settings.py 爬虫配置文件 11.4.3.1. 忽略 robots.txt 规则 11.4.4. Item 11.4.5. Pipeline 11.5. 下载图片 11.5.1. 配置 settings.py 11.5.2. 修改 pipelines.py 文件 11.5.3. 编辑 items.py 11.5.4. Spider 爬虫文件 11.6. xpath 11.6.1. 逻辑运算符 11.6.1.1. and 11.6.1.2. or 11.6.2. function 11.6.2.1. text() 11.6.2.2. contains() https://scrapy.org 11.1.安装 scrapy 开发环境 11.1.1.Mac neo@MacBook-Pro ~ % brew install python3 neo@MacBook-Pro ~ % pip3 install scrapy 11.1.2.Ubuntu 搜索 scrapy 包,scrapy 支持 Python2.7 和 Python3 我们只需要 python3 版本 neo@netkiller ~ % apt-cache search scrapy | grep python3 python3-scrapy - Python web scraping and crawling framework (Python 3) python3-scrapy-djangoitem - Scrapy extension to write scraped items using Django models (Python3 version) python3-w3lib - Collection of web-related functions (Python 3) Ubuntu 17.04 默认 scrapy 版本为 1.3.0-1 如果需要最新的 1.4.0 请使用 pip 命令安装 neo@netkiller ~ % apt search python3-scrapy Sorting... Done Full Text Search... Done python3-scrapy/zesty,zesty 1.3.0-1~exp2 all Python web scraping and crawling framework (Python 3) python3-scrapy-djangoitem/zesty,zesty 1.1.1-1 all Scrapy extension to write scraped items using Django models (Python3 version) 安装 scrapy neo@netkiller ~ % sudo apt install python3-scrapy [sudo] password for neo: Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: ipython3 libmysqlclient20 libwebpmux2 mysql-common python-pexpect python-ptyprocess python3-attr python3-boto python3-bs4 python3-cffi-backend python3-click python3-colorama python3-constantly python3-cryptography python3-cssselect python3-decorator python3-html5lib python3-idna python3-incremental python3-ipython python3-ipython-genutils python3-libxml2 python3-lxml python3-mysqldb python3-openssl python3-pam python3-parsel python3-pexpect python3-pickleshare python3-pil python3-prompt-toolkit python3-ptyprocess python3-pyasn1 python3-pyasn1-modules python3-pydispatch python3-pygments python3-queuelib python3-serial python3-service-identity python3-setuptools python3-simplegeneric python3-traitlets python3-twisted python3-twisted-bin python3-w3lib python3-wcwidth python3-webencodings python3-zope.interface Suggested packages: python-pexpect-doc python-attr-doc python-cryptography-doc python3-cryptography-vectors python3-genshi python3-lxml-dbg python-lxml-doc default-mysql-server | virtual-mysql-server python-egenix-mxdatetime python3-mysqldb-dbg python-openssl-doc python3-openssl-dbg python3-pam-dbg python-pil-doc python3-pil-dbg doc-base python-pydispatch-doc ttf-bitstream-vera python-scrapy-doc python3-wxgtk3.0 | python3-wxgtk python-setuptools-doc python3-tk python3-gtk2 python3-glade2 python3-qt4 python3-wxgtk2.8 python3-twisted-bin-dbg The following NEW packages will be installed: ipython3 libmysqlclient20 libwebpmux2 mysql-common python-pexpect python-ptyprocess python3-attr python3-boto python3-bs4 python3-cffi-backend python3-click python3-colorama python3-constantly python3-cryptography python3-cssselect python3-decorator python3-html5lib python3-idna python3-incremental python3-ipython python3-ipython-genutils python3-libxml2 python3-lxml python3-mysqldb python3-openssl python3-pam python3-parsel python3-pexpect python3-pickleshare python3-pil python3-prompt-toolkit python3-ptyprocess python3-pyasn1 python3-pyasn1-modules python3-pydispatch python3-pygments python3-queuelib python3-scrapy python3-serial python3-service-identity python3-setuptools python3-simplegeneric python3-traitlets python3-twisted python3-twisted-bin python3-w3lib python3-wcwidth python3-webencodings python3-zope.interface 0 upgraded, 49 newly installed, 0 to remove and 0 not upgraded. Need to get 7,152 kB of archives. After this operation, 40.8 MB of additional disk space will be used. Do you want to continue? [Y/n] 输入大写 “Y” 然后回车 11.1.3.使用 pip 安装 scrapy neo@netkiller ~ % sudo apt install python3-pip neo@netkiller ~ % pip3 install scrapy 11.1.4.测试 scrapy 创建测试程序,用于验证 scrapy 安装是否存在问题。 $ cat > myspider.py <<EOF import scrapy class BlogSpider(scrapy.Spider): name = 'blogspider' start_urls = ['https://blog.scrapinghub.com'] def parse(self, response): for title in response.css('h2.entry-title'): yield {'title': title.css('a ::text').extract_first()} for next_page in response.css('div.prev-post > a'): yield response.follow(next_page, self.parse) EOF 运行爬虫 $ scrapy runspider myspider.py 原文出处:Netkiller 系列 手札 本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

优秀的个人博客,低调大师

Android系统的开机画面显示过程分析(11)

BootAnimation类的成员函数movie的实现比较长,我们分段来阅读: boolBootAnimation::movie() { ZipFileRO&zip(mZip); size_tnumEntries=zip.getNumEntries(); ZipEntryROdesc=zip.findEntryByName("desc.txt"); FileMap*descMap=zip.createEntryFileMap(desc); LOGE_IF(!descMap,"descMapisnull"); if(!descMap){ returnfalse; } String8desString((charconst*)descMap->getDataPtr(), descMap->getDataLength()); charconst*s=desString.string(); Animationanimation; //Parsethedescriptionfile for(;;){ constchar*endl=strstr(s,"\n"); if(!endl)break; String8line(s,endl-s); constchar*l=line.string(); intfps,width,height,count,pause; charpath[256]; if(sscanf(l,"%d%d%d",&width,&height,&fps)==3){ //LOGD(">w=%d,h=%d,fps=%d",fps,width,height); animation.width=width; animation.height=height; animation.fps=fps; } if(sscanf(l,"p%d%d%s",&count,&pause,path)==3){ //LOGD(">count=%d,pause=%d,path=%s",count,pause,path); Animation::Partpart; part.count=count; part.pause=pause; part.path=path; animation.parts.add(part); } s=++endl; } 从前面BootAnimation类的成员函数readyToRun的实现可以知道,如果目标设备上存在压缩文件/data/local/bootanimation.zip,那么BootAnimation类的成员变量mZip就会指向它,否则的话,就会指向目标设备上的压缩文件/system/media/bootanimation.zip。无论BootAnimation类的成员变量mZip指向的是哪一个压缩文件,这个压缩文件都必须包含有一个名称为“desc.txt”的文件,用来描述用户自定义的开机动画是如何显示的。 文件desc.txt的内容格式如下面的例子所示: 60048024 p10part1 p010part2 第一行的三个数字分别表示开机动画在屏幕中的显示宽度、高度以及帧速(fps)。剩余的每一行都用来描述一个动画片断,这些行必须要以字符“p”来开头,后面紧跟着两个数字以及一个文件目录路径名称。第一个数字表示一个片断的循环显示次数,如果它的值等于0,那么就表示无限循环地显示该动画片断。第二个数字表示每一个片断在两次循环显示之间的时间间隔。这个时间间隔是以一个帧的时间为单位的。文件目录下面保存的是一系列png文件,这些png文件会被依次显示在屏幕中。 以上面这个desct.txt文件的内容为例,它描述了一个大小为600 x 480的开机动画,动画的显示速度为24帧每秒。这个开机动画包含有两个片断part1和part2。片断part1只显示一次,它对应的png图片保存在目录part1中。片断part2无限循环地显示,其中,每两次循环显示的时间间隔为10 x (1 / 24)秒,它对应的png图片保存在目录part2中。 上面的for循环语句分析完成desc.txt文件的内容后,就得到了开机动画的显示大小、速度以及片断信息。这些信息都保存在Animation对象animation中,其中,每一个动画片断都使用一个Animation::Part对象来描述,并且保存在Animation对象animation的成员变量parts所描述的一个片断列表中。 接下来,BootAnimation类的成员函数movie再断续将每一个片断所对应的png图片读取出来,如下所示: //readallthedatastructures constsize_tpcount=animation.parts.size(); for(size_ti=0;i<numEntries;i++){ charname[256]; ZipEntryROentry=zip.findEntryByIndex(i); if(zip.getEntryFileName(entry,name,256)==0){ constString8entryName(name); constString8path(entryName.getPathDir()); constString8leaf(entryName.getPathLeaf()); if(leaf.size()>0){ for(intj=0;j<pcount;j++){ if(path==animation.parts[j].path){ intmethod; //supportsonlystoredpngfiles if(zip.getEntryInfo(entry,&method,0,0,0,0,0)){ if(method==ZipFileRO::kCompressStored){ FileMap*map=zip.createEntryFileMap(entry); if(map){ Animation::Frameframe; frame.name=leaf; frame.map=map; Animation::Part&part(animation.parts.editItemAt(j)); part.frames.add(frame); } } } } } } } } 每一个png图片都表示一个动画帧,使用一个Animation::Frame对象来描述,并且保存在对应的Animation::Part对象的成员变量frames所描述的一个帧列表中。 获得了开机动画的所有信息之后,接下来BootAnimation类的成员函数movie就准备开始显示开机动画了,如下所示: //clearscreen glShadeModel(GL_FLAT); glDisable(GL_DITHER); glDisable(GL_SCISSOR_TEST); glDisable(GL_BLEND); glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(mDisplay,mSurface); glBindTexture(GL_TEXTURE_2D,0); glEnable(GL_TEXTURE_2D); glTexEnvx(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE); glTexParameterx(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameterx(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexParameterx(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterx(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); constintxc=(mWidth-animation.width)/2; constintyc=((mHeight-animation.height)/2); nsecs_tlastFrame=systemTime(); nsecs_tframeDuration=s2ns(1)/animation.fps; RegionclearReg(Rect(mWidth,mHeight)); clearReg.subtractSelf(Rect(xc,yc,xc+animation.width,yc+animation.height)); 前面的一系列gl函数首先用来清理屏幕,接下来的一系列gl函数用来设置OpenGL的纹理显示方式。 变量xc和yc的值用来描述开机动画的显示位置,即需要在屏幕中间显示开机动画,另外一个变量frameDuration的值用来描述每一帧的显示时间,它是以纳秒为单位的。 Region对象clearReg用来描述屏幕中除了开机动画之外的其它区域,它是用整个屏幕区域减去开机动画所点据的区域来得到的。 准备好开机动画的显示参数之后,最后就可以执行显示开机动画的操作了,如下所示: for(inti=0;i<pcount&&!exitPending();i++){ constAnimation::Part&part(animation.parts[i]); constsize_tfcount=part.frames.size(); glBindTexture(GL_TEXTURE_2D,0); for(intr=0;!part.count||r<part.count;r++){ for(intj=0;j<fcount&&!exitPending();j++){ constAnimation::Frame&frame(part.frames[j]); if(r>0){ glBindTexture(GL_TEXTURE_2D,frame.tid); }else{ if(part.count!=1){ glGenTextures(1,&frame.tid); glBindTexture(GL_TEXTURE_2D,frame.tid); glTexParameterx(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterx(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } initTexture( frame.map->getDataPtr(), frame.map->getDataLength()); } if(!clearReg.isEmpty()){ Region::const_iteratorhead(clearReg.begin()); Region::const_iteratortail(clearReg.end()); glEnable(GL_SCISSOR_TEST); while(head!=tail){ constRect&r(*head++); glScissor(r.left,mHeight-r.bottom, r.width(),r.height()); glClear(GL_COLOR_BUFFER_BIT); } glDisable(GL_SCISSOR_TEST); } glDrawTexiOES(xc,yc,0,animation.width,animation.height); eglSwapBuffers(mDisplay,mSurface); nsecs_tnow=systemTime(); nsecs_tdelay=frameDuration-(now-lastFrame); lastFrame=now; longwait=ns2us(frameDuration); if(wait>0) usleep(wait); } usleep(part.pause*ns2us(frameDuration)); } //freethetexturesforthispart if(part.count!=1){ for(intj=0;j<fcount;j++){ constAnimation::Frame&frame(part.frames[j]); glDeleteTextures(1,&frame.tid); } } } returnfalse; } 第一层for循环用来显示每一个动画片断,第二层的for循环用来循环显示每一个动画片断,第三层的for循环用来显示每一个动画片断所对应的png图片。这些png图片以纹理的方式来显示在屏幕中。 注意,如果一个动画片断的循环显示次数不等于1,那么就说明这个动画片断中的png图片需要重复地显示在屏幕中。由于每一个png图片都需要转换为一个纹理对象之后才能显示在屏幕中,因此,为了避免重复地为同一个png图片创建纹理对象,第三层的for循环在第一次显示一个png图片的时候,会调用函数glGenTextures来为这个png图片创建一个纹理对象,并且将这个纹理对象的名称保存在对应的Animation::Frame对象的成员变量tid中,这样,下次再显示相同的图片时,就可以使用前面已经创建好了的纹理对象,即调用函数glBindTexture来指定当前要操作的纹理对象。 如果Region对象clearReg所包含的区域不为空,那么在调用函数glDrawTexiOES和eglSwapBuffers来显示每一个png图片之前,首先要将它所包含的区域裁剪掉,避免开机动画可以显示在指定的位置以及大小中。 每当显示完成一个png图片之后,都要将变量frameDuration的值从纳秒转换为毫秒。如果转换后的值大小于,那么就需要调用函数usleep函数来让线程睡眠一下,以保证每一个png图片,即每一帧动画都按照预先指定好的速度来显示。注意,函数usleep指定的睡眠时间只能精确到毫秒,因此,如果预先指定的帧显示时间小于1毫秒,那么BootAnimation类的成员函数movie是无法精确地控制地每一帧的显示时间的。 还有另外一个地方需要注意的是,每当循环显示完成一个片断时,需要调用usleep函数来使得线程睡眠part.pause * ns2us(frameDuration)毫秒,以便可以按照预先设定的节奏来显示开机动画。 最后一个if语句判断一个动画片断是否是循环显示的,即循环次数不等于1。如果是的话,那么就说明前面为它所对应的每一个png图片都创建过一个纹理对象。现在既然这个片断的显示过程已经结束了,因此,就需要释放前面为它所创建的纹理对象。 至此,第三个开机画面的显示过程就分析完成了。 本文转自 Luoshengyang 51CTO博客,原文链接:http://blog.51cto.com/shyluo/967046,如需转载请自行联系原作者

优秀的个人博客,低调大师

阿里云双11访谈之中间件

以下内容根据访谈视频整理而成 中间件技术一开始是支撑阿里云内部的系统。很多外部客户在从集中式系统向分布式系统转型过程中碰到一些技术上的难题。为了更好的服务客户、把阿里云一些成熟的技术分享给外部的客户,阿里云推出了类似恢复框架、消息队列、实时监控、性能测试等一系列互联网中间件产品。 在制作EDAS产品过程中,一开始我们对外部客户提供应用的基础功能,包括应用管理、应用的发布等一系列功能,之后我们将阿里内部RPC框架提供给外部客户,希望外部客户能够基于EDAS平台进行微服架构的快速构建,并帮助他们开发应用。除此之外,我们会在这层之上,向外部客户提供像服务治理、高可用管控、限流降级等一系列功能。 用户在什么场景下会使用到限流降级这一功能? 限流降级比较针对有一定规模的互联网公司。这些公司会在特定时间有产品大促活动导致非常多的用户在同一时间使用系统

优秀的个人博客,低调大师

阿里云双11访谈之ECS弹性计算

以下内容根据访谈视频整理而成 在2017年,阿里云不仅完成了ECS企业级产品的发布,而且完成了一次软件和硬件的数据迭代,推出了新一代硬件架构和软件架构产品,同时还持续优化和挖掘现有功能和产品形态优势,把弹性发挥到极致,在弹性上做了进一步功能优化和深度挖掘。 今年阿里云ECS升级带来了哪些方面的提升? 在企业线发布之前,很多企业客户也在使用阿里云ECS产品,体验也还良好。作为产品方,我们很清楚企业在某种特定场景下用当时的产品是否能达到最优的性价比。答案肯定是否定的。所以针对企业的复杂场景,如数据库、大数据、针对性AI运算等,我们有很多新定义的产品,保证在特定场景下,客户能选择最优性价比的产品。这也是阿里云发布企业线的根本目的。 如何做到企业级产品在性能和价格上的优化及场景化方式推荐? 在企业级产品的定义里,我们对各种软硬件体系架构进行了深度优

优秀的个人博客,低调大师

Azure China (11) 使用Azure China Storage Public Blob

《Windows Azure Platform 系列文章目录》 本文介绍的是国内由世纪互联运维的Azure China 注意:本文介绍的是Azure China Storage Public Blob,即可以通过匿名访问到Azure Storage云存储中的内容 项目源代码下载地址:http://files.cnblogs.com/files/threestone/AzurePublicBlob.rar 我们需要收集的内容如下: 1.Azure Storage Account Name 2.Azure Storage Account Key 3.修改源代码的web.config文件 1.首先我们需要查看Azure Storage Account Name和Account Key 2.使用Visual Studio 2013,下载并打开项目文件。 3.修改项目文件中的Web.config文件: <appSettings> <!--存储账号名称--> <add key="AccountName" value="[accoountname]" /> <!--存储账号密钥--> <add key="AccountKey" value="[accountkey]" /> <!--ContainerName,必须是小写--> <add key="ContainerName" value="publiccontainer" /> </appSettings> 修改上面的AccountName和AccountKey参数 4.运行项目代码 本文转自Lei Zhang博客园博客,原文链接:http://www.cnblogs.com/threestone/p/5506711.html,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码