Skip to content

Commit

Permalink
Merge pull request navasmdc#139 from filipc/switchMemoryLeakFix
Browse files Browse the repository at this point in the history
Switch memory leak fix
  • Loading branch information
navasmdc committed Apr 4, 2015
2 parents 3feb01c + 8b76586 commit 9e94e99
Showing 1 changed file with 43 additions and 39 deletions.
82 changes: 43 additions & 39 deletions MaterialDesign/src/com/gc/materialdesign/views/Switch.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.gc.materialdesign.views;

import com.gc.materialdesign.R;
import com.gc.materialdesign.utils.Utils;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.view.ViewHelper;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
Expand All @@ -19,47 +14,53 @@
import android.view.View;
import android.widget.RelativeLayout;

import com.gc.materialdesign.R;
import com.gc.materialdesign.utils.Utils;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.view.ViewHelper;

public class Switch extends CustomView {

int backgroundColor = Color.parseColor("#4CAF50");
private int backgroundColor = Color.parseColor("#4CAF50");

Ball ball;
private Ball ball;

boolean check = false;
boolean eventCheck = false;
boolean press = false;
private boolean check = false;
private boolean eventCheck = false;
private boolean press = false;

OnCheckListener onCheckListener;
private OnCheckListener onCheckListener;
private Bitmap bitmap;

public Switch(Context context, AttributeSet attrs) {
super(context, attrs);
setAttributes(attrs);
setOnClickListener(new OnClickListener() {
public Switch(Context context, AttributeSet attrs) {
super(context, attrs);
setAttributes(attrs);
setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
if (check)
setChecked(false);
else
setChecked(true);
}
});
}
@Override
public void onClick(View arg0) {
if (check)
setChecked(false);
else
setChecked(true);
}
});
}

// Set atributtes of XML to View
protected void setAttributes(AttributeSet attrs) {
// Set atributtes of XML to View
protected void setAttributes(AttributeSet attrs) {

setBackgroundResource(R.drawable.background_transparent);
setBackgroundResource(R.drawable.background_transparent);

// Set size of view
setMinimumHeight(Utils.dpToPx(48, getResources()));
setMinimumWidth(Utils.dpToPx(80, getResources()));
// Set size of view
setMinimumHeight(Utils.dpToPx(48, getResources()));
setMinimumWidth(Utils.dpToPx(80, getResources()));

// Set background Color
// Color by resource
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
"background", -1);
if (bacgroundColor != -1) {
// Set background Color
// Color by resource
int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
"background", -1);
if (bacgroundColor != -1) {
setBackgroundColor(getResources().getColor(bacgroundColor));
} else {
// Color by hexadecimal
Expand Down Expand Up @@ -121,12 +122,15 @@ public boolean onTouchEvent(MotionEvent event) {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (!placedBall)
placeBall();
if (!placedBall) {
placeBall();
}

// Crop line to transparent effect
Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(),
canvas.getHeight(), Bitmap.Config.ARGB_8888);
if(null == bitmap) {
bitmap = Bitmap.createBitmap(canvas.getWidth(),
canvas.getHeight(), Bitmap.Config.ARGB_8888);
}
Canvas temp = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
Expand Down

0 comments on commit 9e94e99

Please sign in to comment.