public static void setCustomTheme(Context context, SparseIntArray customAttrs) { if (customAttrs == null || customAttrs.size() == 0) { currentInstance = null; return; } TypedValue tmp = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.textColorPrimary, tmp, true); int textColorPrimaryOriginal = (tmp.type >= TypedValue.TYPE_FIRST_COLOR_INT && tmp.type <= TypedValue.TYPE_LAST_COLOR_INT) ? tmp.data : Color.TRANSPARENT; int textColorPrimaryOverridden = customAttrs.get(android.R.attr.textColorPrimary, textColorPrimaryOriginal); try { processWindow(context, customAttrs, textColorPrimaryOriginal, textColorPrimaryOverridden); } catch (Exception e) { Logger.e(TAG, e); } currentInstance = new CustomThemeHelper( context, customAttrs, textColorPrimaryOriginal, textColorPrimaryOverridden); }
public static boolean isPortAvailable(int port) { boolean available = true; int available_code = mOpenPorts.get(port); if (available_code != 0) return available_code != 1; try { // attempt 3 times since proxy and server could be still releasing // their ports for (int i = 0; i < 3; i++) { Socket channel = new Socket(); InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(mNetwork.getLocalAddressAsString()), port); channel.connect(address, 200); available = !channel.isConnected(); channel.close(); if (available) break; Thread.sleep(200); } } catch (Exception e) { available = true; } mOpenPorts.put(port, available ? 2 : 1); return available; }
@Override public Object[] getSections() { positionOfSection = new SparseIntArray(); sectionOfPosition = new SparseIntArray(); int count = getCount(); list = new ArrayList<String>(); list.add(getContext().getString(R.string.search_header)); positionOfSection.put(0, 0); sectionOfPosition.put(0, 0); for (int i = 1; i < count; i++) { String letter = getItem(i).getHeader(); EMLog.d( TAG, "contactadapter getsection getHeader:" + letter + " name:" + getItem(i).getUsername()); int section = list.size() - 1; if (list.get(section) != null && !list.get(section).equals(letter)) { list.add(letter); section++; positionOfSection.put(section, i); } sectionOfPosition.put(i, section); } return list.toArray(new String[list.size()]); }
/** * Create a key with the given top-left coordinate and extract its attributes from the XML * parser. * * @param res resources associated with the caller's context * @param parent the row that this key belongs to. The row must already be attached to a {@link * Keyboard}. * @param x the x coordinate of the top-left * @param y the y coordinate of the top-left * @param parser the XML parser containing the attributes for this key */ public Key( Context askContext, Resources res, Row parent, KeyboardDimens keyboardDimens, int x, int y, XmlResourceParser parser) { this(parent, keyboardDimens); final Resources askResources = askContext.getResources(); SparseIntArray attributeIdMap = parent.parent.attributeIdMap; this.x = x; this.y = y; // setting up some defaults width = Math.min(keyboardDimens.getKeyMaxWidth(), parent.defaultWidth); height = KeyboardSupport.getKeyHeightFromHeightCode( keyboardDimens, parent.defaultHeightCode, askResources.getConfiguration().orientation); gap = parent.defaultHorizontalGap; codes = null; iconPreview = null; popupCharacters = null; popupResId = 0; repeatable = false; showPreview = true; dynamicEmblem = KEY_EMBLEM_NONE; modifier = false; sticky = false; // loading data from XML int[] remoteKeyboardLayoutStyleable = parent.parent.remoteKeyboardLayoutStyleable; TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardLayoutStyleable); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardLayoutStyleable[remoteIndex]); setDataFromTypedArray(parent, keyboardDimens, askResources, a, remoteIndex, localAttrId); } a.recycle(); this.x += gap; int[] remoteKeyboardKeyLayoutStyleable = parent.parent.remoteKeyboardKeyLayoutStyleable; a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardKeyLayoutStyleable); n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardKeyLayoutStyleable[remoteIndex]); setDataFromTypedArray(parent, keyboardDimens, askResources, a, remoteIndex, localAttrId); } externalResourcePopupLayout = popupResId != 0; if (codes == null && !TextUtils.isEmpty(label)) { codes = new int[] {label.charAt(0)}; } a.recycle(); }
protected MetadataDTO generateListMetadata() { synchronized (mObjectList) { MetadataDTO metadata = new MetadataDTO(); D currentHeaderData = null; int currentHeaderDataPosition = 0; SparseIntArray headerPositions = new SparseIntArray(); // this.mHeadersPositions = new SparseIntArray(); sortList(mObjectList); for (T item : mObjectList) { if (currentHeaderData == null || compareHeadersData(currentHeaderData, getHeadersData(item)) != 0) { currentHeaderData = getHeadersData(item); metadata.getTotalItems().add(currentHeaderData); int lastCurrentHeaderDataPosition = currentHeaderDataPosition; currentHeaderDataPosition = metadata.getTotalItems().size() - 1; metadata.getViewTypesByPosition().append(currentHeaderDataPosition, VIEW_TYPE_HEADER); headerPositions.append(lastCurrentHeaderDataPosition, currentHeaderDataPosition); // mHeadersPositions.append(lastCurrentDatePosition, // currentDatePosition); metadata .getPrevHeadersPositionByIndex() .append(currentHeaderDataPosition, currentHeaderDataPosition); } metadata.getTotalItems().add(item); int position = metadata.getTotalItems().size() - 1; metadata.getViewTypesByPosition().append(position, VIEW_TYPE_ITEM); metadata.getPrevHeadersPositionByIndex().append(position, currentHeaderDataPosition); } for (int index = 0; index < metadata.getPrevHeadersPositionByIndex().size(); index++) { int key = metadata.getPrevHeadersPositionByIndex().keyAt(index); int value = metadata.getPrevHeadersPositionByIndex().valueAt(index); if (key != value) { value = headerPositions.get(value, -1); } metadata.getNextHeadersPositionByIndex().append(key, value); } return metadata; } }
@Before public void setup() { final SparseIntArray bucketSizes = new SparseIntArray(); bucketSizes.put(32, 2); bucketSizes.put(64, 1); bucketSizes.put(128, 1); mPool = new FakeNativeMemoryChunkPool(new PoolParams(128, bucketSizes)); }
static { SparseIntArray localSparseIntArray = new SparseIntArray(); ab = localSparseIntArray; localSparseIntArray.put(0, efj.YL); ab.put(1, efj.YJ); ab.put(2, efj.YM); ab.put(3, efj.YK); }
private ViewConstraints getViewMetrics(int id) { if (id == PARENT) { return mRootConstraints; } else if (id > 0 && mIdToViewConstraints.indexOfKey(id) >= 0) { return mViewConstraints[mIdToViewConstraints.get(id)]; } return null; }
public int getPictureId(int position) { int id = mSparseIntArray.get(position); if (id == 0) { id = mIdsList.get(mRandom.nextInt(mSize)); mSparseIntArray.put(position, id); } return id; }
@Test public void testAssertSparseIntArrayEquals() { final SparseIntArray sparseIntArray = new SparseIntArray(); sparseIntArray.put(3, 15); sparseIntArray.put(1, 15); SparseAsserts.assertSparseIntArrayEquals(sparseIntArray, sparseIntArray); }
public Row(Context askContext, Resources res, Keyboard parent, XmlResourceParser parser) { this.parent = parent; // some defaults defaultWidth = parent.mDefaultWidth; defaultHeightCode = parent.mDefaultHeightCode; defaultHorizontalGap = parent.mDefaultHorizontalGap; verticalGap = parent.getVerticalGap(); // now reading from the XML SparseIntArray attributeIdMap = parent.attributeIdMap; int[] remoteKeyboardLayoutStyleable = parent.remoteKeyboardLayoutStyleable; TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardLayoutStyleable); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardLayoutStyleable[remoteIndex]); try { switch (localAttrId) { case android.R.attr.keyWidth: defaultWidth = getDimensionOrFraction( a, remoteIndex, parent.mDisplayWidth, parent.mDefaultWidth); break; case android.R.attr.keyHeight: defaultHeightCode = getKeyHeightCode(a, remoteIndex, parent.mDefaultHeightCode); break; case android.R.attr.horizontalGap: defaultHorizontalGap = getDimensionOrFraction( a, remoteIndex, parent.mDisplayWidth, parent.mDefaultHorizontalGap); break; } } catch (Exception e) { Log.w(TAG, "Failed to set data from XML!", e); } } a.recycle(); int[] remoteKeyboardRowLayoutStyleable = parent.remoteKeyboardRowLayoutStyleable; a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardRowLayoutStyleable); n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int remoteIndex = a.getIndex(i); final int localAttrId = attributeIdMap.get(remoteKeyboardRowLayoutStyleable[remoteIndex]); try { switch (localAttrId) { case android.R.attr.rowEdgeFlags: rowEdgeFlags = a.getInt(remoteIndex, 0); break; case android.R.attr.keyboardMode: mode = a.getResourceId(remoteIndex, 0); break; } } catch (Exception e) { Log.w(TAG, "Failed to set data from XML!", e); } } a.recycle(); }
private void clearHistogram() { mMostCommonKeyHeight = 0; mMaxHeightCount = 0; mHeightHistogram.clear(); mMaxWidthCount = 0; mMostCommonKeyWidth = 0; mWidthHistogram.clear(); }
/** * Serializes the map data to a string. * * @return The string representation of the map data. */ public String serialize() { // Serialize the map data to a multi-delimited string String result = ""; for (int i = 0; i < mMap.size(); i++) { // Putting the value first makes the string a bit more human readable IMO result += mMap.valueAt(i) + ":" + mMap.keyAt(i) + ","; } return result; }
public SparseIntArray buildFilterIndex(ArrayList<Filter> myFilterList) { SparseIntArray myPositionMap = new SparseIntArray(); Integer position = 0; for (Filter myCat : myFilterList) { myPositionMap.put(myCat.getID(), position); position++; } return myPositionMap; }
public static boolean resolveAttribute(int attrId, TypedValue outValue) { if (currentInstance == null) return false; SparseIntArray customAttrs = currentInstance.customAttrs; int index = customAttrs.indexOfKey(attrId); if (index < 0) return false; outValue.type = TypedValue.TYPE_INT_COLOR_ARGB8; outValue.data = customAttrs.valueAt(index); return true; }
public SparseIntArray buildCategoryIndex(ArrayList<Category> myCategoryList) { SparseIntArray myPositionMap = new SparseIntArray(); Integer position = 0; for (Category myCat : myCategoryList) { myPositionMap.put(myCat.getID(), position); position++; } return myPositionMap; }
private void createViewMetrics(Stack<ViewConstraints> springMetrics) { springMetrics.clear(); mIdToViewConstraints.clear(); if (mRootConstraints != null) { mRootConstraints.release(); for (ViewConstraints mViewConstraint : mViewConstraints) { mViewConstraint.release(); } mRootConstraints.reset(this); resizeViewConstraintsArray(getChildCount()); } else { mRootConstraints = new ViewConstraints(this, mLayoutMath); mViewConstraints = new ViewConstraints[getChildCount()]; } mRootConstraints.left.setValueObject(mLayoutMath.variable(0)); mRootConstraints.top.setValueObject(mLayoutMath.variable(0)); final int count = getChildCount(); for (int i = 0; i < count; i++) { final View v = getChildAt(i); mIdToViewConstraints.append(v.getId(), i); if (mViewConstraints[i] == null) { mViewConstraints[i] = new ViewConstraints(v, mLayoutMath); } else { mViewConstraints[i].reset(v); } } for (int i = 0; i < count; i++) { final ViewConstraints viewConstraints = mViewConstraints[i]; final LayoutParams layoutParams = (LayoutParams) viewConstraints.getView().getLayoutParams(); if (layoutParams.getWidthWeight() > 0) { viewConstraints.markAsHorizontalSpring(); } if (layoutParams.getHeightWeight() > 0) { viewConstraints.markAsVerticalSpring(); } int[] childRules = layoutParams.getRelations(); for (int relation : VALID_RELATIONS) { final ViewConstraints metrics = getViewMetrics(childRules[relation]); if (metrics != null) { metrics.updateRelation(viewConstraints, relation); } } if (viewConstraints.isHorizontalSpring() || viewConstraints.isVerticalSpring()) { springMetrics.add(viewConstraints); } } }
private int efficientTextSizeSearch( final int start, final int end, final SizeTester sizeTester, final RectF availableSpace) { if (!_enableSizeCache) return binarySearch(start, end, sizeTester, availableSpace); final String text = getText().toString(); final int key = text == null ? 0 : text.length(); int size = _textCachedSizes.get(key); if (size != 0) return size; size = binarySearch(start, end, sizeTester, availableSpace); _textCachedSizes.put(key, size); return size; }
private CustomThemeHelper( Context context, SparseIntArray customAttrs, int textColorPrimaryOriginal, int textColorPrimaryOverridden) { this.customAttrs = customAttrs; this.mappingKeys = new int[customAttrs.size()]; this.mappingValues = new int[customAttrs.size()]; this.textColorPrimaryOriginal = textColorPrimaryOriginal; this.textColorPrimaryOverridden = textColorPrimaryOverridden; this.resources = context.getResources(); this.inflater = LayoutInflater.from(context); LayoutInflaterCompat.setFactory(inflater, this); }
public void moveItemTemp(int paramInt1, int paramInt2) { if (paramInt1 != paramInt2) return; int i = this.mTempRowMapping.get(paramInt1, paramInt1); if (paramInt1 > paramInt2) { j = paramInt1; while (j > paramInt2) { SparseIntArray localSparseIntArray1 = this.mTempRowMapping; SparseIntArray localSparseIntArray2 = this.mTempRowMapping; int k = j + -1; int m = j + -1; int n = localSparseIntArray2.get(k, m); localSparseIntArray1.put(j, n); j += -1; } } int j = paramInt1; while (j < paramInt2) { SparseIntArray localSparseIntArray3 = this.mTempRowMapping; SparseIntArray localSparseIntArray4 = this.mTempRowMapping; int i1 = j + 1; int i2 = j + 1; int i3 = localSparseIntArray4.get(i1, i2); localSparseIntArray3.put(j, i3); j += 1; } this.mTempRowMapping.put(paramInt2, i); }
private int efficientTextSizeSearch( int start, int end, SizeTester sizeTester, RectF availableSpace) { if (!mEnableSizeCache) { return binarySearch(start, end, sizeTester, availableSpace); } String text = getText().toString(); int key = text == null ? 0 : text.length(); int size = mTextCachedSizes.get(key); if (size != 0) { return size; } size = binarySearch(start, end, sizeTester, availableSpace); mTextCachedSizes.put(key, size); return size; }
private int getColumnWidth(int pos) { int colIndex = mItems.get(pos, -1); if (colIndex == -1) return 0; return mColumns[colIndex].getColumnWidth(); }
// TODO: Remove this method once TTS supports those accented letters' verbalization. private String getSpokenAccentedLetterDescription(final Context context, final int code) { final boolean isUpperCase = Character.isUpperCase(code); final int baseCode = isUpperCase ? Character.toLowerCase(code) : code; final int baseIndex = mKeyCodeMap.indexOfKey(baseCode); final int resId = (baseIndex >= 0) ? mKeyCodeMap.valueAt(baseIndex) : getSpokenDescriptionId(context, baseCode, SPOKEN_LETTER_RESOURCE_NAME_FORMAT); if (resId == 0) { return null; } final String spokenText = context.getString(resId); return isUpperCase ? context.getString(R.string.spoken_description_upper_case, spokenText) : spokenText; }
/** * Retrieves the JPEG orientation from the specified screen rotation. * * @param rotation The screen rotation. * @return The JPEG orientation (one of 0, 90, 270, and 360) */ private int getOrientation(int rotation) { // Sensor orientation is 90 for most devices, or 270 for some devices (eg. Nexus 5X) // We have to take that into account and rotate JPEG properly. // For devices with orientation of 90, we simply return our mapping from ORIENTATIONS. // For devices with orientation of 270, we need to rotate the JPEG 180 degrees. return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360; }
@Override protected void onSizeChanged( final int width, final int height, final int oldwidth, final int oldheight) { _textCachedSizes.clear(); super.onSizeChanged(width, height, oldwidth, oldheight); if (width != oldwidth || height != oldheight) reAdjust(); }
@Override public final int getItemViewType(int position) { CardBase item = getItem(position); if (item.getLayout() > 0) { if (mViewTypes.get(item.getLayout()) != 0) return mViewTypes.get(item.getLayout()); else if (mLayout == item.getLayout()) return TYPE_REGULAR; else if (mLayoutNoContent == item.getLayout()) return TYPE_NO_CONTENT; else if (mLayoutHeader == item.getLayout()) return TYPE_HEADER; String name = getContext().getResources().getResourceName(item.getLayout()); throw new RuntimeException("The layout " + name + " is not registered."); } else { if (item.isHeader()) return TYPE_HEADER; else if ((item.getContent() == null || item.getContent().trim().isEmpty())) return TYPE_NO_CONTENT; else return TYPE_REGULAR; } }
private void capturaFoto() { try { criaArquivosFotos(); // verificaCaminhoFotos(); final Activity activity = getActivity(); if (null == activity || null == cameraDevice) { return; } final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); captureBuilder.addTarget(imageReader.getSurface()); captureBuilder.set( CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); if (flashOn == true) { captureBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH); } int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); if (cameraEscolhida == "0") captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, orientacoes.get(rotation)); else captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, orientacoes.get(rotation) + 180); CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() { @Override public void onCaptureCompleted( @NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) { desabilitaFoco(); } }; captureSession.stopRepeating(); captureSession.capture(captureBuilder.build(), CaptureCallback, null); if (flagMudancaAutoCamera == true) { alteraCamera(); } } catch (CameraAccessException e) { e.printStackTrace(); } }
/** Cache should be reset whenever the cursor changes or groups are expanded or collapsed. */ private void resetCache() { mCount = -1; mLastCachedListPosition = -1; mLastCachedCursorPosition = -1; mLastCachedGroup = -1; mPositionMetadata.listPosition = -1; mPositionCache.clear(); }
private void handleAddListener(int uid) { synchronized (mListeners) { if (mClientUids.indexOfKey(uid) >= 0) { // Shouldn't be here -- already have this uid. Log.w(TAG, "Duplicate add listener for uid " + uid); return; } mClientUids.put(uid, 0); if (mNavigating) { try { mBatteryStats.noteStartGps(uid); } catch (RemoteException e) { Log.w(TAG, "RemoteException in addListener"); } } } }
private void handleRemoveListener(int uid) { synchronized (mListeners) { if (mClientUids.indexOfKey(uid) < 0) { // Shouldn't be here -- don't have this uid. Log.w(TAG, "Unneeded remove listener for uid " + uid); return; } mClientUids.delete(uid); if (mNavigating) { try { mBatteryStats.noteStopGps(uid); } catch (RemoteException e) { Log.w(TAG, "RemoteException in removeListener"); } } } }