added "Open Image in Browser"-Intent
This commit is contained in:
parent
27f4c93582
commit
c101b48c19
1 changed files with 11 additions and 10 deletions
|
@ -35,7 +35,6 @@ import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.support.annotation.DrawableRes;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -44,7 +43,6 @@ import android.view.LayoutInflater;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.SubMenu;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.webkit.ConsoleMessage;
|
import android.webkit.ConsoleMessage;
|
||||||
|
@ -60,7 +58,6 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -328,7 +325,7 @@ public class NewsDetailFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private URL downloadUrl;
|
private URL imageUrl;
|
||||||
private long downloadID;
|
private long downloadID;
|
||||||
private DownloadManager dlManager;
|
private DownloadManager dlManager;
|
||||||
private BroadcastReceiver downloadCompleteReceiver;
|
private BroadcastReceiver downloadCompleteReceiver;
|
||||||
|
@ -352,7 +349,7 @@ public class NewsDetailFragment extends Fragment {
|
||||||
Elements imgtag = htmldoc.getElementsByAttributeValueContaining("src", imageUrl);
|
Elements imgtag = htmldoc.getElementsByAttributeValueContaining("src", imageUrl);
|
||||||
imgaltval = imgtag.first().attr("alt");
|
imgaltval = imgtag.first().attr("alt");
|
||||||
imgsrcval = imageUrl.substring(imageUrl.lastIndexOf('/') + 1, imageUrl.length());
|
imgsrcval = imageUrl.substring(imageUrl.lastIndexOf('/') + 1, imageUrl.length());
|
||||||
downloadUrl = new URL(imageUrl);
|
this.imageUrl = new URL(imageUrl);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -387,22 +384,26 @@ public class NewsDetailFragment extends Fragment {
|
||||||
}
|
}
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_downloadimg:
|
case R.id.action_downloadimg:
|
||||||
downloadImage(downloadUrl);
|
downloadImage(imageUrl);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_shareimg:
|
case R.id.action_shareimg:
|
||||||
//Intent Share
|
//Intent Share
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_openimg:
|
case R.id.action_openimg:
|
||||||
//Intent OpenInBrowser
|
openImageInBrowser(imageUrl);
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.onContextItemSelected(item);
|
return super.onContextItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openImageInBrowser(URL url) {
|
||||||
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||||
|
i.setData(Uri.parse(url.toString()));
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void downloadImage(URL url) {
|
||||||
public void downloadImage(URL url) {
|
|
||||||
if(isExternalStorageWritable()) {
|
if(isExternalStorageWritable()) {
|
||||||
String filename = url.getFile().substring(url.getFile().lastIndexOf('/') + 1, url.getFile().length());
|
String filename = url.getFile().substring(url.getFile().lastIndexOf('/') + 1, url.getFile().length());
|
||||||
dlManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
|
dlManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||||
|
|
Loading…
Reference in a new issue