How do i clear the OSMdroid cache - java

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()

Related

Using glide to display multiple images

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.

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));
}
}

PDFClown Editable Rectangle

Following the given examples pdfClown can both highlight a specific text and draw a rectangle around the respective words.
Is there a possibility to make this reactangle editable afterwards with the Adobe Acrobat?
My current workflow (as planned):
Import a document
Search document for Highlightings
Determine the Hightlighting's color
Draw a rectangle around the outer boundaries of the rectangle
add a callout to a another rectangle containing a letter, depending on the determined color
I can not (e.g.) drag the rectangle around the formerly highlighted word with Acrobat Reader, as far as I can see. I used the provided example from pdfClown's webpage to draw a reactangle around every character.
Is there something that I forgot to consider?
File inFile = null;
String inFilePath = "/path/to/inputFile/input_highlight.pdf";
String outDirPath = "/tmp";
try {
inFile = new File(inFilePath);
} catch (Exception e) {
throw new RuntimeException(inFilePath + " file access error.", e);
}
Document document = inFile.getDocument();
Pages pages = document.getPages();
PageStamper stamper = new PageStamper();
for (Page page : pages) {
stamper.setPage(page);
PageAnnotations annotations = page.getAnnotations();
for (Annotation annotation : annotations) {
if (annotation.getColor() == null) {
continue;
}
Rectangle2D textStringBox = annotation.getBox();
PrimitiveComposer composer = stamper.getBackground();
composer.setStrokeColor(DeviceRGBColor.Black);
textStringBox.setRect(annotation.getBox().getX(), annotation.getBox().getY(), annotation.getBox().getWidth(), annotation.getBox().getHeight());
composer.drawRectangle(textStringBox);
composer.stroke();
composer.beginLocalState();
composer.setStrokeColor(DeviceRGBColor.Black);
composer.end();
stamper.flush();
System.out.println("Text: " + annotation.getText());
System.out.println("Color: " + annotation.getColor());
System.out.println("Coordinates: " + annotation.getBox().toString());
annotation.setColor(DeviceRGBColor.White);
}
}
As it seems your main issue is that
I can not (e.g.) drag the rectangle around the formerly highlighted word with Acrobat Reader
The reason is that you draw your rectangle in the page content (the PageStamper you use is documented as Tool for content insertion into existing pages). The page content is fixed, in particular as far as Acrobat Reader is concerned; Acrobat Reader only allows you to move annotations.
If you want to have a rectangle you can drag around, therefore, you have to use a rectangle annotation. Rectangle annotations can be created like this:
new org.pdfclown.documents.interaction.annotations.Rectangle(
page,
new Rectangle(50, 370, 100, 30),
"Text of the Rectangle annotation"
).withColor(DeviceRGBColor.get(Color.RED))
.withBorder(new Border(1, new LineDash(new double[]{5})))
.withAuthor("Stefano")
.withSubject("Rectangle")
.withPopup(new Popup(
page,
new Rectangle2D.Double(200, 325, 200, 75),
"Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
));
(AnnotationSample.java)
You also mention that you want to add a callout; a callout annotation can be created like this:
new StaticNote(
page,
new Rectangle(250, 90, 150, 70),
"Text of the Callout note annotation"
).withLine(
new StaticNote.CalloutLine(
page,
new Point(250,125),
new Point(150,125),
new Point(100,100)
)
)
.withLineEndStyle(LineEndStyleEnum.OpenArrow)
.withBorder(new Border(1))
.withColor(DeviceRGBColor.get(Color.YELLOW));
(AnnotationSample.java)

How to programmatically set drawableLeft on Android button?

