mirror of
https://github.com/TrianguloY/UrlChecker.git
synced 2024-09-19 20:02:16 +02:00
bold host & italic query+fragment
This commit is contained in:
parent
94eabe486e
commit
4b25b521bc
@ -1,12 +1,19 @@
|
|||||||
package com.trianguloy.urlchecker.modules.list;
|
package com.trianguloy.urlchecker.modules.list;
|
||||||
|
|
||||||
|
import static android.graphics.Typeface.BOLD;
|
||||||
|
import static android.graphics.Typeface.ITALIC;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
import android.text.Spannable;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.style.StyleSpan;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.trianguloy.urlchecker.BuildConfig;
|
||||||
import com.trianguloy.urlchecker.R;
|
import com.trianguloy.urlchecker.R;
|
||||||
import com.trianguloy.urlchecker.activities.ModulesActivity;
|
import com.trianguloy.urlchecker.activities.ModulesActivity;
|
||||||
import com.trianguloy.urlchecker.dialogs.MainDialog;
|
import com.trianguloy.urlchecker.dialogs.MainDialog;
|
||||||
@ -100,7 +107,7 @@ class TextInputDialog extends AModuleDialog {
|
|||||||
public void onDisplayUrl(UrlData urlData) {
|
public void onDisplayUrl(UrlData urlData) {
|
||||||
// setText fires the afterTextChanged listener, so we need to skip it
|
// setText fires the afterTextChanged listener, so we need to skip it
|
||||||
skipUpdate = true;
|
skipUpdate = true;
|
||||||
txt_url.setText(urlData.url);
|
txt_url.setText(getSpannableUriText(urlData.url));
|
||||||
edtxt_url.setText(urlData.url);
|
edtxt_url.setText(urlData.url);
|
||||||
txt_url.setVisibility(View.VISIBLE);
|
txt_url.setVisibility(View.VISIBLE);
|
||||||
edtxt_url.setVisibility(View.GONE);
|
edtxt_url.setVisibility(View.GONE);
|
||||||
@ -109,4 +116,38 @@ class TextInputDialog extends AModuleDialog {
|
|||||||
skipUpdate = false;
|
skipUpdate = false;
|
||||||
doubleEdit.reset(); // next user update, even if immediately after, will be considered new
|
doubleEdit.reset(); // next user update, even if immediately after, will be considered new
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CharSequence getSpannableUriText(String rawUri) {
|
||||||
|
var str = new SpannableStringBuilder(rawUri);
|
||||||
|
|
||||||
|
// bold host
|
||||||
|
try {
|
||||||
|
var start = rawUri.indexOf("://");
|
||||||
|
if (start != -1) {
|
||||||
|
start += 3;
|
||||||
|
var end = rawUri.indexOf("/", start);
|
||||||
|
|
||||||
|
var userinfo = rawUri.indexOf("@", start);
|
||||||
|
if (userinfo != -1 && userinfo < end) start = userinfo + 1;
|
||||||
|
|
||||||
|
var port = rawUri.lastIndexOf(":", end);
|
||||||
|
if (port != -1 && port > start) end = port;
|
||||||
|
|
||||||
|
str.setSpan(new StyleSpan(BOLD), start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (BuildConfig.DEBUG) e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// italic query+fragment
|
||||||
|
try {
|
||||||
|
var start = rawUri.indexOf("?");
|
||||||
|
if (start == -1) start = rawUri.indexOf("#");
|
||||||
|
if (start != -1) str.setSpan(new StyleSpan(ITALIC), start, rawUri.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (BuildConfig.DEBUG) e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user