SparseArray error: Call requires API level S : SparseArray.set()【Kotlin】

こんなの出ましたけど。

SparseArray error: Call requires API level S : SparseArray.set()

どうしましょう。

また、アノテーションつけて、SDKバージョンによる分岐ですか?

内容

API level 1 からある SparseArray ですが、set メソッドが API level 31 (Android 12/S) で追加されています。

Alias for put(int, java.lang.Object) to support Kotlin [index]= operator.

👉 SparseArray  |  Android Developers 

set was added in Android 12 and is just a copy of the put function, which you can freely use instead.

setはAndroid12で追加されたもので、関数の単なるコピーであり、put代わりに自由に使用できます。

The reason they copied the function with a different name is so array access syntax can work in Kotlin. When the Kotlin compiler sees a function in a Java class with the name set and two parameters, it allows it to be called using array syntax like this:

配列アクセスがKotlinで機能できるようにするためです。Kotlinコンパイラが名前setと2つのパラメータを持つJavaクラスの関数を検出すると、次のような配列構文を使用して関数を呼び出すことができます。


mySparseArray.put(3, someObject)

// is the same as
mySparseArray[3] = someObject

But since they only added it in Android 12, it is not practical to use the new function if you are targeting anything less than Android 12 (sdk version 31), so it will take a few years to become useful.

ただし、Android 12でのみ追加されているため、Android 12(sdkバージョン31)未満をターゲットにしている場合は、新しい機能を使用するのは実用的ではありません。そのため、使用できるようになるまでに数年かかります。

In my opinion, it was a mistake to add this function to the base class, because now it is impossible to use array access syntax for a few years until it finally becomes sensible to make SDK 31 the minSdkVersion. Before they added it, it was possible to use an extension function to have this functionality, but now an extension function cannot be used because its name would shadow the one in the base class. Also, lint doesn't show an error for the array access syntax, so it will crash at runtime if you use it. They should have put this in as an extension function in androidx-core-ktx.

私の意見では、この関数を基本クラスに追加するのは間違いでした。SDK31を最終的に実用化するまで、数年間は配列アクセス構文を使用できなくなったためminSdkVersionです。追加する前は、拡張関数を使用してこの機能を使用することは可能でしたが、その名前が基本クラスの拡張関数をシャドウするため、拡張関数を使用できなくなりました。また、lintは配列アクセス構文のエラーを表示しないため、使用すると実行時にクラッシュします。彼らはこれを拡張関数として androidx-core-ktx に入れるべきでした。

Edit: Looks like maybe this is fixed in an upcoming version, if I'm understanding "backport" correctly.

編集:「バックポート」を正しく理解していれば、これは今後のバージョンで修正される可能性があります。

👉 android - SparseArray error: Call requires API level S - Stack Overflow 

The core-ktx library defines extension functionSparseArray.set(). This method does not exist in the Android SDK until S, the currently in-development version. Many apps use this extension function and compile against pre-S SDKs, meaning it resolves to the library function. Such apps will run fine on earlier platform versions as well as S.

core-ktxライブラリでは、拡張関数として SparseArray.set() が定義されています。このメソッドは、Android S までのAndroid SDKには存在しません。多くのアプリはこの拡張関数を使用し、S以前のSDKに対してコンパイルしています。つまり、ライブラリの関数に解決されます。そのようなアプリは、Sだけでなく、それ以前のプラットフォームのバージョンでも問題なく実行されます。

When these apps are updated to compile against S, the Kotlin compiler will resolve calls to the S SDK function which only exists on devices running the S platform; however, these apps are expected to run against earlier platform versions. They will crash when run against pre-S platforms since the method does not exist.

これらのアプリを Android S に対してコンパイルするように更新すると、Kotlin コンパイラーは、S プラットフォームを実行しているデバイスにのみ存在する S SDK 関数の呼び出しを解決しますが、これらのアプリは以前のプラットフォームのバージョンに対して実行されます。S以前のプラットフォームで実行すると、このメソッドが存在しないためクラッシュします。