I'm dynamically creating buttons. I styled them using XML first, and I'm trying to take the XML below and make it programattic.
<Button
android:id="#+id/buttonIdDoesntMatter"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="buttonName"
android:drawableLeft="#drawable/imageWillChange"
android:onClick="listener"
android:layout_width="fill_parent">
</Button>
This is what I have so far. I can do everything but the drawable.
linear = (LinearLayout) findViewById(R.id.LinearView);
Button button = new Button(this);
button.setText("Button");
button.setOnClickListener(listener);
button.setLayoutParams(
new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT
)
);
linear.addView(button);
You can use the setCompoundDrawables method to do this. See the example here. I used this without using the setBounds and it worked. You can try either way.
UPDATE: Copying the code here incase the link goes down
Drawable img = getContext().getResources().getDrawable(R.drawable.smiley);
img.setBounds(0, 0, 60, 60);
txtVw.setCompoundDrawables(img, null, null, null);
or
Drawable img = getContext().getResources().getDrawable(R.drawable.smiley);
txtVw.setCompoundDrawablesWithIntrinsicBounds(img, null, null, null);
or
txtVw.setCompoundDrawablesWithIntrinsicBounds(R.drawable.smiley, 0, 0, 0);
Simply you can try this also
txtVw.setCompoundDrawablesWithIntrinsicBounds(R.drawable.smiley, 0, 0, 0);
Kotlin Version
Use below snippet to add a drawable left to the button:
val drawable = ContextCompat.getDrawable(context, R.drawable.ic_favorite_white_16dp)
button.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
Important Point in Using Android Vector Drawable
When you are using an android vector drawable and want to have backward compatibility for API below 21, add the following codes to:
In app level build.gradle:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
In Application class:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
}
}
myEdtiText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.smiley, 0, 0, 0);
For me, it worked:
button.setCompoundDrawablesWithIntrinsicBounds(com.example.project1.R.drawable.ic_launcher, 0, 0, 0);
Worked for me. To set drawable at the right
tvBioLive.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_close_red_400_24dp, 0)
If you are using drawableStart, drawableEnd, drawableTop or drawableBottom; you must use "setCompoundDrawablesRelativeWithIntrinsicBounds"
edittext.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.anim_search_to_close, 0)
I did this:
// Left, top, right, bottom drawables.
Drawable[] drawables = button.getCompoundDrawables();
// get left drawable.
Drawable leftCompoundDrawable = drawables[0];
// get new drawable.
Drawable img = getContext().getResources().getDrawable(R.drawable.ic_launcher);
// set image size (don't change the size values)
img.setBounds(leftCompoundDrawable.getBounds());
// set new drawable
button.setCompoundDrawables(img, null, null, null);
as #Jérémy Reynaud pointing out, as described in this answer, the safest way to set the left drawable without changing the values of the other drawables (top, right, and bottom) is by using the previous values from the button with setCompoundDrawablesWithIntrinsicBounds:
Drawable leftDrawable = getContext().getResources()
.getDrawable(R.drawable.yourdrawable);
// Or use ContextCompat
// Drawable leftDrawable = ContextCompat.getDrawable(getContext(),
// R.drawable.yourdrawable);
Drawable[] drawables = button.getCompoundDrawables();
button.setCompoundDrawablesWithIntrinsicBounds(leftDrawable,drawables[1],
drawables[2], drawables[3]);
So all your previous drawable will be preserved.
Might be helpful:
TextView location;
location=(TextView)view.findViewById(R.id.complain_location);
//in parameter (left,top,right,bottom) any where you wnat to put
location.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.arrow,0);
Add a Kotlin Extension
If you are going to be doing this frequently, adding an extension makes your code more readable. Button extends TextView; use Button if you want to be more narrow.
fun TextView.leftDrawable(#DrawableRes id: Int = 0) {
this.setCompoundDrawablesWithIntrinsicBounds(id, 0, 0, 0)
}
To use the extension, simply call
view.leftDrawable(R.drawable.my_drawable)
Anytime you need to clear, don't pass a param or make another extension called removeDrawables
Following is the way to change the color of the left icon in edit text and set it in left side.
Drawable img = getResources().getDrawable( R.drawable.user );
img.setBounds( 0, 0, 60, 60 );
mNameEditText.setCompoundDrawables(img,null, null, null);
int color = ContextCompat.getColor(this, R.color.blackColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
DrawableCompat.setTint(img, color);
} else {
img.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
Try this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
fillButton[i].setBackground(getBaseContext().getResources().getDrawable(R.drawable.drawable_name));
}
else {
fillButton[i].setBackgroundColor(Color.argb(255,193,234,203));
}
Try this:
((Button)btn).getCompoundDrawables()[0].setAlpha(btn.isEnabled() ? 255 : 100);

How can the no. of pages in an OpenOffice.org spreadsheet be obtained programmatically?

I want to count the number of pages that would be produced if I printed out an OpenOffice.org document. I can already do it for ODT files using the following code:
public short getPageCount() {
XModel model = (XModel) UnoRuntime.queryInterface(XModel.class,
getDocument());
XTextViewCursorSupplier supplier = (XTextViewCursorSupplier) UnoRuntime
.queryInterface(XTextViewCursorSupplier.class, model
.getCurrentController());
XTextViewCursor viewCursor = supplier.getViewCursor();
XPageCursor pageCursor = (XPageCursor) UnoRuntime.queryInterface(
XPageCursor.class, viewCursor);
pageCursor.jumpToLastPage();
return pageCursor.getPage();
}
public Object getDocument() {
XComponentContext context = Bootstrap.bootstrap();
XMultiComponentFactory factory = context.getServiceManager();
Object desktop = factory.createInstanceWithContext(
"com.sun.star.frame.Desktop", context);
XComponentLoader loader = (XComponentLoader) UnoRuntime.queryInterface(
XComponentLoader.class, desktop);
XComponent component = loader.loadComponentFromURL("file:///path/to/file.odt",
"_blank", 0, new PropertyValue[0]);
return UnoRuntime.queryInterface(XTextDocument.class,
component);
}
I want to know if I can do something similar with ODS files. Maybe count the no. of page breaks in the sheets? There is a ShowPageBreaks property in the SpreadsheetViewSettings class but no PageBreakCount or getPageBreaks(). :P
// get the sheet document using UnoRuntime
XSpreadsheetDocument sheetDoc = ...;
// get an object containing all sheets
XSpreadsheets sheets = sheetDoc.getSheets();
// get the sheets names
String[] sheetnames = sheets.getElementNames();
and there you have something you can count or iterate.
EDIT:
The sheet itself probably has no concept of print pages.
So i guess you either need to use something like XPrintPreview, but i don't see how to determine pages from there, or see
Printing Spreadsheet Documents and try to use PrintAreas and some maths.

Categories