...
This commit is contained in:
@@ -154,10 +154,10 @@
|
||||
</receiver>
|
||||
|
||||
<activity
|
||||
android:name="com.wuadam.awesomewebview.AwesomeWebViewActivity"
|
||||
android:name="kr.lunaticbum.awesomewebview.AwesomeWebViewActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:hardwareAccelerated="true"
|
||||
android:theme="@style/FinestWebViewTheme.Light" />
|
||||
android:theme="@style/FinestWebViewTheme.Fullscreen" />
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
|
||||
@@ -1,168 +1,168 @@
|
||||
package android.print;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class PDFPrint {
|
||||
|
||||
public static void generatePDFFromHTML(final Context context, final File file, final String htmlString, final OnPDFPrintListener onPDFPrintListener) {
|
||||
final WebView mWebView = new WebView(context);
|
||||
mWebView.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
PrintAttributes printAttributes = new PrintAttributes.Builder()
|
||||
.setMediaSize(PrintAttributes.MediaSize.ISO_A4)
|
||||
.setResolution(new PrintAttributes.Resolution("RESOLUTION_ID", "RESOLUTION_ID", 600, 600))
|
||||
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
|
||||
.build();
|
||||
|
||||
final PrintDocumentAdapter documentAdapter = mWebView.createPrintDocumentAdapter(file.getName());
|
||||
documentAdapter.onLayout(null, printAttributes, null, new PrintDocumentAdapter.LayoutResultCallback() {
|
||||
@Override
|
||||
public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {
|
||||
documentAdapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, getOutputFile(file), null, new PrintDocumentAdapter.WriteResultCallback() {
|
||||
|
||||
@Override
|
||||
public void onWriteCancelled() {
|
||||
super.onWriteCancelled();
|
||||
onPDFPrintListener.onError(new Exception("PDF Write cancelled."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteFailed(CharSequence error) {
|
||||
super.onWriteFailed(error);
|
||||
onPDFPrintListener.onError(new Exception(error.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteFinished(PageRange[] pages) {
|
||||
super.onWriteFinished(pages);
|
||||
onPDFPrintListener.onSuccess(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
});
|
||||
mWebView.loadData(htmlString.replaceAll("#", "%23"), "text/HTML", "UTF-8");
|
||||
}
|
||||
|
||||
public static void generatePDFFromWebView(final File file, final WebView webView, final OnPDFPrintListener onPDFPrintListener) {
|
||||
PrintAttributes printAttributes = new PrintAttributes.Builder()
|
||||
.setMediaSize(PrintAttributes.MediaSize.ISO_A4)
|
||||
.setResolution(new PrintAttributes.Resolution("RESOLUTION_ID", "RESOLUTION_ID", 600, 600))
|
||||
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
|
||||
.build();
|
||||
|
||||
final PrintDocumentAdapter documentAdapter = webView.createPrintDocumentAdapter(file.getName());
|
||||
documentAdapter.onLayout(null, printAttributes, null, new PrintDocumentAdapter.LayoutResultCallback() {
|
||||
@Override
|
||||
public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {
|
||||
documentAdapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, getOutputFile(file), null, new PrintDocumentAdapter.WriteResultCallback() {
|
||||
|
||||
@Override
|
||||
public void onWriteCancelled() {
|
||||
super.onWriteCancelled();
|
||||
onPDFPrintListener.onError(new Exception("PDF Write cancelled."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteFailed(CharSequence error) {
|
||||
super.onWriteFailed(error);
|
||||
try {
|
||||
if (error != null && error.toString().length() > 0) {
|
||||
onPDFPrintListener.onError(new Exception(error.toString()));
|
||||
} else {
|
||||
onPDFPrintListener.onError(new Exception("Empty Page"));
|
||||
}
|
||||
}catch (Exception e) {e.printStackTrace();}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteFinished(PageRange[] pages) {
|
||||
super.onWriteFinished(pages);
|
||||
onPDFPrintListener.onSuccess(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
private static ParcelFileDescriptor getOutputFile(File file) {
|
||||
try {
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_WRITE);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PrintJob printPDF(final Activity activity, final File pdfFileToPrint, final PrintAttributes printAttributes) {
|
||||
PrintManager printManager = (PrintManager) activity.getSystemService(Context.PRINT_SERVICE);
|
||||
String jobName = Long.valueOf(System.currentTimeMillis()).toString();
|
||||
return printManager.print(jobName, new PrintDocumentAdapter() {
|
||||
@Override
|
||||
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
|
||||
InputStream input = null;
|
||||
OutputStream output = null;
|
||||
|
||||
try {
|
||||
|
||||
input = new FileInputStream(pdfFileToPrint);
|
||||
output = new FileOutputStream(destination.getFileDescriptor());
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
int bytesRead;
|
||||
|
||||
while ((bytesRead = input.read(buf)) > 0) {
|
||||
output.write(buf, 0, bytesRead);
|
||||
}
|
||||
|
||||
callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES});
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
input.close();
|
||||
output.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
|
||||
if (cancellationSignal.isCanceled()) {
|
||||
callback.onLayoutCancelled();
|
||||
return;
|
||||
}
|
||||
|
||||
PrintDocumentInfo pdi = new PrintDocumentInfo.Builder(pdfFileToPrint.getName()).setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build();
|
||||
callback.onLayoutFinished(pdi, true);
|
||||
}
|
||||
}, printAttributes);
|
||||
}
|
||||
|
||||
public interface OnPDFPrintListener {
|
||||
void onSuccess(File file);
|
||||
|
||||
void onError(Exception exception);
|
||||
}
|
||||
}
|
||||
//package android.print;
|
||||
//
|
||||
//import android.app.Activity;
|
||||
//import android.content.Context;
|
||||
//import android.os.Bundle;
|
||||
//import android.os.CancellationSignal;
|
||||
//import android.os.ParcelFileDescriptor;
|
||||
//import android.webkit.WebView;
|
||||
//import android.webkit.WebViewClient;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.io.FileInputStream;
|
||||
//import java.io.FileOutputStream;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStream;
|
||||
//import java.io.OutputStream;
|
||||
//
|
||||
//public class PDFPrint {
|
||||
//
|
||||
// public static void generatePDFFromHTML(final Context context, final File file, final String htmlString, final OnPDFPrintListener onPDFPrintListener) {
|
||||
// final WebView mWebView = new WebView(context);
|
||||
// mWebView.setWebViewClient(new WebViewClient() {
|
||||
// @Override
|
||||
// public void onPageFinished(WebView view, String url) {
|
||||
// PrintAttributes printAttributes = new PrintAttributes.Builder()
|
||||
// .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
|
||||
// .setResolution(new PrintAttributes.Resolution("RESOLUTION_ID", "RESOLUTION_ID", 600, 600))
|
||||
// .setMinMargins(PrintAttributes.Margins.NO_MARGINS)
|
||||
// .build();
|
||||
//
|
||||
// final PrintDocumentAdapter documentAdapter = mWebView.createPrintDocumentAdapter(file.getName());
|
||||
// documentAdapter.onLayout(null, printAttributes, null, new PrintDocumentAdapter.LayoutResultCallback() {
|
||||
// @Override
|
||||
// public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {
|
||||
// documentAdapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, getOutputFile(file), null, new PrintDocumentAdapter.WriteResultCallback() {
|
||||
//
|
||||
// @Override
|
||||
// public void onWriteCancelled() {
|
||||
// super.onWriteCancelled();
|
||||
// onPDFPrintListener.onError(new Exception("PDF Write cancelled."));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onWriteFailed(CharSequence error) {
|
||||
// super.onWriteFailed(error);
|
||||
// onPDFPrintListener.onError(new Exception(error.toString()));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onWriteFinished(PageRange[] pages) {
|
||||
// super.onWriteFinished(pages);
|
||||
// onPDFPrintListener.onSuccess(file);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }, null);
|
||||
// }
|
||||
// });
|
||||
// mWebView.loadData(htmlString.replaceAll("#", "%23"), "text/HTML", "UTF-8");
|
||||
// }
|
||||
//
|
||||
// public static void generatePDFFromWebView(final File file, final WebView webView, final OnPDFPrintListener onPDFPrintListener) {
|
||||
// PrintAttributes printAttributes = new PrintAttributes.Builder()
|
||||
// .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
|
||||
// .setResolution(new PrintAttributes.Resolution("RESOLUTION_ID", "RESOLUTION_ID", 600, 600))
|
||||
// .setMinMargins(PrintAttributes.Margins.NO_MARGINS)
|
||||
// .build();
|
||||
//
|
||||
// final PrintDocumentAdapter documentAdapter = webView.createPrintDocumentAdapter(file.getName());
|
||||
// documentAdapter.onLayout(null, printAttributes, null, new PrintDocumentAdapter.LayoutResultCallback() {
|
||||
// @Override
|
||||
// public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {
|
||||
// documentAdapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, getOutputFile(file), null, new PrintDocumentAdapter.WriteResultCallback() {
|
||||
//
|
||||
// @Override
|
||||
// public void onWriteCancelled() {
|
||||
// super.onWriteCancelled();
|
||||
// onPDFPrintListener.onError(new Exception("PDF Write cancelled."));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onWriteFailed(CharSequence error) {
|
||||
// super.onWriteFailed(error);
|
||||
// try {
|
||||
// if (error != null && error.toString().length() > 0) {
|
||||
// onPDFPrintListener.onError(new Exception(error.toString()));
|
||||
// } else {
|
||||
// onPDFPrintListener.onError(new Exception("Empty Page"));
|
||||
// }
|
||||
// }catch (Exception e) {e.printStackTrace();}
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onWriteFinished(PageRange[] pages) {
|
||||
// super.onWriteFinished(pages);
|
||||
// onPDFPrintListener.onSuccess(file);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }, null);
|
||||
// }
|
||||
//
|
||||
// private static ParcelFileDescriptor getOutputFile(File file) {
|
||||
// try {
|
||||
// if (!file.exists()) {
|
||||
// file.createNewFile();
|
||||
// }
|
||||
// return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_WRITE);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public static PrintJob printPDF(final Activity activity, final File pdfFileToPrint, final PrintAttributes printAttributes) {
|
||||
// PrintManager printManager = (PrintManager) activity.getSystemService(Context.PRINT_SERVICE);
|
||||
// String jobName = Long.valueOf(System.currentTimeMillis()).toString();
|
||||
// return printManager.print(jobName, new PrintDocumentAdapter() {
|
||||
// @Override
|
||||
// public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
|
||||
// InputStream input = null;
|
||||
// OutputStream output = null;
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// input = new FileInputStream(pdfFileToPrint);
|
||||
// output = new FileOutputStream(destination.getFileDescriptor());
|
||||
//
|
||||
// byte[] buf = new byte[1024];
|
||||
// int bytesRead;
|
||||
//
|
||||
// while ((bytesRead = input.read(buf)) > 0) {
|
||||
// output.write(buf, 0, bytesRead);
|
||||
// }
|
||||
//
|
||||
// callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES});
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// try {
|
||||
// input.close();
|
||||
// output.close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
|
||||
// if (cancellationSignal.isCanceled()) {
|
||||
// callback.onLayoutCancelled();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// PrintDocumentInfo pdi = new PrintDocumentInfo.Builder(pdfFileToPrint.getName()).setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build();
|
||||
// callback.onLayoutFinished(pdi, true);
|
||||
// }
|
||||
// }, printAttributes);
|
||||
// }
|
||||
//
|
||||
// public interface OnPDFPrintListener {
|
||||
// void onSuccess(File file);
|
||||
//
|
||||
// void onError(Exception exception);
|
||||
// }
|
||||
//}
|
||||
@@ -341,9 +341,8 @@ internal class LauncherActivity : AppCompatActivity() {
|
||||
BLog.LOGE("onConfigurationChanged Configuration >> ${newConfig}")
|
||||
|
||||
BLog.LOGE("onConfigurationChanged newConfig?.screenWidthDp >> ${newConfig?.screenWidthDp}")
|
||||
isOpendFold = (newConfig?.screenWidthDp?.toInt() ?: 0 > 700) == true
|
||||
// binding.viewPager.invalidate()
|
||||
// binding.viewPager.currentItem = 1
|
||||
BLog.LOGE("onConfigurationChanged newConfig?.screenHeightDp >> ${newConfig?.screenHeightDp}")
|
||||
isOpendFold = (newConfig.screenWidthDp * 1.1f) > newConfig.screenHeightDp
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
|
||||
@@ -42,7 +42,7 @@ import bums.lunatic.launcher.workers.WorkersDb
|
||||
import com.google.android.material.imageview.ShapeableImageView
|
||||
import com.google.gson.Gson
|
||||
import com.squareup.picasso.Picasso
|
||||
import com.wuadam.awesomewebview.AwesomeWebView
|
||||
import kr.lunaticbum.awesomewebview.AwesomeWebView
|
||||
import io.realm.kotlin.UpdatePolicy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
@@ -78,9 +78,11 @@ internal class RssItemAdapter (
|
||||
// show(lActivity!!.supportFragmentManager,rss.originPage)
|
||||
// }
|
||||
} else {
|
||||
RssViewer().apply {
|
||||
show(lActivity!!.supportFragmentManager,rss.originPage)
|
||||
}
|
||||
// RssViewer().apply {
|
||||
// show(lActivity!!.supportFragmentManager,rss.originPage)
|
||||
// }
|
||||
AwesomeWebView.Builder(lActivity!!).showIconClose(true).showIconBack(false).showProgressBar(true).webViewMixedContentMode(0)
|
||||
.show(rss.originPage!!)
|
||||
// openOpera(rss.originPage())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user