summaryrefslogtreecommitdiff
path: root/app/src/main/java/uk/co/blatech/blaupload/ImagePager.java
blob: f562e2f4ada4f9a2ce9fc3ab254e396a98e46be3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package uk.co.blatech.blaupload;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import uk.co.blatech.blaupload.ui.ImagePagerAdapter;
import uk.co.blatech.blaupload.ui.ZoomViewPager;
import uk.co.blatech.blaupload.util.EventBus;

public class ImagePager extends Activity {


    private ZoomViewPager mViewPager;
    private JSONArray json;
    private ArrayList<String> urls;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_pager);

        mViewPager = (ZoomViewPager) findViewById(R.id.imagePager);
        EventBus.getInstance().register(this);
        urls = new ArrayList<String>();
        String jsonText = getIntent().getStringExtra("json");
        int id = getIntent().getIntExtra("position", 0);

        try {
            json = new JSONArray(jsonText);
        } catch (JSONException e) {
            //TODO: Error handling if we got something other than JSON
            Log.e(ImagePager.class.toString(), "Failed to parse JSON");
            e.printStackTrace();
        }

        for (int i = 0; i < json.length(); i++) {
            try {
                JSONObject item = json.getJSONObject(i);
                urls.add("http://www.lc8n.com/bla500/"+item.getString("filename"));

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

        ImagePagerAdapter adapter = new ImagePagerAdapter(ImagePager.this, urls);
        mViewPager.setAdapter(adapter);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.image_pager, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }


}