1

I'm trying to display a HTML page on the Google Glass. I've managed to do it but the page is not scrollable. Here is my code:

package com.example.dbe13509.testglass;

import com.google.android.glass.media.Sounds;
import com.google.android.glass.widget.CardBuilder;
import com.google.android.glass.widget.CardScrollAdapter;
import com.google.android.glass.widget.CardScrollView;

import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.AdapterView;

import java.io.File;

/**
 * An {@link Activity} showing a tuggable "Hello World!" card.
 * <p>
 * The main content view is composed of a one-card {@link CardScrollView} that provides tugging
 * feedback to the user when swipe gestures are detected.
 * If your Glassware intends to intercept swipe gestures, you should set the content view directly
 * and use a {@link com.google.android.glass.touchpad.GestureDetector}.
 * @see <a href="https://developers.google.com/glass/develop/gdk/touch">GDK Developer Guide</a>
 */
public class MainActivity extends Activity {

    /** {@link CardScrollView} to use as the main content view. */
    private CardScrollView mCardScroller;

    WebView web;
    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        web = new WebView(this);
        web.getSettings().setJavaScriptEnabled(true);
        web.loadUrl("http://www.google.fr");
        File lFile = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/test.html");
        web.loadUrl("file:///" + lFile.getAbsolutePath());


        mCardScroller = new CardScrollView(this);
        mCardScroller.setAdapter(new CardScrollAdapter() {
            @Override
            public int getCount() {
                return 1;
            }

            @Override
            public Object getItem(int position) {
                return web;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                return web;
            }

            @Override
            public int getPosition(Object item) {
                if (web.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(web);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        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);
//        web.loadUrl("http://www.google.fr");

        return card.getView(web, null);
    }

}

I tried to use the CardScrollView unsuccessfully. I think I need to make some custom class somewhere but I can't find documentation on that and I'm a beginner on Glass so if someone can help me...

MWiesner
  • 8,868
  • 11
  • 36
  • 70
Damien Belard
  • 285
  • 3
  • 12

0 Answers0