Android Open Source - Freebloks-Android Theme






From Project

Back to project page Freebloks-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project Freebloks-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 de.saschahlusiak.freebloks.view.model;
/*  w  w  w .j a va 2 s .  c om*/
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import de.saschahlusiak.freebloks.R;

public class Theme {
  int drawable, texture;
  float rgba[] = { 1, 1, 1, 1 };
  boolean isPreview, isDrawable;

  private Theme() {
    this.isDrawable = false;
    this.isPreview = false;
  }

  private Theme(int drawable, int texture) {
    this.isDrawable = true;
    this.isPreview = false;
    this.drawable = drawable;
    this.texture = texture;
  }

  private Theme(float r, float g, float b) {
    this.isDrawable = false;
    this.isPreview = false;
    setRGB(r, g, b);
  }

  public final boolean isDrawable() {
    return isDrawable;
  }

  private void setDrawable(int drawable, int texture) {
    this.drawable = drawable;
    this.texture = texture;
    this.isDrawable = true;
  }

  private BitmapDrawable getDrawable(Resources resources) {
    BitmapDrawable background = (BitmapDrawable) resources.getDrawable(drawable);

    background.setTileModeXY(TileMode.REPEAT, isPreview ? TileMode.MIRROR : TileMode.REPEAT);
    background.setFilterBitmap(true);
    return background;
  }

  final int getColor() {
    return Color.rgb((int)(rgba[0] * 255.0f), (int)(rgba[1] * 255.0f), (int)(rgba[2] * 255.0f));
  }

  public final float[] getRGBA() {
    return rgba;
  }

  private void setRGB(float r, float g, float b) {
    this.rgba[0] = r;
    this.rgba[1] = g;
    this.rgba[2] = b;
  }

  public void apply(View view) {
    if (isDrawable)
      view.setBackgroundDrawable(getDrawable(view.getResources()));
    else
      view.setBackgroundColor(getColor());
  }

  public int getTexture() {
    return texture;
  }

  public static Theme get(String theme, boolean preview) {
    Theme t = new Theme();
    t.isPreview = preview;

    if (theme.equals("black")) {
      t.setRGB(0, 0, 0);
    } else if (theme.equals("blue")) {
      t.setRGB(0.05f, 0.10f, 0.25f);
    } else if (theme.equals("texture_table_cloth_1")) {
      t.setDrawable(R.drawable.texture_table_1, R.raw.texture_table_1);
      t.setRGB(0.8f, 0.8f, 0.8f);
    } else if (theme.equals("texture_table_cloth_2")) {
      t.setDrawable(R.drawable.texture_table_2, R.raw.texture_table_2);
      t.setRGB(0.7f, 0.7f, 0.7f);
    } else if (theme.equals("texture_wood")) {
      t.setDrawable(R.drawable.texture_wood_fine, R.raw.texture_wood_fine);
      t.setRGB(0.7f, 0.7f, 0.7f);
    } else if (theme.equals("texture_metal")) {
      t.setDrawable(R.drawable.texture_metal, R.raw.texture_metal);
      t.setRGB(0.8f, 0.8f, 0.8f);
    } else if (theme.equals("texture_bricks")) {
      t.setDrawable(R.drawable.texture_bricks, R.raw.texture_bricks);
      t.setRGB(0.85f, 0.85f, 0.85f);
    } else if (theme.equals("texture_carpet_blue")) {
      t.setDrawable(R.drawable.texture_carpet_blue, R.raw.texture_carpet_blue);
      t.setRGB(0.85f, 0.85f, 0.85f);
    } else if (theme.equals("texture_velvet")) {
      t.setDrawable(R.drawable.texture_velvet, R.raw.texture_velvet);
      t.setRGB(0.85f, 0.85f, 0.85f);
    } else if (theme.equals("texture_metal")) {
      t.setDrawable(R.drawable.texture_metal, R.raw.texture_metal);
      t.setRGB(0.85f, 0.85f, 0.85f);
    } else if (theme.equals("texture_grass")) {
      t.setDrawable(R.drawable.texture_grass, R.raw.texture_grass);
      t.setRGB(0.85f, 0.85f, 0.85f);
    }




    return t;
  }
}




Java Source Code List

