Android can now call Angular!

This commit is contained in:
Bradlee Speice 2014-09-01 12:28:51 -04:00
parent 799091b6e4
commit e20e42b7bd
4 changed files with 31215 additions and 13 deletions

File diff suppressed because one or more lines are too long

View File

@ -22,7 +22,7 @@ gulp.task('watch', function() {
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('book-bundle.js'))
.pipe(buffer())
.pipe(uglify())
//.pipe(uglify()) // Since Android needs to call in, can't minify
.pipe(gulp.dest('./dist'));
}

View File

@ -1,4 +1,4 @@
require 'jquery' # For using selectors to access scope
$ = require 'jquery' # For using selectors to access scope
require 'angular'
app = angular.module('bookApp', [])
@ -8,10 +8,21 @@ app.controller 'BookCtrl', ['$scope', ($scope) ->
{'text': 'hello.'}
];
$scope.alert = ->
alert "Hello!"
$scope.appendVerse = (text) ->
$scope.verses.push {'text': text}
]
# Due to page initialization, we can only store the controller string.
# The actual element changes, so there's nothing we can do with JQuery
# etc. to grab the scope ahead of time and re-use it.
controller = "#bookController"
window.appendVerse = (text) ->
scope = angular.element($("#bookController")).scope()
scope.appendVerse text
# Since we're calling outside of angular, we need to manually apply
scope.$apply()
###
Future reference: Get the controller scope like so:
angular.element($("<controller-element>")).scope().<function>

View File

@ -113,7 +113,8 @@ public class BookFragment extends BaseFragment {
Verse initial = new Verse(vUtil.getVersification(mBook.get()),
BibleBook.GEN, 1, 1);
super.onPageFinished(view, url);
// invokeJavascript("set_content", lookupService.getHTMLVerse(initial));
// invokeJavascript("appendVerse", lookupService.getHTMLVerse(initial));
invokeJavascript("appendVerse", "Testing string...");
}
@Override
@ -124,7 +125,7 @@ public class BookFragment extends BaseFragment {
}
});
// TODO: Remove remote debugging when ready
// TODO: Remove remote debugging when ready - or should this be removed?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}