Android Open Source - Aviary-Android-SDK Alert Activity






From Project

Back to project page Aviary-Android-SDK.

License

The source code is released under:

AVIARY API TERMS OF USE Full Legal Agreement The following terms and conditions and the terms and conditions at http://www.aviary.com/terms (collectively, the ?Terms??) govern your use of any and ...

If you think the Android project Aviary-Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.aviary.android.feather;
/*from   w  w w. ja  v a2s.  c om*/
import java.util.ArrayList;
import java.util.Collection;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.os.Bundle;

import com.aviary.android.feather.common.AviaryIntent;
import com.aviary.android.feather.common.log.LoggerFactory;
import com.aviary.android.feather.common.log.LoggerFactory.Logger;
import com.aviary.android.feather.common.log.LoggerFactory.LoggerType;
import com.aviary.android.feather.common.utils.ThrowableUtils;

public class AlertActivity extends Activity implements OnDismissListener, OnCancelListener {

  Logger logger = LoggerFactory.getLogger( "AlertActivity", LoggerType.ConsoleLoggerType );

  @Override
  protected void onCreate( Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );

    Intent intent = getIntent();

    logger.info( "onCreate: %s", intent );

    if ( !handleIntent( intent ) ) {
      finish();
    }
  }

  private boolean handleIntent( final Intent intent ) {
    if ( null != intent ) {
      final String action = intent.getAction();
      final Bundle extras = intent.getExtras();

      if ( null != extras ) {
        if ( AviaryIntent.ACTION_ALERT.equals( action ) ) {
          AlertDialog dialog = handleAlertMessage( extras );
          if( null != dialog ) {
            dialog.show();
            dialog.setOnDismissListener( this );
            dialog.setOnCancelListener( this );
            return true;
          }
        }
      }
    }
    return false;
  }

  @SuppressWarnings ( "unchecked" )
  private AlertDialog handleAlertMessage( Bundle extras ) {
    logger.info( "handleAlertMessage: %s", extras );
    
    final String title = extras.getString( Intent.EXTRA_TITLE );
    final Object exceptions = extras.getSerializable( AviaryIntent.EXTRA_EXCEPTIONS );
    final String message = extras.getString( Intent.EXTRA_TEXT );
    
    logger.log( "title: %s", title );
    logger.log( "exceptions: %s", exceptions );
    logger.log( "text: %s", message );

    if ( null != title && ( extras.containsKey( AviaryIntent.EXTRA_EXCEPTIONS ) || extras.containsKey( Intent.EXTRA_TEXT )) ) {
      
      String text = null;
      
      if( extras.containsKey( AviaryIntent.EXTRA_EXCEPTIONS )) {
        if( null != exceptions && ( exceptions instanceof ArrayList<?> ) ) {
          Collection<Throwable> throwables = (Collection<Throwable>) exceptions;
          text = ThrowableUtils.getLocalizedMessage( throwables, "\n\n" );
        }
      } else if( extras.containsKey( Intent.EXTRA_TEXT )) {
        text = extras.getString( Intent.EXTRA_TEXT );
      }
      
      AlertDialog.Builder alert = new AlertDialog.Builder( this );
      alert.setTitle( title );
      alert.setIcon( android.R.drawable.ic_dialog_alert );
      
      if( null != text ) {
        alert.setMessage( text );
      }
      
      alert.setPositiveButton( android.R.string.cancel, new OnClickListener() {
        
        @Override
        public void onClick( DialogInterface dialog, int which ) {
          dialog.dismiss();
        }
      } );
      return alert.create();
    }
    return null;
  }

  @Override
  public void onCancel( DialogInterface dialog ) {
    logger.info( "onCancel" );
    finish();
  }

  @Override
  public void onDismiss( DialogInterface dialog ) {
    logger.info( "onDismiss" );
    finish();
  }

}




Java Source Code List

com.aviary.android.feather.AlertActivity.java
com.aviary.android.feather.AviaryMainController.java
com.aviary.android.feather.FeatherActivity.java
com.aviary.android.feather.async_tasks.AsyncImageManager.java
com.aviary.android.feather.async_tasks.DownloadImageAsyncTask.java
com.aviary.android.feather.async_tasks.ExifTask.java
com.aviary.android.feather.effects.AbstractContentPanel.java
com.aviary.android.feather.effects.AbstractOptionPanel.java
com.aviary.android.feather.effects.AbstractPanelLoaderService.java
com.aviary.android.feather.effects.AbstractPanel.java
com.aviary.android.feather.effects.AdjustEffectPanel.java
com.aviary.android.feather.effects.BordersPanel.java
com.aviary.android.feather.effects.ColorSplashPanel.java
com.aviary.android.feather.effects.CropPanel.java
com.aviary.android.feather.effects.DelayedSpotDrawPanel.java
com.aviary.android.feather.effects.DrawingPanel.java
com.aviary.android.feather.effects.EffectsPanel.java
com.aviary.android.feather.effects.EnhanceEffectPanel.java
com.aviary.android.feather.effects.MemePanel.java
com.aviary.android.feather.effects.NativeEffectRangePanel.java
com.aviary.android.feather.effects.SimpleStatusMachine.java
com.aviary.android.feather.effects.SliderEffectPanel.java
com.aviary.android.feather.effects.StickersPanel.java
com.aviary.android.feather.effects.TextPanel.java
com.aviary.android.feather.effects.TiltShiftPanel.java
com.aviary.android.feather.graphics.CdsPreviewTransformer.java
com.aviary.android.feather.graphics.GalleryBottomIndicatorDrawable.java
com.aviary.android.feather.graphics.GalleryTopIndicatorDrawable.java
com.aviary.android.feather.graphics.GlowBitmapDrawable.java
com.aviary.android.feather.graphics.GlowDrawable.java
com.aviary.android.feather.graphics.PluginDividerDrawable.java
com.aviary.android.feather.graphics.PreviewFillColorDrawable.java
com.aviary.android.feather.graphics.PreviewSpotDrawable.java
com.aviary.android.feather.graphics.RepeatableHorizontalDrawable.java
com.aviary.android.feather.opengl.AviaryGLSurfaceView.java
com.aviary.android.feather.utils.PackIconCallable.java
com.aviary.android.feather.utils.SimpleBitmapCache.java
com.aviary.android.feather.utils.ThreadUtils.java
com.aviary.android.feather.utils.TypefaceUtils.java
com.aviary.android.feather.utils.UIUtils.java
com.aviary.android.feather.widget.AdjustImageView.java
com.aviary.android.feather.widget.AviaryAbsSpinner.java
com.aviary.android.feather.widget.AviaryAdapterView.java
com.aviary.android.feather.widget.AviaryBadgeToolLayout.java
com.aviary.android.feather.widget.AviaryBottomBarViewFlipper.java
com.aviary.android.feather.widget.AviaryButton.java
com.aviary.android.feather.widget.AviaryEdgeEffect.java
com.aviary.android.feather.widget.AviaryGalleryTopIndicatorView.java
com.aviary.android.feather.widget.AviaryGallery.java
com.aviary.android.feather.widget.AviaryHighlightImageButton.java
com.aviary.android.feather.widget.AviaryImageRestoreSwitcher.java
com.aviary.android.feather.widget.AviaryImageSwitcher.java
com.aviary.android.feather.widget.AviaryNavBarViewFlipper.java
com.aviary.android.feather.widget.AviarySeekBar.java
com.aviary.android.feather.widget.AviaryTextView.java
com.aviary.android.feather.widget.AviaryToast.java
com.aviary.android.feather.widget.AviaryToggleButton.java
com.aviary.android.feather.widget.AviaryWheel.java
com.aviary.android.feather.widget.AviaryWorkspaceIndicator.java
com.aviary.android.feather.widget.AviaryWorkspace.java
com.aviary.android.feather.widget.CellLayout.java
com.aviary.android.feather.widget.CropImageView.java
com.aviary.android.feather.widget.DrawableHighlightView.java
com.aviary.android.feather.widget.EffectThumbLayout.java
com.aviary.android.feather.widget.HighlightView.java
com.aviary.android.feather.widget.IAPBuyButton.java
com.aviary.android.feather.widget.IAPDialogDetail.java
com.aviary.android.feather.widget.IAPDialogList.java
com.aviary.android.feather.widget.IAPDialogMain.java
com.aviary.android.feather.widget.ImageViewDrawableOverlay.java
com.aviary.android.feather.widget.ImageViewSpotDraw.java
com.aviary.android.feather.widget.ImageViewTiltiShiftTouch.java
com.aviary.android.feather.widget.ImageViewTouchAndDraw.java
com.aviary.android.feather.widget.PointCloud.java
com.aviary.android.feather.widget.ScrollerRunnable.java
com.aviary.android.feather.widget.VibrationHelper.java
com.aviary.android.feather.widget.VibrationWidget.java