Example usage for android.opengl GLSurfaceView GLSurfaceView

List of usage examples for android.opengl GLSurfaceView GLSurfaceView

Introduction

In this page you can find the example usage for android.opengl GLSurfaceView GLSurfaceView.

Prototype

public GLSurfaceView(Context context) 

Source Link

Document

Standard View constructor.

Usage

From source file:ru.zapolnov.MainActivity.java

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

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    int[] opts = new int[6];
    nativeGetInitOptions(opts);//from  w  ww .j a v  a 2 s.  c  o m
    int redBits = opts[0];
    int greenBits = opts[1];
    int blueBits = opts[2];
    int alphaBits = opts[3];
    int depthBits = opts[4];
    int stencilBits = opts[5];

    m_GLView = new GLSurfaceView(this);
    m_GLView.setEGLContextClientVersion(2);
    m_GLView.setEGLConfigChooser(redBits, greenBits, blueBits, alphaBits, depthBits, stencilBits);

    m_GLView.setRenderer(new GLSurfaceView.Renderer() {
        private long m_PrevTime;
        private int m_Width;
        private int m_Height;

        @Override
        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
            m_PrevTime = System.currentTimeMillis();
            nativeInit();
        }

        @Override
        public final void onSurfaceChanged(GL10 gl, int width, int height) {
            m_Width = width;
            m_Height = height;
        }

        @Override
        public final void onDrawFrame(GL10 gl) {
            long newTime = System.currentTimeMillis();
            long timeDelta = newTime - m_PrevTime;
            m_PrevTime = newTime;
            nativeRunFrame(m_Width, m_Height, timeDelta);
        }
    });

    setContentView(m_GLView);

    //      m_GestureDetector = new GestureDetectorCompat(this, this);
    //      m_GestureDetector.setOnDoubleTapListener(this);

    m_GLView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN)
                nativeTouchBegin(event.getX(), event.getY());
            else if (event.getAction() == MotionEvent.ACTION_MOVE)
                nativeTouchContinue(event.getX(), event.getY());
            else if (event.getAction() == MotionEvent.ACTION_UP)
                nativeTouchEnd(event.getX(), event.getY());
            return true;
        }
    });
}

From source file:eu.sathra.SathraActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mCurrentSathra = this;
    mWasInitiated = false;/*from  w ww. java  2 s. c o  m*/

    ResourceManager.getInstance().unloadAll();

    mParams = getParameters();

    if (mParams.fullscreen) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    if (mParams.layout == 0) {
        mSurfaceView = new GLSurfaceView(this);
        setContentView(mSurfaceView);
    } else {
        setContentView(mParams.layout);
        mSurfaceView = (GLSurfaceView) findViewById(R.id.surface);
    }

    mSurfaceView.setRenderer(this);
    mSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    mSurfaceView.setPreserveEGLContextOnPause(true);

    // resize view to forced resolution
    if (mParams.width != 0 && mParams.height != 0)
        mSurfaceView.getHolder().setFixedSize(mParams.width, mParams.height);

    SathraAdapter adapter = new SathraAdapter();

    IO.getInstance().registerAdapter(SathraActivity.class, adapter);
    IO.getInstance().registerAdapter(Context.class, adapter);

    mIsRunning = true;

    // setup FPS view

    showFPS(mParams.showFPS);

    setTimeScale(1);

    setAmbientColor(mParams.ambientColor);

    setRequestedOrientation(
            mParams.orientation == Orientation.VERTICAL ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
                    : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    // new CameraNode(this, null, null, true, null, null, null, null);
    // mRootNode.addChild(CameraNode.getActiveCamera());
}

From source file:cz.urbangaming.galgs.GAlg.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    ArrayList<String> itemList = new ArrayList<String>();
    //TODO:Make static, use String constants strings.xml
    itemList.add(getResources().getString(R.string.workmode_add));
    itemList.add(getResources().getString(R.string.workmode_edit));
    itemList.add(getResources().getString(R.string.workmode_delete));
    this.aAdpt = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1,
            itemList);/*from w  w w  . ja va 2  s  .c o m*/
    actionBar.setListNavigationCallbacks(aAdpt, this);
    mGLSurfaceView = new GLSurfaceView(this);

    if (detectOpenGLES20()) {
        // Tell the surface view we want to create an OpenGL ES 2.0-compatible
        // context, and set an OpenGL ES 2.0-compatible renderer.
        mGLSurfaceView.setEGLContextClientVersion(2);
        pointsRenderer = new PointsRenderer(this);
        mGLSurfaceView.setRenderer(pointsRenderer);
    } else {
        // TODO: Handle as an unrecoverable error and leave the activity somehow...
    }

    // External files preparation

    InputStream in = null;
    OutputStream out = null;
    try {
        Log.d(DEBUG_TAG, "Media rady: " + isExternalStorageWritable());

        AssetManager assetManager = getAssets();
        in = assetManager.open(GALGS_CLASS_FILE);
        if (in != null) {
            galgsRubyClassesDirectory = new File(GALGS_CLASS_DIR);
            galgsRubyClassesDirectory.mkdir();
            if (!galgsRubyClassesDirectory.isDirectory()) {
                Log.d(DEBUG_TAG, "Hmm, " + galgsRubyClassesDirectory + " does not exist, trying mkdirs...");
                galgsRubyClassesDirectory.mkdirs();
            }
            File outputFile = new File(galgsRubyClassesDirectory, GALGS_CLASS_FILE);
            if (outputFile.exists()) {
                // Load from what user might have edited
                outputFile = new File(galgsRubyClassesDirectory, GALGS_CLASS_FILE + ".orig");
            }
            out = new FileOutputStream(outputFile);
            copyFile(in, out);
            in.close();
            in = null;
            out.flush();
            out.close();
            out = null;
        } else {
            Log.e("IO HELL", "Asset " + GALGS_CLASS_FILE + " not found...");
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // Stops the thing from trashing the context on pause/resume.
    mGLSurfaceView.setPreserveEGLContextOnPause(true);
    setContentView(mGLSurfaceView);

}

From source file:com.watabou.noosa.Game.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Context context = getApplicationContext();
    StringsManager.setContext(context);/*from w  ww .  ja v  a  2 s.  co  m*/

    if (!BuildConfig.DEBUG) {
        EventCollector.logEvent("apk signature", Util.getSignature(this));
    }

    FileSystem.setContext(context);
    ModdingMode.setContext(context);

    try {
        version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        version = "???";
        versionCode = 0;
    }

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    view = new GLSurfaceView(this);
    view.setEGLContextClientVersion(2);

    // Hope this allow game work on broader devices list
    // view.setEGLConfigChooser( false );
    view.setRenderer(this);
    view.setOnTouchListener(this);

    layout = new LinearLayout(this);
    getLayout().setOrientation(LinearLayout.VERTICAL);
    getLayout().addView(view);

    setContentView(getLayout());
}

From source file:openscience.crowdsource.experiments.MainActivity.java

/*************************************************************************/
@Override/* w  w w  .j  av a2 s  .c o  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    b_start = (Button) findViewById(R.id.b_start);
    b_start.setText(s_b_start);

    t_email = (EditText) findViewById(R.id.t_email);

    addListenersOnButtons();

    log = (EditText) findViewById(R.id.log);
    log.append(welcome);

    // Getting local tmp path (for this app)
    File fpath = getFilesDir();
    path0 = fpath.toString();
    path = path0 + '/' + path1;

    File fp = new File(path);
    if (!fp.exists()) {
        if (!fp.mkdirs()) {
            log.append("\nERROR: can't create directory for local tmp files!\n");
            return;
        }
    }

    /* Read config */
    email = read_one_string_file(path0 + '/' + cemail);
    if (email == null)
        email = "";
    if (!email.equals("")) {
        t_email.setText(email.trim());
    }

    this.glSurfaceView = new GLSurfaceView(this);
    this.glSurfaceView.setRenderer(this);
    ((ViewGroup) log.getParent()).addView(this.glSurfaceView);

    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
    }
}

From source file:com.aincc.libtest.activity.flip.FlipViewGroup.java

/**
 * Surface  <br>/*from w  ww . ja v a2s  .c om*/
 *    ? .
 * 
 * @since 1.0.0
 */
private void setupSurfaceView() {
    Logger.v("FlipViewGroup::setupSurfaceView()");
    surfaceView = new GLSurfaceView(getContext());
    renderer = new FlipRenderer(this);
    surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    surfaceView.setZOrderOnTop(true);
    surfaceView.setRenderer(renderer);
    // surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); // ?  
    surfaceView.getHolder().setFormat(PixelFormat.OPAQUE);
    surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    renderer.getCards().setFlipViewGroup(this);
    addView(surfaceView);
}

