LaunchInteractionDialog.java
Go to the documentation of this file.
00001 package com.github.rosjava.android_remocons.rocon_remocon.dialogs;
00002 
00007 import android.app.Activity;
00008 import android.app.AlertDialog;
00009 import android.graphics.Bitmap;
00010 import android.graphics.BitmapFactory;
00011 import android.graphics.drawable.BitmapDrawable;
00012 import android.util.Log;
00013 
00014 import org.jboss.netty.buffer.ChannelBuffer;
00015 
00019 public class LaunchInteractionDialog extends AlertDialogWrapper {
00020     public LaunchInteractionDialog(Activity context) {
00021         super(context, new AlertDialog.Builder(context), "Launch", "Cancel");
00022     }
00023 
00024     public void setup(rocon_interaction_msgs.Interaction app, boolean allowed, String reason) {
00025 
00026         boolean hasValidIcon = false;
00027         String iconFormat = app.getIcon().getFormat();
00028         ChannelBuffer buffer = app.getIcon().getData();
00029 
00030         if (buffer.array().length > 0 && iconFormat != null &&
00031            (iconFormat.equals("jpeg") || iconFormat.equals("png"))) {
00032             Bitmap bitmap =
00033                     BitmapFactory.decodeByteArray(buffer.array(), buffer.arrayOffset(), buffer.readableBytes());
00034             if (bitmap != null) {
00035                 Bitmap iconBitmap = Bitmap.createScaledBitmap(bitmap, 180, 180, false);
00036                 dialog.setIcon(new BitmapDrawable(context.getResources(), iconBitmap));
00037                 hasValidIcon = true;
00038             }
00039         }
00040 
00041         if (! hasValidIcon) {
00042             // dialog.setIcon(context.getResources().getDrawable(R.drawable.question_mark));
00043             // TODO default image?  concert icon?
00044         }
00045 
00046         dialog.setTitle(app.getDisplayName());
00047 
00048         if (allowed) {
00049             Log.i("Remocon", "This interaction is permitted [" + reason + "]");
00050             dialog.setMessage(app.getDescription() + "\n\nLovely, you are allowed to launch this interaction.");
00051             enablePositive = true;
00052         }
00053         else {
00054             Log.i("Remocon", "This interaction is not permitted [" + reason + "]");
00055             dialog.setMessage(app.getDescription() + "\n\nDude, this is not allowed - what did you do?\n" + reason);
00056             enablePositive = false;
00057         }
00058     }
00059 }


android_remocons
Author(s): Daniel Stonier, Kazuto Murase
autogenerated on Sat Jun 8 2019 19:32:24