How do you dynamically load default HTML5 video thumbnails in Android WebView? - android-studio

I've just recently started using Android Studio for the first time to develop a mobile app that simply loads my website and displays it. I added a WebView with WebSettings that enable JavaScript among other things and it works! However, video thumbnails do not display. Instead an ugly gray placeholder play button image is used. How do I make it so that the video thumbnails load like they would on desktop devices, or even in mobile browsers (because they do display there as well)?
I'm not entirely sure whether or not to include code in this question but I will share anyway :P
Here's the relevant snippets of the MainActivity.java file:
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setDomStorageEnabled(true);
webView.loadUrl("https://example.com"); //My domain
}
}
So basically, it's either the preload="metadata" in my website's code or some equivalent attribute or CSS property that messes with Android WebView's autogeneration of video thumbnails, or it's because of my extreme newbieness to the whole Android app development thing. I'm willing to bet on the latter.
Also as a side question, should I store thumbnails on my server instead of having everyone's browsers load the 1st frame of every video every time?
Thanks in advance :)

Related

Import image Android Sudio

I got a school project where i need to make a cooking app, I struggle with programmaticaly importing an image to get a preview of the dish in my class.
The images are located in the drawable-v24 folder but i can't figure out ou to get the right path to it.
I want it to be a Drawable to create an image view in my layout.
package com.example.projet_info0306;
import android.graphics.drawable.Drawable;
public class Recette {
private String nom;
private Etape[] steps;
private Drawable Demo;
public Recette(String n,Etape[] e,String PathImg,) {
nom=n;
steps=e;
Demo= Drawable.createFromPath("#drawable/"+PathImg+".png");
}
}
If you want to show the Image in your App, just go to your activity_main.xml, add an ImageView to the layout and give it an ID.
You can now either link up the image statically in the XML by unsing the android:src tag or you can do it programatically by using:
Imageview imageview;
imageview = findViewByID(R.id.[yourID]);
imageview.setDrawable(R.drawable.[yourDrawable]);
NOTE: The code snippet you showed is in a normal Class not in an Activity. If you want to add one just go to your projects folder and right click on App. Android Studio will then lets you create an Activity. Or if your are not that far in the process, just create a new project and add an Activty from the beginning.

Android Studio 3.6 - how use layouts in Design Palette?

I am new to Android development and Android studio. I'm using Android Studio 3.6.1 . I'm having trouble understanding the "Layouts" options in the Design Palette. First, I don't see a "RelativeLayout" option. I realize many feel this is superceded by the ConstraintLayout, but it seems to me it should be a choice. Second, I don't see how to even use these layout options. If I drag one to an existing design, nothing happens. I thought maybe it would replace the root layout, but doesn't seem to. It doesn't create a child layout (if such a thing is possible). My code is just a simple "MainActivity" class with "setContentView(R.layout.activity_main);" in the onCreate() method. I have been tinkering with the activity_main.xml file to learn UI concepts. I can type in manual changes to change the layout to RelativeLayout, but it wasn't obvious what the classpath of the RelativeLayout class was, it is not in the same package as the ConstraintLayout class. I'm trying to use the power of the Android Studio IDE to discover options and build code, but I'm not finding how to use it for Layout options. I tried emptying the "activity_main.xml" file and then dragging a Layout from the palette, but nothing happens. I can delete the "activity_main.xml" file and create a new one, but when it prompts for a layout, there is no discovery to help choose one, it seems you have to know the package.
How can these Layouts in the Design Palette actually be used in the IDE? Can RelativeLayout be added to the list? Are there other missing Layouts?
package com.example.test;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</android.widget.RelativeLayout>
Something changed and I can now right-click a Layout and "add to design" or drag it to the design. I can also right-click the Layout in the component tree and convert to another layout, including RelativeLayout. I had added a Calendar component to my design for the heck of it and built and run in the emulator. After that, I deleted the Calendar and found I was able to now drag the layout components or convert the root component. So I'm comfortable with use of Layouts in the Palette. I am still unclear how to discover Layouts when creating a new layout XML file when it asks for "root tag". But I realize you don't need a full path, just the class name it seems, apparently the IDE finds the class. The glue behind the scenes I'll need to learn more about.

How disable JavaFX Text

How disable JavaFX Text
Text t = new Text();
t.setText("This is a text sample");
t.setDisable(true); //it does not work
Solution
You can style Text visually, so that it looks disabled, if you wish. The solution below binds the opacity setting to the disabled setting of the text.
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class DisabledText extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) {
Text enabledText = new Text("Enabled");
Text disabledText = new Text("Disabled");
disabledText.opacityProperty().bind(
Bindings.when(
disabledText.disabledProperty())
.then(0.4)
.otherwise(1)
);
disabledText.setDisable(true);
VBox layout = new VBox(10, enabledText, disabledText);
layout.setPadding(new Insets(10));
stage.setScene(new Scene(layout));
stage.show();
}
}
Notes
You might be able to accomplish this through CSS as well rather than a binding, I just didn't try that option.
In general, many times you are usually better off using a Label then Text for a lot of things as it includes more flexibility and functionality.
Background
Even though the user can't interact directly with text, so disabling text really has no effect, I guess what you are looking for is that the text look like other things when they are disabled.
Normally what happens when a control such as menu item or button is disabled, is that the CSS pseudo-class :disabled is set on the control. When this occurs, the default modena.css stylesheet for JavaFX 8 will modify the opacity for the control to -fx-opacity: 0.4;. This changes the visual look for the control so that it appears as though it is grayed out, as the low opacity makes the control looks faded.
Text is built to be a base drawing shape. Base drawing shapes in Java deliberately don't rely on CSS (though CSS can be used with them if needed - see the CSS reference guide for info on what default CSS rules apply to shapes). If your scene doesn't use any layout panes or controls, then the standard modena.css stylesheet will not be loaded and CSS processing will not be applied to the scene (for efficiency reasons so that, for instance, you could write a high performance game that did not use CSS processing). So CSS processing for Text is not necessarily required and, if used, is limited in its scope.
Two possible ways:
Add css style to the Text's instance.
Use Label instead.
I recommend using Label instead of Text.

How to get rid of title bar in android studio

I am a very new programmer and I have just finished my first android app, I have a problem with the title bar. Ive googled and searched on stack overflow that if I changed the theme into notitlebar_ i will not have a title bar. However while that is true using the xml view, it is still present on the emulator, and also present when i ran it on my phone. (I also tried android:theme="#android:style/Theme.Black.NoTitleBar", but with the same results)
so how would i solve this? thanks in advance!!
Try something like this on the onCreate
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Here's the way that works best for me:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//hide the titlebar
getSupportActionBar().hide();
setContentView(R.layout.activity_main);

Is this possible to use lwuit.Dialog with javax.microedition.lcdui.Canvas in wireless toolkit 2.5.2?

I am using javax.microedition.lcdui.Canvas for drawing my string on the screen. But I also need one dialog window for some purpose. So I am using lwuit package (com.sun.lwuit.Dialog) for showing dialog window when key pressing.
So in my program I just included that package and create the object of the Dialog box. While running my application, it is terminated unexpectedly.
I just included the following lines...
import javax.microedition.lcdui.Canvas;
import com.sun.lwuit.Dialog;
public class Mycanvas extends Canvas implements CommandListener
{
Dialog dialog = new Dialog();
//some other remaining codes for my canvas...
}
So, is it possible to show lwuit dialog window with lcdui canvas?
I would say it's possible but it will increase size of the app significantly. Whenever you need your dialog you can init LWUIT Display and use LWUIT Forms and Dialogs.
I would better to implement some really simple Dialog ourselves. It's not really much work. Or use another third party solution.
My Idea is create an user defined Item which extends from CustomItem for dialog.But it is difficult to code the complete implementation.Better u search for any third pary jar file which already implemented dialog box.

Resources