Pages

Showing posts with label control. Show all posts
Showing posts with label control. Show all posts

Thursday, May 5, 2016

Android example to create grouped sub OptionsMenu


Create menu/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu
>
<item
android_id="@+id/option1"
android_orderInCategory="100"
app_showAsAction="ifRoom"
android_title="Option 1"/>
<item
android_id="@+id/option2"
android_orderInCategory="100"
app_showAsAction="never"
android_title="Option 2"/>
<item
android_id="@+id/option3"
android_orderInCategory="100"
app_showAsAction="never"
android_title="Option 3...">
<menu >
<group android_id="@+id/group3"
android_checkableBehavior="single">
<item android_id="@+id/submenu3a"
android_title="SubMenu 3A" />
<item android_id="@+id/submenu3b"
android_title="SubMenu 3B" />
</group>
</menu>

</item>
</menu>

MainActivity.java
package com.blogspot.android_er.androidoptionsmenu;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.option1:
Toast.makeText(MainActivity.this, "Option 1", Toast.LENGTH_LONG).show();
return true;
case R.id.option2:
Toast.makeText(MainActivity.this, "Option 2", Toast.LENGTH_LONG).show();
return true;
case R.id.submenu3a:
Toast.makeText(MainActivity.this, "Option 3 A", Toast.LENGTH_LONG).show();
return true;
case R.id.submenu3b:
Toast.makeText(MainActivity.this, "Option 3 B", Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
}



Read More..

Thursday, April 28, 2016

Android Gallery Control

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:

the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android_orientation="vertical"
android_layout_width="fill_parent"
android_layout_height="fill_parent"
>
<TextView
android_layout_width="fill_parent"
android_layout_height="wrap_content"
android_text="Gallery Demo"
/>
<Gallery
android_id="@+id/gallery"
android_layout_width="fill_parent"
android_layout_height="wrap_content"
android_gravity="center_horizontal"
android_spacing="100px"

/>
</LinearLayout>

and in the OnCreate method
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gallery=(Gallery)findViewById(R.id.gallery);
//String array holding the values
String [] text=new String[]{"Hello","Hi","Alloha","Bonjour","Hallo","¡Hola"};
//Array adapter to display our values in the gallery control
ArrayAdapter arr=new ArrayAdapter(this, android.R.layout.simple_gallery_item, text);
gallery.setAdapter(arr);
}

the gallery will be like this

we can increse the spacing between the items by increasing the value of android:spacing property.

we can display a scroll bar to indicate the position of the current selected item in the gallery like this:
<Gallery
android_id="@+id/gallery"
android_layout_width="fill_parent"
android_layout_height="wrap_content"
android_gravity="center_horizontal"
android_spacing="100px"
android_scrollbars="horizontal"
android_scrollbarFadeDuration="0"
android_scrollX="100px"
/>




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:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android_orientation="vertical"
android_layout_width="fill_parent"
android_layout_height="fill_parent"
>
<TextView
android_layout_width="fill_parent"
android_layout_height="wrap_content"
android_text="Gallery Demo"
android_id="@+id/txt"
/>
<Gallery
android_id="@+id/gallery"
android_layout_width="fill_parent"
android_layout_height="wrap_content"
android_gravity="center_horizontal"
android_spacing="100px"
android_scrollbars="horizontal"
android_scrollbarFadeDuration="0"
android_scrollX="100px"
/>
<LinearLayout
android_layout_width="fill_parent"
android_layout_height="wrap_content"
android_orientation="horizontal"
android_layout_marginTop="5px"
>
<Button
android_text="Previous"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_id="@+id/btnPrev"
android_onClick="onClick"
/>
<Button
android_text="Next"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_id="@+id/btnNext"
android_onClick="onClick"
/>

</LinearLayout>

</LinearLayout>


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;
}
}
you can download a sample program from here
Read More..

Wednesday, March 2, 2016

Android Developers Blog Introducing Android 4 1 Jelly Bean preview platform and more

Android Developers Blog: Introducing Android 4.1 (Jelly Bean) preview platform, and more
Read More..

Saturday, February 20, 2016

Android control Arduino Due LED using ADK Accessory Development Kit


Visit: Android control Arduino Due LED, using ADK (Accessory Development Kit)

Read More..

Thursday, March 6, 2014

How Gracenote is taking control of your TV

In depth The scary interactive future of TV has arrived

 How Gracenote is taking control of your TV 

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..."
gracenote
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.
gracenote
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.

"If there are cartoons on in the morning, then well know youll have a kid;...
Read the rest of this post --->
Read More..