mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Merge pull request #500 from veyndan/htmltextview
Define a custom TextView that displays HTML
This commit is contained in:
commit
052d0c9c8e
3 changed files with 25 additions and 29 deletions
|
|
@ -1,10 +1,6 @@
|
||||||
package fr.free.nrw.commons;
|
package fr.free.nrw.commons;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Html;
|
|
||||||
import android.text.method.LinkMovementMethod;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import fr.free.nrw.commons.theme.BaseActivity;
|
import fr.free.nrw.commons.theme.BaseActivity;
|
||||||
|
|
@ -14,11 +10,7 @@ import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class AboutActivity extends BaseActivity {
|
public class AboutActivity extends BaseActivity {
|
||||||
@BindView(R.id.about_version) TextView versionText;
|
@BindView(R.id.about_version) TextView versionText;
|
||||||
@BindView(R.id.about_license) TextView licenseText;
|
|
||||||
@BindView(R.id.about_improve) TextView improveText;
|
|
||||||
@BindView(R.id.about_privacy_policy) TextView privacyPolicyText;
|
|
||||||
@BindView(R.id.about_uploads_to) TextView uploadsToText;
|
@BindView(R.id.about_uploads_to) TextView uploadsToText;
|
||||||
@BindView(R.id.about_credits) TextView creditsText;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
@ -29,22 +21,5 @@ public class AboutActivity extends BaseActivity {
|
||||||
|
|
||||||
uploadsToText.setText(CommonsApplication.EVENTLOG_WIKI);
|
uploadsToText.setText(CommonsApplication.EVENTLOG_WIKI);
|
||||||
versionText.setText(BuildConfig.VERSION_NAME);
|
versionText.setText(BuildConfig.VERSION_NAME);
|
||||||
|
|
||||||
// We can't use formatted strings directly because it breaks with
|
|
||||||
// our localization tools. Grab an HTML string and turn it into
|
|
||||||
// a formatted string.
|
|
||||||
fixFormatting(licenseText, R.string.about_license);
|
|
||||||
fixFormatting(improveText, R.string.about_improve);
|
|
||||||
fixFormatting(privacyPolicyText, R.string.about_privacy_policy);
|
|
||||||
fixFormatting(creditsText, R.string.about_credits);
|
|
||||||
|
|
||||||
licenseText.setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
improveText.setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
privacyPolicyText.setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
creditsText.setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fixFormatting(TextView textView, int resource) {
|
|
||||||
textView.setText(Html.fromHtml(getResources().getString(resource)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package fr.free.nrw.commons.ui.widget;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.AppCompatTextView;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An {@link AppCompatTextView} which formats the text to HTML displayable text and makes any
|
||||||
|
* links clickable.
|
||||||
|
*/
|
||||||
|
public class HtmlTextView extends AppCompatTextView {
|
||||||
|
|
||||||
|
public HtmlTextView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
|
||||||
|
setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
setText(Html.fromHtml(getText().toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<fr.free.nrw.commons.ui.widget.HtmlTextView
|
||||||
android:id="@+id/about_license"
|
android:id="@+id/about_license"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
android:text="@string/about_license"
|
android:text="@string/about_license"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<fr.free.nrw.commons.ui.widget.HtmlTextView
|
||||||
android:id="@+id/about_improve"
|
android:id="@+id/about_improve"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
@ -47,7 +47,7 @@
|
||||||
android:text="@string/about_improve"
|
android:text="@string/about_improve"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<fr.free.nrw.commons.ui.widget.HtmlTextView
|
||||||
android:id="@+id/about_privacy_policy"
|
android:id="@+id/about_privacy_policy"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
@ -57,7 +57,7 @@
|
||||||
android:text="@string/about_privacy_policy"
|
android:text="@string/about_privacy_policy"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<fr.free.nrw.commons.ui.widget.HtmlTextView
|
||||||
android:id="@+id/about_credits"
|
android:id="@+id/about_credits"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue