By Andrea Stagi, deveLover @ Nephila
public class MyActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.content_layout_id);
final Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
}
});
}
}
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/self_destruct"
android:onClick="selfDestruct" />
@ContentView(R.layout.content_layout_id)
class MyActivity extends RoboActivity {
@InjectView(R.id.button_id) Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
}
});
}
}
.controller('NewVotesCtrl', function($scope) {
$scope.nextPage = function() {
// Do things
};
})
<a class="button" ng-click="nextPage()">
Next
</a>
public class MainActivity extends CordovaActivity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
loadUrl(launchUrl);
}
}
You can find all the code on Github
https://github.com/DjangoBeer/ionic-we
<!DOCTYPE html>
<html>
<head>
</head>
<body ng-app="starter">
<ion-nav-view></ion-nav-view>
</body>
</html>
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: "/app",
templateUrl: "templates/menu.html",
controller: 'MenuCtrl'
})
.state('login', {
url: "/login",
templateUrl: "templates/login.html",
controller: 'LoginCtrl'
})
$urlRouterProvider.otherwise('/app');
});
.controller('MenuCtrl', function($scope, $state) {
$scope.goLogin = function() {
$state.go('login');
};
$scope.goVotes = function() {
$state.go('vote');
};
$scope.goWall = function() {
$state.go('wall');
};
$scope.goMap = function() {
$state.go('map');
};
});
cordova.exec(
function(winParam) {},
function(error) {},
"service",
"action",
["hello", 42, false]
);
var fn_buy = function (success, fail, productId) {
if (this.options.showLog) {
log('buy called!');
}
return cordova.exec(
success,
fail,
"InAppBillingPlugin",
"buy",
[productId]
);
};
InAppBilling.prototype.buy = fn_buy;
public class Echo extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args,
CallbackContext callbackContext)
throws JSONException {
if (action.equals("echo")) {
String message = args.getString(0);
this.echo(message, callbackContext);
return true;
}
return false;
}
private void echo(String message, CallbackContext
callbackContext) {
if (message != null && message.length() > 0) {
callbackContext.success(message);
} else {
callbackContext.error(
"Expected one non-empty string argument."
);
}
}
}
public class InAppBillingPlugin extends CordovaPlugin {
//...
public boolean execute(String action, JSONArray data,
final CallbackContext callbackContext) {
this.callbackContext = callbackContext;
Boolean isValidAction = true;
try {
// Action selector
if ("init".equals(action)) {
// ...
} else if ("buy".equals(action)) {
final String sku = data.getString(0);
buy(sku);
} else {
// No handler for the action
isValidAction = false;
}
} catch (IllegalStateException e){
// ....
}
return isValidAction;
}
To be continued...
private void buy(final String sku){
final String payload = "";
if (mHelper == null){
callbackContext.error(
IabHelper.ERR_PURCHASE + "|Not initialized"
);
return;
}
this.cordova.setActivityResultCallback(this);
mHelper.launchPurchaseFlow(
cordova.getActivity(),
sku, RC_REQUEST,
mPurchaseFinishedListener, payload
);
}
@Override
public void onDestroy() {
super.onDestroy();
// Shutdown stuff cause you're a clean coder
}
}
( ... )
$ cd myAppFolder
$ cordova plugin add org.apache.cordova.camera
angular.module('myservices', [])
.factory('Camera', ['$q', function($q) {
return {
getPicture: function(options) {
var q = $q.defer();
navigator.camera.getPicture(function(result) {
q.resolve(result);
}, function(err) {
q.reject(err);
}, options);
return q.promise;
}
}
}]);
Pick a photo
(native intent)
angular.module('mydirectives', [])
.directive('tilewall', function () {
return {
scope: {
size: '@',
ngModel: '=',
},
controller: function ($scope) {
$scope.tiles = Array();
for (var i = 0 ; i < parseInt($scope.size) ; i++) {
$scope.tiles.push(i);
}
$scope.setTileValue = function(value) {
$scope.ngModel = value;
};
},
template: 'tile.html'
};
})
<button ng-click="setTileValue(tile+1)"
ng-repeat="tile in tiles">
{{ tile + 1 }}
</button>
<ion-view view-title="TileWall">
<ion-content>
<div>{{tileval}}</div>
<tilewall size=100 ng-model='tileval'>
</tilewall>
</ion-content>
</ion-view>
var TilesList = React.createClass({
render: function() {
var that = this;
return <tbody>{
this.props.tiles.map(function(tile, i) {
return <button className="styles"
onClick={that.props.clickHandler.bind(that, tile + 1)}>
{tile + 1}
</button>
})
}</tbody>;
}
});
// Inside your directive
controller: function ($scope) {
$scope.tiles = Array();
for (var i = 0 ; i < parseInt($scope.size) ; i++) {
$scope.tiles.push(i);
}
$scope.setTileValue = function(value) {
$scope.ngModel = value;
$scope.$apply();
};
},
link:function(scope, el, attrs){
scope.$watch('tiles', function(newValue, oldValue){
React.render(
<TilesList tiles={newValue}
clickHandler={scope.setTileValue}
/>, el[0]
);
})
}
//...
@4STAGI
github.com/astagi
a.stagi@nephila.it