I am trying to display a graph using graphview. I get the error: "The constructor GraphViewSeries(String, int, GraphView.GraphViewData[]) is undefined"
This is part of what I have:
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphView.GraphViewData;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
// first init data
// sin curve
int num = 150;
GraphViewData[] data = new GraphViewData[num];
double v=0;
for (int i=0; i<num; i++) {
v += 0.2;
data[i] = new GraphViewData(i, Math.sin(v));
}
GraphViewSeries seriesSin = new GraphViewSeries("Sinus curve", Color.rgb(200, 50, 00), data);
I am not sure what is wrong. Can anyone help?
you can try this:
GraphViewSeries seriesSin = new GraphViewSeries("Sinus curve", new GraphViewSeriesStyle(Color.BLUE, 2), data);
Related
I have built an web browser in JavaFX. I want to add new popup window feature in my browser. when I use JavaScript method window.open(). It will execute code and open new popup window.
package browser;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.event.ActionEvent;
import javafx.event.EventTarget;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.JOptionPane;
import netscape.javascript.JSObject;
public class BrowserController implements Initializable {
#FXML
BorderPane browserBP;
#FXML
WebView browserWV;
#FXML
ImageView stopReloadIV;
#FXML
TextField addressBarTF;
#FXML
ProgressIndicator progressPI;
#FXML
Label statusL;
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb)
{
popup pop_up = new popup();
browserWV.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>()
{
#Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
statusL.setText("loading... " + browserWV.getEngine().getLocation());
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/stoploading.png")));
progressPI.setVisible(true);
if(newValue == Worker.State.SUCCEEDED) {
//
JSObject window = (JSObject) browserWV.getEngine().executeScript("window");
window.setMember("window",pop_up);
addressBarTF.setText(browserWV.getEngine().getLocation());
statusL.setText("loaded");
progressPI.setVisible(false);
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/reload.png")));
if(browserBP.getParent() != null) {
TabPane tp = (TabPane)browserBP.getParent().getParent();
for(Tab tab : tp.getTabs()) {
if(tab.getContent() == browserBP) {
tab.setText(browserWV.getEngine().getTitle());
break;
}
}
}
}
}
});
WebEngine webEngine = browserWV.getEngine();
webEngine.setJavaScriptEnabled(true);
}
#FXML
private void browserBackButtonAction(ActionEvent event) {
if(browserWV.getEngine().getHistory().getCurrentIndex() <= 0) {
return;
}
browserWV.getEngine().getHistory().go(-1);
}
#FXML
private void browserForwardButtonAction(ActionEvent event) {
if((browserWV.getEngine().getHistory().getCurrentIndex() + 1) >= browserWV.getEngine().getHistory().getEntries().size()) {
return;
}
browserWV.getEngine().getHistory().go(1);
}
#FXML
private void browserGoButtonAction(ActionEvent event) {
String url = addressBarTF.getText().trim();
/*if(url.isEmpty())
{
JOptionPane.showMessageDialog(null, "No url provided");
return;
}
if(!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://"+url;
}*/
browserWV.getEngine().load(url);
//browserStopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/stoploading.png")));
}
#FXML
private void browserStopReloadButtonAction(ActionEvent event) {
if(browserWV.getEngine().getLoadWorker().isRunning()) {
browserWV.getEngine().getLoadWorker().cancel();
statusL.setText("loaded");
progressPI.setVisible(false);
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/reload.png")));
} else {
browserWV.getEngine().reload();
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/stoploading.png")));
}
}
#FXML
private void browserHomeButtonAction(ActionEvent event) {
browserWV.getEngine().loadContent("<html><title>New Tab</title></html>");
addressBarTF.setText("");
}
private TextField setText(String ur1) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
It's popup class to open new popup window.But when I use window.open method in JavaScript. It's working but in same window.How it will be open in new window?
package browser;
import java.net.URL;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.web.PopupFeatures;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Callback;
import static sun.plugin.javascript.navig.JSType.URL;
public class popup
{
public void open(String url)
{
WebView browserWV = new WebView();
Platform.runLater(new Runnable()
{
#Override
public void run()
{
browserWV.getEngine().setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>()
{
#Override
public WebEngine call(PopupFeatures p) {
Stage stage = new Stage(StageStyle.UTILITY);
WebView wv2 = new WebView();
stage.setScene(new Scene(wv2));
stage.show();
WebEngine webEngine = new WebEngine();
webEngine.setJavaScriptEnabled(true);
return wv2.getEngine();
}
});
VBox root = new VBox();
TextField address_bar = new TextField();
root.getChildren().add(address_bar);
root.getChildren().add(browserWV);
Scene scene = new Scene(root, 1370, 700);
Stage primaryStage = new Stage();
primaryStage.setTitle("Popup");
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setIconified(true);
browserWV.getEngine().load(url);
address_bar.setText(browserWV.getEngine().getLocation());
}
});
}
}
i tried to integrate my app with facebook like this:
const FBSDK = require('react-native-fbsdk');
const {
GraphRequest,
GraphRequestManager,
AccessToken,
LoginButton,
LoginManager
} = FBSDK;
....
<LoginButton
style={styles.facebookRegButton}
readPermissions={['public_profile']}
onLogoutFinished={() => alert("User logged out")} />
now when i press on the facebook login button my app crash with the error:
"appname stopped".
i working with android
this is my mainActivity.java file:
package com.students;
import com.facebook.react.ReactActivity;
import com.oblador.vectoricons.VectorIconsPackage;
import com.github.yamill.orientation.OrientationPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import android.content.Intent;
import android.os.Bundle;
import com.facebook.FacebookSdk;
import com.facebook.CallbackManager;
import com.facebook.react.ReactPackage;
public class MainActivity extends ReactActivity {
CallbackManager mCallbackManager = MainApplication.getCallbackManager();
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "students";
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
}
and MainApplication.java file:
package com.students;
import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.imagepicker.ImagePickerPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.appevents.AppEventsLogger;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private static CallbackManager mCallbackManager =
CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
#Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new FBSDKPackage(mCallbackManager),
new ImagePickerPackage()
);
}
};
#Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
My react native version is: 0.36.1
tnx a lot
You don't must edit MainActivity.java only MainApplication.java.
To solve it:
MainActivity.java to default
You must configure strings.xml. That file is in android\app\src\main\res\values\strings.xml. Write this line inside <resources> tag.
<string name="facebook_app_id">IDFACEBOOKAPP</string>
Put your facebook app id inside.
The circle should go back and forth but the start button is not starting it for some reason? When I ran the example file it worked and it looks exactly like mine so not sure why Mine isnt starting. Does anybody know why? Thanks
package projavafx.metronometransition.ui;
import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class MetronomeTransitionMain extends Application{
Button startButton;
Button pauseButton;
Button resumeButton;
Button stopButton;
Circle circle;
public static void main(String[] args) { Application.launch(args);}
#Override
public void start(Stage stage) {
circle = new Circle(100, 50, 4, Color.BLUE);
TranslateTransition anim = new TranslateTransition(new Duration(1000.0), circle);
anim.setFromX(0);
anim.setToX(200);
anim.setAutoReverse(true);
anim.setCycleCount(Animation.INDEFINITE);
anim.setInterpolator(Interpolator.LINEAR);
startButton = new Button("start");
startButton.setOnAction(e -> anim.playFromStart());
pauseButton = new Button("pause");
startButton.setOnAction(e -> anim.pause());
resumeButton = new Button("resume");
resumeButton.setOnAction(e -> anim.play());
stopButton = new Button("stop");
stopButton.setOnAction(e -> anim.stop());
HBox commands = new HBox(10, startButton,
pauseButton,
resumeButton,
stopButton);
commands.setLayoutX(60);
commands.setLayoutY(420);
Group group = new Group(circle, commands);
Scene scene = new Scene(group, 400, 500);
startButton.disableProperty().bind(anim.statusProperty()
.isNotEqualTo(Animation.Status.STOPPED));
pauseButton.disableProperty().bind(anim.statusProperty()
.isNotEqualTo(Animation.Status.RUNNING));
resumeButton.disableProperty().bind(anim.statusProperty()
.isNotEqualTo(Animation.Status.PAUSED));
stopButton.disableProperty().bind(anim.statusProperty()
.isEqualTo(Animation.Status.STOPPED));
stage.setScene(scene);
stage.setTitle("Metronome using TranslateTransition");
stage.show();
}
}
I added into my table the option table.setTableMenuButtonVisible(true); in order to show and hide columns.
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class MainApp extends Application
{
private TableView table = new TableView();
public static void main(String[] args)
{
launch(args);
}
#Override
public void start(Stage stage)
{
Scene scene = new Scene(new Group());
stage.setTitle("Table View Sample");
stage.setWidth(300);
stage.setHeight(500);
final Label label = new Label("Address Book");
label.setFont(new Font("Arial", 20));
table.setEditable(true);
TableColumn firstNameCol = new TableColumn("First Name");
TableColumn lastNameCol = new TableColumn("Last Name");
TableColumn emailCol = new TableColumn("Email");
table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
table.setTableMenuButtonVisible(true);
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
vbox.getChildren().addAll(label, table);
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.show();
}
}
Can I for example show the columns First Name and Last Name by default and to hide Email?
Is there any option for this?
I am developing an app in which i want offline map so am using osmdroid and slf4j libs.I have map tiles which i get using the Mobile Atlas Creator. How to integrate those tiles in java code ?
MainActvity is:
package com.example.osmofflinemap;
import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.tileprovider.tilesource.XYTileSource;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import org.osmdroid.views.overlay.SimpleLocationOverlay;
import android.support.v4.app.Fragment;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends Activity {
private MapView mapView;
private MapController mapController;
private ScaleBarOverlay mScaleBarOverlay;
private SimpleLocationOverlay mMyLocationOverlay;
MyItemizedOverlay myItemizedOverlay = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView map = (MapView) findViewById(R.id.mapview);
map.setTileSource(new XYTileSource("MapQuest",
ResourceProxy.string.mapquest_osm, 0, 18, 256, ".jpg", new String[] {
"/sdcard/osmdroid/MapQuest/4/10/6",
"/sdcard/osmdroid/MapQuest/4/10/7",
"/sdcard/osmdroid/MapQuest/4/11/6",
"/sdcard/osmdroid/MapQuest/4/11/7"}));
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
map.setUseDataConnection(false); //optional, but a good way to prevent loading from the network and test your zip loading.
IMapController mapController = map.getController();
mapController.setZoom(4);
GeoPoint startPoint = new GeoPoint(18.533333, 73.866667);
mapController.setCenter(startPoint);
}
}