提交 e66b9a67 编写于 作者: E Eric Frohnhoefer

Remove Unity wrapper from Twitter Kit repo

Change-Id: I911f510cefd2b8b514134540871bca5cdf9508b0
上级 4960bdaf
......@@ -25,7 +25,6 @@ subprojects { Project subproject ->
}
dependencies {
classpath dependency.androidGradlePlugin
classpath 'io.fabric.gradle.unity:unity:0.0.1'
}
}
......
......@@ -20,5 +20,4 @@ include ':tweet-composer'
include ':tweet-ui'
include ':twitter-mopub'
include ':twitter'
include ':twitter-unity'
include ':samples:app'
\ No newline at end of file
/*
* Copyright (C) 2015 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
apply plugin: 'com.android.library'
apply plugin: 'io.fabric.gradle.unity'
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
versionCode 1
versionName version
minSdkVersion rootProject.minSdkVersion
consumerProguardFiles 'proguard.txt'
}
buildTypes {
debug {
buildConfigField "String", "GROUP", "\"${pom_group_id}\""
buildConfigField "String", "ARTIFACT_ID", "\"${pom_artifact_id}\""
buildConfigField "String", "BUILD_NUMBER", "\"${buildNumber}\""
buildConfigField "long", "BUILD_TIME", "${System.currentTimeMillis()}L"
testCoverageEnabled enableTestCodeCoverage
}
release {
buildConfigField "String", "GROUP", "\"${pom_group_id}\""
buildConfigField "String", "ARTIFACT_ID", "\"${pom_artifact_id}\""
buildConfigField "String", "BUILD_NUMBER", "\"${buildNumber}\""
buildConfigField "long", "BUILD_TIME", "${System.currentTimeMillis()}L"
}
}
lintOptions {
warningsAsErrors true
}
compileOptions {
sourceCompatibility rootProject.sourceCompatibilityVersion
targetCompatibility rootProject.targetCompatibilityVersion
}
// Forcibly add debug and the generated "R" files onto the test classpath
sourceSets {
test.java.srcDirs += "build/generated/source/r/debug"
test.java.srcDirs += "src/debug"
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
provided fileTree(dir: 'libs', include: ['unity.jar'])
compile project(':twitter-core')
compile project(':tweet-composer')
}
\ No newline at end of file
# Twitter Unity Android SDK changelog
*Non-trivial pull requests should include an entry below. Entries must be suitable for inclusion in public-facing materials such as release notes and blog posts. Keep them short, sweet, and in the past tense. New entries go on top. When merging to deploy, add the version number and date.*
## Unreleased
## v3.0.0
## v0.1.0
* Added support for "Login with Twitter".
* Added support for request email.
* Added support for composer with app install card.
#
# Copyright (C) 2015 Twitter, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# The to be released version. When releasing, drop -SNAPSHOT. After releasing, bump version
# number and add back -SNAPSHOT
version=3.0.1-SNAPSHOT
version_code=1
pom_name=Twitter Unity Android SDK
pom_group_id=com.twitter.sdk.android
pom_artifact_id=twitter-unity
pom_packaging=aar
/*
* Copyright (C) 2015 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
apply plugin: 'com.android.library'
apply from: rootProject.qualityScript
apply plugin: 'io.fabric.gradle.unity'
apply plugin: io.fabric.gradle.weaving.ArtifactSizePlugin
apply plugin: io.fabric.gradle.weaving.DexMethodCountPlugin
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
versionCode 1
versionName version
group pom_group_id
minSdkVersion rootProject.minSdkVersion
consumerProguardFiles 'proguard.txt'
}
buildTypes {
debug {
buildConfigField "String", "GROUP", "\"${pom_group_id}\""
buildConfigField "String", "ARTIFACT_ID", "\"${pom_artifact_id}\""
buildConfigField "String", "BUILD_NUMBER", "\"${buildNumber}\""
buildConfigField "long", "BUILD_TIME", "${System.currentTimeMillis()}L"
testCoverageEnabled enableTestCodeCoverage
}
release {
buildConfigField "String", "GROUP", "\"${pom_group_id}\""
buildConfigField "String", "ARTIFACT_ID", "\"${pom_artifact_id}\""
buildConfigField "String", "BUILD_NUMBER", "\"${buildNumber}\""
buildConfigField "long", "BUILD_TIME", "${System.currentTimeMillis()}L"
}
}
lintOptions {
warningsAsErrors true
}
dexMethodCount {
packageFilter = "com.twitter.sdk.android.unity"
}
//Gradle publishes only release by default for multi module projects
//This will publish all build variants and we can specifically choose them
defaultPublishConfig 'release'
publishNonDefault true
compileOptions {
sourceCompatibility rootProject.sourceCompatibilityVersion
targetCompatibility rootProject.targetCompatibilityVersion
}
testOptions {
unitTests.returnDefaultValues = true
}
}
ext.projectDependencies = [
':sdk:twitter:twitter-core' : 'com.twitter.sdk.android:twitter-core:+@aar',
':sdk:twitter:tweet-composer' : 'com.twitter.sdk.android:tweet-composer:+@aar'
]
dependencies {
provided fileTree(dir: 'libs', include: ['unity.jar'])
projectDependencies.each { path, binary ->
debugCompile project(path: path, configuration: 'debug')
releaseCompile projectOrBinary(path: path, configuration: 'release', binary: binary)
}
}
apply from: rootProject.deployScript
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2015 Twitter, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<lint>
<issue id="InvalidPackage" severity="ignore"/>
</lint>
\ No newline at end of file
# Proguard config for JNI helper
-keep class com.twitter.sdk.android.unity.TwitterKit { *; }
<!--
~ Copyright (C) 2015 Twitter, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twitter.sdk.android.unity">
<application>
<activity android:name="com.twitter.sdk.android.unity.LoginActivity"/>
</application>
</manifest>
\ No newline at end of file
/*
* Copyright (C) 2015 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.twitter.sdk.android.core;
/**
* Helper for serializing/deserializing TwitterSession class
*/
public class TwitterSessionHelper {
public static String serialize(TwitterSession session) {
final TwitterSession.Serializer serializer = new TwitterSession.Serializer();
return serializer.serialize(session);
}
public static TwitterSession deserialize(String session) {
final TwitterSession.Serializer serializer = new TwitterSession.Serializer();
return serializer.deserialize(session);
}
}
/*
* Copyright (C) 2015 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.twitter.sdk.android.unity;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.twitter.sdk.android.core.Twitter;
import com.twitter.sdk.android.core.TwitterCore;
import com.twitter.sdk.android.core.internal.persistence.SerializationStrategy;
class ApiError {
public final int code;
public final String message;
ApiError(int code, String message) {
this.code = code;
this.message = message;
}
static class Serializer implements SerializationStrategy<ApiError> {
private final Gson gson;
public Serializer() {
this.gson = new Gson();
}
@Override
public String serialize(ApiError error) {
try {
return gson.toJson(error);
} catch (Exception e) {
Twitter.getLogger().d(TwitterCore.TAG, e.getMessage());
}
return "";
}
@Override
public ApiError deserialize(String serializedSession) {
if (!TextUtils.isEmpty(serializedSession)) {
try {
return gson.fromJson(serializedSession, ApiError.class);
} catch (Exception e) {
Twitter.getLogger().d(TwitterCore.TAG, e.getMessage());
}
}
return null;
}
}
}
/*
* Copyright (C) 2015 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.twitter.sdk.android.unity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.TwitterSession;
import com.twitter.sdk.android.core.TwitterSessionHelper;
import com.twitter.sdk.android.core.identity.TwitterAuthClient;
/**
* Activity used to launch Twitter login, receive the result, and publish result to Unity.
*/
public class LoginActivity extends Activity {
TwitterAuthClient authClient;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
authClient = new TwitterAuthClient();
authClient.authorize(this, new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
final String session = TwitterSessionHelper.serialize(result.data);
final UnityMessage message = new UnityMessage.Builder()
.setMethod("LoginComplete")
.setData(session)
.build();
message.send();
finish();
}
@Override
public void failure(TwitterException ex) {
final String error = new ApiError.Serializer()
.serialize(new ApiError(0, ex.getMessage()));
final UnityMessage message = new UnityMessage.Builder()
.setMethod("LoginFailed")
.setData(error)
.build();
message.send();
finish();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
authClient.onActivityResult(requestCode, resultCode, data);
}
}
/*
* Copyright (C) 2015 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.twitter.sdk.android.unity;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.Twitter;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterConfig;
import com.twitter.sdk.android.core.TwitterCore;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.TwitterSession;
import com.twitter.sdk.android.core.TwitterSessionHelper;
import com.twitter.sdk.android.core.identity.TwitterAuthClient;
import com.twitter.sdk.android.tweetcomposer.ComposerActivity;
import com.unity3d.player.UnityPlayer;
/**
* A class to expose TwitterKit methods for Unity
*/
public class TwitterKit {
public static final String GAME_OBJECT_NAME = "TwitterGameObject";
/**
* Initializes TwitterKit, must be called before {@link #login}
* @param consumerKey Twitter App Consumer Key (API Key)
* @param consumerSecret Twitter App Consumer Secret (API Secret)
*/
public static void init(final String consumerKey, final String consumerSecret) {
final TwitterConfig config = new TwitterConfig.Builder(
UnityPlayer.currentActivity.getApplicationContext())
.twitterAuthConfig(new TwitterAuthConfig(consumerKey, consumerSecret))
.build();
Twitter.initialize(config);
}
/**
* Convenience method for launching Twitter login using JNI.
*/
public static void login() {
final Activity currentActivity = UnityPlayer.currentActivity;
final Intent intent = new Intent(currentActivity, LoginActivity.class);
currentActivity.startActivity(intent);
}
/**
* Convenience method for logging out active user using JNI.
*/
public static void logout() {
TwitterCore.getInstance().getSessionManager().clearActiveSession();
}
/**
* Convenience method for retrieving active user using JNI.
*/
public static String session() {
final TwitterSession session = TwitterCore.getInstance().getSessionManager()
.getActiveSession();
return TwitterSessionHelper.serialize(session);
}
/**
* Convenience method for starting Tweet composer with app card preview.
*
* @param session the user session
* @param imageUri URI of the image
* @param text the text to be included in the tweet
* @param hashtags the hashtags to be included in the tweet
*/
public static void compose(String session, String imageUri, String text, String[] hashtags) {
final Activity currentActivity = UnityPlayer.currentActivity;
final Intent intent = new ComposerActivity.Builder(currentActivity)
.session(TwitterSessionHelper.deserialize(session))
.image(imageUri != null ? Uri.parse(imageUri) : null)
.text(text)
.hashtags(hashtags)
.createIntent();
currentActivity.startActivity(intent);
}
/**
* Convenience method for requesting users email address using JNI.
*
* @param session the user session
*/
public static void requestEmail(String session) {
final TwitterSession twitterSession = TwitterSessionHelper.deserialize(session);
new TwitterAuthClient().requestEmail(twitterSession, new Callback<String>() {
@Override
public void success(Result<String> result) {
final UnityMessage message = new UnityMessage.Builder()
.setMethod("RequestEmailComplete")
.setData(result.data)
.build();
message.send();
}
@Override
public void failure(TwitterException exception) {
final String error = new ApiError.Serializer()
.serialize(new ApiError(0, exception.getMessage()));
final UnityMessage message = new UnityMessage.Builder()
.setMethod("RequestEmailFailed")
.setData(error)
.build();
message.send();
}
});
}
}
/*
* Copyright (C) 2015 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.twitter.sdk.android.unity;
import com.unity3d.player.UnityPlayer;
class UnityMessage {
final String data;
final String method;
UnityMessage(String method, String data) {
this.method = method;
this.data = data;
}
public static class Builder {
String data = "";
String method;
public Builder setData(String data) {
this.data = data;
return this;
}
public Builder setMethod(String method) {