Categories
discuss

Youtube IFrame API Untrusted Origin

I’m using the IFrame API as the title suggests. I have been following the guide in the API Reference. It works for me however I have found a few warnings that occur and would like to solve them. They are:

Untrusted origin: https://www.youtube.com

and

Untrusted origin: chrome-extension://boadgeojelhgndaghljhdicfkmllpafd

both of which originate from www-embed-player.js:331

Through my research I have found that the second one happens because it constantly polls for the chromecast extension (kinda weird but its google). If I disable the chromecast extension that warning becomes errors such as:

GET chrome-extension://boadgeojelhgndaghljhdicfkmllpafd/cast_sender.js net::ERR_FAILED

from www-embed-player.js:163

I have tried adding the enablejsapi and origin parameters mentioned with no change in luck.

I have also tried adding the IFrame directly as mentioned in Loading a Video Player which didn’t remove the untrusted origin errors, and also broke my javascript functionality.

Thank you

Answer

The error has been acknowledged by Google:

https://code.google.com/p/google-cast-sdk/issues/detail?id=309

This is per design; in order to know if a user has the Chromecast
extension installed (and which one), cast_sender.js requests the
script from all potentially installed extensions.

This question has also been answered here:
https://stackoverflow.com/a/26095117/1007392

Best,
Sam

Categories
discuss

React form onChange->setState one step behind

I encountered this problem building a webapp and I replicated it in this jsfiddle. Essentially, I would like an input to call this.setState({message: input_val}) every time I type something into it, then pass it into the parent App class which then re-renders the message onto the Message class. However the output seems to always be one step behind what I actually type. The jsfiddle demo should be self explanatory. I am wondering if I did anything wrong to prompt this.

html

<script src="http://facebook.github.io/react/js/jsfiddle-integration.js"></script>
<div id='app'></div>

js

var App = React.createClass({
    getInitialState: function() {
        return {message: ''}
    },
    appHandleSubmit: function(state) {
        this.setState({message: state.message});
        console.log(this.state.message);
    },
    render: function() {
        return (
            <div className='myApp'>
            <MyForm onChange={this.appHandleSubmit}/>
            <Message message={this.state.message}/>
            </div>
        );
    }
});

var MyForm = React.createClass({
    handleSubmit: function() {
        this.props.onChange(this.state);
    },
    handleChange: function(e) {
        console.log(e.target.value);
        this.setState({message: e.target.value});
        this.handleSubmit();
    },
    render: function() {
        return (
            <form className="reactForm" onChange={this.handleChange}>
            <input type='text' />
            </form>
        );
    }
});

var Message = React.createClass({
    render: function() {
        return (
            <div className="message">
                <p>{this.props.message}</p>
            </div>
        )
    }
});

React.render(
    <App />,
    document.getElementById('app')
);

Answer

A call to setState isn’t synchronous. It creates a “pending state transition.” (See here for more details). You should explicitly pass the new input value as part of the event being raised (like to handleSubmit in your example).

See this example.

handleSubmit: function(txt) {
    this.props.onChange(txt);
},
handleChange: function(e) {
    var value = e.target.value;
    this.setState({message: value});
    this.handleSubmit(value);
},
Categories
discuss

JPA @Column annotation to create comment/description

I was wondering is it possible to create from jpa/hibernate annotation a database column description/comment like this:

ALTER TABLE tablename CHANGE status status INT(11) NOT NULL COMMENT 'sample description/comment';

It will be great functionality, but I cant find anything about this in JPA specification.

Maybe I should use @Column(columnDefinition="") property, but I dont have any clue. Please help

Answer

I found answer for my own question.

I am not sure is it ok? Will it work for all Databases?

For sure it works for mysql.

Here is the working code:

@Column(columnDefinition=" INT(11) NOT NULL COMMENT '0 for no action, 1 for executed, 2 for validated, 3 for aproved'")
private int status;
Categories
discuss

multiple targets in android studio

I am handling a project for education university ,where there are 5 seperate universities each university having there own app but in each application images ,json differs and the source code remains same . i want to create 5seperate apks with different package name using only one source code and if any change done in source code should update in all apks.

please give me structure of project ,graddle.build tool setting and if i need to make library how and where it will be, or please upload a sample to do above type in detail.

Answer

Following Android Developers guide Configuring Gradle Builds I was able to create application sharing same code with different resources.

Firstly, after creating new project in Android Studio (Gradle: Android Module), I added to build.gradle file (residing in your module directory, like ‘Project/app/build.gradle’) ‘blue’ and ‘red’ flavors:

android {
// ...
    productFlavors {
        blue {
            applicationId 'com.example.app.blue'
            versionName '1.0-blue'
        }
        red {
            applicationId 'com.example.app.red'
            versionName '1.0-red'
        }
    }
}

IDE requested to sync project files with Gradle, so I did it. Then I added resource file colors.xml to ‘red’ flavor by right-clicking directory ‘app’ in project root in Project panel (New -> Android resource file, selected ‘red’ as my Source Set).

Next I modified new file to contain definition of color resource:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="primary">#ff0000</color>
</resources>

I did the same for my ‘blue’ flavor (but with different color value).

I changed background color of activity layout created automatically while creating new project to see if it’ll work.

<RelativeLayout
    ...
    android:background="@color/primary" />

Switching Build Variant in Build Variants panel (opened by lower-left button names such) resulted in different background colors in my activity.

I assume you keep your images, json and other files in Android resurces directories, so the way you should keep different files in different flavors is similiar to what I’ve achieved.

See this site to better understand product flavors and Build Variants.

Categories
discuss

Dagger: class could not be bound with key

I’m trying for first time dagger and, after configuring the module, I get an error I don’t understand.

My code is:

public class Parrot {

    private Language language;

    @Inject
    public Parrot(Language language) {
        this.language = language;
    }

    public void sayHello() {
        System.out.println(language.getSalute());
    }
}

public interface Language {
    public String getSalute();
}

public class EnglishLanguage implements Language {

    @Override
    public String getSalute() {
        return "Hello!";
    }
}

My module is

@Module(
        injects = Language.class
)
public class PetShopModule {

    @Provides Parrot provideParrot(Parrot parrot){
        return parrot;
    }
}

And in the code I use it this way

EnglishLanguage lang=SystemApp.getSystemLanguage();
ObjectGraph objectGraph = ObjectGraph.create(new PetShopModule());
objectGraph.inject(myLanguage);
Parrot parrot = objectGraph.get(Parrot.class);

The compiler complains with:

error: com.example.petshop.Language could not be bound 
with key com.example.petshop.Language required by com.example.petshop.PetShopModule 
for com.example.petshop.PetShopModule

What do I am doing wrong?

Note: This is only a simplified example, in the real code the EnglishLanguage is a system class, and I can’t modify nor create it, just get a reference

Answer

Instead of commenting on what you’re doing wrong, let’s give the correct example, and explain what’s happening there.

This snippet is perfect, and stays as it is:

public class Parrot {

    private Language language;

    @Inject
    public Parrot(Language language) {
        this.language = language;
    }

    public void sayHello() {
        System.out.println(language.getSalute());
    }
}

public interface Language {
    public String getSalute();
}

public class EnglishLanguage implements Language {

    @Override
    public String getSalute() {
        return "Hello!";
    }
}

With the @Inject annotation on the Parrot constructor, you’re telling Dagger, “Whenever I request an instance of Parrot, use this constructor to instantiate it”.

Dagger sees that Parrot needs an instance of the Language interface, and tries to find a way to retrieve it. However, since Language is an interface, Dagger needs to know which concrete type to use.

Since you cannot edit the EnglishLanguage class, you’ll need to write a @Provider method for it:

@Module
public class PetshopModule {

  @Provides
  Language provideLanguage() {
    return SystemApp.getSystemLanguage();
  }
}

Now, you should be able to get an instance of Parrot out of your ObjectGraph, like this:

ObjectGraph graph = ObjectGraph.create(new PetshopModule());
Parrot parrot = graph.get(Parrot.class);

I have not tested this, bit this should work.


If you were able to modify the EnglishLanguage class, you could do the following. Annotate the EnglishLanguage constructor with @Inject, and request an EnglishLanguage instance in the Language provider method:

public class EnglishLanguage implements Language {

  @Inject
  public EnglishLanguage() {
  }

  @Override
  public String getSalute() {
    return "Hello!";
  }
}

@Module
public class PetshopModule {

  @Provides
  Language provideLanguage(EnglishLanguage language) {
    return language;
  }
}

In this case, Dagger looks for the Language provider method, and instantiates an EnglishLanguage to return.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..