We are using Native Module in order to display our ads to our gaming Application. We are using Mobfox SDK for the integration to our Mobile App. Though I can logcat and seems I can request to the admob, my problem now is how am I going to pass what admob returns by calling it to my javascript file?
public class API {
public static void requestAds(final ForgeTask task, #ForgeParam("pub_id") final String pub_id, #ForgeParam("state") final String state, #ForgeParam("type") final String type){
final AdSize size;
if (pub_id.length() == 0) {
task.error("No Published ID entered");
return;
}
if (type == "1"){
size = AdSize.BANNER;
}else if (type == "2"){
size = AdSize.IAB_BANNER;
}else if (type == "3"){
size = AdSize.IAB_LEADERBOARD;
}else if (type == "4"){ //my size
size = AdSize.IAB_MRECT;
}else if (type == "5"){
size = AdSize.IAB_WIDE_SKYSCRAPER;
}else if(type == "6"){
size = AdSize.SMART_BANNER;
}else{
size = AdSize.BANNER;
}
task.performUI(new Runnable() {
public void run() {
AdView adView = new AdView(ForgeApp.getActivity(), size, pub_id);
adView.loadAd(new AdRequest());
AdRequest request = new AdRequest();
if(state == "TEST"){
request.addTestDevice(AdRequest.TEST_EMULATOR);
}
adView.loadAd(request);
}
});
}
Now, what I want is to get the values of adView.loadAd(request);. How am I going to do it so that I can display and pass it to my js file? For example, I want it to be the return value to my success function(), Is it possible? Can you please guide us on how doing it?
Thanks, waiting for your reply.
To return a value to javascript you can use the success method on the task object passed into your API method. You can call this with a String or a JsonElement. i.e.
task.success("This string will be passed to the success callback in JS");
Related
I'm using PdfReader.HasUsageRights() and PdfReader.RemoveUsageRights() in iTextSharp v5. Can't seem to find similar functionality in iText7?
There is probably no direct alternative but it's easy to implement those methods yourself:
public boolean hasUsageRights(PdfDocument pdfDocument) {
PdfDictionary perms = pdfDocument.getCatalog().getPdfObject().getAsDictionary(PdfName.Perms);
if (perms == null) {
return false;
}
return perms.containsKey(new PdfName("UR")) || perms.containsKey(PdfName.UR3);
}
public void removeUsageRights(PdfDocument pdfDocument) {
PdfDictionary perms = pdfDocument.getCatalog().getPdfObject().getAsDictionary(PdfName.Perms);
if (perms == null) {
return;
}
perms.remove(new PdfName("UR"));
perms.remove(PdfName.UR3);
if (perms.size() == 0) {
pdfDocument.getCatalog().remove(PdfName.Perms);
}
}
If you need the first method then you can pass either a document created with PdfDocument(PdfReader, PdfWriter) constructor or with PdfDocument(PdfReader) one. If you need the second method then you need to pass a document created in stamping mode, i.e. with PdfDocument(PdfReader, PdfWriter) constructor
I am trying to check if the user has not entered anything in a TextBox by using the onKeyUp method of KeyUpHandler and chacking if value.length is 0 or not.
When I test it in a browser the condition passes as true but when I test it in Android mobile it doesn't detect whether the TextBox value is 0. Please suggest. I am to new to GWT.
Code:
final E12TextBox newPasswordPwd = new E12TextBox();
newPasswordPwd.addKeyUpHandler(new KeyUpHandler()
{
#Override
public void onKeyUp(KeyUpEvent event)
{
String newPass = newPasswordPwd.getText();
if(newPass.length() != 0 && !newPass.isEmpty())
{
newPassImg.setStyleName("rightPass");
confirmPasswordPwd.setEnabled(true);
}
else
{
newPassImg.setStyleName("wrongPass");
confirmPasswordPwd.setEnabled(false);
}
}
});
You should use getValue() instead of getText(), because getText may return a null value, in which case length() will throw an exception.
I want to cache state in form page when switching from page to page.
So : I have 3 page with forms and I want to data stays in forms when I switch from one to another.
I found this : https://wiki.eclipse.org/Scout/Concepts/Page_Detail_Form
#Override
protected void execPageActivated() throws ProcessingException {
if (getDetailForm() == null) {
PersonDetailForm form = new PersonDetailForm();
form.setPersonNr(getPersonNr());
setDetailForm(form);
form.startView();
}
}
and says that setDetailForm() caches datas
As already said, attaching a detail form to a page means the detail form will automatically be
hidden when the page gets deactivated and shown when the page gets activated (see
PageDetailFormChanged on Desktop). So the detail form actually gets cached and does not need to
be started more than once per page. This requires that the form does not get closed.
But this don't work for me.
My code is
#Override
protected void execPageActivated() throws ProcessingException {
// / Create and open form
if (getDetailForm() == null) {
MarginCalculationForm form = new MarginCalculationForm();
form.startModify();
setDetailForm(form);
}
super.execPageActivated();
}
but it stays on last page.
For example :
If I have page A,B,C and I open page A it create it self and set it to detailForm(). If I then open page B it is OK too. But if I then click on page A again it check if the detailForm() is not null (and it is not) so it stays on page B (insted of going on page A)
EDIT :
I figure that getDetailForm() is returning the right form but apparently super.execPageActivated() don't work.
I found out what was wrong.
Problem is in DefaultPageChangeStrategy class in Scout. Method pageChanged() is like this :
#Override
public void pageChanged(IOutline outline, IPage deselectedPage, IPage selectedPage) {
if (outline == null) {
return;
}
outline.clearContextPage();
IForm detailForm = null;
ITable detailTable = null;
ISearchForm searchForm = null;
// new active page
outline.makeActivePageToContextPage();
IPage activePage = outline.getActivePage();
if (activePage != null) {
try {
activePage.ensureChildrenLoaded();
}
catch (ProcessingException e1) {
SERVICES.getService(IExceptionHandlerService.class).handleException(e1);
}
if (activePage instanceof IPageWithTable) {
IPageWithTable tablePage = (IPageWithTable) activePage;
detailForm = activePage.getDetailForm();
if (activePage.isTableVisible()) {
detailTable = tablePage.getTable();
}
if (tablePage.isSearchActive()) {
searchForm = tablePage.getSearchFormInternal();
}
}
else if (activePage instanceof IPageWithNodes) {
IPageWithNodes nodePage = (IPageWithNodes) activePage;
detailForm = activePage.getDetailForm();
if (activePage.isTableVisible()) {
detailTable = nodePage.getInternalTable();
}
}
}
// remove first
if (detailForm == null) {
outline.setDetailForm(null);
}
if (detailTable == null) {
outline.setDetailTable(null);
}
if (searchForm == null) {
outline.setSearchForm(null);
}
// add new
if (detailForm != null) {
outline.setDetailForm(detailForm);
}
if (detailTable != null) {
outline.setDetailTable(detailTable);
}
if (searchForm != null) {
outline.setSearchForm(searchForm);
}
}
}
And if it is activePage a AbstractPage (and not AbstractPageWithTable AbstractPageWithNode), detailForm is always null and this break behavior.
So solution is to change AbstractPage with AbstractPageWithNode and add line
setTableVisible(false);
This line is needed because if it's not the firs time launch page will not be presented. (nodePage.getInternalTable() is not null but it is empty so :
if (detailTable != null) {
outline.setDetailTable(detailTable);
}
will present empty page.)
I need to create an application that contains multiple widgets. These are not desktop widgets. I need to be able to interact with these widgets as if they were desktop widgets, but they need to be encased inside a larger application. (Each widget has it's own functionality and behavior when clicked.)
Is this possible in android? Or do I need to create an application and create each object that I'd like to behave like a widget actually as a view?
Ex. The parent app is for a car. Example of "in app" widgets are: oil change history (list of last three oil change dates visible, clicking on a date will open a scan of the receipt, etc.), tire pressure monitor, lap speed history (shows last four laps, pinching and expanding will show more than four), etc.
Can I make each of these objects widgets? Or do they have to be views inside the app?
Edit: The Android developer's App Widget Host page mentions: "The AppWidgetHost provides the interaction with the AppWidget service for apps, like the home screen, that want to embed app widgets in their UI."
Has anyone created their own App Widget Host or worked directly with this class?
Create your appwidget normally
Then in your activity add this code
Call selectWidget() to open popup to pick avaible widget
//init
mAppWidgetManager = AppWidgetManager.getInstance(this);
mAppWidgetHost = new AppWidgetHost(this, R.id.APPWIDGET_HOST_ID);
//select widget
void selectWidget() {
int appWidgetId = this.mAppWidgetHost.allocateAppWidgetId();
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
addEmptyData(pickIntent);
startActivityForResult(pickIntent, R.id.REQUEST_PICK_APPWIDGET);
}
void addEmptyData(Intent pickIntent) {
ArrayList customInfo = new ArrayList();
pickIntent.putParcelableArrayListExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
ArrayList customExtras = new ArrayList();
pickIntent.putParcelableArrayListExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras);
};
//Configure the widget
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK ) {
if (requestCode == REQUEST_PICK_APPWIDGET) {
configureWidget(data);
}
else if (requestCode == REQUEST_CREATE_APPWIDGET) {
createWidget(data);
}
}
else if (resultCode == RESULT_CANCELED && data != null) {
int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
if (appWidgetId != -1) {
mAppWidgetHost.deleteAppWidgetId(appWidgetId);
}
}
}
private void configureWidget(Intent data) {
Bundle extras = data.getExtras();
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
if (appWidgetInfo.configure != null) {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
intent.setComponent(appWidgetInfo.configure);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
} else {
createWidget(data);
}
}
//adding it to you view
public void createWidget(Intent data) {
Bundle extras = data.getExtras();
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
AppWidgetHostView hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
hostView.setAppWidget(appWidgetId, appWidgetInfo);
layout.addView(hostView);
}
//Update widget
#Override
protected void onStart() {
super.onStart();
mAppWidgetHost.startListening();
}
#Override
protected void onStop() {
super.onStop();
mAppWidgetHost.stopListening();
}
//Now to remove it call this
public void removeWidget(AppWidgetHostView hostView) {
mAppWidgetHost.deleteAppWidgetId(hostView.getAppWidgetId());
layout.removeView(hostView);
}
Hope this helps
If you want to embed a specific widget in your app, and know the package name and class name:
public boolean createWidget(View view, String packageName, String className) {
// Get the list of installed widgets
AppWidgetProviderInfo newAppWidgetProviderInfo = null;
List<AppWidgetProviderInfo> appWidgetInfos;
appWidgetInfos = mAppWidgetManager.getInstalledProviders();
boolean widgetIsFound = false;
for(int j = 0; j < appWidgetInfos.size(); j++)
{
if (appWidgetInfos.get(j).provider.getPackageName().equals(packageName) && appWidgetInfos.get(j).provider.getClassName().equals(className))
{
// Get the full info of the required widget
newAppWidgetProviderInfo = appWidgetInfos.get(j);
widgetIsFound = true;
break;
}
}
if (!widgetIsFound) {
return false;
} else {
// Create Widget
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
AppWidgetHostView hostView = mAppWidgetHost.createView(getApplicationContext(), appWidgetId, newAppWidgetProviderInfo);
hostView.setAppWidget(appWidgetId, newAppWidgetProviderInfo);
// Add it to your layout
LinearLayout widgetLayout = view.findViewById(R.id.widget_view);
widgetLayout.addView(hostView);
// And bind widget IDs to make them actually work
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
boolean allowed = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, newAppWidgetProviderInfo.provider);
if (!allowed) {
// Request permission - https://stackoverflow.com/a/44351320/1816603
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, newAppWidgetProviderInfo.provider);
final int REQUEST_BIND_WIDGET = 1987;
startActivityForResult(intent, REQUEST_BIND_WIDGET);
}
}
return true;
}
}
I am creating a facebook application with the help of Facebook graph API in Actionscript3. For some weird reason 2 days ago Facebook.addJSEventListener decided not to call the callback function anymore.
Here is my code:
static public function ConnectToApp(sAppID_:String , sPermissions_:String, sRedirectURL_:String):void
{
sAppID = sAppID_;
sPermissions = sPermissions_;
sRedirectURL = sRedirectURL_;
Facebook.init(sAppID, loginHandler);
}
static private function loginHandler(objectSession_:Object,objectFail_:Object):void
{
if( objectSession_ == null)
{
ExternalInterface.call("redirect",sAppID, sPermissions,sRedirectURL);
}
Facebook.addJSEventListener('auth.statusChange', detectLogin);
}
static private function detectLogin(userInfo_:Object):void
{
if (userInfo_.status == "connected")
{
iUserStatus = Globals.FB_USER_CONNECTED;
iUserID = userInfo_.authResponse.userID;
Facebook.api('/me' ,getMeHandler);
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
sProfilePicURL = Facebook.getImageUrl(iUserID.toString());
loadMyPicture();
}
else if (userInfo_.status == "not_authorized")
{
iUserStatus = Globals.FB_USER_NOT_AUTHORIZED;
}
else
{
iUserStatus = Globals.FB_USER_NOT_CONNECTED;
}
}
Facebook.init is calling the loginHandler callback function but Facebook.addJSEventListener('auth.statusChange', detectLogin); decides not to.
Thank you in advance for all the help.
I was able to get it to work. I did the following code change:
static public function ConnectToApp(sAppID_:String , sPermissions_:String, sRedirectURL_:String):void
{
sAppID = sAppID_;
sPermissions = sPermissions_;
sRedirectURL = sRedirectURL_;
Facebook.init(sAppID, loginHandler);
}
static private function loginHandler(objectSession_:Object,objectFail_:Object):void
{
if( objectSession_ == null)
{
ExternalInterface.call("redirect",sAppID, sPermissions,sRedirectURL);
return;
}
GetAllInfo();
}
static private function GetAllInfo():void
{
iUserStatus = Globals.FB_USER_CONNECTED;
iUserID = int(Facebook.getAuthResponse().uid);
Facebook.api('/me' ,getMeHandler);
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
sProfilePicURL = Facebook.getImageUrl(iUserID.toString());
loadMyPicture();
}
So basically now I'm not adding an event listener that calls a callback function when the user is connected, if the session is not ready I redirect and return... when the session is ready I automatically start getting the information.
I am not sure if I will ever get a problem where I start asking for the info before fully logging in but so far I did a lot of tests and it seems to work.
If anyone has a better solution please let me know.