From source file:joshuatee.wx.USWXOGLRadarActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    //editor = preferences.edit();
    theme_blue_current = preferences.getString("THEME_BLUE", "");
    setTheme(Utility.Theme(theme_blue_current));

    //setContentView(R.layout.activity_uswxoglradar);

    if (!DataStore.loaded)
        DataStore.Init(this);

    space = Pattern.compile(" ");
    comma = Pattern.compile(",");
    colon = Pattern.compile(":");

    //mImageMap = (ImageMap) findViewById(R.id.map);
    //mImageMap.setVisibility(View.GONE);

    cod_warnings_default = preferences.getString("COD_WARNINGS_DEFAULT", "");
    cod_cities_default = preferences.getString("COD_CITIES_DEFAULT", "");
    cod_hw_default = preferences.getString("COD_HW_DEFAULT", "true");
    cod_locdot_default = preferences.getString("COD_LOCDOT_DEFAULT", "true");
    cod_lakes_default = preferences.getString("COD_LAKES_DEFAULT", "true");

    //delay = UtilityImg.GetAnimInterval(preferences);

    img = new TouchImageView2(getApplicationContext());
    img.setMaxZoom(max_zoom);// ww w. jav  a 2s .  c om
    img.setZoom(init_zoom);

    dm = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);

    boolean isActionBarSplitted = ((dm.widthPixels / dm.density) < 400.00f);
    if (isActionBarSplitted) {
        ab_split = true;
    }

    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    statusBarHeight = getResources().getDimensionPixelSize(resourceId);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
    actionBarHeight = getResources().getDimensionPixelSize(tv.resourceId);
    actionBarHeight *= dm.density;

    screen_width = dm.widthPixels;
    screen_height = dm.heightPixels - statusBarHeight - actionBarHeight;

    turl = getIntent().getStringArrayExtra(RID);

    prod = "N0Q";

    view = new GLSurfaceView(this);
    view.setEGLContextClientVersion(2);
    mScaleDetector = new ScaleGestureDetector(this, new ScaleListener());
    mGestureDetector = new GestureDetectorCompat(this, this);

    OGLR = new OpenGLRenderRadar2Dv4(this);
    view.setRenderer(OGLR);
    view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    density = (float) (OGLR.ort_int * 2) / dm.widthPixels;

    setContentView(view);
    ogl_in_view = true;

    rid1 = turl[0];
    state = turl[1];
    if (turl.length > 2) {
        prod = turl[2];
        if (prod.equals("N0R")) {
            prod = "N0Q";
        }
    }

    //rid_fav = preferences.getString(pref_token," : : :");
    //sector = preferences.getString("COD_SECTOR_"+state,"");
    //state = preferences.getString("STATE_CODE_"+state,"");
    //onek = preferences.getString("COD_1KM_"+rid1,"");

    setTitle(prod);

    rid_fav = preferences.getString(pref_token, " : : :");
    rid_arr_loc = UtilityFavorites.SetupFavMenu(preferences, rid_fav, turl[0], pref_token_location, colon);
    adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item,
            rid_arr_loc);
    getActionBar().setListNavigationCallbacks(adapter, navigationListener);
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    navigationListener = new OnNavigationListener() {

        @Override
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {

            if (itemPosition == 0 || itemPosition > 2) {
                rid1 = space.split(rid_arr_loc[itemPosition])[0];

                //rid_loc = preferences.getString("RID_LOC_"+rid1,"");
                //editor.putString("NEXRAD_LAST", rid1); 
                //editor.commit();

                old_state = state;
                old_sector = sector;
                old_onek = onek;
                state = comma.split(preferences.getString("RID_LOC_" + rid1, ""))[0];
                sector = preferences.getString("COD_SECTOR_" + state, "");
                state = preferences.getString("STATE_CODE_" + state, "");
                onek = preferences.getString("COD_1KM_" + rid1, "");

                if (prod.equals("2k")) {
                    img_url = img_url.replace(old_sector, sector);
                    img_url = img_url.replace(old_state, state);
                    img_url = img_url.replace(old_onek, onek);
                }
                if (!restarted) {
                    img.resetZoom();
                    img.setZoom(init_zoom);
                    OGLR.setZoom(1.0f);
                    mScaleFactor = 1.0f;
                    OGLR.mPositionX = 0.0f;
                    OGLR.mPositionY = 0.0f;
                }
                restarted = false;
                new GetContent().execute();
            } else if (itemPosition == 1) {
                Intent dtx_srm = new Intent(getApplicationContext(), RIDAddFavActivity.class);
                startActivity(dtx_srm);
            } else if (itemPosition == 2) {
                Intent dtx_srm2 = new Intent(getApplicationContext(), RIDRemoveFavActivity.class);
                startActivity(dtx_srm2);
            }

            return false;
        }
    };
    getActionBar().setListNavigationCallbacks(adapter, navigationListener);

}

