1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2025-12-15 00:31:11 +01:00

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

@ -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);
}
}