Load license, contributors, maintainers and 3party libs from ressources

This commit is contained in:
Gregor Santner 2016-08-27 16:40:16 +02:00
parent 89ee0450e9
commit c93e28cdc7
10 changed files with 142 additions and 50 deletions

View File

@ -3,9 +3,9 @@
02l>> If you helped by translating the app, please send a message on crowdin
03l>>
04l>> Schemes:
05l>> Firstname Lastname (Link)
06l>> Firstname Lastname (E-Mail)
07l>> Username (Link)
08l>> Username (E-Mail)
05l>> Firstname Lastname (Link): Text
06l>> Firstname Lastname (E-Mail): Text
07l>> Username (Link): Text
08l>> Username (E-Mail): Text
## 99l CONTRIBUTORS
Abhijith Balan (abhijithb21@openmailbox.org): Malayalam translation

View File

@ -15,4 +15,5 @@ along with this program. If not, see http://www.gnu.org/licenses/.
# Splashscreen-Images
The splashscreen images can be found on [flickr](https://www.flickr.com/photos/129581906@N06/sets/72157651933980136/with/16594947123/).

View File

@ -53,14 +53,25 @@ dependencies {
task copyRepoFiles(type: Copy) {
String[] copyFiles = ["README.md", "CONTRIBUTORS.md", "LICENSE.md", "CHANGELOG.md"]
String[] copyFiles = ["README.md", "LICENSE.md", "CHANGELOG.md"]
from rootProject.files(copyFiles)
into 'src/main/res/raw'
rename { String fileName ->
fileName.replace(fileName, fileName.toLowerCase())
}
filter { line -> (line.toString().matches("..l>>.*") || line.toString().startsWith("## 99l CONTRIBUTORS")) \
? null : line.toString().trim()
// Filter Contributors file
from(rootProject.file("CONTRIBUTORS.md")) {
into '.' // Target already changed to 'src/main/res/raw'
rename { String fileName ->
fileName.replace(fileName, fileName.toLowerCase())
}
filter { line ->
(line.toString().matches("..l>>.*") || line.toString().startsWith("## 99l CONTRIBUTORS")) ? null : line.toString().trim().replaceAll(" \\(.*\\)", "")
}
}
}
tasks.copyRepoFiles.execute()
tasks
.
copyRepoFiles.execute()

View File

@ -41,6 +41,11 @@ import android.widget.TextView;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.ui.HtmlTextView;
import com.github.dfa.diaspora_android.util.Helpers;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* Activity that holds some fragments that show information about the app in a tab layout
@ -79,7 +84,6 @@ public class AboutActivity extends AppCompatActivity {
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
}
/**
@ -96,10 +100,10 @@ public class AboutActivity extends AppCompatActivity {
View rootView = inflater.inflate(R.layout.fragment_about, container, false);
TextView appVersion = (TextView) rootView.findViewById(R.id.fragment_about__app_version);
if(isAdded()) {
if (isAdded()) {
try {
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName+ " ("+pInfo.versionCode+")"));
appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName + " (" + pInfo.versionCode + ")"));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
@ -113,16 +117,62 @@ public class AboutActivity extends AppCompatActivity {
* Fragment that shows information about the license of the app and used 3rd party libraries
*/
public static class LicenseFragment extends Fragment {
@BindView(R.id.fragment_license__licensetext)
HtmlTextView textLicenseBox;
@BindView(R.id.fragment_license__3rdparty)
HtmlTextView textLicense3partyBox;
public LicenseFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_license, container, false);
ButterKnife.bind(this, rootView);
final Context context = rootView.getContext();
accentColor = Helpers.hexColorFromRessourceColor(context, R.color.colorAccent);
textLicenseBox.setTextFormatted(getString(R.string.fragment_license__license_content,
getMaintainersHtml(context),
getContributorsHtml(context),
getLicenseHtml(context)
));
textLicense3partyBox.setTextFormatted(
getLicense3dPartyHtml(context)
);
return rootView;
}
private String accentColor;
public String getContributorsHtml(Context context) {
String text = Helpers.readTextfileFromRawRessource(context, R.raw.contributors,
"<font color='" + accentColor + "'><b>*</b></font> ", "<br>");
return text;
}
public String getMaintainersHtml(Context context) {
String text = Helpers.readTextfileFromRawRessource(context, R.raw.maintainers, "", "<br>");
text = text
.replace("NEWENTRY", "<font color='" + accentColor + "'><b>*</b></font> ")
.replace("SUBTABBY", "&nbsp;&nbsp;");
return text;
}
public String getLicenseHtml(Context context) {
String text = Helpers.readTextfileFromRawRessource(context, R.raw.license,
"", "").replace("\n\n", "<br><br>");
return text;
}
public String getLicense3dPartyHtml(Context context) {
String text = Helpers.readTextfileFromRawRessource(context, R.raw.license_third_party, "", "<br>");
text = text.replace("NEWENTRY", "<font color='" + accentColor + "'><b>*</b></font> ");
return text;
}
}
/**
@ -141,13 +191,13 @@ public class AboutActivity extends AppCompatActivity {
TextView appVersion = (TextView) rootView.findViewById(R.id.fragment_debug__app_version);
TextView podDomain = (TextView) rootView.findViewById(R.id.fragment_debug__pod_domain);
if(isAdded()) {
if (isAdded()) {
try {
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
AppSettings settings = ((App) getActivity().getApplication()).getSettings();
packageName.setText(pInfo.packageName);
appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName+ " ("+pInfo.versionCode+")"));
appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName + " (" + pInfo.versionCode + ")"));
podDomain.setText(getString(R.string.fragment_debug__pod_domain, settings.getPodDomain()));
} catch (PackageManager.NameNotFoundException e) {

View File

@ -65,6 +65,15 @@ public class HtmlTextView extends TextView {
* Linkify, format markdown and escape the displayed text.
*/
private void init(){
formatHtmlAndCustomTags();
}
public void setTextFormatted(String text){
setText(text);
formatHtmlAndCustomTags();
}
private void formatHtmlAndCustomTags(){
setText(new SpannableString(Html.fromHtml(getText().toString())));
Linkify.TransformFilter filter = new Linkify.TransformFilter() {
public final String transformUrl(final Matcher match, String url) {

View File

@ -26,8 +26,10 @@ import android.os.Environment;
import com.github.dfa.diaspora_android.R;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
@ -64,4 +66,35 @@ public class Helpers {
storageDir /* directory */
);
}
public static String readTextfileFromRawRessource(Context context, int rawRessourceId, String linePrefix, String linePostfix) {
StringBuilder sb = new StringBuilder();
String line = "";
BufferedReader br = null;
linePrefix = linePrefix == null ? "" : linePrefix;
linePostfix = linePostfix == null ? "" : linePostfix;
try {
br = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(rawRessourceId)));
while ((line = br.readLine()) != null) {
sb.append(linePrefix);
sb.append(line);
sb.append(linePostfix);
sb.append("\n");
}
} catch (Exception ignored) {
} finally {
if (br != null) {
try {
br.close();
} catch (IOException ignored) {
}
}
}
return sb.toString();
}
public static String hexColorFromRessourceColor(Context context, int idColor){
return "#" + Integer.toHexString(context.getResources().getColor(idColor) & 0x00ffffff);
}
}

