安装APK(filePath)
function 安装APK(filePath)
local intent = Intent(Intent.ACTION_VIEW);
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
local uri = nil
if (Build.VERSION.SDK_INT >= 24) then--24是N
uri = xFileProvider.getUriForFile(activity, activity.getPackageName()..".FileProvider", File(filePath))
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
else
uri = Uri.fromFile(File(filePath))
end
intent.setDataAndType(uri, "application/vnd.android.package-archive");
activity.startActivity(intent);
end
联系QQ(qqNUM)
function 联系QQ(qqNUM)
local s = "mqqwpa://im/chat?chat_type=wpa&uin=" .. qqNUM
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(s)))
end
加QQ群
function 加QQ群(qqNUM)
local s = "mqqapi://card/show_pslcard?src_type=internal&version=1&uin=" .. qqNUM .. "&card_type=group&source=qrcode"
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(s)))
end
发送邮件(email,subject,content)
function 发送邮件(email,subject,content)
import "android.content.Intent"
i = Intent(Intent.ACTION_SEND)
i.setType("message/rfc822")
i.putExtra(Intent.EXTRA_EMAIL, {email})
i.putExtra(Intent.EXTRA_SUBJECT,subject)
i.putExtra(Intent.EXTRA_TEXT,content)
activity.startActivity(Intent.createChooser(i, "Choice"))
end
获取剪切板()
function 获取剪切板()
if(Context==nil)then
import "android.content.Context"
end
return activity.getSystemService(Context.CLIPBOARD_SERVICE).getText()
end
复制文本(a)
function 复制文本(a)
if(Context==nil)then
import "android.content.Context"
end
activity.getSystemService(Context.CLIPBOARD_SERVICE).setText(a)
end
分享链接()
function 分享链接()
分享文本(获取浏览器().url)
end
泡沫对话框
local bindClass=luajava.bindClass
local AlertDialog=bindClass("android.app.AlertDialog")
local Builder=AlertDialog.Builder
local indexBuilderPool={}
function 对话框(ctx)
local index=#indexBuilderPool+1
local dialog=AlertDialog.Builder(ctx or activity or this)
indexBuilderPool[index]=dialog
local _M
_M= {
["设置标题"]=function(...) dialog.setTitle(...) return _M end;
["设置消息"]=function(...) dialog.setMessage(...) return _M end;
["设置积极按钮"]=function(...)
local args={...}
if (#args==1) then
dialog.setPositiveButton(args[1],nil)
else
dialog.setPositiveButton(...)
end
return _M end;
["设置消极按钮"]=function(...)
local args={...}
if (#args==1) then
dialog.setNegativeButton(args[1],nil)
else
dialog.setNegativeButton(...)
end
return _M end;
["设置中立按钮"]=function(...)
local args={...}
if (#args==1) then
dialog.setNeutralButton(args[1],nil)
else
dialog.setNeutralButton(...)
end
return _M end;
["显示"]=function(...)
dialog=dialog.show(...)
indexBuilderPool[index]=dialog
return _M end;
["创建"]=function(...)
dialog=dialog.create(...)
indexBuilderPool[index]=dialog
return _M end;
["取消"]=function(...) dialog.cancel(...) return _M end;
["关闭"]=function(...)
dialog.dismiss(...)
luajava.clear(indexBuilderPool[index])
indexBuilderPool[index]=true
return _M end;
["dismiss"]=function(...)
dialog.dismiss(...)
luajava.clear(indexBuilderPool[index])
indexBuilderPool[index]=true
return _M end;
["隐藏"]=function(...) dialog.hide(...) return _M end;
["设置按钮"]=function(...) dialog.setButton(...) return _M end;
["设置按钮1"]=function(...) dialog.setButton(...) return _M end;
["设置按钮2"]=function(...) dialog.setButton(...) return _M end;
["设置按钮3"]=function(...) dialog.setButton(...) return _M end;
["设置视图"]=function(...) dialog.setView(...) return _M end;
["设置图标"]=function(...) dialog.setIcon(...) return _M end;
["设置是否可以取消"]=function(...) dialog.setCancelable(...) return _M end;
["设置项目"]=function(...) dialog.setItems(...) return _M end;
["设置多选项目"]=function(...) dialog.setMultiChoiceItems(...) return _M end;
["设置取消监听器"]=function(...) dialog.setOnCancelListener(...) return _M end;
["设置关闭监听器"]=function(...) dialog.setOnDismissListener(...) return _M end;
["设置按键监听器"]=function(...) dialog.setOnKeyListener(...) return _M end;
["设置项目选择监听器"]=function(...) dialog.setOnItemSelectedListener(...) return _M end;
["启用测量时设置回收"]=function(...) dialog.setRecycleOnMeasureEnabled(...) return _M end;
["设置简单选择项目"]=function(...) dialog.setSingleChoiceItems(...) return _M end;
["设置自定义标题"]=function(...) dialog.setCustomTitle(...) return _M end;
["设置适配器"]=function(...) dialog.setAdapter(...) return _M end;
["设置光标"]=function(...) dialog.setCursor(...) return _M end;
["设置图标属性"]=function(...) dialog.setIconAttribute(...) return _M end;
["设置背景强制反向"]=function(...) dialog.setInverseBackgroundForced(...) return _M end;
["获得按钮"]=function(...) dialog.getButton(...) return _M end;
["获得列表视图"]=function(...) dialog.getListView(...) return _M end;
["当键按下时"]=function(...) dialog.onKeyDown(...) return _M end;
["当键抬起时"]=function(...) dialog.onKeyUp(...) return _M end;
["添加内容视图"]=function(...) dialog.addContentView(...) return _M end;
["设置内容视图"]=function(...) dialog.setContentView(...) return _M end;
["关闭选项菜单"]=function(...) dialog.closeOptionsMenu(...) return _M end;
["是否正在显示"]=function(...) dialog.isShowing(...) return _M end;
["获得窗口"]=function(...) dialog.getWindow(...) return _M end;
["设置能否在点击外部后取消"]=function(...) dialog.setCanceledOnTouchOutside(...) return _M end;
["设置取消消息"]=function(...) dialog.setCancelMessage(...) return _M end;
["getThisDialogObject"]=function()return dialog end,
["获得对话框实例"]=function()return dialog end,
}
local transC2E={
["标题"]="Title",
["消息"]="Message",
}
setmetatable(_M,{
["__newindex"]=function(_M,k,v)
k=transC2E[k] or k
dialog[k]=v
end,
["__index"]=function(_M,method,...)
if method=="标题" or method=="Title" or method=="title" or method=="getTitle" then
return dialog.findViewById(android.R.id.icon).parent.getChildAt(1).text
end
if method=="消息" or method=="Message" or method=="message" or method=="getMessage" then
return dialog.findViewById(android.R.id.message).text
end
_M[method]=function(...)
local a=dialog[method]
if type(a)=="function" then
a(...)
else
return a
end
return _M
end
return _M[method]
end
})
return _M
end
function 泡沫对话框(ctxOrnum,num)
if num==nil then
num=ctxOrnum
ctxOrnum=nil
end
local token="|"..tostring(tointeger(num))
local OneTimeDialogMark=activity.getSharedData("ONE-TIME-DIALOG-MARK")
if OneTimeDialogMark==nil then
OneTimeDialogMark="|"
activity.setSharedData("ONE-TIME-DIALOG-MARK",OneTimeDialogMark)
end
if OneTimeDialogMark:find(token,0,true) then
local _M={}
setmetatable(_M,{
["__index"]=function(_M,method,...)
_M[method]=function(...) return _M end
return _M[method]
end
})
return _M
end
OneTimeDialogMark=OneTimeDialogMark..token
local basedialog=对话框(ctxOrnum)
local func1=basedialog["显示"]
local func2=basedialog["show"]
basedialog["显示"]=function(...)
func1(...)
activity.setSharedData("ONE-TIME-DIALOG-MARK",OneTimeDialogMark)
end
basedialog["show"]=function(...)
func2(...)
activity.setSharedData("ONE-TIME-DIALOG-MARK",OneTimeDialogMark)
end
return basedialog
end
本文由【产品经理不是经理】gzh同步发布,欢迎关注
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
我使用Ember作为我的前端和GrapeAPI来为我的API提供服务。前端发送类似:{"service"=>{"name"=>"Name","duration"=>"30","user"=>nil,"organization"=>"org","category"=>nil,"description"=>"description","disabled"=>true,"color"=>nil,"availabilities"=>[{"day"=>"Saturday","enabled"=>false,"timeSlots"=>[{"startAt"=>"09:00AM","endAt"=>
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
我正在阅读一本关于Ruby的书,作者在编写类初始化定义时使用的形式与他在本书前几节中使用的形式略有不同。它看起来像这样:classTicketattr_accessor:venue,:datedefinitialize(venue,date)self.venue=venueself.date=dateendend在本书的前几节中,它的定义如下:classTicketattr_accessor:venue,:datedefinitialize(venue,date)@venue=venue@date=dateendend在第一个示例中使用setter方法与在第二个示例中使用实例变量之间是
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些