Using glide to display multiple images - java

For a scanning ticket app, I want to display full screen image.
The app does sequential operation. You scan your QrCode (first image), the device reach server (second image indicating to wait), then I display a third image if the ticket is validate, else I display the last one.
I'm using glide and the image path is indicated in a second activity, I transmit URI to main activity with a sharedPreferences file.
Here is the issue:
val settings = getSharedPreferences("PrefFile", 0)
if (S_mod){//priority on S_mod
uri_State_init = Uri.parse(settings.getString("mainUri", "none"))
uri_State_waiting = Uri.parse(settings.getString("waitUri", "none"))
uri_State_validated = Uri.parse(settings.getString("okUri", "none"))
uri_State_refused = Uri.parse(settings.getString("errorUri", "none"))
displayUri( uri_State_init, background)
image.setImageResource(R.drawable.empty)
}
where displayUri is
fun displayUri( uri: Uri?, dir:ImageView){//use to display image known by uri, only for full screen
Glide.with(this)
.load(uri)
.error(R.drawable.imagenotfound) // image in case of error
.override(1280, 800) // resizing if user doesn't respect the indicated dim
.centerCrop()//type of resizing
.into(dir)
}
The issue is that only the first image called by displayUri is displayed, the other call show the error image (imagenotfound)
It seem that I've not totally understood the glide extension.
If someone know about this particular issue thanks a lot!!

Here
val settings = getSharedPreferences("PrefFile", 0)
if (S_mod){//priority on S_mod
uri_State_init = Uri.parse(settings.getString("mainUri", "none"))
uri_State_waiting = Uri.parse(settings.getString("waitUri", "none"))
uri_State_validated = Uri.parse(settings.getString("okUri", "none"))
uri_State_refused = Uri.parse(settings.getString("errorUri", "none"))
displayUri( uri_State_init, background)
image.setImageResource(R.drawable.empty)
}
displayUri( uri_State_init, background)
You are just calling the display Image function with the same uri which means if you didn't passed the uri, then uri will be null and you will definitely get errors. What you can do is to send uri like this ,
val settings = getSharedPreferences("PrefFile", 0)
if (S_mod){//priority on S_mod
uri = Uri.parse(settings.getString("main_uri", "none"))
displayUri( uri_State_init, background)
image.setImageResource(R.drawable.empty)
}
Just change the value of main_uri in Shared Preferences whenever you want to change the state. You can also use onSharedPreferencesChanged Listener.

Related

JavaFX - Getting icons of the default Alerts (ERROR,WARNING,INFORMATION)

I want to change the Icon of TextInputDialog... Instead of show the CONFIRMATION icon I want to display the WARNING icon. But how to receive it without inserting any downloaded/drawed image?
TextInputDialog dia = new TextInputDialog();
dia.setTitle("Wait for input");
dia.setHeaderText(titleString);
dia.setContentText(messageString);
dia.setGraphic(/*WARNING_ICON*/);
Optional<String> result = dia.showAndWait();
if (result.isPresent())
/*do something juicy*/
else
/*do nothing*/
I already tried dia.setGraphic( new Alert(AlertType.WARNING).getGraphic()); but that doesn't work. The Icon disappears in this case.

Imebra library shows completely gray image for transfer syntax 1.2.840.10008.1.2.1

