/**
   * Calculate sections of the list
   *
   * @param addSeparators True to add GUI-level separators, false to just populate the cache
   */
  private void calculateSections(boolean addSeparators) {
    char prevFirstChar = 'a';
    boolean firstSeparator = true;

    for (int i = 0; i < mItems.size(); ++i) {
      String title = mItems.get(i).mTitle;
      char firstChar;
      if (title.length() > 0) firstChar = title.toUpperCase(Locale.ENGLISH).charAt(0);
      else firstChar = '#'; // Blank / spaces-only song title.

      if (Character.isLetter(firstChar)) {
        if (firstSeparator || firstChar != prevFirstChar) {
          if (addSeparators) {
            ListItem item = new ListItem(String.valueOf(firstChar), null, null, true);
            mItems.add(i, item);
            mSections.put(i, String.valueOf(firstChar));
            i++;
          } else mSections.put(i, String.valueOf(firstChar));
          prevFirstChar = firstChar;
          firstSeparator = false;
        }
      } else if (firstSeparator) {
        if (addSeparators) {
          ListItem item = new ListItem("#", null, null, true);
          mItems.add(i, item);
          mSections.put(i, "#");
          i++;
        } else mSections.put(i, "#");
        prevFirstChar = firstChar;
        firstSeparator = false;
      }
    }
  }
  static {
    sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    sMimeTypes = new SparseArray<String>();
    sUriMatcher.addURI(
        SmartKidContract.HomeSameCityList.AUTHORITY,
        SmartKidContract.HomeSameCityList.TABLE_NAME,
        1);
    sUriMatcher.addURI(
        SmartKidContract.HomeSameCityList.AUTHORITY,
        SmartKidContract.HomeSameCityList.TABLE_NAME + "/#",
        2);

    sMimeTypes.put(
        1,
        "vnd.android.cursor.dir/vnd."
            + SmartKidContract.HomeSameCityList.AUTHORITY
            + "."
            + SmartKidContract.HomeSameCityList.TABLE_NAME);
    sMimeTypes.put(
        2,
        "vnd.android.cursor.item/vnd."
            + SmartKidContract.HomeSameCityList.AUTHORITY
            + "."
            + SmartKidContract.HomeSameCityList.TABLE_NAME);
  }
  /**
   * Creates the list of {@link PhotoBoothModeAdapter.Mode} for the selection ui.
   *
   * @param context the {@link Context}.
   * @return the {@link SparseArray} of {@link PhotoBoothModeAdapter.Mode}.
   */
  private static SparseArray<PhotoBoothModeAdapter.Mode> createItems(Context context) {
    SparseArray<PhotoBoothModeAdapter.Mode> modes = new SparseArray<PhotoBoothModeAdapter.Mode>();

    // Add self-serve mode.
    PhotoBoothModeAdapter.Mode selfServeMode = new PhotoBoothModeAdapter.Mode();
    selfServeMode.mMode = PhotoBoothMode.SELF_SERVE;
    selfServeMode.mDisplayName =
        context.getString(R.string.photo_booth_mode_adapter__self_serve_display_name);
    selfServeMode.mDescription =
        context.getString(R.string.photo_booth_mode_adapter__self_serve_description);
    modes.put(PhotoBoothMode.SELF_SERVE.ordinal(), selfServeMode);

    // Add automatic mode.
    PhotoBoothModeAdapter.Mode automaticMode = new PhotoBoothModeAdapter.Mode();
    automaticMode.mMode = PhotoBoothMode.AUTOMATIC;
    automaticMode.mDisplayName =
        context.getString(R.string.photo_booth_mode_adapter__automatic_display_name);
    automaticMode.mDescription =
        context.getString(R.string.photo_booth_mode_adapter__automatic_description);
    modes.put(PhotoBoothMode.AUTOMATIC.ordinal(), automaticMode);

    // Add photographer mode.
    PhotoBoothModeAdapter.Mode photographerMode = new PhotoBoothModeAdapter.Mode();
    photographerMode.mMode = PhotoBoothMode.PHOTOGRAPHER;
    photographerMode.mDisplayName =
        context.getString(R.string.photo_booth_mode_adapter__photographer_display_name);
    photographerMode.mDescription =
        context.getString(R.string.photo_booth_mode_adapter__photographer_description);
    modes.put(PhotoBoothMode.PHOTOGRAPHER.ordinal(), photographerMode);

    return modes;
  }
  public SparseArray<String> getUnreadItemCountForFolder(Context mContext) {
    String buildSQL =
        "SELECT f.rowid, COUNT("
            + RSS_ITEM_RSSITEM_ID
            + ")"
            + " FROM "
            + RSS_ITEM_TABLE
            + " rss "
            + " JOIN "
            + SUBSCRIPTION_TABLE
            + " st ON rss."
            + RSS_ITEM_SUBSCRIPTION_ID
            + " = st.rowid"
            + " JOIN "
            + FOLDER_TABLE
            + " f ON st."
            + SUBSCRIPTION_FOLDER_ID
            + " = f.rowid"
            + " WHERE "
            + RSS_ITEM_READ_TEMP
            + " != 1 "
            + " GROUP BY f."
            + FOLDER_LABEL_ID;

    SparseArray<String> values = getSparseArrayFromSQL(buildSQL, 0, 1);

    values.put(
        ALL_UNREAD_ITEMS.getValue(),
        new UnreadFolderCount(mContext, ALL_UNREAD_ITEMS.getValueString()).getText());
    values.put(
        ALL_STARRED_ITEMS.getValue(),
        new UnreadFolderCount(mContext, ALL_STARRED_ITEMS.getValueString()).getText());

    return values;
  }
  /**
   * 读取本应用 日志信息 ,需要 读日志权限
   *
   * @param baos
   * @param levels
   * @return
   */
  public static boolean readApplicationLogs(ByteArrayOutputStream baos, int... levels) {
    // "logcat *:e *:w | grep \"("+mPID+")\""
    if (levels == null) {
      throw new IllegalArgumentException("argument levels should not be null");
    }
    StringBuilder sb = new StringBuilder();

    SparseArray<String> pArray = new SparseArray<String>(6);
    pArray.put(Log.DEBUG, "*:D");
    pArray.put(Log.ERROR, "*:E");
    pArray.put(Log.INFO, "*:I");
    pArray.put(Log.VERBOSE, "*:V");
    pArray.put(Log.WARN, "*:W");
    pArray.put(Log.ASSERT, "*:A");

    for (int i = 0; i < levels.length; i++) {
      String c = pArray.get(levels[i]);
      if (c != null) {
        sb.append(c).append(' ');
      }
    }

    i(TAG);

    String cmd = String.format("logcat -d %s| grep \"\\[%s\\]\"", sb, APP_PACKAGE);
    return readApplicationLogs(baos, cmd);
  }
  @Test
  public void testAssertSparseArrayArrayEquals() {
    final SparseArray<Date> sparseBooleanArray = new SparseArray<>();
    sparseBooleanArray.put(3, new Date(10));
    sparseBooleanArray.put(1, new Date(100));

    SparseAsserts.assertSparseArrayEquals(sparseBooleanArray, sparseBooleanArray);
  }
