Prepare The Main Activity

After creating our Glass Activity we will now add some codding into MainActivity in order to show some help to end-user and call the MyGlass activity. Add the following missing code into MainActivity class in your project:

package com.example.sosa; import; import; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout; import android.widget.ToggleButton; import; import; /** * The main activity show a button for starting the MyGlass activity as well as button for * showing help fragment. */ public class MainActivity extends Activity { private static final String HELP_TAG = "help"; private static final String HELP_FILE = "SOSAHelp.html"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //prepare clock handlers MyOnClickListener listener = new MyOnClickListener(); Button btn = (Button) findViewById(; btn.setOnClickListener(listener); btn = (Button) findViewById(; btn.setOnClickListener(listener); } /** * Start the MyGlass Activity */ private void startMyGlass() { Intent intent = new Intent(this, MyGlass.class); startActivity(intent); } /** * Prepare the help fragment */ private void prepareHelpFragment(boolean show) { try { FragmentTransaction ft = getFragmentManager().beginTransaction(); ImprovedWebViewFragment frag = (ImprovedWebViewFragment) getFragmentManager().findFragmentByTag(HELP_TAG); if (show) { if (frag == null) { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); frag = new ImprovedWebViewFragment(layoutParams); frag.setAssetFile(HELP_FILE); ft.setCustomAnimations(R.animator.slide_help_up_in, 0) .add(, frag, HELP_TAG) .commit(); } else { ft.setCustomAnimations(R.animator.slide_help_up_in, 0) .show(frag) .commit(); } } else { ft.setCustomAnimations(0, R.animator.slide_help_down_out) .hide(frag) .commit(); } } catch (Exception e) { getCGApplication().popupError("Fail to load help file '" + HELP_FILE + "'", e); } } /** * Utility method for casting the Application object into its tru type: {@link CGApplication} * @return instance of CGApplication */ private CGApplication getCGApplication() { return (CGApplication) getApplication(); } /** * Handle click events for either starting MyGlass activity or show/hide the help */ private class MyOnClickListener implements View.OnClickListener { @Override public void onClick(View view) { int itemId = view.getId(); switch (itemId) { case startMyGlass(); break; case prepareHelpFragment(((ToggleButton) view).isChecked()); break; } } } }



Here are the resources used by MainActivity.  

Starting with main.xml - located under "res\layout" dir 

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Space android:layout_width="match_parent" android:layout_height="10dp" android:layout_marginTop="10dp"/> <ToggleButton android:layout_width="270dp" android:layout_height="wrap_content" android:text="@string/help" android:textOff="Show help" android:textOn="Hide help" android:id="@+id/buttonHelp" android:layout_gravity="center_horizontal"/> <Space android:layout_width="match_parent" android:layout_height="10dp" /> <Button android:layout_width="270dp" android:layout_height="wrap_content" android:text="@string/start_my_glass" android:id="@+id/buttonStartMyGlass" android:layout_gravity="center_horizontal"/> <Space android:layout_width="match_parent" android:layout_height="10dp" /> </LinearLayout>


Entries to set into values.xml - located under "res\values" dir 

<string name="help">Help</string> <string name="start_my_glass">Start MyGlass</string>


Help animation resources. 

1) slide_help_up_in.xml - located under "res\animator" dir 

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="" android:fillAfter="true"> <objectAnimator android:duration="1500" android:propertyName="y" android:valueFrom="2500" android:valueTo="100" android:valueType="floatType"/> </set>


2) slide_help_down_out.xml  - located under "res\animator" dir 

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="" android:fillAfter="true"> <objectAnimator android:duration="1500" android:propertyName="y" android:valueFrom="500" android:valueTo="2500" android:valueType="floatType"/> </set>


Finally SOSAHelp.html - located under "assets" dir 

<html> <body> <h1>Application Overview</h1> <p> This SOSA App demonstrate simple and didactic implementation of 'Object Glass' pattern for associating widgets in relation with some code that we assume is a representation for a state of some object. </p> <p> This is very abstract example mainly intend to show and explain the easy of creating state oriented sharing app. A real application will probably refer to some more constructed object and possibly with choose to represent the state of this object by scanning a code or maybe by taking a picture of the object, or maybe relate with location or other sensor data or even use user entry of some predefined code or open code field as we do here. </p> <p> Whatever the approach for representing the state of an object is, The concept remain the same: <b>State oriented sharing is the operation of sharing data in the form of widgets by associating the data to state of something: Object, website, physical condition, physiological condition etc'</b> </p> <p> The API let you create state oriented sharing apps where the entire sharing algorithms, as well as collaboration algorithms, as well as data storage, network operations, search graph, views, dialogs, added value services and many more advanced features (e.g. Computational SaaS) are all given to you by API specifically and the by the broad Content Glass system. </p> <p> It is very easy to write simple State Oriented Sharing Apps. Of course you will have to take care the styling of your app and the general user experience. Content Glass on the other end will provide you the entire infrastructure so you can focus on creating your solution. </p> </body> </html>