Iam trying to use Imebra library to display DICOM images in android. Iam using version 5.0 of the library.
The bitmap shown is completely gray, transfer syntax for image is 1.2.840.10008.1.2.1.For other supported transfer syntax i.e JPEG it works fine.
Also I am unable to add VOILUT transform functionality as mentioned in documentation it gives error cons tructor not found for VOILUT.
Below is the code Iam using, VOILUT transform part is giving constructor not found. if i remove VOILUT transform part things work fine but for image with transfer syntax 1.2.840.10008.1.2.1 it shows completely grey image
private Bitmap fromDicom(String filePath, int frameNumber){
// have been applied).
Image dicomImage = loadedDataSet.getImageApplyModalityTransform(frameNumber);
// Use a DrawBitmap to build a stream of bytes that can be handled by the
// Android Bitmap class.
com.imebra.TransformsChain chain = new com.imebra.TransformsChain();
if( com.imebra.ColorTransformsFactory.isMonochrome(dicomImage.getColorSpace()))
{
// Retrieve the VOIs (center/width pairs)
com.imebra.VOIs vois = loadedDataSet.getVOIs();
if(!vois.isEmpty())
{
// Get the first VOI setting from the dataset
chain.addTransform(new VOILUT(vois.get(0)));
}
else
{
// The dataset does not have any VOI setting, find the optimal one
com.imebra.SWIGTYPE_p_imebra__VOIDescription voiDescription = VOILUT.getOptimalVOI(dicomImage, 0, 0, dicomImage.getWidth(), dicomImage.getHeight());
chain.addTransform(new VOILUT(voiDescription));
}
}
DrawBitmap drawBitmap = new DrawBitmap(chain);
Memory memory = drawBitmap.getBitmap(dicomImage, drawBitmapType_t.drawBitmapRGBA, 4);
// Build the Android Bitmap from the raw bytes returned by DrawBitmap.
Bitmap renderBitmap = Bitmap.createBitmap((int)dicomImage.getWidth(), (int)dicomImage.getHeight(), Bitmap.Config.ARGB_8888);
byte[] memoryByte = new byte[(int)memory.size()];
memory.data(memoryByte);
ByteBuffer byteBuffer = ByteBuffer.wrap(memoryByte);
renderBitmap.copyPixelsFromBuffer(byteBuffer);
// Update the image
return renderBitmap;
}
After changing the code suggested by you, I don't find classes mentioned
VOIDescription instead i see class SWIGTYPE_p_imebra__VOIDescription should i use that class
There is one more error no getWidth() method available with vois.get(0).getWidth
One last Error i don't see class vois_t instead there is a class VOIs should VOIs be used
Thanks for the reponse
The VOILUT must be initialized with the proper contrast settings from the dataset like in the code below.
However, the dataset contains a VOI setting that is wrong (the window width is 0) so this file will be displayed correctly only if you use custom VOI settings or just use automatic settings when width is zero (see alternative code below which checks for width > 0).
Code that does not check for width:
if(com.imebra.ColorTransformsFactory.isMonochrome(dicomImage.getColorSpace());
{
// Retrieve the VOIs (center/width pairs)
com.imebra.vois_t vois = loadedDataSet.getVOIs();
if(!vois.isEmpty())
{
// Get the first VOI setting from the dataset
chain.addTransform(new VOILUT(vois.get(0)));
}
else
{
// The dataset does not have any VOI setting, find the optimal one
com.imebra.VOIDescription voiDescription = VOILUT.getOptimalVOI(dataSetImage, 0, 0, width, height);
chain.addTransform(new VOILUT(voiDescription));
}
}
Alternative code that checks if width is 0:
if(com.imebra.ColorTransformsFactory.isMonochrome(dicomImage.getColorSpace());
{
// Retrieve the VOIs (center/width pairs)
com.imebra.vois_t vois = loadedDataSet.getVOIs();
if(!vois.isEmpty() && vois.get(0).getWidth() > 0.1)
{
// Get the first VOI setting from the dataset
chain.addTransform(new VOILUT(vois.get(0)));
}
else
{
// The dataset does not have any VOI setting, find the optimal one
com.imebra.VOIDescription voiDescription = VOILUT.getOptimalVOI(dataSetImage, 0, 0, width, height);
chain.addTransform(new VOILUT(voiDescription));
}
}

Return current android layout or screen width for debugging

I am trying to add come conditional processing depending on screen width. I set up a refs in my /res/values to point to the appropriate resource on screen width > 600 (sw600dp), have the two layouts, etc. Then I have
Log.d(TAG, "From mButton onClick, layout: " + getActivity().????);
if (getActivity().findViewById(R.id.dialog_widget) == null) {
Intent intent = WidgetActivity.newIntent(getActivity(), mThinger.getInfo());
Log.d(TAG, "From mButton onClick, intent: " + intent.toString());
startActivityForResult(intent, REQUEST_INFO);
} else {
FragmentManager manager = getFragmentManager();
WidgetDialogFragment dialog = WidgetDialogFragment.newInstance(mThinger.getInfo());
dialog.setTargetFragment(ThingerFragment.this, REQUEST_INFO);
dialog.show(manager, DIALOG_INFO);
}
I never hit the else condition, so I am trying to add a Log (see first line of code block) to let me know what layout elements are available, or what the screen width is, or anything to help me know why I'm not seeing the fragment on larger screens. Thanks!
Maybe this will help a bit - at startup of my app I always log:
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
Log.e(TAG,"dpHeight= "+dpHeight+" dpWidth="+dpWidth);
And one other trick to log the screen layout determined by the system is to use the "values" layout-specific folders:
values-sw320dp/
values-sw420dp/
values-sw600dp/
values-sw720dp/
and in each folder define a strings.xml (or any value resource) which looks like:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="selected_configuration">sw320dp</string>
</resources>
and in App main Applicaton class log:
Log.d(TAG, "Selected configuration: "+getString(R.string.selected_configuration));
You can use another resource value besides string of course.

How do i clear the OSMdroid cache

I loaded the same tiles (Mapbox) into OSmdroid, but know when i modify it on the web, it changes in my app, but the former map still remaines in the cache, and is replace by the new map little by little.
I want to know how to delete the cache, programmatically, so it can load the tiles normally.
I've got the code to load it right here :
private void loadMap() {
String html = "http://a.tiles.mapbox.com/v3/myUsername.map-f1rhoycw/";
String name = "500x300";
XYTileSource freemap = new XYTileSource(name, null, 0, 16, 256, ".png", html);
map.setTileSource(freemap);
mapController = map.getController();
mapController.setZoom(16);
map.setMultiTouchControls(true);
}
Try this:
mMapView.getTileProvider().clearTileCache()

Select multiple images from Photo Gallery on Android using Intents

#See this https://stackoverflow.com/a/15029515/185022
I`m trying to select images from gallery, but i only found the way to select a single image.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
Is there a way to select multiple images?
Create a custom gallery same like: Android custom image gallery with checkbox in grid to select multiple
First of all you need to use putExtra with your photoPickerIntent
photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE);
Then in your on activity result you should get ClipData from Intent like this
ClipData clipData = data.getClipData();
//Where data is param intent of onActivityForResult
And iterate this clipData to get URI for specific picked image.
for (int i = 0; i < clipData.getItemCount(); i++){
Uri uri = clipData.getItemAt(i).getUri();
}
I hope this helps
Why don't you try ACTION_SEND_MULTIPLE thing. You will receive a set of Uris.
Something like
if (Intent.ACTION_SEND_MULTIPLE.equals(action))
&& Intent.hasExtra(Intent.EXTRA_STREAM)) {
ArrayList<Parcelable> list =
intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
for (Parcelable parcel : list) {
Uri uri = (Uri) parcel;
/// do things here.
}
}
Saw this code block on a google-groups post. Just try this out.
Thanks.
I think, you should implement custom gallery for multiple image pick action.
see here in details.

Categories