I am running React Native 0.56. When I start my app, it first shows a white screen for 1 second then goes to the app. My files are:
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
#Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new BlurViewPackage(),
new OrientationPackage(),
new ReactVideoPackage(),
new RNDeviceInfo(),
new LinearGradientPackage()
);
}
#Override
protected String getJSMainModuleName() {
return "index";
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
and
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "CONtv";
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Intent intent = new Intent("onConfigurationChanged");
intent.putExtra("newConfig", newConfig);
this.sendBroadcast(intent);
}
}
and index.js
import {AppRegistry} from 'react-native';
import App from './src/App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
How do I make the white screen not appear? This is happening on Android.
As a solution for the white screen add a splash screen.
Check with this https://android.jlelse.eu/the-complete-android-splash-screen-guide-c7db82bce565
Related
I'm following a guide on coding by Easy Tuto, currently on part 7 at the end where the recycler_note_item.xml would show up on the interface. In the video, he fixed the problem by adding the onStart, onStop, onResume commands and adding `noteAdapter.startListening' in between the lines as shown here: image In the video, it worked and showed the item however nothing showed up for me as can be seen here . I tried scouring the video trying to find what I did wrong. I'm pretty new to coding and I was using his video as a base to learn more about it. I added those lines myself but it diddn't work for me it seems. Can someone please help me? It would be greatly appreciated. Here is my code for MainActivity.Java:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageButton;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.firestore.Query;
public class MainActivity extends AppCompatActivity {
FloatingActionButton addNoteBtn;
RecyclerView recyclerView;
ImageButton menuBtn;
NoteAdapter noteAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addNoteBtn = findViewById(R.id.add_note_btn);
recyclerView = findViewById(R.id.recyler_view);
menuBtn = findViewById(R.id.menu_btn);
addNoteBtn.setOnClickListener((v)-> startActivity(new Intent(MainActivity.this,NoteDetailsActivity.class)) );
menuBtn.setOnClickListener((v)->showMenu());
setupRecyclerView();
}
void showMenu(){
//TODO Display menu
}
void setupRecyclerView(){
Query query = Utility.getCollectionReferenceForNotes().orderBy("timestamp",Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Note> options = new FirestoreRecyclerOptions.Builder<Note>()
.setQuery(query,Note.class).build();
recyclerView.setLayoutManager(new LinearLayoutManager(this));
noteAdapter = new NoteAdapter(options,this);
recyclerView.setAdapter(noteAdapter);
}
#Override
protected void onStart() {
super.onStart();
noteAdapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
noteAdapter.stopListening();
}
#Override
protected void onResume() {
super.onResume();
noteAdapter.notifyDataSetChanged();
}
}
I think the other relevant codes is my NoteAdapter which is this:
package com.example.myapplication;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import io.grpc.okhttp.internal.Util;
public class NoteAdapter extends FirestoreRecyclerAdapter<Note, NoteAdapter.NoteViewHolder>{
Context context;
public NoteAdapter(#NonNull FirestoreRecyclerOptions<Note> options, Context context) {
super(options);
this.context = context;
}
#Override
protected void onBindViewHolder(#NonNull NoteViewHolder holder, int position, #NonNull Note note) {
holder.titleTextView.setText(note.title);
holder.contentTextView.setText(note.content);
holder.timestampTextView.setText(Utility.timestamptoString(note.timeStamp));
}
#NonNull
#Override
public NoteViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_note_item,parent,true);
return new NoteViewHolder(view);
}
class NoteViewHolder extends RecyclerView.ViewHolder{
TextView titleTextView,contentTextView,timestampTextView;
public NoteViewHolder(#NonNull View itemView) {
super(itemView);
titleTextView = itemView.findViewById(R.id.note_title_text_view);
contentTextView = itemView.findViewById(R.id.note_content_text_view);
timestampTextView = itemView.findViewById(R.id.note_timestamp_text_view);
}
}
}
Please tell me if there are any other relevant codes I can give to help give more context on my problem. Thanks for helping me out if anyone!
I was trying to understand how to make a search functions in an app. I go through the Creating a Search Interface documentation, but its quite hard and yea i need help. However, i do succeed to just create a search interface, displaying results based from a string arrray. It does work, but it doesnt had any activity behind it or any intent. It more like a simple text-search. I just wondering can i put int that can simultaneously work with string ?
Or any solution and ideas, really appreciate it.
for now here is my homefragment class
package com.example.testtt;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SearchView;
import androidx.annotation.Nullable;
import java.util.ArrayList;
public class HomeFragment extends Fragment implements View.OnClickListener {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_home, container, false);
//define
RelativeLayout drawerlayouthome;
ListView list;
ListViewAdapter adapter;
SearchView editsearch;
ArrayList<DoaSearchIndex> arrayList = new ArrayList<DoaSearchIndex>();
String[] doasearchindex = getActivity().getResources().getStringArray(R.array.doasearchindex);
//locatelistview
list = v.findViewById(R.id.searchlistview);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
list.setVisibility(View.INVISIBLE);
}
});
for (int i = 0; i < doasearchindex.length; i++) {
DoaSearchIndex doaSearchIndex = new DoaSearchIndex(doasearchindex[i]);
arrayList.add(doaSearchIndex);
}
//pass result to listviewadapter.class
adapter = new ListViewAdapter(this.getActivity(), arrayList);
//binds adapter to listview
list.setAdapter(adapter);
list.setVisibility(View.INVISIBLE);
//locatesearchview
editsearch = v.findViewById(R.id.searchview);
editsearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
if(TextUtils.isEmpty(newText)){
list.clearTextFilter();
adapter.filter("");
list.setVisibility(View.INVISIBLE);
} else {
adapter.filter(newText);
list.setVisibility(View.VISIBLE);
}
return true;
}
});
drawerlayouthome = v.findViewById(R.id.drawer_layouthome);
drawerlayouthome.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
list.setVisibility(View.INVISIBLE);
editsearch.clearFocus();
}
});
//definingcardview
CardView doacard = v.findViewById(R.id.doacard);
CardView ziarahcard = v.findViewById(R.id.ziarahcard);
//setcardviewlistener
doacard.setOnClickListener(this);
ziarahcard.setOnClickListener(this);
return v;
}
#Override
public void onClick(View view) {
Intent i ;
switch (view.getId()) {
case R.id.doacard:
i = new Intent(getActivity(), listdoa.class);
startActivity(i);
break;
case R.id.ziarahcard:
i = new Intent(getActivity(), listziarah.class);
startActivity(i);
break;
}
}
}
and my listviewadapter
package com.example.testtt;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class ListViewAdapter extends BaseAdapter {
//Declare variables first
Context mContext;
LayoutInflater inflater;
private List<DoaSearchIndex> doaSearchIndexList = null;
private ArrayList<DoaSearchIndex> arrayList;
public ListViewAdapter(Context context, List<DoaSearchIndex> doaSearchIndexList) {
mContext = context;
this.doaSearchIndexList = doaSearchIndexList;
inflater = LayoutInflater.from(mContext);
this.arrayList = new ArrayList<DoaSearchIndex>();
this.arrayList.addAll(doaSearchIndexList);
}
public class ViewHolder {
TextView name;
}
#Override
public int getCount() {
return doaSearchIndexList.size();
}
#Override
public DoaSearchIndex getItem(int position) {
return doaSearchIndexList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.listview_item, null);
// Locate the TextViews in listview_item.xml
holder.name = (TextView) view.findViewById(R.id.name);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// Set the results into TextViews
holder.name.setText(doaSearchIndexList.get(position).getDoaSearchIndex());
return view;
}
// Filter Class
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
doaSearchIndexList.clear();
if (charText.length() == 0) {
doaSearchIndexList.addAll(arrayList);
} else {
for (DoaSearchIndex wp : arrayList) {
if (wp.getDoaSearchIndex().toLowerCase(Locale.getDefault()).contains(charText)) {
doaSearchIndexList.add(wp);
}
}
}
notifyDataSetChanged();
}
}
and my doasearchindex class
package com.example.testtt;
public class DoaSearchIndex {
private String doaSearchIndex;
public DoaSearchIndex(String doaSearchIndex) {
this.doaSearchIndex = doaSearchIndex;
}
public String getDoaSearchIndex() {
return this.doaSearchIndex;
}
}
I got this (https://stackoverflow.com/a/42040344/3789572) solution, which code is below, but it isn't working. When I press the button, nothing is shown.
You can change the file paths and try it for yourself.
Can you help me?
Controller code:
package sample.principal;
import javafx.concurrent.Worker;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import netscape.javascript.JSObject;
import java.io.File;
import java.net.URL;
import java.util.Base64;
import java.util.ResourceBundle;
import org.apache.commons.io.FileUtils;
public class WebController implements Initializable {
#FXML
private WebView web;
#FXML
private Button btn;
public void initialize(URL location, ResourceBundle resources) {
WebEngine engine = web.getEngine();
String url = getClass().getResource("..\\resources\\web\\viewer.html").toExternalForm();
// connect CSS styles to customize pdf.js appearance
engine.setUserStyleSheetLocation(getClass().getResource("..\\resources\\web\\viewer.css").toExternalForm());
engine.setJavaScriptEnabled(true);
engine.load(url);
engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
// to debug JS code by showing console.log() calls in IDE console
JSObject window = (JSObject) engine.executeScript("window");
window.setMember("java", new JSLogListener());
engine.executeScript("console.log = function(message){ java.log(message); };");
// this pdf file will be opened on application startup
if (newValue == Worker.State.SUCCEEDED) {
try {
// readFileToByteArray() comes from commons-io library
byte[] data = FileUtils.readFileToByteArray(new File("C:\\Users\\Felipe\\Documents\\" +
"Programação\\Java\\" +
"IdeaProjects\\PDFviewerStackOverFlow\\src\\sample\\principal\\teste.pdf"));
String base64 = Base64.getEncoder().encodeToString(data);
// call JS function from Java code
engine.executeScript("openFileFromBase64('" + base64 + "')");
} catch (Exception e) {
e.printStackTrace();
}
}
});
// this file will be opened on button click
btn.setOnAction(actionEvent -> {
try {
byte[] data = FileUtils.readFileToByteArray(new File("teste.pdf"));
String base64 = Base64.getEncoder().encodeToString(data);
engine.executeScript("openFileFromBase64('" + base64 + "')");
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
The Main code:
package sample.principal;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
Application.launch();
}
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("PDF test app");
primaryStage.setScene(new Scene(root, 1280, 576));
primaryStage.show();
}
}
and the other one:
package sample.principal;
public class JSLogListener {
public void log(String text) {
System.out.println(text);
}
}
I would be very grateful for your help.
Thanks.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage stage) {
stage.setTitle("HTML");
stage.setWidth(500);
stage.setHeight(500);
Scene scene = new Scene(new Group());
VBox root = new VBox();
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(browser);
webEngine.loadContent("<b>asdf</b>");
root.getChildren().addAll(scrollPane);
scene.setRoot(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I Have D3 Intergrated in my Project.
Anytimes comes the Exception "could not initialize javascript connector because no javascript init function was found"
Here my Code
MainUI
package testd323.asdg;
import java.util.ArrayList;
import java.util.List;
import com.company.grafiktest5.ui.MainView;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Widgetset;
import com.vaadin.data.validator.IntegerRangeValidator;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.xdev.ui.XdevUI;
import com.xdev.ui.navigation.XdevNavigator;
#Theme("mytheme")
#SuppressWarnings("serial")
#Widgetset("CircleD3.circle.AppWidgetSet")
#com.vaadin.annotations.JavaScript( {"d3.v3.min.js",
"CircleD3_circle_Diagram.js"} )
public class MainUI extends XdevUI {
final VerticalLayout layout = new VerticalLayout();
final TextField xCoordField = new TextField("X");
final TextField yCoordField = new TextField("Y");
final Button button = new Button("move circle");
final Diagram diagram = new Diagram();
final List<Integer> coords = new ArrayList<>();
#Override
protected void init(final VaadinRequest request) {
configureIntegerField(this.xCoordField); //not interesting, just adding converter/validator to the textFields
configureIntegerField(this.yCoordField);
this.button.addClickListener(new Button.ClickListener() { //ATTENTION! Here we get the coordinates from the textfields and apply them to our Diagram via calling diagram.setCoords()
#Override
public void buttonClick(final Button.ClickEvent event) {
if(MainUI.this.xCoordField.isValid() && MainUI.this.yCoordField.isValid()){
MainUI.this.coords.clear();
MainUI.this.coords.add(Integer.parseInt(MainUI.this.xCoordField.getValue()));
MainUI.this.coords.add(Integer.parseInt(MainUI.this.yCoordField.getValue()));
MainUI.this.diagram.setCoords(MainUI.this.coords);
}
}
});
//now we build the layout.
this.layout.setSpacing(true);
this.layout.addComponent(this.xCoordField);
this.layout.addComponent(this.yCoordField);
this.layout.addComponent(this.button);
this.layout.addComponent(this.diagram); //add the diagram like any other vaadin component, cool!
setContent(this.layout);
}
private void configureIntegerField(final TextField integerField) {
integerField.setConverter(Integer.class);
integerField.addValidator(new IntegerRangeValidator("only integer, 0-500", 0, 500));
integerField.setRequired(true);
integerField.setImmediate(true);
}
Diagramm.Java
package testd323.asdg;
import java.util.List;
import com.vaadin.annotations.JavaScript;
import com.vaadin.ui.AbstractJavaScriptComponent;
#JavaScript({"d3.v3.min.js",
"testd323.asdg.diagram_connector.js"})
public class Diagram extends AbstractJavaScriptComponent {
public void setCoords(final List<Integer> coords) {
getState().setCoords(coords);
}
#Override
public DiagramState getState() {
return (DiagramState) super.getState();
}
}
DiagramState.java
package testd323.asdg;
import java.util.List;
import com.vaadin.shared.ui.JavaScriptComponentState;
public class DiagramState extends JavaScriptComponentState {
private List<Integer> coords;
public List<Integer> getCoords() {
return this.coords;
}
public void setCoords(final List<Integer> coords) {
this.coords = coords;
}
}
diagram_connector.js
window.testd323_asdg_Diagram = function() {
var diagramElement = this.getElement();
var diagramFrame = d3.select(diagramElement).append("svg:svg").attr("width", 500).attr("height", 500);
diagramFrame.append("svg:circle").attr("cx", 250).attr("cy", 250).attr("r", 20).attr("fill", "red");
this.onStateChange = function() {
var coords = this.getState().coords;
d3.selectAll("circle").transition().attr("cx", parseInt(coords[0]));
d3.selectAll("circle").transition().delay(500).attr("cy", parseInt(coords[1]));
}
Hope that anyone can help me.
Thanks!
The JavaScript files need to be in resources/testd323/asdg in order to be found.
I have a JavaFX WebView and want to call the method "hello" of the class "JavaBridge" from "test.html" displayed in the webview.
Why doesn't this work? I making sure that the "bridge" object only be added to the window.object when the page has been fully rendered, so that is probably not the problem. I can't see any problem with the HTML either.
Here is the HTML code ("test.html"):
<html>
<head>
</head>
<body>
call java
</body>
</html>
And here is the Java Code:
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import netscape.javascript.JSObject;
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
java.net.URI uri = java.nio.file.Paths.get("test.html").toAbsolutePath().toUri();
WebView root = new javafx.scene.web.WebView();
root.getEngine().load(uri.toString());
root.getEngine().
getLoadWorker().
stateProperty().
addListener(new ChangeListener < State > () {
#Override public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == Worker.State.SUCCEEDED) {
System.out.println("READY");
JSObject jsobj = (JSObject) root.getEngine().executeScript("window");
jsobj.setMember("bridge", new JavaBridge());
}
}
});
primaryStage.setScene(new javafx.scene.Scene(root, 800, 600));
primaryStage.show();
}
}
class JavaBridge {
public void hello() {
System.out.println("hello");
}
}
When using this bridge feature on Java 10.0.2, I noticed that it was not working consistently. Javascript upcalls wasn't working all the times.
After researching, I found out this OpenJDK bug related to Java Garbage Collector, which seems to happen on regular JDK as well:
https://bugs.openjdk.java.net/browse/JDK-8170085
Indeed, according to https://docs.oracle.com/javase/9/docs/api/javafx/scene/web/WebEngine.html, it's recommended to store the bridge into a variable to avoid Java GC to collect the object.
After adding a private variable to the class, the JS to Java calls started to work all the time in my Application.
Your inner class should be inside the main class. And it should be public. Like this:
import java.net.URL;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
final URL url = getClass().getResource("test.html");
WebView root = new javafx.scene.web.WebView();
root.getEngine().load(url.toExternalForm());
root.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
#Override
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == Worker.State.SUCCEEDED) {
System.out.println("READY");
JSObject jsobj = (JSObject) root.getEngine().executeScript("window");
jsobj.setMember("bridge", new JavaBridge());
}
}
});
primaryStage.setScene(new javafx.scene.Scene(root, 800, 600));
primaryStage.show();
}
public class JavaBridge {
public void hello() {
System.out.println("hello");
}
}
}
I had the same problem and the only way to fix it was storing the Bridge on a static variable.
this is an example to use the javafx FileChooser.
public class Controller implements Initializable {
#FXML private WebView webview;
#FXML private JFXButton btn_insertimg;
#FXML private AnchorPane anchorpane;
private WebEngine webEngine;
public static Bridge bridge; //it's important to be static
#Override
public void initialize(URL location, ResourceBundle resources) {
webEngine = webview.getEngine();
webEngine.getLoadWorker().stateProperty().addListener(
(ov, oldState, newState) -> {
if (newState == Worker.State.SUCCEEDED) {
//todo when the document is fully loaded
FileChooser fileChooser=new FileChooser();
bridge=new Bridge(webview,fileChooser);
JSObject window = (JSObject) webEngine.executeScript("window");
window.setMember("myFileChooser", bridge);
System.out.println("member "+window.getMember("myFileChooser").toString());;
}//end of SUCCEEDED state
});
webEngine.load(getClass().getResource("/patient/texteditor/summernote.html").toExternalForm());
}
public class Bridge{
FileChooser fileChooser;
WebView webView;
Bridge(WebView webView,FileChooser fileChooser){
this.webView=webView;
this.fileChooser=fileChooser;
}
public void display(){
fileChooser.showOpenDialog(webView.getScene().getWindow());
}
}
}