Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions styledlabel/mobile/android/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="build/.apt_generated"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/Users/ehouriga/Bluebridge/android/dev/sdk/platforms/android-14/android.jar"/>
<classpathentry kind="lib" path="/Users/ehouriga/Library/Application Support/Titanium/mobilesdk/osx/3.2.3.GA/android/titanium.jar"/>
<classpathentry kind="lib" path="/Users/ehouriga/Library/Application Support/Titanium/mobilesdk/osx/3.2.3.GA/android/kroll-common.jar"/>
<classpathentry kind="lib" path="/Users/ehouriga/Library/Application Support/Titanium/mobilesdk/osx/3.2.3.GA/android/kroll-apt.jar"/>
<classpathentry kind="lib" path="lib/tagsoup-1.2.1.jar"/>
<classpathentry kind="lib" path="/usr/android-sdk/platforms/android-8/android.jar"/>
<classpathentry kind="lib" path="/usr/android-sdk/add-ons/addon_google_apis_google_inc_8/libs/maps.jar"/>
<classpathentry kind="lib" path="/Library/Application Support/Titanium/mobilesdk/osx/2.1.3.GA/android/titanium.jar"/>
<classpathentry kind="lib" path="/Library/Application Support/Titanium/mobilesdk/osx/2.1.3.GA/android/modules/titanium-ui.jar"/>
<classpathentry kind="lib" path="/Library/Application Support/Titanium/mobilesdk/osx/2.1.3.GA/android/modules/titanium-filesystem.jar"/>
<classpathentry kind="lib" path="/Library/Application Support/Titanium/mobilesdk/osx/2.1.3.GA/android/js.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
8 changes: 0 additions & 8 deletions styledlabel/mobile/android/build.properties.example

This file was deleted.

2 changes: 1 addition & 1 deletion styledlabel/mobile/android/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
<property name="ti.module.root" location="${basedir}"/>
<property file="build.properties"/>

<import file="${titanium.platform}/../module/android/build.xml"/>
<import file="/Users/ehouriga/Library/Application Support/Titanium/mobilesdk/osx/3.2.3.GA/module/android/build.xml"/>
</project>
Binary file not shown.
4 changes: 2 additions & 2 deletions styledlabel/mobile/android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 2.0.1
version: 3.3
apiversion: 2
description: Gives you the power of HTML and CSS without the weight of a WebView.
author: Dawson Toth
Expand All @@ -15,4 +15,4 @@ name: styledlabel
moduleid: ti.styledlabel
guid: e0405808-ee07-4d00-8207-19b211dadceb
platform: android
minsdk: 2.1.3.GA
minsdk: 3.2.3.GA
79 changes: 50 additions & 29 deletions styledlabel/mobile/android/src/ti/styledlabel/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

package ti.styledlabel;

import java.util.HashMap;

import org.appcelerator.titanium.TiApplication;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiUIView;
import org.ccil.cowan.tagsoup.Parser;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiMessenger;
import org.appcelerator.kroll.common.AsyncResult;

Expand All @@ -22,6 +25,8 @@
import android.graphics.Color;
import android.text.InputType;
import android.view.Gravity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.os.Handler;
import android.os.Message;
Expand All @@ -32,18 +37,37 @@ public class Label extends TiUIView {
private String _html;
private String[] _filteredTags;
private int _filterTagsMode = -1;
private TiViewProxy pr;

public Label(TiViewProxy proxy) {
super(proxy);
TextView textView = new TextView(TiApplication.getAppCurrentActivity());
textView.setMovementMethod(new CustomLinkMovementMethod(proxy));
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
textView.setPadding(0, 0, 0, 0);
textView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
textView.setKeyListener(null);
textView.setTextColor(Color.BLACK);
textView.setFocusable(false);
setNativeView(textView);

WebView webview = new WebView(TiApplication.getAppCurrentActivity().getApplicationContext());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview.getSettings().setAllowContentAccess(true);
webview.setDrawingCacheEnabled(false);
webview.setBackgroundColor(0x00000000);
pr = proxy;
webview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if(url.startsWith("blankify://")) {
HashMap<String, String> hashMap= new HashMap<String, String>();
hashMap.put("data", url.replaceAll("blankify://", ""));
pr.fireEvent("blankify.answer.updated", hashMap);
return true;
}
else if(url.startsWith("selected://")) {
HashMap<String, String> hashMap= new HashMap<String, String>();
hashMap.put("data", url.replaceAll("selected://", ""));
pr.fireEvent("blankify.answer.selected", hashMap);
return true;
}
return false;
}
});
setNativeView(webview);
}

