在 Eclipse 中直接查看 Android SDK 源代码的方法

 在学习 Android 开发的过程中,经常调用一个类的方法的时候,总想按住 command + 鼠标左键 去点击这个方法,试图进入该类的源代码中看看是怎样实现的,但屡屡都报找不到 Android 源代码的错误。不爽,于是就干脆去下源代码好了。

Android SDK 官方源代码的下载地址:http://source.android.com/source/downloading.html

按照上面的教程一步一步来,就可以很方便地将源代码拖回到本地硬盘上,占用了我硬盘 9 个 G 的空间!不过这个教程是针对 Linux 或 Mac OS X 系统的。

然后在 Eclipse 中点击项目中的 android.jar,在右键菜单中选择“属性”,Location 指向刚刚下回来的源代码库的根目录,硬盘一阵狂响,搞定。

源代码全部出来了,很爽有木有?

Posted in 代码人生 | Tagged , , | 1 Comment

CoCoa Touch: pushViewController’s flip effect

来源:http://stackoverflow.com/questions/2506647/iphone-flip-animation-when-controller-pushed 

总所周知,在 CoCoa Touch 中通过设置 modalTransitionStyle 属性可以很方便地在切换 ViewController 的时候实现各种动画效果,但如果使用 pushViewController 则不会出现如何效果,如果在 pushViewController 中实现 Flip 的翻页的效果呢? 废话不多说,上代码:

1
2
3
4
5
[UIView beginAnimations:@"animation" context:nil];
[self.navigationController pushViewController:myController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
[UIView setAnimationDuration:0.7];
[UIView commitAnimations];
Posted in 代码人生 | Tagged , , | Leave a comment

Pirates of Silicon Valley

Posted in Mac Geek | Tagged , , , | Leave a comment

jQueryMobile新版中导航栏按钮消失的解决方法

 

最近将jQueryMobile的库更新到最新版后,发现以前用 jQueryMobile 写的一些东西, header 导航栏上的“后退”按钮统统不见了。这个功能挺贴心的,可以自动为你的 Web App 在不同页面之间跳转的时候增加导航功能。于是翻 jQueryMobile 的官方文档,在不起眼的地方发现了这样一句话:

jQuery Mobile has a feature to automatically create and append "back" buttons to any header, though it is disabled by default. This is primarily useful in chromeless installed applications, such as those running in a native app web view. The framework automatically generates a "back" button on a header when the page plugin’s addBackBtn option is true. This can also be set via markup if the page div has a data-add-back-btn="true" attribute.

原来默认把这个功能是关闭。打开它很简单,需要在页面源代码的 page 中加上 data-add-back-btn="true" 。

同时页面的代码中加上一句 js 代码即可:

1
2
3
$(document).bind("mobileinit", function() {
    $.mobile.page.prototype.options.addBackBtn = true;
});
Posted in 代码人生 | Tagged , , | Leave a comment

I like this video

虽然我是个果粉,但这次小米手机超高的性价比还是足够吸引住了咱的眼球。公司不少兄弟伙的手机刷的都是小米的系统,他们的产品从功能到细节,都做得非常有诚意。这样认真做事而不是哗众取宠的公司,值得去尊重。如果有机缘,我会预订一台小米手机。

我很喜欢它们的宣传视频。

 

Posted in 网络玩家 | Tagged | 1 Comment

New iPad2 Ad: We’ll Always

Posted in Mac Geek | Tagged | Leave a comment

pman – PHP Help as a Man Page

1
2
3
$ pear channel-discover doc.php.net
$ pear install doc.php.net/pman 
$ pman urlencode

Posted in PHP心得 | Tagged , | Leave a comment

PHP中file_get_contents超时的设置

 最近写PHP遇到一件挺郁闷的事情,用flie_get_contents获得一个网页的内容,如果网速很慢或下载这个页面需要很长的时间,就会经常超时,发出[function.file-get-contents]: failed to open stream: HTTP request failed! 错误。即使设置php.ini中的执行超时或者在代码中加入set_limit_time函数延长超时时间也无济于事。Google一下,找到了解决方法,需要在file_get_contents的参数中进行超时的设置,代码如下:

1
2
3
4
5
6
7
8
// Create the stream context 
$context = stream_context_create(array(
     'http' => array(
      'timeout' => 3000 //超时时间,单位为秒
     ) 
));  
// Fetch the URL's contents 
$contents = file_get_contents('http://sample.com', 0, $context);
Posted in PHP心得 | Tagged , | 2 Comments

《NCIS》Gibbs rules文字版

 

Posted in 美剧笔记 | Tagged , | Leave a comment

iOS中使用QLPreviewController来预览文件

 Mac OS系统有一个很方便的功能就是文件预览,在Finder中选中一个文件,按下空格键就能够预览其中的内容。支持图片、文档、视频等类型。在iOS4.0系统中,官方SDK提供了一个QLPreviewController,使用它就可以让我们的App在iPhone/iPad中直接预览各个文件了。官方的开发文档中说明其支持的文件类型有:

  1. iWork文档
  2. 微软Office97以上版本的文档
  3. RTF文档
  4. PDF文件
  5. 图片文件
  6. 文本文件和CSV文件

使用方法也很简单,直接alloc出一个QLPreviewController对象,用presentModalViewController方法把它调出来即可。要指定QLPreviewController预览那个文件,只要直接实现它的代理方法previewItemAtIndex,返回一个NSURL对象即可:

1
2
3
4
- (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)idx
{   
    return [NSURL fileURLWithPath:[NSString stringWithFormat:@“%@/Documents/files/%@”, NSHomeDirectory(), [fileList objectAtIndex:currentIndex]]];
}

 

直接预览PDF,效果不错

Posted in Mac Geek, 代码人生 | Tagged , , | Leave a comment