pdf support via pdfjs

This commit is contained in:
Page Asgardius 2022-09-17 12:35:34 -07:00
parent 74700dd23f
commit c34010680f
4 changed files with 23 additions and 4 deletions

View file

@ -29,6 +29,7 @@ import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.S3ObjectSummary; import com.amazonaws.services.s3.model.S3ObjectSummary;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -132,6 +133,9 @@ public class ObjectSelect extends AppCompatActivity {
else if (Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".txt") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".md")) { else if (Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".txt") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".md")) {
Img.add(R.drawable.textfile); Img.add(R.drawable.textfile);
} }
else if (Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".pdf")) {
Img.add(R.drawable.pdffile);
}
else if (Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".jpg") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".jpeg") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".png") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".gif")) { else if (Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".jpg") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".jpeg") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".png") || Name.get(i).toString().toLowerCase(Locale.ROOT).endsWith(".gif")) {
Img.add(R.drawable.imagefile); Img.add(R.drawable.imagefile);
} }
@ -219,6 +223,16 @@ public class ObjectSelect extends AppCompatActivity {
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
} }
} else if (Img.get(position).equals(R.drawable.pdffile)) {
//load media file
try {
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString());
URL objectURL = s3client.generatePresignedUrl(request);
//System.out.println(getResources().getString(R.string.pdf_reader)+ URLEncoder.encode(objectURL.toString(), "UTF-8" ));
webBrowser(getResources().getString(R.string.pdf_reader)+ URLEncoder.encode(objectURL.toString(), "UTF-8" ), Name.get(position).toString());
} catch (Exception e) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
}
} else if (Img.get(position).equals(R.drawable.audiofile) || Img.get(position).equals(R.drawable.videofile)) { } else if (Img.get(position).equals(R.drawable.audiofile) || Img.get(position).equals(R.drawable.videofile)) {
//load media file //load media file
try { try {

View file

@ -3,12 +3,14 @@ package asgardius.page.s3manager;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
public class WebBrowser extends AppCompatActivity { public class WebBrowser extends AppCompatActivity {
private WebView npw; private WebView browser;
WebSettings webSettings;
String webURL, pagetitle; String webURL, pagetitle;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -19,9 +21,11 @@ public class WebBrowser extends AppCompatActivity {
webURL = getIntent().getStringExtra("web_url"); webURL = getIntent().getStringExtra("web_url");
pagetitle = getIntent().getStringExtra("title"); pagetitle = getIntent().getStringExtra("title");
getSupportActionBar().setTitle(pagetitle); getSupportActionBar().setTitle(pagetitle);
npw =(WebView)findViewById(R.id.webview); browser =(WebView)findViewById(R.id.webview);
npw.setWebViewClient(new MyBrowser()); webSettings = browser.getSettings();
npw.loadUrl(webURL); webSettings.setJavaScriptEnabled(true);
browser.setWebViewClient(new MyBrowser());
browser.loadUrl(webURL);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
finish(); finish();

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -2,6 +2,7 @@
<string name="app_name" translatable="false">S3 Manager</string> <string name="app_name" translatable="false">S3 Manager</string>
<string name="aws_endpoint" translatable="false">.amazonaws.com</string> <string name="aws_endpoint" translatable="false">.amazonaws.com</string>
<string name="endpoint_url" translatable="false">https://object.asgardius.company</string> <string name="endpoint_url" translatable="false">https://object.asgardius.company</string>
<string name="pdf_reader" translatable="false">https://office.asgardius.company/pdfjs/web/viewer.html?file=</string>
<string name="access_key" translatable="false">google</string> <string name="access_key" translatable="false">google</string>
<string name="account_list">Account list</string> <string name="account_list">Account list</string>
<string name="bucket_list">Bucket list</string> <string name="bucket_list">Bucket list</string>