示例#7
0
 static {
   sPositionMappedStringResourceIds.put(11, R.string.value_plus);
   sPositionMappedStringResourceIds.put(114, R.string.value_plus);
   sPositionMappedStringResourceIds.put(112, R.string.value_minus);
   sPositionMappedStringResourceIds.put(116, R.string.value_minus);
   sPositionMappedStringResourceIds.put(111, R.string.value_hours);
   sPositionMappedStringResourceIds.put(115, R.string.value_minutes);
 }
 static {
   VIDEO_HEIGHT_TO_FORMAT_MAP.put(480, TvContract.Channels.VIDEO_FORMAT_480P);
   VIDEO_HEIGHT_TO_FORMAT_MAP.put(576, TvContract.Channels.VIDEO_FORMAT_576P);
   VIDEO_HEIGHT_TO_FORMAT_MAP.put(720, TvContract.Channels.VIDEO_FORMAT_720P);
   VIDEO_HEIGHT_TO_FORMAT_MAP.put(1080, TvContract.Channels.VIDEO_FORMAT_1080P);
   VIDEO_HEIGHT_TO_FORMAT_MAP.put(2160, TvContract.Channels.VIDEO_FORMAT_2160P);
   VIDEO_HEIGHT_TO_FORMAT_MAP.put(4320, TvContract.Channels.VIDEO_FORMAT_4320P);
 }
