モジュールのbuild.gradleに依存関係を記述します。
compile('de.psdev.licensesdialog:licensesdialog:1.8.0')
次に、使用するライブラリを含むリストを作成する必要があります。 これを行うには、 res / raw フォルダーにlicense.xmlファイルを作成します (他の名前を使用できます)。
例:
<?xml version="1.0" encoding="utf-8"?> <notices> <notice> <name>Application Crash Reporting for Android (ACRA)</name> <url>http://acra.ch/</url> <copyright>Copyright 2010 Emmanuel Astier & Kevin Gaudin</copyright> <license>Apache Software License 2.0</license> </notice> <notice> <name>Android ViewPagerIndicator</name> <url>http://viewpagerindicator.com/</url> <copyright>Copyright (C) 2011 The Android Open Source Project<br/>Copyright (C) 2012 Jake Wharton</copyright> <license>Apache Software License 2.0</license> </notice> <notice> <name>OrmLite</name> <url>http://ormlite.com/</url> <copyright>Copyright Gray Watson</copyright> <license>ISC License</license> </notice> <notice> <name>PhotoView</name> <url>https://github.com/chrisbanes/PhotoView</url> <copyright>Copyright 2011, 2012 Chris Banes.</copyright> <license>Apache Software License 2.0</license> </notice> </notices>
ご覧のとおり、ライセンスの巨大なテキストを書く必要はありませんが、名前のみを示すことができます。 このファイルに基づいて、ライブラリはHTMLコードを生成し、ダイアログボックスに表示されます。 執筆時点では、次のライセンスがサポートされています。
- Apacheソフトウェアライセンス2.0
- BSD 2/3条項ライセンス
- Gnu General Public License 2.0 / 3.0
- GNU Lesser General Public License 2.1 / 3
- MIT
- Mozilla Public License 1.1
Licenseクラスから継承して抽象メソッドを実装することにより、独自のライセンスを作成することもできます。
ライブラリに著作権がない場合は、次のように書くだけです。
<copyright/>
アクティビティにコードを書くことは残っています:
new LicensesDialog.Builder(this) .setNotices(R.raw.license) .build() .showAppCompat();
出力は次のとおりです。
Javaで直接ライセンスを作成することもできます。
final String name = "LicensesDialog"; final String url = "http://psdev.de"; final String copyright = "Copyright 2013 Philip Schiffer <admin@psdev.de>"; final License license = new ApacheSoftwareLicense20(); final Notice notice = new Notice(name, url, copyright, license); new LicensesDialog.Builder(this) .setNotices(notice) .build() .showAppCompat();
サンプルのソースコードは、 こちらにあります 。 ご清聴ありがとうございました。