Google Glass GDK Hello World Immersion Activity - google-glass

Steps, I have used to create my first Google Glass GDK App
New Project > Application name, company domain > Next > Glass (Glass Development Kit Preview (Google Inc.) (API 19)) > Next > Immersion Activity
ImmersionActivity.java:
public class ImmersionActivity extends Activity {
/**
* {#link CardScrollView} to use as the main content view.
*/
private CardScrollView mCardScroller;
private View mView;
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
mView = buildView();
mCardScroller = new CardScrollView(this);
mCardScroller.setAdapter(new CardScrollAdapter() {
#Override
public int getCount() {
return 1;
}
#Override
public Object getItem(int position) {
return mView;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return mView;
}
#Override
public int getPosition(Object item) {
if (mView.equals(item)) {
return 0;
}
return AdapterView.INVALID_POSITION;
}
});
// Handle the TAP event.
mCardScroller.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Plays disallowed sound to indicate that TAP actions are not supported.
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.playSoundEffect(Sounds.DISALLOWED);
}
});
setContentView(mCardScroller);
}
#Override
protected void onResume() {
super.onResume();
mCardScroller.activate();
}
#Override
protected void onPause() {
mCardScroller.deactivate();
super.onPause();
}
/**
* Builds a Glass styled "Hello World!" view using the {#link CardBuilder} class.
*/
private View buildView() {
CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
card.setText(R.string.hello_world);
return card.getView();
}
}
Manifest.xml:
<activity
android:name=".ImmersionActivity"
android:icon="#drawable/ic_glass_logo"
android:label="#string/title_activity_immersion" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/voice_trigger" />
</activity>
voice_trigger.xml:
<trigger command="SHOW_ME_A_DEMO" />
Now, what i have understood, we can run this app by trigger voice command "SHOW ME A DEMO", Is that right or wrong ?
And is there any way to run Glass GDK app on Android Emulator using Android Studio ?

Now, what i have understood, we can run this app by trigger voice command "SHOW ME A DEMO", Is that right or wrong ?
It's correct. YOu can even configure this trigger and use other commands.
And is there any way to run Glass GDK app on Android Emulator using Android Studio ?
No you can't. Only Tablet, Phone, Wear (watches) and TV devices are available on the Android Virtual Device Manager.

Now, what i have understood, we can run this app by trigger voice command "SHOW ME A DEMO", Is that right or wrong ?
yes you could run a app with the trigger set as command = "Show_me_a_demo"
But with this you are only able to run it from the speak menu.
I would turn it into
<trigger keyword="#string/app_name"/>
you could use any keyword you want but with this it would show up in the application menu as well as on the speak menu. The name that would show would be whatever you named your app.
It would also be a good idea to add <uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
to your manifest. To make sure the custom commands work
there are no emulators for the glass available as of now.

Related

HOW TO: Get the Item Selected in NavigationView in C++

I'm new to UWP and I have what I think is a simple problem to solve, but the examples I've found haven't worked. I'm using a navigation view in UWP project and I want to be able to switch page and display in a frame. When I select an item in the navigation view the ItemInvoked event is fired. I know the code to load the page into the frame which I've included below.
void enVigilServer::MainPage::nvSample_ItemInvoked(Windows::UI::Xaml::Controls::NavigationView^ sender, Windows::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ args)
{
this->contentFrame->Navigate(Windows::UI::Xaml::Interop::TypeName(SysConf::typeid));
}
My problem is how to determine which item I've selected from the NavigationView to show the relevant page.
Thanks
It's actually related to c++-cx and I will purpose this tag to your issue.
To make the navigation simple we can use the tag system in our app. See the following code:
<NavigationView x:Name="NavigationViewControl" ItemInvoked="NavigationViewControl_ItemInvoked" >
<NavigationView.MenuItems>
<NavigationViewItem Content="A" x:Name="A" Tag="tga" />
<NavigationViewItem Content="B" x:Name="B" Tag="tgb"/>
<NavigationViewItem Content="C" x:Name="C" />
</NavigationView.MenuItems>
<Frame x:Name="contentFrame"/>
</NavigationView>
This is an example, we will add tags to our items. Then we will do the following in our invoke code:
void NavigationVWCX::MainPage::NavigationViewControl_ItemInvoked(Windows::UI::Xaml::Controls::NavigationView^ sender, Windows::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ args)
{
auto navitemtag = args->InvokedItemContainer->Tag->ToString();
if (navitemtag == "tga")
{
contentFrame->Navigate(Windows::UI::Xaml::Interop::TypeName(PageA::typeid));
}
if (navitemtag == "tgb")
{
contentFrame->Navigate(Windows::UI::Xaml::Interop::TypeName(PageB::typeid));
}
}
BTW, don't forget to also add tag to your pages, like:
PageB::PageB()
{
InitializeComponent();
this->Tag = "tgb";
}