@Override
Expand All @@ -62,14 +86,14 @@ public void processProperties(KrollDict props) {

private static final int MSG_UPDATE_TEXT = 50000;

private final Handler handler = new Handler(TiMessenger.getMainMessenger().getLooper(), new Handler.Callback ()
private final Handler handler = new Handler(TiMessenger.getMainMessenger().getLooper(), new Handler.Callback ()
{
public boolean handleMessage(Message msg)
{
switch (msg.what) {
case MSG_UPDATE_TEXT: {
AsyncResult result = (AsyncResult) msg.obj;
handleUpdateText((Spanned) result.getArg());
handleUpdateText((String) result.getArg());
result.setResult(null);
return true;
}
Expand All @@ -78,21 +102,21 @@ public boolean handleMessage(Message msg)
}
});

private void updateText(final Spanned text)
{
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(handler.obtainMessage(MSG_UPDATE_TEXT), text);
} else {
handleUpdateText(text);
}
}
private void updateText(final String html)
{handleUpdateText(html);
// if (!TiApplication.isUIThread()) {
// TiMessenger.sendBlockingMainMessage(handler.obtainMessage(MSG_UPDATE_TEXT), html);
// } else {
// handleUpdateText(html);
// }
}

private void handleUpdateText(final Spanned text)
{
TextView textView = (TextView) getNativeView();
textView.setText(text);
textView.invalidate();
}
private void handleUpdateText(final String html){
WebView webview = (WebView) getNativeView();
webview.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);

}

public void setHtml(String html) {
_html = html;
Expand All @@ -107,11 +131,8 @@ public void setHtml(String html) {
throw new RuntimeException(e);
}

HtmlToSpannedConverter converter = new HtmlToSpannedConverter(html, new CustomImageGetter(proxy), parser);
converter.setFilteredTags(_filteredTags);
converter.setFilteredTagsMode(_filterTagsMode);

updateText(converter.convert());
updateText(_html);
}

public void setFilteredTags(String[] tags) {
Expand Down
4 changes: 4 additions & 0 deletions styledlabel/mobile/android/src/ti/styledlabel/LabelProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package ti.styledlabel;

import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiUIView;

Expand All @@ -29,9 +30,12 @@ public TiUIView createView(Activity activity) {
@Override
public boolean fireEvent(String event, Object args) {
// Suppress click events that didn't come from us (no "url" property).
Log.e("TL SL", "touch event fired");
if (event.equals("click") &&
(args instanceof HashMap) &&
!((HashMap)args).containsKey("url")) {

Log.e("TL SL", "returning false");
return false;
}
return super.fireEvent(event, args);
Expand Down
4 changes: 3 additions & 1 deletion styledlabel/mobile/ios/Classes/TiStyledlabelLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

#import "TiUIView.h"

@interface TiStyledlabelLabel : TiUIView<UIWebViewDelegate> {
@interface TiStyledlabelLabel : TiUIView<UIWebViewDelegate, UIScrollViewDelegate, UIGestureRecognizerDelegate> {
UIWebView* _web;
NSString* _html;
float _contentHeight;
// UIGestureRecognizer *singleTap;
// CGFloat og;
}

-(void)setHtml_:(NSString *)html;
Expand Down
Loading