View File

@ -25,6 +25,7 @@
<com.github.dfa.diaspora_android.ui.HtmlTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_license__licensetext"
android:text="@string/fragment_license__license_content"
style="@android:style/TextAppearance.DeviceDefault.Small"
android:linksClickable="true" />
@ -39,7 +40,7 @@
<com.github.dfa.diaspora_android.ui.HtmlTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fragment_license__3rd_party_libs_content"
android:id="@+id/fragment_license__3rdparty"
style="@android:style/TextAppearance.DeviceDefault.Small"
android:linksClickable="true" />
</LinearLayout>

View File

@ -0,0 +1,11 @@
NEWENTRY NetCipher
https://github.com/guardianproject/NetCipher
NEWENTRY ButterKnife
https://jakewharton.github.io/butterknife
NEWENTRY Android Support Library
https://developer.android.com/topic/libraries/support-library/index.html
NEWENTRY Android Design Library
https://android-developers.blogspot.de/2015/05/android-design-support-library.html

View File

@ -0,0 +1,5 @@
NEWENTRY Gregor Santner (gsantner)
SUBTABBY https://gsantner.github.io
NEWENTRY Paul Schaub (vanitasvitae)
SUBTABBY https://github.com/vanitasvitaes

View File

@ -107,30 +107,11 @@
<!-- License & help (large amount of text) -->
<string name="fragment_license__copyright_years" translatable="false">Copyright © 20152016</string>
<string name="fragment_license__license_content" translatable="false">&lt;b>Maintainers:&lt;/b>&lt;br>
&#8226; gsantner&lt;br>
https://gsantner.github.io&lt;br>
&#8226; Paul Schaub (vanitasvitae)&lt;br>
https://github.com/vanitasvitae&lt;br> &lt;br>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see&lt;br>
http://www.gnu.org/licenses.&lt;br> &lt;br>
&lt;i>The splashscreen images can be found on flickr: &lt;br>
https://www.flickr.com/photos/129581906@N06/sets/72157651933980136/with/16594947123 &lt;br>
They were published by \"Lydia\" and are licensed under cc by-nc-sa.&lt;/i></string>
<string name="fragment_license__license_content" translatable="false">
&lt;h2>Maintainers:&lt;/h2> %1$s
&lt;h2>Contributors:&lt;/h2> %2$s
&lt;h2>License:&lt;/h2> %3$s
</string>
<string name="about_activity__title_about_app">About</string>
<string name="about_activity__title_about_license">License</string>
<string name="about_activity__title_debug_info">Debugging</string>
@ -157,15 +138,5 @@
Also feel free to tell your friends about #DiasporaForAndroid!</string>
<string name="lorem_ipsum" translatable="false">Auch gibt es niemanden, der den Schmerz an sich liebt, sucht oder wünscht, nur, weil er Schmerz ist, es sei denn, es kommt zu zufälligen Umständen, in denen Mühen und Schmerz ihm große Freude bereiten können. Um ein triviales Beispiel zu nehmen, wer von uns unterzieht sich je anstrengender körperlicher Betätigung, außer um Vorteile daraus zu ziehen? Aber wer hat irgend ein Recht, einen Menschen zu tadeln, der die Entscheidung trifft, eine Freude zu genießen, die keine unangenehmen Folgen hat, oder einen, der Schmerz vermeidet, welcher keine daraus resultierende Freude nach sich zieht? Auch gibt es niemanden, der den Schmerz an sich liebt, sucht oder wünscht, nur, weil er Schmerz ist, es sei denn, es kommt zu zufälligen Umständen, in denen Mühen und Schmerz ihm große Freude bereiten können. Um ein triviales Beispiel zu nehmen, wer von uns unterzieht sich je anstrengender körperlicher Betätigung, außer um Vorteile daraus zu ziehen? Aber wer hat irgend ein Recht, einen Menschen zu tadeln, der die Entscheidung trifft, eine Freude zu genießen, die keine unangenehmen Folgen hat, oder einen, der Schmerz vermeidet, welcher keine daraus resultierende Freude nach sich zieht?</string>
<string name="fragment_license__3rd_party_libs_title">Used 3rd Party Libraries</string>
<string name="fragment_license__3rd_party_libs_content" translatable="false">
&#8226;Android Support Library:&lt;br>
https://developer.android.com/topic/libraries/support-library/index.html &lt;br>
&#8226;Anndroid Design Library:&lt;br>
https://android-developers.blogspot.de/2015/05/android-design-support-library.html &lt;br>
&#8226;NetCipher:&lt;br>
https://github.com/guardianproject/NetCipher &lt;br>
&#8226;ButterKnife:&lt;br>
https://jakewharton.github.io/butterknife/ &lt;br>
</string>
</resources>