Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save GMadorell/6130476 to your computer and use it in GitHub Desktop.

Select an option

Save GMadorell/6130476 to your computer and use it in GitHub Desktop.
Shows how to implement Gitfiz SDK without using an external layout XML file, useful for the LibGDX framework.
/**
* Extends AndroidApplication incorporating a view for the Gitfiz sdk, which is just a bottom left button.
*/
public class AdmobApplication
extends AndroidApplication
// Giftiz interfaces.
implements ButtonNeedsUpdateDelegate {
private ImageView giftizButtonView;
@Override public void onCreate ( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
RelativeLayout layout = new RelativeLayout( this );
// Can't use the normal initialize() because we need multiple views.
View libGDXView = initializeForView( new QixPrototype(), Configuration.getAndroidConfiguration() );
layout.addView( libGDXView );
setFullScreenWindow();
GiftizSDK.Inner.setButtonNeedsUpdateDelegate( this );
setupGiftizButtonView();
layout.addView( giftizButtonView, getGiftizButtonViewParams() );
// Hook it all up
setContentView( layout );
}
private void setFullScreenWindow() {
requestWindowFeature( Window.FEATURE_NO_TITLE );
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN );
getWindow().clearFlags( WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN );
}
private void setupGiftizButtonView() {
giftizButtonView = new ImageView( getApplicationContext() );
giftizButtonView.bringToFront();
final AdmobApplication admobApplication = this;
giftizButtonView.setOnClickListener( new OnClickListener() {
@Override
public void onClick( View v ) {
GiftizSDK.Inner.buttonClicked( admobApplication );
}
});
}
private RelativeLayout.LayoutParams getGiftizButtonViewParams() {
RelativeLayout.LayoutParams giftizParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT );
giftizParams.addRule( RelativeLayout.ALIGN_PARENT_LEFT );
giftizParams.addRule( RelativeLayout.ALIGN_PARENT_BOTTOM );
return giftizParams;
}
@Override
protected void onPause() {
super.onPause();
GiftizSDK.onPauseMainActivity( this );
}
@Override
protected void onResume() {
super.onResume();
GiftizSDK.onResumeMainActivity( this );
updateGitfizButtonImage();
}
@Override
public void hideButton() {
runOnUiThread( new Runnable() {
@Override
public void run() {
giftizButtonView.setVisibility( View.GONE );
}
});
}
@Override
public void showButton() {
Log.log( "Show giftiz button called." );
runOnUiThread( new Runnable() {
@Override
public void run() {
giftizButtonView.setVisibility( View.VISIBLE );
buttonNeedsUpdate();
}
});
}
// --- ButtonNeedsUpdateDelegate implementation - Gitfiz button. ---
@Override
public void buttonNeedsUpdate() {
updateGitfizButtonImage();
}
/** Pick the right button image according to the actual button status. */
private void updateGitfizButtonImage() {
boolean invisible = false;
switch (GiftizSDK.Inner.getButtonStatus(this)) {
case ButtonInvisible : invisible = true; break;
case ButtonNaked : giftizButtonView.setImageResource( R.drawable.giftiz_logo_self ); break;
case ButtonBadge : giftizButtonView.setImageResource( R.drawable.giftiz_logo_badge_self ); break;
case ButtonWarning : giftizButtonView.setImageResource( R.drawable.giftiz_logo_warning_self ); break;
}
if ( invisible ) {
giftizButtonView.setVisibility( View.GONE );
} else {
giftizButtonView.setVisibility( View.VISIBLE );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment