九月 27, 2015
» How to detect foreground process name in Android with Lollipop

(Katwijk.Holland)

Android 一直改版,原本可以用的功能,因為安全性,因為有的 app 會亂搞,所以把許多流程和功能不是改得變複雜,就是直接拿掉了。

原本一個很單純的抓取前景正在執行的程式名稱的功能,也變得愈來愈複雜。之前只需要抓一下getRunningTasks() 就可以找到想要的結果,但是現在得要為 application 加上新的 permission PACKAGE_USAGE_STATS,然後還要要求使用者進到 Settings > Security > User Apps with access to usage data , 勾選該 application 後才可以。

這種小功能還需要使用者大費周章的做一堆事,實在是很麻煩。

下面的程式碼,是透過 user stats去取得這資料。另外,如果使用者還沒有在 Settings 中勾選 app 的話,出來的 runningTask 會是空的,這時應該要用程式碼中最下面的 startActivity 去把設定的畫面叫起來,叫使用者打勾。使用者不打勾,你還是抓不到資料的。



八月 13, 2014
» 在 Pebble 上顯示中文的 Android 通知,和開發 Pebble 的簡單程式

(Lyon)

想在 Pebble 上顯示中文的話,iOS手機可以裝 PebbleCC ,Android手機的話可以裝 YaNC。不過 YaNC 在 Android 的 PlayStore 是要錢的。目前用 YaNC 的感覺還不錯。只是,如果一天下來訊息比較多的話,手錶變得比較快沒電。因為它是把訊息的內容傳成圖檔,然後把圖檔發到手錶上呈現。

另外,在 Mac 上下載了 Pebble SDK ,試著用 command-line 開發 pebble 上的 app。目前只試了一下 persistent storage 的 API,寫了個手動的 counter,還沒仔細看它 UI 的架構和其他功能的 library。希望有空可以逐漸熟悉,看能有什麼樣的應用方式。

https://developer.getpebble.com/2/guides/


七月 22, 2014
» AutoScreenOnOff 再升級

(Dansui.Taiwan)

前幾天花了半天加入 app 黑名單的功能後,評價還不錯,至少止血了。今天趁著明天颱風要來早點回家,花了一個多小時,把一個單純的 screen off widget 給加了進去。

花的時間比預料的快很多,因為本來在 notification 的互動中就已經有這個 intent 和處理邏輯在了,今天只是照著原本的 widget 再生一個出來,然後設定個 pendingIntent 給它,就收工了。

另外,還隨手將 changelog 的輸出方式改了一下,改成每個版本都會是一個新的 string ,如果其他語言沒有翻譯的話,那自然會抓到預設英文的版本,省下我每次升級都要把同樣的字串貼到每個語系的changelog_html中。

六月 22, 2014
» 如何讓 Android 中的 Activity 不要顯示任何畫面

(ShinShan.Dream Lake.Taipei)

北部難得可以找到人少一點的景點。
之前來路跑竟然沒有看到。

*****
最近又在寫小 app,但總是在畫面上卡關,一直無法很順利的進行。
今天早上起床,順手又改了幾個自己在使用上覺得不夠方便的地方,
然後,就是這麼自然地,在網路上逛到了如何解決自己試了很久都沒成功的功能。

根據 app 的需求,我在 AndroidManifest.xml 中透過 intent filter來接收某些事件。當事件發生時,被叫起的 Activity 其實並不需要顯示畫面,我只是要將事件再傳給 Servic,讓 Service 把事情處理掉。但是卻老是卡在 Activity 或多或少會秀一下白畫面,或黑畫面,或是閃一下,才會乖乖的不見。即使在 onCreate() 中呼叫了 finish()也解決不了這個問題。

今天在網路上找到的解法,很簡單。只需要設定一個 theme 就好了。雖然這方法自己也試過,但應該是少了些什麼其他的設定吧。好吧,答案就是:

            android:theme="@android:style/Theme.NoDisplay"

REF:
http://stackoverflow.com/questions/4551868/how-to-completely-get-rid-of-an-activitys-gui-avoid-a-black-screen



六月 10, 2013
» 在Lime HD中快速啟動語音輸入法

(富貴角.Taiwan)

剛剛試了一下谷歌的語音輸入,覺得有些時候應該蠻實用的。所以打算幫它在Lime HD中加個快速切換的功能。在Lime HD中原本就有開啟Google語音輸入法的方式,只是我覺得有點太麻煩了。原本的方式是:
1. 長按左下方的設定鈕,這時會跳出一個對話視窗,可以設定輸入簡繁中文的切換,分割鍵盤等一些選擇。畫面最下方則是切換成語音輸入法。