示例#9
0
 private void initOperateStep() {
   mOpreateSparse.put(R.id.activity_edit_info_bt_info_save, getString(R.string.save));
   mOpreateSparse.put(
       R.id.activity_edit_info_lay_choose_model, getString(R.string.select_vehicle_model));
   mOpreateSparse.put(
       R.id.activity_edit_info_lay_choose_length, getString(R.string.select_vehicle_length));
   mOpreateSparse.put(
       R.id.activity_edit_info_lay_choose_load, getString(R.string.select_vehicle_load));
 }
    @Override
    public void setInForeground(int pid, boolean inForeground) {
      mProcessInForegroundMap.put(pid, inForeground);

      if (inForeground) {
        mVisibilityCallsMap.put(pid, mVisibilityCallsMap.get(pid) + "FG;");
      } else {
        mVisibilityCallsMap.put(pid, mVisibilityCallsMap.get(pid) + "BG;");
      }
    }
示例#11
0
 @Override
 public void startElement(
     String nsURI, String strippedName, String tagName, Attributes attributes)
     throws SAXException {
   strippedName = strippedName.trim();
   String name = strippedName.length() == 0 ? tagName.trim() : strippedName;
   if (inAcross) {
     int clueNum = Integer.parseInt(attributes.getValue("cn"));
     if (clueNum > maxClueNum) {
       maxClueNum = clueNum;
     }
     try {
       acrossNumToClueMap.put(
           clueNum, URLDecoder.decode(attributes.getValue("c"), CHARSET_NAME));
     } catch (UnsupportedEncodingException e) {
       acrossNumToClueMap.put(clueNum, attributes.getValue("c"));
     }
   } else if (inDown) {
     int clueNum = Integer.parseInt(attributes.getValue("cn"));
     if (clueNum > maxClueNum) {
       maxClueNum = clueNum;
     }
     try {
       downNumToClueMap.put(clueNum, URLDecoder.decode(attributes.getValue("c"), CHARSET_NAME));
     } catch (UnsupportedEncodingException e) {
       downNumToClueMap.put(clueNum, attributes.getValue("c"));
     }
   } else if (name.equalsIgnoreCase("title")) {
     puz.setTitle(attributes.getValue("v"));
   } else if (name.equalsIgnoreCase("author")) {
     puz.setAuthor(attributes.getValue("v"));
   } else if (name.equalsIgnoreCase("width")) {
     puz.setWidth(Integer.parseInt(attributes.getValue("v")));
   } else if (name.equalsIgnoreCase("height")) {
     puz.setHeight(Integer.parseInt(attributes.getValue("v")));
   } else if (name.equalsIgnoreCase("allanswer")) {
     String rawGrid = attributes.getValue("v");
     Box[] boxesList = new Box[puz.getHeight() * puz.getWidth()];
     for (int i = 0; i < rawGrid.length(); i++) {
       char sol = rawGrid.charAt(i);
       if (sol != '-') {
         boxesList[i] = new Box();
         boxesList[i].setSolution(sol);
         boxesList[i].setResponse(' ');
       }
     }
     puz.setBoxesList(boxesList);
     puz.setBoxes(puz.buildBoxes());
   } else if (name.equalsIgnoreCase("across")) {
     inAcross = true;
   } else if (name.equalsIgnoreCase("down")) {
     inDown = true;
   }
 }
 private void addToHistogram(SparseArray<Integer> histogram, DiskStorage.DiskDumpInfoEntry entry) {
   for (int i = 0; i < histogram.size(); i++) {
     int key = histogram.keyAt(i);
     if (entry.size / KB < key) {
       histogram.put(key, histogram.get(key) + 1);
       return;
     }
   }
   // big
   histogram.put((int) (entry.size / KB), 1);
 }
