Android Open Source - FlappyCow Util






From Project

Back to project page FlappyCow.

License

The source code is released under:

MIT License

If you think the Android project FlappyCow 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.quchen.flappycow;
/*from   w  ww .jav a 2s  . co  m*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Util {
private static final int DEFAULT_DENSITY = 1024;
  
  public static Bitmap getScaledBitmapAlpha8(Context context, int id) {
    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
    bitmapOptions.inPreferredConfig = Bitmap.Config.ALPHA_8;
    bitmapOptions.inScaled = true;
    bitmapOptions.inDensity = DEFAULT_DENSITY;
    bitmapOptions.inTargetDensity = (int)(getScaleFactor(context)*DEFAULT_DENSITY);
    Bitmap b = BitmapFactory.decodeResource(context.getResources(), id, bitmapOptions);
    b.setDensity(context.getResources().getDisplayMetrics().densityDpi);
    return b;
  }
  
  public static Bitmap getDownScaledBitmapAlpha8(Context context, int id) {
    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
    bitmapOptions.inPreferredConfig = Bitmap.Config.ALPHA_8;
    bitmapOptions.inScaled = true;
    bitmapOptions.inDensity = DEFAULT_DENSITY;
    bitmapOptions.inTargetDensity = Math.min((int)(getScaleFactor(context)*DEFAULT_DENSITY), DEFAULT_DENSITY);
    Bitmap b = BitmapFactory.decodeResource(context.getResources(), id, bitmapOptions);
    b.setDensity(context.getResources().getDisplayMetrics().densityDpi);
    return b;
  }
  
  public static Bitmap getBitmapAlpha8(Context context, int id) {
    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
    bitmapOptions.inPreferredConfig = Bitmap.Config.ALPHA_8;
    return BitmapFactory.decodeResource(context.getResources(), id, bitmapOptions);
  }
  
  /**
   * Returns a scale factor related to the screen resolution that is used for scaling bitmaps.
   * @param context
   * @return
   */
  public static float getScaleFactor(Context context){
    // 1.2 @ 720x1280 px
    return context.getResources().getDisplayMetrics().heightPixels / 1066f;
  }
}




Java Source Code List

com.quchen.flappycow.About.java
com.quchen.flappycow.AccomplishmentBox.java
com.quchen.flappycow.GameOverDialog.java
com.quchen.flappycow.GameView.java
com.quchen.flappycow.Game.java
com.quchen.flappycow.MainActivity.java
com.quchen.flappycow.StartscreenView.java
com.quchen.flappycow.Util.java
com.quchen.flappycow.sprites.Background.java
com.quchen.flappycow.sprites.Coin.java
com.quchen.flappycow.sprites.Cow.java
com.quchen.flappycow.sprites.Frontground.java
com.quchen.flappycow.sprites.NyanCat.java
com.quchen.flappycow.sprites.Obstacle.java
com.quchen.flappycow.sprites.PauseButton.java
com.quchen.flappycow.sprites.PlayableCharacter.java
com.quchen.flappycow.sprites.PowerUp.java
com.quchen.flappycow.sprites.Rainbow.java
com.quchen.flappycow.sprites.Spider.java
com.quchen.flappycow.sprites.Sprite.java
com.quchen.flappycow.sprites.Toast.java
com.quchen.flappycow.sprites.Tutorial.java
com.quchen.flappycow.sprites.WoodLog.java