通常會想用語音輸入的時機,都是在手不方便慢慢點螢幕的時候,所以,操作步驟愈多,就愈麻煩。原本我是打算在長按(中/En)按鈕時,直接啟動語音輸入。目前這個按鈕的長按並沒有預設的作用,所以很適合。

可惜的是,我不知道怎麼debug InputMethodService,所以沒有辦法短時間內看清楚在LIMEService中的長按功能,是怎麼前後串起來的。一直找不到好的interception point。

無意中卻發現了,原來Lime有針對輸入的整個面版實作swipe的key listener!!做為一個多年的Lime HD愛用者,竟然不知道有這麼一回事。看了原始碼後,它的目前對應功能是:
滑上:開啟設定對話窗(跟長按設定按鈕一樣)
滑下:關閉輸入法
滑左:模擬刪除鍵
滑右:送出目前選擇的候選字

既然設定對話窗已經可以很方便地長按設定鍵來開啟,我把"滑上"給改成呼叫Google語音輸入法。程式碼很簡單,在LIMEService中的swipeUp(),把原本的code換成StartVoiceInput()就可以了。

六月 6, 2013
» Some hacking articles about IdeaVIM under Intellij

 (Leiden.Netherlands)

IdeaVIM is a vim-like input plugin for intellij IDE, good for text editing but not so powerful if you want to use it for other IDE tasks, for example accessing menu actions by defining keyboard shortcuts.

Fortunately, someone in Japan branched the source codes on GitHub, and wrote some tweaks to make it possible to configure all kinds of Intellij menu items to keyboard shortcuts as you wish in a config file.

Tried downloading the modified codes and built it in Intellij; installed the plugin in my Android Studio environment. Working like a charm~

my settings in _ideavim.groovy


REF:
http://d.hatena.ne.jp/masanobuimai/20120720/1342764219
http://d.hatena.ne.jp/masanobuimai/20080323#1206277040


六月 4, 2013
» How to make testing work under Android Studio

(Geneve.Swiss)

It's such a pain to look for solutions for tasks on Android Studio. When can it be mature enough and more well documented for developers?

I would like to write some test cases for my small app, but I couldn't find a way for adding test cases into Android Studio project and have it run successfully.

After wandering around on the internet for a long time, eventually I found a link that did helped me out (see reference below). As Google I/O 2013 video said, a new android build system made of gradle is released, which will be more flexible, more powerful, more etc, etc. However, currently, it 's not well integrated into Android Studio. Some modification in Android Studio won't be directly reflected in gradle build scripts. Well... then, how do I know when I should modify build scripts my self? And to write it by myself, I have to learn groovy first, because that's the language Gradle used to write its build configuration files. How could I master these things in a short time...

Anyway, the solution for my pain point above is to modify build.gradle under the root directory of app project, and make sure all the instrument source folders are well set up. Now I can use cradle to run test cases and generate report files. However, I can't make it work in Android Studio still. orz...


REF:
http://blog.crowdint.com/2013/05/24/android-builds-on-travis-ci-with-gradle.html

六月 1, 2013
» Gradle build error in comman line for Android Studio app projects

I saw someone met the same problem on StackOverflow. Fortunately,  I found out how to make it work. So leave some notes here:
1. upgrade Gradle version to 1.6
2. Afterward, running "gradle build --stacktrace", you will see that ANDROID_HOME environment variable is required to be set up.
3. on Mac, add following line to your ~/.bash_profile
export ANDROID_HOME="/Applications/Android Studio.app/sdk/"

Now it should work like a charm!

五月 28, 2013
» 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:
http://android-er.blogspot.tw/2010/08/orientationeventlistener-detect.html





五月 24, 2013
» 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:
Add a jar library








五月 20, 2013
» 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:
http://userscripts.org/scripts/show/167980

三月 31, 2013
» AVPlayer and AVAudioPlayer on iOS

(Polderpark.Netherlands)
I like the bright color in this picture. Although this photo was taken almost 10 years ago, the image quality is so great that I still can't believe it's taken by a cheap camera at that time.

****
It's easy to play and control local mp3 files by using AVAudioPlayer. However, if someone wants to stream playing mp3 files from the internet, he should try AVPlayer instead.

Spend most of my time trying to find a remote mp3 for testing. Too bad that I just can't even find one. Eventually, I gave up searching on the internet. Instead, I use following python command to create a simple http server locally on my mac:

python -m SimpleHTTPServer
 
 

二月 28, 2013
» Big Data and Hadoop

 Spring.Taiwan

Read the book "Understanding Big Data" today. Half way done.
Here's some excerpts from the book:

Understanding Big Data

2013-02-28 15:45:37
the term Big Data applies to information that can’t be processed or analyzed using tradi-tional processes or tools
2013-02-28 15:46:12
An IBM survey found that over half of the busi-ness leaders today realize they don’t have access to the insights they need to do their jobs
2013-02-28 15:48:45
Even if every bit of this data was relational (and it’s not), it is all going to be raw and have very different for-mats, which makes processing it in a traditional relational system impractical or impossible
2013-02-28 15:49:05
variety combining to create the Big Data problem
2013-02-28 15:51:31
Three characteristics define Big Data: vol-ume, variety, and velocity.
2013-02-28 15:54:17
the opportunity exists, with the right technology platform, to ana-lyze almost all of the data (or at least more of it by identifying the data that’s useful to you) to gain a better understanding of your business, your customers, and the marketplace
2013-02-28 15:55:35
a fundamental shift in analysis require-ments from traditional structured data to include raw, semis-tructured, and unstructured data as part of the decision-making and insight process
2013-02-28 15:56:27
To capi-talize on the Big Data opportunity, enterprises must be able to analyze all types of data, both re-lational and nonrelational: text, sensor data,
2013-02-28 15:56:50
Dealing effectively with Big Data requires that you perform analytics against the volume and variety of data while it is still in motion, not just after it is at rest
2013-02-28 15:58:11
Hadoop-based platform is well suited to deal with semistructured and unstructured data, as well as when a data discovery process is needed
2013-02-28 16:07:26
it is about dis-covery and making the once near-impossible possible from a scalability and analysis per-spec-t
2013-02-28 16:09:19
creator Doug Cutting’s son gave to his stuffed toy elephant
2013-02-28 16:09:44
duce)—more on these in a
2013-02-28 16:10:23
this redundancy provides fault toler-ance and a capability for the Hadoop cluster to heal itself
2013-02-28 16:10:55
Some of the more notable Hadoop-related projects include: Apache Avro (for data serializa-tion), Cassandra and HBase (databases), Chukwa (a monitoring sys-tem spe-cifically designed with large distributed systems in mind), Hive (provides ad hoc SQL-like queries for data aggregation and summariza-tion), Mahout (a machine learning library), Pig (a high-level Hadoop programming language that provides a data-flow language and execution framework for parallel computation), ZooKeeper (provides coordination services for distributed ap-plications), and more
2013-02-28 16:12:23
throughout the cluster
2013-02-28 16:13:54
For Hadoop deployments using a SAN or NAS, the extra network commu-nica-tion overhead can cause performance bottle
2013-02-28 16:14:59
an individual file is actually stored as smaller blocks that are repli-cated across multiple servers in the entire cluster
2013-02-28 16:16:09
default size of these blocks for Apache Hadoop is 64 MB
2013-02-28 16:21:41
All of Hadoop’s data placement logic is managed by a special server called NameNode
2013-02-28 16:28:14
All of the NameNode’s infor-mation is stored in memory, which allows it to provide quick response times
2013-02-28 16:30:33
Any data loss in this metadata will result in a permanent loss of corresponding data in the cluster
2013-02-28 16:32:25
devel-oper doesn’t have to deal with the concepts of the NameNode and where data is stored—Hadoop does that for you
2013-02-28 16:38:42
The first is the map job, which takes a set of data and converts it into another set of data, where individual elements are broken down into tuples
2013-02-28 16:38:51
reduce job takes the output from a map as input and combines those data tuples into a smaller set of tuples
2013-02-28 16:41:20
All five of these output streams would be fed into the reduce tasks, which combine the in-put results and output a single value for each city, producing a final result set
2013-02-28 16:43:08
MapReduce program is referred to as a job. A job is executed by subse-quently breaking it down into pieces called tasks
2013-02-28 16:43:45
An application submits a job to a specific node in a Hadoop cluster, which is running a daemon called the JobTracker
2013-02-28 16:44:39
In a Hadoop cluster, a set of continually running daemons, referred to as TaskTracker agents, monitor the status of each task
2013-02-28 16:46:39
This direct-ing of records to reduce tasks is known as a Shuffle, which takes input from the map tasks and directs the output to a specific re-duce task
2013-02-28 16:47:29
under Hadoop are written in Java, and it is the Java Archive file (jar) that’s distributed by the JobTracker to the various Hadoop cluster nodes to execute the map and reduce tasks
2013-02-28 16:48:00
BigDataUniversity.com and download Info-Sphere BigInsights Basic Edi-tion (www.ibm.com/software/data/infosphere/ biginsights/basic.html
2013-02-28 16:49:58
Hadoop Common Components are a set of libraries that support the var-ious Hadoop subprojects
2013-02-28 16:50:50
When you delete an HDFS file, the data is not actually gone (think of your MAC or Windows-based home computers, and you’ll get the point). Deleted HDFS files can be found in the trash, which is automatically cleaned at some later point in time
2013-02-28 16:52:46
we cover three of the more popular ones, which admit-tedly sound like we’re at a zoo: Pig, Hive, and Jaql
2013-02-28 16:53:09
Pig was initially developed at Yahoo
2013-02-28 16:56:02
you can FIL-TER out rows that are not of interest, JOIN two sets of data files, GROUP data to build aggrega-tions, ORDER results, and much more
2013-02-28 16:58:01
There are three ways to run a Pig program: embedded in a script, embedded in a Java program, or from the Pig command line, called Grunt
2013-02-28 16:58:51
Some folks at Face-book developed a runtime Hadoop sup-port structure that allows anyone who is already fluent with SQL (which is commonplace for rela-tional data-base developers) to leverage the Hadoop platform right out of the gate. Their cre-ation, called Hive
2013-02-28 16:59:50
You can use the Hive Thrift Client within applications written in C++, Java, PHP, Python, or Ruby
2013-02-28 17:01:19
Hive is read-based and therefore not appropriate for transaction processing
2013-02-28 17:03:11
JSON is built on top of two types of struc-tures. The first is a collection of name/value pairs
2013-02-28 17:03:35
The sec-ond JSON structure is the ability to create an or-dered list of values much like an array, list, or se-quence you might have in your existing applica-tion
2013-02-28 17:09:13
The operand used to signify flow from one operand to another is an arrow: ->. Unlike SQL, where the output comes first (for example, the SELECT list)
2013-02-28 17:15:16
Jaql is a flexible infras-tructure for managing and analyzing many kinds of semistructured data such as XML, CSV data, flat files, relational data, and so on

REF:
http://www.ibm.com/developerworks/wikis/display/db2oncampus/FREE+ebook+-+Understanding+Big+Data

二月 21, 2013
» 在未參加iOS developer program的前提下,在iPhone/iPad實機上測試開發中app

(Taipei.Taiwan)

該做的正事不認真,寫程式倒是花了不少時間。
今天總算有了點進展,先是把addTags的功能搞定,
再來是加上了Favorites的頁面,可以顯示自己加過特定tags的照片。

有了這些自己想要的功能之後,光是在emulator上測試,
就開始覺得不大過癮,想找辦法把程式放到iPhone上玩。
為了要把app deploy到手機上開發測試,
一般來說,得要加入US$99/year的developer program才可以。
加入了這個program之後,除了可以在真機上測試,
還可以發佈app到AppStore上去。
不過,目前我還沒有這樣的需求也沒有這打算,
因此實在是很不想花這筆錢。
而且,也不確定自己之後是不是還有時間研究iOS...

由於我的手機已經JB了,想說總會有辦法藉此到達我的目的吧。
果不其然,網路上從很早以前就有很多教學在講怎麼設定和patch xcode。
但是…全都好複雜呀:
又要加certificate,又是改plist,還要加入scripts。
只要其中哪個步驟沒弄好,應該就不行了吧。

好在,找到有人直接提供了懶人包的程式,
只要輕鬆按幾個按鈕就可以把所有的patch給搞定。
步驟如下:
1. 下載JailCoder,在Mac上執行它
2. 根據畫面最上方的Guide button操作,把certificate先搞定
3. 按左下方的patch xcode
4. 再按右下方的patch project,選擇自己想要deploy的project
5. 替自己的iOS device裝上AppSync (前提是要先JB)
    AppSync的source repo path下面有,
    把它加到Cydia的軟件源中,再尋找AppSync這支app就可以了

REF:
JailCoder
AppSync Installaion Source:
http://cydia.myrepospace.com/Bl00dra1n

二月 20, 2013
» iOS Programming

(Chamonix.France)

看了幾課教學後,總算是有點小進度了。
不看還不曉得,原來xcode的開發環境這麼完整和方便,
是我太久沒有接觸開發環境了嗎?
感覺上eclipse的android開發環境還是那麼地原始呀。

不過,寫程式常會遇到鬼打牆…
需要花時間…

REF:
Stanford CS193p

» 難搞的oAuth Process和文件不夠清楚的flickr Developer Documentation

(JingMei Bridge.Taipei)

試圖為抓下來的圖片加上一個tag,查了flickr api dev guide,對於這種request應該要使用post method才行。可是flickr上的api explorer還是用舊的token方式,而api說明頁又說得不清不楚,只說舊版的token要deprecated,要用新版的oAuth。卻沒說清楚oAuth的signature要怎麼生出來。

後來又回頭看了幾次oAuth signature的生法,並且在我原本找來做oAuth認識的class中找到相關的code;這才把它們改了一下搬到我需要的logic中。

結果發現用post method還是會有問題,可是我把整串request直接貼給browser竟然可以了!這是說如果用oAuth機制的話,不需要用post method也可以嗎?那我又何必大費周章的去改用NSURLConnection呢?再改回原本的[NSString URLWithString]]就好了。

REF:
gitk documentation
oAuth 簡介

biggo.com.tw

A Django site.