第一個公開作品: Shuttlecords

之前我開發過兩個app,一個是交功課用的文字接龍遊戲,一個是兼職時做的找工作平台,但是兩個app都沒有上架。

這一次,我大概用了3-4個星期的時間,開發了一個羽毛球專用的記分器,方便自己記錄,亦希望其他羽毛球運動員用得上這個App。以下我會簡單介紹一下,詳細情況就請到Playstore 下載來親身體驗吧﹗

web_hi_res_512

PlayStore download link for Shuttlecords

這個App我名為Shuttlecords,取自Shuttlecocks和Records的結合,有記錄羽毛球比賽之意思。

用法很簡單,先新增球員姓名,系統會自動新增隊伍(單打隊伍和雙打隊伍)。例如加入球員A和球員B,系統會新增2支單打隊伍(A和B),以及1支雙打隊伍(A和B 是雙打搭擋)。其後加入球員C的話,系統會自動增加1支單打隊伍(C),以及2支雙打隊伍(分別是AC和BC)。簡單來說,用家只需要增加球員就可以。之後就可以加入比賽記錄,只需要設置比賽日期和兩支比賽隊伍,輸入比數(最少1局,最多3局)即可。

另外,可以加入打賭設定,賭注自由決定(預設是5元),兩隊最少要有一名球員參與打賭,亦可設定雙炒和三炒情況(如少於11分時賭注雙倍)。若發生1 VS 2的情況,即雙打比賽時,其中一隊的一位球員不參與打賭,另一位球員就要承擔他搭檔的打賭。例如AB 和CD 4人進行雙打比賽,賭注是5元,D不參與打賭,比數是AB勝21:12,C就要給AB兩人各5元。

App內有比賽積分表和打賭積分表兩種,每個積分表內可分別查看球員和隊伍的表現。

以上的記錄方式是以我個人親身經驗來設計,未必符合其他運動員平時練習的風格。所以我十分歡迎各位的意見。

下一步,我會先研究如何在Android上做unit testing,之後會繼續開發,目標是增加線上功能,如不同運動員共同存取記錄。不過,下次的更新日期可能要等很久了,因為下星期一我就要正式上班,開始我的grad job。

Advertisements

Android 筆記

Recently I am focusing on improving my Android development skills. Here are the websites I read.

  1. Introduce Model-View-Presenter Concept
  2. RxJava 2.0: Simpler form of AsyncTask
  3. Lambda: Simpler form of callback
    •  https://yongjhih.gitbooks.io/feed/content/lambda.html
  4. Object/relation mapping. Greatly reduce development time in a database.
    • http://greenrobot.org/
      • GreenDao Schema Migration: https://piercezaifman.com/how-to-setup-database-migrations-with-greendao/
  5. Easy debugger for Android sqlite database
  6. Android testing: Robolectric (still studying)
  7. New Layout: Constraint Layout
  8. Improved ListView: PlaceHolderView
  9. Android Asset Generator: online icon generate tool for Android
  10. Unit testing in Android (JUnit, Mockito)

Some are extracted from: Mindorks: Android Development Best Practices

 

Note: Press back button to return to Main Activity

Suppose we have two activities: MainActivity and GameActivity , and only MainActivity can start GameActivity.

Manifest setting:

<activity android:name=".MainActivity">
    ...
</activity>
<activity android:name=".GameActivity"
    android:launchMode="singleTask">
</activity>

From the Cheese Factory’ blog (2015), for an activity with “singleTask” as the launch mode:

But if there is an existed one, all of Activities placed above that singleTask Activity would be automatically and cruelly destroyed in the proper way (lifecycle trigged) to make that an Activity we want to appear on top of stack.

Overriding the onKeyDown() and onBackPressed() methods in GameActivity .

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (Integer.parseInt(android.os.Build.VERSION.SDK) > 5
            && keyCode == KeyEvent.KEYCODE_BACK
            && event.getRepeatCount() == 0) {
        Log.d(log_name, "onKeyDown Called");
        onBackPressed();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

@Override
public void onBackPressed() {
    //Go back to main activity.
    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
    startActivity(intent);
}

(from http://stackoverflow.com/a/3142471)

Also, overriding the onKeyDown() and onBackPressed() methods in MainActivity, so that when the back button is pressed, home screen is returned.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
 //same as above...
}

@Override
public void onBackPressed() {
   moveTaskToBack(true);
}

Overall Effect:

Start MainActivity (M), and then start GameActivity (G) from it.

–> Back stack: M > G (G is on the top of the stack).

Press back button in GameActivity.

–> Back stack: M > G > M (A new MainActivity is created).

If we start GameActivity again from MainActivity.

–> Back stack: M > G. (Since GameActivity is running, the newer MainActivity is destroyed).

 

Or if we Press back button in MainActivity, home screen is returned. And then we go back to the app.

–> Back stack: M > G > M (Remain unchanged).

 

 

Reference:

The Cheese Factory. (2015). Understand Android Activity’s launchMode: standard, singleTop, singleTask and singleInstance . https://inthecheesefactory.com/blog/understand-android-activity-launchmode/en