Last active
August 29, 2015 14:01
-
-
Save CoffeeCode/05e1f3fecb78baca4601 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Viewer extends Fragment { | |
private static final String TAG = "Viewer"; | |
//Fragment Static strings | |
public static final String IMAGE_RESOURCE_ID = "iconResourceID"; | |
public static final String ITEM_NAME = "itemName"; | |
//Static strings for Bundel and etc. | |
public static final String PREFERENCE_LAST_IMAGE = "lastImage"; | |
public static final String BUNDEL_SELECTED_IMAGE = "selectedImage"; | |
protected String imagePath; | |
protected RenderScript renderScript; | |
protected SubsamplingScaleImageView imageView; | |
protected Context context; | |
public static Viewer init(String imagePath) { | |
Viewer viewerFragment = new Viewer(); | |
Bundle args = new Bundle(); | |
args.putString("imagePath", imagePath); | |
viewerFragment.setArguments(args); | |
return viewerFragment; | |
} | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
imagePath = getArguments().getString("imagePath"); | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.fragment_viewer, container, false); | |
context = super.getActivity(); | |
renderScript = RenderScript.create(context); | |
loadUi(view); | |
imageView = (SubsamplingScaleImageView) view.findViewById(R.id.previewImage); | |
try { | |
imageView.setImageFile(imagePath); | |
Log.d(TAG, "setting imagePath in onCreateView : " + imagePath); | |
textViewExif.setText(imagePath); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return view; | |
} | |
@Override | |
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { | |
inflater.inflate(R.menu.viewer, menu); | |
super.onCreateOptionsMenu(menu,inflater); | |
} | |
protected void setImageFile(File filteredImageFile){ | |
try { | |
imageView.setImageFile(filteredImageFile.getAbsolutePath()); | |
} catch (IOException e) { e.printStackTrace(); } | |
} | |
protected void setImageBitmap(Bitmap filteredImageBitmap){ | |
try { | |
imageView.setImageBitmap(filteredImageBitmap); | |
} catch (IOException e) { e.printStackTrace(); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment