BUILD GRADE compile 'com.unity3d.ads:unity-ads:3.7.+' compile 'cn.pedant.sweetalert:library:1.3' compile 'com.sdsmdg.tastytoast:tastytoast:0.1.1' ////////////////////// ANDROIDMANIESTO //////////////////////////// SOCKSHTTPACTIVITY OR MAINACTIVITY /ads unity import com.unity3d.ads.IUnityAdsInitializationListener; import com.unity3d.ads.IUnityAdsLoadListener; import com.unity3d.ads.IUnityAdsShowListener; import com.unity3d.ads.UnityAds; import com.unity3d.ads.UnityAdsShowOptions; import com.unity3d.services.banners.BannerErrorInfo; import com.unity3d.services.banners.BannerView; import com.unity3d.services.banners.UnityBannerSize; import com.unity3d.ads.IUnityAdsListener; import cn.pedant.SweetAlert.SweetAlertDialog; import android.os.CountDownTimer; import com.jaxtunnel.phtunnel.service.SocksDNSService; import java.util.concurrent.TimeUnit; import java.util.Locale; //end ///////////////////////// public class MainActivity ir SocksHttpActivity IUnityAdsInitializationListener //////////////////////// //private unity ads private String unityGameID = "4087375"; Boolean testMode = true; private String bottomAdUnitId = "Banner_Android"; private String InterstitialadUnitId = "Interstitial_Android"; private String RewardadUnitId = "Rewarded_Android"; private UnityAds interstitialAds; private Button mReward; //end //////////////////// //Under the deprive of unity private BannerView.IListener bannerListener = new BannerView.IListener() { @Override public void onBannerLoaded(BannerView bannerAdView) { // Called when the banner is loaded. Log.v("UnityAdsExample", "onBannerLoaded: " + bannerAdView.getPlacementId()); // Enable the correct button to hide the ad } @Override public void onBannerFailedToLoad( BannerView bannerAdView, BannerErrorInfo errorInfo) { Log.e( "UnityAdsExample", "Unity Ads failed to load banner for " + bannerAdView.getPlacementId() + " with error: [" + errorInfo.errorCode + "] " + errorInfo.errorMessage); // Note that the BannerErrorInfo object can indicate a no fill (see API // documentation). } @Override public void onBannerClick(BannerView bannerAdView) { // Called when a banner is clicked. Log.v("UnityAdsExample", "onBannerClick: " + bannerAdView.getPlacementId()); } @Override public void onBannerLeftApplication(BannerView bannerAdView) { // Called when the banner links out of the application. Log.v( "UnityAdsExample", "onBannerLeftApplication: " + bannerAdView.getPlacementId()); } }; private IUnityAdsLoadListener loadListener =new IUnityAdsLoadListener() { @Override public void onUnityAdsAdLoaded(String placementId) { UnityAds.show(MainActivity.this,RewardadUnitId,new UnityAdsShowOptions(),showListener); //UnityAds.show(MainActivity.this,InterstitialadUnitId,new UnityAdsShowOptions(),showListener); } @Override public void onUnityAdsFailedToLoad( String placementId, UnityAds.UnityAdsLoadError error, String message) { Log.e( "UnityAdsExample", "Unity Ads failed to load ad for " + placementId + " with error: [" + error + "] " + message); } }; private IUnityAdsShowListener showListener = new IUnityAdsShowListener() { private SweetAlertDialog pDialog; @Override public void onUnityAdsShowFailure( String placementId, UnityAds.UnityAdsShowError error, String message) { Log.e( "UnityAdsExample", "Unity Ads failed to show ad for " + placementId + " with error: [" + error + "] " + message); SweetAlertDialog nops = new SweetAlertDialog( MainActivity.this, SweetAlertDialog.ERROR_TYPE); nops.setTitleText("WARNING"); nops.setContentText( "Failed to Load Ad, Please check your internet connection !!"); nops.setConfirmText("Ok"); nops.show(); } @Override public void onUnityAdsShowStart(String placementId) { Log.v("UnityAdsExample", "onUnityAdsShowStart: " + placementId); //progressDialog.dismiss(); } @Override public void onUnityAdsShowClick(String placementId) { Log.v("UnityAdsExample", "onUnityAdsShowClick: " + placementId); } @Override public void onUnityAdsShowComplete( String placementId, UnityAds.UnityAdsShowCompletionState state) { Log.v("UnityAdsExample", "onUnityAdsShowComplete: " + placementId); if (state.equals(UnityAds.UnityAdsShowCompletionState.COMPLETED)) { // doo btnTimer(); // Set button long ads_time = 6000 * 10 * 60 * 2; // add time addTime(ads_time); // set the time /*pDialog = new SweetAlertDialog(MainActivity.this, SweetAlertDialog.CUSTOM_IMAGE_TYPE); pDialog.setTitleText("Reward Time!."); pDialog.setContentText("Watch the whole video to get + 2 hours"); pDialog.setTitle("Gracias por apoyar la aplicacion"); pDialog.setCancelable(false); pDialog.setCustomImage(R.drawable.modojuegos); pDialog.show();*/ Toast.makeText(MainActivity.this, " 2 hours successfully added to your time!", Toast.LENGTH_LONG).show(); // Toast.makeText(SocksHttpMainActivity.this, "Mode Listener: 2 hours // successfully added to your time!", Toast.LENGTH_LONG).show(); // Reward the user for watching the ad to completion } else { // Do not reward the user for skipping the ad } } }; // This banner view object will be placed at the bottom of the screen: BannerView bottomBanner; // View objects to display banners: LinearLayout bottomBannerView; /////////////////////////// protected void onCreate //ads unity UnityAds.initialize(getApplicationContext(), unityGameID, testMode); showAds(); // load reward ads loadRewardAds(); mTextViewCountDown = (TextView) findViewById(R.id.tvTimeRemaining); timer_layout = (LinearLayout) findViewById(R.id.timerLayout); mReward = (Button) findViewById(R.id.btnAddTime); mReward.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View p1) { DisplayRewardedVideoAd(); btnTimer(); long ads_time = 6000 * 10 * 60 * 2; // add time addTime(ads_time); // set the time Toast.makeText(MainActivity.this, "Espere mientras se carga el Video", Toast.LENGTH_LONG).show(); Toast.makeText(MainActivity.this, " 2 hours successfully added to your time!", Toast.LENGTH_LONG).show(); } }); ////////////////////////////// private void loadRewardAds() { IUnityAdsListener RewardListener = new IUnityAdsListener() { @Override public void onUnityAdsReady(String adUnitId) { // Implement functionality for an ad being ready to show. //Toast.makeText(getApplicationContext(),"Video ads loaded",Toast.LENGTH_SHORT).show(); } @Override public void onUnityAdsStart(String adUnitId) { // Implement functionality for a user starting to watch an ad. } @Override public void onUnityAdsFinish(String adUnitId, UnityAds.FinishState finishState) { // Implement functionality for a user finishing an ad. loadRewardAds(); } @Override public void onUnityAdsError(UnityAds.UnityAdsError error, String message) { // Implement functionality for a Unity Ads service error occurring. Toast.makeText(getApplicationContext(),message,Toast.LENGTH_SHORT).show(); loadRewardAds(); } }; UnityAds.setListener(RewardListener); UnityAds.load(RewardadUnitId); } private void showAds() { // Create the bottom banner view object: bottomBanner = new BannerView(this, bottomAdUnitId, new UnityBannerSize(320, 50)); // Set the listener for banner lifecycle events: bottomBanner.setListener(bannerListener); bottomBannerView = (LinearLayout) findViewById(R.id.bottomBanner); LoadBannerAd(bottomBanner, bottomBannerView); } public void LoadBannerAd(BannerView bannerView, LinearLayout bannerLayout) { // Request a banner ad: bannerView.load(); // Associate the banner view object with the banner view: bannerLayout.addView(bannerView); } @Override public void onInitializationComplete() { // Enable the show ad buttons since ads can now be loaded // showAds(); DisplayRewardedVideoAd(); } @Override public void onInitializationFailed(UnityAds.UnityAdsInitializationError error, String message) { Log.e( "UnityAdsExample", "Unity Ads initialization failed with error: [" + error + "] " + message); } // Implement a function to load a rewarded ad. The ad will start to show once the ad has been // loaded. public void DisplayRewardedAd() { UnityAds.load(RewardadUnitId, loadListener); } // to show reward Ads public void DisplayRewardedVideoAd() { if (UnityAds.isReady(RewardadUnitId)) { UnityAds.show(this, RewardadUnitId); }else{ // Toast.makeText(getApplicationContext(),"ads not loaded",Toast.LENGTH_SHORT).show(); } } public void DisplayInterstitialAd() { UnityAds.load(InterstitialadUnitId, loadListener); } ////////////////////////////// //time add private CountDownTimer mCountDownTimer; private boolean mTimerRunning; private long saved_ads_time; private long mTimeLeftInMillis; private long mEndTime; //private SweetAlertDialog pDialog; private long mTimeLeftBtn; private TextView mTextViewCountDown; private LinearLayout timer_layout; private boolean mTimerEnabled; private CountDownTimer mBtnCountDown; //add time private void start(){ if (saved_ads_time == 0){ Toast.makeText(MainActivity.this, "Su tiempo expirará pronto, haga clic en AGREGAR TIEMPO para renovar el acceso.", Toast.LENGTH_LONG).show(); long millisInput = 1000 * 500; setTime(millisInput); } if (!mTimerRunning){ startTimer(); } } private void stop(){ if (mTimerRunning){ pauseTimer(); } } private void addTime(long time){ setTime(time); if (mTimerRunning){ pauseTimer(); } startTimer(); } private void pauseTimer() { mCountDownTimer.cancel(); mTimerRunning = false; } private void updateCountDownText(){ long days = TimeUnit.MILLISECONDS.toDays(mTimeLeftInMillis); long daysMillis = TimeUnit.DAYS.toMillis(days); long hours = TimeUnit.MILLISECONDS.toHours(mTimeLeftInMillis - daysMillis); long hoursMillis = TimeUnit.HOURS.toMillis(hours); long minutes = TimeUnit.MILLISECONDS.toMinutes(mTimeLeftInMillis - daysMillis - hoursMillis); long minutesMillis = TimeUnit.MINUTES.toMillis(minutes); long seconds = TimeUnit.MILLISECONDS.toSeconds(mTimeLeftInMillis - daysMillis - hoursMillis - minutesMillis); String resultString = days + "d:" + hours + "h:" + minutes + "m:" + seconds + "s"; mTextViewCountDown.setText(resultString); } private void setTime(long milliseconds) { saved_ads_time = mTimeLeftInMillis + milliseconds; mTimeLeftInMillis = saved_ads_time; updateCountDownText(); } private void saveTime(){ SharedPreferences saved_current_time = getSharedPreferences("time", Context.MODE_PRIVATE); SharedPreferences.Editor time_edit = saved_current_time.edit(); time_edit.putLong("SAVED_TIME", mTimeLeftInMillis); time_edit.apply(); } private void resumeTime(){ SharedPreferences time = getSharedPreferences("time", Context.MODE_PRIVATE); long saved_time = time.getLong("SAVED_TIME", 0); setTime(saved_time); // Use this code to continue time if app close accidentally while connected String state = SkStatus.getLastState(); if (SkStatus.SSH_CONNECTED.equals(state)) { if (!mTimerRunning){ startTimer(); } } mTimerEnabled = true; } private void startTimer() { mEndTime = System.currentTimeMillis() + mTimeLeftInMillis; mCountDownTimer = new CountDownTimer(mTimeLeftInMillis, 1000) { @Override public void onTick(long millisUntilFinished) { mTimeLeftInMillis = millisUntilFinished; saveTime(); updateCountDownText(); } @Override public void onFinish() { mTimerRunning = false; pauseTimer(); saved_ads_time = 0; // Code for auto stop vpn (sockshtttp) Intent stopVPN = new Intent(SocksDNSService.TUNNEL_SSH_STOP_SERVICE); LocalBroadcastManager.getInstance(MainActivity.this) .sendBroadcast(stopVPN); Toast.makeText(MainActivity.this,"¡Se acabó el tiempo! Haga clic en Agregar + Hora para renovar el acceso.", Toast.LENGTH_LONG).show(); } }.start(); mTimerRunning = true; } private void btnTimer() { mBtnCountDown = new CountDownTimer(20000, 1000) { @Override public void onTick(long millisUntilFinished) { mTimeLeftBtn = millisUntilFinished; mReward.setEnabled(false); updateBtnText(); } @Override public void onFinish() { mReward.setEnabled(true); mReward.setText("ADD + TIME"); } }.start(); } private void updateBtnText() { int seconds = (int) (mTimeLeftBtn / 1000) % 60; String timeLeftFormatted; if (seconds > 0) { timeLeftFormatted = String.format(Locale.getDefault(), "%02d", seconds); mReward.setText("Refresh in " + timeLeftFormatted); } } //end ////////////////////////// Add optiones aditionales timer_layout.setVisibility(View.VISIBLE); start(); stop(); if (!mTimerEnabled){ resumeTime(); // resume time } showInterstitial(); /////////////////////////// Layout time