From source file:org.artoolkit.ar.samples.ARMovie.ARMovieActivity.java

@SuppressWarnings("deprecation") // FILL_PARENT still required for API level 7 (Android 2.1)
@Override//from  ww w .  ja va 2  s . c  om
public void onResume() {
    Log.i(TAG, "onResume()");
    super.onResume();

    // Update info on whether we have an Internet connection.
    ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    nativeSetInternetState(isConnected ? 1 : 0);

    // In order to ensure that the GL surface covers the camera preview each time onStart
    // is called, remove and add both back into the FrameLayout.
    // Removing GLSurfaceView also appears to cause the GL surface to be disposed of.
    // To work around this, we also recreate GLSurfaceView. This is not a lot of extra
    // work, since Android has already destroyed the OpenGL context too, requiring us to
    // recreate that and reload textures etc.

    // Create the camera view.
    camSurface = new CameraSurface(this);
    camSurface.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                focusOnTouch(event);
            }
            return true;
        }
    });

    // Create/recreate the GL view.
    glView = new GLSurfaceView(this);
    //glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); // Do we actually need a transparent surface? I think not, (default is RGB888 with depth=16) and anyway, Android 2.2 barfs on this.
    Renderer r = new Renderer();
    r.setMovieController(movieController);
    glView.setRenderer(r);
    glView.setZOrderMediaOverlay(true); // Request that GL view's SurfaceView be on top of other SurfaceViews (including CameraPreview's SurfaceView).

    mainLayout.addView(camSurface, new LayoutParams(128, 128));
    mainLayout.addView(glView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    if (glView != null)
        glView.onResume();

    // Resume movieController after resuming glView.
    if (movieController != null)
        movieController.onResume(glView);
}

From source file:net.nanocosmos.bintu.demo.encoder.activities.StreamActivity.java

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
    Surface foo = new Surface(surface);
    SurfaceView foo1 = new SurfaceView(this);
    foo = foo1.getHolder().getSurface();
    GLSurfaceView foo2 = new GLSurfaceView(this);
    foo = foo2.getHolder().getSurface();

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        initStreamLib();/*  ww w  .ja v  a  2 s .c  om*/
    } else {
        appPermissions = new CheckAppPermissions(this);
        boolean needPermission = false;
        if (streamVideo) {
            needPermission |= !appPermissions.checkCameraPermissions();
        }
        if (streamAudio) {
            needPermission |= !appPermissions.checkRecordAudioPermission();
        }
        if (recordMp4) {
            needPermission |= !appPermissions.checkWriteExternalStoragePermission();
        }

        if (needPermission) {
            appPermissions.requestMissingPermissions();
        } else {
            initStreamLib();
        }
    }
}

