mark33699 / IDLA

iOS Developer Learning Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IDLA

iOS Developer Learning Android

此為2020第11屆IT邦幫忙鐵人賽Mobile Development組參賽系列文章(寫於2019年)

是一個蘋果工程師學習安卓的過程

因文章與程式碼都為當日現做

故有commit message與文章對不起來的情況

以下方介紹為準


Lesson 01 - Android Studio

  • 大致介紹了AS的板面配置: 像這樣
  • 最大的差別在於Android有規定各種檔案存放的路徑
  • 再來以前Xcode只有一個Consolo,AS分成Log、Build、Run
  • 要執行除錯模式斷點才會停

Lesson 02 - Hello World

  • Log有分類型v,d,i,w,e,分別對應Verbose,Debug,Info,Warn,Error
  • 模擬器要自己下載
  • 實機要啟用開發者模式

Lesson 03 - 專案相關設定

  • AndroidManifest 跟 Gradle是Android兩個很重要的設定檔,類似xcodeproj
  • Gradle有類似podfile可以裝套件
  • 另外這集有講怎麼設定icon跟Target

Lesson 04 - Activity生命週期

  • Activity就是類似ViewController的東西
  • 因為他們沒有NavigationController,所以要切換Activity要透過Intent去call startActivity(類似present)
  • life cycle對照表
iOS Android
VDL onCreate
WillEnterForeground onRestart
VWA, DidBecomeActive onStart
VDA onResume
VWD, WillResignActive onPause
VDD, DidEnterBackground onStop
dealloc onDestroy

Lesson 05 - Activity啟動模式

  • 就是決定要不要new一個新的Activity
  • Standard: 不管怎樣都一定產生一個新的Activity出來。
  • Single Top: 如果要去的Activity已經在Task的Top的話,就直接拿來用,不然的話才new。
  • Single Task: 該Task只有一個Activity,如果Task已存在就pop回去,中間的Activity就都出棧。
  • Single Instance: 比照Single Task,有就pop,沒有才new,但會new在另一條Task

Lesson 06 - 如何製作畫面

  • 可以用拉的,AS會自動產生XML
  • XML是人類看得懂的,也可以自己寫XML,寫的時候可以即時預覽
  • 也可以用Java寫畫面

Lesson 07 - Layout

  • 類似self.view地位,但會安排subView的位置,主要這三種:
  • Linear Layout: 畫面很簡單的時候用
  • Relative Layout: 以前比較常用,現在應該都用ConstraintLayout
  • Frame Layout: Fragment會用到

Lesson 08 - ConstraintLayout基礎

  • 就是類似AutoLayout的東西,介紹基本用法

Lesson 09 - ConstraintLayout特色

  • Guideline: 輔助線,可以拿來算比例
  • Chain: 把多個物件串起來,自動分配位置(像stackView),但好用很多
  • gone: 物件不顯示了,而且位置還會被其他元件替補
  • CircleAngle: 可以用角度去算

Lesson 10 - TextView + EditText

Android iOS
TextView UILabel
EditText UITextField
  • 不用寫code就可做到跑馬燈跟UITextView自動長高

Lesson 11 - Button + Dialog

Android iOS
Button UIButton
Dialog UIAlertController
  • 基本上Android的元件事件都是用監聽(setOnXXXXXListener)給他一個Closure
  • Alert可以用鏈式寫法一路點下去很爽
  • 有個小提示叫做Toast,可以顯示訊息給user

Lesson 12 - ImageView + ImagePicker

Android iOS
ImageView UIImageView
Bitmap UIImage
  • 圖片檔名連一個大寫都不能出現= =,不然就會build不起來
  • scaleType就是以前的UIContentMode
    1. UIViewContentModeScaleToFill = fitXY
    2. UIViewContentModeScaleAspectFit = fitCenter
    3. UIViewContentModeScaleAspectFill = centerCrop
  • 圖片可能會被轉90度,還不知道怎麼解!!!
  • 模擬器可以測相機

Lesson 13 - Spinner + DatePickerDialog

Android iOS
Spinner UIPickerView
DatePickerDialog UIDatePicker

Lesson 14 - SeekBar + ProgressBar

Android iOS
ProgressBar UIActivityIndicatorView
SeekBar UISilder
  • Loading轉圈動畫是用ProgressBar

Lesson 15 - Buttons = [Radio,Chip,Switch,Toggle,Material]

Android iOS
RadioButton UISegment
Switch UISWitch
ToggleButton
Chip
MaterialButton UIButton
  • Chip可以做到常見的tag或是Mail收件人功能

Lesson 16 - RecyclerView

  • 以前都用ListView,但不像TableView有回收的機制,後來就出了個RecyclerView
  • iOS的Delegate跟DataSource,在安卓世界裡要用個RecyclerView.Adapter來處理三個必做的方法
    1. onCreateViewHolder(給它畫面)
    2. onBindViewHolder(給它資料或監聽點擊)
    3. getItemCount(資料筆數)
  • Adapter裡面要有個RecyclerView.ViewHolder負責持有畫面跟更新資料

