Création des Logiciels de gestion d'Entreprise, Création et référencement des sites web, Réseaux et Maintenance, Conception
Création des Logiciels de gestion d'Entreprise, Création et référencement des sites web, Réseaux et Maintenance, Conception
{2. In the Chrome manifest, we specified the relevant file types to which the service applies. In our case, that's most file types, as seen below. Specialized services may just want certain types, such as images for Picasa.
"name”: "Box Uploader",
...
"file_browser_handlers": [
{
"id”: "upload",
"default_title": "Save to Gallery", // What the button will display
"file_filters": [
]
}
],
"file_browser_handlers": [3. With some JavaScript code connecting to the file browser handler, we set up a way to upload files through Box’s Quick Importer.
{
"id": "upload",
"default_title": "Save to Box",
"file_filters": [
"filesystem:*.*"
]
}
],
var fm = new FileManager();That's actually all there was to the integration.
fm.uploadServer = 'https://www.box.net/<...>';
if (bgPage && bgPage.filesToUpload.length) {
var entry;
while(entry = bgPage.filesToUpload.pop()) {
entry.file(function(file) {
fm.uploadFile(file);
});
}
}
One of the most exciting aspects of Google's Android platform is the rapid release pace, so support for cutting-edge technologies can be included in the platform early on. As engineers, we're excited about such features, because we like to tinker and test the limits of new technologies. But the real challenge is using these new capabilities to integrate easy-to-use features for end-users, so that everyone can be excited. The introduction of the Near-Field Communication (NFC) API in Android 2.3, accompanying the release of an NFC hardware feature in Google's Nexus S, gave us the opportunity to do just that.
NFC is meant to send and receive small amounts of data. This data can be read from passive (non-powered) devices (e.g. credit cards or interactive posters), or active devices (e.g. payment kiosks). NFC can also be used to communicate between two NFC-equipped devices thanks to a protocol introduced by Google which defines a way for two active devices to exchange NFC messages that follow the NFC Data Exchange Format (NDEF) specification. This protocol (NDEF Push Protocol (NPP)) is implemented in Android 2.3.3 and beyond.
The NPP is very simple: it allows us to send an NDEF message to another device, which will then process the message as if it had been read from a passive tag. Thus, to understand how to use NPP, we need only to understand the NDEF message. An NDEF message is a collection of NDEF records. An NDEF record is a short header describing the contents of the record’s data payload, and then the data payload.
This new NFC/NPP capability enables the exchange of a few hundred bytes of information in a well-defined format between devices, using proximity as a method for instigation and authentication. In other words, we can now share a small amount of data between two devices without going through the normal steps of pairing or association that are required by more conventional (and higher-bandwidth) avenues like Bluetooth or WiFi—the fact that the two phones are in close proximity is enough evidence to convince the NFC software that the devices are eligible to receive information from each other.
The NFC API for Android handles all of the details of receiving and parsing NFC messages. It then decides what to do with the message by investigating the intent filters registered for applications on the device. In some cases the messages may have characteristics that can lead to finer-grained dispatching. In the case of an NDEF message, you can register for NFC messages at varying levels of detail: from as vague as any NDEF message to as detailed as an NDEF message containing a URI matching a given pattern. A pleasant result of this approach is that the operating system can have "catch-all" applications for messages that have unknown details.
Let’s consider a possible application of the NFC technology in the context of the doubleTwist app. If you’re listening to a song and you want to share the details of the song with your friend, how can NFC help with this? Well, we can use NFC to bundle up a small bit of information about the song in a well-defined format, which the other phone can then parse and use to display information about the song. We will pass the metadata in a single NDEF Record containing a JSON object.
To ensure that our message is routed to doubleTwist on the receiving phone, we rely on Android's ability to dispatch messages based on the data type of the payload, signaled by setting the the type name field to TNF_MIME_MEDIA. This indicates that the type field of the NDEF record should be a MIME type as specified by RFC2046. To take advantage of this capability, we create our own custom MIME type to use in the type field. Since the NDEF message must be composed of bytes, we’ll also need to convert the strings into byte arrays. The code for all of this looks like this:
//Assume that musicService is an interface to our music
//playback service
JSONObject songMetadata = new JSONObject();
String title = musicService.getCurrentTrackTitle();
String artist = musicService.getCurrentTrackArtist();
String album = musicService.getCurrentTrackAlbum();
songMetadata.put(“title”, title);
songMetadata.put(“artist”, artist);
songMetadata.put(“album”, album);
String mimeType = "application/x-doubletwist-taptoshare";
byte[] mimeBytes = mimeType.getBytes(Charset.forName("UTF-8"));
String data = songMetadata.toString();
byte[] dataBytes = data.getBytes(Charset.forName("UTF-8"));
byte[] id = new byte[0]; //We don’t use the id field
r = NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, id, dataBytes);
NdefMessage m = new NdefMessage(new NdefRecord[]{r});
Similarly, our application registers an Intent filter to define the Activity that will handle NFC messages that match this mime type. So, when another phone running doubleTwist receives our message, doubleTwist will have priority in processing the message. To do this, we add an <intent-filter>
element to AndroidManifest.xml's entry for the activity that should launch to handle this NDEF message:
<activity name="SongInfoShare">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<data android:mimeType="application/x-doubletwist-taptoshare" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
The SongInfoShare activity will be started whenever the NFC radio receives our special message from another NFC-capable phone. In the onCreate method for this activity, we can check the action for the intent that started to activity to verify that it’s the NDEF_DISCOVERED action, and then use the normal intent helper methods to get the NFC message data from the Intent. Here’s what the code will look like for our info-sharing example:
public class SongInfoShare extends Activity {
…
public void onCreate(Bundle b) {
if(android.nfc.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction()) {
Parcelable[] msgs =
b.getParcelableArray(NfcAdapter.EXTRA_NDEF_MESSAGES);
if(msgs != null && msgs.length > 0) {
NdefMessage m = (NdefMessage)msgs[0];
NdefRecord[] r = m.getRecords();
JSONObject sharedInfo = null;
if(r != null && r.length > 0) {
try {
String payload = new String(r[0].getPayload());
sharedInfo = new JSONObject(payload);
} catch (JSONException e) {
Log.d(TAG, "Couldn't get JSON: ",e);
}
}
//At this point, we can use the contents of
//sharedInfo to set up the contents of the activity.
So, now we’re able to easily pass along song information to a friend by simply bringing the NFC radios close together. No cutting, pasting, tapping, or searching for options in menus!
So, what happens if our friend isn’t running doubleTwist? Well, the stock Android NFC handler app can help us. It will display any text or link records contained in the NDEF message it receives. So, for example, we can also share a pre-formatted link that will do a Google search for the song information. To achieve this, we can modify the end of our first code example as follows:
r1 = NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, id, dataBytes);
String query = UrlEncoder.encode("\""+artist+"/" /""+title"\"", "UTF-8");
String searchLink = "http://www.google.com/?q="+query;
byte[] searchBytes = data.getBytes(Charset.forName("UTF-8"));
NdefRecord r2 = new NdefRecord(
NdefRecord.TNF_ABSOLUTE_URL, searchBytes, id, searchBytes);
NdefMessage m = new NdefMessage(new NdefRecord[]{r1, r2});
Now, in the case where the receiving user doesn’t have doubleTwist installed, they will at least be presented with a link that they can click on to begin a Google search for more information about the song.
The first version of Google’s NDEF Push Protocol API has allowed us to bring some novel enhancements to our app using one of the newest available handset technologies. We are looking forward to further development of device-to-device NFC APIs that will allow even richer inter-device communication using just a tap!
request: function(formdata) {This function is called when the user clicks Submit in the search tab of the YouTube source in the Storify Editor. The main controller executes the request and sends the JSON result to the results method, which returns an array of normalized results:
return {
'url' : 'http://gdata.youtube.com/feeds/api/videos',
'params': {
'v' : 2,
'max-results' : 20,
'alt' : 'jsonc',
'q' : formdata.keywords
}
};
}
results: function(json) {
if (json.data && json.data.totalItems && json.data.totalItems == 0) {
throw "No results found";
}
var videos = json.data.items;
var results_array = [];
for (var i = 0; i < videos.length; i++) {
var normalizedResult = {
permalink : 'http://www.youtube.com/watch?v='+videos[i].id,
source : 'youtube',
elementClass : 'video',
metadata : videos[i],
thumbnail : videos[i].thumbnail.sqDefault,
title: videos[i].title,
description : videos[i].description.substr(0,140),
author: {username: videos[i].uploader },
created_at : videos[i].uploaded,
oembed: {html: '<iframe id="youtube-'+videos[i].id+'" type="text/html" width="360" height="294" src="http://www.youtube.com/embed/'+videos[i].id+'?enablejsapi=1&origin=storify.com" frameborder="0">'
}};
results_array.push(normalizedResult);
}
return results_array;
}
#googleio
http://storify.com/story/new?callback=yoursiteurlcallback
. The user will be asked to authenticate with Twitter and then will be able to create a new story. Once the user is done and hits “Publish”, we call you back, passing you the permalink of the new story created:yoursiteurlcallback?permalink=storyPermalink
.storyPermalink
or you can embed the story by loading <script src=”storyPermalink.js”></script>
. This is a great way to provide your community with a way to create stories right from your site.webkitRequestFileSystem
, which takes options to create either a temporary or permanent file system, and to define the size of the sandbox location. The difference between temporary and permanent is quite clear, with temporary acting only as a cache: the files may disappear when the browser needs to free up disk space. Once the file system has been successfully created, you can do all the operations you expect, such as creating, deleting, copying, and moving files and directories.ContactsContract
API to scan the device for local contacts. We then hash-encode the names and email addresses and send them to our servers to see if they match existing members of the community. The result is a list of possible friends already using Endomondo. The user can then send a friend request by clicking on the relevant person.AccountManager
. Our next step was to write our own synchronization manager by extending AbstractAccountAuthenticator
. When the user logs in or signs up, our app automatically creates a new account. The new account can be controlled using Android’s built in “Accounts & sync settings” service.QuickContactBadges
to show friends' profile pictures and to quickly pivot to other ways to contact them; perfect for planning a run together!ContactsContract
framework will automatically merge contacts, adding a very handy feature to our app without us having to do anything!QuickContactsDemo
.<target action="addTarget">We created a Javascript architecture to interpret the XML and make several calls to the Google Earth API to set up the scene and add 3D models as markers for the target. We then track the user’s position relative to the target using Google Earth’s ground overlays. This involves a lot of background processing, but we were surprised at how well it performs.
<itemPath>assets/images/blank.png</itemPath>
<longitude>-157.8459651634087</longitude>
<latitude>21.31249095467307</latitude>
<imageRadius>.0000018</imageRadius>
<targetRadius>20</targetRadius>
</target>
drawImage()
method allows us to draw only a certain part of a tileset or animation sheet to the screen. In Impact, however, you don't have to deal with any of the Canvas API methods directly. Instead, you specify your tilemaps and animation sheets and let the engine handle the details.// Each animation frame is 16x16 pixelsSimilarly, here's the code needed to create and draw a background layer:
var sheet = new ig.AnimationSheet( 'player.png', 16, 16 );
// This creates the "run" animation: it has 6 frames (the 2nd row
// in the image), with each one being shown for 0.07 seconds
var run = new ig.Animation( sheet, 0.07, [6,7,8,9,10,11] );
// Create a 2D tilemapYou don't have to create these tilemaps by hand. Impact comes with a powerful level editor called Weltmeister, which makes it easy to draw background layers and position your entities (non-static objects in the game world) in your levels.
var map = [
[5, 3, 4],
[2, 7, 1],
[6, 0, 3]
];
// Specify a layer with a tilesize of 16px and our tilemap
var layer = new ig.BackgroundMap( 16, map, 'tileset.png' );
layer.draw();