Remove sucking streampipe totally

This commit is contained in:
tarsin committed 2023-01-30 14:55:54 +08:00
1 parent 2d11a29a79
commit d7f050efc4
4 files changed
-220

No files matched your search

@@ -48,7 +48,6 @@ import com.hippo.ehviewer.dao.buildMainDB
import com.hippo.ehviewer.download.DownloadManager
import com.hippo.ehviewer.ui.CommonOperations
import com.hippo.ehviewer.ui.EhActivity
import com.hippo.util.BitmapUtils
import com.hippo.util.ExceptionUtils
import com.hippo.util.ReadableTime
import com.hippo.yorozuya.FileUtils
@@ -105,7 +104,6 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
Settings.initialize()
ReadableTime.initialize(this)
AppConfig.initialize(this)
BitmapUtils.initialize(this)
EhTagDatabase.update()
AppCompatDelegate.setDefaultNightMode(Settings.getTheme())
launchIO {
@@ -1,58 +0,0 @@
/*
* Copyright 2015 Hippo Seven
*
* 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 com.hippo.io;
import androidx.annotation.NonNull;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.IOUtils;
import java.io.IOException;
import java.io.InputStream;
public class UniFileInputStreamPipe implements InputStreamPipe {
private final UniFile mFile;
private InputStream mIs;
public UniFileInputStreamPipe(UniFile file) {
mFile = file;
}
@Override
public void release() {
// Empty
}
@NonNull
@Override
public InputStream open() throws IOException {
if (mIs != null) {
throw new IllegalStateException("Please close it first");
}
mIs = mFile.openInputStream();
return mIs;
}
@Override
public void close() {
IOUtils.closeQuietly(mIs);
mIs = null;
}
}
@@ -1,32 +0,0 @@
/*
* Copyright 2015-2016 Hippo Seven
*
* 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 com.hippo.streampipe;
import androidx.annotation.NonNull;
import java.io.IOException;
import java.io.InputStream;
public interface InputStreamPipe {
void release();
@NonNull
InputStream open() throws IOException;
void close();
}
@@ -1,128 +0,0 @@
/*
* Copyright 2015 Hippo Seven
*
* 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 com.hippo.util;
import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import androidx.annotation.NonNull;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.yorozuya.MathUtils;
import java.io.IOException;
public final class BitmapUtils {
public static ActivityManager activityManager;
private BitmapUtils() {
}
public static void initialize(Context context) {
activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
}
public static long availableMemory() {
final Runtime runtime = Runtime.getRuntime();
final long used = runtime.totalMemory() - runtime.freeMemory();
final long total = (long) activityManager.getMemoryClass() * 1024 * 1024;
return total - used;
}
public static Bitmap decodeStream(@NonNull InputStreamPipe isp, int maxWidth, int maxHeight,
int pixels, boolean checkMemory, boolean justCalc, int[] sampleSize) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(isp.open(), null, options);
isp.close();
int width = options.outWidth;
int height = options.outHeight;
if (width <= 0 || height <= 0) {
if (sampleSize != null && sampleSize.length >= 1) {
sampleSize[0] = -1;
}
return null;
}
int scaleW = 1;
int scaleH = 1;
int scaleP = 1;
int scaleM = 1;
if (maxWidth > 0 && width > maxWidth) {
scaleW = MathUtils.ceilDivide(width, maxWidth);
}
if (maxHeight > 0 && height > maxHeight) {
scaleH = MathUtils.ceilDivide(height, maxHeight);
}
if (pixels > 0 && width * height > pixels) {
scaleP = (int) Math.ceil(Math.sqrt(width * height / (float) pixels));
}
if (checkMemory) {
long m = availableMemory() - 5 * 1024 * 1024; // Leave 5m
if (m < 0) {
if (sampleSize != null && sampleSize.length >= 1) {
sampleSize[0] = -1;
}
return null;
}
if ((long) width * height * 3 > m) {
scaleM = (int) Math.ceil(Math.sqrt(width * height * 3 / (float) m));
}
}
options.inSampleSize = MathUtils.nextPowerOf2(MathUtils.max(scaleW, scaleH, scaleP, scaleM, 1));
if (sampleSize != null && sampleSize.length >= 1) {
sampleSize[0] = options.inSampleSize;
}
options.inJustDecodeBounds = false;
if (justCalc) {
return null;
} else {
try {
return BitmapFactory.decodeStream(isp.open(), null, options);
} catch (OutOfMemoryError e) {
if (sampleSize != null && sampleSize.length >= 1) {
sampleSize[0] = -1;
}
return null;
}
}
} catch (IOException e) {
if (sampleSize != null && sampleSize.length >= 1) {
sampleSize[0] = -1;
}
return null;
} finally {
isp.close();
isp.release();
}
}
/**
* @return null or the bitmap
*/
public static Bitmap decodeStream(@NonNull InputStreamPipe isp, int maxWidth, int maxHeight) {
return decodeStream(isp, maxWidth, maxHeight, -1, false, false, null);
}
}