/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/package com.aviva_cofco.crowdfunding;
import org.apache.cordova.CordovaActivity;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaWebViewClient;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import com.aviva_cofco.crowdfunding.ssl.SSLAcceptingCordovaWebViewClient;
import com.aviva_cofco.crowdfunding.ssl.SSLAcceptingIceCreamCordovaWebViewClient;
publicclassCordovaAppextendsCordovaActivity {@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
// super.i
setOriention();
/*
* appView.setWebViewClient(new WebViewClient(){
*
* @Override public void onReceivedSslError(WebView view,
* SslErrorHandler handler, SslError error) { // TODO Auto-generated
* method stub handler.proceed(); } });
* appView.getSettings().setDomStorageEnabled(true);
*/// appView.setWebContentsDebuggingEnabled(true);// 修改浏览器UA
String ua = appView.getSettings().getUserAgentString();
// 加入当前App的版本号
ua += "&=AppVersion:0.1";
appView.getSettings().setUserAgentString(ua);
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
}
@OverrideprotectedvoidonResume() {
// TODO Auto-generated method stubsuper.onResume();
setOriention();
}
privatevoidsetOriention() {
if (isPad() || isCustomerDevice()) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
/**
* 判断是否是某些特殊设备
*
* @return
*/privatebooleanisCustomerDevice() {
String model = Build.MODEL;
if ("N5100".equals(model)) {
returntrue;
} else {
returnfalse;
}
}
privatebooleanisPad() {
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point p = new Point();
display.getSize(p);
// 屏幕宽度float screenWidth = p.x;
float screenHeight = p.y;
screenWidth = Math.max(screenWidth, screenHeight);
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
int cssWidth = (int) (screenWidth / dm.density + 0.5f);
if (cssWidth > 700) {
returntrue;
}
returnfalse;
}
@Overrideprotected CordovaWebViewClient makeWebViewClient(CordovaWebView webView) {
// TODO Auto-generated method stubif (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
returnnew SSLAcceptingCordovaWebViewClient(this, webView);
} else {
returnnew SSLAcceptingIceCreamCordovaWebViewClient(this, webView);
}
}
}