/**
     * Get the {@link Entry} best associated with the given {@link Action}, or create and populate a
     * new one if it doesn't exist.
     */
    protected Entry getEntry(Action action) {
      final String mimeType = action.getMimeType();
      Entry entry = mCache.get(mimeType);
      if (entry != null) return entry;
      entry = new Entry();

      final Intent intent = action.getIntent();
      if (intent != null) {
        final List<ResolveInfo> matches =
            mPackageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

        // Pick first match, otherwise best found
        ResolveInfo bestResolve = null;
        final int size = matches.size();
        if (size == 1) {
          bestResolve = matches.get(0);
        } else if (size > 1) {
          bestResolve = getBestResolve(intent, matches);
        }

        if (bestResolve != null) {
          final Drawable icon = bestResolve.loadIcon(mPackageManager);

          entry.bestResolve = bestResolve;
          entry.icon = new SoftReference<Drawable>(icon);
        }
      }

      mCache.put(mimeType, entry);
      return entry;
    }
  /** {@inheritDoc} */
  public void onClick(View view) {
    final boolean isActionView = (view instanceof CheckableImageView);
    final CheckableImageView actionView = isActionView ? (CheckableImageView) view : null;
    final Object tag = view.getTag();
    if (tag instanceof Action) {
      // Incoming tag is concrete intent, so try launching
      final Action action = (Action) tag;
      final boolean makePrimary = mMakePrimary;

      try {
        mContext.startActivity(action.getIntent());
      } catch (ActivityNotFoundException e) {
        Toast.makeText(mContext, R.string.quickcontact_missing_app, Toast.LENGTH_SHORT).show();
      }

      // Hide the resolution list, if present
      setResolveVisible(false, null);
      this.dismiss();

      if (makePrimary) {
        ContentValues values = new ContentValues(1);
        values.put(Data.IS_SUPER_PRIMARY, 1);
        final Uri dataUri = action.getDataUri();
        if (dataUri != null) {
          mContext.getContentResolver().update(dataUri, values, null, null);
        }
      }
    } else if (tag instanceof ActionList) {
      // Incoming tag is a MIME-type, so show resolution list
      final ActionList children = (ActionList) tag;

      // Show resolution list and set adapter
      setResolveVisible(true, actionView);

      mResolveList.setOnItemClickListener(this);
      mResolveList.setAdapter(
          new BaseAdapter() {
            public int getCount() {
              return children.size();
            }

            public Object getItem(int position) {
              return children.get(position);
            }

            public long getItemId(int position) {
              return position;
            }

            public View getView(int position, View convertView, ViewGroup parent) {
              if (convertView == null) {
                convertView = mInflater.inflate(R.layout.quickcontact_resolve_item, parent, false);
              }

              // Set action title based on summary value
              final Action action = (Action) getItem(position);

              TextView text1 = (TextView) convertView.findViewById(android.R.id.text1);
              TextView text2 = (TextView) convertView.findViewById(android.R.id.text2);

              text1.setText(action.getHeader());
              text2.setText(action.getBody());

              convertView.setTag(action);
              return convertView;
            }
          });

      // Make sure we resize to make room for ListView
      mDecor.forceLayout();
      mDecor.invalidate();
    }
  }