|
|
@@ -2,8 +2,20 @@ package com.usai.redant.apexdrivers.update;
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.telephony.PhoneNumberUtils;
|
|
|
import android.text.Editable;
|
|
|
+import android.text.Spannable;
|
|
|
+import android.text.SpannableString;
|
|
|
+import android.text.Spanned;
|
|
|
+import android.text.TextPaint;
|
|
|
import android.text.TextWatcher;
|
|
|
+import android.text.method.LinkMovementMethod;
|
|
|
+import android.text.style.ClickableSpan;
|
|
|
+import android.text.style.ForegroundColorSpan;
|
|
|
+import android.text.style.URLSpan;
|
|
|
+import android.text.util.Linkify;
|
|
|
+import android.util.Log;
|
|
|
+import android.util.Patterns;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
@@ -15,6 +27,9 @@ import android.widget.ImageButton;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+
|
|
|
+import com.google.i18n.phonenumbers.PhoneNumberMatch;
|
|
|
+import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
|
|
import com.usai.redant.apexdrivers.R;
|
|
|
import com.usai.redant.apexdrivers.signature.SignatureActivity;
|
|
|
import com.usai.redant.apexdrivers.update.model.UpdateBaseModel;
|
|
|
@@ -27,6 +42,9 @@ import com.usai.redant.apexdrivers.update.model.UpdateSignatureModel;
|
|
|
|
|
|
import java.lang.ref.WeakReference;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.Locale;
|
|
|
|
|
|
import static android.text.util.Linkify.PHONE_NUMBERS;
|
|
|
|
|
|
@@ -272,15 +290,127 @@ public class UpdateAdapter extends BaseExpandableListAdapter {
|
|
|
|
|
|
public void bindModel(UpdateLabelModel model) {
|
|
|
|
|
|
- if (model != null && model.detectTel) {
|
|
|
- valueTv.setAutoLinkMask(PHONE_NUMBERS);
|
|
|
- } else {
|
|
|
- valueTv.setAutoLinkMask(0);
|
|
|
+ if (model == null) {
|
|
|
+ titleTv.setText(null);
|
|
|
+ valueTv.setText(null);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
+// if (model != null && model.detectTel) {
|
|
|
+// valueTv.setAutoLinkMask(PHONE_NUMBERS); // 在部分机型不起作用
|
|
|
+// } else {
|
|
|
+// valueTv.setAutoLinkMask(0);
|
|
|
+// }
|
|
|
+
|
|
|
titleTv.setText(model.title);
|
|
|
valueTv.setText(model.value);
|
|
|
+ valueTv.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
+
|
|
|
+ if (model.detectTel) {
|
|
|
+
|
|
|
+ // 部分机型上解析不一样。clickable不一样
|
|
|
+ // implementation 'com.googlecode.libphonenumber:libphonenumber:7.0.4'
|
|
|
+// Spannable text = new SpannableString(model.value);
|
|
|
+//
|
|
|
+// ArrayList<LinkSpec> links = new ArrayList<LinkSpec>();
|
|
|
+//
|
|
|
+// gatherTelLinks(links, text);
|
|
|
+//
|
|
|
+// pruneOverlaps(links);
|
|
|
+//
|
|
|
+// for (LinkSpec link: links) {
|
|
|
+// applyLink(link.url, link.start, link.end, text);
|
|
|
+// }
|
|
|
+//
|
|
|
+// valueTv.setText(text);
|
|
|
+
|
|
|
+ // 暂时看起来clickable一致
|
|
|
+ valueTv.setText(model.value);
|
|
|
+ Linkify.addLinks(valueTv, Patterns.PHONE,"tel:",Linkify.sPhoneNumberMatchFilter,Linkify.sPhoneNumberTransformFilter);
|
|
|
+ valueTv.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
|
|
+ } else {
|
|
|
+ valueTv.setText(model.value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ class LinkSpec {
|
|
|
+ String url;
|
|
|
+ int start;
|
|
|
+ int end;
|
|
|
+ }
|
|
|
+
|
|
|
+ private final void gatherTelLinks(ArrayList<LinkSpec> links, Spannable s) {
|
|
|
+ PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
|
|
|
+ Iterable<PhoneNumberMatch> matches = phoneUtil.findNumbers(s.toString(),
|
|
|
+ Locale.getDefault().getCountry(), PhoneNumberUtil.Leniency.POSSIBLE, Long.MAX_VALUE);
|
|
|
+ for (PhoneNumberMatch match : matches) {
|
|
|
+ LinkSpec spec = new LinkSpec();
|
|
|
+ spec.url = "tel:" + PhoneNumberUtils.normalizeNumber(match.rawString());
|
|
|
+ spec.start = match.start();
|
|
|
+ spec.end = match.end();
|
|
|
+ links.add(spec);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private final void applyLink(String url, int start, int end, Spannable text) {
|
|
|
+ URLSpan span = new URLSpan(url);
|
|
|
+
|
|
|
+ text.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
+ }
|
|
|
+
|
|
|
+ private final void pruneOverlaps(ArrayList<LinkSpec> links) {
|
|
|
+ Comparator<LinkSpec> c = new Comparator<LinkSpec>() {
|
|
|
+ public final int compare(LinkSpec a, LinkSpec b) {
|
|
|
+ if (a.start < b.start) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (a.start > b.start) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (a.end < b.end) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (a.end > b.end) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ Collections.sort(links, c);
|
|
|
+
|
|
|
+ int len = links.size();
|
|
|
+ int i = 0;
|
|
|
+
|
|
|
+ while (i < len - 1) {
|
|
|
+ LinkSpec a = links.get(i);
|
|
|
+ LinkSpec b = links.get(i + 1);
|
|
|
+ int remove = -1;
|
|
|
+
|
|
|
+ if ((a.start <= b.start) && (a.end > b.start)) {
|
|
|
+ if (b.end <= a.end) {
|
|
|
+ remove = i + 1;
|
|
|
+ } else if ((a.end - a.start) > (b.end - b.start)) {
|
|
|
+ remove = i + 1;
|
|
|
+ } else if ((a.end - a.start) < (b.end - b.start)) {
|
|
|
+ remove = i;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (remove != -1) {
|
|
|
+ links.remove(remove);
|
|
|
+ len--;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ i++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -566,14 +696,6 @@ public class UpdateAdapter extends BaseExpandableListAdapter {
|
|
|
dateBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- view.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
-
|
|
|
if (weakDate != null && weakDate.get() != null && mDelegate != null) {
|
|
|
mDelegate.get().dateClick(weakDate.get());
|
|
|
}
|