Android Open Source - HexNanoController_Android Sprite






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;
/*  w  w w . ja  va 2  s . c o m*/
import javax.microedition.khronos.opengles.GL10;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;

public abstract class Sprite 
{
  public enum Align {
    NO_ALIGN,
    CENTER,
    TOP_CENTER,
    BOTTOM_CENTER,
    TOP_RIGHT,
    TOP_LEFT,
    BOTTOM_RIGHT,
    BOTTOM_LEFT
  }

  protected Align alignment;
  protected Rect bounds;
    protected Rect margin;
    
  protected int surfaceWidth;
  protected int surfaceHeight;
  
  protected boolean alphaEnabled;  
  protected boolean enabled;
  protected boolean visible;
  
  private float prevAlpha;
  private float alpha;
  
  public Sprite(Align alignment)
  {
    this.alignment = alignment;
    alphaEnabled = true;
    visible = true;
    alpha = 1.0f;
    enabled = true;
    bounds = new Rect();
    margin = new Rect();
  }
  
  public void surfaceChanged(GL10 gl, int width, int height)
  {
    surfaceWidth = width;
    surfaceHeight = height;
    
    layout(width, height);
  }
  
  
  public void surfaceChanged(Canvas canvas)
  {
    surfaceWidth = canvas.getWidth();
    surfaceHeight = canvas.getHeight();
    
    layout(surfaceWidth, surfaceHeight);
  }
  
  
  public boolean processTouch(View v, MotionEvent event)
  {
    return onTouchEvent(v, event);
  }
  
  
  protected void layout(int width, int height) 
  {
    switch (alignment) {
    case TOP_CENTER:
      bounds.set((width - getWidth()) / 2, margin.top, ((width -getWidth()) / 2) + getWidth(), getHeight() + margin.top);
      break;
    case BOTTOM_CENTER:
      bounds.set((width - getWidth()) / 2, height - getHeight(), ((width - getWidth()) / 2) + getWidth(), height);
      break;
    case TOP_RIGHT:
      bounds.set(width - getWidth() - margin.right, margin.top, width - margin.right, margin.top + getHeight());
      break;
    case TOP_LEFT:
      bounds.set(margin.left, margin.top, margin.left + getWidth(), margin.top + getHeight());
      break;
    case BOTTOM_LEFT:
      bounds.set(margin.left, height - getHeight() - margin.bottom, getWidth() + margin.left, height - margin.bottom);
      break;
    case BOTTOM_RIGHT:
        bounds.set(width - getWidth() - margin.right, height - getHeight() - margin.bottom, width - margin.right, height - margin.bottom);
        break;
    default:
        // Left unimplemented
    }
  }

  
  public void setMargin(int top, int right, int bottom, int left)
  {
      margin.set(left, top, right, bottom);
  }
  
  
  public void setAlphaEnabled(boolean enabled)
  {
    this.alphaEnabled = enabled;
  }
  
  
  final public void setAlpha(float alpha)
    {
      if (!alphaEnabled) {
          return;
      }
      
      boolean alphaChanged = alpha != this.alpha;
        this.alpha = alpha;
        
        if (alphaChanged && alphaEnabled) {
            onAlphaChanged(this.alpha);
        }
    }
  
  
    final public float getAlpha()
    {
        return alpha;
    }
    
    
    public void setVisible(boolean visible)
    {
        this.visible = visible;
    }
    
    
    public boolean isVisible()
    {
        return this.visible;
    }
  
    
    protected void onAlphaChanged(float newAlpha)
    {
        // Left unimplemented
    }
    
    
  public void setEnabled(boolean enabled)
  {
      if (this.enabled != enabled) {
          this.enabled = enabled;
          
         if (enabled) {
          if (prevAlpha != 0) {
            setAlpha(prevAlpha);
          } else {
            setAlpha(1.0f);
          }
        } else {
          prevAlpha = getAlpha();
          setAlpha(0.5f);
        }
      }   
  }
  
  
  public boolean isEnabled()
  {
      return enabled;
  }

     
  public abstract void init(GL10 gl, int program);
    public abstract void draw(GL10 gl);
    public abstract void draw(Canvas canvas);
    public abstract boolean onTouchEvent(View v, MotionEvent event);
    public abstract boolean isInitialized();
    public abstract void setNeedsUpdate();
    public abstract void setViewAndProjectionMatrices(float[] vMatrix, float[] projMatrix);
    public abstract int getWidth();
    public abstract int getHeight();
    public abstract void freeResources();
}




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