Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 6694ace

Browse filesBrowse files
committed
[[ AndroidUtils ]] Add android utility library
Add StringToAndroidColor handler to android utility library
1 parent 141e7f4 commit 6694ace
Copy full SHA for 6694ace

File tree

Expand file treeCollapse file tree

5 files changed

+94
-44
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+94
-44
lines changed

‎extensions/extensions.gyp

Copy file name to clipboardExpand all lines: extensions/extensions.gyp
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
'sources':
148148
[
149149
'modules/widget-utils/widget-utils.lcb',
150+
'modules/android-utils/android-utils.lcb',
150151
'modules/scriptitems/scriptitems.lcb',
151152

152153
'libraries/androidbgaudio/androidbgaudio.lcb',
+67Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright (C) 2018 LiveCode Ltd.
3+
4+
This file is part of LiveCode.
5+
6+
LiveCode is free software; you can redistribute it and/or modify it under
7+
the terms of the GNU General Public License v3 as published by the Free
8+
Software Foundation.
9+
10+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
11+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
17+
18+
/**
19+
A library of utility handlers for functions commonly needed by Android widgets.
20+
*/
21+
22+
module com.livecode.library.androidutils
23+
24+
use com.livecode.foreign
25+
use com.livecode.java
26+
use com.livecode.canvas
27+
use com.livecode.library.widgetutils
28+
29+
metadata version is "1.0.0"
30+
metadata author is "LiveCode"
31+
metadata title is "Android Utilities"
32+
33+
private handler ColorComponentToInt(in pComponent as Real) returns Integer
34+
multiply pComponent by 255
35+
round pComponent
36+
return pComponent
37+
end handler
38+
39+
__safe foreign handler _JNI_GetColorFromARGB(in pA as JInt, in pR as JInt, in pG as JInt, in pB as JInt) returns JInt \
40+
binds to "java:android.graphics.Color>argb(IIII)I!static"
41+
42+
/**
43+
Summary: Convert a color string to an integer for Android
44+
45+
Parameters:
46+
pString: The color string
47+
48+
Description:
49+
Use the <StringToAndroidColor> handler to convert a string representing
50+
a color to an integer that can be used with Android color APIs.
51+
*/
52+
public handler StringToAndroidColor(in pString as String) returns Integer
53+
variable tColor as Color
54+
put stringToColor(pString) into tColor
55+
56+
variable tA as Integer
57+
variable tR as Integer
58+
variable tG as Integer
59+
variable tB as Integer
60+
put ColorComponentToInt(the alpha of tColor) into tA
61+
put ColorComponentToInt(the red of tColor) into tR
62+
put ColorComponentToInt(the green of tColor) into tG
63+
put ColorComponentToInt(the blue of tColor) into tB
64+
65+
return _JNI_GetColorFromARGB(tA,tR,tG,tB)
66+
end handler
67+
end module
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Android Utility Module
2+
3+
A new android utility module has been added. It currently
4+
contains one handler, StringToAndroidColor, which converts
5+
a string representing a color (optionally with alpha component)
6+
to an Android Color object.

‎extensions/widgets/androidbutton/androidbutton.lcb

Copy file name to clipboardExpand all lines: extensions/widgets/androidbutton/androidbutton.lcb
+4-19Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use com.livecode.widget
4242
use com.livecode.canvas
4343
use com.livecode.engine
4444
use com.livecode.library.widgetutils
45+
use com.livecode.library.androidutils
4546

4647
metadata version is "1.0.0"
4748
metadata author is "LiveCode"
@@ -114,8 +115,7 @@ __safe foreign handler _JNI_SetTextViewText(in pView as JObject, in pValue as JS
114115
binds to "java:android.widget.TextView>setText(Ljava/lang/CharSequence;)V?ui"
115116
__safe foreign handler _JNI_SetTextViewTextColor(in pView as JObject, in pValue as JInt) returns nothing \
116117
binds to "java:android.widget.TextView>setTextColor(I)V?ui"
117-
__safe foreign handler _JNI_GetColorFromARGB(in pA as JInt, in pR as JInt, in pG as JInt, in pB as JInt) returns JInt \
118-
binds to "java:android.graphics.Color>argb(IIII)I!static"
118+
119119
__safe foreign handler _JNI_SetTextViewEnabled(in pView as JObject, in pValue as JBoolean) returns nothing \
120120
binds to "java:android.view.View>setEnabled(Z)V?ui"
121121

@@ -261,23 +261,8 @@ private handler ColorComponentToInt(in pComponent as Real) returns Integer
261261
return pComponent
262262
end handler
263263

264-
private handler SetStringAndroidColor(in pString as String)
265-
variable tColor as Color
266-
put stringToColor(pString) into tColor
267-
268-
variable tA as Integer
269-
variable tR as Integer
270-
variable tG as Integer
271-
variable tB as Integer
272-
put ColorComponentToInt(the alpha of tColor) into tA
273-
put ColorComponentToInt(the red of tColor) into tR
274-
put ColorComponentToInt(the green of tColor) into tG
275-
put ColorComponentToInt(the blue of tColor) into tB
276-
277-
variable tColorInt as Integer
278-
put _JNI_GetColorFromARGB(tA,tR,tG,tB) into tColorInt
279-
280-
_JNI_SetTextViewTextColor(mButton, tColorInt)
264+
private handler SetStringAndroidColor(in pString as String)
265+
_JNI_SetTextViewTextColor(mButton, StringToAndroidColor(pString))
281266
end handler
282267

283268
end widget

‎extensions/widgets/androidfield/androidfield.lcb

Copy file name to clipboardExpand all lines: extensions/widgets/androidfield/androidfield.lcb
+16-25Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ use com.livecode.widget
121121
use com.livecode.canvas
122122
use com.livecode.engine
123123
use com.livecode.library.widgetutils
124+
use com.livecode.library.androidutils
124125
use com.livecode.library.scriptitems
125126

126127
metadata version is "1.0.0"
@@ -705,6 +706,7 @@ end handler
705706
handler SetParentProperties()
706707
SetEnabled(my enabled)
707708
SetTextSize(the size of my font)
709+
SetTypeFace(my font)
708710
end handler
709711

710712
// Constants pulled from the android.view.inputmethod.InputMethodManager class
@@ -916,6 +918,8 @@ __safe foreign handler _JNI_TextView_setTextColor(in pView as JObject, in pValue
916918
binds to "java:android.widget.TextView>setTextColor(I)V?ui"
917919
__safe foreign handler _JNI_TextView_setTextSize(in pObj as JObject, in pParam_unit as JInt, in pParam_size as JFloat) returns nothing \
918920
binds to "java:android.widget.TextView>setTextSize(IF)V?ui"
921+
__safe foreign handler _JNI_TextView_setTypeface(in pView as JObject, in pValue as JObject) returns nothing \
922+
binds to "java:android.widget.TextView>setTypeface(Landroid/graphics/Typeface;)V?ui"
919923
__safe foreign handler _JNI_TextView_setTransformationMethod(in pObj as JObject, in pParam_mthd as optional JObject) returns nothing \
920924
binds to "java:android.widget.TextView>setTransformationMethod(Landroid/text/method/TransformationMethod;)V?ui"
921925

@@ -1042,6 +1046,12 @@ handler TextView_setTextSize(in pObj as JObject, in pParam_unit as Number, in pP
10421046
_JNI_TextView_setTextSize(pObj, pParam_unit, pParam_size)
10431047
end handler
10441048

1049+
handler TextView_setTypeface(in pObj as JObject, in pFont as Font) returns nothing
1050+
variable tTypeface as JObject
1051+
put CanvasFontToTypeFace(pFont) into tTypeface
1052+
_JNI_TextView_setTypeface(pObj, tTypeface)
1053+
end handler
1054+
10451055
handler TextView_setTransformationMethod(in pObj as JObject, in pParam_mthd as optional JObject) returns nothing
10461056
_JNI_TextView_setTransformationMethod(pObj, pParam_mthd)
10471057
end handler
@@ -1356,31 +1366,8 @@ public handler GetText() returns String
13561366
return mText
13571367
end handler
13581368

1359-
__safe foreign handler _JNI_GetColorFromARGB(in pA as JInt, in pR as JInt, in pG as JInt, in pB as JInt) returns JInt \
1360-
binds to "java:android.graphics.Color>argb(IIII)I!static?ui"
1361-
private handler SetStringAndroidColor(in pString as String)
1362-
variable tColor as Color
1363-
put stringToColor(pString) into tColor
1364-
1365-
variable tA as Integer
1366-
variable tR as Integer
1367-
variable tG as Integer
1368-
variable tB as Integer
1369-
put ColorComponentToInt(the alpha of tColor) into tA
1370-
put ColorComponentToInt(the red of tColor) into tR
1371-
put ColorComponentToInt(the green of tColor) into tG
1372-
put ColorComponentToInt(the blue of tColor) into tB
1373-
1374-
variable tColorInt as Integer
1375-
put _JNI_GetColorFromARGB(tA,tR,tG,tB) into tColorInt
1376-
1377-
_JNI_TextView_setTextColor(mNativeObj, tColorInt)
1378-
end handler
1379-
1380-
private handler ColorComponentToInt(in pComponent as Real) returns Integer
1381-
multiply pComponent by 255
1382-
round pComponent
1383-
return pComponent
1369+
private handler SetStringAndroidColor(in pString as String)
1370+
_JNI_TextView_setTextColor(mNativeObj, StringToAndroidColor(pString))
13841371
end handler
13851372

13861373
public handler SetTextColor(in pColor as String)
@@ -1402,6 +1389,10 @@ handler SetTextSize(in pSize as Integer)
14021389
TextView_setTextSize(mNativeObj, COMPLEX_UNIT_DIP, pSize)
14031390
end handler
14041391

1392+
handler SetTypeface(in pFont as Font)
1393+
TextView_setTypeface(mNativeObj, pFont)
1394+
end handler
1395+
14051396
__safe foreign handler _JNI_GetResources(in pContext as JObject) returns JObject \
14061397
binds to "java:android.content.Context>getResources()Landroid/content/res/Resources;"
14071398
__safe foreign handler _JNI_GetDisplayMetrics(in pResources as JObject) returns JObject \

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.