示例#13
0
  private void addNewItems() {

    currentChildCount = getChildCount();
    parentLayout = false;
    int start = itemIds.size();
    int end = Math.min(start + screenMaxColumns * rows * 2, adapter.getCount());

    for (int i = start; i < end; i++) {
      int left = (i / rows) * (itemWidth + spaceHori);
      int top = (i % rows) * (spaceVert + itemHeight);
      RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(itemWidth, itemHeight);
      rlp.setMargins(left, top, 0, 0);
      View child = adapter.getView(i, null, this);
      this.addView(child, rlp);
      int viewId = child.getId();
      if (viewId == -1) {
        viewId = TvUtil.buildId();
        // 此处硬设置id同时建议开发者不用此范围id
      }
      child.setId(viewId);
      itemIds.put(viewId, i);
      bindEventOnChild(child, i);
      layoutFlag = true;
    }

    colCount = itemIds.size() % rows == 0 ? itemIds.size() / rows : itemIds.size() / rows + 1;
  }
示例#14
0
  public TkVoiceCmd(TkNotificationSpeaker speaker) {
    BaseCmd cmd = null;

    m_command_list = new SparseArray<BaseCmd>();

    cmd = new StopCmd(speaker);
    m_command_list.put(cmd.getCmdId(), cmd);
    cmd = new RepeatCmd(speaker);
    m_command_list.put(cmd.getCmdId(), cmd);
    cmd = new StopCmd(speaker);
    m_command_list.put(cmd.getCmdId(), cmd);
    cmd = new NextCmd(speaker);
    m_command_list.put(cmd.getCmdId(), cmd);
    cmd = new BackCmd(speaker);
    m_command_list.put(cmd.getCmdId(), cmd);
  }
示例#15
0
  /** Move all views remaining in activeViews to scrapViews. */
  void scrapActiveViews() {
    final View[] activeViews = this.activeViews;
    final int[] activeViewTypes = this.activeViewTypes;
    final boolean multipleScraps = viewTypeCount > 1;

    SparseArray<View> scrapViews = currentScrapViews;
    final int count = activeViews.length;
    for (int i = count - 1; i >= 0; i--) {
      final View victim = activeViews[i];
      if (victim != null) {
        int whichScrap = activeViewTypes[i];

        activeViews[i] = null;
        activeViewTypes[i] = -1;

        if (!shouldRecycleViewType(whichScrap)) {
          continue;
        }

        if (multipleScraps) {
          scrapViews = this.scrapViews[whichScrap];
        }
        scrapViews.put(i, victim);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
          victim.setAccessibilityDelegate(null);
        }
      }
    }

    pruneScrapViews();
  }
