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 6101: Android: Contacts: Rhino/v8, get image from picker does not display an image #778

Merged
merged 13 commits into from
Nov 30, 2011
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 @@ -62,7 +62,7 @@ protected static CommonContactsApi getInstance(TiContext tiContext)
protected static Bitmap getContactImage(long contact_id)
{
CommonContactsApi api = getInstance();
return api.getContactImage(contact_id);
return api.getInternalContactImage(contact_id);
}

protected static Bitmap getContactImage(TiContext context, long contact_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiContext;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Intent;
Expand Down Expand Up @@ -137,6 +138,18 @@ private PersonProxy[] getPeople(int limit, String additionalCondition, String[]
Log.d(LCAT , "Could not getPeople, context is GC'd");
return null;
}*/

if (TiApplication.getInstance() == null) {
Log.e(LCAT, "Could not getPeople, application is null");
return null;
}

Activity activity = TiApplication.getInstance().getRootOrCurrentActivity();
if (activity == null) {
Log.e(LCAT, "Could not getPeople, activity is null");
return null;
}

LinkedHashMap<Long, CommonContactsApi.LightPerson> persons = new LinkedHashMap<Long, LightPerson>();

String condition = "mimetype IN " + INConditionForKinds +
Expand All @@ -146,7 +159,7 @@ private PersonProxy[] getPeople(int limit, String additionalCondition, String[]
condition += " AND " + additionalCondition;
}

Cursor cursor = TiApplication.getInstance().getCurrentActivity().managedQuery(
Cursor cursor = activity.managedQuery(
DataUri,
DATA_PROJECTION,
condition,
Expand Down Expand Up @@ -194,10 +207,21 @@ protected PersonProxy getPersonById(long id)
}
*/

if (TiApplication.getInstance() == null) {
Log.e(LCAT, "Could not getPersonById, application is null");
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A space between this if block and the following statements below it.


Activity activity = TiApplication.getInstance().getRootOrCurrentActivity();
if (activity == null) {
Log.e(LCAT, "Could not getPersonById, activity is null");
return null;
}

CommonContactsApi.LightPerson person = null;

// Basic person data.
Cursor cursor = TiApplication.getInstance().getCurrentActivity().managedQuery(
Cursor cursor = activity.managedQuery(
ContentUris.withAppendedId(ContactsUri, id),
PEOPLE_PROJECTION, null, null, null);

Expand All @@ -216,7 +240,7 @@ protected PersonProxy getPersonById(long id)
String condition = "mimetype IN " + INConditionForKinds +
" AND contact_id = ?";

cursor = TiApplication.getInstance().getCurrentActivity().managedQuery(
cursor = activity.managedQuery(
DataUri,
DATA_PROJECTION,
condition,
Expand Down Expand Up @@ -247,8 +271,14 @@ protected Bitmap getInternalContactImage(long id)
return null;
}
*/

if (TiApplication.getInstance() == null) {
Log.e(LCAT, "Could not getInternalContactImage, application is null");
return null;
}

Uri uri = ContentUris.withAppendedId(ContactsUri, id);
ContentResolver cr = TiApplication.getInstance().getCurrentActivity().getContentResolver();
ContentResolver cr = TiApplication.getInstance().getContentResolver();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be within the scope of this request, but we might consider adding geContentResolver() as a static method on TiApplication so we can wrap the getInstance() check in a single place much like was done with getRootOrCurrentActivity().

InputStream stream = null;
try {
stream = (InputStream) openContactPhotoInputStream.invoke(null, cr, uri);
Expand All @@ -267,5 +297,4 @@ protected Bitmap getInternalContactImage(long id)
}
return bm;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ public PersonProxy getPersonByID(long id)
@Kroll.method
public void showContacts(@Kroll.argument(optional=true) KrollDict d)
{
Activity launchingActivity = TiApplication.getInstance().getRootActivity();
if (TiApplication.getInstance() == null) {
Log.e(LCAT, "Could not showContacts, application is null");
return;
}

Activity launchingActivity = TiApplication.getInstance().getCurrentActivity();
if (launchingActivity == null) {
Log.e(LCAT, "Could not showContacts, current activity is null.");
return;
}

/*
if (launchingActivity == null) { // Not sure if that's even possible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,19 @@ public Activity getCurrentActivity()

return currentActivity.get();
}

public Activity getRootOrCurrentActivity()
{
if (rootActivity != null) {
return (Activity)(rootActivity.get());
}

if (currentActivity != null) {
return currentActivity.get();
}

return null;
}

public void setCurrentActivity(Activity callingActivity, Activity newValue)
{
Expand Down