mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
* AboutActivity links now open with the in-app tabbed browser. * UploadActivity license and policy links now open with the in-app tabbed browser.
This commit is contained in:
parent
af291a5fcc
commit
55113b3018
2 changed files with 55 additions and 7 deletions
|
|
@ -188,6 +188,7 @@ public class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Opens Custom Tab Activity with in-app browser for the specified URL.
|
||||||
* Launches intent for web URL
|
* Launches intent for web URL
|
||||||
* @param context
|
* @param context
|
||||||
* @param url
|
* @param url
|
||||||
|
|
@ -206,7 +207,8 @@ public class Utils {
|
||||||
builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.primaryDarkColor));
|
builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.primaryDarkColor));
|
||||||
builder.setExitAnimations(context, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
|
builder.setExitAnimations(context, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
|
||||||
CustomTabsIntent customTabsIntent = builder.build();
|
CustomTabsIntent customTabsIntent = builder.build();
|
||||||
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
// Clear previous browser tasks, so that back/exit buttons work as intended.
|
||||||
|
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
customTabsIntent.launchUrl(context, url);
|
customTabsIntent.launchUrl(context, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,11 @@ import android.support.v7.widget.CardView;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.text.style.ClickableSpan;
|
||||||
|
import android.text.style.URLSpan;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
|
@ -143,6 +146,7 @@ public class UploadActivity extends AuthenticatedActivity implements UploadView,
|
||||||
configureNavigationButtons();
|
configureNavigationButtons();
|
||||||
configureCategories();
|
configureCategories();
|
||||||
configureLicenses();
|
configureLicenses();
|
||||||
|
configurePolicy();
|
||||||
|
|
||||||
presenter.init();
|
presenter.init();
|
||||||
|
|
||||||
|
|
@ -255,13 +259,10 @@ public class UploadActivity extends AuthenticatedActivity implements UploadView,
|
||||||
@SuppressLint("StringFormatInvalid")
|
@SuppressLint("StringFormatInvalid")
|
||||||
@Override
|
@Override
|
||||||
public void updateLicenseSummary(String selectedLicense, int imageCount) {
|
public void updateLicenseSummary(String selectedLicense, int imageCount) {
|
||||||
String licenseHyperLink = "<a href='" + Utils.licenseUrlFor(selectedLicense)+"'>" +
|
String licenseHyperLink = "<a href='" + Utils.licenseUrlFor(selectedLicense) + "'>" +
|
||||||
getString(Utils.licenseNameFor(selectedLicense)) + "</a><br>";
|
getString(Utils.licenseNameFor(selectedLicense)) + "</a><br>";
|
||||||
licenseSummary.setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
licenseSummary.setText(
|
setTextViewHTML(licenseSummary, getResources().getQuantityString(R.plurals.share_license_summary, imageCount, licenseHyperLink));
|
||||||
Html.fromHtml(
|
|
||||||
getResources().getQuantityString(R.plurals.share_license_summary,
|
|
||||||
imageCount, licenseHyperLink)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -437,6 +438,47 @@ public class UploadActivity extends AuthenticatedActivity implements UploadView,
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses links from HTML string, and makes the links clickable in the specified TextView.<br>
|
||||||
|
* Uses {@link #makeLinkClickable(SpannableStringBuilder, URLSpan)}.
|
||||||
|
* @see <a href="https://stackoverflow.com/questions/12418279/android-textview-with-clickable-links-how-to-capture-clicks">Source</a>
|
||||||
|
*/
|
||||||
|
private void setTextViewHTML(TextView text, String html)
|
||||||
|
{
|
||||||
|
CharSequence sequence = Html.fromHtml(html);
|
||||||
|
SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
|
||||||
|
URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class);
|
||||||
|
for (URLSpan span : urls) {
|
||||||
|
makeLinkClickable(strBuilder, span);
|
||||||
|
}
|
||||||
|
text.setText(strBuilder);
|
||||||
|
text.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets onClick handler to launch browser for the specified URLSpan.
|
||||||
|
* @see <a href="https://stackoverflow.com/questions/12418279/android-textview-with-clickable-links-how-to-capture-clicks">Source</a>
|
||||||
|
*/
|
||||||
|
private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span)
|
||||||
|
{
|
||||||
|
int start = strBuilder.getSpanStart(span);
|
||||||
|
int end = strBuilder.getSpanEnd(span);
|
||||||
|
int flags = strBuilder.getSpanFlags(span);
|
||||||
|
ClickableSpan clickable = new ClickableSpan() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
// Handle hyperlink click
|
||||||
|
String hyperLink = span.getURL();
|
||||||
|
launchBrowser(hyperLink);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
strBuilder.setSpan(clickable, start, end, flags);
|
||||||
|
strBuilder.removeSpan(span);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void launchBrowser(String hyperLink) {
|
||||||
|
Utils.handleWebUrl(this, Uri.parse(hyperLink));
|
||||||
|
}
|
||||||
|
|
||||||
private void configureLicenses() {
|
private void configureLicenses() {
|
||||||
licenseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
licenseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -515,6 +557,10 @@ public class UploadActivity extends AuthenticatedActivity implements UploadView,
|
||||||
categoriesList.setAdapter(categoriesAdapter);
|
categoriesList.setAdapter(categoriesAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void configurePolicy() {
|
||||||
|
setTextViewHTML(licensePolicy, getString(R.string.media_upload_policy));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
private void updateCategoryList(String filter) {
|
private void updateCategoryList(String filter) {
|
||||||
List<String> imageTitleList = presenter.getImageTitleList();
|
List<String> imageTitleList = presenter.getImageTitleList();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue