首页 文章 精选 留言 我的

精选列表

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

ios开发使用UIWebView显示多种文档

使用UIWebView显示多种文档 除了HTML的内容,UIWebView还可以显示多种类型的文档 包括以下的类型 ·Excel (.xls) ·Keynote (.key.zip) ·Numbers (.numbers.zip) ·Pages (.pages.zip) ·PDF (.pdf) ·Powerpoint (.ppt) ·Word (.doc) ·Rich Text Format (.rtf) ·Rich Text Format Directory (.rtfd.zip) ·Keynote '09 (.key) ·Numbers '09 (.numbers) ·Pages '09 (.pages) 其中的rtfd必须是文档包的格式并且时zip压缩,同时调用时还应该保留文件后缀名rtfd.zip 使用时参照 -(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView { NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil]; NSURL *url = [NSURL fileURLWithPath:path]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [webView loadRequest:request]; } // Calling -loadDocument:inView: [self loadDocument:@"mydocument.rtfd.zip" inView:self.myWebview]; 本文转自 arthurchen 51CTO博客,原文链接:http://blog.51cto.com/arthurchen/801318,如需转载请自行联系原作者

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

iOS开发-搜索栏UISearchBar和UISearchController

iOS中UISearchDisplayController用于搜索,搜索栏的重要性我们就不说了,狼厂就是靠搜索起家的,现在越来越像一匹没有节操的狼,UC浏览器搜索栏现在默认自家的神马搜索,现在不管是社交,O2O还是在线教育等都会有一个搜索栏的实现,不过彼此实现效果是不一样的。iOS中的搜索栏实现起来相对简单一点,网上也有很多参考资料,不过靠谱的不是很多,很多都是iOS 8.0之前的实现,iOS 8.0上的实现貌似很少看到,可以运行,不过会看到searchDisplayController' is deprecated: first deprecated in iOS 8.0警告,看了一些老外的代码,使用了一下UISearchController感觉还是非常不错的。 UISearchBar和UISearchDisplayController 是网上最常见的也算是最简单的,也有使用Searh Bar Search Display Controller的控件的,本文就简单的使用Search Bar和UITableView实现搜索Demo的,最上面的就是搜索栏,之前的就是TableView: 为了实现搜索需要声明委托UISearchBarDelegate,UISearchDisplayDelegate,其中搜索主要使用的就是UISearchDisplayDelegate,具体代码实现过程: 声明字段: 1 2 3 @property (strong, nonatomic ) NSMutableArray *dataList; @property (strong, nonatomic ) NSMutableArray *searchList; 初始化数据: 1 2 3 4 5 self .dataList=[ NSMutableArray arrayWithCapacity:100]; for ( NSInteger i=0; i<100; i++) { [ self .dataList addObject:[ NSString stringWithFormat:@ "%ld-FlyElephant" ,( long )i]]; } 设置区域: 1 2 3 4 //设置区域 -( NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } 设置区域的行数(重点),这个就是使用委托之后需要需要判断是一下是否是需要使用Search之后的视图: 1 2 3 4 5 6 7 -( NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:( NSInteger )section{ if (tableView == self .searchDisplayController.searchResultsTableView) { return [ self .searchList count]; } else { return [ self .dataList count]; } } 同样的返回单元格也有两种情况,一种是初始化数据,一种是过滤之后的数据视图: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath{ static NSString *flag=@ "cellFlag" ; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:flag]; if (cell== nil ) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:flag]; } if (tableView== self .searchDisplayController.searchResultsTableView) { [cell.textLabel setText: self .searchList[indexPath.row]]; } else { [cell.textLabel setText: self .dataList[indexPath.row]]; } return cell; } UISearchBarDelegate中的开始和结束的事件: 1 2 3 4 5 6 7 8 9 - ( BOOL )searchBarShouldBeginEditing:(UISearchBar *)searchBar{ NSLog (@ "搜索Begin" ); return YES ; } - ( BOOL )searchBarShouldEndEditing:(UISearchBar *)searchBar{ NSLog (@ "搜索End" ); return YES ; } 搜索时过滤数据: 1 2 3 4 5 6 7 8 9 10 11 12 - ( BOOL )searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:( NSString *)searchString{ // 谓词的包含语法,之前文章介绍过http://www.cnblogs.com/xiaofeixiang/ NSPredicate *preicate = [ NSPredicate predicateWithFormat:@ "SELF CONTAINS[c] %@" , searchString]; if ( self .searchList!= nil ) { [ self .searchList removeAllObjects]; } //过滤数据 self .searchList= [ NSMutableArray arrayWithArray:[_dataList filteredArrayUsingPredicate:preicate]]; //刷新表格 return YES ; } 最终效果如下: UISearchController实现搜索 UISeachBar通过UISearchDisplayDelegate实现上面的效果是没有问题的,网上也有很多类似的实现效果,不过是警告的,信息如下: 'searchDisplayController' is deprecated: first deprecated in iOS 8.0,这么明显一个警告总不能视而不见吧,在StackOverFlow中发现UISearchDisplayController is deprecatedinIOS8.0, and recommended to use UISearchController instead,也就是说iOS8.0不推荐UISearchDisplayController,也就是不推荐使用UISearchDisplayDelegate,但是可以通过UISearchController实现UISearchResultsUpdating这个委托实现上面的效果; 视图中中需要声明UISearchResultsUpdating: 1 2 3 4 @interface ViewController : UITableViewController<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UISearchResultsUpdating> @end 属性声明: 1 @property ( nonatomic , strong) UISearchController *searchController; 需要自己初始化一下UISearchController: 1 2 3 4 5 6 7 8 9 10 11 _searchController = [[UISearchController alloc] initWithSearchResultsController: nil ]; _searchController.searchResultsUpdater = self ; _searchController.dimsBackgroundDuringPresentation = NO ; _searchController.hidesNavigationBarDuringPresentation = NO ; _searchController.searchBar.frame = CGRectMake( self .searchController.searchBar.frame.origin.x, self .searchController.searchBar.frame.origin.y, self .searchController.searchBar.frame.size.width, 44.0); self .tableView.tableHeaderView = self .searchController.searchBar; 之前是通过判断搜索时候的TableView,不过现在直接使用self.searchController.active进行判断即可,也就是UISearchController的active属性: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 //设置区域的行数 -( NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:( NSInteger )section{ if ( self .searchController.active) { return [ self .searchList count]; } else { return [ self .dataList count]; } } //返回单元格内容 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath{ static NSString *flag=@ "cellFlag" ; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:flag]; if (cell== nil ) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:flag]; } if ( self .searchController.active) { [cell.textLabel setText: self .searchList[indexPath.row]]; } else { [cell.textLabel setText: self .dataList[indexPath.row]]; } return cell; } 具体调用的时候使用的方法也发生了改变,这个时候使用updateSearchResultsForSearchController进行结果过滤: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -( void )updateSearchResultsForSearchController:(UISearchController *)searchController { NSString *searchString = [ self .searchController.searchBar text]; NSPredicate *preicate = [ NSPredicate predicateWithFormat:@ "SELF CONTAINS[c] %@" , searchString]; if ( self .searchList!= nil ) { [ self .searchList removeAllObjects]; } //过滤数据 self .searchList= [ NSMutableArray arrayWithArray:[_dataList filteredArrayUsingPredicate:preicate]]; //刷新表格 [ self .tableView reloadData]; } 效果演示: 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/4273620.html,如需转载请自行联系原作者

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

eclipse上Android NDK开发环境搭建

首先要有已集成好Android adt插件的eclipse,如果没有,到http://developer.android.com/sdk/index.html下载已集成ADT的eclipse。 下载Android NDK包http://developer.android.com/tools/sdk/ndk/index.html并解压。 打开eclipse,点击菜单栏 Windows ---> Preferences---> Android ---> NDK 找到上一步解压的NDK,点击OK 保存。 新建一个Android项目ndktest,并在工程下新建jni文件夹。 在编写native函数,例在com.example.ndktest下创建类 myjni。 运行cmd,定位到ndktest根目录下,运行命令javah -classpath bin\classes -d jni com.example.ndktest.myjni 会在jni文件下生成一个h头文件。 如果点开有报错,可以忽略它,可能因为找不到jni.h这个头文件,先不管。 在jni文件夹下编写com_example_ndktest_myjni.c文件实现方法getSum。 在jni文件夹下编写android.mk文件 在package Explorer 里,右键工程 ----> Properties 选择Program ---> OKOK 保存。 libmyjni.so 动态库已生成libs\armeabi文件夹下。 后面附上HTK中工具HCopy的Android 动态库工程的源码,下载导入工程后,确保已经安装好NDK,并修改第9步,第二图中的NDK_Builder的location到你的NDK包下的cmd即可。 上述例子工程源码:http://down.51cto.com/data/1499353 HCopy动态库工程源码:http://down.51cto.com/data/1499346 本文转自 ponpon_ 51CTO博客,原文链接:http://blog.51cto.com/liuxp0827/1438625,如需转载请自行联系原作者

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

Android开发应用实例:ListView的应用

