In Android the Gallery control is a selection control that displays items in a horizontal gallery. the items in the gallery appear beside each other. they can appear separated by a pre-defined space.
remember that there is a sample demo application for the gallery to download at the end of the post
we can use the gallery to display String items using a simple ArrayAdapter. so lets see how to create a gallery that displays the word "Hello" in several languages:
setting the android:scrollbarFadeDuration="0" makes the scroll bar always visible.
The android:scrollX property defines the initial scroll offset of the scroll bar which is the initial distance that the gallery is scrolled for.
Handling Gallery Events since the gallery is a selction Control (a adapter view) so it can register a OnItemSelectedListener to handle the selection of items within the gallery.
final String [] text=new String[]{"Hello","Hi","Alloha","Bonjour","Hallo","¡Hola"}; gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override public void onItemSelected(AdapterView parent, View view, int position, long id) { // TODO Auto-generated method stub TextView txt=(TextView)findViewById(R.id.txt); txt.setText(text[position].toString()); }
@Override public void onNothingSelected(AdapterView parent) { // TODO Auto-generated method stub
} });
now the final step is to add two navigation buttons: Next and Previous to navigate throught the items in the gallery. the layout is gonna be like this:
now in order to keep track of the index of the currently selected item we need to define two variables
//Variable to store the number of items in the gallery int ItemsInGallery=0; int CurrentIndex=0;
and the navigation buttons click handlers:
@Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.btnNext: //Increase the index CurrentIndex++; //if reached the end of the gallery, then start from the first item if(CurrentIndex>ItemsInGallery-1) CurrentIndex=0; gallery.setSelection(CurrentIndex,true); txt.setText(String.valueOf(CurrentIndex)); break; case R.id.btnPrev: //Decrease the index CurrentIndex=CurrentIndex-1; //If reached the first item, then return to the last item in the gallery if(CurrentIndex<0) CurrentIndex=ItemsInGallery-1; gallery.setSelection(CurrentIndex,true); txt.setText(String.valueOf(CurrentIndex)); break; } }
In depth The scary interactive future of TV has arrived
Gracenote is planning to take control of your TV.
The company, ubiquitous with music metadata services, has developed a suite of technologies that take the concept of interactive TV to an unprecedented level.
From next generation programme guides to personalised ad replacement, via fluff like The Million Second Quiz, the company is reinventing the very foundation of television.
"This is disruptive tech," company president Stephen White tells TechRadar with casual understatement. At first glance, what Gracenote appears to be doing seems innocuously clever. The company has developed a next generation programme guide, due to make its debut on LG screens this autumn.
Called On Now, it presents a highly graphical interface of whats available to watch. Instead of scrolling through a traditional timeline, the On Now guide presents content by programme, genre, cast or crew. The viewer navigates from there.
"What were trying to do now is move away from the grid," explains White. "The standard TV listing is a very dated navigation paradigm, one that hasnt really changed since the 1960s. So were bringing together all available content, including over the air, Video on Demand and catch-up. The guides not time based because no one watches that way anymore."
In addition to LG, Gracenotes parent Sony, along with Philips TP Vision, Loewe and OEM giant Vestel are all introducing variations of the system.
"One of the things were doing for Philips is providing a personalised recommendation platform, based on a user profile," reveals White. "We can push things to the front of its guide interface that we know you care about, and push things away that we know you dont."
The algorithm fuelling this knowledge is based on the content descriptors in Gracenotes metadata. "We know things about the show, as you watch it. We can also deliver ads while you browse – the primary engine for all this is content comprehension..." Your device will look for an audio fingerprint to find out what youre watching
Content comprehension
Demonstrations of On Now are certainly compelling, but this is just the start of what Gracenote believes will be an extraordinary change in our relationship with the boob tube.
The company has perfected an Automatic Content Recognition (ACR) platform, known internally as Entourage, which utilises audio fingerprinting to literally monitor what youre watching.
Taking advantage of the built-in microphone in tablets and smart phones, its able to identify a TV show via snippets of dialogue and soundtrack. Its similar in some respects to rival wizardry from Shazam, but with an added important talent for synchronization.
"The idea is that the client on your mobile device is running a Classifier within an app, which listens to the audio or music on a TV show, then cross references it with our database." Entourage works with any content, says White. "Right now were covering something like two hundred channels in the US, a 100 plus in Europe and 14 in Japan."
Gracenote creates the fingerprints through listening stations around the globe. "Were listening to content as its being broadcast, fingerprinting it and marrying it up to EPG data." Sony is preloading the technology on the Xperia Z1, dubbing it Track ID TV. The new EPG is note organised according to time like a standard system
Whats on
In the US, Entourage ARC provided the interactive backbone to hit game show The Million Second quiz. "Its an industry first," says White. "The studio integrated Entourage synchronisation into the official show app, allowing the audience to play along in real time."
The audience was given exactly the same amount of time to answer the questions as the contestants. High scorers were then brought into the studio to compete the next night. "The idea is to get the best players from the entire audience competing. Its never been done before."
White says theres been a surge from the creative community to leverage the technology, citing NBC Universals SyFy channel as one of the more inventive.
The channel created a companion app for its Face-Off visual effects reality show that syncs with the viewer as they watch and unlocks additional behind-the-scenes content as the show progresses. NBC Universal also used Entourage to serve viewers of Sci-fi holkum Haven an alternative episode ending on their companion device.
However the most contentious development of the technology is yet to come. Gracenote is on the verge of trialling video fingerprinting. For the first time, it will be the TV itself actively monitoring what youre watching, not a companion app. And youll probably not realise its doing it.
The video fingerprinting tech is embedded in the TV itself, reveals White. "It takes live video out of the video buffer, compares it against our database and then fingerprints it. This effectively allows the TV to recognise what shows youre watching."
The system is extraordinarily powerful. Most significantly, it allows Gracenote to profile TV usage, allowing the company to learn specific things about your household.