Lesson 17 - BottomNavigationView + Fragment

  • BottomNavigationView做出來會像TabBarController,但是很像View上面放幾個按鈕然後把subView換掉的感覺
  • 我的理解:因為Android不像iOS可以ViewController addChildViewController,所以他們發明了可以加在Activity上的東西:Fragment 因此iOS上常見的ContainerViewController模式到的Android上就要請Fragment出馬了

Lesson 18 - call API

  • OkHttp套件
  • manifest要加<uses-permission android:name="android.permission.INTERNET" />,不然會閃退
  • 由三大部分OkHttpClient, Request, Call組成一次網路請求
  • callback裡動UI要用runOnUiThread包起來

Lesson 19 - JSON轉物件

  • Gson套件
  • 一行搞定:XXXClass xxxInstance = new Gson().fromJson(jsonString,XXXClass.class);
  • @SerializedName可以跟後端的欄位命名匹配

Lesson 20 - Activity Gallery

不知道為什麼有些圖在github上看不到...點我開啟

  • 內建一些範本可以參考或修改
  • Drawer: 漢堡側邊欄
  • Tabbed: 左右滑動切換頁面
  • Master/Detail: SplitViewController
  • FullScreen: 就是不會看到安卓系統下面的那條

Lesson 21 - 指紋辨識

  • 在manifest加上權限申請 <uses-permission android:name="android.permission.USE_FINGERPRINT" />
  • FingerprintManager: 檢查跟辨識使用
  • CancellationSignal: 取消辨識使用
  • 另外說明了怎麼設定才能在模擬器上測指紋

Lesson 22 - Google Map

不知道為什麼有些圖在github上看不到...點我開啟

  • 要去Google API網站申請API Key才能用
  • getSystemService(Context.LOCATION_SERVICE)取得locationManager
  • 用locationManager.requestLocationUpdates去定位
  • 用locationManager.removeUpdates(this)停止定位
  • 用mMap.animateCamera(cameraUpdate)去移動位置

Lesson 23 - 本地儲存

  • SharedPreferences(類似UserDefault)
  • 有file的概念,可以開很多個xml檔,不像我們只有一個.plist

Lesson 24 - Room

不知道為什麼有些圖在github上看不到...點我開啟

  • 是個Google官方提供的套件
  • 用來存取SQLite達到本地資料庫的CRUD
  • 分成三個Class:Entity(就是Model)、DAO(負責新刪改查)、Database(存資料的地方)
  • AS的Device File Explorer可以導出資料庫

Lesson 25 - ActionBar

  • 就是上面那條NavigationBar的位置
  • 改成客製:style.xml的DarkActionBar改成NoActionBar > findviewbyID取得layout上的ActionBar > setSupportActionBar
  • 沒有改成NoActionBar就setSupportActionBar = 閃退
  • 客製ActionBar就是Activity上的一個view

Lesson 26 - FCM Notification

  • FCM = Firebase Cloud Messaging
  • 已整合進AS(在Tools裡可以找到)
  • 不用取得user權限也可收推播
  • 實作繼承FirebaseMessagingService的Service去override onMessageReceived
  • 不像iOS一定要走APNs,他們也可以不透過FCM,像在中國Google不通,就要用其他的推播服務

Lesson 27 - APP Widget

不知道為什麼有些圖在github上看不到...點我開啟

  • Android的widget繼承於BroadcastReceiver
  • 生命週期:onEnabled(加入第一個widget時呼叫)、onUpdate(只要加入widget時就會呼叫)、onDeleted(只要刪除widget時就會呼叫)、onDisabled(刪除最後一個widget時呼叫)
  • onReceive:因為是繼承BroadcastReceiver,所以也可以發廣播給它
  • 佈局只支援FrameLayout、LinearLayout、RelativeLayout、GridLayout
  • 元件只支援AnalogClock、Button、Chronometer、ImageButton、ImageView、ProgressBar、TextView、ViewFlipper、ListView、GridView、StackView、AdapterViewFlipper(連子類也不行)
  • widget跟畫面的溝通必須要透過一個RemoteViews類來處理

Lesson 28 - 伸縮Banner + 瀑布流 + CardView

不知道為什麼有些圖在github上看不到...點我開啟

  • CardView: 就是FrameLayout的一種,但是加了一些現在常用的設計,例如圓角/陰影等等
  • 瀑布流: 給RecycleView一個StaggeredGridLayoutManager就OK了,超簡單
  • 伸縮Banner: 透過CoordinatorLayout跟CollapsingToolbarLayout即可達成~不用寫code
  • 在AndroidMenifest把Activity的label改掉,會蓋掉app_name

Lesson 29 - 上架

  • Android的key(憑證)是存在本地的,沒保管好就不能更新架上的APP了(現在Google好像有代管服務了,但沒研究)
  • 打包跟送審流程每個步驟都截圖下來了,直接去看吧~

About

iOS Developer Learning Android


Languages

Language:Java 100.0%