Skip to content

Commit

Permalink
TIMOB-6186 fixes and refactor for static utility methods on TiApplica…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Opie Cyrus committed Dec 3, 2011
1 parent fc3b77f commit 40e2a96
Showing 1 changed file with 40 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@ public TiApplication()

public static TiApplication getInstance()
{
if (tiApp == null) {
return null;
if (tiApp != null) {
TiApplication tiAppRef = tiApp.get();
if (tiAppRef != null) {
return tiAppRef;
}
}

return tiApp.get();
Log.e(LCAT, "unable to get the TiApplication instance");
return null;
}

// This is a convenience method to avoid having to check TiApplication.getInstance() is not null every
Expand All @@ -136,16 +140,10 @@ public static Activity getAppCurrentActivity()
{
TiApplication tiApp = getInstance();
if (tiApp == null) {
Log.e(LCAT, "unable to get the TiApplication instance");
return null;
}

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

Log.e(LCAT, "no valid current activity found for application");
return null;
return tiApp.getCurrentActivity();
}

// This is a convenience method to avoid having to check TiApplication.getInstance() is not null every
Expand All @@ -154,20 +152,45 @@ public static Activity getAppRootOrCurrentActivity()
{
TiApplication tiApp = getInstance();
if (tiApp == null) {
Log.e(LCAT, "unable to get the TiApplication instance");
return null;
}

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

public Activity getCurrentActivity()
{
Activity activity;
if (currentActivity != null) {
activity = currentActivity.get();
if (activity != null) {
return activity;
}
}

Log.e(LCAT, "no valid current activity found for application instance");
return null;
}

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

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

Log.e(LCAT, "no valid root or current activity found for application");
return null;
Log.e(LCAT, "no valid root or current activity found for application instance");
return null;
}

protected void loadBuildProperties()
Expand Down Expand Up @@ -327,28 +350,6 @@ public TiRootActivity getRootActivity()
return rootActivity.get();
}

public Activity getCurrentActivity()
{
if (currentActivity == null) {
return null;
}

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)
{
synchronized (this) {
Expand Down

0 comments on commit 40e2a96

Please sign in to comment.