<commit_before>/****************************************************************************
Copyright (c) 2008-2010 <NAME>
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011      Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
 
http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
 ****************************************************************************/
package org.cocos2dx.cpp;

import org.cocos2dx.lib.Cocos2dxActivity;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.umeng.social.CCUMSocialController;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

public class AppActivity extends Cocos2dxActivity {

	private AdView mAdView;
	private WindowManager mWm = null;

	public static final int POS_CENTER = 0;
	public static final int POS_TOP = 1;
	public static final int POS_TOP_LEFT = 2;
	public static final int POS_TOP_RIGHT = 3;
	public static final int POS_BOTTOM = 4;
	public static final int POS_BOTTOM_LEFT = 5;
	public static final int POS_BOTTOM_RIGHT = 6;

	public static void addAdView(WindowManager mWm, View adView, int pos) {
		WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams();
		mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
		mLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
		mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
		mLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

		switch (pos) {
		case POS_CENTER:
			mLayoutParams.gravity = Gravity.CENTER;
			break;
		case POS_TOP:
			mLayoutParams.gravity = Gravity.TOP;
			break;
		case POS_TOP_LEFT:
			mLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
			break;
		case POS_TOP_RIGHT:
			mLayoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
			break;
		case POS_BOTTOM:
			mLayoutParams.gravity = Gravity.BOTTOM;
			break;
		case POS_BOTTOM_LEFT:
			mLayoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
			break;
		case POS_BOTTOM_RIGHT:
			mLayoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
			break;
		default:
			break;
		}
		mWm.addView(adView, mLayoutParams);
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// In the main Activity, assigning that activity as a receiver for C++
		// messages
		AndroidNDKHelper.SetNDKReciever(this);

		mAdView = new AdView(this);
		mAdView.setAdSize(AdSize.BANNER);
		mAdView.setAdUnitId("a153a14e5305ecd");

		// Create an ad request.
		AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
		// Optionally populate the ad request builder.
		adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
		// Start loading the ad.
		mAdView.loadAd(adRequestBuilder.build());
		
		CCUMSocialController.initSocialSDK(this, "com.umeng.social.share");
		
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		CCUMSocialController.onActivityResult(requestCode, resultCode, data); 
		super.onActivityResult(requestCode, resultCode, data);
	}

	public void setAd(JSONObject prms) {
		String setad = null;
		try {
			setad = prms.getString("setAd");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (setad.equals("1")) {
			// showadd
			if (null == mWm) {
				mWm = (WindowManager) this.getSystemService("window");
			}
			addAdView(mWm, mAdView, POS_TOP);
		} else {
			// hidadd
			if (null != mWm) {
				mWm.removeView(mAdView);
			}
		}
	}
	
	public void leaderBoardControl(JSONObject param){
		if (param.has("value")) {
			try {
				int value = param.getInt("value");
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}else{
		}
	}<commit_msg>add leader board for android.<commit_after>/****************************************************************************
Copyright (c) 2008-2010 <NAME>
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011      Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
 
http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
 ****************************************************************************/
package org.cocos2dx.cpp;

import org.cocos2dx.lib.Cocos2dxActivity;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Game;
import com.google.android.gms.games.Games;
import com.google.android.gms.plus.Plus;
import com.umeng.social.CCUMSocialController;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

public class AppActivity extends Cocos2dxActivity {

	private AdView mAdView;
	private GoogleApiClient mClient;
	private WindowManager mWm = null;

	public static final int POS_CENTER = 0;
	public static final int POS_TOP = 1;
	public static final int POS_TOP_LEFT = 2;
	public static final int POS_TOP_RIGHT = 3;
	public static final int POS_BOTTOM = 4;
	public static final int POS_BOTTOM_LEFT = 5;
	public static final int POS_BOTTOM_RIGHT = 6;

	public static void addAdView(WindowManager mWm, View adView, int pos) {
		WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams();
		mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
		mLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
		mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
		mLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

		switch (pos) {
		case POS_CENTER:
			mLayoutParams.gravity = Gravity.CENTER;
			break;
		case POS_TOP:
			mLayoutParams.gravity = Gravity.TOP;
			break;
		case POS_TOP_LEFT:
			mLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
			break;
		case POS_TOP_RIGHT:
			mLayoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
			break;
		case POS_BOTTOM:
			mLayoutParams.gravity = Gravity.BOTTOM;
			break;
		case POS_BOTTOM_LEFT:
			mLayoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
			break;
		case POS_BOTTOM_RIGHT:
			mLayoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
			break;
		default:
			break;
		}
		mWm.addView(adView, mLayoutParams);
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// In the main Activity, assigning that activity as a receiver for C++
		// messages
		AndroidNDKHelper.SetNDKReciever(this);

		mAdView = new AdView(this);
		mAdView.setAdSize(AdSize.BANNER);
		mAdView.setAdUnitId("a153a14e5305ecd");

		// Create an ad request.
		AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
		// Optionally populate the ad request builder.
		adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
		// Start loading the ad.
		mAdView.loadAd(adRequestBuilder.build());
		
		CCUMSocialController.initSocialSDK(this, "com.umeng.social.share");
		mClient = new GoogleApiClient.Builder(this)
        .addApi(Plus.API)
        .addScope(Plus.SCOPE_PLUS_LOGIN)
        .setAccountName("<EMAIL>")
        .build();
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		mClient.connect();
	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		mClient.disconnect();
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		CCUMSocialController.onActivityResult(requestCode, resultCode, data); 
		super.onActivityResult(requestCode, resultCode, data);
	}

	public void setAd(JSONObject prms) {
		String setad = null;
		try {
			setad = prms.getString("setAd");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (setad.equals("1")) {
			// showadd
			if (null == mWm) {
				mWm = (WindowManager) this.getSystemService("window");
			}
			addAdView(mWm, mAdView, POS_TOP);
		} else {
			// hidadd
			if (null != mWm) {
				mWm.removeView(mAdView);
			}
		}
	}
	
	private static String mLeaderBoardId = "";
	private static final int REQUEST_LEADERBOARD = 624;
	
	public void leaderBoardControl(JSONObject param){
		if (param.has("value")) {
			try {
				int value = param.getInt("value");
				Games.Leaderboards.submitScore(mClient, mLeaderBoardId, value);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}else{
			startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mClient,
			        mLeaderBoardId), REQUEST_LEADERBOARD);
		}
	}
{'fraction_non_alphanumeric': 0.11477814448111477, 'fraction_numerical': 0.009625962596259627, 'mean_word_length': 4.438185443668993, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4933591', 'n_tokens_mistral': 3808, 'n_tokens_neox': 3322, 'n_words': 956}