Android Open Source - Sertimus Background Tile






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.
  //from   w ww .ja v  a 2 s.c om
    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/>. */

/*  BackgroundTile.java - Class describing a tile that serves as a background
 *  in the contents of a MainCanvas. */

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.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.Log;

public class BackgroundTile {
  private MainCanvas refCanvas;
  private Bitmap completeTile, image;
  
  public BackgroundTile(MainCanvas c, int r) {
    refCanvas = c;
    try {
      loadImageAsset(refCanvas.getAppContext(), "images/tile_grass_optimized.png");
    } catch (IOException e) {
      loadImageResource(refCanvas.getAppContext(), R.drawable.sertimus_launcher_icon_optimized);
    }
  }
  
  public void updateObject() {
    createCompleteTile();
  }
  
  public void draw(Canvas c) {
    if (completeTile != null)
      c.drawBitmap(completeTile, 0, 0, null);
  }
  
  private void createCompleteTile() {
    if (completeTile != null)
      completeTile.recycle();
    completeTile = Bitmap.createBitmap(refCanvas.getWidth(), refCanvas.getHeight(), Config.ARGB_8888);
    
    Canvas c = new Canvas(completeTile);
    for (int y=0; y*image.getHeight() < refCanvas.getHeight(); y++)
      for (int x=0; x*image.getWidth() < refCanvas.getWidth(); x++)
        c.drawBitmap(image, x*image.getWidth(), y*image.getHeight(), null);
    c = null;
  }
  
  protected void loadImageResource(Context c, int r) {
    image = BitmapFactory.decodeResource(c.getResources(), r);
    image = Bitmap.createScaledBitmap(image, 40, 40, false);
  }
  
  protected void loadImageAsset(Context c, String p) throws IOException {
    InputStream i = c.getAssets().open(p);
    image = BitmapFactory.decodeStream(i);
    i.close();
    
    image = Bitmap.createScaledBitmap(image, 40, 40, false);
    Log.v("LiveObject", "Opened image resource: "+image.getWidth()+"X"+image.getHeight());
  }
}




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