Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fluttertoast
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
songyanzhi
fluttertoast
Commits
2eb3590a
Unverified
Commit
2eb3590a
authored
Jul 24, 2018
by
Karthik Ponnam
Committed by
GitHub
Jul 24, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11 from CaiJingLong/master
android toast instance, toast background color
parents
3f324bc8
aed5188b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
64 deletions
+68
-64
android/src/main/kotlin/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.kt
+68
-64
No files found.
android/src/main/kotlin/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.kt
View file @
2eb3590a
package
io.github.ponnamkarthik.toast.fluttertoast
package
io.github.ponnamkarthik.toast.fluttertoast
import
android.content.Context
import
android.content.Context
import
android.util.Log
import
android.view.Gravity
import
android.widget.Toast
import
android.graphics.Color
import
android.graphics.Color
import
android.graphics.Paint
import
android.graphics.drawable.ColorDrawable
import
android.graphics.drawable.ColorDrawable
import
android.graphics.drawable.Drawable
import
android.graphics.drawable.ShapeDrawable
import
android.graphics.drawable.shapes.RoundRectShape
import
android.view.Gravity
import
android.widget.TextView
import
android.widget.Toast
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
import
io.flutter.plugin.common.MethodChannel.Result
import
io.flutter.plugin.common.MethodChannel.Result
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.PluginRegistry.Registrar
import
io.flutter.plugin.common.PluginRegistry.Registrar
import
android.widget.TextView
import
android.graphics.Paint
import
android.graphics.drawable.ShapeDrawable
import
android.graphics.drawable.shapes.RoundRectShape
class
FluttertoastPlugin
(
context
:
Context
)
:
MethodCallHandler
{
var
ctx
:
Context
?
=
context
class
FluttertoastPlugin
(
context
:
Context
):
MethodCallHandler
{
companion
object
{
var
toast
:
Toast
?
=
null
var
ctx
:
Context
?
=
context
@JvmStatic
fun
registerWith
(
registrar
:
Registrar
):
Unit
{
companion
object
{
val
channel
=
MethodChannel
(
registrar
.
messenger
(),
"PonnamKarthik/fluttertoast"
)
@JvmStatic
channel
.
setMethodCallHandler
(
FluttertoastPlugin
(
registrar
.
context
()))
fun
registerWith
(
registrar
:
Registrar
):
Unit
{
}
val
channel
=
MethodChannel
(
registrar
.
messenger
(),
"PonnamKarthik/fluttertoast"
)
channel
.
setMethodCallHandler
(
FluttertoastPlugin
(
registrar
.
context
()))
}
}
}
var
defaultTextColor
:
Int
=
Color
.
TRANSPARENT
override
fun
onMethodCall
(
call
:
MethodCall
,
result
:
Result
):
Unit
{
override
fun
onMethodCall
(
call
:
MethodCall
,
result
:
Result
):
Unit
{
if
(
call
.
method
.
equals
(
"showToast"
))
{
if
(
call
.
method
==
"showToast"
)
{
val
msg
:
String
=
call
.
argument
(
"msg"
)
val
length
:
String
=
call
.
argument
(
"length"
)
val
gravity
:
String
=
call
.
argument
(
"gravity"
)
val
bgcolor
:
String
=
call
.
argument
(
"bgcolor"
)
val
textcolor
:
String
=
call
.
argument
(
"textcolor"
)
var
toast
:
Toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
val
msg
:
String
=
call
.
argument
(
"msg"
)
val
length
:
String
=
call
.
argument
(
"length"
)
val
gravity
:
String
=
call
.
argument
(
"gravity"
)
val
bgcolor
:
String
=
call
.
argument
(
"bgcolor"
)
val
textcolor
:
String
=
call
.
argument
(
"textcolor"
)
if
(
length
.
equals
(
"long"
))
{
val
toast
:
Toast
=
FluttertoastPlugin
.
toast
?:
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
toast
.
duration
=
Toast
.
LENGTH_LONG
FluttertoastPlugin
.
toast
=
toast
}
else
{
toast
.
setText
(
msg
)
toast
.
duration
=
Toast
.
LENGTH_SHORT
if
(
length
.
equals
(
"long"
))
{
}
toast
.
duration
=
Toast
.
LENGTH_LONG
}
else
{
toast
.
duration
=
Toast
.
LENGTH_SHORT
}
if
(
gravity
.
equals
(
"top"
))
{
when
(
gravity
)
{
toast
.
setGravity
(
Gravity
.
TOP
,
0
,
100
)
"top"
->
toast
.
setGravity
(
Gravity
.
TOP
,
0
,
100
)
}
else
if
(
gravity
.
equals
(
"center"
))
{
"center"
->
toast
.
setGravity
(
Gravity
.
CENTER
,
0
,
0
)
toast
.
setGravity
(
Gravity
.
CENTER
,
0
,
0
)
else
->
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
)
}
else
{
}
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
)
}
val
text
:
TextView
=
toast
.
view
.
findViewById
(
android
.
R
.
id
.
message
)
val
text
:
TextView
=
toast
.
view
.
findViewById
(
android
.
R
.
id
.
message
)
if
(
bgcolor
!=
"null"
)
{
if
(
defaultTextColor
==
0
)
{
defaultTextColor
=
text
.
currentTextColor
}
if
(
bgcolor
!=
"null"
)
{
try
{
try
{
val
rectShape
=
RoundRectShape
(
floatArrayOf
(
50f
,
50f
,
50f
,
50f
,
50f
,
50f
,
50f
,
50f
),
null
,
null
)
val
rectShape
=
RoundRectShape
(
floatArrayOf
(
50f
,
50f
,
50f
,
50f
,
50f
,
50f
,
50f
,
50f
),
null
,
null
)
val
shapeDrawable
=
ShapeDrawable
(
rectShape
)
val
shapeDrawable
=
ShapeDrawable
(
rectShape
)
shapeDrawable
.
paint
.
color
=
Color
.
parseColor
(
bgcolor
)
shapeDrawable
.
paint
.
color
=
Color
.
parseColor
(
bgcolor
)
shapeDrawable
.
paint
.
style
=
Paint
.
Style
.
FILL
shapeDrawable
.
paint
.
style
=
Paint
.
Style
.
FILL
shapeDrawable
.
paint
.
isAntiAlias
=
true
shapeDrawable
.
paint
.
isAntiAlias
=
true
shapeDrawable
.
paint
.
flags
=
Paint
.
ANTI_ALIAS_FLAG
shapeDrawable
.
paint
.
flags
=
Paint
.
ANTI_ALIAS_FLAG
text
.
setBackgroundDrawable
(
shapeDrawable
)
toast
.
view
.
setBackgroundDrawable
(
shapeDrawable
)
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
e
.
printStackTrace
()
}
}
else
{
text
.
setBackgroundDrawable
(
ColorDrawable
(
Color
.
TRANSPARENT
))
}
}
}
if
(
textcolor
!=
"null"
)
{
if
(
textcolor
!=
"null"
)
{
try
{
try
{
text
.
setTextColor
(
Color
.
parseColor
(
textcolor
))
text
.
setTextColor
(
Color
.
parseColor
(
textcolor
))
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
e
.
printStackTrace
()
}
}
else
{
text
.
setTextColor
(
defaultTextColor
)
}
}
}
toast
.
show
()
toast
.
show
()
result
.
success
(
"Success"
)
result
.
success
(
"Success"
)
}
else
{
}
else
{
result
.
notImplemented
()
result
.
notImplemented
()
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment