Dispatch text and image files to external viewers

This commit is contained in:
Adrian Ulrich 2015-10-04 16:32:30 +02:00
parent ad4fa0a9d2
commit 18f5e8a849

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2010, 2011 Christopher Eby <kreed@kreed.org>
* Copyright (C) 2015 Adrian Ulrich <adrian@blinkenlights.ch>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -25,6 +26,7 @@ package ch.blinkenlights.android.vanilla;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Environment;
import android.os.FileObserver;
import android.util.Log;
@ -37,6 +39,7 @@ import android.widget.TextView;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URLConnection;
import java.util.Arrays;
import java.util.Comparator;
import java.util.regex.Pattern;
@ -308,10 +311,29 @@ public class FileSystemAdapter
}
@Override
public void onClick(View view)
{
Intent intent = createData((View)view.getParent());
public void onClick(View view) {
Intent intent = createData((View)view.getParent());
String path = intent.getStringExtra(LibraryAdapter.DATA_FILE);
String mimeGuess = URLConnection.guessContentTypeFromName(path);
boolean isFolder = intent.getBooleanExtra(LibraryAdapter.DATA_EXPANDABLE, false);
if (isFolder == false && mimeGuess != null && mimeGuess.matches("^(image|text)/.+")) { // Dispatch images and text to external apps
boolean fallthrough = false;
File file = new File(path);
Uri uri = Uri.fromFile(file);
Intent extView = new Intent(Intent.ACTION_VIEW);
extView.setDataAndType(uri, mimeGuess);
try {
mActivity.startActivity(extView);
} catch (Exception ActivityNotFoundException) {
fallthrough = true;
}
if (fallthrough == false) // activity was started
return;
}
if (isFolder) {
mActivity.onItemExpanded(intent);
} else {