-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ahmed Tarek
committed
May 20, 2017
1 parent
0411134
commit ed5e906
Showing
27 changed files
with
571 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
instacapture/src/main/java/com/tarek360/instacapture/ActivityReferenceManager.java
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
instacapture/src/main/java/com/tarek360/instacapture/ActivityReferenceManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.tarek360.instacapture | ||
|
||
import android.app.Activity | ||
import android.os.Build | ||
|
||
import java.lang.ref.WeakReference | ||
|
||
/** | ||
* Created by tarek on 5/17/16. | ||
*/ | ||
class ActivityReferenceManager { | ||
|
||
private var mActivity: WeakReference<Activity>? = null | ||
|
||
fun setActivity(activity: Activity) { | ||
this.mActivity = WeakReference(activity) | ||
} | ||
|
||
val validatedActivity: Activity? | ||
get() { | ||
if (mActivity == null) { | ||
return null | ||
} | ||
|
||
val activity = mActivity!!.get() | ||
if (!isActivityValid(activity)) { | ||
return null | ||
} | ||
|
||
return activity | ||
} | ||
|
||
private fun isActivityValid(activity: Activity?): Boolean { | ||
if (activity == null) { | ||
return false | ||
} | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | ||
return !activity.isFinishing && !activity.isDestroyed | ||
} else { | ||
return !activity.isFinishing | ||
} | ||
} | ||
} |
90 changes: 0 additions & 90 deletions
90
instacapture/src/main/java/com/tarek360/instacapture/Instacapture.java
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
instacapture/src/main/java/com/tarek360/instacapture/Instacapture.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.tarek360.instacapture | ||
|
||
import android.app.Activity | ||
import android.graphics.Bitmap | ||
import android.view.View | ||
|
||
import com.tarek360.instacapture.exception.ActivityNotRunningException | ||
import com.tarek360.instacapture.listener.ScreenCaptureListener | ||
import com.tarek360.instacapture.screenshot.ScreenshotProvider | ||
import com.tarek360.instacapture.utility.Logger | ||
|
||
import rx.Observable | ||
import rx.Subscriber | ||
import rx.android.schedulers.AndroidSchedulers | ||
|
||
/** | ||
* Created by tarek on 5/20/17. | ||
*/ | ||
|
||
object Instacapture { | ||
|
||
private val MESSAGE_IS_ACTIVITY_RUNNING = "Is your activity running?" | ||
private val ERROR_SCREENSHOT_CAPTURE_FAILED = "Screenshot capture failed" | ||
|
||
fun capture(activity: Activity, | ||
screenCaptureListener: ScreenCaptureListener, | ||
vararg ignoredViews: View) { | ||
|
||
screenCaptureListener.onCaptureStarted() | ||
|
||
captureRx(activity, *ignoredViews).subscribe(object : Subscriber<Bitmap>() { | ||
override fun onCompleted() {} | ||
|
||
override fun onError(e: Throwable) { | ||
Logger.e(ERROR_SCREENSHOT_CAPTURE_FAILED) | ||
Logger.printStackTrace(e) | ||
screenCaptureListener.onCaptureFailed(e) | ||
} | ||
|
||
override fun onNext(bitmap: Bitmap) { | ||
screenCaptureListener.onCaptureComplete(bitmap) | ||
} | ||
}) | ||
|
||
} | ||
|
||
fun captureRx(activity: Activity, | ||
vararg ignoredViews: View): Observable<Bitmap> { | ||
|
||
val activityReferenceManager = ActivityReferenceManager() | ||
activityReferenceManager.setActivity(activity) | ||
|
||
val validatedActivity = activityReferenceManager.validatedActivity ?: | ||
return Observable.error<Bitmap>(ActivityNotRunningException(MESSAGE_IS_ACTIVITY_RUNNING)) | ||
|
||
val screenshotProvider = ScreenshotProvider() | ||
|
||
return screenshotProvider.getScreenshotBitmap(validatedActivity, | ||
ignoredViews.asList().toTypedArray()).observeOn(AndroidSchedulers.mainThread()) | ||
} | ||
|
||
/** | ||
* Get single tone instance. | ||
* @param activity . | ||
* * | ||
* @return Instacapture single tone instance. | ||
*/ | ||
|
||
/** | ||
* Enable logging or disable it. | ||
* @param enable set it true to enable logging. | ||
*/ | ||
fun enableLogging(enable: Boolean) { | ||
if (enable) { | ||
Logger.enable() | ||
} else { | ||
Logger.disable() | ||
} | ||
} | ||
|
||
} |
38 changes: 0 additions & 38 deletions
38
instacapture/src/main/java/com/tarek360/instacapture/InstacaptureConfiguration.java
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
...apture/src/main/java/com/tarek360/instacapture/exception/ActivityNotRunningException.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
...acapture/src/main/java/com/tarek360/instacapture/exception/ActivityNotRunningException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.tarek360.instacapture.exception | ||
|
||
/** | ||
* Created by tarek on 5/31/16. | ||
*/ | ||
|
||
/** | ||
* This exception is thrown when the Activity is finished or destroyed. | ||
*/ | ||
class ActivityNotRunningException : RuntimeException { | ||
|
||
constructor() | ||
|
||
constructor(name: String) : super(name) | ||
} | ||
|
Oops, something went wrong.