road-test.jpg?w=2924

5/1 勞動節在台灣的朋友放假的同時, 我終於迎來人生最重要的考驗之一 (是嗎?) - DMV 路考 (behine-the-wheel drive test). 話說本來在考完 筆試 (written test) 之後, 一直想找時間把所有的路考的東西整理一下. 本來我是不打算約 5/1 這麼近的時間, 剛考完筆試想要休息一下, 加上工作繁忙 … blah blah (我是不會承認我拖延症復發的). 原本的路考時間是 7/2, 後來因為保險問題, 就決定還是早早去考比較好, 拿到正式駕照後也好跟他們 nego 一下 保費不是? (後來還是因為太懶沒有打電話去 nego)

Read more »

日本城櫻花節 (Japan Town - The Northern California Cherry Blossom Festival)

nccbf_banner.png?w=2924

每年四月第三個週末很熱鬧, 正好是美國的復活節 Easter週末, 在這周前的一兩週各地的活動很多, 我們也趁熱鬧跑去 Golden Gate Park 參加了撿彩蛋的活動, 不過兒子不太買單, 覺得撿彩蛋頗無聊, 倒是我撿到快累死了.

Read more »

Why leasing/buying a car?

剛來美國沒多久, 就一直被提醒要趕快去考駕照, 畢竟在一個車輪上的國家, 沒車就跟沒腳一樣哪兒都去不了. 而我所在的北加州(San Francisco) 的大眾交通工具有幾個選擇:

Read more »

Android Hopping Animation

WHY?

If you ever see what the Android onboarding hop animation looks like, it’s an amusing welcome animation for the new user whom first time launches the phone. Here’s an example of that. Let’s see the result first.

ezgif.com-crop.gif
Animation example


Read more »

Android StrictMode for debugging

strictmode.png?w=2924

Introduction

Android provides a handy tool for developers to see what happened to their Apps. Sometimes, you just forgot to keep massive loading job off the main UI thread, e.g., network access, database query, or something you need much time to handle, in these cases, you usually got ANR dialogs to notify you: Your App is going to spend too much time on something in UI thread.

Read more »

1*5koxNC03BSLLt6Urass5yA.png

Small tip

You might wanna change the text alignment of the alert controller. Let’s say, change the alignment from center to right. Then the following is for you.

Just simply open a playground and run these code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import UIKit
import XCPlayground
import PlaygroundSupport

let alertView = UIAlertController(title: "Demo Alert", message: "", preferredStyle: .alert)
alertView.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))

let paragraphStyle = NSMutableParagraphStyle()
// Here is the key thing!
paragraphStyle.alignment = .left

let messageText = NSMutableAttributedString(
string: "Left Position, correct?",
attributes: [
NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font : UIFont.preferredFont(forTextStyle: .body),
NSAttributedString.Key.foregroundColor : UIColor.black
]
)

alertView.setValue(messageText, forKey: "attributedMessage")

let viewController = UIViewController()
PlaygroundPage.current.liveView = viewController.view
viewController.present(alertView, animated: true, completion: nil)

The most important thing is the key attributedMessage. An alert controller can change its text alignment value by using this key.

[References]

Introduction to Key-Value Observing Programming Guide

mysql-logo.jpg?w=2924

What happened?

Alright, I don’t know what happened when trying to log in to MySQL. And it shows that message: MySQL - Error 1045 (28000) using password: YES. I am pretty sure that user/pwd pair is correct. After searching and studying some articles and forum discussions. I found it might be caused by broken SQL or reinstall SQL. The interesting is I can’t remember I had done that before.

Read more »

android_multi_screen.png?w=2924

Introduction

This is just a note for myself to remind me how to do dp-to-pixel translation and vice versa. Let’s see how to do it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public static float convertDpToPixel(float dp, Context context) {	
float px = dp * getDensity(context);
return px;
}

public static float convertPixelToDp(float px, Context context) {
float dp = px / getDensity(context);
return dp;
}

public static float getDensity(Activity context) {
DisplayMetrics metrics = new DisplayMetrics();
context.getWindowManager().getDefaultDisplay().getMetrics(metrics);
return metrics.density;
}

It’s pretty simple, enjoy.
Happy Coding.

[Reference]

  1. DisplayMetrics | Android Developers
  2. Screen compatibility overview | Android Developers
  3. Pixplicity | DP/PX converter