Infinite Cycle View Pager 3D Item -- How to make NewActivity, when click one card - view

I want to implement a special conversion that is popular on the net, namely "Infinite Cycle View Pager - GithubAndroid Library Dev Light"
Here is the link:Infinite Cycle View Pager
I think you know this, you can present cards that can be rotated in 3D, very design.
I would like a menu system from this, if you click on the card, I would like to open a NewActivity window. It would basically be a video presentation.
But the code below is "myAdapter.java", I transformed it, and in the setOnClickListener - Intent section
so as you can see, it doesn't indicate a syntax error, it translates, it starts, but when I click on the card, the program exits with a program stop.
What do you think could be wrong?
import android.content.Context;
import android.content.Intent;
import android.provider.ContactsContract;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import java.util.List;
public class MyAdopter extends PagerAdapter {
List<Integer> images;
Context context;
LayoutInflater layoutInflater;
public MyAdopter(List<Integer> images, Context context) {
this.images = images;
this.context = context;
layoutInflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
return images.size();
}
#Override
public boolean isViewFromObject(#NonNull View view, #NonNull Object object) {
return view.equals(object);
}
#Override
public void destroyItem(#NonNull ViewGroup container, int position, #NonNull Object object) {
container.removeView((View)object);
}
#NonNull
#Override
public Object instantiateItem(#NonNull ViewGroup container, final int position) {
View view= layoutInflater.inflate(R.layout.card_item,container,false);
ImageView imageView =(ImageView)view.findViewById(R.id.imageview);
imageView.setImageResource(images.get(position));
container.addView(view);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, zoompresentationvideo.class);
context.startActivity(intent);
//Toast.makeText(context,"Clicked image show presentation " +position,Toast.LENGTH_LONG ).show();
}
});
return view;
}
}
Thank you in advance for your help.

Related

Javafx titledpane animation speed

Is there a way to set the animation speed of a titledpane? I couldn't find anything.
In fact there are two issues.
First:
The animation of the expanding is faster than the expanding of the content itself. You see that the circle is slightly slower than the bar from the second titledpane is moving down.
Second:
How to change the speed of both of them. I need them at the same speed, because it looks weird.
Here is a small example for testing purposes:
package test;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
public class TestClass extends Application{
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
VBox vb = new VBox();
{
TitledPane tp = new TitledPane();
System.out.println(tp.getContextMenu());
tp.setContent(new Circle(100));
tp.setText("asfadf");
tp.expandedProperty().addListener(new ChangeListener<Boolean>() {
#Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
System.out.println("expand " + newValue);
}
});
vb.getChildren().add(tp);
}
vb.getChildren().add(new Line(0, 0, 100, 0));
{
TitledPane tp = new TitledPane();
tp.setContent(new Circle(100));
tp.setText("asfadf");
tp.expandedProperty().addListener(new ChangeListener<Boolean>() {
#Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
System.out.println("expand " + newValue);
}
});
vb.getChildren().add(tp);
}
vb.setStyle("-fx-background-color: gray");
Scene scene = new Scene(vb,500,500);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Short answer: There's no API to change the duration.
However, there are two ways to achieve it anyway:
Alternative #1: Reflection
The duration is defined in the static final field com.sun.javafx.scene.control.TitledPaneSkin.TRANSITION_DURATION. Using reflection, you can change its value but this is really bad. Not only because that's a dirty hack, but also because TitledPaneSkin is Oracle internal API that is subject to change anyway. Also, this does not fix the issue with the different speeds:
private static void setTitledPaneDuration(Duration duration) throws NoSuchFieldException, IllegalAccessException {
Field durationField = TitledPaneSkin.class.getField("TRANSITION_DURATION");
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(durationField, durationField.getModifiers() & ~Modifier.FINAL);
durationField.setAccessible(true);
durationField.set(TitledPaneSkin.class, duration);
}
Alternative #2: Set your own skin
To be on the safe side, you could create and use your own skin (start by copying the existing one) using titledPane.setSkin(). This way you can also fix the different speed, which is basically caused by linear vs. ease interpolation - but that's quite some work.
Just disable the animation with something like:
TitledPane pane = new TitledPane();
pane.animatedProperty().set(false);
and expanding will be as fast as possible.