Update text of card in Google Glass

My Glass app is very simple. I have one static card and I set its text and display it in the overridden "onCreate()" method of my Activity:
myCard.setText("First text");
View cardView = myCard.getView();
// Display the card we just created
setContentView(cardView);
I want to sleep for 5 seconds then display "Second Text" to the user. An earlier question on StackExchange discussed that you get a new view as above, and call setContentView() again.
This is fine so far, but my naive question is, where do I sleep and reset the content view? Obviously I can't sleep in "onCreate()" or "onStart()" of the activity, because the display has not been rendered for the user yet. I have a simple Service. In the service? Do I create a thread somewhere and use that? Thanks!
No need to start a new thread or sleep. You can do this with Android's Handler.postDelayed method, which posts a task to be executed on the UI thread at a later time.
public class MyActivity {
private Handler mHandler = new Handler();
#Override
protected boolean onCreate() {
myCard.setText("First text");
View cardView = myCard.getView();
// Display the card we just created
setContentView(cardView);
mHandler.postDelayed(new Runnable() {
#Override
public void run() {
updateCard();
}
}, 5000 /* 5 sec in millis */);
}
private void updateCard() {
// update the card with "Second text"
}
}

How do you update a Glass CardScrollView programatically in XE16 (KitKat)?

How do you update a Glass CardScrollView programatically in XE16 (KitKat)?
I have a CardScrollView of cards that display photos from url's. I download the photos from the url's in a background thread and then I want to "refresh" or update the CardScrolView to make the cards display the new images.
I was calling:
cardScrollView.updateViews(true);
In XE12, but in XE16/KitKat that operation is deprecated. So how do you download an image in the background and then update a displayed "Card" with that image? Just calling card.addImage() seems to add a blank image and doesn't display the image.
I've updated my call from the background thread to be:
cardScrollView.getAdapter().notifyDataSetChanged();
Here is the code for the card scroll adapter with
private class SpecialCardsScrollAdapter extends CardScrollAdapter {
#Override
public int getPosition(Object item) {
return specialCardsList.indexOf(item);
}
#Override
public int getCount() {
return specialCardsList.size();
}
#Override
public Object getItem(int position) {
return specialCardsList.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return specialCardsList.get(position).getView();
}
}
Should I expect that calling cardScrollView.getAdapter().notifyDataSetChanged(); would cause Cards already put into the scrollview to update the image they have stored?
As mentioned in the release notes, use BaseAdapter#notifyDataSetChanged() from your CardScrollAdapter instead.

In Sitecore how to open a custom Sitecore app by right clicking on a content item?

