-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stickers #1958
Open
apjagdale
wants to merge
6
commits into
Samsung:master
Choose a base branch
from
apjagdale:stickers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Stickers #1958
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
23c9cc6
Optimize animation data structure
NolaDonato 839fe9f
Merge branch 'animdata' of https://github.com/NolaDonato/GearVRf
apjagdale 73ca334
Merge branch 'master' of https://github.com/Samsung/GearVRf
apjagdale 9e81d10
Added new feature to dump screenshots to SD Card
apjagdale 0794a70
Rebasing
apjagdale c16837d
Renaming functions
apjagdale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
150 changes: 150 additions & 0 deletions
150
GVRf/Framework/framework/src/main/java/org/gearvrf/GVRSticker.java
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,150 @@ | ||
/* Copyright 2015 Samsung Electronics Co., LTD | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.gearvrf; | ||
|
||
import android.graphics.Bitmap; | ||
import android.os.Environment; | ||
import android.util.Log; | ||
|
||
import org.gearvrf.utility.Threads; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* This class takes screenshots at a specified interval and writes the output PNG files to GearVRFScreenshots directory. | ||
* The capturing can be stopped by calling {@link GVRSticker#stop()} | ||
* The images can be used to create Stickers (a GIF animation) | ||
*/ | ||
|
||
public class GVRSticker { | ||
private final GVRContext mGVRContext; | ||
private final String mTag; | ||
private final String mDirectory; | ||
private final long mInterval; | ||
private boolean mCaptureFlag = true; | ||
private final static String TAG = "GVRSticker"; | ||
|
||
/** | ||
* Constructor takes the following parameters | ||
* @param gvrContext | ||
* @param tag | ||
* Name for outputting PNG's to the SD Card along with appended frame ID | ||
* @param interval | ||
* Time in milliseconds to take screenshot at that interval | ||
*/ | ||
public GVRSticker(GVRContext gvrContext, String tag, long interval){ | ||
mGVRContext = gvrContext; | ||
mTag = tag; | ||
mInterval = interval; | ||
|
||
File sdcard = Environment.getExternalStorageDirectory(); | ||
mDirectory = sdcard.getAbsolutePath() + "/GearVRFScreenshots/"; | ||
File d = new File(mDirectory); | ||
d.mkdirs(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably the fact that WRITE_EXTERNAL_STORAGE is required should be mentioned. Also I'd recommend checking the return value of mkdirs and throwing an exception immediately if needed. |
||
} | ||
|
||
private boolean lastScreenshotFinished[] = {true, true, true}; | ||
private int pboIndex = 0; | ||
|
||
/** | ||
* Initiate's the screenshot capturing | ||
* Captures images every {@link GVRSticker#mInterval} milliseconds | ||
*/ | ||
public void startCapturing() | ||
{ | ||
mCaptureFlag = true; | ||
Threads.spawn(new Runnable() | ||
{ | ||
public void run() | ||
{ | ||
int frame = 0; | ||
boolean lastStickerCall; | ||
while(mCaptureFlag) { | ||
if (lastScreenshotFinished[pboIndex]) { | ||
lastStickerCall = mGVRContext | ||
.captureSticker(newScreenshotCallback(frame, pboIndex), pboIndex); | ||
if(lastStickerCall) { | ||
lastScreenshotFinished[pboIndex] = false; | ||
pboIndex = (pboIndex + 1) % 3; | ||
frame++; | ||
} | ||
} | ||
else{ | ||
Log.e(TAG, "Sticker skipped since previous read is not completed"); | ||
} | ||
try { | ||
Thread.sleep(mInterval); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Stop's the screenshot thread | ||
*/ | ||
public void stopCapturing(){ | ||
mCaptureFlag = false; | ||
} | ||
|
||
private GVRScreenshotCallback newScreenshotCallback(final int frame, final int currentPboIndex) | ||
{ | ||
return new GVRScreenshotCallback() | ||
{ | ||
@Override | ||
public void onScreenCaptured(Bitmap bitmap) | ||
{ | ||
if (bitmap != null) | ||
{ | ||
File file = new File(mDirectory + mTag +"_"+ frame +"_" + ".png"); | ||
FileOutputStream outputStream = null; | ||
try | ||
{ | ||
outputStream = new FileOutputStream(file); | ||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream); | ||
} | ||
catch (FileNotFoundException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
finally | ||
{ | ||
try | ||
{ | ||
outputStream.close(); | ||
} | ||
catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
Log.e(TAG, "Returned Bitmap is null for frame " + frame); | ||
} | ||
|
||
// enable next screenshot | ||
lastScreenshotFinished[currentPboIndex] = true; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about other backend adapters?