Android Open Source - HexNanoController_Android Image






From Project

Back to project page HexNanoController_Android.

License

The source code is released under:

Code license GNU GPL v2 http://www.gnu.org/licenses/gpl.html Content license CC BY-NC-SA 4.0 http://creativecommons.org/licenses/by-nc-sa/4.0/

If you think the Android project HexNanoController_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.hexairbot.hexmini.ui;
/*from www  .j  a va  2  s  .c o  m*/
import javax.microedition.khronos.opengles.GL10;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;

import com.hexairbot.hexmini.ui.gl.GLSprite;
import com.hexairbot.hexmini.util.TextureUtils;


public class Image extends Sprite 
{
  public enum SizeParams {
    NONE,
    FILL_SCREEN,
    REPEATED
  }
  
  private GLSprite sprite;
  private SizeParams widthParam;
  private SizeParams heightParam;
  
  private boolean isInitialized;
  
  private boolean updateTexture;
  
   
    private Resources res;  
    private int resId;
  
  public Image(Resources resources, int resId, Align align)
  {
    super(align);
    
    widthParam = SizeParams.NONE;
    heightParam = SizeParams.NONE;
    
    isInitialized = false;
    sprite = new GLSprite(resources, resId);  
    this.res = resources;
    this.resId = resId;
  }
  
  
  @Override
  public void init(GL10 gl, int program) 
  {
    sprite.init(gl, program);
    isInitialized = true;
  }

  
  @Override
  public void surfaceChanged(GL10 gl, int width, int height) 
  {
    sprite.onSurfaceChanged(gl, width, height);
    
    if (widthParam == SizeParams.FILL_SCREEN) {
      sprite.setSize(width, sprite.height);
    }
    if(heightParam == SizeParams.FILL_SCREEN){
      sprite.setSize(sprite.width, height);
    }
    
    super.surfaceChanged(gl, width, height);
  }

  
  @Override
  public void surfaceChanged(Canvas canvas)
  {
    super.surfaceChanged(canvas);
  }
  
  private void invalidate()
  {
    updateTexture = true;
  }

  private Bitmap createBitmapToRender(boolean xRepeated, boolean yRepeated) {
    return TextureUtils.makeTexture(res, BitmapFactory.decodeResource(res, resId), surfaceWidth, surfaceHeight, true, true);
  }
  
  @Override
  public void draw(GL10 gl) 
  {
    if (updateTexture) {
      boolean xRepated = (widthParam == SizeParams.REPEATED) ? true : false;
      boolean yRepated = (heightParam == SizeParams.REPEATED) ? true : false;      
      
      Bitmap bitmap = createBitmapToRender(xRepated ,yRepated);
      sprite.updateTexture(res, bitmap);
      layout(surfaceWidth, surfaceHeight);
      
      updateTexture = false;
    }
    
    sprite.onDraw(gl, bounds.left, surfaceHeight - bounds.top - sprite.height);
  }

  
  @Override
  public void draw(Canvas canvas)
  {
    sprite.onDraw(canvas, bounds.left, bounds.top);
  }
  

  @Override
  public boolean onTouchEvent(View v, MotionEvent event) 
  {
    return false;
  }

  
  @Override
    protected void onAlphaChanged(float newAlpha)
    {
      sprite.setAlpha(newAlpha);
    }


  @Override
  public boolean isInitialized() 
  {
    return isInitialized;
  }

  
  @Override
  public void setViewAndProjectionMatrices(float[] vMatrix, float[] projMatrix) 
  {
    sprite.setViewAndProjectionMatrices(vMatrix, projMatrix);
  }

  
  public void setBounds(Rect rect)
  {
    this.bounds = rect;
  }

  
  public void setPosition(int x, int y) 
  {
    bounds.offsetTo(x, y);
  }

  
  @Override
  public int getWidth() 
  {
    return sprite.width;
  }

  @Override
  public int getHeight() 
  {
    return sprite.height;
  }
  

  public void setSizeParams(SizeParams width, SizeParams height) 
  {
    widthParam = width;
    heightParam = height;
    
    if (width == SizeParams.REPEATED || height == SizeParams.REPEATED) {
      invalidate();
    }
  }

  
    @Override
    public void freeResources()
    {
        sprite.freeResources();
    }


  @Override
  public void setNeedsUpdate() {
    isInitialized = false;
  }
}




Java Source Code List

.FileHelper.java
.Input.java
.Output.java
.Serializable.java
com.hexairbot.hexmini.HelpActivity.java
com.hexairbot.hexmini.HexMiniApplication.java
com.hexairbot.hexmini.HudActivity.java
com.hexairbot.hexmini.HudViewControllerDelegate.java
com.hexairbot.hexmini.HudViewController.java
com.hexairbot.hexmini.SettingsDialogDelegate.java
com.hexairbot.hexmini.SettingsDialog.java
com.hexairbot.hexmini.SettingsViewControllerDelegate.java
com.hexairbot.hexmini.SettingsViewController.java
com.hexairbot.hexmini.ViewController.java
com.hexairbot.hexmini.adapter.SettingsViewAdapter.java
com.hexairbot.hexmini.ble.BleConnectinManagerDelegate.java
com.hexairbot.hexmini.ble.BleConnectinManager.java
com.hexairbot.hexmini.ble.BluetoothLeService.java
com.hexairbot.hexmini.gestures.EnhancedGestureDetector.java
com.hexairbot.hexmini.modal.ApplicationSettings.java
com.hexairbot.hexmini.modal.Channel.java
com.hexairbot.hexmini.modal.OSDCommon.java
com.hexairbot.hexmini.modal.Transmitter.java
com.hexairbot.hexmini.sensors.DeviceOrientationChangeDelegate.java
com.hexairbot.hexmini.sensors.DeviceOrientationManager.java
com.hexairbot.hexmini.sensors.DeviceSensorManagerWrapper.java
com.hexairbot.hexmini.sensors.SensorManagerWrapper.java
com.hexairbot.hexmini.services.ConnectStateManager.java
com.hexairbot.hexmini.services.IpcControlService.java
com.hexairbot.hexmini.services.IpcProxy.java
com.hexairbot.hexmini.services.NavData.java
com.hexairbot.hexmini.services.OnIpcConnectChangedListener.java
com.hexairbot.hexmini.services.VIConfig.java
com.hexairbot.hexmini.ui.Button.java
com.hexairbot.hexmini.ui.Image.java
com.hexairbot.hexmini.ui.Indicator.java
com.hexairbot.hexmini.ui.Sprite.java
com.hexairbot.hexmini.ui.Text.java
com.hexairbot.hexmini.ui.ToggleButton.java
com.hexairbot.hexmini.ui.UIRenderer.java
com.hexairbot.hexmini.ui.control.CustomSeekBar.java
com.hexairbot.hexmini.ui.control.ViewPagerIndicator.java
com.hexairbot.hexmini.ui.gl.GLSprite.java
com.hexairbot.hexmini.ui.joystick.AcceleratorJoystick.java
com.hexairbot.hexmini.ui.joystick.AnalogueJoystick.java
com.hexairbot.hexmini.ui.joystick.JoystickBase.java
com.hexairbot.hexmini.ui.joystick.JoystickFactory.java
com.hexairbot.hexmini.ui.joystick.JoystickListener.java
com.hexairbot.hexmini.util.DebugHandler.java
com.hexairbot.hexmini.util.FontUtils.java
com.hexairbot.hexmini.util.SystemUiHiderBase.java
com.hexairbot.hexmini.util.SystemUiHiderHoneycomb.java
com.hexairbot.hexmini.util.SystemUiHider.java
com.hexairbot.hexmini.util.SystemUtil.java
com.hexairbot.hexmini.util.TextureUtils.java
fix.android.opengl.GLES20.java