Android Open Source - Sertimus Live Object






From Project

Back to project page Sertimus.

License

The source code is released under:

GNU General Public License

If you think the Android project Sertimus 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

/*  Sertimus - A live wallpaper featuring a cute Chao.
  //w  w w . j  a  v a 2s.c  o m
    Copyright (C) 2013  Kevin Negrin

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */

//  LiveObject.java - Class describing any animate object. 

package gameaddict30.wallpaper.sertimus.objects;

import java.io.IOException;
import java.io.InputStream;

import gameaddict30.wallpaper.sertimus.MainCanvas;
import gameaddict30.wallpaper.sertimus.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.Log;

public abstract class LiveObject {
  protected MainCanvas refCanvas;
  
  protected Bitmap image;
  
  protected int width=0,height=0;
  protected int offsetX=0,offsetY=0;
  protected float x=0,y=0;
  
  public LiveObject(MainCanvas c, int r) {
    init(c);
    loadImageResource(c.getAppContext(), r);
  }
  
  public LiveObject(MainCanvas c, String s) {
    init(c);
    try {
      loadImageAsset(c.getAppContext(), s);
    } catch (IOException e) {
      loadImageResource(c.getAppContext(), R.drawable.sertimus_launcher_icon_optimized);
    }
  }
  
  public LiveObject(MainCanvas c) {
    init(c);
  }
  
  protected void init(MainCanvas c) {
    c.addForeObject(this);
    refCanvas = c;
  }
  
  public abstract void updateObject(); // Any general logic goes there
  public abstract void drawObject(Canvas c); // Draw the object however we'd like
  
  protected void loadImageResource(Context c, int r) { // Load the resources needed to represent this object on canvas
    image = BitmapFactory.decodeResource(c.getResources(), r, null);
    Log.v("LiveObject", "Opened image resource: "+image.getWidth()+"X"+image.getHeight());
  }
  
  protected void loadImageAsset(Context c, String p) throws IOException {
    InputStream i = c.getAssets().open(p);
    image = BitmapFactory.decodeStream(i);
    i.close();
    Log.v("LiveObject", "Opened image resource: "+image.getWidth()+"X"+image.getHeight());
  }
  
  public final float getX() {
    return x;
  }
  public final float getY() {
    return y;
  }
  public int getOffsetX() {
    return offsetX;
  }
  public int getOffsetY() {
    return offsetY;
  }
  public final int getWidth() {
    return width;
  }
  public final int getHeight() {
    return height;
  }
  
  public void onSurfaceChanged(int oW, int oH, int nW, int nH) {
    move((float)(x*((nW-oW)/nW)),(float)(y*((nH-oH)/nH)));
  }
  
  protected void move(float x, float y) {
    this.x += x;
    this.y += y;
  }
  
  public String toString() {
    return getClass().getName()+"."+this.hashCode()+": x="+x+" y="+y+" width="+width+" height="+height;
  }
}




Java Source Code List

gameaddict30.wallpaper.sertimus.DrawThread.java
gameaddict30.wallpaper.sertimus.LogicThread.java
gameaddict30.wallpaper.sertimus.MainCanvas.java
gameaddict30.wallpaper.sertimus.MainService.java
gameaddict30.wallpaper.sertimus.activities.MyPreferencesActivity.java
gameaddict30.wallpaper.sertimus.activities.SetWallpaperActivity.java
gameaddict30.wallpaper.sertimus.constants.CharacterAnimation.java
gameaddict30.wallpaper.sertimus.events.LiveObjectMotionEvent.java
gameaddict30.wallpaper.sertimus.interfaces.InteractiveLiveObject.java
gameaddict30.wallpaper.sertimus.interfaces.TalkableLiveObject.java
gameaddict30.wallpaper.sertimus.objects.BackgroundTile.java
gameaddict30.wallpaper.sertimus.objects.GrassStrands.java
gameaddict30.wallpaper.sertimus.objects.LiveObject.java
gameaddict30.wallpaper.sertimus.objects.Sertimus.java
gameaddict30.wallpaper.sertimus.objects.TalkBubble.java
gameaddict30.wallpaper.sertimus.utilities.Arithmetic.java
gameaddict30.wallpaper.sertimus.utilities.Strings.java