The widgets in a new activity not showing up

I am working on an application that has a button which will lead to a new activity. I managed to make that work but when I am trying to add a button in the new activity with xml it is not showing up. I tried to make it work with programming but I was only able to make a button big as the whole screen. When I tried to change the size of the button with programming it could not work. Can someone please tell me how can I make that widgets show on the new activity preferably using XML.
This is the code of my first activity:
package com.example.user.myapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
import android.view.View;
import android.content.Intent;
public class MainActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main_actions, menu);
return super.onCreateOptionsMenu(menu);
}
public void sendButton(View view){
Intent intent = new Intent(this, Ut.class);
startActivity(intent);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
And this is the code of my second activity:
package com.example.user.myapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Button;
import android.content.Intent;
public class Ut extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
setContentView(R.layout.activity_ut);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main_actions, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
and this is the code that I added after Intent intent = getIntent() when I tried to make it work with programming
Button button2 = new Button(this);
button2.setWidth(10);
button2.setHeight(10);
setContentView(button2);
With this code a button big as the whole screen showed up although I set the size of it.
Can somebody tell me how I can make this work?

Android Studio, Parse.com, custom adapter, cannot resolve symbol

I am new in creating apps. I am learning by doing courses on Udemy. So right now I am learning how to create a simple app where your can register, login and post a message, and I am doing all of this using Parse.com. Everything worked perfectly until today, when it was time to create a custom adapter that shows these posts.
The error is: cannot resolve symbol mStatus in the HomepageActivity class, though in the Udemy video, everything works perfectly.
Another strange error is in the line
ParseQuery<ParseObject> query = new ParseQuery <ParseObject> ("Status");
the second <ParseObject> is greyed out and it says Explicit type argument can be replaced with <>, though in the video its white(working).
The only explanation I thought of is that the video is old and something changed in the syntax, but I am not that great of a programmer to understand what to do. Or maybe im doing something wrong? Please help.
P.S . when I am trying to run the app, I am getting this message:
Note:C:\Users\User\AndroidStudioProjects\LiveUpdate\app\src\main\java\com\mycompany\liveupdate\StatusAdapter.java uses unchecked or unsafe operations.
Here is the adapter code:
package com.mycompany.liveupdate;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.parse.ParseObject;
import java.util.List;
/**
* Created by User on 2015-01-18.
*/
public class StatusAdapter extends ArrayAdapter {
protected Context mContext;
protected List<ParseObject> mStatus;
public StatusAdapter(Context context, List status) {
super(context, R.layout.homepagecustomlayout, status);
mContext = context;
mStatus = status;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(
R.layout.homepagecustomlayout, null);
holder = new ViewHolder();
holder.usernameHomepage = (TextView) convertView
.findViewById(R.id.usernameHP);
holder.statusHomepage = (TextView) convertView
.findViewById(R.id.statusHP);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ParseObject statusObject = mStatus.get(position);
// title
String username = statusObject.getString("user");
holder.usernameHomepage.setText(username);
// content
String status = statusObject.getString("newStatus");
holder.statusHomepage.setText(status);
return convertView;
}
public static class ViewHolder {
TextView usernameHomepage;
TextView statusHomepage;
}
}
Here is the code, where im trying to call this adapter:
package com.mycompany.liveupdate;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.parse.FindCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import java.util.List;
public class HomepageActivity extends ListActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homepage);
Parse.initialize(this, "uinXCHcfbdm8zrbUT9y8Vu4R2qU5D22FZwkHs5HZ", "v1PL4oDu3ebtSidJFhjWRkkBQVAD8sefIB1WDFeq");
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
// show user the homepage
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Status");
query.orderByDescending("createdAt");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> status, ParseException e) {
if(e == null){
//success
mStatus = status;
StatusAdapter adapter = new StatusAdapter(getListView().getContext(), status);
setListAdapter(adapter);
}else {
//there was a problem
}
}
});
} else {
// show the signup or login screen
Intent takeUserToLogin = new Intent(HomepageActivity.this, LogInActivity.class);
startActivity(takeUserToLogin);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_homepage, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id){
case R.id.updateStatus:
//take user to updatestatus activity
Intent intent = new Intent(this, UpdateStatusActivity.class );
startActivity(intent);
break;
case R.id.logoutUser:
// log out user
ParseUser.logOut();
// take the user back to logout screen
Intent takeUserToLogin = new Intent(this, LogInActivity.class);
startActivity(takeUserToLogin);
break;
}
return super.onOptionsItemSelected(item);
}
}

