2013年12月15日日曜日

Androidのグラフ描画ライブラリを探してみる。

Androidアプリに限らず、ツールを作成しているとグラフが描きたい場面に遭遇することはあるかと思います。
しかしながら、グラフ描画をゼロから作成するなんて簡単ではないです。(少なくとも自分には)

そこで、だれかが開発しているであろうライブラリを探すのですが・・・
探す上で幾つか問題が出てきます。

1. 使いやすいのか?
2. ライセンスは大丈夫か?

など。いろいろなライブラリを紹介しているサイトがあるので一覧を作成しませんが、個人的に使おうと決めたライブラリを紹介。

achartengine なにが良かったのか。
当然ですが、描きたいグラフが描ける。ライセンスが厳しくない(厳しいとか厳しくないとかの次元ではないですが、Apache License 2.0)
あと、設定が細かくできるため使いやすかったです。

公開しているアプリもこれを使いました。

棒グラフと折れ線グラフが同じグラフに表示できたり、複数の折れ線グラフを重ねることができたり。
便利です。

Apache License は以下の2点だけ気をつけました。

1. Google Play の記載情報として、以下の文を載せる。
このソフトウェアは、 Apache 2.0ライセンスで配布されている製作物が含まれています。
2. ソースファイルに以下を追記する。(XXXXXXの箇所は隠しました。)
/*
* Copyright (C) 2013 XXXXXXXXX
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

他にもやることあるかもしれないですが、このくらいで。

2013年12月14日土曜日

Androidのアプリ開発におけるStringの注意点

なんとなく普段Javaを書く感覚で開発してたところ、Eclipseに出ていたWarningが気になった。

以下、出力された渓谷
Provides more information about this issue.
Calling String#toLowerCase() or #toUpperCase()
 without specifying an explicit locale is a common
 source of bugs. The reason for that is that those
 methods will use the current locale on the user's
 device, and even though the code appears to work
 correctly when you are developing the app, it will fail
 in some locales. For example, in the Turkish locale,
 the uppercase replacement for i is not I.
If you want the methods to just perform ASCII
 replacement, for example to convert an enum name,
 call String#toUpperCase(Locale.US) instead. If you
 really want to use the current locale, call
 String#toUpperCase(Locale.getDefault()) instead.


詳細メッセージを表示してみた。

URL書いてあったので移動(ここ)。

たぶん、文字列を扱う際に英語以外の言語に注意しろと言っていると思う。
トルコ文字の"i"と”I"は違うんだ!って書いてあった。
他の事例はわからんけど、toUpperCaseとか文字列変換を気軽にやると痛い目に会うよということらしい。
USはたくさん使ってる人いるし、使いやすい。みたいなことが書いてあってすごく適当な仕様だとおもった。

普段使う文には大丈夫なんだろうけど、Locale.USをいつも指定すれば、平気かなぁなんて考えてる。

Warningが減ったので気分はすこしすっきり。