様々なdialog、alertdialog、AlertDialog.Burderのまとめ、javaScript呼び出しとして封じ込められています.
20200 ワード
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_dialog 2.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.ページコード
>
<>>
<title>EMF
<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」>
<body>
<label id='testlabel'>123
<input type=“button”value=“get StartLoading()”onclick=“get StartLoading()”/”
<input type=“button”value=“show Center TipMyTwoButton()”onclick=“show Center TipMyTwoButton()”/”
<input type=“button”value=“show Center TipMyTime()”onclick=“show Center TipMyTime()”/”
<input type=“button”value=“show Center TipTimeSystem()”onclick=“show Center TipTimeSystem()”/”
<input type=「button」value=「show Center TipButotonTwo()」onclick=「show Center TipButotonTwo()」
<input type=「button」value=「show Center TipButton One()」onclick=「show Center TipButtonOne()」/>
<script type=「text/javascript」>
//function show Center TipTest(){
//}
//testlabel.innerText+="abc:"+get Download();
//get StartLoading();
//window.set Timeout('finish Loading()',6000)
//testlabel.innerText=emf.makeCall('telePhone'、'{query:query');
//testlabel.innerText="abc:"+get ContactsId();
//testlabel.innerText+="abc:"+get Download();
//testlabel.innerText+="abc:"+get StartLoading();