顯示具有 OpenAlarm 標籤的文章。 顯示所有文章
顯示具有 OpenAlarm 標籤的文章。 顯示所有文章

2012-02-04

Experiment the Tips for reducing APK file size

I came across this article: Tips for reducing APK file size at SonyEricsson Developer blog. Among them, the one I am aware of is the PNG file optimization. So, I took some time to experiment it.

First, I downloaded the GUI wrapper of command-line optimizer ImageOptim and optimize the PNG files at res/ directory. According to the result, it reduce total file size from 748K bytes to 700K bytes.

Second, I recompile the release binary of my application. But, the size of APK file remains the same as the one w/o PNG optimization.

Hmm. I repeated this process some times to make sure I didn't miss some important steps. While I was wondering, I noticed some messages spewed out during compilation like,
  [crunch] Processing image to cache: /Users/yenliangl/Work/Android/bozaalarm-android/res/drawable-hdpi/handler_app.png => /Users/yenliangl/Work/Android/bozaalarm-android/bin/res/drawable-hdpi/handler_app.png
Looks like PNG optimization has been included in the standard Android tool v14??

This should confirm my guess. From official site of Android tool, it says that in revision 14, aapt optimizes PNG during compilation.

png processing in aapt.
When aapt packages the resources, its main goal is to compile the XML to binary format and to create a resource table with all the resource values (string, color, ids, etc...). Additionally, it processes the png files to optimize them (for instance, pre-processing of 9-patches).
Because the aapt process is not incremental, this means every build goes through all png files and processes them always. For large projects with numerous (and/or large) png this process could take a long time.
Revision 14 now processes the png files outside of the aapt packaging step and caches them. Only modified png files are re-processed. 



2012-01-06

TimePicker/DatePicker with keyboard input problem

I got some complaints from users saying they can't use keyboard to input in TimePicker or DatePicker widgets and found that this bug has been posted on Android developer forum for some time.

The quick workaround for this bug is,

2011-04-08

Why TaskKiller prevents my Alarm apps from working

It is well-known that task killers on the Android Market prevents Alarm applications from working. But why? To understand this, we should understand how alarms in Android are handled. A hardware alarm event should go through 2 layers to bring up your software component.
  1. Hardware alarm event
  2. AlarmManagerService
  3. Your application components to handle alarms
The AlarmManagerService stores the information required to link hardware alarm event to your application components. The task killer actutually removes these information from AlarmManagerService and this is why your Alarm application doesn't work after a task killer kills your application.

For devices running Android 2.1 and below, the method the task killer uses to kill an application is ActivityManager.restartPackage(String) that in turn triggers the UninstallReceiver defined in AlarmManagerService to remove all links registered by your application.
class UninstallReceiver extends BroadcastReceiver {
        public UninstallReceiver() {
            IntentFilter filter = new IntentFilter();
            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
            filter.addAction(Intent.ACTION_PACKAGE_RESTARTED); // <------ this line
            filter.addDataScheme("package");
            mContext.registerReceiver(this, filter);
        }
        
        @Override
        public void onReceive(Context context, Intent intent) {
            synchronized (mLock) {
                Uri data = intent.getData();
                if (data != null) {
                    String pkg = data.getSchemeSpecificPart();
                    removeLocked(pkg);
                    mBroadcastStats.remove(pkg);
                }
            }
        }
    }

But, in Android 2.2, things changed. The restartPackage method is changed to be just a wrapper of a new method killBackgroundProcesses. So, task killers on the Market are doing the same thing as default Out-Of-Memory (OOM) killer. Although we can still install them to proactively kill processes, but they are not necessary any more.

2010-04-13

New release of OpenAlarm

A new version of OpenAlarm is released at 04/15/2010. This version has several minor bug fixes and some UI changes.
  • Fixed FC when no default ringtone exists.
  • Fixed silent alarm if no ringtone specified (Play fallback ringtone instead).
  • Fallback to normal mode if user selects password mode but no password set.
  • Users can pull phone number directly from contact database in Phone alarms. The rule of picking a number to call is
    1. Default phone number if exists. 
    2. First phone number.
    3. No phone number for this person and show "no phone number" error message along with the name of this person.
  • Justify the position of the banner so that it is at the center of the screen.
  • Use hardware search button to apply another search to an filtered result is NOT allowed anymore.
  • Insert device information to the e-mail caused by the clicking on my email address in the About dialog.
  • UI changes. Move New menu item to the main screen.
  • Add explicit on/off settings to ToggleSwitch.