As far as I can tell, there is nothing that either app developers or the core-ktx library can do about this situation. The library cannot remove the function without breaking binary compatibility with dependent libraries and regressing functionality. The app developer cannot explicitly force Kotlin to call the extension function on earlier platforms, either in their app code or dependent libraries.

私の知る限り、アプリ開発者にもcore-ktxライブラリにも、この状況に対してできることは何もないようです。ライブラリは、依存ライブラリとのバイナリ互換性を破壊し、機能を後退させることなく、この関数を削除することができません。アプリ開発者は、アプリのコードや依存ライブラリで、以前のプラットフォームで拡張関数を呼び出すように明示的にKotlinに強制することはできません。

Extension function resolution policy of "member always wins" is problematic for Android SDKs

Android SDKでは「メンバーが常に勝つ」という拡張関数解決ポリシーが問題視されている

👉 Extension function resolution policy of "member always wins" is problematic for Android SDKs : KT-45968 

SparseArray.set was added as an alias for SparseArray.put in Android S.
Consider backporting that by rewriting SparseArray.set to SparseArray.put.

SparseArray.set はSparseArray.put のエイリアスとして Android S に追加されました。
SparseArray.setをSparseArray.put に書き換えてバックポートすることを検討するべし。

👉 Backport SparseArray.set [185547135] - Visible to Public - Issue Tracker 

対処方法

put(Int, Object) の形式に戻して修正されたバージョンのSDKを待つ。


mySparseArray[3] = someObject

  ↓

mySparseArray.put(3, someObject)


日本語文字起こしに対応した「Google レコーダー」が音声入力として最強では?

最近、やっと更新されて日本語でも高精度な文字起こしができるようになりました。

👉 レコーダー - Google Play のアプリ 

レコーダーで、録音した音声を検索できます。会議、講義、バンド練習、家族の思い出など、なんでも録音して保存し、後で再生できます。レコーダーで、録音した音声の文字起こしとラベル付けが自動的に行われるため、大事な情報を簡単に見つけることができます。

✍ 編集

「語句の編集」から聞き直しながら意図する語句に編集できます。

また、録音した音声の前後の不要部分を書き起こし文字を見ながら「切り抜く」ことも可能です。

✍ 共有

以下の形式で共有することができます。

- 音声 (.m4a ファイル)
- 文字起こし (.gdoc .txt ファイル)
- 動画クリップ (.mp4 ファイル)

✍ まとめ

私がよく使うのは、テキスト編集画面から「全選択」でクリップボードへコピーしてからの好きなエディタに貼り付けです。

iPhoneやパソコンからもブラウザ経由で録音、文字起こししたアーカイブを確認できます。

👉 ブラウザ版 Recorder 

以上です。よろしくおねがいします。


Android12でアイコンを四角にする方法

Android11 では、フォントやアイコン形状などはシステムUIのテーマとしてカスタマイズできていました。

Android11 custom theme icons

👉 Android 12 is missing font and icon shape customization 

しかし、Android12では、

android12 dynamic theme

フォント変更
→ できない。

アイコンの形状変更
→ できない。

👉 Android 12 Beta 3 Changelog: All the new features and changes! 

ということで、

Android12ではアイコンは丸型だけ。四角には変更できない。

ということになります。

このことについては、上記XDAデベロッパーサイトのコメントやGoogle Issue Tracker でも悲しみのコメントが多く寄せられています。

👉 Custom Styles missing from Wallpaper and Style menu [193775634] - Visible to Public - Issue Tracker 

しかし、Google 社員がコメントしているように、

“The custom style features (font, icon shape, icon pack, and accent color) in R are being replaced by the new dynamic theming feature that we are introducing in S. We see the new dynamic theming feature as more modern and intelligent. A simple and delightful experience that we hope all users can get to enjoy.”

「カスタムスタイル機能は、Android12ではダイナミックテーマ機能に置き換えられています。よりモダンでインテリジェントなものと見なされています。すべてのユーザーにシンプルで楽しい体験をお届けします。」

と、新しいダイナミックテーマ機能は、

- モダン
- インテリジェント
- シンプル
- 楽しい

ということなので心配ないようです。

使いづらくなっただけかと思ってびっくりしていましたが、

- モダン
- インテリジェント
- シンプル
- 楽しい

ということです。

よろしくおねがいいたします。

👉 アイコンの形は四角のほうが使いやすい 


Jake Wharton さん「Android12、ロック画面 / 常時表示の時計が良い。」

Android12について何かつぶやいています。


Android 12にアップグレードしたばかり。システムUIの使いやすさと実用性の急激な低下傾向が続いています。通知ペインは、コンテンツを表示するためのエリアですが、実際のコンテンツの2倍のネガティブスペースがあります。システムUIのピークは、時計が動く前のAndroid8でした。

でも、ロック画面や常時表示はとても気に入っています。大きな時計がいい。さらに、今回は時間と分のフォントが同じ太さになっています。

Android12 always show clock and info

 

「ロック画面」とか?

スマホを利用したあと、

電源ボタンを押したり、

一定時間経過後に、

画面が変化していきます。


スリープ画面 (画面消灯)

 ↓ 再度画面をオン

ロック画面

スリープ画面 (時間と情報を常に表示時 ※設定は後に記述)
Android12 消灯画面クロック表示

ロック画面
Android12 lock screen clock

 

各画面への条件や操作設定

利用画面から スリープ画面(画面消灯) へ遷移するには、

一定時間経過させるか、電源ボタンで消灯。


設定

 ↓

ディスプレイ

 ↓

画面消灯

Android12 画面消灯時間設定

この スリープ画面(画面消灯)時にも、

ロック画面のように、時計などが表示できる。


設定

 ↓

ディスプレイ

 ↓

ロック画面

 ↓

時間と情報を常に表示

Android12 時計と情報を常に表示する

さらに、ロック画面 へ遷移するには、

さらに、そこから、

一定時間経過させるか、電源ボタンでロック。


設定

 ↓

セキュリティ

 ↓

画面ロック 歯車アイコン

 ↓

画面消灯後からロックまでの時間

電源ボタンですぐロックする

Android12 画面ロック

うん、確かに見やすいし、使える。

しかしこの、

スリープ常時時計表示は、

暗闇で、

「OK、グーグル 今何時?」 とか言わなくても良いのだが!

👉 Android12 が来たので新機能を使ってみました。 | #android ファショ通 
👉 【Android12】「At a Glance」が壊れてる件 


【Android12】「At a Glance」が壊れてる件

今日も、OTAにてOSアップデートが行われましたが。

Android12-update-2021-11-05

天気が表示されないし、消すこともできないのが「At a Glance」。

Android12-at-a-glance-broken

以下、Reddit 和訳状況要点箇条書き。

- Pixel6 Pro でも壊れている。
- ファクトリーリセットしかない。→ばかげてる。
- ロック画面にも表示される。
- 古い天気アプリかカレンダーどちらかを開く。
- ホーム画面から削除できない。
- 空白部分が多すぎ。
- ドラッグして移動ができない。
- 天気が表示されない。
- Googleアプリの天気ウィジェットで代用。
- 一般でリリースされるのが信じられません。
- Android11では問題はなかった。

👉 At a Glance broken in Android 12? : GooglePixel 

android12-at-a-glance-weather

android12-at-a-glance-off

正しい使用が分かりづらいですが、Android11ではこのような不具合の話は盛り上がってませんでしたので、そこらが正しい仕様なのだろうと思われます。

- 日時表示(タップでカレンダーへ)
- 日付天気気温表示(タップで天気アプリへ)
- 次のスケジュールなど表示

機種を限定せずPixel3~6で壊れている雰囲気。

待つしかないのでしょうか。

👉 Google is prepping a big update to At a Glance that should have launched with Android 12 

👉 Android12 が来たので新機能を使ってみました。 

追記: 2021-11-25

しれっと修正アップデートされとる!!
at glance