Skip to content

Commit

Permalink
Merge pull request #75 from adjust/context_application
Browse files Browse the repository at this point in the history
Context application
  • Loading branch information
nonelse committed Oct 8, 2014
2 parents 02c700d + 7991608 commit c94d15a
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Adjust/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
defaultConfig {
versionCode 11
versionName '3.6.0'
versionName '3.6.1'
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
Expand Down
58 changes: 53 additions & 5 deletions Adjust/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>adjust-android</artifactId>
<groupId>com.adjust.sdk</groupId>
<version>3.6.0</version>
<version>3.6.1</version>
<packaging>jar</packaging>
<name>Adjust Android SDK</name>
<url>https://github.com/adjust/android_sdk</url>
Expand Down Expand Up @@ -42,6 +42,16 @@
<scope>provided</scope>
</dependency>
</dependencies>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
Expand All @@ -57,23 +67,23 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2</version>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadoc</id>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
Expand All @@ -91,6 +101,44 @@
</sdk>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.2</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
</project>
14 changes: 7 additions & 7 deletions Adjust/src/com/adjust/sdk/ActivityHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ public class ActivityHandler extends HandlerThread {
private String clientSdk;
private Map<String,String> pluginKeys;

public ActivityHandler(Activity activity) {
public ActivityHandler(Context context) {
super(LOGTAG, MIN_PRIORITY);

initActivityHandler(activity);
initActivityHandler(context);

Message message = Message.obtain();
message.arg1 = SessionHandler.INIT_BUNDLE;
sessionHandler.sendMessage(message);
}

public ActivityHandler(Activity activity, String appToken,
public ActivityHandler(Context context, String appToken,
String environment, String logLevel, boolean eventBuffering) {
super(LOGTAG, MIN_PRIORITY);

initActivityHandler(activity);
initActivityHandler(context);

this.environment = environment;
this.eventBuffering = eventBuffering;
Expand All @@ -101,17 +101,17 @@ public ActivityHandler(Activity activity, String appToken,
sessionHandler.sendMessage(message);
}

private void initActivityHandler(Activity activity) {
private void initActivityHandler(Context context) {
setDaemon(true);
start();

TIMER_INTERVAL = AdjustFactory.getTimerInterval();
SESSION_INTERVAL = AdjustFactory.getSessionInterval();
SUBSESSION_INTERVAL = AdjustFactory.getSubsessionInterval();
sessionHandler = new SessionHandler(getLooper(), this);
context = activity.getApplicationContext();
this.context = context.getApplicationContext();
clientSdk = Constants.CLIENT_SDK;
pluginKeys = Util.getPluginKeys(context);
pluginKeys = Util.getPluginKeys(this.context);
enabled = true;

logger = AdjustFactory.getLogger();
Expand Down
45 changes: 19 additions & 26 deletions Adjust/src/com/adjust/sdk/Adjust.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

package com.adjust.sdk;

import static com.adjust.sdk.Constants.NO_ACTIVITY_HANDLER_FOUND;
import android.content.Context;
import android.net.Uri;

import java.util.Map;

import android.app.Activity;
import android.net.Uri;
import static com.adjust.sdk.Constants.NO_ACTIVITY_HANDLER_FOUND;

/**
* The main interface to Adjust.
Expand All @@ -30,13 +30,12 @@ public class Adjust {
* This is used to initialize Adjust and keep track of the current session state.
* Call this in the onResume method of every activity of your app.
*
* @param activity The activity that has just resumed.
* @param context The context of the activity that has just resumed.
*/
public static void onResume(Activity activity) {
public static void onResume(Context context) {
if (null == activityHandler) {
activityHandler = new ActivityHandler(activity);
activityHandler = new ActivityHandler(context);
}
logger = AdjustFactory.getLogger();
activityHandler.trackSubsessionStart();
}

Expand All @@ -48,20 +47,18 @@ public static void onResume(Activity activity) {
*/
public static void onPause() {
try {
logger.debug("onPause");
getLogger().debug("onPause");
activityHandler.trackSubsessionEnd();
} catch (NullPointerException e) {
if(logger != null)
logger.error(NO_ACTIVITY_HANDLER_FOUND);
getLogger().error(NO_ACTIVITY_HANDLER_FOUND);
}
}

public static void setOnFinishedListener(OnFinishedListener listener) {
try {
activityHandler.setOnFinishedListener(listener);
} catch (NullPointerException e) {
if(logger != null)
logger.error(NO_ACTIVITY_HANDLER_FOUND);
getLogger().error(NO_ACTIVITY_HANDLER_FOUND);
}
}

Expand All @@ -86,8 +83,7 @@ public static void trackEvent(String eventToken, Map<String, String> parameters)
try {
activityHandler.trackEvent(eventToken, parameters);
} catch (NullPointerException e) {
if(logger != null)
logger.error(NO_ACTIVITY_HANDLER_FOUND);
getLogger().error(NO_ACTIVITY_HANDLER_FOUND);
}
}

Expand Down Expand Up @@ -117,8 +113,7 @@ public static void trackRevenue(double amountInCents, String eventToken, Map<Str
try {
activityHandler.trackRevenue(amountInCents, eventToken, parameters);
} catch (NullPointerException e) {
if(logger != null)
logger.error(NO_ACTIVITY_HANDLER_FOUND);
getLogger().error(NO_ACTIVITY_HANDLER_FOUND);
}
}

Expand All @@ -131,8 +126,7 @@ public static void setEnabled(Boolean enabled) {
try {
activityHandler.setEnabled(enabled);
} catch (NullPointerException e) {
if (logger != null)
logger.error(NO_ACTIVITY_HANDLER_FOUND);
getLogger().error(NO_ACTIVITY_HANDLER_FOUND);
}
}

Expand All @@ -143,8 +137,7 @@ public static Boolean isEnabled() {
try {
return activityHandler.isEnabled();
} catch (NullPointerException e) {
if (logger != null)
logger.error(NO_ACTIVITY_HANDLER_FOUND);
getLogger().error(NO_ACTIVITY_HANDLER_FOUND);
}
return false;
}
Expand All @@ -153,16 +146,15 @@ public static void appWillOpenUrl(Uri url) {
try {
activityHandler.readOpenUrl(url);
} catch (NullPointerException e) {
if (logger != null)
logger.error(NO_ACTIVITY_HANDLER_FOUND);
getLogger().error(NO_ACTIVITY_HANDLER_FOUND);
}

}


// Special appDidLaunch method used by SDK wrappers such as our Adobe Air SDK.
public static void appDidLaunch(Activity activity, String appToken, String environment, String logLevel, boolean eventBuffering) {
activityHandler = new ActivityHandler(activity, appToken, environment, logLevel, eventBuffering);
public static void appDidLaunch(Context context, String appToken, String environment, String logLevel, boolean eventBuffering) {
activityHandler = new ActivityHandler(context, appToken, environment, logLevel, eventBuffering);
}

// Special method used by SDK wrappers such as our Adobe Air SDK.
Expand All @@ -174,6 +166,7 @@ public static void setSdkPrefix(String sdkPrefix) {
* Every activity will get forwarded to this handler to be processed in the background.
*/
private static ActivityHandler activityHandler;
private static Logger logger;

private static Logger getLogger() {
return AdjustFactory.getLogger();
};
}
2 changes: 1 addition & 1 deletion Adjust/src/com/adjust/sdk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface Constants {
int THIRTY_MINUTES = 30 * ONE_MINUTE;

String BASE_URL = "https://app.adjust.io";
String CLIENT_SDK = "android3.6.0";
String CLIENT_SDK = "android3.6.1";
String LOGTAG = "Adjust";

String SESSION_STATE_FILENAME = "AdjustIoActivityState";
Expand Down
4 changes: 2 additions & 2 deletions Adjust/src/com/adjust/sdk/Reflection.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static String getPlayAdId(Context context) {
}
}

public static boolean isPlayTrackingEnabled(Context context) {
public static Boolean isPlayTrackingEnabled(Context context) {
try {
Object AdvertisingInfoObject = getAdvertisingInfoObject(context);

Expand All @@ -30,7 +30,7 @@ public static boolean isPlayTrackingEnabled(Context context) {
return !isLimitedTrackingEnabled;
}
catch (Throwable t) {
return false;
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void testFirstSession() {

// check the Sdk version is being tested
assertEquals(activityPackage.getExtendedString(),
"android3.6.0", activityPackage.getClientSdk());
"android3.6.1", activityPackage.getClientSdk());

// check the server url
assertEquals(Constants.BASE_URL, "https://app.adjust.io");
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.6.0
3.6.1
6 changes: 3 additions & 3 deletions doc/migrate.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Migrate your adjust SDK for Android to 3.6.0 from v2.1.x
## Migrate your adjust SDK for Android to 3.6.1 from v2.1.x

We renamed the main class `com.adeven.adjustio.AdjustIo` to
`com.adjust.sdk.Adjust`. Follow these steps to update all adjust SDK calls.
Expand All @@ -24,7 +24,7 @@ We renamed the main class `com.adeven.adjustio.AdjustIo` to
4. In the same fashion, replace `adeven.adjustio` with `adjust.sdk` in all
manifest files to update the package name of the `ReferrerReceiver`.

5. Download version v3.6.0 and create a new Android project from the `Adjust` folder.
5. Download version v3.6.1 and create a new Android project from the `Adjust` folder.

![][import]

Expand All @@ -36,7 +36,7 @@ We renamed the main class `com.adeven.adjustio.AdjustIo` to

8. Build your project to confirm that everything is properly connected again.

The adjust SDK v3.6.0 added delegate notifications. Check out the [README] for
The adjust SDK v3.6.1 added delegate notifications. Check out the [README] for
details.


Expand Down

0 comments on commit c94d15a

Please sign in to comment.