⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 script.hcl

📁 Hecl编程语言是一个高层次的脚本语言的Java实现。其用意是要小
💻 HCL
📖 第 1 页 / 共 2 页
字号:
## script.hcl - this is a series of Hecl/Android examples## demonstrating various parts of the API.# Hash table containing a mapping from titles like 'Web View' to proc# names like WebViewset titles_names {}# main --##	The initial, main screen.proc main {} {    global context    global procname    set procname main    set layout [linearlayout -new $context]    $layout setorientation VERTICAL    set layoutparams [linearlayoutparams -new {FILL_PARENT WRAP_CONTENT}]    set tv [textview -new $context -text {Welcome to Hecl on Android. This is a short tour of some of the functionality that can be scripted in Hecl.} -layoutparams $layoutparams]    $layout addview $tv    set lview [basiclist $context [list "Introduction" "Simple Widgets" "Web View" "Date Picker" \				       "Time Picker" "Progress Dialog" "Spinner" \				       "Hecl Editor" "Hecl Server" \				       "Contacts" "Task List" \				       "Send GTalk Message"] \		   -layoutparams $layoutparams]    $lview requestfocus    $layout addview $lview    set callback [callback -new [list [list SelectDemo]]]    $lview setonitemclicklistener $callback    [activity] setcontentview $layout    MenuSetup}# MenuSetup --##	Set up the menus so that it's possible to see the source code#	for the current widget demo/proc.proc MenuSetup {} {    # Used to set up a callback for when the menu is requested by the    # user, and it's necessary to set it up.    proc MenuCallBack {menu} {	$menu add 0 0 "View Source"    }    [activity] -field onCreateOptionsMenuCallBack MenuCallBack    # Sets up the actual callback code for when a menu item is    # selected.    proc OptionsSelected {menuitem} {	viewCode    }    [activity] -field onOptionsItemSelectedCallBack OptionsSelected}# This is used everywhere, so making it a global is no big deal.set context [activity]# Start things running.main# CreateActivity --##	CreateActivity and RunActivityproc CreateActivity {name title code} {    global titles_names    hset $titles_names $title $name    set setup "\[activity\] settitle"    append $setup " \"$title\" \n"    append $setup "\n"    append $setup "MenuSetup\n"    append $setup "global procname\n"    append $setup "set procname $name\n"    append $setup $code    proc $name {} $setup}CreateActivity Introduction "Introduction" {    set textsize 20.0    set context [activity]    set layoutparams [linearlayoutparams -new {FILL_PARENT WRAP_CONTENT}]    set scroll [scrollview -new $context -layoutparams $layoutparams]    set layout [linearlayout -new $context -layoutparams $layoutparams]    $layout setorientation VERTICAL    $scroll addview $layout    [activity] setcontentview $scroll    $layout addview [textview -new $context \			   -text "Hello, and welcome to Hecl on Android.  This application gives you a brief overview of some of the things the Hecl scripting language is capable of on Android.  And of course, the entire application is written in Hecl!\n\nYou can even view and edit the source code by using the 'view source' menu button." \			   -layoutparams $layoutparams -textsize $textsize]    after 1 PlayIntro}proc PlayIntro {} {    catch {	java android.media.MediaPlayer mediaplayer	set mp [mediaplayer create [activity] [reslookup R.raw.zintro]]	$mp prepareAsync	$mp start    } err    androidlog "Error: $err"}# SimpleWidgets --##	A demo of some basic widgets: textview, button, edittext and#	digitalclock and imagebutton.CreateActivity SimpleWidgets "Simple Widgets" {    set textsize 30.0    set context [activity]    set layoutparams [linearlayoutparams -new {FILL_PARENT WRAP_CONTENT}]    set scroll [scrollview -new $context -layoutparams $layoutparams]    set swlayout [linearlayout -new $context -layoutparams $layoutparams]    $swlayout setorientation VERTICAL    $scroll addview $swlayout    [activity] setcontentview $scroll    $swlayout addview [button -new $context -text "This is a button" \			   -layoutparams $layoutparams]    $swlayout addview [edittext -new $context \			   -text "This is editable text" \			   -layoutparams $layoutparams]    $swlayout addview [textview -new $context \			   -text "Digital clock:" \			   -layoutparams $layoutparams -textsize $textsize]    java android.widget.DigitalClock digitalclock    $swlayout addview [digitalclock -new $context \			   -layoutparams $layoutparams -textsize $textsize]    java android.widget.ImageButton imagebutton    set ib [imagebutton -new $context -layoutparams $layoutparams]    $swlayout addview $ib    $ib setImageResource [reslookup "R.drawable.buttonhecl"]    # Since this is added to the linearlayout, it has to have    # linearlayoutparams    java {android.widget.RadioGroup$LayoutParams} radiogrouplayoutparams    java android.widget.RadioButton radiobutton    java android.widget.RadioGroup radiogroup    set radiolayoutparams [radiogrouplayoutparams -new {FILL_PARENT WRAP_CONTENT}]    set radiogroup \	[radiogroup -new $context \	     -layoutparams [linearlayoutparams -new {FILL_PARENT FILL_PARENT}]]    $radiogroup setorientation VERTICAL    $swlayout addview [textview -new $context \			   -text "Radio buttons:" \			   -layoutparams $layoutparams -textsize $textsize]    $swlayout addview $radiogroup    $radiogroup addview [radiobutton -new $context \			     -text "Android" -layoutparams $radiolayoutparams]    $radiogroup addview [radiobutton -new $context \			     -text "JavaME" -layoutparams $radiolayoutparams]    $radiogroup addview [radiobutton -new $context \			     -text "Flash Lite" -layoutparams $radiolayoutparams]    $swlayout addview [textview -new $context \			   -text "Check boxes - pick any two:" \			   -layoutparams $layoutparams -textsize $textsize]    java android.widget.CheckBox checkbox    set cb1 [checkbox -new $context \		 -text "Fast" -layoutparams $layoutparams]    set cb2 [checkbox -new $context \		 -text "Cheap" -layoutparams $layoutparams]    set cb3 [checkbox -new $context \		 -text "Good" -layoutparams $layoutparams]    set callback [callback -new [list [list CheckBoxCallback $cb1 $cb2 $cb3]]]    foreach cb [list $cb1 $cb2 $cb3] {	$cb setoncheckedchangelistener $callback	$swlayout addview $cb    }}# WebView --##	Demonstrate the WebView widget.CreateActivity WebView "Web View" {    set context [activity]    set procname WebView    set layoutparams [linearlayoutparams -new {WRAP_CONTENT WRAP_CONTENT}]    java "android.webkit.WebView" webview    set wv [webview -new $context -layoutparams $layoutparams]    [activity] setcontentview $wv    # Fetch the Hecl web page, which, unfortunately, isn't all that    # beautiful ...    $wv loadurl http://www.hecl.org    $wv requestfocus}# Callback --##	Generic callback proc to hand off to various widgets.proc Callback {args} {    set args [lrange $args 1 -1]    alert "Callback called with arguments: $args"}# DatePicker --##	Put a datepicker dialog up on the screen.proc DatePicker {} {    global context    java android.app.DatePickerDialog datedialog    set callback [callback -new [list [list Callback]]]    set dp [datedialog -new [list $context $callback 2007 10 10 1]]    $dp show}# TimePicker --##	Put a time picker dialog up on the screen.proc TimePicker {} {    global context    java android.app.TimePickerDialog timedialog    set callback [callback -new [list [list Callback]]]    set tp [timedialog -new \		[list $context $callback \		     "It's 5 o'clock somewhere" 5 0 1]]    $tp show}# ProgressDialog --##	Create a "progress bar", and, via the updateProgress proc,#	update it and finally dismiss it.proc ProgressDialog {} {    global context    java android.app.ProgressDialog progressdialog    set pd [progressdialog show $context "Working..." \		"This is a progress dialog - it lasts 5 seconds" 0 0]    updateProgress $pd 0}# updateProgress --##	This proc is called at intervals to update the progress#	dialog, and then dismiss it when its time is up.  This is done#	via the after command.proc updateProgress {pd progress} {    $pd setprogress [i $progress]    if { < $progress 5000 } {	after 1000 [list updateProgress $pd [+ 2000 $progress]]    } else {	$pd dismiss    }}# CheckBoxCallback --##	This is the callback for the CheckBox code.  It ensures that#	the user can only select two out of the three options.proc CheckBoxCallback {cb1 cb2 cb3 checkbox ischecked} {    # Only do something if the checkbox has been checked, rather than    # unchecked.    if { = 1 $ischecked } {	set total 0	foreach cb [list $cb1 $cb2 $cb3] {	    incr $total [$cb ischecked]	}	# If they've checked the third of three, uncheck it.	if { = $total 3 } {	    $checkbox setchecked 0	}    }}# Spinner --##	Displays a spinner, and links it to a textview via a callback,#	SpinnerCallback.CreateActivity Spinner "Spinner" {    set procname Spinner    set context [activity]    set layoutparams [linearlayoutparams -new {FILL_PARENT WRAP_CONTENT}]    set layout [linearlayout -new $context]    $layout setorientation VERTICAL    set spinner [basicspinner $context [list "Wheel" "Of" "Fortune!"] \		     -layoutparams $layoutparams]    $layout addview $spinner    # requestfocus is necessary or you won't be able to access the    # spinner if it's redisplayed.  I think this is an Android bug.    $spinner requestfocus    set selected [textview -new $context -text "Currently selected: Wheel" \		      -layoutparams $layoutparams]    $layout addview $selected    set callback [callback -new [list [list SpinnerCallback $selected]]]    $spinner setonitemselectedlistener $callback    [activity] setcontentview $layout}# SpinnerCallback --##	Display the currently selected spinner item.proc SpinnerCallback {textview parent view position id} {    set text [$view gettext]    $textview settext "Currently selected: $text"}# HeclEditor --##	Edit and run simple Hecl scripts.CreateActivity HeclEditor "Hecl Editor" {    set procname HeclEditor    set context [activity]    set layoutparams [linearlayoutparams -new {FILL_PARENT WRAP_CONTENT}]    set layout [linearlayout -new $context]    $layout setorientation VERTICAL    $layout addview [textview -new $context \			 -text "Hecl evaluator: enter code below and hit 'eval' to evaluate" \			 -layoutparams $layoutparams]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -