- 浏览: 1539770 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
hairdryre:
哈哈哈,太好玩啦!
java设计模式之——代理模式 -
wxyz4214769:
aclululu 写道最后一个表示不解,既然已经New Jia ...
java设计模式之——代理模式 -
wxyz4214769:
aclululu 写道最后一个表示不解,既然已经New Jia ...
java设计模式之——代理模式 -
wxyz4214769:
写的不错,是男人的话,瞬间就能理解了。
java设计模式之——代理模式 -
aclululu:
最后一个表示不解,既然已经New JiaShi出来了,为毛在装 ...
java设计模式之——代理模式
各种dialog,alertdialog,AlertDialog.Builder(this)的总结,并封住成javaScript调用
package com.emn.emf.android.basecommands.loading; import org.json.JSONException; import org.json.JSONObject; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import com.emn.emf.android.AndroidBaseActivity; import com.emn.emf.android.CommandObject; import com.emn.emf.android.R; public class Loading extends AndroidBaseActivity implements CommandObject { private ProgressDialog myDialog2 = null; private ProgressDialog myDialogTime = null; private long time = 0,time2 = 0,time3 = 0; private CustomDialog cd; private Dialog cd2; public AlertDialog alertDialog; private String showCenterTipTitle = "",showCenterTipTitle2 = "",showCenterTipTitle3 = "",showCenterTipTitle4 = ""; private String showCenterTipTime = "",showCenterTipTime2 = "",showCenterCallback3 = null,showCenterTipContent3 = ""; private String showCenterTipContent = "",showCenterTipContent2 = "" ,showCenterTipTimeTitle = "";; private String showCenterCallback4 = null,showCenterTipContent4 = ""; private String showCenterTipTimeTime = "",showCenterTipTiemContent = "",showCenterCallback = ""; private Handler mHandler = new Handler(); @Override public Boolean checkValidation(String checkCommand, Object parameters) { // TODO Auto-generated method stub return Boolean.TRUE; } /* * (non-Javadoc) * @see com.emn.emf.android.CommandObject#handleIt(java.lang.String, java.lang.Object) */ @Override public Object handleIt(String checkCommand, Object parameters) { String jsonstartLoad = ""; if (checkCommand.equals("startLoad")) { jsonstartLoad = getStartLoad(parameters); } else if (checkCommand.equals("finishLoad")) { jsonstartLoad = getFinishLoading(); } else if (checkCommand.equals("showCenterTipMyTwoButton")) { jsonstartLoad = getshowCenterTipMyTwoButton(parameters); } else if (checkCommand.equals("showCenterTipMyTime")) { jsonstartLoad = getshowCenterTipMyTime(parameters); } else if (checkCommand.equals("showCenterTipButtonTwo")) { jsonstartLoad = getshowCenterTipButtonTwo(parameters); } else if (checkCommand.equals("showCenterTipButtonOne")) { jsonstartLoad = getshowCenterTipBttonOne(parameters); }else if (checkCommand.equals("showCenterTipTimeSystem")) { jsonstartLoad = getshowCenterTipTimeSystem(parameters); } return jsonstartLoad; } /* * 启动对话框,带有系统默认旋转图片,可以自定义标题,和内容提示部分。 */ private String getStartLoad(Object parameters) { String loadingTitle = ""; String loadingContent = ""; String strJSONParam = parameters.toString(); JSONObject jsonObject; try { jsonObject = new JSONObject(strJSONParam); loadingTitle = jsonObject.getString("title"); loadingContent = jsonObject.getString("content"); } catch (JSONException e1) { e1.printStackTrace(); } CharSequence strDialogTitle = (CharSequence) loadingTitle; CharSequence strDialogBody = (CharSequence) loadingContent; // 显示Progress对话框 myDialog2 = ProgressDialog.show(AndroidBaseActivity.self, strDialogTitle, strDialogBody, true); return "{states:success}"; } /* * 加载Loading效果,你可以自定义指定标题,内容。但没有自动取消。 * 如果需要取消需要调用JS方法finishLoading()进行取消。 */ private String getshowCenterTipTimeSystem(Object parameters) { String strJSONParam = parameters.toString(); JSONObject jsonObject; try { jsonObject = new JSONObject(strJSONParam); showCenterTipTimeTitle = jsonObject.getString("title"); showCenterTipTimeTime = jsonObject.getString("time"); showCenterTipTiemContent = jsonObject.getString("content"); time2 = Long.parseLong(showCenterTipTimeTime); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } CharSequence strDialogTitle = (CharSequence) showCenterTipTimeTitle; CharSequence strDialogBody = (CharSequence) showCenterTipTiemContent; // 显示Progress对话框 myDialogTime = ProgressDialog.show(AndroidBaseActivity.self, strDialogTitle, strDialogBody, true); new Thread() { public void run() { try { sleep(time2); } catch (Exception e) { e.printStackTrace(); } finally { // 卸载所创建的myDialog对象。 myDialogTime.dismiss(); } } }.start(); // 开始运行运行线程 return "{states:success}"; } /* * 取消Loading效果,和getshowCenterTipTime(Object parameters)配对使用。 */ private String getFinishLoading() { if(myDialog2 == null) { return "{states:success}"; } myDialog2.dismiss(); return "{states:success}"; } /* * 自定义dialog,按确定,可以指定执行JS方法,可以指定标题,内容。 * 暂时不支持指定时间,需要的话可以随时添加; */ private String getshowCenterTipMyTwoButton(Object parameters) { String strJSONParam = parameters.toString(); JSONObject jsonObject; try { jsonObject = new JSONObject(strJSONParam); showCenterTipTitle = jsonObject.getString("title"); showCenterTipTime = jsonObject.getString("time"); showCenterTipContent = jsonObject.getString("content"); showCenterCallback = jsonObject.getString("callback"); time = Long.parseLong(showCenterTipTime); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } cd = new CustomDialog(AndroidBaseActivity.self); cd.show(); return "{states:success}"; } /* * 自定义对话框 */ class CustomDialog extends Dialog { public CustomDialog(Context context) { super(context); } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.custom_dialog); setTitle(showCenterTipTitle); TextView text = (TextView) findViewById(R.id.text); text.setText(showCenterTipContent); ImageView image = (ImageView) findViewById(R.id.image); image.setImageResource(R.drawable.icon); Button buttonYes = (Button) findViewById(R.id.button_yes); buttonYes.setHeight(5); buttonYes.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { dismiss(); mHandler.post(new Runnable() { public void run() { getWebView().loadUrl( "javascript:" + showCenterCallback); } }); } }); Button buttonNo = (Button) findViewById(R.id.button_no); buttonNo.setSingleLine(true); buttonNo.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { dismiss(); } }); } } /* * 自定义dialog,可以指定执行时间长度,标题,内容部分支持最大48*48像素PNG图片。 * */ private String getshowCenterTipMyTime(Object parameters) { String strJSONParam = parameters.toString(); JSONObject jsonObject; try { jsonObject = new JSONObject(strJSONParam); showCenterTipTitle2 = jsonObject.getString("title"); showCenterTipTime2 = jsonObject.getString("time"); showCenterTipContent2 = jsonObject.getString("content"); // showCenterCallback = jsonObject.getString("callback"); time3 = Long.parseLong(showCenterTipTime2); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } cd2 = new CustomDialog2(AndroidBaseActivity.self); cd2.setContentView(R.layout.custom_dialog2); cd2.setTitle(showCenterTipTitle2); cd2.show(); new Thread() { public void run() { try { sleep(time3); } catch (Exception e) { e.printStackTrace(); } finally { // 卸载所创建的myDialog对象。 cd2.dismiss(); } } }.start(); // 开始运行运行线程 return "{states:success}"; } class CustomDialog2 extends Dialog { public CustomDialog2(Context context) { super(context); } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.custom_dialog2); TextView text = (TextView) findViewById(R.id.text); text.setText(showCenterTipContent2); ImageView image = (ImageView) findViewById(R.id.image); image.setImageResource(R.drawable.icon); } } /* * 系统dialog的封装,可以指定执行时间,标题,内容。 * 有确定按钮,和取消按钮,点击确定时执行一个JS方法,取消不执行。 * */ private String getshowCenterTipButtonTwo(Object parameters) { String strJSONParam = parameters.toString(); JSONObject jsonObject; try { jsonObject = new JSONObject(strJSONParam); showCenterTipTitle3 = jsonObject.getString("title"); //showCenterTipTime3 = jsonObject.getString("time"); showCenterTipContent3 = jsonObject.getString("content"); showCenterCallback3 = jsonObject.getString("callback"); //time4 = Long.parseLong(showCenterTipTime3); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } new AlertDialog.Builder(AndroidBaseActivity.self) .setTitle(showCenterTipTitle3)//.setView(view) .setMessage(showCenterTipContent3) .setPositiveButton("确定", new DialogInterface.OnClickListener(){ public void onClick( DialogInterface dialoginterface, int i){ getWebView().loadUrl( "javascript:" + showCenterCallback3); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener(){ public void onClick( DialogInterface dialoginterface, int i){ } }) .show(); return "{states:success}"; } /* * 系统dialog的封装,可以指定执行时间,标题,内容。 * 只有确定按钮,,点击确定时执行一个JS方法。 * */ private String getshowCenterTipBttonOne(Object parameters) { String strJSONParam = parameters.toString(); JSONObject jsonObject; try { jsonObject = new JSONObject(strJSONParam); showCenterTipTitle4 = jsonObject.getString("title"); //showCenterTipTime3 = jsonObject.getString("time"); showCenterTipContent4 = jsonObject.getString("content"); showCenterCallback4 = jsonObject.getString("callback"); //time4 = Long.parseLong(showCenterTipTime3); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } new AlertDialog.Builder(AndroidBaseActivity.self) .setTitle(showCenterTipTitle4)//.setView(view) .setMessage(showCenterTipContent4) .setPositiveButton("确定", new DialogInterface.OnClickListener(){ public void onClick( DialogInterface dialoginterface, int i){ getWebView().loadUrl( "javascript:" + showCenterCallback4); } }) .show(); return "{states:success}"; } }
2.custom_dialog.xml的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_root" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg3" android:padding="10dp" > <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="2px" > <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="2dp" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFF" android:paddingTop="12dp" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:padding="5px" > <Button android:id="@+id/button_yes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" 确定 " /> <Button android:id="@+id/button_no" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" 取消 " /> </LinearLayout> </LinearLayout>
3.custom_dialog2.xml的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:background="@drawable/bg3" > <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" android:padding="2px" > <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="2dp" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="18px" android:gravity="center_horizontal" /> </LinearLayout> </LinearLayout>
4.main.js代码
//加载效果,你可以自定义指定标题,内容。但没有自动取消。如果需要取消需要调用JS方法finishLoading() function getStartLoading(){ return emf.makeCall('startLoading.startLoad', "{title:'联系人',content:'请您稍等正在加载联系人...'}"); } //与上面方法一对,负责关闭上面的方法。 function finishLoading(){ return emf.makeCall('startLoading.finishLoad', "{}"); } //自定义dialog,可以指定执行JS方法,可以指定标题,内容。暂时不支持指定时间,需要的话可以随时添加 function showCenterTipMyTwoButton(){ return emf.makeCall('startLoading.showCenterTipMyTwoButton', "{title:'操作成功',content:'操作成功信息部分',time:'5000',callback:'showCenterTipMyTime()'}"); } //自定义dialog,可以指定执行时间,标题,内容。内容部分支持最大48*48像素PNG图片 function showCenterTipMyTime(){ return emf.makeCall('startLoading.showCenterTipMyTime', "{title:'操作成功时间',content:'时间操作成功信息部分',time:'5000'}"); } //系统dialog的封装,可以指定执行时间,标题,内容。有确定,执行一个JS方法,取消不执行。 function showCenterTipButtonTwo(){ return emf.makeCall('startLoading.showCenterTipButtonTwo', "{title:'操作标题',content:'时间操作成功信息部分呵呵!',callback:'showCenterTipButtonOne()'}"); } function showCenterTipButtonOne(){ return emf.makeCall('startLoading.showCenterTipButtonOne', "{title:'操作标题',content:'时间操作成功信息部分呵呵!',callback:'showCenterTipButtonTwo()'}"); } //系统自带的Dialog,但可以指定执行时间,标题,内容。 function showCenterTipTimeSystem(){ return emf.makeCall('startLoading.showCenterTipTimeSystem', "{title:'恭喜操作成功',content:'操作成功信息部分',time:'5000'}"); }
5.index.html页面代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>EMF</title>
<base href="mobile/">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="file:///android_asset/main.js"
charset="utf-8"></script>
</head>
<body>
<label id='testlabel'>123 </label>
<br />
<br />
<input type="button" value="getStartLoading()" onclick="getStartLoading()" />
<input type="button" value="showCenterTipMyTwoButton()" onclick="showCenterTipMyTwoButton()" />
<input type="button" value="showCenterTipMyTime()" onclick="showCenterTipMyTime()" />
<input type="button" value="showCenterTipTimeSystem()" onclick="showCenterTipTimeSystem()" />
<input type="button" value="showCenterTipButtonTwo()" onclick="showCenterTipButtonTwo()" />
<input type="button" value="showCenterTipButtonOne()" onclick="showCenterTipButtonOne()" />
<br />
</body>
<script type="text/javascript">
//function showCenterTipTest(){
//}
//testlabel.innerText += "abc:" + getDownload();
//getStartLoading();
// window.setTimeout('finishLoading()',6000)
//testlabel.innerText = emf.makeCall('telePhone', '{query:query}');
//testlabel.innerText = "abc:" + getContactsId();
//testlabel.innerText += "abc:" + getDownload();
//testlabel.innerText += "abc:" + getStartLoading();
</script>
</html>
<html>
<head>
<title>EMF</title>
<base href="mobile/">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="file:///android_asset/main.js"
charset="utf-8"></script>
</head>
<body>
<label id='testlabel'>123 </label>
<br />
<br />
<input type="button" value="getStartLoading()" onclick="getStartLoading()" />
<input type="button" value="showCenterTipMyTwoButton()" onclick="showCenterTipMyTwoButton()" />
<input type="button" value="showCenterTipMyTime()" onclick="showCenterTipMyTime()" />
<input type="button" value="showCenterTipTimeSystem()" onclick="showCenterTipTimeSystem()" />
<input type="button" value="showCenterTipButtonTwo()" onclick="showCenterTipButtonTwo()" />
<input type="button" value="showCenterTipButtonOne()" onclick="showCenterTipButtonOne()" />
<br />
</body>
<script type="text/javascript">
//function showCenterTipTest(){
//}
//testlabel.innerText += "abc:" + getDownload();
//getStartLoading();
// window.setTimeout('finishLoading()',6000)
//testlabel.innerText = emf.makeCall('telePhone', '{query:query}');
//testlabel.innerText = "abc:" + getContactsId();
//testlabel.innerText += "abc:" + getDownload();
//testlabel.innerText += "abc:" + getStartLoading();
</script>
</html>
相关推荐
首先,实例化Builder,然后通过各种方法设置标题、消息、按钮等,最后调用`create()`方法生成Dialog对象,并使用`show()`方法将其显示在屏幕上。 ```java AlertDialog.Builder builder = new AlertDialog.Builder...
final AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); builder.setTitle("对话框") .setMessage(message) .setPositiveButton("确定", null); // 不需要绑定按键事件 // 屏蔽 ...
在Android开发中,WebView是一个非常重要的...需要注意的是,为了安全起见,你应该只接受来自可信源的JavaScript调用,并对传递的数据进行验证。同时,考虑兼容性问题,确保在不同的Android版本和设备上都能正常工作。
在Android开发中,DialogShow可能指的是`AlertDialog.Builder`类的一个实例,通过该类可以构建并显示警告、确认或输入类型的对话框。开发者可以通过调用`create()`和`show()`方法来创建并显示对话框。 在Web开发中...
AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage("是否继续?") .setPositiveButton("是", new DialogInterface.OnClickListener() { public void onClick(DialogInterface ...
在Android开发中,我们可以使用`AlertDialog.Builder`来构建对话框,并设置其标题、内容和按钮。在Web开发中,可以使用HTML、CSS和JavaScript创建自定义的模态框。 2. **设置倒计时逻辑**:使用编程语言中的定时器...
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("AlertDialog"); builder.setMessage(message); builder.setPositiveButton("确定", new DialogInterface....
为了实现RN与Android原生代码的交互,开发者可以使用`RCTBridgeModule`接口定义Java模块,并通过`NativeModules`在JavaScript中调用。此外,`ReactContextBaseJavaModule`和`ReactMethod`也是常用的交互工具。 6. ...
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Title"); final EditText input = new EditText(this); builder.setView(input); builder.setPositiveButton("OK", new ...
AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); builder.setTitle("安全警告"); builder.setMessage("该网站的证书不受信任,是否继续访问?"); builder.setPositiveButton("继续",...
4.15.6、AlertDialog.Builder 133 4.15.7、模式对话框 134 4.16、拖动BUTTON获得位置 135 5、ANDROID UI 美化 137 5.1、简单美化BUTTON、IMAGEBUTTON、TEXTVIEW等控件 137 5.2、BUTTON美化案例☆ 139 5.3、...