Eclipse 启动后被 "Android Library Update" 任务所阻塞

有时候 Eclipse 启动后,会一直阻塞在 "Android Library Update" 任务中,无法执行任何操作,包括保存文件修改、编译、运行等,甚至正常退出 Eclipse 都不行。这一般是由于上一次的不正常退出所导致的。

如果反复重启 Eclipse 依然如此,可以试试这个办法:在启动 Eclipse 后,立即执行 "Clean all projects" 任务(必须赶在 "Android Library Update" 自动执行之前,否则会被其阻塞而无法做任何事情)。执行完 "Clean all projects" 之后,应该就不会再被阻塞了。

更彻底的办法是,删掉 workspace 下面的 .metadata 目录,不过该方法比较暴力,将会清除所有的 project 信息,建议慎用。

引用链接 http://minotes.net/notes/15

Ubuntu 12.04 Server安装Bittorrent Transmission

Ubuntu Server 没有图形界面,如果作为BT 下载服务器的话,可以使用Bittorrent Transmission 来通过Web界面操作,类似http://192.168.1.X:9091这样的方式管理下载。

1.安装服务器端

2.配置文件修改

主要调整如下部分的内容

也就是调整白名单为所有地址都可以网络访问,同时修改用户名密码到自己熟悉的即可。其中  "download-dir" 用来调整文件下载到的地址,这个自己调整即可。

3.使得配置信息生效(注意,必须使用此命令,否则Bittorrent Transmission 会在重启的时候把数据写回磁盘,导致修改无效)

4.修改系统配置文件,开放对于UDP的访问限制

增加如下语句

然后重启服务器。

5.通过浏览器访问即可。

Android 字体调整 fontScale 变化导致界面显示异常的问题

Android 字体调整,比如调整为超大字体,此时会导致Configuration 中的fontScale 变化导致界面显示异常。目前找到的办法为,在Application 的OnCreate 事件中增加如下代码

继承并覆盖 onConfigurationChanged 方法

在 AndroidManifest.xml 中的 application 部分增加处理 onConfigurationChanged 事件的声明

可以解决问题,但是会不会引起其他副作用,暂时未知。

Android 报告 java.lang.StackOverflowErrors 异常的问题分析

一般情况下,在使用比较复杂的布局的时候,尤其是 Fragment + ViewPager + SlideMenu 这种组合的情况下,会报告类似如下内容的崩溃栈信息

该异常在 2.X版本的Android系统上面表现尤为明显,往往 4.X版本的一切正常或者偶有卡顿,在 2.X版本上面直接崩溃。

分析一下,是一个 draw() -> dispatchDraw() -> drawChild() 的深度递归调用导致栈的溢出越界。对于 Android目前使用的 dalvik 虚拟机而言,系统默认的栈深度如下

Browsing for stack sizes through the dalvik source history:

也就是说,如果 draw() -> dispatchDraw() -> drawChild()  递归的深度太深,就会导致栈的不足问题。

解决方法, 目前貌似 dalvik 虚拟机 并不支持动态的修改栈的深度,这导致问题复杂化,首先,Fragment + ViewPager + SlideMenu  这种组合,即是什么都不增加,就已经有超过 10 层的递归了,这个可以在崩溃栈中的 drawChild 函数的数量就可以统计出来,这也就意味着,目前只有一条路可以走,那就是想办法减少布局的层次。有建议废弃 Fragment 来自己实现一套完整的东西,暂时还不建议如此操作。

一般方法就是

1.使用RelativeLayout 来减少尤其是 LinearLayout导致的布局深度问题,尽量在同层展开。

2.复杂布局的情况下,可以使用自定义View来实现,实在不行,可以自己计算坐标,直接绘制,比如用类似游戏的SurfaceView 之类的东西来替代。

3.利用 merge 来简化收缩布局,目前貌似FrameLayout 上面比较合适。

4.继承ViewGroup 的自定义View也是一层,这点不要忘记,能直接继承View的,就不要继承 ViewGroup

其他的方法,根据实际项目来处理好了。

Android抽象布局——include、merge 、ViewStub

在布局优化中,Android的官方提到了这三种布局,并介绍了这三种布局各有的优势,下面也是简单说一下他们的优势,以及怎么使用,记下来权当做笔记。

1、布局重用
标签能够重用布局文件,简单的使用如下:

1)标签可以使用单独的layout属性,这个也是必须使用的。

