FileDocCategorySizeDatePackage
GearsBaseDialog.javaAPI DocAndroid 1.5 API12950Wed May 06 22:42:42 BST 2009com.android.browser

GearsBaseDialog

public class GearsBaseDialog extends Object
Base dialog class for gears

Fields Summary
private static final String
TAG
protected android.os.Handler
mHandler
protected android.app.Activity
mActivity
protected String
mDialogArguments
private android.graphics.Bitmap
mIcon
private final int
MAX_ICON_SIZE
protected int
mChoosenIconSize
public static final int
CANCEL
public static final int
ALWAYS_DENY
public static final int
ALLOW
public static final int
DENY
public static final int
NEW_ICON
public static final int
UPDATE_ICON
public static final int
REQUEST_ICON
public static final int
PAUSE_REQUEST_ICON
public static final int
CLEAR_REQUEST_ICON
protected final String
LOCAL_DATA_STRING
protected final String
LOCAL_STORAGE_STRING
protected final String
LOCATION_DATA_STRING
protected String
mGearsVersion
protected boolean
mDebug
Constructors Summary
public GearsBaseDialog(android.app.Activity activity, android.os.Handler handler, String arguments)


         
    mActivity = activity;
    mHandler = handler;
    mDialogArguments = arguments;
  
Methods Summary
public java.lang.StringcloseDialog(int closingType)

    return null;
  
voiddisplayAsLink(android.widget.Button button)
Display a button as an HTML link. Remove the background, set the text color to R.color.dialog_link and draw an underline

    if (button == null) {
      return;
    }

    CharSequence text = button.getText();
    button.setBackgroundDrawable(null);
    int color = getResources().getColor(R.color.dialog_link);
    button.setTextColor(color);
    SpannableString str = new SpannableString(text);
    str.setSpan(new UnderlineSpan(), 0, str.length(),
                Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    button.setText(str);
    button.setFocusable(false);
  
voiddownloadIcon(java.lang.String url)
Utility method to download an icon from a url and set it to the GUI element R.id.origin_icon. It is used both in the shortcut dialog and the permission dialog. The actual download is done in the background via IconDownload; once the icon is downlowded the UI is updated via updateIcon(). The icon size is included in the layout with the choosen size, although not displayed, to limit text reflow once the icon is received.

    if (url == null) {
      return;
    }
    View view = findViewById(R.id.origin_icon);
    if (view != null) {
      view.setMinimumWidth(mChoosenIconSize);
      view.setMinimumHeight(mChoosenIconSize);
      view.setVisibility(View.INVISIBLE);
    }
    Thread thread = new Thread(new IconDownload(url));
    thread.start();
  
android.view.ViewfindViewById(int id)

    return mActivity.findViewById(id);
  
android.content.res.ResourcesgetResources()

    return mActivity.getResources();
  
private java.lang.StringgetString(int id)

    return mActivity.getString(id);
  
java.lang.ObjectgetSystemService(java.lang.String name)

    return mActivity.getSystemService(name);
  
public booleanhandleBackButton()
Method called when the back button is pressed, allowing the dialog to intercept the default behaviour.

    return false;
  
voidhideView(android.view.View v, int rsc)
Utility method to hide a view.

    if (rsc == 0) {
      return;
    }
    View view;
    if (v == null) {
      view = findViewById(rsc);
    } else {
      view = v.findViewById(rsc);
    }
    if (view != null) {
      view.setVisibility(View.GONE);
    }
  
voidinflate(int layout, int viewID)
Inflate a given layout in a view (which has to be a ViewGroup, e.g. LinearLayout). This is used to share the basic dialog outline among the different dialog types.

    LayoutInflater inflater = (LayoutInflater) getSystemService(
        Context.LAYOUT_INFLATER_SERVICE);
    View view = findViewById(viewID);
    if (view != null) {
      try {
        ViewGroup viewGroup = (ViewGroup) view;
        inflater.inflate(layout, viewGroup);
      } catch (ClassCastException e) {
        String msg = "exception, the view (" + view + ")";
        msg += " is not a ViewGroup";
        Log.e(TAG, msg, e);
      } catch (InflateException e) {
        Log.e(TAG, "exception while inflating the layout", e);
      }
    } else {
      String msg = "problem, trying to inflate a non-existent view";
      msg += " (" + viewID + ")";
      Log.e(TAG, msg);
    }
  
public intnotification()
Returns the resource string of the notification displayed after the dialog. By default, does not return one.

    return 0;
  
public android.app.DialogonCreateDialog(int id)
If a secondary dialog (e.g. a confirmation dialog) is created, GearsNativeDialog will call this method.

    // This should be redefined by subclasses as needed.
    return null;
  
public voidsetDebug(boolean debug)

    mDebug = debug;
  
public voidsetGearsVersion(java.lang.String version)

    mGearsVersion = version;
  
voidsetLabel(org.json.JSONObject json, java.lang.String name, int rsc)
Utility method to set elements' text indicated in the dialogs' arguments.

    try {
      if (json.has(name)) {
        String text = json.getString(name);
        View view = findViewById(rsc);
        if (view != null && text != null) {
          TextView textView = (TextView) view;
          textView.setText(text);
          textView.setVisibility(View.VISIBLE);
        }
      }
    } catch (JSONException e) {
      Log.e(TAG, "json exception", e);
    }
  
voidsetText(android.view.View v, int rsc, java.lang.CharSequence text)
Utility method to set a text.

    if (rsc == 0) {
      return;
    }
    View view = v.findViewById(rsc);
    if (view != null) {
      TextView textView = (TextView) view;
      textView.setText(text);
      textView.setVisibility(View.VISIBLE);
    }
  
voidsetText(android.view.View v, int rsc, int txtRsc)
Utility method to set a text.

    if (rsc == 0) {
      return;
    }
    View view = v.findViewById(rsc);
    if (view != null) {
      TextView textView = (TextView) view;
      if (txtRsc == 0) {
        textView.setVisibility(View.GONE);
      } else {
        CharSequence text = getString(txtRsc);
        textView.setText(text);
        textView.setVisibility(View.VISIBLE);
      }
    }
  
public voidsetup()
Setup the dialog By default, just display a simple message.

    setupButtons(0, 0, R.string.default_button);
    setupDialog();
  
voidsetupButton(int buttonRscID, int rscString, View.OnClickListener listener, boolean isLink, boolean requestFocus)
Button setup. Set the button's text and its listener. If the text resource's id is 0, makes the button invisible.

    View view = findViewById(buttonRscID);
    if (view == null) {
      return;
    }

    Button button = (Button) view;

    if (rscString == 0) {
      button.setVisibility(View.GONE);
    } else {
      CharSequence text = getString(rscString);
      button.setText(text);
      button.setOnClickListener(listener);
      if (isLink) {
        displayAsLink(button);
      }
      if (requestFocus) {
        button.requestFocus();
      }
    }
  
voidsetupButton(int buttonRsc, int rsc, View.OnClickListener listener)
Button setup: as the above method, except that 'isLink' and 'requestFocus' default to false.

    setupButton(buttonRsc, rsc, listener, false, false);
  
voidsetupButtons(int alwaysDenyRsc, int allowRsc, int denyRsc)
Utility method to setup the three dialog buttons.

    setupButton(R.id.button_alwaysdeny, alwaysDenyRsc,
                new Button.OnClickListener() {
                  public void onClick(View v) {
                    mHandler.sendEmptyMessage(ALWAYS_DENY);
                  }
                });

    setupButton(R.id.button_allow, allowRsc,
                new Button.OnClickListener() {
                  public void onClick(View v) {
                    mHandler.sendEmptyMessage(ALLOW);
                  }
                });

    setupButton(R.id.button_deny, denyRsc,
                new Button.OnClickListener() {
                  public void onClick(View v) {
                    mHandler.sendEmptyMessage(DENY);
                  }
                });
  
public voidsetupDialog()
Utility method that get the dialogMessage and icon and ask the setupDialog(message,icon) method to set the values.

    TextView dialogMessage = null;
    ImageView icon = null;

    View view = findViewById(R.id.dialog_message);
    if (view != null) {
      dialogMessage = (TextView) view;
    }

    View iconView = findViewById(R.id.icon);
    if (iconView != null) {
      icon = (ImageView) iconView;
    }

    if ((dialogMessage != null) && (icon != null)) {
      setupDialog(dialogMessage, icon);
      dialogMessage.setVisibility(View.VISIBLE);
    }
  
public voidsetupDialog(android.widget.TextView message, android.widget.ImageView icon)

    message.setText(R.string.unrecognized_dialog_message);
    icon.setImageResource(R.drawable.ic_dialog_menu_generic);
    message.setVisibility(View.VISIBLE);
  
voidshowView(android.view.View v, int rsc)
Utility method to show a view.

    if (rsc == 0) {
      return;
    }
    View view;
    if (v == null) {
      view = findViewById(rsc);
    } else {
      view = v.findViewById(rsc);
    }
    if (view != null) {
      view.setVisibility(View.VISIBLE);
    }
  
public voidupdateIcon()
Utility method to update the icon. Called on the UI thread.

    if (mIcon == null) {
      return;
    }
    View view = findViewById(R.id.origin_icon);
    if (view != null) {
      ImageView imageView = (ImageView) view;
      imageView.setMaxHeight(MAX_ICON_SIZE);
      imageView.setMaxWidth(MAX_ICON_SIZE);
      imageView.setScaleType(ImageView.ScaleType.FIT_XY);
      imageView.setImageBitmap(mIcon);
      imageView.setVisibility(View.VISIBLE);
    }