示例#16
0
  private Map<String, List<Map<String, Object>>> getOrderSummary() {
    Map<String, List<Map<String, Object>>> summaryCategoryGrouping =
        new HashMap<String, List<Map<String, Object>>>();

    int orderLen = mOrderSelections.size();
    for (int idx = 0; idx < orderLen; idx++) {
      // the keys have no importance; we just want access to the elements
      Map<String, Object> selection = mOrderSelections.get(idx);
      String category = (String) selection.get(OrderFeature.CATEGORY);
      int categoryId = (Integer) selection.get(OrderFeature.ITEM_CATEGORY_ID);

      if (summaryCategoryGrouping.containsKey(category)) {
        summaryCategoryGrouping.get(category).add(selection);
      } else {
        // append to list of menu categories and start new list in
        // category grouping summary
        mOrderCategories.put(categoryId, category);
        List<Map<String, Object>> categorySelectedItemList = new ArrayList<Map<String, Object>>();
        categorySelectedItemList.add(selection);

        summaryCategoryGrouping.put(category, categorySelectedItemList);
      }
    }

    return summaryCategoryGrouping;
  }
 /**
  * 添加一次性事件
  *
  * @param nEventCode
  */
 protected void addOncesEventListener(int nEventCode) {
   if (codeToListenerMap == null) {
     codeToListenerMap = new SparseArray<OnEventListener>();
   }
   codeToListenerMap.put(nEventCode, this);
   AndroidEventManager.getInstance().addEventListener(nEventCode, this, true);
 }
 /**
  * Read as much as possible from the tag with the given key information.
  *
  * @param keyMap Keys (A and B) mapped to a sector. See {@link #buildNextKeyMapPart()}.
  * @return A Key-Value Pair. Keys are the sector numbers, values are the tag data. This tag data
  *     (values) are arrays containing one block per field (index 0-3 or 0-15). If a block is
  *     "null" it means that the block couldn't be read with the given key information.<br>
  *     On Error "null" will be returned (tag was removed during reading or keyMap is null). If
  *     none of the keys in the key map is valid for reading and therefore no sector is read, an
  *     empty set (SparseArray.size() == 0) will be returned.
  * @see #buildNextKeyMapPart()
  */
 public SparseArray<String[]> readAsMuchAsPossible(SparseArray<byte[][]> keyMap) {
   SparseArray<String[]> ret = null;
   if (keyMap != null && keyMap.size() > 0) {
     ret = new SparseArray<String[]>(keyMap.size());
     // For all entries in map do:
     for (int i = 0; i < keyMap.size(); i++) {
       String[][] results = new String[2][];
       try {
         if (keyMap.valueAt(i)[0] != null) {
           // Read with key A.
           results[0] = readSector(keyMap.keyAt(i), keyMap.valueAt(i)[0], false);
         }
         if (keyMap.valueAt(i)[1] != null) {
           // Read with key B.
           results[1] = readSector(keyMap.keyAt(i), keyMap.valueAt(i)[1], true);
         }
       } catch (TagLostException e) {
         return null;
       }
       // Merge results.
       if (results[0] != null || results[1] != null) {
         ret.put(keyMap.keyAt(i), mergeSectorData(results[0], results[1]));
       }
     }
     return ret;
   }
   return ret;
 }
 private int getResourceForMedia(Resources resources, Uri uri) {
   int drawable = 0;
   if (uri.getScheme().equals("file")) {
     if (uri.getLastPathSegment().endsWith("3gp")) {
       drawable = R.drawable.media_film;
     } else if (uri.getLastPathSegment().endsWith("jpg")) {
       drawable = R.drawable.media_camera;
     } else if (uri.getLastPathSegment().endsWith("txt")) {
       drawable = R.drawable.media_notepad;
     }
   } else if (uri.getScheme().equals("content")) {
     if (uri.getAuthority().equals(GPStracking.AUTHORITY + ".string")) {
       drawable = R.drawable.media_mark;
     } else if (uri.getAuthority().equals("media")) {
       drawable = R.drawable.media_speech;
     }
   }
   synchronized (sBitmapCache) {
     if (sBitmapCache.get(drawable) == null) {
       Bitmap bitmap = BitmapFactory.decodeResource(resources, drawable);
       sBitmapCache.put(drawable, bitmap);
     }
   }
   return drawable;
 }
    private void registerClientLocked(IMediaRouterClient client,
            int pid, String packageName, int userId, boolean trusted) {
        final IBinder binder = client.asBinder();
        ClientRecord clientRecord = mAllClientRecords.get(binder);
        if (clientRecord == null) {
            boolean newUser = false;
            UserRecord userRecord = mUserRecords.get(userId);
            if (userRecord == null) {
                userRecord = new UserRecord(userId);
                newUser = true;
            }
            clientRecord = new ClientRecord(userRecord, client, pid, packageName, trusted);
            try {
                binder.linkToDeath(clientRecord, 0);
            } catch (RemoteException ex) {
                throw new RuntimeException("Media router client died prematurely.", ex);
            }

            if (newUser) {
                mUserRecords.put(userId, userRecord);
                initializeUserLocked(userRecord);
            }

            userRecord.mClientRecords.add(clientRecord);
            mAllClientRecords.put(binder, clientRecord);
            initializeClientLocked(clientRecord);
        }
    }
  /**
   * See {@link UIManagerModule#addMeasuredRootView}.
   *
   * <p>Must be called from the UI thread.
   */
  public void addRootView(
      int tag, SizeMonitoringFrameLayout view, ThemedReactContext themedContext) {
    UiThreadUtil.assertOnUiThread();
    if (view.getId() != View.NO_ID) {
      throw new IllegalViewOperationException(
          "Trying to add a root view with an explicit id already set. React Native uses "
              + "the id field to track react tags and will overwrite this field. If that is fine, "
              + "explicitly overwrite the id field to View.NO_ID before calling addMeasuredRootView.");
    }

    mTagsToViews.put(tag, view);
    mTagsToViewManagers.put(tag, mRootViewManager);
    mRootTags.put(tag, true);
    mRootViewsContext.put(tag, themedContext);
    view.setId(tag);
  }
 private void loadWidgetsFromDisk() {
   if (!mNoteWidgetData.exists()) {
     return;
   }
   try {
     ObjectInputStream in = null;
     try {
       in = new ObjectInputStream(new FileInputStream(mNoteWidgetData));
       NoteWidget[] noteWidgets = (NoteWidget[]) in.readObject();
       synchronized (mWidgets) {
         mWidgets.clear();
         for (NoteWidget noteWidget : noteWidgets) {
           mWidgets.put(noteWidget.id, noteWidget);
         }
       }
     } finally {
       if (in != null) {
         in.close();
       }
     }
   } catch (ClassNotFoundException e) {
     mNoteWidgetData.delete();
   } catch (IOException e) {
     mNoteWidgetData.delete();
   }
 }
