VideoView acting weird on scroll - android-linearlayout

I'm having a ViewGroup where I can scroll through per page, these pages are images.
Some have links, some have media on them, when there's for example a video square on the image I place a VideoView on it so when the user taps it, it plays the movie from the raw folder.
However, when I do this, and I scroll through to the next page or back, there's a black border over the next or previous screen, it's acting all messed up. Anyone has any idea what this is and how to fix this? Is it the VideoView it's behavior? Or is it my pager class or my other layout code??
piece of code:
LinearLayout linVid2 = new LinearLayout(this);
LinearLayout linVid = new LinearLayout(this);
linVid.setBackgroundResource(R.drawable.landscape_1003_1_full);
linVid.setLayoutParams(new LinearLayout.LayoutParams(
1024, 748));
linVid2.setPadding(386, 53, 1024 - 587 - 386,
748 - 440 - 53);
linVid.addView(linVid2);
VideoView vd = new VideoView(this);
String tmp = MovieLink2.replace(".mp4", "");
int movieID = res.getIdentifier(tmp, "raw",
getPackageName());
Uri uri = Uri.parse("android.resource://"
+ getPackageName() + "/" + movieID);
MediaController mc = new MediaController(this);
vd.setMediaController(mc);
vd.setVideoURI(uri);
linVid2.addView(vd);
horizontalViewSwitcher.addView(linVid, current);
vd.start();

You can call requestLayout() in the onScrollChanged() function. It resolved the same issue for me.

Related

The button in nattable is covering half of my table, can someone explain why?

i have used the following code for the button
natTable.addOverlayPainter(new NatTableBorderOverlayPainter());
Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 5;
layout.marginWidth = 8;
panel.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
Composite gridPanel = new Composite(panel, SWT.NONE);
gridPanel.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new RowLayout());
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
Button addButton = new Button(gridPanel, SWT.PUSH);
addButton.setText("Export");
addButton.setSize(1, 1);
addButton.setLocation(450, 150);
addButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new ExportCommand(natTable
.getConfigRegistry(), null, editable));
natTable.updateResize();
}
but at the end i am getting this as a result
https://imgur.com/EFcPaqo
Your layout is broken. Probably because the NatTable instance is not created on one of your Composites. But hard to tell without seeing the creation of it.
Either have a look at Understanding layouts in SWT or even check the NatTable examples PrintExample that shows exactly the same. There you can see that NatTable is created on the gridPanel.

JavaFX format Math during input

Is there a way that a mathematical expression can be formatted in JavaFX during input? Something like a TextArea that behaves exactly as the mathquill editor, which is for web applications?
If not, would it be possible to create a custom TextField / TextArea to provide such functionality? I have not yet looked into this so any guidance or suggestions are welcome :)
The only workaround I came up with is to input the expression as a String and convert it to an image using jLaTeXmath, which is not preferred as the end result should be an editable equation.
Short example on embedding jLaTeXmath:
This is done by converting a TeX expression to a BufferedImage that can be placed on a Pane. See below the code for the conversion:
/**
* Converts LaTeX code to a BufferedImage
* #param latex
*/
public static BufferedImage latexToImage(String latex){
String start ="\\begin{array}{l}";
start += latex;
start += "\\end{array}";
TeXFormula formula = new TeXFormula(start);
// Note: Old interface for creating icons:
//TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
// Note: New interface using builder pattern (inner class):
TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(65f).build();
icon.setInsets(new Insets(1, 1, 1, 1));
BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
g2.setComposite(AlphaComposite.Clear);
// g2.setColor(Color.WHITE);
g2.fillRect(0,0,icon.getIconWidth(),icon.getIconHeight());
JLabel jl = new JLabel();
jl.setForeground(new Color(0, 0, 0));
g2.setComposite(AlphaComposite.Src);
icon.paintIcon(null, g2, 0, 0);
/*
File file = new File("Example2.png");
try {
ImageIO.write(image, "png", file.getAbsoluteFile());
} catch (IOException ex) {}
*/
return image;
}
The image can then be converted and set in a ImageView in JavaFX as folllows:
BufferedImage bimage = latexToImage("a = 2 \cdot x");
Image image = SwingFXUtils.toFXImage(bimage , null);
// have an ImageView in your scene and set the image
imgView.setImage(image );
The next coming versions of JavaFX support MathML by using a HTMLEditor Control :
JavaFX 8 Update 192 included in Java 8 Update 192
JavaFX 11.
Follow this link Java Early Access Download to reach the early access to these versions.
I'm afraid that what you are looking for doesn't exist yet.
There is a project in the JavaFX GitHub Reprository, but it's long term project.
About MathQuill, it seems that it is a JavaScript code. Or HTMLEditor uses an implementation of WebKit and can execute JavaScript code. It could be a short term solution.

How to set JavaFX-Alert into middle of actual monitor?

