// load Ads for multiple times in background
// if (getResources().getBoolean(R.bool.ads_switch)) {
// mInterstitialAd.loadAd(new AdRequest.Builder().build());
// }
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_glob) {
startActivity(new Intent(this, Servers.class));
return true;
}
if (id == R.id.action_purchase) {
startActivity(new Intent(this, PurchasesActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_upgrade) {
// upgrade application is available...
startActivity(new Intent(this, Servers.class));
} else if (id == R.id.nav_unlock) {
startActivity(new Intent(this, PurchasesActivity.class));
} else if (id == R.id.nav_helpus) {
// find help about the application
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"infinityvideoreward@courseunity.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Improve Comments");
intent.putExtra(Intent.EXTRA_TEXT, "message body");
try {
startActivity(Intent.createChooser(intent, "send mail"));
} catch (ActivityNotFoundException ex) {
Toast.makeText(this, "No mail app found!!!", Toast.LENGTH_SHORT);
} catch (Exception ex) {
Toast.makeText(this, "Unexpected Error!!!", Toast.LENGTH_SHORT);
}
} else if (id == R.id.nav_rate) {
// rate application...
rateUs();
} else if (id == R.id.nav_share) {
// share the application...
try {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "share app");
shareIntent.putExtra(Intent.EXTRA_TEXT, "I'm using this Free VPN App, it's provide all servers free https://play.google.com/store/apps/details?id="+ BuildConfig.APPLICATION_ID);
startActivity(Intent.createChooser(shareIntent, "choose one"));
} catch (Exception e) {
}
} else if (id == R.id.nav_setting) {
// Application settings...
startActivity(new Intent(this, Settings.class));
} else if (id == R.id.nav_faq) {
startActivity(new Intent(this, Faq.class));
} else if (id == R.id.nav_policy) {
Uri uri = Uri.parse(getResources().getString(R.string.privacy_policy_link)); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
private Handler mUIHandler = new Handler(Looper.getMainLooper());
final Runnable mUIUpdateRunnable = new Runnable() {
@Override
public void run() {
updateUI();
checkRemainingTraffic();
mUIHandler.postDelayed(mUIUpdateRunnable, 10000);
}
};
@Override
protected void onResume() {
// if the application again available from background state...
super.onResume();
isConnected(new Callback() {
@Override
public void success(@NonNull Boolean aBoolean) {
if (aBoolean) {
startUIUpdateTask();
}
}
// To find vpn state...
HydraSdk.getVpnState(new Callback() {
@Override
public void success(@NonNull VPNState vpnState) {
state = vpnState;
switch (vpnState) {
case IDLE: {
// vpn is idle...
loadIcon();
connectBtnTextView.setEnabled(true);
connectionStateTextView.setText(R.string.disconnected);
timerTextView.setVisibility(View.GONE);
hideConnectProgress();
break;
}
case CONNECTED: {
// vpn Connected Successfully...
loadIcon();
connectBtnTextView.setEnabled(true);
connectionStateTextView.setText(R.string.connected);
timer();
timerTextView.setVisibility(View.VISIBLE);
hideConnectProgress();
break;
}
case CONNECTING_VPN:
case CONNECTING_CREDENTIALS:
case CONNECTING_PERMISSIONS: {
// during connecting vpn
loadIcon();
connectionStateTextView.setText(R.string.connecting);
connectBtnTextView.setEnabled(true);
timerTextView.setVisibility(View.GONE);
showConnectProgress();
break;
}
case PAUSED: {
// vpn paused...
connectBtnTextView.setImageResource(R.drawable.power_off);
t_connection_status.setText("NotSecure");
connectionStateTextView.setText(R.string.paused);
i_connection_status_image.setImageResource(R.drawable.not_secure_vpn);
break;
}
}
}
@Override
public void failure(@NonNull HydraException e) {
}
});
getCurrentServer(new Callback<String>() {
// try to connect to current vpn server...
@Override
public void success(@NonNull final String currentServer) {
runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
}
@Override
public void failure(@NonNull HydraException e) {
}
});
}
protected void updateTrafficStats(long outBytes, long inBytes) {
// try to update the traffic state of the vpn...
String outString = LocalFormatter.easyRead(outBytes, false);
String inString = LocalFormatter.easyRead(inBytes, false);
// Updating progressbar
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
while (state == VPNState.CONNECTING_VPN || state == VPNState.CONNECTING_CREDENTIALS) {
progressBarValue++;
handler.post(new Runnable() {
@Override
public void run() {
}
});
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
protected void hideConnectProgress() {
connectionStateTextView.setVisibility(View.VISIBLE);
}
protected void showMessage(String msg) {
Toast.makeText(ContentsActivity.this, msg, Toast.LENGTH_SHORT).show();
}
protected void rateUs() {
Uri uri = Uri.parse("market://details?id=" + this.getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
// To count with Play market backstack, After pressing back button,
// to taken back to our application, we need to add following flag to intent.
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try {
startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=" + this.getPackageName())));
}
}
protected void timer() {
if (adCount == 0) {
startTime = SystemClock.uptimeMillis();
customHandler.postDelayed(updateTimerThread, 0);
timeSwapBuff += timeInMilliseconds;
}
}
private Runnable updateTimerThread = new Runnable() {
public void run() {
timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
updatedTime = timeSwapBuff + timeInMilliseconds;
int secs = (int) (updatedTime / 1000);
int mins = secs / 60;
int hrs = mins / 60;
secs = secs % 60;
int milliseconds = (int) (updatedTime % 1000);
timerTextView.setText(String.format("%02d", hrs) + ":"
+ String.format("%02d", mins) + ":"
+ String.format("%02d", secs));
customHandler.postDelayed(this, 0);
}
};
protected void loadIcon() {
if (state == VPNState.IDLE) {
Glide.with(this).load(R.drawable.power_off).into(connectBtnTextView);
t_connection_status.setText("NotSecure");
i_connection_status_image.setImageResource(R.drawable.not_secure_vpn);
} else if (state == VPNState.CONNECTING_VPN || state == VPNState.CONNECTING_CREDENTIALS) {
connectBtnTextView.setVisibility(View.VISIBLE);/*INVISIBLE IS CHEANGED TO VISIBLE*/
lottieAnimationView.setVisibility(View.VISIBLE);
} else if (state == VPNState.CONNECTED) {
Glide.with(this).load(R.drawable.power_on).into(connectBtnTextView);
connectBtnTextView.setVisibility(View.VISIBLE);
t_connection_status.setText("Secure");
lottieAnimationView.setVisibility(View.INVISIBLE);
if (vpn_toast_check == true) {
Toasty.success(ContentsActivity.this, "VPN Connected Successfully", Toast.LENGTH_SHORT).show();
vpn_toast_check = false;
}
i_connection_status_image.setImageResource(R.drawable.secure_vpn);
}
}
protected void disconnectAlert() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Do you want to disconnect?");
builder.setPositiveButton("Disconnect",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
disconnectFromVnp();
vpn_toast_check = true;
Toasty.success(ContentsActivity.this, "VPN Disconnected", Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toasty.success(ContentsActivity.this, "VPN Remains Connected", Toast.LENGTH_SHORT).show();
}
});
builder.show();
}
//loading native ad
private void populateUnifiedNativeAdView(UnifiedNativeAd nativeAd, UnifiedNativeAdView
adView) {
// Set the media view. Media content will be automatically populated in the media view once
MediaView mediaView = adView.findViewById(R.id.ad_media);
adView.setMediaView(mediaView);
// Set other ad assets.
adView.setHeadlineView(adView.findViewById(R.id.ad_headline));
adView.setBodyView(adView.findViewById(R.id.ad_body));
adView.setCallToActionView(adView.findViewById(R.id.ad_call_to_action));
adView.setIconView(adView.findViewById(R.id.ad_app_icon));
adView.setPriceView(adView.findViewById(R.id.ad_price));
adView.setStarRatingView(adView.findViewById(R.id.ad_stars));
adView.setStoreView(adView.findViewById(R.id.ad_store));
adView.setAdvertiserView(adView.findViewById(R.id.ad_advertiser));
// The headline is guaranteed to be in every UnifiedNativeAd.
((TextView) adView.getHeadlineView()).setText(nativeAd.getHeadline());
// These assets aren't guaranteed to be in every UnifiedNativeAd, so it's important to
// check before trying to display them.
if (nativeAd.getBody() == null) {
adView.getBodyView().setVisibility(View.INVISIBLE);
} else {
adView.getBodyView().setVisibility(View.VISIBLE);
((TextView) adView.getBodyView()).setText(nativeAd.getBody());
}
if (nativeAd.getCallToAction() == null) {
adView.getCallToActionView().setVisibility(View.INVISIBLE);
} else {
adView.getCallToActionView().setVisibility(View.VISIBLE);
((Button) adView.getCallToActionView()).setText(nativeAd.getCallToAction());
}
if (nativeAd.getIcon() == null) {
adView.getIconView().setVisibility(View.GONE);
} else {
((ImageView) adView.getIconView()).setImageDrawable(
nativeAd.getIcon().getDrawable());
adView.getIconView().setVisibility(View.VISIBLE);
}
if (nativeAd.getPrice() == null) {
adView.getPriceView().setVisibility(View.INVISIBLE);
} else {
adView.getPriceView().setVisibility(View.VISIBLE);
((TextView) adView.getPriceView()).setText(nativeAd.getPrice());
}
if (nativeAd.getStore() == null) {
adView.getStoreView().setVisibility(View.INVISIBLE);
} else {
adView.getStoreView().setVisibility(View.VISIBLE);
((TextView) adView.getStoreView()).setText(nativeAd.getStore());
}
if (nativeAd.getStarRating() == null) {
adView.getStarRatingView().setVisibility(View.INVISIBLE);
} else {
((RatingBar) adView.getStarRatingView())
.setRating(nativeAd.getStarRating().floatValue());
adView.getStarRatingView().setVisibility(View.VISIBLE);
}
if (nativeAd.getAdvertiser() == null) {
adView.getAdvertiserView().setVisibility(View.INVISIBLE);
} else {
((TextView) adView.getAdvertiserView()).setText(nativeAd.getAdvertiser());
adView.getAdvertiserView().setVisibility(View.VISIBLE);
}
// This method tells the Google Mobile Ads SDK that you have finished populating your
// native ad view with this native ad. The SDK will populate the adView's MediaView
// with the media content from this native ad.
adView.setNativeAd(nativeAd);
// Get the video controller for the ad. One will always be provided, even if the ad doesn't
// have a video asset.
VideoController vc = nativeAd.getVideoController();
// Updates the UI to say whether or not this ad has a video asset.
if (vc.hasVideoContent()) {
// Create a new VideoLifecycleCallbacks object and pass it to the VideoController. The
// VideoController will call methods on this object when events occur in the video
// lifecycle.
vc.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
@Override
public void onVideoEnd() {
// Publishers should allow native ads to complete video playback before
// refreshing or replacing them with another ad in the same UI location.
super.onVideoEnd();
}
});
} else {
}
}
/**
* Creates a request for a new native ad based on the boolean parameters and calls the
* corresponding "populate" method when one is successfully returned.
*/
private void refreshAd() {
AdLoader.Builder builder = new AdLoader.Builder(this, getString(R.string.admob_native));
builder.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
@Override
public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
// You must call destroy on old ads when you are done with them,
// otherwise you will have a memory leak.
if (nativeAd != null) {
nativeAd.destroy();
}
nativeAd = unifiedNativeAd;
RelativeLayout frameLayout =
findViewById(R.id.fl_adplaceholder);
UnifiedNativeAdView adView = (UnifiedNativeAdView) getLayoutInflater()
.inflate(R.layout.ad_unified, null);
populateUnifiedNativeAdView(unifiedNativeAd, adView);
frameLayout.removeAllViews();
frameLayout.addView(adView);
}
});
VideoOptions videoOptions = new VideoOptions.Builder()
.build();
NativeAdOptions adOptions = new NativeAdOptions.Builder()
.setVideoOptions(videoOptions)
.build();
builder.withNativeAdOptions(adOptions);
AdLoader adLoader = builder.withAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int errorCode) {
Log.w("asdsadsad", "ads" + errorCode);
}
}).build();
adLoader.loadAd(new AdRequest.Builder()
.build());
}
}
**these imports or not resolve** import com.anchorfree.hydrasdk.HydraSdk;
import com.anchorfree.hydrasdk.api.response.RemainingTraffic;
import com.anchorfree.hydrasdk.callbacks.Callback;
import com.anchorfree.hydrasdk.exceptions.HydraException;
import com.anchorfree.hydrasdk.vpnservice.VPNState;`
in build.gradle
implementation 'com.github.AnchorFreePartner.hydra-sdk-android:sdk:3.3.1' implementation 'com.github.AnchorFreePartner.hydra-sdk-android:openvpn:3.3.1'
Hi i just update hydra sdk to 3.3.1 now i am unable to get my project build due to error below is full class
`package com.iplay3d.foxbayvpn.vpn.Activities;
import android.content.ActivityNotFoundException; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.SystemClock; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.RatingBar; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout;
import com.airbnb.lottie.LottieAnimationView; import com.anchorfree.hydrasdk.HydraSdk; import com.anchorfree.hydrasdk.api.response.RemainingTraffic; import com.anchorfree.hydrasdk.callbacks.Callback; import com.anchorfree.hydrasdk.exceptions.HydraException; import com.anchorfree.hydrasdk.vpnservice.VPNState; import com.iplay3d.foxbayvpn.vpn.BuildConfig; import com.iplay3d.foxbayvpn.vpn.Config; import com.iplay3d.foxbayvpn.vpn.R; import com.iplay3d.foxbayvpn.vpn.Utils.LocalFormatter; import com.bumptech.glide.Glide; import com.google.android.gms.ads.AdListener; import com.google.android.gms.ads.AdLoader; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.InterstitialAd; import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.VideoController; import com.google.android.gms.ads.VideoOptions; import com.google.android.gms.ads.formats.MediaView; import com.google.android.gms.ads.formats.NativeAdOptions; import com.google.android.gms.ads.formats.UnifiedNativeAd; import com.google.android.gms.ads.formats.UnifiedNativeAdView; import com.google.android.material.navigation.NavigationView; import com.onesignal.OneSignal; import com.pixplicity.easyprefs.library.Prefs;
import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import es.dmoral.toasty.Toasty;
public abstract class ContentsActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
// Lottie animation to show animation in the project lottieAnimationView = findViewById(R.id.animation_view);
// Interstitial Ad loaded successfully... mInterstitialAd.show(); } else {
// load Ads for multiple times in background // if (getResources().getBoolean(R.bool.ads_switch)) { // mInterstitialAd.loadAd(new AdRequest.Builder().build()); // } }
// upgrade application is available... startActivity(new Intent(this, Servers.class)); } else if (id == R.id.nav_unlock) { startActivity(new Intent(this, PurchasesActivity.class)); } else if (id == R.id.nav_helpus) { // find help about the application Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"infinityvideoreward@courseunity.com"}); intent.putExtra(Intent.EXTRA_SUBJECT, "Improve Comments"); intent.putExtra(Intent.EXTRA_TEXT, "message body");
// rate application... rateUs(); } else if (id == R.id.nav_share) { // share the application... try { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_SUBJECT, "share app"); shareIntent.putExtra(Intent.EXTRA_TEXT, "I'm using this Free VPN App, it's provide all servers free https://play.google.com/store/apps/details?id="+ BuildConfig.APPLICATION_ID); startActivity(Intent.createChooser(shareIntent, "choose one")); } catch (Exception e) { }
// Application settings... startActivity(new Intent(this, Settings.class)); } else if (id == R.id.nav_faq) { startActivity(new Intent(this, Faq.class)); } else if (id == R.id.nav_policy) { Uri uri = Uri.parse(getResources().getString(R.string.privacy_policy_link)); // missing 'http://' will cause crashed Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
// if the application again available from background state... super.onResume(); isConnected(new Callback() {
@Override
public void success(@NonNull Boolean aBoolean) {
if (aBoolean) {
startUIUpdateTask();
}
}
// application in the background state... super.onPause(); stopUIUpdateTask(); }
// Interstitial Ad loaded successfully... if (mInterstitialAd.isLoaded()) { mInterstitialAd.show(); } else { updateUI(); connectToVpn(); }
// To find vpn state... HydraSdk.getVpnState(new Callback() {
@Override
public void success(@NonNull VPNState vpnState) {
state = vpnState;
switch (vpnState) {
case IDLE: {
// vpn is idle...
loadIcon();
connectBtnTextView.setEnabled(true);
connectionStateTextView.setText(R.string.disconnected);
timerTextView.setVisibility(View.GONE);
hideConnectProgress();
break;
}
case CONNECTED: {
// vpn Connected Successfully...
loadIcon();
connectBtnTextView.setEnabled(true);
connectionStateTextView.setText(R.string.connected);
timer();
timerTextView.setVisibility(View.VISIBLE);
hideConnectProgress();
break;
}
case CONNECTING_VPN:
case CONNECTING_CREDENTIALS:
case CONNECTING_PERMISSIONS: {
// during connecting vpn
loadIcon();
connectionStateTextView.setText(R.string.connecting);
connectBtnTextView.setEnabled(true);
timerTextView.setVisibility(View.GONE);
showConnectProgress();
break;
}
case PAUSED: {
// vpn paused...
connectBtnTextView.setImageResource(R.drawable.power_off);
t_connection_status.setText("NotSecure");
connectionStateTextView.setText(R.string.paused);
i_connection_status_image.setImageResource(R.drawable.not_secure_vpn);
break;
}
// try to update the traffic state of the vpn... String outString = LocalFormatter.easyRead(outBytes, false); String inString = LocalFormatter.easyRead(inBytes, false);
// Updating progressbar new Thread(new Runnable() {
}
**these imports or not resolve**
import com.anchorfree.hydrasdk.HydraSdk; import com.anchorfree.hydrasdk.api.response.RemainingTraffic; import com.anchorfree.hydrasdk.callbacks.Callback; import com.anchorfree.hydrasdk.exceptions.HydraException; import com.anchorfree.hydrasdk.vpnservice.VPNState;`in build.gradle
implementation 'com.github.AnchorFreePartner.hydra-sdk-android:sdk:3.3.1' implementation 'com.github.AnchorFreePartner.hydra-sdk-android:openvpn:3.3.1'
in other build.gradle
allprojects { repositories { google() jcenter() mavenCentral() maven { url "https://www.jitpack.io" } maven { url 'https://maven.google.com' } } }
Error Log: error: cannot find symbol import com.anchorfree.hydrasdk.SessionConfig; ^ symbol: class SessionConfig location: package com.anchorfree.hydrasdk