use of com.google.android.gms.ads.AdRequest in project Space-Station-Tracker by Kiarasht.
the class MapsActivity method onResume.
/**
* Reread the refreshrate and update views if needed such as prediction line, texts and their
* properties (Color, size, etc.).
*/
protected void onResume() {
super.onResume();
// Asks for a interstitial ad now so next time user starts a new activity we have it ready
requestNewInterstitial();
// Update decimal format
String format = "0";
for (int i = 0; i < mSharedPreferences.getInt("decimalType", 3); ++i) {
if (i == 0)
format += ".";
format += "#";
}
mDecimalFormat = new DecimalFormat(format);
// When activity was just paused
if (mStart) {
mRefreshrate = 1000 * (mSharedPreferences.getInt("refresh_Rate", 9) + 1);
if (mTimer != null) {
mTimer.cancel();
mTimer.purge();
mTimer = null;
}
// Track ISS based on refreshrate
mTimer = new Timer();
mTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
trackISS();
}
}, 0, mRefreshrate);
mMaptype();
// When activity is killed or created for first time
} else {
mStart = true;
mTimer = new Timer();
}
// Provide optional advertisements that is visible/hidden by a checkbox in Preferences
if (mSharedPreferences.getBoolean("advertisement", false) && mAdView != null) {
// User disabled ads
mAdView.setVisibility(View.GONE);
} else if (!mSharedPreferences.getBoolean("advertisement", false)) {
if (mAdView == null) {
// User wants ads but instance is null
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(getString(R.string.test_device)).build();
mAdView.loadAd(adRequest);
} else {
// User wants ads, instance already got one
mAdView.setVisibility(View.VISIBLE);
}
}
// Update the color and size of polylines if they are different in settings than what they are right now
mCurrentColor = Color.YELLOW;
mCurrentWidth = 5;
try {
mCurrentColor = mSharedPreferences.getInt("colorType", Color.YELLOW);
mCurrentWidth = mSharedPreferences.getInt("sizeType", 5);
} catch (ClassCastException e) {
Toast.makeText(mContext, R.string.data_corrupted, Toast.LENGTH_LONG).show();
mSharedPreferences.edit().clear().apply();
}
if (mPolyLine != null) {
if (mMap != null) {
// Color needs updating?
if (mPolyLine.getColor() != mCurrentColor) {
for (int i = 0; mPolyArray[i] != null && i < mPolyArray.length - 1; ++i) {
mPolyArray[i].setColor(mCurrentColor);
}
}
// What about their size?
if (mPolyLine.getWidth() != mCurrentWidth) {
for (int i = 0; mPolyArray[i] != null && i < mPolyArray.length - 1; ++i) {
mPolyArray[i].setWidth(mCurrentWidth);
}
}
} else {
Toast.makeText(mContext, R.string.errorMap, Toast.LENGTH_SHORT).show();
}
}
// If user even wants the additional info, and their properties have been changed, update them
if (mDescription.getVisibility() == View.VISIBLE && !mSharedPreferences.getBoolean("info_ISS", true)) {
mDescription.setVisibility(View.GONE);
} else if (mDescription.getVisibility() == View.GONE && mSharedPreferences.getBoolean("info_ISS", true)) {
mDescription.setVisibility(View.VISIBLE);
}
// Update text color if different than settings
int textColor = mSharedPreferences.getInt("colorText", Color.YELLOW);
if (mLatLong.getCurrentTextColor() != textColor) {
mLatLong.setTextColor(textColor);
mDescription.setTextColor(textColor);
}
// Update text outline color if different
int textOutlineColor = mSharedPreferences.getInt("colorHighlightText", Color.BLACK);
if (mLatLong.getShadowColor() != mSharedPreferences.getInt("colorHighlightText", Color.BLACK)) {
mLatLong.setShadowLayer(6, 0, 0, textOutlineColor);
mDescription.setShadowLayer(6, 0, 0, textOutlineColor);
}
// Update text size as well if different
int textSize = mSharedPreferences.getInt("textSizeType", 12);
if (mLatLong.getTextSize() != textSize) {
mLatLong.setTextSize(textSize);
mDescription.setTextSize(textSize);
}
if (mAdView != null) {
mAdView.resume();
}
mSuccess = 0;
}
use of com.google.android.gms.ads.AdRequest in project Space-Station-Tracker by Kiarasht.
the class Locations method onCreate.
/**
* Assign simple widgets while also use the Google API to get user's location.
*
* @param savedInstanceState on create method
*/
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locations_layout);
mActivity = this;
LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false);
mRecyclerView = (ObservableRecyclerView) findViewById(R.id.recycler);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// Show an ad, or hide it if its disabled
if (!sharedPreferences.getBoolean("advertisement", false)) {
adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(getString(R.string.test_device)).build();
if (adView != null) {
adView.loadAd(adRequest);
adView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (!mPaddingOnce) {
mPaddingOnce = true;
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom() + adView.getHeight());
}
}
});
}
} else {
findViewById(R.id.adView).setVisibility(View.GONE);
}
mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
mActionBarSize = getActionBarSize();
mImageView = (ImageView) findViewById(R.id.image);
mOverlayView = findViewById(R.id.overlay);
mTitleView = (TextView) findViewById(R.id.title);
mTitleView.setText(getTitle());
setTitle(null);
mRecyclerView.setScrollViewCallbacks(this);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setNestedScrollingEnabled(true);
// mRecyclerViewBackground makes RecyclerView's background except header view.
mRecyclerViewBackground = findViewById(R.id.list_background);
//since you cannot programmatically add a header view to a RecyclerView we added an empty view as the header
// in the adapter and then are shifting the views OnCreateView to compensate
final float scale = 1 + MAX_TEXT_SCALE_DELTA;
mRecyclerViewBackground.post(new Runnable() {
@Override
public void run() {
ViewHelper.setTranslationY(mRecyclerViewBackground, mFlexibleSpaceImageHeight);
}
});
ViewHelper.setTranslationY(mOverlayView, mFlexibleSpaceImageHeight);
mTitleView.post(new Runnable() {
@Override
public void run() {
ViewHelper.setTranslationY(mTitleView, (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale));
ViewHelper.setPivotX(mTitleView, 0);
ViewHelper.setPivotY(mTitleView, 0);
ViewHelper.setScaleX(mTitleView, scale);
ViewHelper.setScaleY(mTitleView, scale);
}
});
requestQueue = Volley.newRequestQueue(this);
Connected();
}
use of com.google.android.gms.ads.AdRequest in project Space-Station-Tracker by Kiarasht.
the class PeopleinSpace method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.people_in_space_layout);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler);
mActivity = this;
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
mRequestQueue = Volley.newRequestQueue(this);
display_people();
// Show an ad, or hide it if its disabled
if (!sharedPreferences.getBoolean("advertisement", false)) {
adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(getString(R.string.test_device)).build();
if (adView != null) {
adView.loadAd(adRequest);
adView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (!mPaddingOnce) {
mPaddingOnce = true;
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom() + adView.getHeight());
}
}
});
}
} else {
findViewById(R.id.adView).setVisibility(View.GONE);
}
}
use of com.google.android.gms.ads.AdRequest in project quickstart-android by firebase.
the class MainActivity method requestNewInterstitial.
/**
* Load a new interstitial ad asynchronously.
*/
// [START request_new_interstitial]
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
}
use of com.google.android.gms.ads.AdRequest in project quickstart-android by firebase.
the class MainActivity method onCreate.
// [END_EXCLUDE]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
// [END load_banner_ad]
// AdMob ad unit IDs are not currently stored inside the google-services.json file.
// Developers using AdMob can store them as custom values in a string resource file or
// simply use constants. Note that the ad units used here are configured to return only test
// ads, and should not be used outside this sample.
// [START instantiate_interstitial_ad]
// Create an InterstitialAd object. This same object can be re-used whenever you want to
// show an interstitial.
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
// [END instantiate_interstitial_ad]
// [START create_interstitial_ad_listener]
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
beginSecondActivity();
}
@Override
public void onAdLoaded() {
// [START_EXCLUDE]
if (mLoadInterstitialButton != null) {
mLoadInterstitialButton.setEnabled(true);
}
// [END_EXCLUDE]
}
@Override
public void onAdFailedToLoad(int i) {
// See https://goo.gl/sCZj0H for possible error codes.
Log.w(TAG, "onAdFailedToLoad:" + i);
}
});
// [END create_interstitial_ad_listener]
// [START display_interstitial_ad]
mLoadInterstitialButton = (Button) findViewById(R.id.load_interstitial_button);
mLoadInterstitialButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
beginSecondActivity();
}
}
});
// [END display_interstitial_ad]
// Disable button if an interstitial ad is not loaded yet.
mLoadInterstitialButton.setEnabled(mInterstitialAd.isLoaded());
}
Aggregations