Skip to content

Commit

Permalink
Add license text to about screen
Browse files Browse the repository at this point in the history
  • Loading branch information
MrApplejuice committed Feb 1, 2022
1 parent c49c4e3 commit fd05989
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 6 deletions.
11 changes: 9 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ plugins {
}

task generateAboutStrings {
String fileContents = new File("ATTRIBUTIONS.md").text
String[] sections = fileContents.replaceAll("\n", " ").split("##")
String attributionsText = new File("ATTRIBUTIONS.md").text
String[] sections = attributionsText.replaceAll("\n", " ").split("##")

def outList = []

Expand All @@ -31,6 +31,11 @@ task generateAboutStrings {
outList.add(["icons": tagsList, "title": aHrefTitle, "link": aHrefAddress])
}

String licenseText = new File("LICENSE.md").text.trim()
String[] splits = licenseText.split("\n", 2)
String licenseTitle = splits[0].replace("#", "").trim()
licenseText = splits[1].trim().replaceAll("\n\n", "\\\\\\n\\\\\\n").replaceAll("\n", " ")

def xmlout = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(xmlout)
xml.resources {
Expand All @@ -49,6 +54,8 @@ task generateAboutStrings {
xml.item(item["link"])
}
}
xml.string(name:"autostring_about_license_title", "License under ${licenseTitle}")
xml.string(name:"autostring_about_license_text", licenseText)
}

FileWriter about_strings_file_writer = new FileWriter("app/src/main/res/values/about_strings.xml")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package eu.pkgsoftware.babybuddywidgets;

import android.graphics.Color;
import android.graphics.drawable.Icon;
import android.media.Image;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.phrase.Phrase;

import java.util.ArrayList;

import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.widget.TextViewCompat;
import androidx.fragment.app.Fragment;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -28,6 +42,10 @@ public IconData(String icons, String title, String link) {
}
}

private int dpToPx(float dp) {
return (int) (getContext().getResources().getDisplayMetrics().density * dp + 0.5f);
}

@Override
public View onCreateView(
@NonNull LayoutInflater inflater,
Expand All @@ -52,13 +70,58 @@ public View onCreateView(
));
}

for (IconData iconData : iconDataList) {
for (final IconData iconData : iconDataList) {
LinearLayout group = new LinearLayout(getContext());
group.setPadding(0, dpToPx(8), 0, dpToPx(8));
group.setOrientation(LinearLayout.VERTICAL);
group.setGravity(Gravity.START);

LinearLayout iconsList = new LinearLayout(getContext());
group.addView(iconsList);

for (String icon : iconData.icons) {
ImageView iView = new ImageView(getContext());
int id = getResources().getIdentifier(icon, "drawable", getActivity().getPackageName());
iView.setImageDrawable(ContextCompat.getDrawable(getActivity(), id));
iView.setMinimumWidth(dpToPx(48));
iView.setMinimumHeight(dpToPx(48));
iconsList.addView(iView);
}

TextView tv = new TextView(getContext());
tv.setText(iconData.title);
tv.setMovementMethod(LinkMovementMethod.getInstance());
TextViewCompat.setTextAppearance(tv, R.style.TextAppearance_AppCompat_Body1);
String rawText = Phrase.from(
"Images based on or derived from works from:\n{title}"
).put(
"title", iconData.title
).format().toString();
SpannableString spanText = new SpannableString(rawText + "\n" + "Open creator's website");
spanText.setSpan(
new ClickableSpan() {
@Override
public void onClick(@NonNull View view) {
showUrlInBrowser(iconData.link);
}

@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.setUnderlineText(true);
ds.setColor(Color.BLUE);
}
},
rawText.length() + 1,
spanText.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
);
tv.setText(spanText);
tv.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT
));
binding.root.addView(tv);

group.addView(tv);

binding.root.addView(group);
}

return binding.root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -94,4 +96,8 @@ public void onDestroy() {
protected MainActivity getMainActivity() {
return (MainActivity) getActivity();
}

protected void showUrlInBrowser(String url) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
}
24 changes: 23 additions & 1 deletion app/src/main/res/layout/about_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,26 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".AboutFragment" />
android:padding="8dp"
tools:context=".AboutFragment">

<TextView
android:id="@+id/aboutLicenseTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/autostring_about_license_title"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />

<TextView
android:id="@+id/aboutLicenseText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/autostring_about_license_text" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="External Resources"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />

</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/about_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
<item>https://www.flaticon.com/free-icons/poop</item>
<item>https://www.flaticon.com/free-icons/humidity</item>
</string-array>
<string name='autostring_about_license_title'>License under The MIT License (MIT)</string>
<string name='autostring_about_license_text'>Copyright © 2022 Paul Konstantin Gerke (and contributors)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</string>
</resources>

0 comments on commit fd05989

Please sign in to comment.