Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the LicensesDialogFragment's licenses text styleable #75

Merged
merged 4 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
import android.support.annotation.RawRes;
import android.support.annotation.StringRes;
import android.support.annotation.StyleRes;
import android.support.v4.app.DialogFragment;

import de.psdev.licensesdialog.model.Notice;
import de.psdev.licensesdialog.model.Notices;

Expand All @@ -40,6 +42,7 @@ public class LicensesDialogFragment extends DialogFragment {
private static final String ARGUMENT_THEME_XML_ID = "ARGUMENT_THEME_XML_ID";
private static final String ARGUMENT_DIVIDER_COLOR = "ARGUMENT_DIVIDER_COLOR";
private static final String ARGUMENT_USE_APPCOMPAT = "ARGUMENT_USE_APPCOMPAT";
private static final String ARGUMENT_NOTICE_STYLE = "ARGUMENT_NOTICE_STYLE";
private static final String STATE_TITLE_TEXT = "title_text";
private static final String STATE_LICENSES_TEXT = "licenses_text";
private static final String STATE_CLOSE_TEXT = "close_text";
Expand All @@ -62,6 +65,7 @@ public class LicensesDialogFragment extends DialogFragment {
private static LicensesDialogFragment newInstance(final Notices notices,
final boolean showFullLicenseText,
final boolean includeOwnLicense,
final String noticeStyle,
final int themeResourceId,
final int dividerColor,
final boolean useAppCompat) {
Expand All @@ -70,6 +74,7 @@ private static LicensesDialogFragment newInstance(final Notices notices,
args.putParcelable(ARGUMENT_NOTICES, notices);
args.putBoolean(ARGUMENT_FULL_LICENSE_TEXT, showFullLicenseText);
args.putBoolean(ARGUMENT_INCLUDE_OWN_LICENSE, includeOwnLicense);
args.putString(ARGUMENT_NOTICE_STYLE, noticeStyle);
args.putInt(ARGUMENT_THEME_XML_ID, themeResourceId);
args.putInt(ARGUMENT_DIVIDER_COLOR, dividerColor);
args.putBoolean(ARGUMENT_USE_APPCOMPAT, useAppCompat);
Expand All @@ -80,6 +85,7 @@ private static LicensesDialogFragment newInstance(final Notices notices,
private static LicensesDialogFragment newInstance(final int rawNoticesResourceId,
final boolean showFullLicenseText,
final boolean includeOwnLicense,
final String noticeStyle,
final int themeResourceId,
final int dividerColor,
final boolean useAppCompat) {
Expand All @@ -88,6 +94,7 @@ private static LicensesDialogFragment newInstance(final int rawNoticesResourceId
args.putInt(ARGUMENT_NOTICES_XML_ID, rawNoticesResourceId);
args.putBoolean(ARGUMENT_FULL_LICENSE_TEXT, showFullLicenseText);
args.putBoolean(ARGUMENT_INCLUDE_OWN_LICENSE, includeOwnLicense);
args.putString(ARGUMENT_NOTICE_STYLE, noticeStyle);
args.putInt(ARGUMENT_THEME_XML_ID, themeResourceId);
args.putInt(ARGUMENT_DIVIDER_COLOR, dividerColor);
args.putBoolean(ARGUMENT_USE_APPCOMPAT, useAppCompat);
Expand Down Expand Up @@ -153,7 +160,11 @@ public void onCreate(final Bundle savedInstanceState) {
mDividerColor = arguments.getInt(ARGUMENT_DIVIDER_COLOR);
}
}
mLicensesText = NoticesHtmlBuilder.create(getActivity()).setNotices(notices).setShowFullLicenseText(showFullLicenseText).build();
String noticeStyle = arguments.getString(ARGUMENT_NOTICE_STYLE);
if (noticeStyle == null) {
noticeStyle = resources.getString(R.string.notices_default_style);
}
mLicensesText = NoticesHtmlBuilder.create(getActivity()).setNotices(notices).setShowFullLicenseText(showFullLicenseText).setStyle(noticeStyle).build();
} else {
throw new IllegalStateException("Missing arguments");
}
Expand Down Expand Up @@ -239,6 +250,7 @@ public static class Builder {
private Integer mRawNoticesResourceId;
private boolean mShowFullLicenseText;
private boolean mIncludeOwnLicense;
private String mNoticesStyle;
private int mThemeResourceId;
private int mDividerColor;
private boolean mUseAppCompat;
Expand All @@ -252,6 +264,7 @@ public Builder(@NonNull final Context context) {
// Set default values
mShowFullLicenseText = false;
mIncludeOwnLicense = true;
mNoticesStyle = context.getString(R.string.notices_default_style);
mThemeResourceId = 0;
mDividerColor = 0;
mUseAppCompat = false;
Expand Down Expand Up @@ -287,6 +300,16 @@ public Builder setIncludeOwnLicense(final boolean includeOwnLicense) {
return this;
}

public Builder setNoticesCssStyle(@StringRes final int cssStyleTextId) {
mNoticesStyle = mContext.getString(cssStyleTextId);
return this;
}

public Builder setNoticesCssStyle(final String cssStyleText) {
mNoticesStyle = cssStyleText;
return this;
}

public Builder setThemeResourceId(@StyleRes final int themeResourceId) {
mThemeResourceId = themeResourceId;
return this;
Expand All @@ -309,9 +332,9 @@ public Builder setUseAppCompat(final boolean useAppCompat) {

public LicensesDialogFragment build() {
if (mNotices != null) {
return newInstance(mNotices, mShowFullLicenseText, mIncludeOwnLicense, mThemeResourceId, mDividerColor, mUseAppCompat);
return newInstance(mNotices, mShowFullLicenseText, mIncludeOwnLicense, mNoticesStyle, mThemeResourceId, mDividerColor, mUseAppCompat);
} else if (mRawNoticesResourceId != null) {
return newInstance(mRawNoticesResourceId, mShowFullLicenseText, mIncludeOwnLicense, mThemeResourceId, mDividerColor, mUseAppCompat);
return newInstance(mRawNoticesResourceId, mShowFullLicenseText, mIncludeOwnLicense, mNoticesStyle, mThemeResourceId, mDividerColor, mUseAppCompat);
} else {
throw new IllegalStateException("Required parameter not set. You need to call setNotices.");
}
Expand Down
23 changes: 15 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,32 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.6</java.version>
<android.sdk.platform>23</android.sdk.platform>
<android.sdk.platform>25</android.sdk.platform>

<!-- Dependency Versions -->
<junit.version>4.12</junit.version>
<robolectric.version>3.0</robolectric.version>
<android.version>6.0_r3</android.version>
<android-support.version>23.3.0</android-support.version>
<android.version>4.1.1.4</android.version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be 7.1.1_r3 when android.sdk.platform is 25

<android-support.version>25.2.0</android-support.version>
<jsr305.version>3.0.1</jsr305.version>

<!-- Plugin Versions -->
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<android-maven-plugin.version>4.4.1</android-maven-plugin.version>
<maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version>
<android-maven-plugin.version>4.4.3</android-maven-plugin.version>
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<maven-javadoc-plugin.version>2.10.3</maven-javadoc-plugin.version>
<maven-source-plugin.version>3.0.0</maven-source-plugin.version>
<jacoco-maven-plugin.version>0.7.6.201602180812</jacoco-maven-plugin.version>
<maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
</properties>

<repositories>
<repository>
<id>android-support</id>
<url>file://${env.ANDROID_HOME}/extras/android/m2repository</url>
</repository>
</repositories>

<dependencyManagement>
<dependencies>
<!-- Testing -->
Expand Down
147 changes: 83 additions & 64 deletions sample/res/layout/activity_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,78 +15,97 @@
~ limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/single"
android:onClick="onSingleClick"
android:layout_weight="1" />
android:layout_height="match_parent">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the child inside a scrollview should use wrap_content for height


<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple"
android:onClick="onMultipleClick"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/single"
android:onClick="onSingleClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple_include_own"
android:onClick="onMultipleIncludeOwnClick"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple"
android:onClick="onMultipleClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple_programmatic"
android:onClick="onMultipleProgrammaticClick"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple_include_own"
android:onClick="onMultipleIncludeOwnClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/single_fragment"
android:onClick="onSingleFragmentClick"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple_programmatic"
android:onClick="onMultipleProgrammaticClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple_fragment"
android:onClick="onMultipleFragmentClick"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/single_fragment"
android:onClick="onSingleFragmentClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple_include_own_fragment"
android:onClick="onMultipleIncludeOwnFragmentClick"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple_fragment"
android:onClick="onMultipleFragmentClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple_programmatic_fragment"
android:onClick="onMultipleProgrammaticFragmentClick"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple_include_own_fragment"
android:onClick="onMultipleIncludeOwnFragmentClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/custom_theme"
android:onClick="onCustomThemeClick"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/multiple_programmatic_fragment"
android:onClick="onMultipleProgrammaticFragmentClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/custom_theme_fragment"
android:onClick="onCustomThemeFragmentClick"
android:layout_weight="1" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/custom_theme"
android:onClick="onCustomThemeClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/custom_theme_fragment"
android:onClick="onCustomThemeFragmentClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/custom_css_style"
android:onClick="onCustomCssStyleClick"
android:layout_weight="1" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/custom_css_style_fragment"
android:onClick="onCustomCssStyleFragmentClick"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
56 changes: 56 additions & 0 deletions sample/res/values/base_html.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2017 Chaos Leong
~ Copyright 2013 Philip Schiffer
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<resources>
<string name="coustom_notices_default_style" translatable="false">
p.license {
background:grey;
}
body {
font-family: sans-serif;
overflow-wrap: break-word;
background:#616161;
}
pre {
background-color: #eeeeee;
padding: 1em;
white-space: pre-wrap;
}
</string>
<string name="coustom_notices_format_style" translatable="false">
p.license {
%1$s
}
body {
font-family: sans-serif;
overflow-wrap: break-word;
%2$s
}
pre {
%3$s
padding: 1em;
white-space: pre-wrap;
}
li {
%4$s
}
li a {
%5$s
}
</string>
</resources>
2 changes: 2 additions & 0 deletions sample/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
<string name="multiple_programmatic_fragment">Multiple programmaticly (Fragment)</string>
<string name="custom_theme">Custom theme</string>
<string name="custom_theme_fragment">Custom theme (Fragment)</string>
<string name="custom_css_style">Custom CSS Style</string>
<string name="custom_css_style_fragment">Custom CSS Style (Fragment)</string>
</resources>
Loading