這個版本修正了一些小臭蟲以及使用者介面上的一些小改變。
  • 修正當沒有預設響鈴時可能發生的強制關閉。
  • 修正當沒有設定響鈴時的無聲鬧鈴。使用緊急鬧鈴。
  • 如果使用者選擇密碼模式但忘記設定密碼,則使用正常模式。
  • 在設定電話鬧鈴時,使用者可以直接從聯絡人清單挑選聯絡人。電話號碼的選擇順序為,
    1. 預設號碼。
    2. 第一組號碼。
    3. 無號碼時則顯示錯誤訊息。
  • 對正OpenAlarm的Banner。
  • 對搜尋出的鬧鐘再執行搜尋並無太大意義。關閉這個功能。
  • 在關於此程式中,按我的email位址寄信給我,會在郵件中插入幾行除錯資訊。
  • 使用者介面的稍許更動。將加入新鬧鈴的選單項目移到主畫面。
  • 加入明確的開關設定。


2010-03-29

Changes in release 2010/03/29

This release focus on audio volume of alarms. It's been ignored in previous releases until some users remind me of this. Here are changes,

  1. Use hardware back button to go back from filtered result.
  2. Use hardware search button to do alarms filtering.
  3. Force screen orientation portrait when alarm goes off.
  4. Use hardware volume up/down buttons throughout OpenAlarm to adjust alarm volume. To get this, ringtones that are not alarm ringtones will not shown up on the ringtone picker. You need to use 3rd-party tools to pick up your favorite music songs as alarm ringtones or copy them into right directory in SD card. (You can find more information from my previous post)

Lags of alarms in Motorola Milestone or all its devices??

Some people owned Motorola devices complained to me about the lags of their scheduled alarms or even not went off. I googled and found many people have the same problem on their devices especially Milestone, even the built-in AlarmClock. I am not very sure who should be blamed. I tried to find out why in an "economic" way (I don't want to buy another Motorola phone). I downloaded their SDK add-ons to emulate Motorola devices on their website.

According to users report, their failed alarms are scheduled to go off when device sleeps. So, I did the following steps to replicate their condition.
  • Turned AC power off in emulator
  • Setup an alarm that will go off after power off
Indeed, this alarm didn't go off at scheduled time. But, it went off when you turn device on.

I carefully inspect the logs line by line and found these lines interesting.

03-29 12:38:21.536    62    96 V ActivityManager: Broadcast: Intent { act=android.intent.action.TIME_TICK flg=0x40000004 (has extras) } ordered=true
03-29 12:38:21.536    62    96 V ActivityManager: Enqueueing ordered broadcast BroadcastRecord{43ae6820 android.intent.action.TIME_TICK}: prev had 0
03-29 12:38:21.536    62    96 I ActivityManager: Enqueueing broadcast android.intent.action.TIME_TICK
03-29 12:38:21.551    62    74 V ActivityManager: Received BROADCAST_INTENT_MSG
03-29 12:38:21.551    62    74 V ActivityManager: processNextBroadcast: 0 broadcasts, 1 serialized broadcasts
03-29 12:38:21.564    62    74 V ActivityManager: Processing ordered broadcast BroadcastRecord{43ae6820 android.intent.action.TIME_TICK}
03-29 12:38:21.564    62    74 V ActivityManager: Submitting BROADCAST_TIMEOUT_MSG for 869828
03-29 12:38:21.564    62    74 V ActivityManager: Delivering serialized to registered BroadcastFilter{439d1460 ReceiverList{439d85e0 62 system/1000 local:43a24fb8}}: BroadcastRecord{43ae6820 android.intent.action.TIME_TICK}
03-29 12:38:21.564    62    74 I ActivityManager: Delivering to ProcessRecord{43b67508 62:system/1000}: BroadcastRecord{43ae6820 android.intent.action.TIME_TICK}
03-29 12:38:21.564    62    74 I ActivityThread: Receiving broadcast android.intent.action.TIME_TICK to android.app.ActivityThread$PackageInfo$ReceiverDispatcher@43a27b00
03-29 12:38:21.564    62    74 I ActivityThread: Enqueueing broadcast android.intent.action.TIME_TICK to com.android.server.AlarmManagerService$ClockReceiver@43a28528
03-29 12:38:21.564    62    73 I ActivityThread: Dispathing broadcast android.intent.action.TIME_TICK to com.android.server.AlarmManagerService$ClockReceiver@43a28528
03-29 12:38:21.571    62    73 V ActivityManager: Finish receiver: android.app.ActivityThread$PackageInfo$ReceiverDispatcher$InnerReceiver@43a24fb8
03-29 12:38:21.571    62    73 V ActivityManager: processNextBroadcast: 0 broadcasts, 1 serialized broadcasts
03-29 12:38:21.571    62   100 D WindowManager: interceptKeyTq event=android.view.RawInputEvent@43acae08 keycode=26 screenIsOn=false keyguardShowing=false
03-29 12:38:21.571    62   100 D PhoneWindowManager: inECBM: false
03-29 12:38:21.571    62   100 D WindowManager: interceptKeyTq event=android.view.RawInputEvent@43acae08 keycode=26 screenIsOn=false keyguardShowing=false
Why interesting? The TIME_TICK events. It is plausible that I suspect Motorola optimizes their devices by stopping clock as system goes to sleep and restarting it as system goes back on. This sounds plausible.

I really need to think about how to fix this if Motorola doesn't want to fix this and OpenAlarm keeps not-functioning in user feedback. Damn it.

2010-03-25

Ringtones confusion and volume settings of audio streams

People asked me about how to add their favorite music as alarm ringtone. In Android, there are four categories of ringtones,
  1. Phone ringtones.
  2. Alarm ringtones.
  3. Notification ringtones.
  4. UI ringtones.
In built-in ringtone picker, it filters out ringtones that don't belong to the category you queried. From a user's perspective, if you want to have your favorite music as your alarm ringtones, you need to either place it in the right directory or install RingsExtended to do it.

If you don't want to install RingsExtended, put your favorite songs into /sdcard/media/audio/alarms in your SD card. You will see them showing up on the built-in ringtone picker for you to select.

From a developer's perspective, another thing you need to take into account is the volume up/down buttons of your phone. You need to decide which audio stream is affected by volume up/down buttons in your application. In my case, OpenAlarm is an alarm application and whenever you click volume up/down buttons, only alarm volume should be affected.

The mistake I made was that I only change the volume of an internal MediaPlayer charged of playing ringtone. It's not enough. In Android, audio settings are controlled by AudioManager and concepts of audio streams are used to control volumes of sounds in different situations. In documentation, they are
  • STREAM_ALARM
  • STREAM_DTMF
  • STREAM_MUSIC
  • STREAM_NOTIFICATION
  • STREAM_SYSTEM
So, all you have to do is to implement things mentioned above
  • Have your activities aware of volume change by

    setVolumeControlStream(AudioManager.STREAM_ALARM);
     
     
  • Apply proper audio stream settings to your MediaPlayer.

    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);

