aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
diff options
context:
space:
mode:
authorLibravatar Renard1911 2016-04-11 17:52:55 -0300
committerLibravatar Renard1911 2016-04-11 17:52:55 -0300
commitc94f0e1d27f0a92a17b2e65363bdce6461249d95 (patch)
tree6990d471d884ad87a2be9234e40fd2a91f6bb827 /app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
parent0f3adf23154e6d7e0eaced70a31676d71bef8e34 (diff)
parent90ee611af8ba4c38e70f27eb0df55e9134ad625c (diff)
downloadBaiApp-1.6.0.tar.gz
BaiApp-1.6.0.tar.xz
BaiApp-1.6.0.zip
Merge pull request #1 from Renard1911/devv1.6.0
Dev
Diffstat (limited to 'app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java')
-rw-r--r--app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java208
1 files changed, 51 insertions, 157 deletions
diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
index 4501c0f..8dc1262 100644
--- a/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
+++ b/app/src/main/java/org/bienvenidoainternet/baiparser/ViewerActivity.java
@@ -2,55 +2,71 @@ package org.bienvenidoainternet.baiparser;
import android.content.Context;
import android.content.ContextWrapper;
-import android.graphics.Bitmap;
-import android.os.AsyncTask;
+import android.media.MediaScannerConnection;
+import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
+import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
-import com.davemorrissey.labs.subscaleview.ImageSource;
-import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
-import com.koushikdutta.async.future.FutureCallback;
-import com.koushikdutta.ion.Ion;
-
-import org.bienvenidoainternet.baiparser.structure.BoardItem;
+import org.bienvenidoainternet.baiparser.structure.BoardItemFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.ArrayList;
-import pl.droidsonroids.gif.GifDrawable;
-import pl.droidsonroids.gif.GifImageView;
-
-public class ViewerActivity extends AppCompatActivity {
- private SubsamplingScaleImageView imageView;
- private GifImageView gifView;
- private BoardItem bi;
- File imagePath;
+import layout.FragmentImage;
+public class ViewerActivity extends AppCompatActivity implements FragmentImage.OnFragmentInteractionListener {
+ private static final String EXTRA_FILELIST = "fileList", EXTRA_RELATIVEPOSITION = "position";
+ private ViewPager imagePager;
+ public ProgressBar barDownload;
+ private int relativePosition = 0;
+ public ArrayList<BoardItemFile> fileList = new ArrayList<BoardItemFile>();
+ private CustomFragmentPagerAdapter pagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (savedInstanceState != null){
- bi = savedInstanceState.getParcelable("boardItem");
- }
if (getIntent().getExtras() != null){
- bi = getIntent().getParcelableExtra("boardItem");
+ fileList = getIntent().getParcelableArrayListExtra(EXTRA_FILELIST);
+ relativePosition = getIntent().getIntExtra(EXTRA_RELATIVEPOSITION, 0);
}
setContentView(R.layout.activity_viewer);
- imageView = (SubsamplingScaleImageView)findViewById(R.id.imageView);
- gifView = (GifImageView) findViewById(R.id.gifView);
- setTitle(bi.getFile());
- downloadFile();
+ barDownload = (ProgressBar) findViewById(R.id.downloadProgressBar);
+ imagePager = (ViewPager) findViewById(R.id.imagePager);
+ this.pagerAdapter = new CustomFragmentPagerAdapter(getSupportFragmentManager());
+ for (int i = 0; i < fileList.size(); i++){
+ Log.v("ImageViewer", fileList.get(i).toString());
+ pagerAdapter.addFragment(FragmentImage.newInstance(fileList.get(i)));
+ }
+ imagePager.setAdapter(pagerAdapter);
+ imagePager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ getSupportActionBar().setSubtitle("(" + (position + 1) + " / " + fileList.size() + ") " + fileList.get(position).file);
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+
+ }
+ });
+ imagePager.setCurrentItem(relativePosition);
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@@ -61,9 +77,13 @@ public class ViewerActivity extends AppCompatActivity {
baiDir.mkdir();
}
if (item.getItemId() == R.id.menu_save_img){
- File to = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/" + bi.getFile());
+ BoardItemFile boardItemFile = fileList.get(imagePager.getCurrentItem());
+ File to = new File(Environment.getExternalStorageDirectory().getPath() + "/Bai/" + boardItemFile.file);
+ ContextWrapper cw = new ContextWrapper(getApplicationContext());
+ File directory = cw.getDir("src", Context.MODE_PRIVATE);
+ File fileSource = new File(directory, boardItemFile.boardDir + "_" + boardItemFile.file);
try{
- InputStream in = new FileInputStream(imagePath);
+ InputStream in = new FileInputStream(fileSource);
OutputStream out = new FileOutputStream(to);
byte[] buf = new byte[1024];
int len;
@@ -72,7 +92,8 @@ public class ViewerActivity extends AppCompatActivity {
}
in.close();
out.close();
- Toast.makeText(getApplicationContext(), bi.getFile() + " guardado.", Toast.LENGTH_LONG).show();
+ Toast.makeText(getApplicationContext(), boardItemFile.file + " guardado.", Toast.LENGTH_LONG).show();
+ MediaScannerConnection.scanFile(this, new String[]{to.getPath()}, new String[]{"image/jpeg"}, null);
}catch (Exception e){
e.printStackTrace();
}
@@ -91,135 +112,8 @@ public class ViewerActivity extends AppCompatActivity {
return true;
}
- private void downloadFile(){
- ContextWrapper cw = new ContextWrapper(getApplicationContext());
- File directory = cw.getDir("src", Context.MODE_PRIVATE);
- final File filePath = new File(directory, bi.getParentBoard().getBoardDir() + "_" + bi.getFile());
- final ProgressBar downloadBar = (ProgressBar) findViewById(R.id.downloadProgressBar);
- if (filePath.exists()){
- downloadBar.setVisibility(View.GONE);
- if (bi.getFile().endsWith(".gif")){
- try {
- GifDrawable gifFromFile = new GifDrawable(filePath);
- gifView.setImageDrawable(gifFromFile);
- imageView.setVisibility(View.GONE);
- }catch(Exception e){
- e.printStackTrace();
- }
- }else{
- imageView.setImage(ImageSource.uri(filePath.toURI().getPath()));
- gifView.setVisibility(View.GONE);
- }
- }
- Ion.with(getApplicationContext())
- .load("http://bienvenidoainternet.org/" + bi.getParentBoard().getBoardDir() + "/src/" + bi.getFile())
- .progressBar(downloadBar)
- .asInputStream()
- .setCallback(new FutureCallback<InputStream>() {
- @Override
- public void onCompleted(Exception e, InputStream result) {
- downloadBar.setVisibility(View.GONE);
- if (e != null){
- e.printStackTrace();
- }else{
- FileOutputStream fout;
- try {
- fout = new FileOutputStream(filePath);
- final byte data[] = new byte[1024];
- int count;
- while ((count = result.read(data, 0, 1024)) != -1) {
- fout.write(data, 0, count);
- }
- }catch(Exception e1) {
- e1.printStackTrace();
- }
- if (bi.getFile().endsWith(".gif")){
- try {
- GifDrawable gifFromFile = new GifDrawable(filePath);
- gifView.setImageDrawable(gifFromFile);
- imageView.setVisibility(View.GONE);
- }catch(Exception e2){
- e2.printStackTrace();
- }
- }else{
- imageView.setImage(ImageSource.uri(filePath.toURI().getPath()));
- gifView.setVisibility(View.GONE);
- }
- }
- }
- });
- }
-
- class TaskDownloadFile extends AsyncTask<Void, Void, File> {
-
- @Override
- protected File doInBackground(Void... params) {
- Bitmap downloadedBitmap = null;
- ContextWrapper cw = new ContextWrapper(getApplicationContext());
- File directory = cw.getDir("src", Context.MODE_PRIVATE);
- File mypath = new File(directory, bi.getParentBoard().getBoardDir() + "_" + bi.getFile());
- if (mypath.exists()){
- System.out.println("[Viewer] resource exist!");
- return mypath;
- }
- try {
- String sUrl = "http://bienvenidoainternet.org/" + bi.getParentBoard().getBoardDir() + "/src/" + bi.getFile();
- System.out.println("[Viewer]dwonloading " + sUrl);
-// System.out.println(sUrl);
- InputStream in = new java.net.URL(sUrl).openStream();
-// downloadedBitmap = BitmapFactory.decodeStream(in);
-
-// if (downloadedBitmap != null){
- FileOutputStream fout = null;
- try {
-// in = new BufferedInputStream(new URL(urlString).openStream());
- fout = new FileOutputStream(mypath);
-
- final byte data[] = new byte[1024];
- int count;
- while ((count = in.read(data, 0, 1024)) != -1) {
- fout.write(data, 0, count);
- }
-
-
- }catch(Exception e){
- e.printStackTrace();
- }finally {
- if (in != null) {
- in.close();
- }
- if (fout != null) {
- fout.close();
- }
- }
-// }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return mypath;
- }
-
- @Override
- protected void onPostExecute(File file) {
- super.onPostExecute(file);
- imagePath = file;
-// iv.setImageBitmap(bitmap);
- if (bi.getFile().endsWith(".gif")){
- try {
- GifDrawable gifFromFile = new GifDrawable(file);
- gifView.setImageDrawable(gifFromFile);
- imageView.setVisibility(View.GONE);
- }catch(Exception e){
- e.printStackTrace();
- }
- }else{
- imageView.setImage(ImageSource.uri(file.toURI().getPath()));
- gifView.setVisibility(View.GONE);
-// imageView.setImage(ImageSource.resource(R.drawable.bai));
-// System.out.println("not a gif file: " + file.toURI().getPath());
- }
+ @Override
+ public void onFragmentInteraction(Uri uri) {
- }
}
}