该程序完成如下功能:1在ListView中显示多个学生的名字。2点击ListView中的条目,查询并显示该学生的年龄、性别、照片等信息。 效果图: student.java packagecom.lingdududu.listview; publicclassStudent{ publicStringsname; publicStringssex; publicintsage; Student(Stringname,Stringsex,intage){ sname=name; ssex=sex; sage=age; } voidStuedent(Stringname){ sname=name; } publicStringgetName(){ returnsname; } publicStringgetSex(){ returnssex; } publicintgetAge(){ returnsage; } publicStringtoString(){ returnsname; } //这个方法返回学生的姓名,性别,年龄 publicStringgetStuIfo(){ return("姓名:"+sname+"\n性别:"+ssex+"\n年龄:"+sage); } } ListViewActivity.java packagecom.lingdududu.listview; importjava.util.ArrayList; importandroid.app.Activity; importandroid.app.AlertDialog; importandroid.content.DialogInterface; importandroid.os.Bundle; importandroid.view.View; importandroid.widget.AdapterView; importandroid.widget.AdapterView.OnItemClickListener; importandroid.widget.ArrayAdapter; importandroid.widget.ListView; /* *@authorlingdududu *该程序的主要功能是点击ListView的学生姓名,就能弹出对话框 *在对话框里面显示学生的详细信息:图片,姓名,性别,年龄 */ publicclassListViewActivityextendsActivity{ privateListViewlv; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); //学生图片的ID数组 finalint[]stu_pic={ R.drawable.pic1, R.drawable.pic2, R.drawable.pic3, R.drawable.pic4, R.drawable.pic5, R.drawable.pic6}; finalAlertDialog.Builderbuilder=newAlertDialog.Builder(this); lv=(ListView)findViewById(R.id.list); /*生成动态数组,加入数据*/ finalArrayList<Student>students=newArrayList<Student>(); students.add(newStudent("小张","女",21)); students.add(newStudent("小明","男",22)); students.add(newStudent("小王","男",23)); students.add(newStudent("小丽","女",21)); students.add(newStudent("小红","女",22)); students.add(newStudent("小周","男",23)); ArrayAdapter<Student>adapter=newArrayAdapter<Student> (this,//布局文件 android.R.layout.simple_list_item_1,//android.R.layout.simple_list_item_1,系统定义的布局文件 students);//数据来源 //为ListView设置适配器 lv.setAdapter(adapter); lv.setOnItemClickListener(newOnItemClickListener(){ //arg0发生点击动作的AdapterView //arg1在AdapterView中被点击的视图(它是由adapter提供的一个视图) //arg2视图在adapter中的位置 //arg3被点击元素的行id publicvoidonItemClick(AdapterView<?>arg0,Viewarg1,intarg2, longarg3){ //将学生的详细信息在对话框里面显示 builder.setMessage(students.get(arg2).getStuIfo()) //显示学生的图片 .setIcon(stu_pic[arg2]) .setTitle("你好,这是我的详细信息!") .setPositiveButton("确定",newDialogInterface.OnClickListener(){ publicvoidonClick(DialogInterfacedialog,intwhich){ } }); //创建对话框 AlertDialogad=builder.create(); //显示对话框 ad.show(); } }); } } main.xml <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> 附件:http://down.51cto.com/data/2359281 本文转自 lingdududu 51CTO博客,原文链接: http://blog.51cto.com/liangruijun/716529

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

【移动开发】Android中各种xml汇总

Android中xml使用十分广泛,这里简单汇总一下,使其更加系统化! 1.arrays.xml 定义数组 1 2 3 4 5 6 7 <resources> <string-array name= "newstitle" > <item>国际</item> <item>国内</item> <item>军事</item> </string-array> </resources> 2.colors.xml 定义颜色 1 2 3 4 5 6 7 8 9 10 11 <resources> <color name= "blue_sky" >#A0C8FF</color> <color name= "vert_manu" >#CCFF00</color> <color name= "black" ># 000000 </color> <color name= "white" >#FFFFFF</color> <color name= "red" >#FF0000</color> <color name= "link_color" >#FF0066CC</color> <color name= "simiple_button_color" >#FFF</color> <color name= "blue" >#0000FF</color> <color name= "grey" >#FFCBD2D8</color> </resources> 3.dimens.xml 定义尺寸 1 2 3 4 5 <resources> <dimen name= "bottom_tab_font_size" >12dp</dimen> <dimen name= "bottom_tab_padding_up" >5dp</dimen> <dimen name= "bottom_tab_padding_drawable" >8dp</dimen> </resources> 4.drawables.xml 定义画布 1 2 3 4 5 6 7 <resources> <item type= "drawable" name= "shader1" >#7f7f7f7f</item> <item type= "drawable" name= "highlight" >#cf7f7f7f</item> <item type= "drawable" name= "barbg" >#ef0a4267</item> <item type= "drawable" name= "trans" ># 00000000 </item> <item type= "drawable" name= "chatdivider" >#ffd6dadc</item> </resources> 5.strings.xml 定义字符串 1 2 3 4 5 <resources> <string name= "app_name" >Beem</string> <string name= "OkButton" >Ok</string> <string name= "ClearButton" >Clear</string> </resources> 6.styles.xml 定义样式 1 2 3 4 5 6 7 8 9 <resources> <style name= "Label" > <item name= "android:textSize" >18sp</item> <item name= "android:textStyle" >bold</item> <item name= "android:typeface" >sans</item> <item name= "android:focusable" > false </item> <item name= "android:padding" >12dip</item> </style> </resources> 7.selector选择(按下效果) phoinix_popumenu_style.xml 1 2 3 4 5 <selector xmlns:android= "http://schemas.android.com/apk/res/android" > <item android:state_focused= "true" android:state_pressed= "true" android:drawable= "@drawable/phoinix_pushmail_btn_selected" /> <item android:state_focused= "false" android:state_pressed= "true" android:drawable= "@drawable/phoinix_pushmail_btn_selected" /> <item android:state_focused= "true" android:drawable= "@drawable/phoinix_small_selected" /> </selector> 8.menu 菜单 1 2 3 4 5 6 7 8 9 10 11 12 13 <menu xmlns:android= "http://schemas.android.com/apk/res/android" > <group> <item android:id= "@+id/chat_menu_contacts_list" android:visible= "true" android:title= "@string/chat_menu_contacts_list" android:icon= "@drawable/ic_menu_friendslist" /> <item android:id= "@+id/chat_menu_change_chat" android:visible= "true" android:title= "@string/chat_menu_change_chat" android:icon= "@drawable/ic_menu_chat_dashboard" /> </group> <item android:id= "@+id/chat_menu_close_chat" android:visible= "true" android:title= "@string/chat_menu_close_chat" android:icon= "@drawable/ic_menu_end_conversation" /> </menu> 8.anim 旋转动画 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 < set xmlns:android= "http://schemas.android.com/apk/res/android" > <rotate android:interpolator= "@android:anim/accelerate_decelerate_interpolator" android:fromDegrees= "0" android:toDegrees= "+360" android:duration= "3000" /> <!-- rotate 旋转动画效果 属性:interpolator 指定一个动画的插入器,用来控制动画的速度变化 fromDegrees 属性为动画起始时物件的角度 toDegrees 属性为动画结束时物件旋转的角度,+代表顺时针 duration 属性为动画持续时间,以毫秒为单位 --> </ set > 以上这些就是android中常用的xml,至于其他的自行查阅喽~ 本文转自zhf651555765 51CTO博客,原文链接:http://blog.51cto.com/smallwoniu/1248892,如需转载请自行联系原作者

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

一次Hadoop开发思路分享

困扰了自己1周的一个问题终于得到解决了,感谢给我帮助的同学,同时记录下来分享给大家. 问题简化描述: HDFS存在这样格式的文件:用户ID主题ID用户对此主题的偏好分数score。 现在要求实现对给定的几个主题T1,T2,T3,...TN,每个主题要求筛选出指定数量的用户ID是M1,M2,M3,...MX。 希望尽可能根据score来选出偏好的用户ID,并且主题之间的用户ID不可以重复。 另外HDFS上distinct的用户ID数量是大于等于M1+M2+M3+...+MX的。 思路分析: 问题有几个关键点,第一,不重复,第二,数量上要满足,第三,偏好分数score。 如何保证,主题之间的用户不重复呢? 其实就是完成,一个用户只能属于一个主题的过程,当然,我们可以很简单的对一个用户下的所有偏好分数进行排序,取出最偏好的主题。 虽然这样避免了重复的问题,可是问题来了,如果偏好主题T1要求的数量是100W,而仅仅只有90W的用户ID对T1最偏好,这该如何补数呢?又如何通过程序来自动化的实现这个过程呢?越想越复杂! 这个问题好像有点类似于高考填自愿的问题,我们每一个人会填写几个志愿,但是我们终究只会被一个院校录取,这是怎么做到的呢?是否可以从中借鉴呢? 首先,我们根据HDFS的内容,写一个MapReduce完成一次计算,形成下面的用户志愿HDFS内容: 用户ID 主题ID-A:score1;主题ID-B:score2;... 很简单,希望得到一个用户ID下面按照score desc排序的主题列表,上面一行其实就是说: 用户ID的第一志愿是主题A,第二志愿是主题B...。 ------------------------------------------ 接下来,形成下面的一个列表list信息: 主题A count-A 主题B count-B 主题C count-C ... 按照主题需要的用户ID的数量进行ASC排序。 ------------------------------------------ 下面,我们就来看如何进行主题选择用户的过程: 我们首先选择对数量要求最少的主题A完成下面的MapReduce计算: 这样,我们就完成了主题A的用户筛选问题。 接下来,我们取出list中数量要求比A多一点的主题B,那么它怎么取用户呢? 很简单,我们只需要在MAP处理阶段,传递主题A生成的结果HDFS路径(路径下面的文件内容当然是主题A的用户)用于reduce阶段取用户时进行过滤。 那么,主题C又如何取用户呢? 类似的,只需要给MAP多传递主题A,主题B已经占用的用户信息用于过滤,其他处理操作不变! 其实,我们可以发现,上面的MapReduce其实可以是一个通用的程序,类似于COMMAND: hadoop jar XXX.jar 主题ID 数量 [input1,input2,input3,...] 用户志愿HDFS路径 输出路径 其中input1,input2,input3,...是可选的,其实就是用于用户过滤的。 最后,我们可以写一个Shell脚本,根据list的内容来进行重复调用上面的COMMAND,通过传递不同的参数信息达到目的,这样我们就可以自动化实现上面的要求了! 本文转自zfz_linux_boy 51CTO博客,原文链接:http://blog.51cto.com/zhangfengzhe/1689902,如需转载请自行联系原作者

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

Android开发学习笔记:圆角的Button

在res目录下的drawable-mdpi建立xml文件shape.xml,如下图所示: shape.xml <?xmlversion="1.0"encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!--填充的颜色--> <solidandroid:color="#FFFFFF"/> <!--设置按钮的四个角为弧形--> <!--android:radius弧形的半径--> <cornersandroid:radius="5dip"/> <!--padding:Button里面的文字与Button边界的间隔--> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> main.xml 在android:background="@drawable/shape"就使用了shape.xml资源 <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/roundButton" android:text="圆角按钮" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/shape" /> </LinearLayout> strings.xml <?xmlversion="1.0"encoding="utf-8"?> <resources> <stringname="hello">HelloWorld,RoundButtonDemoActivity!</string> <stringname="app_name">RoundButtonDemo</string> </resources> RoundButtonDemoActivity.java packagecom.android.RoundButtonDemo.activity; importandroid.app.Activity; importandroid.os.Bundle; importandroid.view.View; importandroid.view.View.OnClickListener; importandroid.widget.Button; importandroid.widget.Toast; publicclassRoundButtonDemoActivityextendsActivity{ ButtonroundButton; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); roundButton=(Button)findViewById(R.id.roundButton); //使用匿名类注册Button事件 roundButton.setOnClickListener(newOnClickListener() { publicvoidonClick(Viewv) { Toast.makeText(RoundButtonDemoActivity.this,"你点击了圆角按钮",Toast.LENGTH_LONG).show(); } }); } } 效果图: 本文转自 lingdududu 51CTO博客,原文链接:http://blog.51cto.com/liangruijun/630051

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

Android开发学习笔记:浅谈Content Provider

一.Content Provider的概念介绍 Content Providers是所有应用程序之间数据存储和检索的桥梁,它使得各个应用程序之间实现数据共享。是应用程序间共享数据的唯一途径。Content Provider 主要的功能就是存储并检索数据以及向其他应用程序提供访问数据的接口。其中包括添加,删除,查询,更新等操作。 在Content Provider使用过程中,还需要借用ContentResolver对象间接来操作ContentProvider来获取数据。ContentResolver通过应用程序的getContentResolver()方法获得。一般情况下,ContentResolver是单实例的,但是可以有多个ContentResolver在不用的应用程序和不同的进程之间和ContentResolver交互。 二.Content Provider的简介 1.Content Provider的常用方法 //查询 query(Uri,String[],String,String[],String); //插入 insert(Uri,ContentValues); //更新 update(Uri,ContentValues,String,String[]); //删除 delete(Uri,String,String[]); //获得MIME数据类型 getType(Uri); 2.数据模型 Content Provider 将其存储的数据以数据表的形式提供给访问者,在数据表中每一行为一条记录,每一列为具有特定类型和意义的数据。每一条数据记录都包括一个 "_ID" 数值字段,改字段唯一标识一条数据。 _ID NUMBER NUMBER_KEY LABEL NAME TYPE 13 (425) 555 6677 425 555 6677 Kirklandoffice Bully Pulpit TYPE_WORK 44 (212) 555-1234 212 555 1234 NY apartment Alan Vain TYPE_HOME 45 (212) 555-6657 212 555 6657 Downtown office Alan Vain TYPE_MOBILE 53 201.555.4433 201 555 4433 Love Nest Rex Cars TYPE_HOME 3.URI URI,每一个Content Provider 都对外提供一个能够唯一标识自己数据集(data set)的URI, 如果一个Content Provider管理多个数据集,其将会为每个数据集分配一个独立的URI。Content Provider就是通过URI对象来共享其数据的。 URI的格式图如下: 各个部分的组成: A:标准前缀,是固定的,"content://"是用来标识数据是由Content Provider管理的 schema。 B:URI的标识,它定义了是哪个Content Provider提供这些数据。对于第三方应用程序,为了保证URI标识的唯一性,它必须是一个完整的、小写的类名。这个标识在 元素的 authorities属性中说明:一般是定义该ContentProvider的包.类的名称 C:需要访问的数据字段名称。 D:如果URI中包含表示需要获取的记录的_ID;如何有D部分,则就返回该_ID对应的数据,否则表示返回整张表的数据 三.Content Provider实例 Anroid系统自带的Content Provider对象 获得系统联系人信息(姓名和手机号码)的例子 MainActivity.java packagecom.lingdududu.provide; importandroid.app.Activity; importandroid.os.Bundle; importandroid.provider.ContactsContract; importandroid.provider.ContactsContract.PhoneLookup; importandroid.database.Cursor; importandroid.graphics.Color; importandroid.widget.TextView; importandroid.content.ContentResolver; publicclassMainActivityextendsActivity{ publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); TextViewtv=newTextView(this); Stringstring=getQueryData(); //设置文本的颜色 tv.setTextColor(Color.BLUE); //设置TextView显示的内容 tv.setText(string); //设置文本字体的大小 tv.setTextSize(30.0f); //显示到屏幕 setContentView(tv); } publicStringgetQueryData(){ Stringstring=""; //得到ContentResolver对象 ContentResolvercr=getContentResolver(); //取得电话本中开始一项的光标 Cursorcursor=cr.query(ContactsContract.Contacts.CONTENT_URI,null, null,null,null); //向下移动光标 while(cursor.moveToNext()){ //取得联系人名字 intnameFieldColumnIndex=cursor .getColumnIndex(PhoneLookup.DISPLAY_NAME); Stringcontact=cursor.getString(nameFieldColumnIndex); //取得电话号码 StringContactId=cursor.getString(cursor .getColumnIndex(ContactsContract.Contacts._ID)); Cursorphone=cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID+"=" +ContactId,null,null); while(phone.moveToNext()){ StringPhoneNumber=phone .getString(phone .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); string+=(contact+":"+PhoneNumber+"\n"); } } cursor.close(); returnstring; } } 注意:记得在AndroidManifest.xml加上17行的权限声明 <?xmlversion="1.0"encoding="utf-8"?> <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.lingdududu.provide" android:versionCode="1" android:versionName="1.0"> <uses-sdkandroid:minSdkVersion="10"/> <applicationandroid:icon="@drawable/icon"android:label="@string/app_name"> <activityandroid:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <actionandroid:name="android.intent.action.MAIN"/> <categoryandroid:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> <uses-permissionandroid:name="android.permission.READ_CONTACTS"/> </manifest> 通讯录中联系人的信息: 效果图: 本文转自 lingdududu 51CTO博客,原文链接: http://blog.51cto.com/liangruijun/667264

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

Android 项目开发基础再回顾(一)

1,主activity_splash: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/launcher_bg"//设置初始背景图片 tools:context=".SplashActivity" > <TextView android:id="@+id/tv_version_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"#把这个textview 放到中间 android:shadowDx="1//这个指的是相对于原字体在x方向上的偏移量 android:shadowDy="1" android:shadowColor="#f00"//黑色 android:shadowRadius="1"//表示阴影的模糊程度 android:textSize="16sp" android:text="版本名称" /> <ProgressBar //加载滚动条 android:layout_below="@id/tv_version_name" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> 2,副activity_home <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:text="HomeActivity" android:textSize="20sp" android:textColor="#000" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> 3,让第二个活动可以启动 <activity android:name="com.example.moblesafe73.HomeActivity"/> 4,接下来创造两个工具类, 一个是将流转化为字符串 mport java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class StreamUtil { public static String StreamToString(InputStream is) { //1.在读取的过程中,将读取的内容存取到缓存中,然后一次性用字符转化成字符串 ByteArrayOutputStream bos=new ByteArrayOutputStream(); //2.读取操作,读到没有为止(循环) byte[] buffer=new byte[1024]; //3.记录读取内容的临时变量 int temp=-1; try { while((temp=is.read(buffer))!=-1){ bos.write(buffer,0,temp); } //返回读取的数据 return bos.toString(); } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); }finally{ try { is.close(); bos.close(); } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } return null; } } 另一个是可以弹出toast import android.content.Context; import android.widget.Toast; public class ToastUtils { public static void show(Context ctx,String msg){ Toast.makeText(ctx, msg, 0).show(); } } 5,主营业务的介绍: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //去除当前activity头title requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_splash); //初始化ui initUI(); //初始化方法 initData(); } 6,关于如何初始化ui private void initUI() { // TODO 自动生成的方法存根 tv_version_name = (TextView) findViewById(R.id.tv_version_name); } 找到相应控件 private void initData() { // TODO 自动生成的方法存根 //应用版本名称 tv_version_name.setText(getVersionName()); //获取本地服务版本号 myLockVersionCode = getVersionCode(); //获取服务器版本号(客户端发请求,服务器给相应(json,xml一般用的是json)) checkVersion(); } //返回版本号 private int getVersionCode() { // TODO 自动生成的方法存根 //1,包管理者对象packagemanager PackageManager pm=getPackageManager(); //2,从包的管理者对象中,获取指定包名的基本信息(版本名称,版本号,0代表基本信息) try { PackageInfo packageinfo=pm.getPackageInfo(getPackageName(), 0); return packageinfo.versionCode; } catch (NameNotFoundException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } return 0; } 这个方法可以 再来看checkVersion();方法 如果上网的话需要用到线程方面的知识 private void checkVersion() { new Thread(){ public void run(){ //Message message=new Message(); Message msg=Message.obtain(); long startTime=System.currentTimeMillis();//程序开始的时间 try { //封装url地址 URL url=new URL("http://192.168.1.104:8080/update74.json"); //开启一个地址 HttpURLConnection connection=(HttpURLConnection)url.openConnection(); //3,设置常见的请求参数(请求头) //请求超时 connection.setConnectTimeout(2000); //读取超时 connection.setReadTimeout(2000); //默认是get请求 //connection.setRequestMethod("POST"); //获取请求响应码 if(connection.getResponseCode()==200){ //5.以流的形式,将数据保存起来 InputStream is=connection.getInputStream(); //6.将流换成字符串(工具类封装) String json=StreamUtil.StreamToString(is); Log.i(tag, json);//打印日志 //7.json解析 JSONObject jsonObject=new JSONObject(json); String versionName=jsonObject.getString("versionName"); mversionDes = jsonObject.getString("versionDes"); String versionCode=jsonObject.getString("versionCode"); mdownloadUrl = jsonObject.getString("downloadUrl"); Log.i(tag, versionName); Log.i(tag, mversionDes); Log.i(tag, versionCode); Log.i(tag, mdownloadUrl); //8,比对版本号(服务器版本号,提示用户更新) if(myLockVersionCode <Integer.parseInt(versionCode)){ //提示用户更新,弹出对话框 msg.what=UPDATE_VERSION; }else{ //进入应用程序主界面 msg.what=ENTER_HOME; } } }catch (MalformedURLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); msg.what=URL_ERROR; }catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); msg.what=IO_ERROR; } catch (JSONException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); msg.what=JSON_ERROR; }finally{ //请求网络的时长超过四秒则不做处理 //请求小于四秒,强制让其睡眠四秒 long endTime=System.currentTimeMillis(); if(endTime-startTime<4000) { try { Thread.sleep(4000-(endTime-startTime)); } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } mhandler.sendMessage(msg); } }; }.start(); 对上述信息进行相关的处理: private Handler mhandler=new Handler(){ public void handleMessage(android.os.Message msg){ switch(msg.what){ case UPDATE_VERSION: //弹出对话框,提示用户更新 showUpdateDialog();//弹出一个对话框,让我们进行更新 break; case ENTER_HOME: enterHome(); break; case IO_ERROR: ToastUtils.show(getApplicationContext(), "IO异常"); enterHome(); break; case URL_ERROR: ToastUtils.show(getApplicationContext(), "url异常"); enterHome(); break; case JSON_ERROR: ToastUtils.show(getApplicationContext(), "URL异常");//SplashActivity.this enterHome(); break; } } }; protected void showUpdateDialog() { // TODO 自动生成的方法存根 //对话框是依赖activity存在的 Builder builder = new AlertDialog.Builder(this);//必须用this,而不是getApplicationContext() builder.setIcon(R.drawable.ic_launcher); builder.setTitle("版本更新"); //设置描述内容 builder.setMessage(mversionDes);//这个描述内容见上文是由其发送过来的 //积极按钮,立即更新 builder.setPositiveButton("立即更新", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //下载apk,apk链接地址,downloadUrl downloadApk(); } });//创建两个按钮监听器 builder.setNegativeButton("稍后再说", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //取消对话框,进入主界面 enterHome(); } }); builder.show(); } 接下来是对文件进行下载 protected void downloadApk() { //apk下载链接地址,放置apk的所在路径 //1,判断sd卡是否可用,是否挂在上 if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ //2,获取sd卡路径 String path=Environment.getExternalStorageDirectory().getAbsolutePath() +File.separator+"mobilesafe73.apk"; //发送请求,获取sdk,并且添加到指定路径 HttpUtils httpUtils=new HttpUtils(); //发送请求,传递参数吧(下载应用放置的位置) httpUtils.download(mdownloadUrl, path,new RequestCallBack<File>() {//mdownloadUrl刚才所获得的下载的地址 @Override public void onSuccess(ResponseInfo<File> responseInfo) { Log.i(tag, "下载成功"); // TODO 自动生成的方法存根 File file=responseInfo.result; //提示用户安装 installAPK(file); } @Override public void onFailure(HttpException arg0, String arg1) { Log.i(tag, "下载失败"); // TODO 自动生成的方法存根 } @Override public void onStart() { // TODO 自动生成的方法存根 Log.i(tag, "开始下载"); super.onStart(); } @Override public void onLoading(long total, long current, boolean isUploading) { // TODO 自动生成的方法存根 Log.i(tag, "下载中........"); Log.i(tag, "total = "+total); Log.i(tag, "current = "+current); super.onLoading(total, current, isUploading); } }); } } //开始安装 protected void installAPK(File file) { // TODO 自动生成的方法存根 //系统应用界面,源码,安装apk入口 Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); /*//文件作为数据源 intent.setData(Uri.fromFile(file)); //设置安装的类型 intent.setType("application/vnd.android.package-archive");*/ intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive"); // startActivity(intent); startActivityForResult(intent, 0); } //开启另一个界面 protected void enterHome() { Intent intent = new Intent(this,HomeActivity.class); startActivity(intent); //在开启一个新的界面后将导航界面关闭,因为导航界面只可见一次 finish(); } 本文转自眉间雪 51CTO博客,原文链接:http://blog.51cto.com/13348847/2046800,如需转载请自行联系原作者

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

Android开发之如何实现日历控件

我们大家都知道,在Android平台3.0中才新增了日历视图控件,可以显示网格状的日历内容,那么对于3.0以下的版本要使用日历控件只能借助第三方,目前用的最多的是CalendarView。 先简单介绍下CalendarView日历控件的使用。 android.widget.CalendarView是从android.widget.FrameLayout中继承。 CalendarView 类提供了基本的日历设置方法: long getDate() 获取从1970年,1月1日,0点0分0秒到现在的毫秒数,因为返回是long型最终只能截止到2038年 int getFirstDayOfWeek() //获取当天是本周的第几天,Android123提示返回的定义在java.util.Calendar类中,比如Calendar.Monday为星期一,定义值为2。 long getMaxDate() //获取CalendarView支持1970年到那天的最大天数 long getMinDate() //获取CalendarView支持1970年到那天的最小天数 boolean getShowWeekNumber() //获取是否显示星期号 boolean isEnabled() //是否显示本日历视图 public void setDate (long date, boolean animate, boolean center) //设置选择日期到1970年的描述 void setDate(long date) //设置选择的日期描述到1970年 void setEnabled(boolean enabled) //设置是否启用视图 void setFirstDayOfWeek(int firstDayOfWeek) //设置本周起始天数 void setMaxDate(long maxDate) void setMinDate(long minDate) void setOnDateChangeListener(CalendarView.OnDateChangeListener listener) //日历视图修改的接口,这个介绍看下面。 void setShowWeekNumber(boolean showWeekNumber) //设置是否显示周号 有关日历控件CalendarView的设置接口 android.widget.CalendarView.OnDateChangeListener 只实现了一个回调方法void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth)。 这四个参数的具体介绍为 view The view associated with this listener. year The year that was set. month The month that was set [0-11]. dayOfMonth The day of the month that was set. 下面给大家展示这几种有用的日历控件效果图: 这是CalendarView的效果图。可以实现上月和下月翻页,设置事件等。 这个日历控件也比较强大,但外观不够友好。 这是我们自己实现的日历控件。可以通过选择日期查询相关数据等操作。 这是Android3.0及以上版本自带的日历控件。 本文转自 wws5201985 51CTO博客,原文链接:http://blog.51cto.com/wws5201985/818593,如需转载请自行联系原作者

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

Android开发者指南(2) —— aapt

正文 使用aapt aapt是标准的Android辅助打包工具,位于SDK的tools/文件夹下。该工具允许查看、创建或更新Zip兼容格式(zip,jar,apk)的文档,并且能将资源编译到二进制格式的包中。 通常不需要直接使用aapt工具,IDE插件和编译脚本能利用它打包apk文件来合成应用程序。 详细的用法可以打开命令行终端,到tools文件夹下运行如下命令: Linux或Mac OS X: ./aapt Windows: aapt.exe 本文转自over140 51CTO博客,原文链接:http://blog.51cto.com/over140/582290,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

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

Sublime Text

Sublime Text

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

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