2)可以使用其他属性。标签若指定了ID属性,而你的layout也定义了ID,则你的layout的ID会被覆盖。
3)在include标签中所有的android:layout_*都是有效的,前提是必须要写layout_width和layout_height两个属性。
4)布局中可以包含两个相同的include标签,引用时可以使用如下方法解决(参考):

2、减少视图层级

标签在UI的结构优化中起着非常重要的作用,它可以删减多余的层级,优化UI。多用于替换FrameLayout或者当一个布局包含另一个时,标签消除视图层次结构中多余的视图组。例如你的主布局文件是垂直布局,引入了一个垂直布局的include,这是如果include布局使用的LinearLayout就没意义了,使用的话反而减慢你的UI表现。这时可以使用标签优化。

现在,当你添加该布局文件时(使用标签),系统忽略节点并且直接添加两个Button。更多介绍可以参考《Android Layout Tricks #3: Optimize by merging

3、需要时使用
标签最大的优点是当你需要时才会加载,使用他并不会影响UI初始化时的性能。各种不常用的布局想进度条、显示错误消息等可以使用标签,以减少内存使用量,加快渲染速度。是一个不可见的,大小为0的View。标签使用如下:

当你想加载布局时,可以使用下面其中一种方法:

当调用inflate()函数的时候,ViewStub被引用的资源替代,并且返回引用的view。 这样程序可以直接得到引用的view而不用再次调用函数findViewById()来查找了。
注:ViewStub目前有个缺陷就是还不支持 标签。

更多标签介绍可以参考《Android Layout Tricks #3: Optimize with stubs

转自 http://blog.csdn.net/xyz_lmn/article/details/14524567

Android 背景图片平铺

一般布局设置的背景图都是做拉伸处理,有时候我们需要背景图片做平铺处理,类似于网页开发中CSS的repeat。
在Android中可以使用如下方法使背景图片平铺。在drawable目录下创建一个repeat_bg.xml:

然后在布局的xml文件中可以这样引用:

Mac SSD TRIM的终极方案

该方法在 Mac 10.9.1 版本上面有效。

Enable SSD TRIM for Mac, Ultimate Solution. TRIM终极方案 我的Mac机型是Mac mini Late 2012,把硬盘换成了SSD。试了多种打开SSD TRIM的教程,总不能成功,有一次还弄到系统无法启动。今天大盘开始盘整了,于是可以静下心来把那些教程仔细debug一遍,发现了问题所在,成功开启了SSD TRIM。

最重要的先讲:在做这个工作之前,用Time Machine备份机器。

其次是怎么会弄到系统无法启动?原因是在改写IOAHCIBlockStorage这个文件的时候,把权限破坏了。一旦权限不对,系统会显示警告窗口,说无法加载IOAHCIBlockStorage。千万不要忽视这个警告,去重启机器,而是应该先修复权限。最简单最彻底的办法就是使用Disk Utility,选择系统盘,然后Repare Disk Permissions.

为什么有些教程会不起作用呢?这是因为不同的系统版本,如10.8.1、10.8.2,加上不同的机型,特别是新机型,系统文件有可能是不一样的。
如果教程不起作用,那就要先理解这些开启SSD TRIM办法的实质:其实就是把IOAHCIBlockStorage文件中硬盘型号的字符“APPLE SSD”这九个字节抹去,替换成全零字节。但是在整个文件中做全替换也不行,只能替换含义为硬盘型号字符的字节。
就因为各种系统和机型的文件不同,同时又要选择性地做替换,于是出现了不同的教程。这里介绍的终极方案,就是先查看你机器上的IOAHCIBlockStorage文件,然后修改教程中的一条命令,然后再执行那些命令。

ugmbbc_001734902074378

用一个二进制编辑器(比如说“Hex Fiend”)打开

搜索十六进制“52 6F 74 61 74 69 6F 6E 61 6C 00”,也就是“Rotational”字串加上0结尾。整个文件我就只搜到一个匹配的。查看后面是不是9个字符的“APPLE SSD”,如果是的话,就看“APPLE SSD”接下来的字符是什么。图中是“Time To Ready”,记下这个字串的第一个字符,是“T”,他的十六进制是54。

接下来就修改那些教程中的命令,请看https://gist.github.com/3334193,点击“Download Gist”下载文件,然后双击打开,就会自动解压缩。修改文件enable_trim.sh中的(x00{1,20}x51)中的51为上文的54,修改完就是(x00{1,20}x54),保存文件。解压的这个enable_trim.sh文件是没有执行权限的,那就在控制台运行“chmod 755 enable_trim.sh”,赋予执行权限。

注意,对于由于某墙封锁导致的不能访问github 问题,可以直接复制如下代码来自己生成sh文件

在运行“./enable_trim.sh”之前,一定要保证你现在的

文件一定是未经修改的原系统文件。执行完毕后,系统如果没有弹出什么提示框,那就万事大吉了。有兴趣的话,你还可以用Hex Fiend查看一下修改后的文件,和原文件相比,有啥不同。

ugmbbc_0016571229804857
手工重启机器后,应该就是成功了。
ugmbbc_0017201152901000

参考连接 http://www.cnbeta.com/articles/219752.htm

解决WD MyCloud 通过SSH 登陆之后中文显示问题

WD MyCloud通过SSH登陆之后中文显示为问号,网上查询了一下,找到解决方法。

首先执行

可以看到,在输出中是存在中文的“zh_CN.utf8”,因此,只要启用就可以了。

因此,执行如下命令

然后修改里面的

然后,退出,重新登陆终端即可。

WD My Cloud NAS on Ubuntu

下文暂时没有办法处理有用户名,密码的情况。

I decided that 2014 for me was going to be the year of the Network Attached Storage (NAS). Last year was the year that I finally abandoned my desktops and went all laptop for both my Mac-based iOS development workflow and general purpose computing (i.e, everything else on my Acer i5 running Lubuntu). This year I wanted to have a massive centralized storage where I could put all my videos and photos so I can access it from any laptop or mobile device. What follows is what I chose and how to hook it up to Lubuntu.

I first looked at external cloud solutions (DropBox, Box, CrashPlan, BackBlaze) and although they were all cool they were unfortunately out for me due to three reasons. First, the storage limits – I didn’t want Gigs – I wanted Terabytes. Although, CrashPlan and BackBlaze both offer unlimited online storage they limit the number of devices. Two, I didn’t have all the files centralized on one computer and it would be best to centralized all my Mac, Linux, and iOS data first before I could go to one of these offsite back-up solutions. Third, these all cost money in a form of a monthly fee of 5or50 yearly subscriptions. These offline solutions are definitely part of the final solution but I decided that would be a second phase for me. It looked like I had developed a phased project that broke down into two phases of centralization first and then offsite continuous backup second.

The first phase then came down to having a Network Attached Storage (NAS) type unit. The new Airport Time Capsule looked cool but I wanted something less Appley. I have had good experiences with Western Digital (WD) drives and saw in the January 2014 issue of Maximum PC a head-to-head between Dropbox and the new WD My Cloud product. A successor to the My Book branded drive this new My Cloud branded offering provides a shell to a NAS device and it was cheaper than a Time Capsule. I was sold and for X-mas asked Santa for the WD My Cloud 4TB Personal Cloud Storage – NAS (WDBCTL0040HWT-NESN) device.

Set-up was literally plug and play. There is an iOS App for iPad and iPhone/iPod Touch which allows upload to and download/stream from the NAS. The WD website and User Manual mention Mac and PC software to mount and sync that make connection a breeze. The device supports Time Capsule so I’ll be doing that with my Mac laptops (yes – there is no limit to how many computers connect to this thing). Then came my Linux laptop. There was no mention of Linux which is a shame since you would think that they are leveraging the community’s efforts in their products. But it was easy enough to connect my Lubuntu laptop as a Network File System (NFS) Client via three shell commands.

First, I changed directory to my home directory and created a nfs directory in there:

Then I applied the following three shell commands:

If you cd into nfs you’ll be accessing the WD My Cloud device. That’s it. I started to copy twenty mp4 files totalling 1.6GB into the device through 802.11g and it took 8 minutes. I was then streaming these on my iPad mini.

I hope this helps assure you you can connect to this from Linux. I know once I finished the plug and play I panicked for a bit thinking I wouldn’t be able to connect my Linux machines to this device but now I happily throw everything I have onto this. Also, it has a USB 3 port on the back so I can simply plug another 4TB USB drive on it and expand it in the future.

引用链接 http://cocoaallocinit.com/2014/01/04/wd-my-cloud-nas-on-ubuntu/