Skip to content

Commit

Permalink
Fixed error on preview image
Browse files Browse the repository at this point in the history
Fixed error on non-unlimited mode
  • Loading branch information
ThibaudM committed Jun 3, 2017
1 parent 7dde7b4 commit 492efa2
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# built application files
#*.apk
*.apk
*.ap_

# files for the dex VM
Expand Down
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
lintOptions {
disable 'MissingTranslation'
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@
android:name=".timelapse.service.IntervalometerService"
android:exported="false"/>

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.thibaudperso.sonycamera.fileprovider"
android:exported="false"
android:grantUriPermissions="true"
>
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ void sendRequest(final String method, final JSONArray params, final Listener lis
throw new RequestNotWellFormatedException(e);
}

Log.v("DEBUG", "Request URL: "+mWSUrl);
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST,
mWSUrl, inputJsonObject, new Response.Listener<JSONObject>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Arrays;
import java.util.List;

import static com.thibaudperso.sonycamera.timelapse.Constants.LOG_TAG;
import static com.thibaudperso.sonycamera.timelapse.control.connection.StateMachineConnection.State.BAD_API_ACCESS;
import static com.thibaudperso.sonycamera.timelapse.control.connection.StateMachineConnection.State.CHECK_API;
import static com.thibaudperso.sonycamera.timelapse.control.connection.StateMachineConnection.State.GOOD_API_ACCESS;
Expand Down Expand Up @@ -60,7 +61,7 @@ public StateMachineConnection(TimelapseApplication application) {

public void start() {

Log.d("DEBUG", " ----------- StateMachineConnection START -----------");
Log.d(LOG_TAG, " ----------- StateMachineConnection START -----------");
mCurrentState.process(this);

mWifiHandler.setListener(mWifiListener);
Expand All @@ -73,7 +74,7 @@ public void start() {

public void stop() {

Log.d("DEBUG", " ----------- StateMachineConnection STOP -----------");
Log.d(LOG_TAG, " ----------- StateMachineConnection STOP -----------");
mCurrentState.stopAsyncTasks();

mWifiHandler.setListener(null);
Expand Down Expand Up @@ -483,7 +484,7 @@ public void onNewDevice(Device device) {
private void setCurrentState(State newState) {
if (Arrays.asList(newState.previousPossibleStates()).contains(mCurrentState)) {

Log.d("DEBUG", "State: " + mCurrentState + " ---> " + newState);
Log.d(LOG_TAG, "State: " + mCurrentState + " ---> " + newState);
for (Listener listener : mListeners) listener.onNewState(mCurrentState, newState);

mCurrentState.stopAsyncTasks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import java.io.File;

import static android.support.v4.content.FileProvider.getUriForFile;
import static com.thibaudperso.sonycamera.timelapse.Constants.PREF_AUTOMATIC_CONTINUE;

public class AdjustmentsFragment extends Fragment {
Expand Down Expand Up @@ -219,15 +220,25 @@ private void onResultPicture(String url) {
// data network to try to download this image (by default) and it will fail. So we need to
// use the current process to download and store it in a public directory.

mTemporaryPreviewPicture = new File(getContext().getExternalCacheDir(), PREVIEW_PICTURE_NAME);
File imgPath = new File(getContext().getExternalCacheDir(), "images");
if (!imgPath.exists()) {
if (!imgPath.mkdir()) {
throw new RuntimeException("Impossible to create " + imgPath.toString());
}
}
mTemporaryPreviewPicture = new File(imgPath, PREVIEW_PICTURE_NAME);

Request request = new FileRequest<>(url, mTemporaryPreviewPicture,
new Response.Listener<File>() {
@Override
public void onResponse(File file) {
Uri uri = getUriForFile(getContext(),
"com.thibaudperso.sonycamera.fileprovider",
mTemporaryPreviewPicture);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(mTemporaryPreviewPicture), "image/jpeg");
intent.setDataAndType(uri, "image/jpeg");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent, PREVIEW_PICTURE_ACTIVITY_RESULT);
getActivity().overridePendingTransition(0, 0);
}
Expand Down Expand Up @@ -282,7 +293,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
public void onNewState(StateMachineConnection.State previousState,
StateMachineConnection.State newState) {

if(!mIsFragmentResumed) return;
if (!mIsFragmentResumed) return;

if (newState == StateMachineConnection.State.GOOD_API_ACCESS) {
startLiveView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private void updateProgressBar(double millisUntilFinished) {
double ratio = (double) totalElapsedTime / totalTime;
mOverallProgressBar.setProgress((int) totalElapsedTime);
mOverallProgressValue.setText(String.format(getString(R.string.percent1f),
(int) (ratio * 100)));
ratio * 100));
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-cache-path name="my_images" path="images/"/>
</paths>

0 comments on commit 492efa2

Please sign in to comment.