From source file:openscience.crowdsource.video.experiments.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
    setContentView(R.layout.activity_main);
    setTaskBarColored(this);

    Button consoleButton = (Button) findViewById(R.id.btn_consoleMain);
    consoleButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from w  ww . j  av a2 s. co  m*/
        public void onClick(View v) {
            Intent logIntent = new Intent(MainActivity.this, ConsoleActivity.class);
            startActivity(logIntent);
        }
    });

    Button infoButton = (Button) findViewById(R.id.btn_infoMain);
    infoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent aboutIntent = new Intent(MainActivity.this, InfoActivity.class);
            startActivity(aboutIntent);
        }
    });

    initConsole();

    startStopCam = (Button) findViewById(R.id.btn_capture);
    startStopCam.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            createDirIfNotExist(externalSDCardOpenscienceTmpPath);
            String takenPictureFilPath = String.format(
                    externalSDCardOpenscienceTmpPath + File.separator + "%d.jpg", System.currentTimeMillis());
            AppConfigService.updateActualImagePath(takenPictureFilPath);
            Intent aboutIntent = new Intent(MainActivity.this, CaptureActivity.class);
            startActivity(aboutIntent);
        }
    });

    recognize = (Button) findViewById(R.id.suggest);
    recognize.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final RecognitionScenario recognitionScenario = RecognitionScenarioService
                    .getSelectedRecognitionScenario();
            if (recognitionScenario == null) {
                AppLogger.logMessage(" Please select an image recognition scenario first! \n");
                return;
            }

            if (recognitionScenario.getState() == RecognitionScenario.State.NEW) {
                AlertDialog.Builder clarifyDialogBuilder = new AlertDialog.Builder(MainActivity.this);
                clarifyDialogBuilder
                        .setMessage(Html.fromHtml("Please download this scenario first or select another one."))
                        .setCancelable(false)
                        .setPositiveButton("continue", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                                LoadScenarioFilesAsyncTask loadScenarioFilesAsyncTask = new LoadScenarioFilesAsyncTask();
                                loadScenarioFilesAsyncTask.execute(recognitionScenario);
                                recognitionScenario.setLoadScenarioFilesAsyncTask(loadScenarioFilesAsyncTask);
                                Intent mainIntent = new Intent(MainActivity.this, ScenariosActivity.class);
                                startActivity(mainIntent);
                            }
                        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                final AlertDialog clarifyDialog = clarifyDialogBuilder.create();
                clarifyDialog.show();
                return;
            }

            if (recognitionScenario.getState() == RecognitionScenario.State.DOWNLOADING_IN_PROGRESS) {
                AlertDialog.Builder clarifyDialogBuilder = new AlertDialog.Builder(MainActivity.this);
                clarifyDialogBuilder.setMessage(Html.fromHtml("Download is in progress, please wait ..."))
                        .setCancelable(false)
                        .setPositiveButton("continue", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                final AlertDialog clarifyDialog = clarifyDialogBuilder.create();
                clarifyDialog.show();
                return;
            }

            if (isCameraStarted) {
                captureImageFromCameraPreviewAndPredict(true);
                return;
            }

            // Call prediction
            predictImage(AppConfigService.getActualImagePath());
        }
    });

    final View selectedScenarioTopBar = findViewById(R.id.selectedScenarioTopBar);
    selectedScenarioTopBar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent selectScenario = new Intent(MainActivity.this, ScenariosActivity.class);
            startActivity(selectScenario);

        }
    });
    selectedScenarioTopBar.setEnabled(false);

    final TextView selectedScenarioText = (TextView) findViewById(R.id.selectedScenarioText);
    selectedScenarioText.setText(PRELOADING_TEXT);

    imageView = (ImageView) findViewById(R.id.imageView1);

    btnOpenImage = (Button) findViewById(R.id.btn_ImageOpen);
    btnOpenImage.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, REQUEST_IMAGE_SELECT);
        }
    });

    // Lazy preload scenarios
    RecognitionScenarioService.initRecognitionScenariosAsync(new RecognitionScenarioService.ScenariosUpdater() {
        @Override
        public void update() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    RecognitionScenario selectedRecognitionScenario = RecognitionScenarioService
                            .getSelectedRecognitionScenario();
                    selectedScenarioText.setText(selectedRecognitionScenario.getTitle());
                    updateViewFromState();
                }
            });
        }
    });

    SharedPreferences sharedPreferences = getSharedPreferences(
            AppConfigService.CROWDSOURCE_VIDEO_EXPERIMENTS_ON_ANDROID_PREFERENCES, MODE_PRIVATE);
    if (sharedPreferences.getBoolean(AppConfigService.SHARED_PREFERENCES, true)) {
        AppLogger.logMessage(welcome);
        sharedPreferences.edit().putBoolean(AppConfigService.SHARED_PREFERENCES, false).apply();
    }

    this.glSurfaceView = new GLSurfaceView(this);
    this.glSurfaceView.setRenderer(this);
    ((ViewGroup) imageView.getParent()).addView(this.glSurfaceView);

    initAppConfig(this);

    client2 = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();

    final TextView resultPreviewText = (TextView) findViewById(R.id.resultPreviewtText);
    resultPreviewText.setText(AppConfigService.getPreviewRecognitionText());
    AppConfigService.registerPreviewRecognitionText(new AppConfigService.Updater() {
        @Override
        public void update(final String message) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    View imageButtonsBar = (View) findViewById(R.id.imageButtonBar);
                    imageButtonsBar.setVisibility(View.VISIBLE);
                    imageButtonsBar.setEnabled(true);
                    resultPreviewText.setText(message);
                }
            });

        }
    });
    updateViewFromState();
}