Skip to content
This repository was archived by the owner on Apr 9, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ dependencies {
compile libraries.supportDesign
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'

debugCompile 'com.github.tatocaster.BuildNumberOverlay:buildnumberoverlaylibrary:1.0.1'
releaseCompile 'com.github.tatocaster.BuildNumberOverlay:buildnumberoverlaylibrary-no-op:1.0.1'
debugCompile project(':buildnumberoverlaylibrary')
releaseCompile project(':buildnumberoverlaylibrary-no-op')

debugCompile libraries.leakCanary
releaseCompile libraries.leakCanaryReleaseAndTest
Expand Down
25 changes: 18 additions & 7 deletions app/src/main/java/me/tatocaster/buildversionoverlay/MyApp.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.tatocaster.buildversionoverlay;

import android.app.Application;
import android.graphics.Color;
import android.view.Gravity;

import me.tatocaster.buildnumberoverlaylibrary.NumberOverlay;

Expand All @@ -9,11 +11,20 @@
*/

public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();

// initialize build number overlay
NumberOverlay.initialize(this);
}
@Override
public void onCreate() {
super.onCreate();

// initialize build number overlay
new NumberOverlay.Builder(this)
.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
.setText(String.format("Name: %s \n Code: %s",
BuildConfig.VERSION_NAME,
BuildConfig.VERSION_CODE))
.setTextColor(Color.YELLOW)
.setBackgroundColor(Color.BLUE)
.setWidth(300)
.setHeight(200)
.build();
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-beta2'
classpath 'com.android.tools.build:gradle:2.3.2'
// jitpack
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,98 @@ public static synchronized boolean isInitialized() {
public static Context getApplicationContext() {
return null;
}

public static class Builder{

/**
* Builder for {@link NumberOverlay}. If you want to initialize call method {@link Builder#build()}
* Example of use:
* <code>
* <p>new NumberOverlay.Builder(this)</p>
* <p>.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL)</p>
* <p>.setText(String.format("DEBUG VERSION"))</p>
* <p>.setTextColor(Color.YELLOW)</p>
* <p>.setBackgroundColor(Color.BLUE)</p>
* <p>.build();</p>
* </code>
* @param context application
*/
public Builder(Context context) {


}


/**
* Set background color of canvas, otherwise it is used default background Color.BLACK
* @param backgroundColor color
* @return builder
*/
public Builder setBackgroundColor(int backgroundColor) {

return this;
}


/**
* Set text color, otherwise it is used default Color.RED
* @param textColor text color
* @return builder
*/
public Builder setTextColor(int textColor) {
return this;
}


/**
* Set formatted text, otherwise it is used default text with build number and build code.
* <code>
* <p>Name: version name</p>
* <p>Code: version code</p>
* </code>
* @param text text to set
* @return builder
*/
public Builder setText(String text) {

return this;
}


/**
* Set gravity of canvas, otherwise it is used default value Gravity.BOTTOM | Gravity.END
* @param gravity gravity of canvas
* @return builder
*/
public Builder setGravity(int gravity) {
return this;
}


/**
* Set height of canvas, otherwise it is used default value 300 pixels
* @param height canvas height in pixels
* @return builder
*/
public Builder setHeight(int height) {
return this;
}

/**
* Set width of canvas, otherwise it is used default value 150 pixels
* @param width canvas width in pixels
* @return builder
*/
public Builder setWidth(int width) {
return this;
}

/**
* Build set properties and initialize number overlay
*/
public void build(){

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;

import me.tatocaster.buildnumberoverlaylibrary.NumberOverlayView.OverlayView;
import me.tatocaster.buildnumberoverlaylibrary.utils.Utils;

/**
Expand All @@ -21,23 +22,40 @@
public class AccessPermissionActivity extends AppCompatActivity {

private static final int PERMISSION_REQUEST_CODE = 9991;

private static final String PROPERTIES = "Properties";

private OverlayView.Properties properties;


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


getPropertiesFromExtra();

if (isSystemAlertPermissionGranted(this))
startOverlayService();
startOverlayService(properties);
else
requestSystemAlertPermission(this, null, PERMISSION_REQUEST_CODE);
}

/**

private void getPropertiesFromExtra() {
if (getIntent() == null){
return;
}

properties = (OverlayView.Properties) getIntent().getSerializableExtra(PROPERTIES);
}

/**
* start the service
*/
private void startOverlayService() {
if (!Utils.isOverlayingServiceIsRunning(this, OverlayService.class))
startService(new Intent(AccessPermissionActivity.this, OverlayService.class));
* @param properties
*/
private void startOverlayService(OverlayView.Properties properties) {
if (!Utils.isOverlayingServiceIsRunning(this, OverlayService.class)) {
Intent intent = OverlayService.getCallingIntent(this, properties);
startService(intent);
}
finish();
}

Expand Down Expand Up @@ -68,8 +86,15 @@ public static boolean isSystemAlertPermissionGranted(Context context) {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PERMISSION_REQUEST_CODE && isSystemAlertPermissionGranted(NumberOverlay.getApplicationContext()))
startOverlayService();
startOverlayService(properties);

super.onActivityResult(requestCode, resultCode, data);
}

public static Intent getCallingIntent(Context context, OverlayView.Properties properties){
Intent intent = new Intent(context, AccessPermissionActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(PROPERTIES, properties);
return intent;
}
}
Loading