Commit 45560982 authored by Nature's avatar Nature

init

parents
This diff is collapsed.
打开在线页面的WebView插件,支持在线页面中调用cordova插件,支持android和ios平台
使用方法:
(1)打开在线页面:
WebViewPlugin.loadWebView(function (data) {
//成功打开在线页面,回调函数返回的data值为0,关闭在线页面返回值为1,仅ios平台有效
if (ionic.Platform.isIOS() && data === 1) {
//to do ....
}
}, function () {
console.log("WebViewPlugin.loadWebView failed");
}, url);
注意:对应android平台,关闭在线页面时回调函数不会返回值,如果想在关闭在线页面时做一些处理,
可以在app.js中监听resume事件,例如:
$ionicPlatform.ready(function () {
//关闭在线页面时,android平台会触发resume事件
if (ionic.Platform.isAndroid()) {
$ionicPlatform.on("pause", function (event) {
//to do ...
});
$ionicPlatform.on("resume", function (event) {
//to do ....
});
}
});
(2)关闭在线页面:
WebViewPlugin.dismissWebView(function () {
console.log("WebViewPlugin.dismissWebView success");
}, function () {
console.log("WebViewPlugin.dismissWebView error");
}, '');
\ No newline at end of file
{
"_args": [
[
{
"raw": "D:\\cordova-plugin-hand-webview",
"scope": null,
"escapedName": null,
"name": null,
"rawSpec": "D:\\cordova-plugin-hand-webview",
"spec": "D:\\cordova-plugin-hand-webview",
"type": "directory"
},
"D:\\Project\\jianXinRenShou\\jxrs-app"
]
],
"_from": "..\\..\\..\\cordova-plugin-hand-webview",
"_id": "cordova-plugin-hand-webview@1.0.4",
"_inBundle": false,
"_inCache": true,
"_integrity": "sha512-HiOuakLrf5c64LwjO14KbbJw6aEIXJsreXARRRQFF6uCjJz1y8sw3VxljEF50gkT+9VMo58uV3AyjNe9yfMqUA==",
"_location": "/cordova-plugin-hand-webview",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "cordova-plugin-hand-webview",
"name": "cordova-plugin-hand-webview",
"escapedName": "cordova-plugin-hand-webview",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER"
],
"_resolved": "file:..\\..\\..\\cordova-plugin-hand-webview",
"_shasum": "1edd7e7fbb373e4376dbeab13e84efd65163074d",
"_shrinkwrap": null,
"_spec": "cordova-plugin-hand-webview",
"_where": "D:\\develop\\mobile\\app\\jxrs-app",
"author": {
"name": "hand plugin"
},
"bugs": {
"url": "https://github.com/liuzong/cordova-plugin-hand-webview/issues"
},
"bundleDependencies": false,
"cordova": {
"id": "cordova-plugin-hand-webview",
"platforms": [
"android",
"ios"
]
},
"dependencies": {},
"deprecated": false,
"description": "open the H5 page",
"devDependencies": {},
"homepage": "https://github.com/liuzong/cordova-plugin-hand-webview#readme",
"keywords": [
"cordova",
"cordova-webview",
"webview"
],
"license": "Apache 2.0",
"name": "cordova-plugin-hand-webview",
"optionalDependencies": {},
"readme": "打开在线页面的WebView插件,支持在线页面中调用cordova插件,支持android和ios平台\r\n\r\n使用方法:\r\n(1)打开在线页面:\r\n WebViewPlugin.loadWebView(function (data) {\r\n //成功打开在线页面,回调函数返回的data值为0,关闭在线页面返回值为1,仅ios平台有效\r\n if (ionic.Platform.isIOS() && data === 1) {\r\n //to do ....\r\n }\r\n }, function () {\r\n console.log(\"WebViewPlugin.loadWebView failed\");\r\n }, url);\r\n 注意:对应android平台,关闭在线页面时回调函数不会返回值,如果想在关闭在线页面时做一些处理,\r\n 可以在app.js中监听resume事件,例如:\r\n $ionicPlatform.ready(function () {\r\n //关闭在线页面时,android平台会触发resume事件\r\n if (ionic.Platform.isAndroid()) {\r\n $ionicPlatform.on(\"pause\", function (event) {\r\n //to do ...\r\n });\r\n $ionicPlatform.on(\"resume\", function (event) {\r\n //to do ....\r\n });\r\n }\r\n });\r\n(2)关闭在线页面:\r\n WebViewPlugin.dismissWebView(function () {\r\n console.log(\"WebViewPlugin.dismissWebView success\");\r\n }, function () {\r\n console.log(\"WebViewPlugin.dismissWebView error\");\r\n }, '');",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/liuzong/cordova-plugin-hand-webview.git"
},
"version": "1.0.4"
}
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-hand-webview" version="1.0.4">
<name>WebViewPlugin</name>
<author>hand</author>
<description>hand plugin.</description>
<keywords>cordova,avtive</keywords>
<license>Apache 2.0</license>
<js-module charset="utf-8" name="WebViewPlugin" src="www/WebViewPlugin.js">
<clobbers target="WebViewPlugin"/>
</js-module>
<platform name="android">
<config-file parent="/*" target="res/xml/config.xml">
<feature name="WebViewPlugin">
<param name="android-package" value="com.hand.webview.WebViewPlugin"/>
</feature>
</config-file>
<source-file src="src/android/src/com/hand/webview/Util.java" target-dir="src/com/hand/webview"/>
<source-file src="src/android/src/com/hand/webview/WebViewActivity.java" target-dir="src/com/hand/webview"/>
<source-file src="src/android/src/com/hand/webview/WebViewActivityManager.java" target-dir="src/com/hand/webview"/>
<source-file src="src/android/src/com/hand/webview/WebViewPlugin.java" target-dir="src/com/hand/webview"/>
<source-file src="src/android/src/com/hand/webview/DialogLoad.java" target-dir="src/com/hand/webview"/>
<source-file src="src/android/layout/activity_webview.xml" target-dir="res/layout"/>
<source-file src="src/android/drawable/anim_loading.xml" target-dir="res/drawable"/>
<source-file src="src/android/layout/dialog_loading.xml" target-dir="res/layout"/>
<source-file src="src/android/values/web_style.xml" target-dir="res/values"/>
<source-file src="src/android/drawable-hdpi/load1.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load2.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load3.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load4.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load5.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load6.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load7.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load8.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load9.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load10.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load11.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load12.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load13.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load14.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load15.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load16.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load17.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load18.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load19.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load20.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load21.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load22.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load23.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load24.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load25.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load26.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load27.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load28.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load29.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load30.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load31.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load32.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load33.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load34.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load35.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load36.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load37.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load38.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load39.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load40.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load41.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load42.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load43.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load44.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load45.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load46.png" target-dir="res/drawable-hdpi"/>
<source-file src="src/android/drawable-hdpi/load47.png" target-dir="res/drawable-hdpi"/>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:screenOrientation="portrait" android:name="com.hand.webview.WebViewActivity"></activity>
</config-file>
<config-file parent="/manifest" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.INTERNET" />
</config-file>
</platform>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="WebViewPlugin">
<param name="ios-package" value="CDVWebViewPlugin"/>
</feature>
</config-file>
<header-file src="src/ios/plugins/CDVWebViewPlugin.h" />
<source-file src="src/ios/plugins/CDVWebViewPlugin.m" />
<header-file src="src/ios/plugins/WebPluginController.h" />
<source-file src="src/ios/plugins/WebPluginController.m" />
<header-file src="src/ios/plugins/MBProgressHUD.h" />
<source-file src="src/ios/plugins/MBProgressHUD.m" />
<header-file src="src/ios/plugins/MBProgressHUD+XW.h" />
<source-file src="src/ios/plugins/MBProgressHUD+XW.m" />
<header-file src="src/ios/plugins/DRPLoadingSpinner.h" />
<source-file src="src/ios/plugins/DRPLoadingSpinner.m" />
<header-file src="src/ios/plugins/DRPLoadingSpinnerTimingFunction.h" />
<source-file src="src/ios/plugins/DRPLoadingSpinnerTimingFunction.m" />
</platform>
</plugin>
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/load2"
android:duration="10" />
<item
android:drawable="@drawable/load3"
android:duration="10" />
<item
android:drawable="@drawable/load4"
android:duration="10" />
<item
android:drawable="@drawable/load5"
android:duration="10" />
<item
android:drawable="@drawable/load6"
android:duration="10"/>
<item
android:drawable="@drawable/load7"
android:duration="10" />
<item
android:drawable="@drawable/load8"
android:duration="10" />
<item
android:drawable="@drawable/load9"
android:duration="10" />
<item
android:drawable="@drawable/load10"
android:duration="10" />
<item
android:drawable="@drawable/load11"
android:duration="10" />
<item
android:drawable="@drawable/load12"
android:duration="10" />
<item
android:drawable="@drawable/load13"
android:duration="10" />
<item
android:drawable="@drawable/load14"
android:duration="10" />
<item
android:drawable="@drawable/load15"
android:duration="10" />
<item
android:drawable="@drawable/load16"
android:duration="10" />
<item
android:drawable="@drawable/load17"
android:duration="10" />
<item
android:drawable="@drawable/load18"
android:duration="10" />
<item
android:drawable="@drawable/load19"
android:duration="10" />
<item
android:drawable="@drawable/load20"
android:duration="10" />
<item
android:drawable="@drawable/load21"
android:duration="10" />
<item
android:drawable="@drawable/load22"
android:duration="10" />
<item
android:drawable="@drawable/load23"
android:duration="10" />
<item
android:drawable="@drawable/load24"
android:duration="10" />
<item
android:drawable="@drawable/load25"
android:duration="10" />
<item
android:drawable="@drawable/load26"
android:duration="10" />
<item
android:drawable="@drawable/load27"
android:duration="10" />
<item
android:drawable="@drawable/load28"
android:duration="10" />
<item
android:drawable="@drawable/load29"
android:duration="10" />
<item
android:drawable="@drawable/load30"
android:duration="10" />
<item
android:drawable="@drawable/load31"
android:duration="10" />
<item
android:drawable="@drawable/load32"
android:duration="10" />
<item
android:drawable="@drawable/load33"
android:duration="10" />
<item
android:drawable="@drawable/load34"
android:duration="10" />
<item
android:drawable="@drawable/load35"
android:duration="10" />
<item
android:drawable="@drawable/load36"
android:duration="10" />
<item
android:drawable="@drawable/load37"
android:duration="10" />
<item
android:drawable="@drawable/load38"
android:duration="10" />
<item
android:drawable="@drawable/load39"
android:duration="10" />
<item
android:drawable="@drawable/load40"
android:duration="10" />
<item
android:drawable="@drawable/load41"
android:duration="10" />
<item
android:drawable="@drawable/load42"
android:duration="10" />
<item
android:drawable="@drawable/load43"
android:duration="10" />
<item
android:drawable="@drawable/load44"
android:duration="10" />
<item
android:drawable="@drawable/load45"
android:duration="10" />
<item
android:drawable="@drawable/load46"
android:duration="10" />
<item
android:drawable="@drawable/load47"
android:duration="10" />
</animation-list>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<org.apache.cordova.engine.SystemWebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"></org.apache.cordova.engine.SystemWebView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id = "@+id/img_load"
android:layout_width="30dp"
android:layout_height="30dp"
android:adjustViewBounds="true"
android:src="@drawable/load1"
/>
</LinearLayout>
package com.hand.webview;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
/**
* Created by panx on 2017/3/30.
*/
public class DialogLoad extends Dialog {
private ImageView imgLoad;
public DialogLoad(Context context) {
super(context,Util.getRS("Dialog_No_Border","style",context));
LayoutInflater layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(Util.getRS("dialog_loading","layout",context),null);
this.setContentView(view);
imgLoad = (ImageView) view.findViewById(Util.getRS("img_load","id",context));
WindowManager.LayoutParams lp = this.getWindow().getAttributes();
// 设置背景层透明度
lp.dimAmount = 0.0f;
this.getWindow().setAttributes(lp);
this.setCancelable(false);
}
@Override
public void show() {
if(this.isShowing()){
return;
}
super.show();
imgLoad.setImageResource(Util.getRS("anim_loading","drawable",getContext()));
AnimationDrawable animationDrawable = (AnimationDrawable) imgLoad.getDrawable();
animationDrawable.start();
}
@Override
public void dismiss() {
try {
AnimationDrawable animationDrawable = (AnimationDrawable) imgLoad.getDrawable();
animationDrawable.stop();
imgLoad.setImageResource(Util.getRS("load1","drawable",getContext()));
}catch (Exception e){
}
if(getWindow()!=null){
super.dismiss();
}
}
}
package com.hand.webview;
import android.content.Context;
/**
* Created by panx on 2017/2/7.
*/
public class Util {
public static int getRS(String name, String type, Context context){
int resID=0;
resID = context.getResources().getIdentifier(name, type, context.getPackageName());
return resID;
}
}
package com.hand.webview;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;
import org.apache.cordova.CordovaActivity;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaWebViewImpl;
import org.apache.cordova.engine.SystemWebChromeClient;
import org.apache.cordova.engine.SystemWebView;
import org.apache.cordova.engine.SystemWebViewClient;
import org.apache.cordova.engine.SystemWebViewEngine;
/**
* Created by panx on 2017/2/22.
*/
public class WebViewActivity extends CordovaActivity {
public static final String URL = "url";
private SystemWebView webView;
private String url;
private DialogLoad dialogLoad;
private boolean isFirstLoad = true;
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
WebViewActivityManager.OnCreateActivity(this);
setContentView(Util.getRS("activity_webview", "layout", this));
readIntent();
initView();
loadUrl(url);
}
private void readIntent() {
url = getIntent().getStringExtra(URL);
}
private void initView() {
webView = (SystemWebView) findViewById(Util.getRS("webview", "id", this));
dialogLoad = new DialogLoad(this);
}
@Override
protected CordovaWebView makeWebView() {
webView.getSettings().setJavaScriptEnabled(true);
webView.clearCache(true);
webView.clearHistory();
SystemWebViewEngine webViewEngine = new SystemWebViewEngine(webView);
webView.setWebViewClient(new SystemWebViewClient(webViewEngine) {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if(isFirstLoad) {
dialogLoad.show();
isFirstLoad = false;
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if(dialogLoad.isShowing())
new Handler(getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
dialogLoad.dismiss();
}
},2000);
}
});
return new CordovaWebViewImpl(webViewEngine);
}
@Override
public void finish() {
Log.e("WebViewActivity", "finish");
super.finish();
}
@Override
public void onDestroy() {
super.onDestroy();
WebViewActivityManager.OnDestroyActivity(this);
}
@Override
protected void createViews() {
appView.getView().requestFocusFromTouch();
}
}
package com.hand.webview;
import android.app.Activity;
import java.util.ArrayList;
import java.util.List;
/**
* Created by panx on 2017/2/22.
*/
public class WebViewActivityManager {
private static List<Activity> list = new ArrayList<Activity>();
public static void OnCreateActivity(Activity activity) {
for (Activity a : list) {
if (a.equals(list)) {
return;
}
}
list.add(activity);
}
public static void OnDestroyActivity(Activity activity) {
list.remove(activity);
}
public static List<Activity> GetActivityList() {
return list;
}
}
package com.hand.webview;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.List;
/**
* Created by panx on 2017/2/22.
*/
public class WebViewPlugin extends CordovaPlugin {
private final static String LOAD_WEBVIEW = "loadWebView";
private final static String DISMISS_WEBVIEW = "dismissWebView";
private CallbackContext callbackContext;
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
this.callbackContext = callbackContext;
if(LOAD_WEBVIEW.equals(action)){
loadWebview(args);
return true;
}else if(DISMISS_WEBVIEW.equals(action)){
disMissWebView();
return true;
}
return false;
}
private void loadWebview(JSONArray args){
try {
String url = args.getString(0);
Intent intent = new Intent(cordova.getActivity(),WebViewActivity.class);
intent.putExtra(WebViewActivity.URL,url);
cordova.setActivityResultCallback(this);
cordova.startActivityForResult(this, intent, 1);
} catch (JSONException e) {
callbackContext.error("Wrong arguments");
e.printStackTrace();
}
}
private void disMissWebView(){
Log.e("WebViewPlugin","dismisswebView");
/* if(WebViewActivity.instance!=null) {
WebViewActivity.instance.finish();
}*/
List<Activity> activities = WebViewActivityManager.GetActivityList();
if(activities!=null&&activities.size()>0){
activities.get(activities.size()-1).finish();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Dialog_No_Border" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
//
// CDVWebViewPlugin.h
// HelloCordova
//
// Created by Mr.xiao on 17/2/16.
//
//
#import <Cordova/CDVPlugin.h>
@interface CDVWebViewPlugin : CDVPlugin
- (void)loadWebView:(CDVInvokedUrlCommand *)command;
- (void)dismissWebView:(CDVInvokedUrlCommand *)command;
@end
//
// CDVWebViewPlugin.m
// HelloCordova
//
// Created by Mr.xiao on 17/2/16.
//
//
#import "CDVWebViewPlugin.h"
#import "WebPluginController.h"
@interface CDVWebViewPlugin ()<WebPluginProtocol>
@property (nonatomic ,strong) WebPluginController *webPluginCtrl;
@property (nonatomic, strong) NSString *callId;
@end
@implementation CDVWebViewPlugin
- (void)loadWebView:(CDVInvokedUrlCommand *)command{
NSString *result = [[command arguments] firstObject];
self.webPluginCtrl = [[WebPluginController alloc] init];
self.callId = command.callbackId;
[[NSUserDefaults standardUserDefaults] setObject:self.callId forKey:@"WebViewPluginid"];
self.webPluginCtrl.startPage = result;
self.webPluginCtrl.delegate = self;
self.webPluginCtrl.openDelegate = self.commandDelegate;
__weak CDVWebViewPlugin *weakSelf = self;
[self.commandDelegate runInBackground:^{
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.webPluginCtrl.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[weakSelf.viewController presentViewController:weakSelf.webPluginCtrl animated:YES completion:nil];
});
}];
}
- (void)dismissWebView:(CDVInvokedUrlCommand *)command{
__weak CDVWebViewPlugin *weakSelf = self;
NSString* callBackId = [[NSUserDefaults standardUserDefaults] objectForKey:@"WebViewPluginid"];
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:1];
WebPluginController* ctl = (WebPluginController*)self.viewController;
[ctl.openDelegate sendPluginResult:result callbackId:callBackId];
[self.commandDelegate runInBackground:^{
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.viewController dismissViewControllerAnimated:YES completion:nil];
//CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
});
}];
[self.commandDelegate sendPluginResult:result callbackId:callBackId];
}
- (void)webViewDidSuccessLoad{
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:0];
// [self.commandDelegate sendPluginResult:result callbackId:self.callId];
}
- (void)webViewDidFailedLoad{
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
// [self.commandDelegate sendPluginResult:result callbackId:self.callId];
}
@end
//
// DRPLoadingSpinner.h
// DRPLoadingSpinner
//
// Created by Justin Hill on 11/11/14.
// Copyright (c) 2014 Justin Hill. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "DRPLoadingSpinnerTimingFunction.h"
/**
* @brief The set of directions that DRPLoadingSpinner can spin
*/
typedef NS_ENUM(NSInteger, DRPRotationDirection) {
DRPRotationDirectionClockwise,
DRPRotationDirectionCounterClockwise
};
@interface DRPLoadingSpinner : UIView
/**
* @brief Which direction the spinner should spin. Defaults to clockwise.
*/
@property (nonatomic, assign) DRPRotationDirection rotationDirection;
/**
* @brief When the spinner is not animating, the length of the arc to be drawn. This can
* be used to implement things like pull-to-refresh as seen in DRPRefreshControl.
*/
@property (nonatomic, assign) CGFloat staticArcLength;
/**
@brief When the arc is shrinking, how small it should get at a minimum in radians.
*/
@property (assign) CGFloat minimumArcLength;
/**
* @brief When the arc is growing, how large it should get at a maximum in radians
*/
@property (assign) CGFloat maximumArcLength;
/**
* @brief The width of the arc's line.
*/
@property (nonatomic) CGFloat lineWidth;
/**
@brief How long in seconds it should take for the drawing to rotate 360 degrees.
No easing function is applied to this duration, i.e. it is linear.
*/
@property (assign) CFTimeInterval rotationCycleDuration;
/**
@brief How long in seconds it should take for a complete circle to be drawn
or erased. An in-out easing function is applied to this duration.
*/
@property (assign) CFTimeInterval drawCycleDuration;
/**
@brief The timing function that should be used for drawing the rail.
*/
@property (strong) CAMediaTimingFunction *drawTimingFunction;
/**
@brief An array of UIColors that defines the colors the spinner will draw in
and their order. The colors will loop back to the beginning when the
cycle for the last color has been completed.
*/
@property (strong) NSArray<UIColor *> *colorSequence UI_APPEARANCE_SELECTOR;
/**
@brief The color of the rail behind the spinner. Defaults to clear.
*/
@property (nonatomic) UIColor *backgroundRailColor;
/**
@return YES if the spinner is animating, otherwise NO
*/
@property (readonly) BOOL isAnimating;
/**
@brief Start animating.
*/
- (void)startAnimating;
/**
@brief Stop animating and clear the drawing context.
*/
- (void)stopAnimating;
@end
This diff is collapsed.
//
// DRPLoadingSpinnerTimingFunction.h
// DRPLoadingSpinner
//
// Created by Justin Hill on 3/21/17.
// Copyright © 2017 Justin Hill. All rights reserved.
//
@import UIKit;
@interface DRPLoadingSpinnerTimingFunction : NSObject
+ (CAMediaTimingFunction *)linear;
+ (CAMediaTimingFunction *)easeIn;
+ (CAMediaTimingFunction *)easeOut;
+ (CAMediaTimingFunction *)easeInOut;
+ (CAMediaTimingFunction *)sharpEaseInOut;
@end
//
// DRPLoadingSpinnerTimingFunction.m
// DRPLoadingSpinner
//
// Created by Justin Hill on 3/21/17.
// Copyright © 2017 Justin Hill. All rights reserved.
//
#import "DRPLoadingSpinnerTimingFunction.h"
@implementation DRPLoadingSpinnerTimingFunction
+ (CAMediaTimingFunction *)linear {
return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
}
+ (CAMediaTimingFunction *)easeIn {
return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
}
+ (CAMediaTimingFunction *)easeOut {
return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
}
+ (CAMediaTimingFunction *)easeInOut {
return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
}
+ (CAMediaTimingFunction *)sharpEaseInOut {
return [CAMediaTimingFunction functionWithControlPoints:0.62 :0.0 :0.38 :1.0];
}
@end
//
// MBProgressHUD+XW.h
// handehrms
//
// Created by xiaowei on 16/9/20.
// Copyright © 2016年 xiaowei. All rights reserved.
//
#import "MBProgressHUD.h"
@interface MBProgressHUD (XW)
+ (void)showSuccess:(NSString *)success view:(UIView *)view;
+ (void)showError:(NSString *)error view:(UIView *)view;
+ (void)showError:(NSString *)error;
+ (void)showSuccess:(NSString *)success;
+ (void)showRequestLoad:(NSString *)text toView:(UIView *)toview;
+ (void)hideRequestLoad:(UIView *)view;
+ (void)showInterminateWithView:(UIView *)view;
+ (void)showNoOffset:(NSString *)text toView:(UIView *)toview;
+ (void)customShowLoading:(UIView *)view;
@end
//
// MBProgressHUD+XW.m
// handehrms
//
// Created by xiaowei on 16/9/20.
// Copyright © 2016年 xiaowei. All rights reserved.
//
#import "MBProgressHUD+XW.h"
#import "DRPLoadingSpinner.h"
@implementation MBProgressHUD (XW)
+ (void)show:(NSString *)text image:(NSString *)img toView:(UIView *)toView{
if(toView == nil){
toView = [[[UIApplication sharedApplication] windows] lastObject];
}
dispatch_async(dispatch_get_main_queue(), ^{
MBProgressHUD *hub = [MBProgressHUD showHUDAddedTo:toView animated:YES];
//配置
hub.label.text = text;
hub.customView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:img]];
hub.mode = MBProgressHUDModeCustomView;
hub.animationType = MBProgressHUDAnimationZoomOut;
hub.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
hub.bezelView.backgroundColor = [UIColor colorWithWhite:.1 alpha:.9];
hub.label.textColor = [UIColor whiteColor];
hub.removeFromSuperViewOnHide = YES;
//设置蒙版效果
// hub.dimBackground = YES;
//设置隐藏的时间
[hub hideAnimated:YES afterDelay:1.2];
});
}
+ (void)showSuccess:(NSString *)success{
[self show:success image:@"progress_success" toView:nil];
}
+ (void)showError:(NSString *)error{
[self show:error image:@"progress_error" toView:nil];
}
+ (void)showSuccess:(NSString *)success view:(UIView *)view{
[self show:success image:@"progress_success" toView:view];
}
+ (void)showError:(NSString *)error view:(UIView *)view{
[self show:error image:@"progress_error" toView:view];
}
+ (void)showRequestLoad:(NSString *)text toView:(UIView *)toview{
if(toview == nil){
UIViewController *ctrl = [self getTopViewControllerWithCtrl:nil];
if(ctrl){
toview = ctrl.presentedViewController ? ctrl.presentedViewController.view : ctrl.view;
}else{
NSArray *list = [[UIApplication sharedApplication] windows];
if(![NSStringFromClass([[list lastObject] class]) isEqualToString:@"UITextEffectsWindow"]){
for (UIView *v in list) {
if([NSStringFromClass([v class]) isEqualToString:@"UITextEffectsWindow"]){
toview = v;
}
}
if(toview == nil){
toview = [list lastObject];
}
}else{
toview = [list lastObject];
}
}
}
dispatch_async(dispatch_get_main_queue(), ^{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:toview animated:YES];
// Set the custom view mode to show any view.
hud.mode = MBProgressHUDModeCustomView;
DRPLoadingSpinner *loadingView = [[DRPLoadingSpinner alloc] init];
loadingView.colorSequence = @[[UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1]];
[loadingView startAnimating];
hud.customView = loadingView;
// hud.offset = CGPointMake(0, -64);
hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.bezelView.backgroundColor = [UIColor clearColor];
if(text){
hud.backgroundColor = [UIColor clearColor];
}else{
hud.backgroundColor = [UIColor whiteColor];
}
hud.animationType = MBProgressHUDAnimationZoom;
[hud setRemoveFromSuperViewOnHide:YES];
});
}
//获取当前显示的控制器
+ (UIViewController *)getTopViewControllerWithCtrl:(UIViewController *)vc{
UIViewController *current;
if(vc == nil){
vc = [UIApplication sharedApplication].keyWindow.rootViewController;
}
if([vc isKindOfClass:[UITabBarController class]]){
return [self getTopViewControllerWithCtrl:[(UITabBarController *)vc selectedViewController]];
}else if ([vc isKindOfClass:[UINavigationController class]]){
return [self getTopViewControllerWithCtrl:[(UINavigationController *)vc visibleViewController]];
}else{
current = vc;
}
return current;
}
+ (void)showNoOffset:(NSString *)text toView:(UIView *)toview{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:toview animated:YES];
// Set the custom view mode to show any view.
hud.mode = MBProgressHUDModeCustomView;
NSMutableArray *animationList = [NSMutableArray array];
for (NSInteger i=0; i<47; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"custom_000%02ld",i+1]];
[animationList addObject:image];
}
UIImageView *imgView = [[UIImageView alloc] init];
imgView.animationImages = animationList;
imgView.animationDuration = 0.8;
[imgView startAnimating];
hud.customView = imgView;
// hud.customView.layer.cornerRadius = 25;
// hud.customView.layer.masksToBounds = YES;
hud.offset = CGPointMake(0, -64);
hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.bezelView.backgroundColor = [UIColor clearColor];
hud.backgroundColor = [UIColor whiteColor];
hud.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
hud.animationType = MBProgressHUDAnimationZoomIn;
// [hud hideAnimated:YES afterDelay:5.f];
[hud setRemoveFromSuperViewOnHide:YES];
}
+ (void)showInterminateWithView:(UIView *)view{
if(view == nil){
view = [[[UIApplication sharedApplication]windows] lastObject];
}
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.bezelView.backgroundColor = [UIColor clearColor];
}
+ (void)hideRequestLoad:(UIView *)view{
if(view == nil){
UIViewController *ctrl = [self getTopViewControllerWithCtrl:nil];
if(ctrl){
view = ctrl.presentedViewController ? ctrl.presentedViewController.view : ctrl.view;
}else{
NSArray *list = [[UIApplication sharedApplication] windows];
if(![NSStringFromClass([[list lastObject] class]) isEqualToString:@"UITextEffectsWindow"]){
for (UIView *v in list) {
if([NSStringFromClass([v class]) isEqualToString:@"UITextEffectsWindow"]){
view = v;
}
}
if(view == nil){
view = [list lastObject];
}
}else{
view = [list lastObject];
}
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:view animated:YES];
});
}
+ (void)customShowLoading:(UIView *)view {
if(view == nil){
UIViewController *ctrl = [self getTopViewControllerWithCtrl:nil];
if(ctrl){
view = ctrl.presentedViewController ? ctrl.presentedViewController.view : ctrl.view;
}else{
NSArray *list = [[UIApplication sharedApplication] windows];
if(![NSStringFromClass([[list lastObject] class]) isEqualToString:@"UITextEffectsWindow"]){
for (UIView *v in list) {
if([NSStringFromClass([v class]) isEqualToString:@"UITextEffectsWindow"]){
view = v;
}
}
if(view == nil){
view = [list lastObject];
}
}else{
view = [list lastObject];
}
}
}
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
// Set the custom view mode to show any view.
hud.mode = MBProgressHUDModeCustomView;
NSMutableArray *animationList = [NSMutableArray array];
for (NSInteger i=0; i<47; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"custom_000%02ld",i+1]];
[animationList addObject:image];
}
UIImageView *imgView = [[UIImageView alloc] init];
imgView.animationImages = animationList;
imgView.animationDuration = 0.8;
[imgView startAnimating];
hud.customView = imgView;
hud.offset = CGPointMake(0, -64);
hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.bezelView.backgroundColor = [UIColor clearColor];
hud.backgroundColor = [UIColor whiteColor];
hud.animationType = MBProgressHUDAnimationZoom;
[hud setRemoveFromSuperViewOnHide:YES];
}
@end
This diff is collapsed.
This diff is collapsed.
//
// DetailController.h
// CordBradge-OC
//
// Created by Mr.xiao on 17/2/14.
// Copyright © 2017年 keepJion. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Cordova/CDVViewController.h>
@protocol WebPluginProtocol<NSObject>
- (void)webViewDidSuccessLoad;
- (void)webViewDidFailedLoad;
@end
@interface WebPluginController : CDVViewController
@property (nonatomic ,copy) NSString *fileUrl;
@property (nonatomic, weak) id<WebPluginProtocol> delegate;
@property (nonatomic, strong) id <CDVCommandDelegate> openDelegate;
@end
//
// DetailController.m
// CordBradge-OC
//
// Created by Mr.xiao on 17/2/14.
// Copyright © 2017年 keepJion. All rights reserved.
//
#import "WebPluginController.h"
#import "CDVSplashScreen.h"
#import "MBProgressHUD+XW.h"
@interface WebPluginController ()<UIGestureRecognizerDelegate>
@property (nonatomic,strong) UILabel *titleLalel;
@property (nonatomic,strong) UIWebView *baseView;
@end
@implementation WebPluginController
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didLunch:) name:CDVPageDidLoadNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didStart:) name:CDVPluginResetNotification object:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
[MBProgressHUD showRequestLoad:nil toView:self.view];
self.view.backgroundColor = [UIColor whiteColor];
// Do any additional setup after loading the view.
self.webView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) );
self.webView.backgroundColor = [UIColor whiteColor];
if(@available(iOS 11.0,*)){
self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
//MARK: ACTION
- (void)didLunch:(NSNotification *)not{
[MBProgressHUD hideRequestLoad:self.view];
if([self.delegate respondsToSelector:@selector(webViewDidSuccessLoad)]){
[self.delegate webViewDidSuccessLoad];
}
}
- (void)didStart:(NSNotification *)not{
}
/*
重写CDVViewController方法,这样就可以根据自己的需要加载插件了
这里是不加载 CDVSplashScreen 这个插件
*/
- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className
{
if([className isEqualToString:@"CDVSplashScreen"]){
return;
}
[super registerPlugin:plugin withClassName:className];
}
- (UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleDefault;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
var exec = require('cordova/exec');
var WebViewPlugin = {
loadWebView: function (successCallback, errorCallback, options) {
if (errorCallback == null) {
errorCallback = function () {
}
}
if (typeof errorCallback != "function") {
return
}
if (typeof successCallback != "function") {
return
}
exec(successCallback, errorCallback, "WebViewPlugin", "loadWebView", [options]);
},
//dismissWebView
dismissWebView: function (successCallback, errorCallback, options) {
if (errorCallback == null) {
errorCallback = function () {
}
}
if (typeof errorCallback != "function") {
return
}
if (typeof successCallback != "function") {
return
}
exec(successCallback, errorCallback, "WebViewPlugin", "dismissWebView", [options]);
}
};
if (typeof module !== 'undefined' && module.exports) {
module.exports = WebViewPlugin;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment