I'm trying to display image files for the android layout of each screen.
I tried displaying the base menu picture file and image 2 and add them both into the screen. However, I seem to capture the base menu but not the 2nd image.
My function for getting the images, under class name "MyResource'
public function getImage(name:String):Image{
var img:Image = new Image(assetManager.getTexture(name));
return img;
}
My 'main menu' class. It has a bunch of buttons that will redirect it to selected the selected class containing the screens.
switch (btn.name)
{
case "genji":
trace("Genji voice menu was selected.");
app.getScreenManager().getScreen(ScreenManager.SCREEN_GENJI);
break;
}
The screen class that's supposed to display the 2nd image.
public class GenjiScreenClass extends Screens
{
public function GenjiScreenClass(app:StarlingBaseClass)
{
super(app);
}
override public function initialize():void{
trace("I am in GenjiScreenClass initialize() function");
var img:Image = myResource.getImage("basemenu320x480");
var genjiImage:Image = myResource.getImage("GenjiMenuPicture")
this.addChild(genjiImage);
this.addChild(img);
}
}
The image files are all under asset/x1. The base menu image came out but how come the 2nd one didn't?
You add img last:
this.addChild(genjiImage);
this.addChild(img);
This means img is on top of genjiImage covering it up. Depending on the content and size of the images the above one might entirely hide the below one, which can lead to the impression that only the top one is being displayed.
Swap the order of these two statements to solve the problem.
Related
I need to add back navigation on swipe. I can do that fairly easily by just adding a swipe listener to the page view and calling goBack. But I really would like the animation that goes with it (in Instagram or FB) where as soon as you start dragging your thumb, the page translates to the right and the previous page starts to translate into view. And then once you get to a certain point it actually performs the navigation.
I tried animating the page, as well as the frame to the right figuring since the view isn't being destroyed it might work. But it doesn't display the page Im navigating back to.
Looking for help on how to accomplish this!
I guess you might have come across the other SO thread answering this question natively.
All you have to do is modify the default gesture recogniser on iOS frame.
export function onNavigatedFrom(args: EventData) {
console.log("Adding gesture...");
const frame = (<Page>args.object).frame;
if (frame.ios && !(<any>frame)._gestureRecognizer) {
const controller = frame.ios.controller;
const popGestureRecognizer = controller.interactivePopGestureRecognizer;
const targets = popGestureRecognizer.valueForKey("targets");
if (targets) {
let gestureRecognizer = UIPanGestureRecognizer.alloc().init();
gestureRecognizer.setValueForKey(targets, "targets");
frame.nativeView.addGestureRecognizer(gestureRecognizer);
(<any>frame)._gestureRecognizer = gestureRecognizer;
}
}
}
export function onNavigatedTo(args: EventData) {
console.log("Back to root page, removing gesture...");
const frame = (<Page>args.object).frame;
if (frame.ios && (<any>frame)._gestureRecognizer) {
frame.nativeView.removeGestureRecognizer((<any>frame)._gestureRecognizer);
(<any>frame)._gestureRecognizer = null;
}
}
Playground Sample
I installed web hide menu on https://www.odoo.com/apps/modules/8.0/web_menu_hide_8.0/
I modified to use it on Odoo 10, but the form will be adjusted to full width IF we press the hide button, if we were to change to another view after we pressed hide button, the form page will remain same as original (not full width).
So i need to adjust class "o_form_sheet" on form view after the page has been rendered. May i know how can i do that using javascript? Which class & method do i need to extend?
I'm going to answer my own question.
After some researched, i found out the best option was to inherit ViewManager widget using load_views function.
var ViewManager = require('web.ViewManager');
ViewManager.include({
load_views: function (load_fields) {
var self = this;
// Check if left menu visible
var root=self.$el.parents();
var visible=(root.find('.o_sub_menu').css('display') != 'none')
if (visible) {
// Show menu and resize form components to original values
root.find('.o_form_sheet_bg').css('padding', self.sheetbg_padding);
root.find('.o_form_sheet').css('max-width', self.sheetbg_maxwidth);
root.find('.o_form_view div.oe_chatter').css('max-width', self.chatter_maxwidth);
} else {
// Hide menu and save original values
self.sheetbg_padding=root.find('.o_form_sheet_bg').css('padding');
root.find('.o_form_sheet_bg').css('padding', '16px');
self.sheetbg_maxwidth=root.find('.o_form_sheet').css('max-width');
root.find('.o_form_sheet').css('max-width', '100%');
self.chatter_maxwidth=root.find('.o_form_view div.oe_chatter').css('max-width');
root.find('.o_form_view div.oe_chatter').css('max-width','100%');
}
return this._super.apply(this, arguments, load_fields);
},
});
I have two p5 sketches, and I want to use them in the same space of a website. So that after clicking a button, the sketches switch. So I made three different files. The first two, are the sketches, and they are wrapped in a function (instance mode). The third sketch is a code written in global mode, because It has the information that loads a button right when the website is first accesed, and it has the information containing what the button is supposed to do: call the other sketches.
The code looks like this:
var playing = false;
var button;
function setup() {
var col = color(185,185,185,150);
button = createButton('Play');
button.position(20,20);
button.parent('black');
button.style("background-color", col);
button.style("padding", "10px 20px");
button.style("font-size", "14px");
button.mousePressed(toggleCanvas); // attach button listener
}
function mousePressed() {
}
function toggleCanvas() {
if (playing) {
if(myp5r){
myp5r.remove();
runSketch();
button.html('Stop');
}else{
runSketch();
button.html('Stop');
}
}else {
if(myp5){myp5.remove();
stopSketch();
button.html('Play');
}else{
stopSketch();
button.html('Play');}
}
playing = !playing;
}
I have been warned, to not mix global and instance mode, although my "common sense" says that it is ok to use a global mode for the button. Because I want it to be loading first, along with the page.
I noticed that weird things happen, though. Like, I get a blank space added beneath the footer, it looks horrible. And, even more worse, button is not appearing in the correct spot in the site. I already ckecked that css has position:relative for example. And the design works in localhost, but not in the site.
I have a LWUIT form which contains a list, a number of items has been added to the list, items themselves are strings (I want to make them as statements).
returns
My simple problem is that end user cannot see the whole statements(strings). I tried the below method but the scrolling won't move.
All of form.setScrollableY(true), form.setScrollabelX(true), and form.setScrollable(true).
This is the code
import javax.microedition.midlet.*;
import com.sun.lwuit.layouts.*;
import com.sun.lwuit.*;
public class HelloLWUITMidlet3 extends MIDlet
{
public void startApp()
{
com.sun.lwuit.Display.init(this);
final com.sun.lwuit.Form form = new com.sun.lwuit.Form("");
final com.sun.lwuit.List l = new com.sun.lwuit.List();
l.addItem("MY favourite Science is computer Sciences");
l.addItem("MY favourite computer Science subject is programming");
l.addItem("MY favourite programming language is java ");
form.setScrollableY(true);
form.setScrollableX(true);
form.addComponent(l);
form.show( );
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
}
First of all, scrolling horizontally back and forth to read content is
really bad UX. This answer will solve only the vertical scrolling issue.
The problem with your code is that you are adding a scrollable (List)
inside another scrollable
(Form). This leads to unexpected results, since it is
not clear which component should handle scrolling. This can be fixed by
using the BorderLayout in the form and placing the list at the center.
...
form.setScrollable(false);
form.setLayout(new BorderLayout());
form.addComponent(BorderLayout.CENTER, l);
...
This will enable vertical scrolling, but the horizontal scrolling will not
work.
Clarification about scrolling:
LWUIT's approach
to scrolling is based on Focus, which means that a Container scrolls
because the focused element is out of the screen. This has the consequence
that LWUIT does not support scrolling elements bigger than the screen and, thus,
that your List will not be scrollable horizontally. (Source:LWUIT mini FAQ )
Suggestion:
The maximum element height is taken as the component height in a List. This
makes the List component adequate to show data that is "pre-formatted" in
a specific way, like contact lists of a folder's details list. If you
want to stack pieces of text of variable length, you should
use a Form with BoxLayoutY and put your text in various TextAreas.
void startApp() {
Display.init()
final Form form = new Form("Title");
addItem(form, "String..");
// as many times as you like
addItem(form, "String..");
form.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
form.setScrollableY(true);
form.show()
}
void addItem(Form f, String s) {
TextArea t = new TextArea(s);
t.setGrowByContent(true);
f.addComponent(t);
}
i would like to design a component that look like a switch that has 3 position. One neutral position, and upper switch position, when the user click on the upper half of the component and a lower switch position, when the user click the lower half of the component. When the mouse is released the switch go back to neutral position. I have got 3 switch images for these position. I was thinking using a Button then check if the mouse click coordinate is in the upper half or the lower half then set images accordingly. I am looking for any better suggestion, if possible with the use of css for the images (i don't know if it is possible though), or any other suggestion with the use of another component if it is more suitable. Thank you.
Here is what i did, it works...
final Button rstButton = new Button();
final Image rstNeutral = new Image(MyClass.class.getResourceAsStream("images/switch_neutral.png"));
final Image rstUp = new Image(MyClass.class.getResourceAsStream("images/switch_on.png"));
final Image rstDown = new Image(MyClass.class.getResourceAsStream("images/switch_off.png"));
final ImageView rstImage = new ImageView();
rstImage.setImage(rstNeutral);
rstButton.setGraphic(rstImage);
rstButton.setOnMousePressed(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent me) {
double mouseY = me.getY();
double buttonY = rstButton.getLayoutY();
double buttonHeight = rstButton.getHeight();
if(buttonY + mouseY > buttonY + (buttonHeight / 2)) {
rstImage.setImage(rstDown);
} else {
rstImage.setImage(rstUp);
}
}
});
rstButton.setOnMouseReleased(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent arg0) {
rstImage.setImage(rstNeutral);
}
});
I think you should use three component instead of one.
For exemple, you could use three instance of ToogleButton. This component is like a button in appearance, but have a toogle state (clicked/unclicked). I never use it in javaFX but I think you will find enough help on the oracle site (for example : http://docs.oracle.com/javafx/2/ui_controls/toggle-button.htm)
EDIT :
After comment, I think an image of a mechanical switch (http://docs.oracle.com/javafx/2/api/javafx/scene/image/Image.html) could be the solution. If you're showing the switch from the side you can change the rotation of the image according to the state of the switch.
For knowing where the user clicked, locating the position of the button could work.
Another solution could be to had three transparent region on top of the image and intercept the click event on these region, instead of the image. Having never used such a solution, I can really help you more.
Last solution I see could be the use of two another image component on the side of the switch image, showing two arrow, for pulling up or down the switch.