Permalink
Browse files

fixed a force close issue in the sample app

  • Loading branch information...
1 parent a53dfed commit e2a6af7630e6e7c2514fda3a52876c9f37984709 @laurencedawson committed Nov 29, 2012
Binary file not shown.
@@ -48,7 +48,7 @@ public ActiveTextView(final Context context, AttributeSet attrs) {
super(context, attrs);
setup();
}
-
+
public ActiveTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setup();
@@ -59,7 +59,7 @@ public ActiveTextView(Context context, AttributeSet attrs, int defStyle) {
private SpannableStringBuilder mSpannable;
private ActiveTextView.OnLinkClickedListener mListener;
private ActiveTextView.OnLongPressedLinkListener mLongPressedLinkListener;
-
+
private void setup(){
mSpannable = new SpannableStringBuilder();
// Set the movement method
@@ -97,9 +97,11 @@ public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event
if(mListener!=null)
mListener.onClick(mUrl);
else{
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(Uri.parse(mUrl));
- getContext().startActivity(i);
+ if(mUrl!=null){
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse(mUrl));
+ getContext().startActivity(i);
+ }
}
}
Selection.removeSelection(buffer);
@@ -32,7 +32,7 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
+
// Create a new ActiveTextView programatically
// You can also add it to a layout file by adding <com.laurencedawson.ActiveTextView />
ActiveTextView activeTextView = new ActiveTextView(this);
@@ -44,12 +44,14 @@ protected void onCreate(Bundle savedInstanceState) {
public void onClick(String url) {
// Decide what to do when a link is clicked.
// (This is useful if you want to open an in app-browser)
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(Uri.parse(url));
- startActivity(i);
+ if(url!=null){
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ i.setData(Uri.parse(url));
+ startActivity(i);
+ }
}
});
-
+
// Set a long pressed link listener (required if you want to show the additional
// options menu when links are long pressed)
activeTextView.setLongPressedLinkListener(new OnLongPressedLinkListener() {
@@ -58,7 +60,7 @@ public void onLongPressed() {
Toast.makeText(SampleActivity.this, "Long pressed", Toast.LENGTH_SHORT).show();
}
}, false);
-
+
// Set the ActiveTextView as the content view
setContentView(activeTextView);
}

0 comments on commit e2a6af7

Please sign in to comment.