Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-7249 Give access to getAction and getType in IntentProxy, plus exp... #2114

Merged
merged 2 commits into from
May 2, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public IntentProxy createIntent(Object[] args)
public IntentProxy createServiceIntent(Object[] args)
{
IntentProxy intent = new IntentProxy();
intent.setType(IntentProxy.TYPE_SERVICE);
intent.setInternalType(IntentProxy.TYPE_SERVICE);
intent.handleCreationArgs(this, args);
Object startMode = intent.getProperty(TiC.INTENT_PROPERTY_START_MODE);
if (startMode != null) {
Expand All @@ -266,7 +266,7 @@ public IntentProxy createServiceIntent(Object[] args)
public IntentProxy createBroadcastIntent(Object[] args)
{
IntentProxy intent = new IntentProxy();
intent.setType(IntentProxy.TYPE_BROADCAST);
intent.setInternalType(IntentProxy.TYPE_BROADCAST);
intent.handleCreationArgs(this, args);
return intent;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand Down Expand Up @@ -66,7 +66,7 @@ public void handleCreationArgs(KrollModule createdInModule, Object[] args)
if (pendingIntentContext == null || intent == null) {
throw new IllegalStateException("Creation arguments must contain intent");
}
switch (intent.getType()) {
switch (intent.getInternalType()) {
case IntentProxy.TYPE_ACTIVITY : {
pendingIntent = PendingIntent.getActivity(
pendingIntentContext, 0, intent.getIntent(), flags);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
package org.appcelerator.titanium.proxy;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiConfig;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBlob;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.TiBlob;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.content.ContentResolver;

@Kroll.proxy(propertyAccessors = {
TiC.PROPERTY_ACTION,
TiC.PROPERTY_CLASS_NAME,
TiC.PROPERTY_PACKAGE_NAME,
TiC.PROPERTY_TYPE,
TiC.PROPERTY_URL
})
/**
Expand Down Expand Up @@ -249,7 +246,26 @@ public void addCategory(String category)
@Kroll.method
public String getStringExtra(String name)
{
return intent.getStringExtra(name);
if (!intent.hasExtra(name)) {
return null;
}

String result = intent.getStringExtra(name);
if (result == null) {
// One more try as parcelable extra, such as when it's a Uri.
// We can't really support getParcelableExtra(name) by itself,
// since the type of object coming out of it is unknown and
// might not make its way successfully over to Javascript.
// By getting it as a string, we at least allow people to grab
// Uris (Intent.STREAM) stored as parcelable extras, which is a
// very common use case.
Object parcelable = intent.getParcelableExtra(name);
if (parcelable != null) {
result = parcelable.toString();
}
}

return result;
}

@Kroll.method
Expand Down Expand Up @@ -313,23 +329,47 @@ public Intent getIntent()
return intent;
}

@Kroll.method @Kroll.getProperty
public String getType()
{
return intent.getType();
}

@Kroll.method @Kroll.setProperty
public void setType(String type)
{
intent.setType(type);
}

@Kroll.method @Kroll.getProperty
public String getAction()
{
return intent.getAction();
}

@Kroll.method @Kroll.setProperty
public void setAction(String action)
{
intent.setAction(action);
}

/**
* @return intent type.
* @return intent type for internal purposes (TYPE_ACTIVITY, etc.)
*/
public int getType()
public int getInternalType()
{
return type;
}

/**
* Sets the intent type.
* @param type the intent type to set.
* @param type the intent type for internal purposes (TYPE_ACTIVITY etc.)
*/
public void setType(int type)
public void setInternalType(int type)
{
this.type = type;
}

@Kroll.method
public boolean hasExtra(String name)
{
Expand Down
1 change: 1 addition & 0 deletions apidoc/Titanium/Android/Intent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ methods:

- name: getStringExtra
summary: Get a string property from this Intent.
description: Can also be used to get the string representation of a [parcelable extra](http://developer.android.com/reference/android/content/Intent.html#getParcelableExtra(java.lang.String)), which is useful since we do not support `getParcelableExtra` due to the inability to translate all of its possible return types to Javascript.
returns:
type: String
parameters:
Expand Down