Skip to content

Commit

Permalink
Merge pull request #20 from telefonicaid/feature/prepareRelease
Browse files Browse the repository at this point in the history
feature/prepareRelease. Minor updates for the final 1.2.0 release!
  • Loading branch information
davidgarsan committed Jul 16, 2014
2 parents 3575630 + 26bcf18 commit 947dfc0
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 88 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ Pods
*/*/gen/
*/*/build/

# Web
.idea

# Development
node_modules
bower_components
6 changes: 3 additions & 3 deletions Hybridge.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Hybridge"
s.version = "1.1.0"
s.version = "1.2.0"
s.summary = "Yet another javascript / mobile native simple bridge for hybrid apps, back and forth..."

s.description = <<-DESC
Expand All @@ -12,11 +12,11 @@ Pod::Spec.new do |s|

s.license = { :type => "Affero GNU GPL v3", :file => "LICENSE.txt" }

s.authors = { 'David Garcia' => '[email protected]', 'Guillermo Gonzalez' => '[email protected]' }
s.authors = { 'David Garcia' => '[email protected]', 'Guillermo Gonzalez' => '[email protected]' }

s.platform = :ios
s.ios.deployment_target = "6.0"
s.source = { :git => "https://github.com/gonzalezreal/tdigital-hybridge.git", :branch => "refactoring-ios" }
s.source = { :git => "https://github.com/telefonicaid/tdigital-hybridge.git", :tag => "1.2.0" }

s.source_files = "ios/Hybridge/Hybridge/*.{h,m}"
s.private_header_files = "ios/Hybridge/Hybridge/HYBURLProtocol.h", "ios/Hybridge/Hybridge/NSString+Hybridge.h"
Expand Down
65 changes: 43 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Yet another javascript / mobile native simple bridge for hybrid apps, back and f
## <a name='index'>Index</a>

