Android Open Source - Estimotes-Xamarin Distance Background View






From Project

Back to project page Estimotes-Xamarin.

License

The source code is released under:

Apache License

If you think the Android project Estimotes-Xamarin 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.estimote.examples.demos;
/*from w w w .  jav a  2 s .  c  o  m*/
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Draws distance background that is stretched to parent's height, keeps aspect ration
 * and centers the image.
 *
 * @author wiktor@estimote.com (Wiktor Gworek)
 */
public class DistanceBackgroundView extends View {

  private final Drawable drawable;

  public DistanceBackgroundView(Context context, AttributeSet attrs) {
    super(context, attrs);
    drawable = context.getResources().getDrawable(R.drawable.bg_distance);
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    int width = drawable.getIntrinsicWidth() * canvas.getHeight() / drawable.getIntrinsicHeight();
    int deltaX = (width - canvas.getWidth()) / 2;
    drawable.setBounds(-deltaX, 0, width - deltaX, canvas.getHeight());
    drawable.draw(canvas);
  }
}




Java Source Code List

com.estimote.examples.demos.AllDemosActivity.java
com.estimote.examples.demos.CharacteristicsDemoActivity.java
com.estimote.examples.demos.DistanceBackgroundView.java
com.estimote.examples.demos.DistanceBeaconActivity.java
com.estimote.examples.demos.LeDeviceListAdapter.java
com.estimote.examples.demos.ListBeaconsActivity.java
com.estimote.examples.demos.NotifyDemoActivity.java