@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); glSurfaceView = new GLSurfaceView(this); // Check if the system supports OpenGL ES 2.0. final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000; final MyRenderer mRenderer = new MyRenderer(this); if (supportsEs2) { // Request an OpenGL ES 2.0 compatible context. glSurfaceView.setEGLContextClientVersion(2); // Set the renderer to our demo renderer, defined below. glSurfaceView.setRenderer(mRenderer); // save the context when onPause is called glSurfaceView.setPreserveEGLContextOnPause(true); rendererSet = true; } else { Toast.makeText(this, "This device does not support OpenGL ES 2.0.", Toast.LENGTH_LONG).show(); return; } glSurfaceView.setOnTouchListener( new View.OnTouchListener() { float previousX, previousY; @Override public boolean onTouch(View v, MotionEvent event) { // Dump touch event to log for debug // dumpEvent(event); // Handle touch events here... if (event != null) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: previousX = event.getX(); previousY = event.getY(); Log.d(TAG, "mode=DRAG"); mode = DRAG; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: Log.d(TAG, "mode=NONE"); mode = NONE; break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); Log.d(TAG, "oldDist=" + oldDist); if (oldDist > 10f) { midPoint(mid, event); mode = ZOOM; Log.d(TAG, "mode=ZOOM"); } break; case MotionEvent.ACTION_MOVE: if (mode == DRAG) { final float deltaX = event.getX() - previousX; final float deltaY = event.getY() - previousY; previousX = event.getX(); previousY = event.getY(); glSurfaceView.queueEvent( new Runnable() { @Override public void run() { mRenderer.handleTouchDrag(deltaX, deltaY); } }); } else if (mode == ZOOM) { float newDist = spacing(event); Log.d(TAG, "newDist=" + newDist); if (newDist > 10f) { final float scale = newDist / oldDist; Log.d(TAG, "scale=" + scale); glSurfaceView.queueEvent( new Runnable() { @Override public void run() { mRenderer.handlePinchZoom(scale); } }); } } break; } return true; } else { return false; } } }); setContentView(glSurfaceView); getActionBar().setTitle("Awesome Face"); getActionBar().setDisplayHomeAsUpEnabled(true); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_camera_capture); File outputFile = new File(Environment.getExternalStorageDirectory(), "camera-test.mp4"); TextView fileText = (TextView) findViewById(R.id.cameraOutputFile_text); fileText.setText(outputFile.toString()); Spinner spinner = (Spinner) findViewById(R.id.cameraFilter_spinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.cameraFilterNames, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner. spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); // Define a handler that receives camera-control messages from other threads. All calls // to Camera must be made on the same thread. Note we create this before the renderer // thread, so we know the fully-constructed object will be visible. mCameraHandler = new CameraHandler(this); mRecordingEnabled = sVideoEncoder.isRecording(); // Configure the GLSurfaceView. This will start the Renderer thread, with an // appropriate EGL context. mGLView = (GLSurfaceView) findViewById(R.id.cameraPreview_surfaceView); mGLView.setEGLContextClientVersion(2); // select GLES 2.0 mRenderer = new CameraSurfaceRenderer(mCameraHandler, sVideoEncoder, outputFile); mGLView.setRenderer(mRenderer); mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); Log.d(TAG, "onCreate complete: " + this); }
@Override public void onSetScript() { mSurfaceView = new GLSurfaceView(mActivity); mSurfaceView.setPreserveEGLContextOnPause(true); mSurfaceView.setEGLContextClientVersion(3); mSurfaceView.setEGLContextFactory(mContextFactory); mSurfaceView.setEGLConfigChooser(mConfigChooser); mSurfaceView.setEGLWindowSurfaceFactory(mWindowSurfaceFactory); mSurfaceView.setRenderer(mRenderer); mSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mActivity.setContentView(mSurfaceView); final DisplayMetrics metrics = new DisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics); final VrAppSettings appSettings = mActivity.getAppSettings(); final int screenWidthPixels = Math.max(metrics.widthPixels, metrics.heightPixels); final int screenHeightPixels = Math.min(metrics.widthPixels, metrics.heightPixels); final int frameBufferWidth = appSettings.getFramebufferPixelsWide(); final int frameBufferHeight = appSettings.getFramebufferPixelsHigh(); final SurfaceHolder holder = mSurfaceView.getHolder(); holder.setFormat(PixelFormat.TRANSLUCENT); if ((-1 != frameBufferHeight) && (-1 != frameBufferWidth)) { if ((screenWidthPixels != frameBufferWidth) && (screenHeightPixels != frameBufferHeight)) { Log.v(TAG, "--- window configuration ---"); Log.v(TAG, "--- width: %d", frameBufferWidth); Log.v(TAG, "--- height: %d", frameBufferHeight); // a different resolution of the native window requested holder.setFixedSize((int) frameBufferWidth, (int) frameBufferHeight); Log.v(TAG, "----------------------------"); } } }
/** * Sets the GLSurfaceView which will display the preview. * * @param view the GLSurfaceView */ public void setGLSurfaceView(final GLSurfaceView view) { mGlSurfaceView = view; mGlSurfaceView.setEGLContextClientVersion(2); mGlSurfaceView.setRenderer(mRenderer); mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mGlSurfaceView.requestRender(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); surfaceView = new GLSurfaceView(this); surfaceView.setEGLContextClientVersion(3); surfaceView.setRenderer(new GLRenderer(this)); setContentView(surfaceView); }
private VideoRendererGui(GLSurfaceView surface) { this.surface = surface; // Create an OpenGL ES 2.0 context. surface.setPreserveEGLContextOnPause(true); surface.setEGLContextClientVersion(2); surface.setRenderer(this); surface.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); yuvImageRenderers = new ArrayList<YuvImageRenderer>(); }
/** * Sets the GLSurfaceView which will display the preview. * * @param view the GLSurfaceView */ public void setGLSurfaceView(final GLSurfaceView view) { mGlSurfaceView = view; // 设置OpenGl版本号为2 mGlSurfaceView.setEGLContextClientVersion(2); // 设置颜色缓存为RGBA,位数都为8,深度缓存位数为16,蒙版缓存位数为0 mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); mGlSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888); mGlSurfaceView.setRenderer(mRenderer); // 脏模式,需要重绘时手动调用requestRender() mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mGlSurfaceView.requestRender(); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); view = new GLSurfaceView(this); view.setEGLContextClientVersion(2); view.setRenderer(new TriangleRenderer(view)); setContentView(view); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // make FULLSCREEN, witout title and bar requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); surface = new GLSurfaceView(this); surface.setEGLContextClientVersion(2); surface.setRenderer(new GlRenderer(this)); setContentView(surface); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setBackgroundDrawable(null); created = true; Log.d(TAG, "onCreate"); pipe = new DataPipe(this); cam = new Camera(); engine = new Engine(pipe, cam); gameView = new GLSurfaceView(this); gameView.setEGLContextClientVersion(2); gameView.setOnTouchListener(this); }
protected void createSurfaceView() { mSurfaceView = new GLSurfaceView(this); ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); if (checkOpenGLVersion) { ConfigurationInfo info = am.getDeviceConfigurationInfo(); if (info.reqGlEsVersion < 0x20000) throw new Error("OpenGL ES 2.0 is not supported by this device"); } mSurfaceView.setEGLContextClientVersion(2); mLayout = new FrameLayout(this); mLayout.addView(mSurfaceView); if (mMultisamplingEnabled) createMultisampleConfig(); setContentView(mLayout); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_main); RelativeLayout blLay = (RelativeLayout) findViewById(R.id.bottom_l); RelativeLayout brLay = (RelativeLayout) findViewById(R.id.bottom_r); RelativeLayout tmLay = (RelativeLayout) findViewById(R.id.top_m); // ----------- cubeView = new GLSurfaceView(this); cubeView.setRenderer(myCube = new OpenGLRenderer()); tmLay.addView(cubeView); // ----------- // ----------- Implement Joystick ----- joy1 = new VirtualJoystick(blLay, 150, 150); joy1.addEventListener(this); joy1.addEventListener(myCube); joy1.lockAxis('y', false); joy2 = new VirtualJoystick(brLay, 150, 150); joy2.addEventListener(this); joy2.addEventListener(myCube); joy2.lockAxis('x', false); // ----------- GLSurfaceView mGLSurfaceView = new GLSurfaceView(this); mGLSurfaceView.setEGLContextClientVersion(2); mGLSurfaceView.setRenderer(new LessonOneRenderer()); // tmLay.addView(mGLSurfaceView); /* * Debugger dbg = new Debugger(); dbg.supervised = joy2; dbg.start(); */ // ------- }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); glSurfaceView = new GLSurfaceView(this); ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000; if (supportsEs2) { glSurfaceView.setEGLContextClientVersion(2); glSurfaceView.setRenderer(new AirHockeyRenderer(this)); rendererSet = true; } else { Toast.makeText(this, "This device does not support OpenGL ES 2.0", Toast.LENGTH_LONG).show(); return; } setContentView(glSurfaceView); }
public void updateGLViews(SessionUIPresenter presenter) { // _on_pause = false; for (int i = 0; i < _renders.size(); i++) { RenderViewData d = _renders.valueAt(i); LogSdk.d(TAG, "updating GLview " + d._view_id + " for user " + d._user); GLSurfaceView glview = (GLSurfaceView) presenter.findViewById(d._view_id); if (glview == null) { LogSdk.e(TAG, "NULL GL view!!! " + d._view_id); continue; } try { glview.setEGLContextClientVersion(2); d._render = new VideoRenderer(glview); glview.setRenderer(d._render); glview.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); // .RENDERMODE_CONTINUOUSLY); } catch (IllegalStateException e) { } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_point_cloud); vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); mPoseTextView = (TextView) findViewById(R.id.pose); mQuatTextView = (TextView) findViewById(R.id.quat); mPoseCountTextView = (TextView) findViewById(R.id.posecount); mDeltaTextView = (TextView) findViewById(R.id.deltatime); mTangoEventTextView = (TextView) findViewById(R.id.tangoevent); mPoseStatusTextView = (TextView) findViewById(R.id.status); mPointCountTextView = (TextView) findViewById(R.id.pointCount); mAverageZTextView = (TextView) findViewById(R.id.averageZ); mFrequencyTextView = (TextView) findViewById(R.id.frameDelta); mFirstPersonButton = (Button) findViewById(R.id.first_person_button); mFirstPersonButton.setOnClickListener(this); mThirdPersonButton = (Button) findViewById(R.id.third_person_button); mThirdPersonButton.setOnClickListener(this); mTopDownButton = (Button) findViewById(R.id.top_down_button); mTopDownButton.setOnClickListener(this); mTango = new Tango(this); mConfig = new TangoConfig(); mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT); mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true); mTangoUxLayout = (TangoUxLayout) findViewById(R.id.layout_tango); mTangoUx = new TangoUx(this); mTangoUx.setLayout(mTangoUxLayout); mTangoUx.setUxExceptionEventListener(mUxExceptionListener); int maxDepthPoints = mConfig.getInt("max_point_cloud_elements"); mRenderer = new PCRenderer(maxDepthPoints); mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view); mGLView.setEGLContextClientVersion(2); mGLView.setRenderer(mRenderer); mIsTangoServiceConnected = false; startUIThread(); }
@Override protected void onCreate(Bundle savedInstanceState) { // Turn off the window's title bar requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); mGLSurfaceView = new GLSurfaceView(this); if (detectOpenGLES30()) { // Tell the surface view we want to create an OpenGL ES 3.0-compatible // context, and set an OpenGL ES 3.0-compatible renderer. mGLSurfaceView.setEGLContextClientVersion(3); // Set the renderer to our demo renderer, defined below. mGLSurfaceView.setRenderer(new LessonOneRenderer()); } else { // This is where you could create an OpenGL ES 2.0 and/or 1.x compatible // renderer if you wanted to support both ES 1 and ES 2. Log.e("HelloTriangle", "OpenGL ES 3.0 not supported on device. Exiting..."); finish(); } setContentView(mGLSurfaceView); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mGLSurfaceView = new GLSurfaceView(this); final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000; if (supportsEs2) { mGLSurfaceView.setEGLContextClientVersion(2); mGLSurfaceView.setRenderer(new LW3Renderer()); } else { return; } setContentView(mGLSurfaceView); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); settingsFragment = new SettingsFragment(); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); sharedPreferences.registerOnSharedPreferenceChangeListener(this); // Debug // setContentView(R.layout.title); mGLSurfaceView = new MyGLSurfaceView(this); // Create an OpenGL ES 2.0 context mGLSurfaceView.setEGLContextClientVersion(2); mGLSurfaceView.setPreserveEGLContextOnPause(true); // mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); setContentView(mGLSurfaceView); // The app user object mUser = new User(); mStarMapperRenderer = new StarMapperRenderer(this, mUser); // Set the StarMapperRenderer for drawing on the GLSurfaceView mGLSurfaceView.setRenderer(mStarMapperRenderer); // Retrieving location mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria locCriteria = new Criteria(); // gps locCriteria.setAccuracy(Criteria.ACCURACY_FINE); locCriteria.setBearingRequired(false); locCriteria.setAltitudeRequired(false); locCriteria.setCostAllowed(true); locCriteria.setSpeedRequired(false); locCriteria.setPowerRequirement(Criteria.POWER_LOW); String locProvider = mLocationManager.getBestProvider(locCriteria, true); Location loc = mLocationManager.getLastKnownLocation(locProvider); mUser.setGeoLocation((float) loc.getLatitude(), (float) loc.getLongitude()); mUser.setGeomagneticField(); mUser.setZenith(); // Initializing touch variables mPreviousX1 = 0; mPreviousY1 = 0; mPreviousX2 = 0; mPreviousY2 = 0; mPointerIndex = 0; mCurrentTouchState = TouchState.INIT; mZoomer = new Zoom(); // Initializing auto sensors mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometerSensor = null; mMagneticFieldSensor = null; mAccelerometerModel = null; mMagneticFieldModel = null; // Check for necessary sensors if ((mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) == null) || (mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) == null)) { // phone doesn't have appropriate sensors, only use manual mode mUseAutoSensorMode = false; } else { // phone has sensors, initialize them mAccelerometerSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMagneticFieldSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mUseAutoSensorMode = true; mAccelerometerModel = new AccelerometerModel(mUser, mStarMapperRenderer, mGLSurfaceView); mMagneticFieldModel = new MagneticFieldModel(mUser, mStarMapperRenderer, mGLSurfaceView); } if (mAccelerometerSensor != null) { mSensorManager.registerListener( mAccelerometerModel, mAccelerometerSensor, SensorManager.SENSOR_DELAY_FASTEST); } if (mMagneticFieldSensor != null) { mSensorManager.registerListener( mMagneticFieldModel, mMagneticFieldSensor, SensorManager.SENSOR_DELAY_FASTEST); } // ****** DEBUG ****** // mUseAutoSensorMode = false; // flinger flinger = new GestureDetector( this, new Flinger( new FlingListener() { public void fling(float distanceX, float distanceY) { float radsPerPixel = mStarMapperRenderer.mFovYRad / mStarMapperRenderer.mScreenHeight; changeMapX(-distanceX * radsPerPixel); changeMapY(-distanceY * radsPerPixel); mStarMapperRenderer.mLookX = mUser.getLookX(); mStarMapperRenderer.mLookY = mUser.getLookY(); mStarMapperRenderer.mLookZ = mUser.getLookZ(); mStarMapperRenderer.mUpX = mUser.getNormalX(); mStarMapperRenderer.mUpY = mUser.getNormalY(); mStarMapperRenderer.mUpZ = mUser.getNormalZ(); } })); }
public HudViewController(Activity context, HudViewControllerDelegate delegate) { this.delegate = delegate; this.context = context; Transmitter.sharedTransmitter().setBleConnectionManager(new BleConnectinManager(context)); settings = ((HexMiniApplication) context.getApplication()).getAppSettings(); joypadOpacity = settings.getInterfaceOpacity(); isLeftHanded = settings.isLeftHanded(); this.context = context; gestureDetector = new EnhancedGestureDetector(context, this); joysticks = new JoystickBase[2]; glView = new GLSurfaceView(context); glView.setEGLContextClientVersion(2); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // LinearLayout hud = (LinearLayout)inflater.inflate(R.layout.hud, null); // LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, // LayoutParams.FILL_PARENT); // hud.addView(glView, layoutParams); // glView.setBackgroundResource(R.drawable.settings_bg); context.setContentView(glView); renderer = new UIRenderer(context, null); initGLSurfaceView(); Resources res = context.getResources(); Image topBarBg = new Image(res, R.drawable.bar_top, Align.TOP_CENTER); topBarBg.setSizeParams(SizeParams.FILL_SCREEN, SizeParams.NONE); // Width水平伸缩至全屏,height保持不边 topBarBg.setAlphaEnabled(false); bottomBarBg = new Image(res, R.drawable.bar_bottom, Align.BOTTOM_CENTER); bottomBarBg.setSizeParams(SizeParams.FILL_SCREEN, SizeParams.NONE); bottomBarBg.setAlphaEnabled(false); Image middleBg = new Image(res, R.drawable.bg_tile, Align.CENTER); middleBg.setAlpha(1f); middleBg.setVisible(false); middleBg.setSizeParams( SizeParams.FILL_SCREEN, SizeParams.FILL_SCREEN); // Width水平伸缩至全屏,height保持不边 middleBg.setAlphaEnabled(true); Image bottomLeftSkrew = new Image(res, R.drawable.screw, Align.BOTTOM_LEFT); Image bottomRightSkrew = new Image(res, R.drawable.screw, Align.BOTTOM_RIGHT); Image logo = new Image(res, R.drawable.logo, Align.BOTTOM_LEFT); logo.setMargin( 0, 0, (int) res.getDimension(R.dimen.hud_logo_margin_bottom), (int) res.getDimension(R.dimen.hud_logo_margin_left)); Image statusBar = new Image(res, R.drawable.status_bar, Align.TOP_LEFT); statusBar.setMargin( (int) res.getDimension(R.dimen.hud_status_bar_margin_top), 0, 0, (int) res.getDimension(R.dimen.hud_status_bar_margin_left)); settingsBtn = new Button( res, R.drawable.btn_settings_normal, R.drawable.btn_settings_hl, Align.TOP_RIGHT); settingsBtn.setMargin( (int) res.getDimension(R.dimen.hud_btn_settings_margin_top), (int) res.getDimension(R.dimen.hud_btn_settings_margin_right), 0, 0); Button helpBtn = new Button(res, R.drawable.btn_help_normal, R.drawable.btn_help_hl, Align.TOP_RIGHT); helpBtn.setMargin( (int) res.getDimension(R.dimen.hud_btn_settings_margin_top), (int) res.getDimension(R.dimen.hud_btn_settings_margin_right) * 4, 0, 0); takeOffBtn = new Button( res, R.drawable.btn_take_off_normal, R.drawable.btn_take_off_hl, Align.BOTTOM_CENTER); stopBtn = new Button(res, R.drawable.btn_stop_normal, R.drawable.btn_stop_hl, Align.TOP_CENTER); String state = context.getResources().getString(R.string.settings_item_connection_state_not_conneceted); stateTextView = new Text(context, state, Align.TOP_LEFT); stateTextView.setMargin( (int) res.getDimension(R.dimen.hud_state_text_margin_top), 0, 0, (int) res.getDimension(R.dimen.hud_state_text_margin_left)); stateTextView.setTextColor(Color.WHITE); stateTextView.setTypeface(FontUtils.TYPEFACE.Helvetica(context)); stateTextView.setTextSize(res.getDimensionPixelSize(R.dimen.hud_state_text_size)); altHoldToggleBtn = new ToggleButton( res, R.drawable.alt_hold_off, R.drawable.alt_hold_off_hl, R.drawable.alt_hold_on, R.drawable.alt_hold_on_hl, R.drawable.alt_hold_on, Align.TOP_LEFT); altHoldToggleBtn.setMargin( res.getDimensionPixelOffset(R.dimen.hud_alt_hold_toggle_btn_margin_top), 0, 0, res.getDimensionPixelOffset(R.dimen.hud_alt_hold_toggle_btn_margin_left)); altHoldToggleBtn.setChecked(settings.isAltHoldMode()); buttons = new Button[5]; buttons[0] = settingsBtn; buttons[1] = takeOffBtn; buttons[2] = stopBtn; buttons[3] = altHoldToggleBtn; buttons[4] = helpBtn; renderer.addSprite(MIDLLE_BG_ID, middleBg); renderer.addSprite(TOP_BAR_ID, topBarBg); renderer.addSprite(BOTTOM_BAR_ID, bottomBarBg); renderer.addSprite(BOTTOM_LEFT_SKREW, bottomLeftSkrew); renderer.addSprite(BOTTOM_RIGHT_SKREW, bottomRightSkrew); renderer.addSprite(LOGO, logo); renderer.addSprite(STATUS_BAR, statusBar); renderer.addSprite(TAKE_OFF_BTN_ID, takeOffBtn); renderer.addSprite(STOP_BTN_ID, stopBtn); renderer.addSprite(SETTINGS_BTN_ID, settingsBtn); renderer.addSprite(ALT_HOLD_TOGGLE_BTN, altHoldToggleBtn); renderer.addSprite(STATE_TEXT_VIEW, stateTextView); renderer.addSprite(HELP_BTN, helpBtn); isAccMode = settings.isAccMode(); deviceOrientationManager = new DeviceOrientationManager(new DeviceSensorManagerWrapper(this.context), this); deviceOrientationManager.onCreate(); initJoystickListeners(); helpBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(HudViewController.this.context, HelpActivity.class); HudViewController.this.context.startActivity(intent); } }); if (isAccMode) { initJoysticks(JoystickType.ACCELERO); } else { initJoysticks(JoystickType.ANALOGUE); } initListeners(); initChannels(); if (settings.isHeadFreeMode()) { aux1Channel.setValue(1); } else { aux1Channel.setValue(-1); } if (settings.isAltHoldMode()) { aux2Channel.setValue(1); } else { aux2Channel.setValue(-1); } if (settings.isBeginnerMode()) { new AlertDialog.Builder(context) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.dialog_title_info) .setMessage(R.string.beginner_mode_info) .setPositiveButton( R.string.dialog_btn_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {} }) .show(); } }
public HudViewController(Activity context, boolean useSoftwareRendering) { joypadOpacity = 1f; this.context = context; this.useSoftwareRendering = useSoftwareRendering; gestureDetector = new EnhancedGestureDetector(context, this); canvasView = null; joysticks = new JoystickBase[2]; glView = new GLSurfaceView(context); glView.setEGLContextClientVersion(2); context.setContentView(glView); renderer = new VideoStageRenderer(context, null); if (useSoftwareRendering) { // Replacing OpneGl based view with Canvas based one // RelativeLayout root = (RelativeLayout) context.findViewById(R.id.controllerRootLayout); // root.removeView(glView); glView = null; canvasView = new VideoStageView(context); canvasView.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); // root.addView(canvasView, 0); } initNavdataStrings(); initCanvasSurfaceView(); initGLSurfaceView(); Resources res = context.getResources(); btnSettings = new Button(res, R.drawable.btn_settings, R.drawable.btn_settings_pressed, Align.TOP_LEFT); btnSettings.setMargin(0, 0, 0, (int) res.getDimension(R.dimen.hud_btn_settings_margin_left)); btnBack = new Button(res, R.drawable.btn_back, R.drawable.btn_back_pressed, Align.TOP_LEFT); btnBack.setMargin(0, 0, 0, res.getDimensionPixelOffset(R.dimen.hud_btn_back_margin_left)); btnEmergency = new Button( res, R.drawable.btn_emergency_normal, R.drawable.btn_emergency_pressed, Align.TOP_CENTER); btnTakeOff = new Button( res, R.drawable.btn_take_off_normal, R.drawable.btn_take_off_pressed, Align.BOTTOM_CENTER); btnLand = new Button( res, R.drawable.btn_landing, R.drawable.btn_landing_pressed, Align.BOTTOM_CENTER); btnLand.setVisible(false); Image topBarBg = new Image(res, R.drawable.barre_haut, Align.TOP_CENTER); topBarBg.setSizeParams(SizeParams.FILL_SCREEN, SizeParams.NONE); topBarBg.setAlphaEnabled(false); bottomBarBg = new Image(res, R.drawable.barre_bas, Align.BOTTOM_CENTER); bottomBarBg.setSizeParams(SizeParams.FILL_SCREEN, SizeParams.NONE); bottomBarBg.setAlphaEnabled(false); btnPhoto = new Button(res, R.drawable.btn_photo, R.drawable.btn_photo_pressed, Align.TOP_RIGHT); btnRecord = new ToggleButton( res, R.drawable.btn_record, R.drawable.btn_record_pressed, R.drawable.btn_record1, R.drawable.btn_record1_pressed, R.drawable.btn_record2, Align.TOP_RIGHT); btnRecord.setMargin(0, res.getDimensionPixelOffset(R.dimen.hud_btn_rec_margin_right), 0, 0); txtRecord = new Text(context, "REC", Align.TOP_RIGHT); txtRecord.setMargin( (int) res.getDimension(R.dimen.hud_rec_text_margin_top), (int) res.getDimension(R.dimen.hud_rec_text_margin_right), 0, 0); txtRecord.setTextColor(Color.WHITE); txtRecord.setTypeface(TYPEFACE.Helvetica(context)); txtRecord.setTextSize(res.getDimensionPixelSize(R.dimen.hud_rec_text_size)); usbIndicator = new Image(res, R.drawable.picto_usb_actif, Align.TOP_RIGHT); usbIndicator.setMargin( 0, res.getDimensionPixelOffset(R.dimen.hud_usb_indicator_margin_right), 0, 0); prevRemainingTime = -1; txtUsbRemaining = new Text(context, "KO", Align.TOP_RIGHT); txtUsbRemaining.setMargin( res.getDimensionPixelOffset(R.dimen.hud_usb_indicator_text_margin_top), res.getDimensionPixelOffset(R.dimen.hud_usb_indicator_text_margin_right), 0, 0); txtUsbRemaining.setTypeface(TYPEFACE.Helvetica(context)); txtUsbRemaining.setTextSize(res.getDimensionPixelSize(R.dimen.hud_usb_indicator_text_size)); btnCameraSwitch = new Button(res, R.drawable.btn_camera, R.drawable.btn_camera_pressed, Align.TOP_RIGHT); btnCameraSwitch.setMargin( 0, res.getDimensionPixelOffset(R.dimen.hud_btn_camera_switch_margin_right), 0, 0); int batteryIndicatorRes[] = { R.drawable.btn_battery_0, R.drawable.btn_battery_1, R.drawable.btn_battery_2, R.drawable.btn_battery_3 }; batteryIndicator = new Indicator(res, batteryIndicatorRes, Align.TOP_LEFT); batteryIndicator.setMargin( 0, 0, 0, (int) res.getDimension(R.dimen.hud_battery_indicator_margin_left)); txtBatteryStatus = new Text(context, "0%", Align.TOP_LEFT); txtBatteryStatus.setMargin( (int) res.getDimension(R.dimen.hud_battery_text_margin_top), 0, 0, (int) res.getDimension(R.dimen.hud_battery_indicator_margin_left) + batteryIndicator.getWidth()); txtBatteryStatus.setTextColor(Color.WHITE); txtBatteryStatus.setTypeface(TYPEFACE.Helvetica(context)); txtBatteryStatus.setTextSize((int) res.getDimension(R.dimen.hud_battery_text_size)); int margin = res.getDimensionPixelOffset(R.dimen.hud_sphero_mode_margin); btnCombinedYawOn = new Button(res, R.drawable.btn_sphero1, R.drawable.btn_sphero1, Align.BOTTOM_RIGHT); btnCombinedYawOn.setMargin( 0, res.getDimensionPixelOffset(R.dimen.hud_joy_margin), bottomBarBg.getHeight() + margin, 0); btnCombinedYawOff = new Button(res, R.drawable.btn_sphero2, R.drawable.btn_sphero2, Align.BOTTOM_RIGHT); btnCombinedYawOff.setMargin( 0, res.getDimensionPixelOffset(R.dimen.hud_joy_margin), bottomBarBg.getHeight() + margin, 0); btnCombinedYawOff.setVisible(false); int wifiIndicatorRes[] = { R.drawable.btn_wifi_0, R.drawable.btn_wifi_1, R.drawable.btn_wifi_2, R.drawable.btn_wifi_3 }; wifiIndicator = new Indicator(res, wifiIndicatorRes, Align.TOP_LEFT); wifiIndicator.setMargin( 0, 0, 0, (int) res.getDimension(R.dimen.hud_wifi_indicator_margin_left)); buttons = new Button[10]; buttons[0] = btnSettings; buttons[1] = btnEmergency; buttons[2] = btnTakeOff; buttons[3] = btnLand; buttons[4] = btnPhoto; buttons[5] = btnRecord; buttons[6] = btnCameraSwitch; buttons[7] = btnBack; buttons[8] = btnCombinedYawOn; buttons[9] = btnCombinedYawOff; txtAlert = new Text(context, "", Align.TOP_CENTER); txtAlert.setMargin((int) res.getDimension(R.dimen.hud_alert_text_margin_top), 0, 0, 0); txtAlert.setTextColor(Color.RED); txtAlert.setTextSize((int) res.getDimension(R.dimen.hud_alert_text_size)); txtAlert.setBold(true); txtAlert.blink(true); // txtUsbRemaining = new Text(context, "KO", Align.TOP_RIGHT); // // txtUsbRemaining.setMargin(res.getDimensionPixelOffset(R.dimen.hud_usb_indicator_text_margin_top), // res.getDimensionPixelOffset(R.dimen.hud_usb_indicator_text_margin_right), 0, 0); // txtUsbRemaining.setTypeface(TYPEFACE.Helvetica(context)); // txtUsbRemaining.setTextSize(res.getDimensionPixelSize(R.dimen.hud_usb_indicator_text_size)); // txtSphPitch = new Text(context, "sphero 1 - pitch : ", Align.TOP_LEFT); // txtSphPitch.setMargin(60, 0, 0, 30); // txtSphPitch.setTextColor(Color.GREEN); // txtSphRoll = new Text(context, "sphero 1 - roll : ", Align.TOP_LEFT); // txtSphRoll.setMargin(85, 0, 0, 30); // txtSphRoll.setTextColor(Color.GREEN); // txtDronePitch = new Text(context, "drone - pitch : ", Align.TOP_LEFT); // txtDronePitch.setMargin(110, 0, 0, 30); // txtDronePitch.setTextColor(Color.GREEN); // txtDroneRoll = new Text(context, "drone - roll : ", Align.TOP_LEFT); // txtDroneRoll.setMargin(135, 0, 0, 30); // txtDroneRoll.setTextColor(Color.GREEN); // // txtSph2Pitch = new Text(context, "sphero 2 - pitch : ", Align.TOP_LEFT); // txtSph2Pitch.setMargin(60, 0, 0, 300); // txtSph2Pitch.setTextColor(Color.GREEN); // txtSph2Roll = new Text(context, "sphero 2 - roll : ", Align.TOP_LEFT); // txtSph2Roll.setMargin(85, 0, 0, 300); // txtSph2Roll.setTextColor(Color.GREEN); // txtDroneGaz = new Text(context, "drone - gaz : ", Align.TOP_LEFT); // txtDroneGaz.setMargin(110, 0, 0, 300); // txtDroneGaz.setTextColor(Color.GREEN); // txtDroneYaw = new Text(context, "drone - yaw : ", Align.TOP_LEFT); // txtDroneYaw.setMargin(135, 0, 0, 300); // txtDroneYaw.setTextColor(Color.GREEN); renderer.addSprite(TOP_BAR_ID, topBarBg); renderer.addSprite(BOTTOM_BAR_ID, bottomBarBg); renderer.addSprite(SETTINGS_ID, btnSettings); renderer.addSprite(BACK_BTN_ID, btnBack); renderer.addSprite(PHOTO_ID, btnPhoto); renderer.addSprite(RECORD_ID, btnRecord); renderer.addSprite(CAMERA_ID, btnCameraSwitch); renderer.addSprite(ALERT_ID, btnEmergency); renderer.addSprite(TAKE_OFF_ID, btnTakeOff); renderer.addSprite(LAND_ID, btnLand); renderer.addSprite(BATTERY_INDICATOR_ID, batteryIndicator); renderer.addSprite(WIFI_INDICATOR_ID, wifiIndicator); renderer.addSprite(EMERGENCY_LABEL_ID, txtAlert); renderer.addSprite(BATTERY_STATUS_LABEL_ID, txtBatteryStatus); renderer.addSprite(RECORD_LABEL_ID, txtRecord); renderer.addSprite(USB_INDICATOR_ID, usbIndicator); renderer.addSprite(USB_INDICATOR_TEXT_ID, txtUsbRemaining); renderer.addSprite(SPHERO_COMBINED_YAW_ON, btnCombinedYawOn); renderer.addSprite(SPHERO_COMBINED_YAW_OFF, btnCombinedYawOff); // renderer.addSprite(20, txtSphPitch); // renderer.addSprite(21, txtSphRoll); // renderer.addSprite(22, txtDronePitch); // renderer.addSprite(23, txtDroneRoll); // renderer.addSprite(24, txtSph2Pitch); // renderer.addSprite(25, txtSph2Roll); // renderer.addSprite(26, txtDroneGaz); // renderer.addSprite(27, txtDroneYaw); }