0

I'm new to programming for Google Glass. I really like the cards possibilities (https://glass-python-starter-demo.appspot.com/) and it's great that I can submit HTML.

Because the project I'm working on (for which I would like to use Glass) is an online platform, I would like to be able to work from the website. As I found out, I can detect (from the user agent) that Glass is being used (http://www.googleglass.gs/quick-tip-google-glass-web-browser-user-agent/)

So, now my question in two parts.

1) Can I create an Android app that's actually a 'browser without a toolbar' so that I can direct directly to a webpage, but that functions as an app so that I can have it in the menu (after: "ok Glass")?

2) Can I use voice commands in the above app?

PS: I know this is a beginner question, but -with exception from the Glass Cards option- it's hard to find a starting point for this.

Bob van Luijt
  • 7,153
  • 12
  • 58
  • 101

1 Answers1

0

So if I understand you correctly, you want to do this following: 1) Create an app that is basically just a browser. 2) Have the link that opens be to your website where the app is actually contained. 3) Use voice commands to control this app. All to bypass having to code in java/xml so you can code in the language you know better and then run it online, and just have one line of code creating the browser in the actual app code.

Yes, you can create an app that is just a browser. Yes, you can have it link to your website and then have it stay there.

I think that it will be much harder for you to interact with the website. The default browser controls are tap to click, hold 2 fingers down and move your head to move "mouse" around the current screen, slide up and down to scroll.

If you want to control the app, you'd have to implement your own gesturedetector, override the default actions taken each time you do something, and then for each action send something to your website to let it know that you just did something.

You could use voice recognition for controls as well.

Either way, you'll need a gesturedetector to override the default controls for the browser if you decide to use the standard one. Here is what you'd need for that:

At the very top, you'll have

private GestureDetector gestureDetector;

Then in your onCreate method, you'll need to create your gestureDetector. I like to have a method to create it farther down. It is just cleaner that way for me.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        gestureDetector = createGestureDetector(this);
    }

And then the method to actually create the GestureDetector:

private GestureDetector createGestureDetector(Context context) {
        GestureDetector gestureDetectorTemp = new GestureDetector(context, new GestureDetector.OnGestureListener() {
            @Override
            public boolean onDown(MotionEvent motionEvent) {
                return false;
            }

            @Override
            public void onShowPress(MotionEvent motionEvent) {
                return false;
            }

            @Override
            public boolean onSingleTapUp(MotionEvent motionEvent) {
                //communicate to the website that you tapped, and have it handle the tap
                Log.v("APP_TAG","Someone tapped me!");
                return false; 
            }
            @Override
            public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float distanceX, float distanceY) {
                return false;
            }
            @Override
            public void onLongPress(MotionEvent motionEvent) {
                return false;
            }

            @Override
            public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent2, float v, float v2) { //fling = a single slide
                return false;
            }
        });
        return gestureDetectorTemp;
    }

Notice that each method that was overriden has a "return false" in it. The boolean you are returning represents whether or not the event is to be consumed. In other words, if you look at onSingleTapUp, we have a Log.v that will print out "Someone tapped me!" when you tap the screen. By returning false, you are letting whatever else was going to occur based on a tao (in the case of a browser, a "click" of the mouse) occur. If you return true, nothing else will occur. The event won't be reported to the other default methods. So to nullify all of the default controls of the browser, you would just change all of the return statements there to "return true", indicating that the event was consumed and that no further action is necessary!

I hope that helped a bit. If you goal is to completely bypass the entire android coding platform and just develop in the browser and then link the app to the browser, I don't think you'll be able to do it completely just because of the nature of Glass. There is no touch screen with lots of different buttons and a keyboard, etc. You'll need to do at least some glass development to get it to work.

Alex K
  • 8,269
  • 9
  • 39
  • 57