I want to be able to right click on a content item in Sitecore and then select something like "Run My App" in the context menu. Then in the app that runs I need to be able to reference the content item that was right clicked. Is this possible?
Yes you can do this, its not as hard as it sounds.
You want to drop into the Core database and open up the content editor. The right click menu is defined within the sitecore/content/Applications/Content Editor/Context Menus/Default
The items within that folder are what you see when you right-click an item in the tree. So you can add a new item there with a template of Menu Item.
If you look at the existing ones, most of them send a message to the Sitecore Desktop. These messages are the commands defined in /App_Config/Commands.config. I can't see anything in there that would just launch another Sitecore application, so you would need to create a new command to do that. To create one, just inherit from the Sitecore.Shell.Framework.Commands.Command class. That passes in a CommandContext which will holds a collection of Items.
public class DemoCommand: Command
{
#region Overrides of Command
/// <summary>
/// Executes the command in the specified context.
/// </summary>
/// <param name="context">The context.</param>
public override void Execute(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
var parameters = new NameValueCollection();
if (context.Items != null && context.Items.Length == 1)
{
var item = context.Items[0];
parameters["id"] = item.ID.ToString();
}
Context.ClientPage.Start(this, "Run", parameters);
}
#endregion
public CommandState QueryStat(CommandContext context)
{
Assert.ArgumentNotNull(context, "context");
return CommandState.Enabled;
}
protected static void Run(ClientPipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
SheerResponse.CheckModified(false);
SheerResponse.Broadcast(
SheerResponse.ShowModalDialog(
"[Path to your application here]"
),
"Shell");
}
}
To get the item passed over, in your message call - just pass the variable $Target.
So the field Message in the Menu Item would be something like:
item:runMyApplication(id=$Target)
Hope that makes sense :)

How to make a looping/circular ScrollViewer in Windows 8 Metro (C++/XAML)

In a Windows 8 Metro app, is it possible to create a ScrollViewer which upon reaching the last item in the view, it loops back to the first item in the view? If so, how can I achieve this effect?
It is definitely possible. I am solving the problem at the moment and will post work when done. So far it goes something like below.
THe idea is that you hook into the viewchanged event for the scroll viewer, which fires anytime you move the bar. Once there, calculate where you are in the offset and the size of your items, and then you can use that to measure against the actual size of your listbox container or what have you.
Once you know where you are in the offset and know the actual height of your listbox and the height of your items, you know which items are currently visible and which are not. Make sure your list bound to the object is an observable collection implementing the INotifyChanged interface with two way binding. Then you can define a set of objects to rotate back and forth based on where in the scrolling you are.
Another option is to try a different starting point, perhaps a single control with a marquee and a scrollbar under it?
XAML
</UserControl.Resources>
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ScrollViewer x:Name="ScrollViewer1">
<ListBox x:Name="SampleListBox" Background="White" ItemsSource="{Binding Path=sampleItems}" ItemTemplate="{StaticResource sampleTemplate}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.Row="0" Grid.RowSpan="2">
</ListBox>
</ScrollViewer>
</Grid>
Code Behind
public sealed partial class MainPage : Page
{
List<SampleItem> sampleItems;
const int numItems = 15;
public MainPage()
{
sampleItems = new List<SampleItem>();
for (int i = 0; i < numItems; i++)
{
sampleItems.Add(new SampleItem(i));
}
this.InitializeComponent();
SampleListBox.ItemsSource = sampleItems;
ScrollViewer1.ViewChanged += ScrollViewer1_ViewChanged;
}
void ScrollViewer1_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
ScrollViewer viewer = sender as ScrollViewer;
ListBox box = viewer.Content as ListBox;
ListBoxItem lbi = box.ItemContainerGenerator.ContainerFromIndex(0) as ListBoxItem;
double elementSize;
if (lbi == null)
return;
elementSize = lbi.ActualHeight;
} /// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
}
public class SampleItem
{
public String ItemCount { get; set; }
public SampleItem(int itemCount)
{
ItemCount = itemCount.ToString();
}
}
I don't believe there is a control like that in WinRT/XAML, so you would need to implement a custom control. There are many approaches you could take, but I would probably avoid using the ScrollViewer and handle manipulation events directly since it might not be easy to bend ScrollViewer's behavior to your requirements. I would control the scroll offset based on the manipulation events and based on the scroll offset - position the elements in the view - e.g. using a Canvas control. You would need to reposition elements in the items panel depending on a scroll offset, so that for example items that go beyond the view port on one end are moved to the other end. It would involve custom dependency properties, item containers etc. Probably at least a few hours of work if you know all these APIs.