Add EventHandler to ImageView contained in TilePane contained in VBox?

I have the following schema:
A VBox, containing a HBox and a TilePane.
In HBox are buttons, labels, and text fields.
Every time I click on the root (HBox), I should add a ImageView to the tile pane. This ImageView shold contain an image (example: "2.jpg"). Maximum of tile pane components is 5.
Every time I click the image, i should load a new image to the clicked ImageView, exemple "1.jpg". It is not working. When I click on my image it is like i'm clicking on the root so it creates another cell of TilePane. Here's the code, can you help me?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dadao1;
import java.util.HashSet;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
/**
*
* #author Ambra
*/
public class Dadao1 extends Application {
VBox root;
HashSet dadi = new HashSet();
//static int numeroDadi = 0;
#Override
public void start(Stage primaryStage) {
setGui();
Scene scene = new Scene(root, 300, 300);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
*This private method sets up the GUI.
* No parameters are required
*/
private void setGui(){
root = new VBox();
HBox buttons = new HBox();
final Button newGame = new Button("New Game");
final Button print = new Button("Print");
final Button animation = new Button("Moving");
animation.addEventHandler(ActionEvent.ACTION, new EventHandler<ActionEvent>() {
// this button is labeled "Moving" at the begin. If pressed it changes its label to "Dissolving" and viceversa.
#Override
public void handle(ActionEvent event) {
if (animation.getText().equals(new String("Moving")))
animation.setText("Dissolving");
else animation.setText("Mooving");
}
});
final Label score = new Label("Total");
final TextField points = new TextField();
final Label pointsLabel = new Label("Score");
root.setStyle("-fx-background-color: green");
buttons.getChildren().addAll(newGame,print,animation,score,points,pointsLabel);
final TilePane dadiPane = new TilePane();
dadiPane.setVgap(10);
dadiPane.setHgap(10);
root.getChildren().addAll(buttons, dadiPane);
root.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
if(dadi.size()<5){
System.out.println("Adding img");
final ImageView img = new ImageView("2.jpg");
// should I put final in front of ImageView?
img.addEventHandler(ActionEvent.ACTION, new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
// I want that when a tile is pressed an event occours.
// that event should be "add a new image to the ImageView just clicked",
// for example: img is not "2.jpg" but "3.jpj", by the way, I'm not able neither
// to to print the folowing messagge :(
// It's like my root is pressed even if my mouse ha clicked at the image in img var.
System.out.println("Tile pressed ");
}
});
dadi.add(img);
dadiPane.getChildren().add(img);
}else System.out.println("You cannot create more than 5 dices");
}
});
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
ImageViews don't generate ActionEvents; so it is no surprise that your event handler is never invoked. Since the mouse event is not processed by the ImageView, it propagates up to the container.
Try
img.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
System.out.println("Tile pressed ");
event.consume();
}
});
#James_D is correct; but note for Java 8 you can use the simpler syntax:
img.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
System.out.println("Tile pressed ");
event.consume();
});
Note that MouseEvent.MOUSE_CLICKED is a class from javafx, not from java.awt.event package
imgView. addEventHandler(javafx.scene.input.MouseEvent.MOUSE_CLICKED, event -> {
//event clicked here
});
For someone who mistakenly import java.awt.event.MouseEvent class

XY Scatter AndroidPlot

Attempting to use AndroidPlot to create an XY scatter plot, encountering a problem... whereby the plot only draws points from left to right, a scrolling chart essentially.
Example... say I have the following co-ordinates, (0,1), (1,0), (0,-1), (-1,0) I would expect to see a diamond shape (if all the points were joined by a line)
I've used the AndroidPlot library successfully before so am somewhat familiar with the methods available.
Is there any examples for a scatter plot using the AndroidPlot library?
Hope I'm making sense here..
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import pl.flex_it.androidplot.XYSeries;
import com.androidplot.series.XYSeries;
import com.androidplot.xy.BoundaryMode;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYPlot;
import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Temp extends Fragment {
private static XYPlot xyPlot;
private XYSeriesShimmer series;
private LineAndPointFormatter series1Format;
private ArrayList<Number> ALdata1, ALdata2;
private int Adata1[], Adata2[];
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_test, container, false);
// Import plot from the layout
xyPlot = (XYPlot) rootView.findViewById(R.id.xyPlot);
xyPlot.setDomainBoundaries(-2, 2, BoundaryMode.FIXED); // freeze the domain boundary:
xyPlot.setRangeBoundaries(-2, 2, BoundaryMode.FIXED);
ALdata1 = new ArrayList<Number>();
ALdata2 = new ArrayList<Number>();
ALdata1.clear();
ALdata2.clear();
Adata1 = new int[]{0,1,0,-1};
Adata2 = new int[]{1,0,-1,0};
series = new XYSeriesShimmer(ALdata1, ALdata2, 0, "Sightings in USA");
series1Format = new LineAndPointFormatter(Color.TRANSPARENT, Color.BLACK, null); // line color, point color, fill color
xyPlot.addSeries(series, series1Format);
plotDataMethod();
return rootView;
}
private void plotDataMethod() {
for(int i=0; i<Adata1.length; i++){
ALdata1.add(Adata1[i]);
ALdata2.add(Adata2[i]);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
series.updateData(ALdata1, ALdata2);
xyPlot.redraw();
}
}
}
EDIT:
package pl.flex_it.androidplot;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.androidplot.series.XYSeries;
public class XYSeriesShimmer implements XYSeries {
private List<Number> dataX;
private List<Number> dataY;
private int seriesIndex;
private String title;
public XYSeriesShimmer(List<Number> datasource, int seriesIndex, String title) {
this.dataY = datasource;
this.seriesIndex = seriesIndex;
this.title = title;
}
public XYSeriesShimmer(List<Number> datasourceX, List<Number> datasourceY, int seriesIndex, String title) {
this.dataX = datasourceX;
this.dataY = datasourceY;
this.seriesIndex = seriesIndex;
this.title = title;
}
#Override
public String getTitle() {
return title;
}
#Override
public int size() {
return dataY.size();
}
#Override
public Number getY(int index) {
return dataY.get(index);
}
#Override
public Number getX(int index) {
return index;
}
public void updateData(List<Number> datasourceX){ //dont need to use this cause, the reference is only stored, modifying the datasource externally will cause this to be updated as well
this.dataY=datasourceX;
}
public void updateData(List<Number> datasourceX, List<Number> datasourceY){ //dont need to use this cause, the reference is only stored, modifying the datasource externally will cause this to be updated as well
this.dataX=datasourceX;
this.dataY=datasourceY;
}
}
This looks like it could be the problem - in XYSeriesShimmer:
#Override
public Number getX(int index) {
return index;
}
This is always going to return i, which means each element's x value is 1 larger than the previous...exactly what you are experiencing. Try changing it to this:
#Override
public Number getX(int index) {
return dataX.get(i);
}

Resources