From e76532780b58c037d749381283fe3a1ecde9c54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20P=C3=B3=C5=82grabia?= Date: Sat, 27 Aug 2016 21:31:54 +0200 Subject: [PATCH] Added fragment which allows to show enlarged panoramio photo. --- .../urbanexplorer/MainActivity.java | 36 ++++++++++-- .../urbanexplorer/dto/PanoramioImageInfo.java | 4 +- .../urbanexplorer/fragments/HomeFragment.java | 15 ++++- .../fragments/PanoramioShowerFragment.java | 57 +++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 15 ++--- .../res/layout/fragment_panoramio_shower.xml | 24 ++++++++ 6 files changed, 137 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java create mode 100644 app/src/main/res/layout/fragment_panoramio_shower.xml diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java index cb14140..a72565f 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java @@ -1,25 +1,25 @@ package pl.tpolgrabia.urbanexplorer; -import android.content.Intent; -import android.location.LocationManager; import android.os.Bundle; -import android.provider.Settings; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBarActivity; -import android.support.v7.widget.Toolbar; import android.view.MenuItem; -import android.widget.Toast; import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; import com.nostra13.universalimageloader.core.assist.ImageScaleType; import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; +import pl.tpolgrabia.urbanexplorer.dto.PanoramioImageInfo; import pl.tpolgrabia.urbanexplorer.fragments.HomeFragment; +import pl.tpolgrabia.urbanexplorer.fragments.PanoramioShowerFragment; public class MainActivity extends ActionBarActivity { private static final int LOCATION_SETTINGS_REQUEST_ID = 1; private static final String CLASS_TAG = MainActivity.class.getSimpleName(); + private static final String PHOTO_BACKSTACK = "PHOTO_BACKSTACK"; public static DisplayImageOptions options; @Override @@ -45,6 +45,11 @@ public class MainActivity extends ActionBarActivity { ImageLoader.getInstance().init(config); + getSupportFragmentManager() + .beginTransaction() + .add(R.id.fragments, new HomeFragment()) + .commit(); + } @Override @@ -57,4 +62,25 @@ public class MainActivity extends ActionBarActivity { return super.onOptionsItemSelected(item); } } + + public void switchToPhoto(PanoramioImageInfo photoInfo) { + FragmentManager fragmentManager = getSupportFragmentManager(); + //HomeFragment homeFragment = (HomeFragment) fragmentManager.findFragmentById(R.id.home_frag); + FragmentTransaction ctx = fragmentManager.beginTransaction(); +// ctx.remove(homeFragment); + + // TODO add inserting photo showing fragment + + PanoramioShowerFragment panoramioShower = new PanoramioShowerFragment(); + Bundle arguments = new Bundle(); + arguments.putSerializable(PanoramioShowerFragment.PANORAMIO_PHOTO_ARG_KEY, photoInfo); + panoramioShower.setArguments(arguments); + + // ctx.add(R.id.fragments, panoramioShower); + ctx.replace(R.id.fragments, panoramioShower); + ctx.addToBackStack(PHOTO_BACKSTACK); + + ctx.commit(); + + } } diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioImageInfo.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioImageInfo.java index 2e08775..19dc586 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioImageInfo.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/PanoramioImageInfo.java @@ -1,11 +1,13 @@ package pl.tpolgrabia.urbanexplorer.dto; +import java.io.Serializable; import java.util.Date; /** * Created by tpolgrabia on 27.08.16. */ -public class PanoramioImageInfo { +public class PanoramioImageInfo implements Serializable{ + private static final long serialVersionUID = -3749926831546160047L; private Double height; private String ownerName; private Long ownerId; diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java index 2e88db1..268e67e 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java @@ -20,6 +20,7 @@ import com.androidquery.callback.AjaxCallback; import com.androidquery.callback.AjaxStatus; import org.json.JSONException; import org.json.JSONObject; +import pl.tpolgrabia.urbanexplorer.MainActivity; import pl.tpolgrabia.urbanexplorer.R; import pl.tpolgrabia.urbanexplorer.dto.PanoramioImageInfo; import pl.tpolgrabia.urbanexplorer.utils.NumberUtils; @@ -192,7 +193,7 @@ public class HomeFragment extends Fragment implements LocationListener { private void fetchPanoramioLocations() { - Location location = locationService.getLastKnownLocation(locationProvider); + final Location location = locationService.getLastKnownLocation(locationProvider); Double radiusX = fetchRadiusX(); Double radiusY = fetchRadiusY(); final String aqQuery = "http://www.panoramio.com/map/get_panoramas.php?" + @@ -232,6 +233,18 @@ public class HomeFragment extends Fragment implements LocationListener { R.layout.location_item, photosInfos); locations.setAdapter(adapter); + + locations.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView adapterView, View view, int pos, long rowId) { + PanoramioAdapter panAdapter = (PanoramioAdapter) locations.getAdapter(); + PanoramioImageInfo photoInfo = panAdapter.getItem(pos); + MainActivity activity = (MainActivity) getActivity(); + activity.switchToPhoto(photoInfo); + return false; + } + }); + } catch (JSONException e) { Log.w(CLASS_TAG, "Json not supported format", e); } diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java new file mode 100644 index 0000000..5978895 --- /dev/null +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/PanoramioShowerFragment.java @@ -0,0 +1,57 @@ +package pl.tpolgrabia.urbanexplorer.fragments; + + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import android.widget.ImageView; +import android.widget.TextView; +import com.nostra13.universalimageloader.core.ImageLoader; +import pl.tpolgrabia.urbanexplorer.MainActivity; +import pl.tpolgrabia.urbanexplorer.R; +import pl.tpolgrabia.urbanexplorer.dto.PanoramioImageInfo; + +/** + * A simple {@link Fragment} subclass. + */ +public class PanoramioShowerFragment extends Fragment { + + + public static final String PANORAMIO_PHOTO_ARG_KEY = "PANORAMIO_PHOTO_ARG_KEY"; + private TextView photoTitle; + + public PanoramioShowerFragment() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + Bundle arguments = getArguments(); + final View inflatedView = inflater.inflate(R.layout.fragment_panoramio_shower, container, false); + + if (arguments == null) { + return inflatedView; + } + + PanoramioImageInfo imageInfo = (PanoramioImageInfo) arguments.getSerializable(PANORAMIO_PHOTO_ARG_KEY); + + if (imageInfo != null) { + ImageLoader.getInstance().displayImage( + imageInfo.getPhotoFileUrl(), + (ImageView) inflatedView.findViewById(R.id.photo_container), + MainActivity.options); + + photoTitle = (TextView)inflatedView.findViewById(R.id.phot_title); + photoTitle.setText(imageInfo.getPhotoTitle()); + } + + return inflatedView; + } + +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 0f7d333..b4b5f7c 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,6 @@ + tools:context="pl.tpolgrabia.urbanexplorer.MainActivity" android:orientation="horizontal"> @@ -16,11 +17,11 @@ - + + + + + + diff --git a/app/src/main/res/layout/fragment_panoramio_shower.xml b/app/src/main/res/layout/fragment_panoramio_shower.xml new file mode 100644 index 0000000..190b934 --- /dev/null +++ b/app/src/main/res/layout/fragment_panoramio_shower.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + +