「Fragment を利用するか、しないか」という話

How often do you actually use fragments in your job? : androiddev

「どれくらいの頻度でFragmentを使っていますか。」というスレ。

興味深いコメントを多く見ることができます。

以前からFragmentについては否定的な意見を続けている Jake Warthon さんも登場しています。

5 years sober!

5年間使っていない。

Fragments don't represent anything overwhelmingly challenging. Creating re-usable pieces of UI tied to reusable controller/presenter/whatevers doesn't even require a library. Their problem stems from a lifecycle that's too complicated compounded with a menu system that's convoluted and obsolete compounded with trying to solve dialogs, UI, and retaining instances across rotation compounded with asynchronous transactions compounded with an opaque backstack.

Fragment はチャレンジするものではありません。再利用可能なUIのパーツ作成には、再利用可能なコントローラやプレセンターなどを使えば他のライブラリなど必要ありません。問題なのは、複雑すぎるメニューの仕組みとライフサイクルが根源で、不透明なバックスタックを抱えた非同期トランザクションを組み込んでおり、ローテーション時のインスタンス保持をダイアログやUIに対して解決しようとして複雑になりすぎています。

All of these things should have been decoupled: creating modular bits of UI + code with a simple lifecycle, navigation between conceptual destinations, workers that are retained across rotation, and multiple sources of contribution to a menu.

以下のように分離すべきです。

- シンプルなライフサイクルをもつ小分けされた UI+コード
- 概念的な遷移先への遷移
- ローテーション時のワーカーの保持
- メニューに必要な複数のソース

また、「別Activityに遷移する場合は起動に時間がかかる」ということに関しては以下のように答えています。

I only use a single activity. Activity transitions are a mess. I've never seen one that didn't jank or get screwed up by the result of scrolling or adapter changes behind the scenes. I'll use a second activity if there are vastly different window styles such as a pop-up as the result of a notification vs. the full-screen app. Granted, transitions in the same window are also a mess since the use of view overlay means elevation doesn't work... but at least when everything is in one window you actually have control of things.

一つの Activity とします。Activityのトランジションはややこしいです。スクロール処理やアダプターの変更結果で悩まされたり苦労してないものを見たことがありません。

通知の結果としてのポップアップやフルスクリーンのアプリなど、ウィンドウスタイルが大きく異なる場合は、2番目のアクティビティを使用します。 確かに、同じウィンドウ内での遷移は、表示オーバーレイ時にエレベーションが機能しないので混乱しますが、少なくともすべてが1つのウィンドウ内にあるときは、実質的には処理できます。

I've been doing it this way for the last 5 years. No problems. Or rather, all the problems were problems with how the screen was implemented and not with the mechanism itself. The fine grained control shouldn't be at the site requesting navigation anyway. It's either data in the arguments of the navigation action or an implementation of whoever is implementing the mechanism of animation between screens. Neither belongs inside the call site of screen initiating navigation nor the destination screen.

私は、このやり方で5年間やってきましたが何の問題もありません。メカニズム自体が問題になることはなく、むしろ、すべての問題は画面の実装方法によるものです。とにかく、遷移をリクエストする側にきめ細かいコントロール処理を置いてはいけません。遷移のアクションかアニメーションどちらかの利用する引数データだけを置きます。これらは、遷移元、遷移先のどちらにも属しません。

具体的にこんなやりとりもあります。

I'm not sure how he handles viewpager without fragments but for all other purposes he mostly uses custom views (at least that's what I've found from his github)

FragmentなしでViewPagerの使い方がわかりません。他はカスタムViewでやっています。

View pager.

「View」の Pager ですよ。

ネット上にもFragmentを利用したサンプルばかりが目に付きますが、

結局、Fragmentを使う理由は、

「Fragmentを使わない実装方法が分からない、分かりづらい」

というのが実質的なところでしょうか。


Android 9 Pie 使ってみた

アナウンスしてる。

Android 9 Pie

Android 9 Pie: Powered by AI for a smarter, simpler experience that adapts to you

OTA来てたので入れる。

「アップデートのインストール」に30分くらいかかりました。

うん!

映えない隠れた機能が多いようなので少し使ってみてからまた書きます。

Android 9 Pie 使ってみた
【Android Pie】ナビゲーションバー の ホームボタン を ピル型 にする方法
【Android Pie】Google Digital Wellbeing を使う
【Android Pie】Auto-rotate (自動回転) OFF のときの挙動
【Android Pie】使いやすくなった音量設定
【Android Pie】スクリーンショット取得→編集 は「電源ボタン長押し」から


A Mac Book Pro style Wooden Dock for Magic Keyboard and Trackpad 2

A few days ago, I made a place-dock for Magic keyboard and Trackpad by wooden board.

【DIY】700円でつくる Magic Keyboard/Trackpad2 向け Mac Book Pro 13インチ型縦配置の枠



【DIY】700円でつくる Magic Keyboard/Trackpad2 向け Mac Book Pro 13インチ型縦配置の枠

I found this causes un-intented touch on the trackpad upper both sides.

I put on another wood panel on both sides.

I'll use this next weeks more ...


JetBrains の IDE が全て半額! 急げ!! 当然 Intellij IDEA もだぞ?

急げ! あと数時間しかないぞ!

Don’t miss the JetBrains Friendship Day special offer — all individual tools for developers at 50% off! #JetBrainsFriends

持ってる知り合いを探して、クーポン発行をお願いする、なのか?!

詳細はよう分からんがお得なはず!!


【DIY】700円でつくる Magic Keyboard/Trackpad2 向け Mac Book Pro 13インチ型縦配置の枠

横に並べて置くことを想定して設計されていますよね、Magic Keyboard/Trackpad2。

Magic Keyboard - 英語(US) - Apple(日本)

MacのためのMagic Trackpad 2(シルバー)を購入 - Apple(日本)

Keyboard の厚さが 4.1-10.9mm、
Trackpad2 の厚さが 4.9-10.9mm。

元々 Mac Book Pro 13インチ から移行した人にとっては、手の横移動が億劫に感じます。

かといって、縦に並べておくと誤操作連発でイライラすぎ。

この厚みの差が問題なんですよね。

探してみると、こんなのありますが。

BulletTrain eXpress Keyboard Platform | Indiegogo

商品詳細 Crispy Backboard 2

なんだかな...。

ホームセンターの木材加工サービスを利用して作ることにします。

材料

Mac Book Pro 13インチの寸法を雑に測っておきます。

これに近い雰囲気で縦に並べて置くことにして考えます。

縦に並べて置くには、厚さが、6.8-10.9mm の板が良さそう。

ホームセンターに行ってみると、300x300x7mm の木板が、328円であったのでこれにしました。

プラスチック板もあったのですが、今回は木製にします。

設計

ホームセンター内の加工サービス受付で、簡単な図面を書きます。

「直線で切り落としのみ」ということで、途中でカット作業は止めることができないそうなので、切り落とした部材をパズルのように並べることにします。

数分でカットされてきます。

1カット80円ということで、320円でした。

組み立て

とはいっても並べるだけです。

7mmなので木工用ボンドで接合しても強度が弱いので、その場合は薄い何かの上に並べて貼り付ければいいでしょう。

できあがり

手前の板は不要に思っていたのですが、パームレストのようにあると腕が疲れません。

とりあえず、まあいいか。

使いながら改良していこうと思います。

→ A Mac Book Pro style Wooden Dock for Magic Keyboard and Trackpad 2