Skip to content

Commit

Permalink
rfactor Instacapture APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Tarek committed May 20, 2017
1 parent 6357970 commit 0411134
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 268 deletions.
58 changes: 23 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# InstaCapture [![Release](https://jitpack.io/v/tarek360/instacapture.svg)](https://jitpack.io/#tarek360/instacapture)
# Instacapture 2.0 [![Release](https://jitpack.io/v/tarek360/instacapture.svg)](https://jitpack.io/#tarek360/instacapture)

Android library to capture screenshot from your app

Expand All @@ -20,7 +20,7 @@ Add this to your module `build.gradle` file:
```gradle
dependencies {
...
compile "com.github.tarek360:instacapture:1.2.2"
compile "com.github.tarek360:instacapture:2.0.0-beta"
}
```

Expand All @@ -35,59 +35,47 @@ allprojects {
```


### How to use InstaCapture ?
### How to use Instacapture ?

- To capture a screenshot with ScreenCaptureListener.
```java
InstaCapture.getInstance(activity).capture().setScreenCapturingListener(new ScreenCaptureListener() {

@Override public void onCaptureStarted() {
//TODO..
}
@Override public void onCaptureFailed(Throwable e) {
//TODO..
}
@Override public void onCaptureComplete(Bitmap bitmap) {
//TODO..
}
});
Instacapture.capture(activity, new SimpleScreenCapturingListener() {
@Override
public void onCaptureComplete(Bitmap bitmap) {
//Your code here..
}
}, ignoredViews);

```

## OR

- To capture a screenshot with [RxJava](https://github.com/ReactiveX/RxJava) [Observable](http://reactivex.io/RxJava/javadoc/rx/Observable.html) to avoid ugly callback chains.
- Capture a screenshot with [RxJava](https://github.com/ReactiveX/RxJava) [Observable](http://reactivex.io/RxJava/javadoc/rx/Observable.html).
```java
InstaCapture.getInstance(activity).captureRx().subscribe(new Subscriber<Bitmap>() {
@Override public void onCompleted() {
//TODO..
}

@Override public void onError(Throwable e) {
//TODO..
}

@Override public void onNext(Bitmap bitmap) {
//TODO..
}
});
Instacapture.captureRx(this, ignoredViews).subscribe(new Action1<Bitmap>() {
@Override
public void call(Bitmap bitmap) {
//Your code here..
}
});
```

- To ignore view(s) from the screenshot.
```java
.capture(ignoredView); or .captureRx(ignoredView);
Instacapture.capture(.., .., ignoredViews);
//or
Instacapture.captureRx(.., ignoredViews);
```


- To enable logging.
- To enable Instacapture logging.
```java
InstaCaptureConfiguration config = new InstaCaptureConfiguration.Builder().logging(true).build();
InstaCapture.setConfiguration(config);
Instacapture.enableLogging(true);
```


## License

>Copyright 2016 Tarek360
>Copyright 2017 Tarek360
>Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
63 changes: 28 additions & 35 deletions app/src/main/java/com/tarek360/sample/BaseSampleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.tarek360.instacapture.InstaCapture;
import com.tarek360.instacapture.InstaCaptureConfiguration;
import com.tarek360.instacapture.Instacapture;
import com.tarek360.instacapture.listener.SimpleScreenCapturingListener;
import com.tarek360.sample.uncapturableViews.AlertDialogFragment;
import com.tarek360.sample.utility.Utility;
Expand All @@ -25,11 +24,7 @@ public abstract class BaseSampleActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Create new configuration and set Configuration to InstaCapture.
final InstaCaptureConfiguration config =
new InstaCaptureConfiguration.Builder().logging(true).build();
InstaCapture.setConfiguration(config);
Instacapture.enableLogging(true);
}

@Override
Expand All @@ -43,35 +38,33 @@ protected void showAlertDialog() {
.show(getSupportFragmentManager(), "dialogFragment");
}

protected void captureScreenshot() {
captureScreenshot(null);
}
protected void captureScreenshot(@Nullable View... ignoredViews) {

Instacapture.capture(this, new SimpleScreenCapturingListener() {
@Override
public void onCaptureComplete(Bitmap bitmap) {

Utility.getScreenshotFileObservable(BaseSampleActivity.this, bitmap)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<File>() {
@Override
public void call(File file) {

startActivity(ShowScreenShotActivity.buildIntent(BaseSampleActivity.this,
file.getAbsolutePath()));
}
});
}
}, ignoredViews);


Instacapture.captureRx(this, ignoredViews).subscribe(new Action1<Bitmap>() {
@Override
public void call(Bitmap bitmap) {

}
});

protected void captureScreenshot(@Nullable View... views) {
InstaCapture.getInstance(this)
.capture(views)
.setScreenCapturingListener(new SimpleScreenCapturingListener() {

@Override
public void onCaptureStarted() {
super.onCaptureStarted();
}

@Override
public void onCaptureComplete(Bitmap bitmap) {

Utility.getScreenshotFileObservable(BaseSampleActivity.this, bitmap)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<File>() {
@Override
public void call(File file) {

startActivity(ShowScreenShotActivity.buildIntent(BaseSampleActivity.this,
file.getAbsolutePath()));
}
});
}
});
}

@Override
Expand Down
190 changes: 0 additions & 190 deletions instacapture/src/main/java/com/tarek360/instacapture/InstaCapture.java

This file was deleted.

Loading

0 comments on commit 0411134

Please sign in to comment.