I've got a static method in a class without knowing anything about the Application, Scene oder Stage. But I want to show an Alert in the middle of the actual used monitor.
For example: My tool is on the right screen. I want to see the alert also there and not on the main screen.
My method:
private static Alert createAlert(AlertType type, String title, String header, String content) {
Alert alert = new Alert(type);
alert.setTitle(title);
if (!header.isEmpty()) {
alert.setHeaderText(header);
}
alert.setContentText(content);
alert.setResizable(true);
alert.setX(0); // set this into the middle of used monitor
alert.setY(0); //
return alert;
}
How can I get the actual stage, scene or whatever to get its x- and y-position and use these information for setting x and y of the alert?
Assuming you have a reference to the current window, you can find the screen that contains it (e.g. contains its center point) with:
Window currentWindow = ... ;
Point2D windowCenter = new Point2D(currentWindow.getX() + currentWindow.getWidth()/2,
currentWindow.getY() + currentWindow.getHeight()/2);
Screen currentScreen = Screen.getScreens().stream()
.filter(screen -> screen.getBounds().contains(windowCenter))
.findAny().get();
And then you can do
Rectangle2D screenBounds = currentScreen.getBounds();
double screenCenterX = screenBounds.getMinX() + screenBounds.getWidth()/2 ;
double screenCenterY = screenBounds.getMinY() + screenBounds.getHeight()/2 ;
and position the Alert accordingly...
You need to know the current window though; it will be impossible to do this without that information. For example, your application might have multiple windows with different ones on different screens; the notion of "current screen" is simply not well defined in a case like that.

Is there a way to access ALAssets information outside of resultBlock?

Okay so I have my ImagePicker all setup and the ALAssetLibrary setup to get the Picture and Title (if it exists for existing pictures or generic text for a new picture) but now I'm trying to figure out if there's a way I can access this information outside of the block call from the assetForURL method. So here's my code just so I can show what's happening (this is in the viewDidLoad method of a screen that is displayed after a picture selection is made)
__block NSString *documentName;
__block UIImage *docImage;
NSURL *resourceURL = [imageInfo objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset)
{
ALAssetRepresentation *imageRep = [asset defaultRepresentation];
//Get Image
CGImageRef iref = [imageRep fullResolutionImage];
//If image is null then it's a new picture from Camera
if (iref == NULL) {
docImage = [imageInfo objectForKey:UIImagePickerControllerOriginalImage];
documentName = #"New Picture";
}
else {
docImage = [UIImage imageWithCGImage:iref];
documentName = [imageRep filename];
}
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary *imageAsset = [[ALAssetsLibrary alloc] init];
[imageAsset assetForURL:resourceURL resultBlock:resultblock failureBlock:nil];
Now I want to be able to use the two variables (documentName and docImage) elsewhere in this ViewController (for example if someone wants to change the name of the document before they save it I want to be able to revert back to the default name) but I can't seem to figure out what I need to do so these variables can be used later. Don't know if this makes much sense or not, so if I need to clarify anything else let me know.
Okay so I figured out that the problem wasn't with the code but with my logic on how I was using it. I was trying to do this on the Modal View that was presented after an image was selected instead of just doing this in the ImagePicker screen and then calling the Modal window inside of the result block code.

ASP.NET C# Handling an Image

Similar to one of my other questions, but I need clarification.
I have a web application where multiple users will be on at the same time. In the app, an image, which is in one of the app folders, will be drawn on like below, saved, and then added to the image control on the page.
Bitmap image = new Bitmap(Server.MapPath("~") + "/Assets/img/timegrid.jpg");
Graphics graphics = Graphics.FromImage(image);
Pen p = new Pen(Color.Blue, 5);
//draw on image
graphics.DrawLine(p, aPoint, bPoint);
//save new image
image.Save(Server.MapPath("~") + "/Assets/img/newtimegrid.jpg");
imgGrid.ImageUrl = "~/Assets/img/newtimegrid.jpg";
Each user's new image will look different. However, I'm worried that User A will see User B's newtimegrid.jpg instead of his own since every user is saving to the same filename. I've heard of using a generic Image Handler and I've read some of the solutions here, but I still don't understand how to use it, or how to call it if I made one, or if this is even a solution to my problem. Any help would be appreciated.
I would suggest you to keep userID in the session and use this id in the path to uniquely identifying the path of image for each user image path.
You can first check if path already exists for user.
string strDirPath = Server.MapPath("~") + "/Assets/img/ + Session["UserID"].ToString();
if(Directory.Exists(strDirPath))
{
Bitmap image = new Bitmap(strDirPath + "\\" + timegrid.jpg");
//your code here
}
else
{
DirectoryInfo CreateDirectory(strDirPath);
Bitmap image = new Bitmap(strDirPath + "\\" + timegrid.jpg");
//your code here
}

Resources