2010-03-21

What's a suitable feature for an alarm application?

I've an alarm application published in the Android Market, named OpenAlarm. It has a feature that asks people simple math addition problem to wake them up. Some people email me some interesting ideas about this application. Here are some examples,
  1. Harder math question because current one is too simple.
  2. Flip the phone to snooze alarm.
These two features sound like reasonable. But, I prefer not to add feature 2.


Recently, I've been studying iPhone User Interface Guidelines strongly recommended by some successful iPhone killer app authors. I must admit that it is a very good material not just for iPhone but for all mobile platforms. As this document suggests the first thing you must decide when you're developing an application is to come up a product definition statement that concisely defines application's main purpose and intended audience.

For OpenAlarm, I've been thinking what product definition statement it has? It might sound like,

   An easy-to-use alarm application that tries every means to wake people up.

If this is its product definition statement, then feature 2 should not be implemented because it's too kinda natural for people to flip a phone. :)

2010-03-16

Changes in release 2010/03/20

I'm gonna publish the next release of OpenAlarm. It's in code-freezed and testing phase. There are many changes in this release. Let's talk about them.

Big UI changes in this release. As you know, the number of actions OpenAlarm can handle is increasing. If I still use the same bottom sliding bar to contain all actions, users might need to fling it very hard to get what they want. So, I am embarrassed to tell you that I roll back OpenAlarm to what it looked some versions before. Nevertheless, it looks much simpler and harmonic in UI design (still a touch thing for me).





Here are changes I made in this version
  • Fixed forced close when Phone call action is triggering.
  • New password mode added for deep sleeper. You need to re-select math mode or password mode from Alarm's settings and set password over there. In password mode, OpenAlarm asks you to enter the password and if you provide wrong password, OpenAlarm will keep ringing (bothering you) 1 minute and this alarm goes snoozed automatically.
  • Fixed problem that may happen when Alarm and Phone call are set to be trigger at the same time. The behavior really depends which one is executed first by Android.
    • If Phone call is executed first, Alarm will be executed over call screen and plays a beep sound that doesn't interfere the talk.
    • If Alarm is executed first, Phone call will snooze Alarm automatically.
  • Notifications redesigned.
    • If there are enabled alarms, an alarm icon is put on the RIGHT side of status bar, instead of left side.
    • WARNING
      • If OpenAlarm is reinstalled or killed by task killer app, you MUST re-execute OpenAlarm to activate enabled alarms.
      • The alarm icon on the status bar may be removed by system AlarmClock. You can run OpenAlarm again to bring it back (It is removed but this doesn't mean scheduled alarms are canceled).
  • Two new buttons on title bar. One for filtering alarms and the other is for going back to previous state. I think they are pretty self-explained.
  • Red vertical bar is shown for any invalid alarm record.
These are things I haven't had ideas on how to implement,
  • Alarms don't go off if airplane mode is on. People report that this exists in every alarm apps he can find and even built-in AlarmClock.
  • One time events.
  • Week begins on Monday option.
  • Use alarm volume instead media volume.
  • Explicit on/off option for Toggle switch of airplane mode.
You might already know that OpenAlarm is open sourced, if you are interested in making it the best alarm app (of course, free) in the market, please let me know.

2010-03-02

OpenAlarm's User Guide

Introduction

OpenAlarm is a free, extensible and fast alarm application that works a bit like crontab or at in the UNIX system. Most of alarm-like applications on the market only wakes you up at the specified time. Sometimes, we want more. For example, I want to turn on the mobile network at 8am and turn it off at 1am to save battery power or I'd like to text my gf to tell her how beautiful she is at 9am every morning. Things like these should be common in our daily life, but I can't find a good application to do it. That's why I develop this Android application - OpenAlarm.


Targets

Android 1.5 and above. (Some G1 users reported that OpenAlarm is not stable on their phones... I am looking for a G1 to test)

How to Use

I've tried hard to make OpenAlarm's user-interface easy and intuitive so that you don't need to read this page before using it (sarcastic because you're reading it??)

Add a new alarm

To add a new alarm, click menu>Add. Because it is a new alarm, OpenAlarm directs you automatically to its settings page. If you don't want to configure this new alarm at this moment, click BACK key. Still, only when all settings of an alarm are configured correctly, you can enable it.

Configure an alarm

To configure settings of an alarm, a touch or Center key on D-pad on the alarm item gives you its settings page. A BACK key submits your changes into alarm database.

Tell an alarm what to do

What you want an alarm to do when it goes off is specified in Action preference. Touch Action preference brings up Action dialog listing all actions OpenAlarm supports now.

Enable/Disable an alarm

To enable/disable an alarm, you go to check/uncheck an alarm. If an alarm hasn't configured valid, you can't check it and OpenAlarm directs you automatically to its settings page. If an alarm was valid and you make it invalid (for example, by selecting no repeat days), its checked state will be removed when you go back to OpenAlarm's main screen.

If an alarm is checked successfully, it is scheduled and a notification shows up at the left-hand side of the status bar telling you what the next alarm is and when it will go off.
The system's AlarmClock put a notification on the right-hand side of status bar without telling you the schedule of next alarm. Moreover, when AlarmClock is killed by Task Manager (not recommended by Google, but everyone does it), this cute notification is left on the status bar and it makes you think your alarms are still scheduled to go off. It is NOT.

When OpenAlarm is killed or removed, all scheduled alarms are canceled and notification is removed.

Delete an alarm

A long touch on the alarm will bring up a context menu with a Delete menu item for you to delete an alarm.

Auto-Snooze

If an alarm is ringing as follows and you ignore it 1 minute (maybe you're out), OpenAlarm will snooze it minutes later automatically. How many minutes later is from your Snooze Duration setting. Besides, OpenAlarm does auto-snooze 3 times only and this alarm will be dismissed and set to its next schedule.


Math-lock

If you're a deep sleeper, you can check Math Lock on to have your alarm ask you a simple two-integer addition question before you can snooze or dismiss alarm. I've tried and it really wake you up from sleep.


Localization

OpenAlarm supports two locales, Traditional Chinese(繁體中文)and English.

Possible Future Work

Some features I am evaluating if doable,
  1. Love Text: Text someone at the specified time.
  2. You can suggest me.


Feedback

To tell me how you think about OpenAlarm, you can either use menu>Send feedback in OpenAlarm, email me, leave comments here or phone me if you're in Taiwan. You precious opinions should be taken into account on latter releases.

2010-01-28

My second application published on the Android Market

After months of work, today, I published my second Android application, OpenAlarm, on the Android Market. It's an alarm application that lets you choose what your phone does when an alarm goes off. For instance, we can set your alarm to go off with the action of turning off/on mobile network to save some battery power.

I've tried very hard to keep OpenAlarm's UI simple and easy to use (KISS rule always in my mind). And the imperative thing I want to mention is that OpenAlarm is extensible which means you can develop plug-ins on your own to enhance OpenAlarm. For people who are interested, go to project website for user guide and developer how-to.