@@ -0,0 +1,2118 @@
+package com.spiddekauga.android.ui;%0A%0Aimport android.support.annotation.StringRes;%0Aimport android.text.SpannableString;%0Aimport android.text.Spanned;%0Aimport android.text.style.ClickableSpan;%0A%0Aimport com.spiddekauga.android.AppActivity;%0Aimport com.spiddekauga.android.BuildConfig;%0Aimport com.spiddekauga.utils.Strings;%0A%0A/**%0A * Creates a clickable SpannableString from a resource. Automatically determines where the clickable%0A * part from the resource. The resource should contain the clickable part between %7C%7Cclickable text%7C%7C%0A * i.e. between the pipes.%0A */%0Apublic class SpanStringHelper %7B%0Aprivate static final String DELIMITER = %22%5C%5C%7C%5C%5C%7C%22;%0A%0A/**%0A * Creates a clickable SpannableString from a resource. Automatically determines where the clickable%0A * part from the resource. The resource should contain the clickable part between %7C%7Cclickable text%7C%7C%0A * i.e. between the pipes.%0A * @param stringId the string to create the spannable text from%0A * @param clickableListeners array of all clickable spans listeners, should match the number of%0A * clickable lists%0A */%0Apublic static SpannableString createSpannableString(@StringRes int stringId, ClickableSpan... clickableListeners) %7B%0A%09String text = AppActivity.getActivity().getResources().getString(stringId);%0A%09String%5B%5D spans = text.split(DELIMITER, -1);%0A%09%0A%09// Check so listeners matches the spans%0A%09// It should be clickableListener * 2 + 1%0A%09if (BuildConfig.DEBUG) %7B%0A%09%09if (spans.length != (clickableListeners.length * 2) + 1) %7B%0A%09%09%09throw new IllegalArgumentException(%22Text %5C%22%22 + text + %22%5C%22 does not contain %22 + clickableListeners.length + %22 clickable parts%22);%0A%09%09%7D%0A%09%7D%0A%09%0A%09String displayText = Strings.merge(spans);%0A%09SpannableString spannableString = new SpannableString(displayText);%0A%0A%09// Bind each clickable state%0A%09int totalLength = 0;%0A%09for (int i = 0; i %3C spans.length - 1; i += 2) %7B%0A%09%09int beginIndex = totalLength + spans%5Bi%5D.length();%0A%09%09int length = spans%5Bi + 1%5D.length();%0A%09%09int endIndex = beginIndex + length;%0A%0A%09%09spannableString.setSpan(clickableListeners%5Bi / 2%5D, beginIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);%0A%0A%09%09totalLength = endIndex;%0A%09%7D%0A%0A%09return spannableString;%0A%7D%0A%7D%0A

Add helper for creating SpannedString