示例#23
0
 public int addPopup(
     View view, View anchor, int gravity, int offx, int offy, int width, int height) {
   if (view == null) {
     return 0;
   }
   int key = toKey(view);
   Log.d(TAG, "addPopup.key is:" + key);
   PopupWindow popupWindow = getWindow(key);
   if (popupWindow == null) {
     popupWindow = new PopupWindow(view);
     popupWindow.setWidth(width);
     popupWindow.setHeight(height);
     popupWindow.setFocusable(true);
     popupWindow.setOutsideTouchable(true);
     popupWindow.setTouchable(true);
     popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
     popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
     popupWindow.setAnimationStyle(R.style.popwindow_anim_style);
     GradientDrawable gd = createGradientDrawable();
     popupWindow.setBackgroundDrawable(gd);
     DismissLis dismisslis = new DismissLis(key);
     popupWindow.setOnDismissListener(dismisslis);
   }
   popupWindow.showAtLocation(anchor, gravity, offx, offy);
   popupWindows.put(key, popupWindow);
   return key;
 }
  @Override // Binder call
  public void registerCallback(IDisplayManagerCallback callback) {
    if (callback == null) {
      throw new IllegalArgumentException("listener must not be null");
    }

    synchronized (mSyncRoot) {
      int callingPid = Binder.getCallingPid();
      if (mCallbacks.get(callingPid) != null) {
        throw new SecurityException(
            "The calling process has already " + "registered an IDisplayManagerCallback.");
      }

      CallbackRecord record = new CallbackRecord(callingPid, callback);
      try {
        IBinder binder = callback.asBinder();
        binder.linkToDeath(record, 0);
      } catch (RemoteException ex) {
        // give up
        throw new RuntimeException(ex);
      }

      mCallbacks.put(callingPid, record);
    }
  }
 /**
  * Set a tag associated with this task, not be used by internal.
  *
  * @param key The key of identifying the tag. If the key already exists, the old data will be
  *     replaced.
  * @param tag An Object to tag the task with
  */
 public BaseDownloadTask setTag(final int key, final Object tag) {
   if (keyedTags == null) {
     keyedTags = new SparseArray<>(2);
   }
   keyedTags.put(key, tag);
   return this;
 }
  protected void setupSingleChoiceDialog(AlertDialog.Builder builder) {
    final List<ItemT> availableItems = getAvailableItems();

    final ItemPrinter<ItemT> ip = getItemPrinter();
    CharSequence[] items = new CharSequence[availableItems.size()];
    for (int i = 0; i < availableItems.size(); ++i) {
      items[i] = ip.itemToString(availableItems.get(i));
    }

    int checked = -1;
    if (selectedItems.size() > 0) {
      checked = selectedItems.keyAt(0);
      selectedItems.put(checked, getItemAt(checked));
    }

    builder.setSingleChoiceItems(
        items,
        checked,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            selectedItems.clear();
            selectedItems.put(which, getItemAt(which));
          }
        });
  }
示例#27
0
 /* package */ VirtualDisplayAndroid addVirtualDisplay() {
   VirtualDisplayAndroid display = new VirtualDisplayAndroid(getNextVirtualDisplayId());
   assert mIdMap.get(display.getDisplayId()) == null;
   mIdMap.put(display.getDisplayId(), display);
   updateDisplayOnNativeSide(display);
   return display;
 }
  /**
   * Used internally within {@link LocationManager} to copy GPS status data from the Location
   * Manager Service to its cached GpsStatus instance. Is synchronized to ensure that GPS status
   * updates are atomic.
   */
  synchronized void setStatus(
      int svCount,
      int[] prns,
      float[] snrs,
      float[] elevations,
      float[] azimuths,
      int ephemerisMask,
      int almanacMask,
      int usedInFixMask) {
    clearSatellites();
    for (int i = 0; i < svCount; i++) {
      int prn = prns[i];
      int prnShift = (1 << (prn - 1));
      if (prn > 0 && prn <= NUM_SATELLITES) {
        GpsSatellite satellite = mSatellites.get(prn);
        if (satellite == null) {
          satellite = new GpsSatellite(prn);
          mSatellites.put(prn, satellite);
        }

        satellite.mValid = true;
        satellite.mSnr = snrs[i];
        satellite.mElevation = elevations[i];
        satellite.mAzimuth = azimuths[i];
        satellite.mHasEphemeris = ((ephemerisMask & prnShift) != 0);
        satellite.mHasAlmanac = ((almanacMask & prnShift) != 0);
        satellite.mUsedInFix = ((usedInFixMask & prnShift) != 0);
      }
    }
  }
  /**
   * Start activity for result.
   *
   * @param intent Intent to start activity.
   * @param callback Result call-back.
   * @return Handle to this operation.
   */
  public Handle startActivityForResult(Intent intent, ActivityResultCallback callback) {
    // check parameter
    if (intent == null) {
      Log.e(TAG, "startActivityForResult() - No intent");
      return null;
    }

    // check state
    this.verifyAccess();

    // generate request code
    int requestCode = 64;
    for (; requestCode > 0; --requestCode) {
      if (m_ActivityResultHandles.get(requestCode) == null) break;
    }
    if (requestCode <= 0) {
      Log.e(TAG, "startActivityForResult() - No available request code");
      return null;
    }

    // create handle
    ActivityResultHandle handle = new ActivityResultHandle(callback);
    m_ActivityResultHandles.put(requestCode, handle);

    // start activity for result
    try {
      this.startActivityForResult(intent, requestCode);
      return handle;
    } catch (Throwable ex) {
      Log.e(TAG, "startActivityForResult() - Fail to start activity", ex);
      m_ActivityResultHandles.delete(requestCode);
      return null;
    }
  }
  /**
   * Used by {@link LocationManager#getGpsStatus} to copy LocationManager's cached GpsStatus
   * instance to the client's copy. Since this method is only used within {@link
   * LocationManager#getGpsStatus}, it does not need to be synchronized.
   */
  void setStatus(GpsStatus status) {
    mTimeToFirstFix = status.getTimeToFirstFix();
    clearSatellites();

    SparseArray<GpsSatellite> otherSatellites = status.mSatellites;
    int otherSatellitesCount = otherSatellites.size();
    int satelliteIndex = 0;
    // merge both sparse arrays, note that we have already invalidated the elements in the
    // receiver array
    for (int i = 0; i < otherSatellitesCount; ++i) {
      GpsSatellite otherSatellite = otherSatellites.valueAt(i);
      int otherSatellitePrn = otherSatellite.getPrn();

      int satellitesCount = mSatellites.size();
      while (satelliteIndex < satellitesCount
          && mSatellites.valueAt(satelliteIndex).getPrn() < otherSatellitePrn) {
        ++satelliteIndex;
      }

      if (satelliteIndex < mSatellites.size()) {
        GpsSatellite satellite = mSatellites.valueAt(satelliteIndex);
        if (satellite.getPrn() == otherSatellitePrn) {
          satellite.setStatus(otherSatellite);
        } else {
          satellite = new GpsSatellite(otherSatellitePrn);
          satellite.setStatus(otherSatellite);
          mSatellites.put(otherSatellitePrn, satellite);
        }
      } else {
        GpsSatellite satellite = new GpsSatellite(otherSatellitePrn);
        satellite.setStatus(otherSatellite);
        mSatellites.append(otherSatellitePrn, satellite);
      }
    }
  }