public class UserReportActivity extends BaseActivity {
private Context mContext;
private WebView webView;
private LoadingAsyncTask lat;
private CircleLoadingProgressDialog circleLoading;
private boolean exitFlag = false;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.user_report_list);
onLoadWebPage();
mContext = this;
Log.e("UserReportActivity", " onCreate()");
}
/**
*
* WebPage 호출
*
*/
public void onLoadWebPage() {
//lat = (LoadingAsyncTask) new LoadingAsyncTask(this, 2).execute();
circleLoading = CircleLoadingProgressDialog.show(UserReportActivity.this);
try{
webView = (WebView) findViewById(R.id.web_view);
webView.clearCache(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
webView.loadUrl(IConstants.NOTICE_PAGE_URL);
webView.setWebViewClient(new UserReportWebViewClient());
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if (progress == 100) {
if(circleLoading != null) circleLoading.dismiss();
}
}
});
} catch (Exception e) {
if(circleLoading != null) circleLoading.dismiss();
}
}
/**
*
* web page History
*
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
private class UserReportWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals(IConstants.NOTICE_SERVER_HOST)) {
Log.e("UserReportActivity", "webview ==>"+url);
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap ico) {
super.onPageStarted(view, url, ico);
Log.e("UserReportActivity", "onPageStarted : "+url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if(circleLoading != null) circleLoading.dismiss();
Log.e("UserReportActivity", "onPageFinished : " + url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
if(circleLoading != null) circleLoading.dismiss();
}
}
/**
*
* Web Interface 연동
*
*/
private class WebAppInterface {
Context mContext;
/** Instantiate the interface and set the context */
public WebAppInterface(Context c) {
mContext = c;
}
/**
*
* Toast 호출
*
* @param toast
*/
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
/**
*
* 다이얼 로그 호출
*
* @param message
*/
@JavascriptInterface
public void showAlertDialog(String message) {
new AlertDialog.Builder(mContext, AlertDialog.THEME_HOLO_LIGHT)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(mContext.getString(R.string.alert_title))
.setMessage(message)
.setPositiveButton(mContext.getString(R.string.confirm_button), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
})
.show();
}
}
public void onClickClose(View v) {
SharedPreferenceUtil.putBooleanSharedPreference(mContext, "noResume", true);
finish();
}
}
'프런트엔드 > Mobile' 카테고리의 다른 글
Getting Unique Device ID of an Android Smartphone (0) | 2015.06.22 |
---|---|
ImageView src 와 background 차이 (1) | 2013.06.19 |
댓글