Bug 725990 - Add link support to doorhangers. r=margaret

This commit is contained in:
Brian Nicholson 2012-03-06 15:08:55 -08:00
parent 2d6be22456
commit bcbd8548dc
3 changed files with 28 additions and 0 deletions

View File

@ -39,6 +39,10 @@
package org.mozilla.gecko;
import android.content.Context;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
@ -140,6 +144,28 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener {
try {
mTimeout = options.getLong("timeout");
} catch (JSONException e) { }
try {
JSONObject link = options.getJSONObject("link");
String title = mTextView.getText().toString();
String linkLabel = link.getString("label");
String linkUrl = link.getString("url");
SpannableString titleWithLink = new SpannableString(title + " " + linkLabel);
URLSpan linkSpan = new URLSpan(linkUrl) {
@Override
public void onClick(View view) {
GeckoApp.mAppContext.loadUrlInTab(this.getURL());
}
};
// prevent text outside the link from flashing when clicked
ForegroundColorSpan colorSpan = new ForegroundColorSpan(mTextView.getCurrentTextColor());
titleWithLink.setSpan(colorSpan, 0, title.length(), 0);
titleWithLink.setSpan(linkSpan, title.length() + 1, titleWithLink.length(), 0);
mTextView.setText(titleWithLink);
mTextView.setMovementMethod(LinkMovementMethod.getInstance());
} catch (JSONException e) { }
}
// This method checks with persistence and timeout options to see if

View File

@ -6,6 +6,7 @@
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimary"
android:textColorLink="@color/doorhanger_link"
android:padding="10dp"/>
<LinearLayout android:id="@+id/doorhanger_choices"

View File

@ -4,5 +4,6 @@
<color name="splash_msgfont">#ffffff</color>
<color name="splash_urlfont">#000000</color>
<color name="splash_content">#ffffff</color>
<color name="doorhanger_link">#ACC4D5</color>
</resources>