1. [Why?](#why)
1. [Getting Started](#start)
* [Dependencies](#dependencies)
* [Javascript](#dependencies_javascript)
1. [Installation](#installation)
* [Javascript](#installation_javascript)
* [Android](#installation_android)
* [iOS](#installation_ios)
1. [Usage](#usage)
* [Javascript](#usage_javascript)
* [Android](#usage_android)
Expand All @@ -31,14 +32,41 @@ Hybridge tries to make easy communication and data exchanging between native (iO

**[[]](#index)**

## <a name='start'>Getting Started</a>
Firstly, get the code by downloading the zip or cloning the project into your local.
## <a name='installation'>Installation</a>
Hybridge follows [semantic versioning](http://semver.org/). In the `boilerplate` directory you can find examples of how to get running in the different platforms.

### <a name='dependencies'>Dependencies</a>
#### <a name='dependencies_javascript'>Javascript</a>
Hybridge works in an AMD fashion, so you'll need [RequireJS](http://requirejs.org) for the loading.
### <a name='installation_javascript'>Javascript</a>

Since v1.2.0, `hybridge` is available in [bower](http://bower.io/). Bower will install `hybridge` itself and all its dependencies.
```sh
bower install --save hybridge
```

Add it to your HTML
```html
<script type="text/javascript" src="bower_components/hybridge/js/hybridge.js"></script>
```

You can manually download the javascript [js/hybridge.js](js/hybridge.js) and use the traditional way.

Hybridge works in both an AMD/Vanilla javascript fashion. For vanilla javascript, it's available in `window.Hybridge` variable.
You'll also need [JQuery](http://jquery.com) (version 1.8.3 or newer) for the Javascript part since [Deferred](http://api.jquery.com/category/deferred-object) object is used intensively.


### <a name='installation_android'>Android</a>

You can build your own Hybridge, but you can start with the latest version included at [hybridge.jar](boilerplate/android/HybridgeBoilerplate/libs/hybridge-1.2.0.jar) in the boilerplate code.

### <a name='installation_ios'>iOS</a>

Add the following to your `Podfile` and run `$ pod install`.

``` ruby
pod 'Hybridge'
```

If you don't have CocoaPods installed or integrated into your project, you can learn how to do so [here](http://cocoapods.org).

**[[]](#index)**

## <a name='usage'>Usage</a>
Expand All @@ -57,13 +85,12 @@ Load `hybridge.js` as a module in your AMD code. Simplest setup:
require.config({
baseUrl: 'js/lib',
paths: {
jquery: 'jquery',
hybridge: 'hybridge'
jquery: 'bower_components/jquery/dist/jquery',
hybridge: 'bower_components/hybridge/js/hybridge'
}
});
requirejs(['hybridge'],
function (Hybridge) {
require(['hybridge'], function (Hybridge) {
Hybridge.init({
'environment' : 'ios'
}
Expand Down Expand Up @@ -116,6 +143,7 @@ public class DownloadTask extends AsyncTask<Object, Void, JSONObject> {

private JsPromptResult result;
private Context context;
private HybridgeBroadcaster hybridge;

public DownloadTask(Context context) {
this.context = context;
Expand All @@ -125,6 +153,7 @@ public class DownloadTask extends AsyncTask<Object, Void, JSONObject> {
protected JSONObject doInBackground(Object... params) {
JSONObject json = (JSONObject) params[0];
result = (JsPromptResult) params[1];
hybridge = (HybridgeBroadcaster) params[2];
// Process download
...
return json;
Expand Down Expand Up @@ -161,14 +190,6 @@ public void update(Observable observable, Object data) {
**[[]](#index)**

### <a name='usage_ios'>iOS</a>
#### Installation
Add the following to your `Podfile` and run `$ pod install`.

``` ruby
pod 'Hybridge'
```

If you don't have CocoaPods installed or integrated into your project, you can learn how to do so [here](http://cocoapods.org).

#### Creating a Web View Controller
Hybridge provides `HYBWebViewController`, a convenience view controller that hosts both a web view and a bridge object to communicate with it. Users are encouraged to subclass `HYBWebViewController` and specify any supported bridge actions.
Expand Down Expand Up @@ -198,7 +219,7 @@ There are two different ways to handle bridge actions:
} else if ([action isEqualToString:@"some_other_action"]) {
// Handle 'some_other_action'
}

// Return a JSON dictionary or `nil`
return nil;
}
Expand Down Expand Up @@ -248,7 +269,7 @@ HybridgeBroadcaster.getInstance(mWebView).fireJavascriptEvent(webView, Event.REA
```

### <a name='events_ios'>iOS</a>
Hybridge provides an `UIWebView` category that sports a convenience method to trigger events on the Javascript side.
Hybridge provides an `UIWebView` category that sports a convenience method to trigger events on the Javascript side.

```objc
[self.webView hyb_fireEvent:HYBEventMessage data:@{ @"foo": @"bar" }];
Expand Down
6 changes: 3 additions & 3 deletions android/Hybridge/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pdi.hybridge"
android:versionCode="1"
android:versionName="1.0" >
android:versionCode="120"
android:versionName="1.2.0" >

<uses-sdk android:minSdkVersion="12" />

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ private HybridgeBroadcaster() {
public void initJs(WebView view, JSONArray actions, JSONArray events) {
runJsInWebView(view, "window.HybridgeGlobal || setTimeout(function () {"
+ "window.HybridgeGlobal = {" + " isReady : true" + ", version : "
+ HybridgeConst.VERSION + ", actions : " + actions.toString() + ", events : "
+ events.toString() + "};"
+ HybridgeConst.VERSION + ", versionMinor : " + HybridgeConst.VERSION_MINOR
+ ", actions : " + actions.toString() + ", events : " + events.toString() + "};"
+ "(window.document.getElementById('hybridgeTrigger') || {}).className = 'switch';"
+ "},0)");
mIsInitialized = true;
Expand Down
6 changes: 2 additions & 4 deletions android/Hybridge/src/com/pdi/hybridge/HybridgeConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
public class HybridgeConst {

public static final int VERSION = 1;
public static final int VERSION_MINOR = 2;

public static final String EVENT_NAME = "event";

public enum Event {
PAUSE("pause"),
RESUME("resume"),
MESSAGE("message"),
READY("ready");
PAUSE("pause"), RESUME("resume"), MESSAGE("message"), READY("ready");

private String jsName;

Expand Down
2 changes: 1 addition & 1 deletion android/Hybridge/version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#Version = ${build.platform.number}.${build.major.number}.${build.minor.number}

build.revision.number=1
build.major.number=0
build.major.number=2
build.minor.number=0
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

package com.pdi.hybridge.boilerplate;

import java.util.Observable;
import java.util.Observer;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
Expand All @@ -21,47 +15,74 @@

import com.pdi.hybridge.HybridgeBroadcaster;
import com.pdi.hybridge.HybridgeConst;
import com.pdi.hybridge.HybridgeConst.Event;
import com.pdi.hybridge.HybridgeWebChromeClient;
import com.pdi.hybridge.HybridgeWebViewClient;
import com.pdi.hybridge.HybridgeConst.Event;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Observable;
import java.util.Observer;

public class MainActivity extends Activity implements Observer {

private String mTag = "MainActivity";
private WebView mWebView;

private HybridgeBroadcaster mHybridge;

// String keys for JSON data user in Hybridge communication
public static final String JSON_KEY_INIT = "initialized";

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
HybridgeBroadcaster.getInstance().addObserver(this);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(webViewClient);
mWebView.setWebChromeClient(webChromeClient);
mHybridge = HybridgeBroadcaster.getInstance(mWebView);
// Set the URL of your web app
mWebView.loadUrl("http://localhost/hybridge.html");
mWebView.loadUrl("http://192.168.1.40/hybridge.html");
}

private final HybridgeWebViewClient webViewClient = new HybridgeWebViewClient(JsActionImpl.values());
private final HybridgeWebViewClient webViewClient = new HybridgeWebViewClient(
JsActionImpl.values());

private final WebChromeClient webChromeClient = new HybridgeWebChromeClient(
JsActionImpl.values());

private final WebChromeClient webChromeClient = new HybridgeWebChromeClient(JsActionImpl.values());

@Override
public void update(Observable observable, Object data) {
JSONObject json = (JSONObject) data;
final JSONObject json = (JSONObject) data;
if (json.has(HybridgeConst.EVENT_NAME)) {
try {
HybridgeBroadcaster.getInstance().fireJavascriptEvent(mWebView, (Event) json.get(HybridgeConst.EVENT_NAME), json);
} catch (JSONException e) {
mHybridge.fireJavascriptEvent(mWebView, (Event) json.get(HybridgeConst.EVENT_NAME),
json);
} catch (final JSONException e) {
Log.e(mTag, "Problem with JSON object " + e.getMessage());
}
} else {
HybridgeBroadcaster.getInstance().fireMessage(mWebView, json);
mHybridge.fireMessage(mWebView, json);
}
}

/**
* Callback invoke once the fragment is created.
*
* @see android.app.Fragment#onResume()
*/
@Override
public void onResume() {
mHybridge.addObserver(this);
super.onResume();
}

@Override
public void onPause() {
mHybridge.deleteObserver(this);
super.onPause();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

package com.pdi.hybridge.boilerplate.action;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
Expand All @@ -19,27 +16,32 @@
import com.pdi.hybridge.HybridgeConst;
import com.pdi.hybridge.boilerplate.MainActivity;

import org.json.JSONException;
import org.json.JSONObject;

public class InitTask extends AsyncTask<Object, Void, JSONObject> {

private final String mTag = "InitTask";
private JsPromptResult result;
private Context context;
private JsPromptResult mResult;
private Context mContext;
private HybridgeBroadcaster mHybridge;

public InitTask(Activity activity) {
this.context = activity.getApplicationContext();
mContext = activity.getApplicationContext();
}

@Override
protected JSONObject doInBackground(Object... params) {
JSONObject json = (JSONObject) params[0];
result = (JsPromptResult) params[1];
final JSONObject json = (JSONObject) params[0];
mResult = (JsPromptResult) params[1];
mHybridge = (HybridgeBroadcaster) params[2];

try {
if (json.has(MainActivity.JSON_KEY_INIT)) {
json.put(HybridgeConst.EVENT_NAME, HybridgeConst.Event.READY);
HybridgeBroadcaster.getInstance().updateState(json);
mHybridge.updateState(json);
}
} catch (JSONException e) {
} catch (final JSONException e) {
Log.e(mTag, "Download: Problem with JSON object " + e.getMessage());
}

Expand All @@ -53,7 +55,7 @@ protected void onPreExecute() {

@Override
protected void onPostExecute(JSONObject json) {
result.confirm(json.toString());
mResult.confirm(json.toString());
}

}
}
2 changes: 1 addition & 1 deletion boilerplate/ios/HybridgeSample/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# platform :ios, "6.0"

target "HybridgeSample" do
pod 'Hybridge', :path => '../../../'
pod 'Hybridge', :path => '../../..'
end

target "HybridgeSampleTests" do
Expand Down
8 changes: 4 additions & 4 deletions boilerplate/ios/HybridgeSample/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
PODS:
- Hybridge (1.1.0)
- Hybridge (1.2.0)

DEPENDENCIES:
- Hybridge (from `../../../`)
- Hybridge (from `../../..`)

EXTERNAL SOURCES:
Hybridge:
:path: ../../../
:path: ../../..

SPEC CHECKSUMS:
Hybridge: 5ace862416316c8eaee9df4c1c5b8c6f21b938e8
Hybridge: 9c0600c2faf4ba43b2c66b9fbbc714ce7cbfdc8d

COCOAPODS: 0.33.1
Loading

0 comments on commit 947dfc0

Please sign in to comment.