2013/05/31

Open downloaded files directly in Firefox on Mac

(Annecy.France)

It's annoying that I have to click on torrent files every time I download them in firefox. Although I tried to check the option to open always with a certain application in SaveFile dialog, it never worked.

 However, the solution seems so simple that I should have searched the internet earlier to make my life easier. In firefox official support website, it mentioned that this is configurable in Peferences:
  1. On the menu bar, click on the Firefox menu and select Preferences...
  2. Select the Applications panel.
  3. The Applications panel will display. Select the type of file for which you want to change the default action. 
Voila. Let's keep surfing the internet!

REF:
 https://support.mozilla.org/en-US/kb/change-firefox-behavior-when-open-file#w_changing-download-actions

2013/05/28

OrientationEventListener on Android to get current rotation degree

(Central Park.New York)

Strangely, it's not possible to get current rotation angle in android directly, except for getting the fixed 4 rotation modes: 0, 90, 180, 270. In order to get precise rotation degrees instead of rotation modes, OrientationEventListener can be used. Once it's implemented, you can get the rotation degree in onOrientationChanged(). It's a lot easier than manipulating values from all the sensors like gyroscope, accelerator, etc.

REF:





2013/05/24

Tips for using AdMod module in Android Studio

(Geneva.Swiss)
It's pain in the ass to use Android Studio now, since it's just published, which implies bugs appear every now and then, and you're not sure it's due to your misunderstanding of this IDE, or it's really an issue. In addition, it's  relatively hard to find How-to answers comparing to ADT plugin with Eclipse.

While trying to set up AdMob module in my project on Android Studio, it took me some time to fix some external library import errors that should be clearly mentioned in online AdMob doc, or even better, just integrate it into "Android Studio".  Isn't Android Studio meant to make Android developers' life easier?

Problem 1: Add com.google.ads.AdView element  in my layout xml as doc says, but it generates compilation error.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
  <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                         ads:loadAdOnCreate="true"/>
</LinearLayout>
Anser: Pay attention!! You also have to add the red line attributes to the container layout!! It's not clearly mentioned in document. What I just did in adding com.google.ads.AdView component. Obviously, it told me that it can't compile.

Question 2: Don't know how to add the AdMob library to my project in Android Studio. The AdMob doc only has flows for eclipse. I always meet "NoClassDefFoundError" during runtime. This took me most time to wandering on the internet, looking for a right answer.

Answer: it's a bit tedious. Please just check detail information in reference link below. In brief:
1. Put the jar into the libs folder
2. Right click it and hit 'Add as library'
3. Do a clean build (you can probably do this fine in Android Studio, but to make sure I navigated in a terminal to the root folder of my app and typed gradlew clean (I'm on Mac OS X, the command might be different on your system)

Question 3: sometimes, even questions above are all fixed, you still can't get the AdMob View. Why? You have to declare a specific Activity for it including configChanges. This is mentioned in Introduction, but ... I just have ignored it, since who would have thought that creating a View in my own activity needs to declare a specific Activity for it?

    <activity android:name="com.google.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
 

REF:








2013/05/20

Enhance Reading Experience for Android Dev website


Recently I spend most of my time reviewing documents on google's android official site. It annoys me that the left side of the screen is always occupied by the content index; however, I just need to change articles once in a while by using it. It makes me feel bad that one third of the screen is wasted. In addition, it also distracts me while I was reading.

As a consequence, I searched internet to see if there's any extension, plugin, or script to help me hide the navigation panel when I want to do so. Out of luck, no. Maybe it's too tiny to have someone work on it.

Therefore, I decided to write one by myself, after reading a book about jQuery. My choice is to write a userscript for greasemonkey, which is supported on Chrome now as well. The logic is very simple and the lines of codes are few, although it still took me sometime to find right APIs to implement this feature.

Here's the screenshots:

The userscript is uploaded to following site:

2013/05/17

JavaScript & jQuery: The Missing Manual



很容易讀的一本書,花了兩天把它翻完。
前半部的javascript,因為已經看過一些基本的語法介紹,就沒細看。
後面的jQuery介紹,把selector的使用和網頁的一些操作都帶到了。
比較讓人不解的是,最後一章的debugger介紹,為什麼不是放在整本書的最前面呢?
中間在測一些小範例時,老是卡住;還是靠自己摸索才知道firefox和chrome都有console之類的component可以協助debugging。

REF:
Amazon link

2013/05/15

Eclipse/Java code completion not working with Android development

(GreatWall.Beijin.China)

While watching some video tutorials about android development, I found that the lecturer can call out the class completion helper dialog during typing class names. However, I only have the function/variable autocompletion feature after typing a . after a class name in my eclipse. Without entering the class name correctly, I can not get any help from eclipse, which is quite strange comparing to what I've seen for others.

Well, it seems that many people encountered the same problem as I did. This is being discussed on various posts. One way to make it work is to check the "Java Proposal" in Eclipse's Preferences > Java > Editor > Content Assist > Advanced'.

But for me, it seems that something's wrong with my workspace configurations too. The answer from hoipolloi in following reference post helped me to fix this issue. Here's his suggestion:
  • Quit Eclipse
  • Go to workspace/.metadata/.plugins/org.eclipse.jdt.core
  • Remove *.index and savedIndexNames.txt
  • Restart Eclipse and search Ctrl+T for the offending type. The indexes will be rebuilt.

REF:
http://stackoverflow.com/questions/908489/eclipse-java-code-completion-not-working

LIFE

不是很好看。以為 Jake Gyllenhaal 有演出,應該會有點看頭的。 故事是在講一群太空人在太空站上試著培養火星來的休眠單細胞生物,最後愈搞愈大,變得不可收拾的地步。 中間很多故做緊張的情節,但因為張力不夠,再加上配樂又不是很優(也有可能是因為在家看的關係,聲光效...