Androidアプリケーションで使用されるライブラリのリストの実装。 試行番号2

ごく最近、使用済みライブラリのリストを含むダイアログボックスを実装する方法に関するHabrに関する記事に出会いました。 提案されたオプションは私には複雑すぎるようで、リスト自体は曲がって見えました。 この点で、この機能を実装するためのよりシンプルでエレガントな方法を共有することにしました。



モジュールの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コードを生成し、ダイアログボックスに表示されます。 執筆時点では、次のライセンスがサポートされています。





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();
      
      





サンプルのソースコードは、 こちらにあります 。 ご清聴ありがとうございました。



All Articles