📜 ⬆️ ⬇️

Implementation of the list of used libraries in the Android application. Attempt # 2

Most recently I came across an article on Habré on how to implement a dialog box with a list of used libraries. The proposed version seemed too complicated to me, and the list itself looked crooked. In this regard, I decided to share a more simple and elegant way to implement this functionality.

Writing a dependency in the build.gradle of our module:

compile('de.psdev.licensesdialog:licensesdialog:1.8.0') 

Now we need to create a list with used libraries. To do this, create a file license.xml in the res / raw folder (you can use other names).

Example:
')
 <?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> 

As you can see, we do not need to write a huge text of the license, but we can only indicate its name. The library on the basis of this file generates HTML-code, which will then be displayed in the dialog box. At the time of writing, the following licenses are supported:


You can also create your license by inheriting from the License class and implementing abstract methods.

If the library does not have copyright, then simply write:

 <copyright/> 

It remains to write the code in our Activity:

 new LicensesDialog.Builder(this) .setNotices(R.raw.license) .build() .showAppCompat(); 

This is what happens on the output:

image

You can also create a license directly in 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(); 

The source code of the sample can be found here . Thanks for attention.

Source: https://habr.com/ru/post/275097/


All Articles