com.google.example.games.basegameutils.BaseGameActivity.java
com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java
de.saschahlusiak.freebloks.AboutActivity.java
de.saschahlusiak.freebloks.Global.java
de.saschahlusiak.freebloks.backup.FreebloksBackupAgent.java
de.saschahlusiak.freebloks.controller.GameMode.java
de.saschahlusiak.freebloks.controller.JNIServer.java
de.saschahlusiak.freebloks.controller.PlayerData.java
de.saschahlusiak.freebloks.controller.SpielClientInterface.java
de.saschahlusiak.freebloks.controller.SpielClient.java
de.saschahlusiak.freebloks.controller.Spielleiter.java
de.saschahlusiak.freebloks.database.FreebloksDBOpenHandler.java
de.saschahlusiak.freebloks.database.FreebloksDB.java
de.saschahlusiak.freebloks.database.HighscoreDB.java
de.saschahlusiak.freebloks.donate.DonateActivity.java
de.saschahlusiak.freebloks.game.ActivityInterface.java
de.saschahlusiak.freebloks.game.AddScoreTask.java
de.saschahlusiak.freebloks.game.CustomGameDialog.java
de.saschahlusiak.freebloks.game.FreebloksActivity.java
de.saschahlusiak.freebloks.game.GameFinishActivity.java
de.saschahlusiak.freebloks.game.GameMenu.java
de.saschahlusiak.freebloks.game.RateAppDialog.java
de.saschahlusiak.freebloks.game.RetainedConfig.java
de.saschahlusiak.freebloks.game.SpielClientThread.java
de.saschahlusiak.freebloks.lobby.ChatEntry.java
de.saschahlusiak.freebloks.lobby.ChatListAdapter.java
de.saschahlusiak.freebloks.lobby.ColorAdapter.java
de.saschahlusiak.freebloks.lobby.LobbyDialog.java
de.saschahlusiak.freebloks.model.Player.java
de.saschahlusiak.freebloks.model.Spiel.java
de.saschahlusiak.freebloks.model.Stone.java
de.saschahlusiak.freebloks.model.Turn.java
de.saschahlusiak.freebloks.model.Turnpool.java
de.saschahlusiak.freebloks.network.NET_CHAT.java
de.saschahlusiak.freebloks.network.NET_CURRENT_PLAYER.java
de.saschahlusiak.freebloks.network.NET_GAME_FINISH.java
de.saschahlusiak.freebloks.network.NET_GRANT_PLAYER.java
de.saschahlusiak.freebloks.network.NET_HEADER.java
de.saschahlusiak.freebloks.network.NET_REQUEST_GAME_MODE.java
de.saschahlusiak.freebloks.network.NET_REQUEST_HINT.java
de.saschahlusiak.freebloks.network.NET_REQUEST_PLAYER.java
de.saschahlusiak.freebloks.network.NET_REQUEST_UNDO.java
de.saschahlusiak.freebloks.network.NET_REVOKE_PLAYER.java
de.saschahlusiak.freebloks.network.NET_SERVER_STATUS.java
de.saschahlusiak.freebloks.network.NET_SET_STONE.java
de.saschahlusiak.freebloks.network.NET_START_GAME.java
de.saschahlusiak.freebloks.network.NET_UNDO_STONE.java
de.saschahlusiak.freebloks.network.Network.java
de.saschahlusiak.freebloks.preferences.AboutFragment.java
de.saschahlusiak.freebloks.preferences.DisplayFragment.java
de.saschahlusiak.freebloks.preferences.FreebloksPreferences.java
de.saschahlusiak.freebloks.preferences.InterfaceFragment.java
de.saschahlusiak.freebloks.preferences.MiscFragment.java
de.saschahlusiak.freebloks.preferences.StatisticsFragment.java
de.saschahlusiak.freebloks.preferences.ThemePreference.java
de.saschahlusiak.freebloks.stats.StatisticsActivity.java
de.saschahlusiak.freebloks.stats.StatisticsAdapter.java
de.saschahlusiak.freebloks.view.BackgroundRenderer.java
de.saschahlusiak.freebloks.view.BoardRenderer.java
de.saschahlusiak.freebloks.view.Freebloks3DView.java
de.saschahlusiak.freebloks.view.FreebloksRenderer.java
de.saschahlusiak.freebloks.view.SimpleModel.java
de.saschahlusiak.freebloks.view.effects.AbsEffect.java
de.saschahlusiak.freebloks.view.effects.AbsStoneEffect.java
de.saschahlusiak.freebloks.view.effects.BoardStoneGlowEffect.java
de.saschahlusiak.freebloks.view.effects.EffectSet.java
de.saschahlusiak.freebloks.view.effects.Effect.java
de.saschahlusiak.freebloks.view.effects.PhysicalStoneEffect.java
de.saschahlusiak.freebloks.view.effects.StoneFadeEffect.java
de.saschahlusiak.freebloks.view.effects.StoneRollEffect.java
de.saschahlusiak.freebloks.view.effects.StoneUndoEffect.java
de.saschahlusiak.freebloks.view.model.Board.java
de.saschahlusiak.freebloks.view.model.CurrentStone.java
de.saschahlusiak.freebloks.view.model.Intro.java
de.saschahlusiak.freebloks.view.model.Sounds.java
de.saschahlusiak.freebloks.view.model.Theme.java
de.saschahlusiak.freebloks.view.model.ViewElement.java
de.saschahlusiak.freebloks.view.model.ViewModel.java
de.saschahlusiak.freebloks.view.model.Wheel.java