Skip to content

Commit

Permalink
Added leak canary to check leaks and Resolved #7
Browse files Browse the repository at this point in the history
  • Loading branch information
bhargavms committed May 29, 2017
1 parent f0597d6 commit 0598ea7
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
24 changes: 12 additions & 12 deletions library/src/main/java/com/bhargavms/dotloader/Dot.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Dot {
private Paint mPaint;
int mCurrentColorIndex;
private int mDotRadius;
private DotLoader mParent;
private Integer[] mColors;
float cx;
float cy;
int position;
Expand All @@ -21,27 +21,27 @@ class Dot {

Dot(DotLoader parent, int dotRadius, int position) {
this.position = position;
mParent = parent;
mColors = parent.mColors;
mCurrentColorIndex = 0;
mDotRadius = dotRadius;

mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(mParent.mColors[mCurrentColorIndex]);
mPaint.setColor(mColors[mCurrentColorIndex]);
mPaint.setShadowLayer(5.5f, 6.0f, 6.0f, Color.BLACK);
mPaint.setStyle(Paint.Style.FILL);
}

public void setColorIndex(int index) {
void setColorIndex(int index) {
mCurrentColorIndex = index;
mPaint.setColor(mParent.mColors[index]);
mPaint.setColor(mColors[index]);
}

public void setColor(int color) {
void setColor(int color) {
mPaint.setColor(color);
}

public int getCurrentColor() {
return mParent.mColors[mCurrentColorIndex];
private int getCurrentColor() {
return mColors[mCurrentColorIndex];
}

public int incrementAndGetColor() {
Expand All @@ -51,19 +51,19 @@ public int incrementAndGetColor() {

void applyNextColor() {
mCurrentColorIndex++;
if (mCurrentColorIndex >= mParent.mColors.length)
if (mCurrentColorIndex >= mColors.length)
mCurrentColorIndex = 0;
mPaint.setColor(mParent.mColors[mCurrentColorIndex]);
mPaint.setColor(mColors[mCurrentColorIndex]);
}

int incrementColorIndex() {
mCurrentColorIndex++;
if (mCurrentColorIndex >= mParent.mColors.length)
if (mCurrentColorIndex >= mColors.length)
mCurrentColorIndex = 0;
return mCurrentColorIndex;
}

public void draw(Canvas canvas) {
void draw(Canvas canvas) {
canvas.drawCircle(cx, cy, mDotRadius, mPaint);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bhargavms.dotloader;

import android.animation.Animator;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
Expand Down
5 changes: 4 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "com.bhargavms.dotloader"
minSdkVersion 11
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
Expand All @@ -24,4 +24,7 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':library')
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
}
3 changes: 2 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:name=".DotLoaderApp">
<activity android:name="com.bhargavms.dotloader_sample.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bhargavms.dotloader_sample;

import android.app.Application;

import com.squareup.leakcanary.LeakCanary;

/**
* Created by bhargav on 5/29/17.
*/

public class DotLoaderApp extends Application {

@Override
public void onCreate() {
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package com.bhargavms.dotloader_sample;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.bhargavms.dotloader.DotLoader;

public class MainActivity extends AppCompatActivity {
DotLoader dotLoader;
DotLoader textDotLoader;
Button relaunch;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dotLoader = (DotLoader) findViewById(R.id.dot_loader);
relaunch = (Button) findViewById(R.id.btn);
relaunch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, MainActivity.class));
}
});
textDotLoader = (DotLoader) findViewById(R.id.text_dot_loader);
// testing set number of dots after some delay
dotLoader.postDelayed(new Runnable() {
Expand Down
6 changes: 6 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@
app:number_of_dots="3" />
</LinearLayout>

<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Relaunch"/>

</RelativeLayout>

0 comments on commit 0598ea7

Please sign in to comment.