Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
    /**
     * 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();
    }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
  private int getColumnWidth(int pos) {
    int colIndex = mItems.get(pos, -1);

    if (colIndex == -1) return 0;

    return mColumns[colIndex].getColumnWidth();
  }
 /**
  * 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;
 }
Exemplo n.º 6
0
  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;
  }
  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);
  }
  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;
    }
  }
Exemplo n.º 9
0
  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();
    }
  }
Exemplo n.º 10
0
 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;
 }
 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;
 }
Exemplo n.º 12
0
 @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;
   }
 }
 @Override
 public int getItemViewType(int position) {
   return mViewTypesByPosition.get(position);
   // if (getItem(position) != null) {
   // return VIEW_TYPE_PURCAHSE;
   // } else {
   // return VIEW_TYPE_HEADER;
   // }
 }
  /**
   * Capture a still picture. This method should be called when we get a response in {@link
   * #mCaptureCallback} from both {@link #lockFocus()}.
   */
  private void captureStillPicture() {
    try {
      final Activity activity = getActivity();
      if (null == activity || null == mCameraDevice) {
        return;
      }
      // This is the CaptureRequest.Builder that we use to take a picture.
      final CaptureRequest.Builder captureBuilder =
          mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
      captureBuilder.addTarget(mImageReader.getSurface());

      // Use the same AE and AF modes as the preview.
      captureBuilder.set(
          CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

      if (isFlash) {
        //                captureBuilder.set(CaptureRequest.FLASH_MODE,
        // CameraMetadata.FLASH_MODE_TORCH);
        //                captureBuilder.set(CaptureRequest.CONTROL_AE_MODE,
        //                        CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
        mPreviewRequestBuilder.set(
            CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);

      } else {
        //                captureBuilder.set(CaptureRequest.FLASH_MODE,
        // CameraMetadata.FLASH_MODE_OFF);
        captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
      }

      // Orientation
      int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
      captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

      CameraCaptureSession.CaptureCallback CaptureCallback =
          new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(
                @NonNull CameraCaptureSession session,
                @NonNull CaptureRequest request,
                @NonNull TotalCaptureResult result) {
              showToast("Saved: " + mFile);
              Log.d(TAG, mFile.toString());
              unlockFocus();

              if (listener != null) {
                listener.onTakenPicture(mFile);
              }
            }
          };

      mCaptureSession.stopRepeating();
      mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
      e.printStackTrace();
    }
  }
  @Override
  public int getNextHeaderViewPosition(int position) {
    return mNextHeadersPositionByIndex.get(position, -1);

    // int nextPosition = mPrevHeadersPositionByIndex.get(position, -1);
    // if (position != nextPosition) {
    // nextPosition = mHeadersPositions.get(nextPosition, -1);
    // }
    // return nextPosition;
  }
Exemplo n.º 16
0
 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;
 }
Exemplo n.º 17
0
  @Override
  public boolean onKeyUp(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
      // We don't want to swallow the back button press
      return false;
    }

    // NOTE: Most keyboards, and specifically the Android default keyboard when
    // entering non-ascii characters, will not trigger KeyEvent events as documented
    // here: http://developer.android.com/reference/android/view/KeyEvent.html

    // Log.e("KeyDown", "------------");
    // Log.e("KeyDown", "keyChar:" + (int) event.getDisplayLabel());
    // Log.e("KeyDown", "utfChar:" + (char)event.getUnicodeChar());
    // Log.e("KeyDown", "intUtfChar:" + event.getUnicodeChar());

    final NetworkPackage np = new NetworkPackage(MousePadPlugin.PACKAGE_TYPE_MOUSEPAD_REQUEST);

    boolean modifier = false;
    if (event.isAltPressed()) {
      np.set("alt", true);
      modifier = true;
    }

    if (Build.VERSION.SDK_INT >= 11) {
      if (event.isCtrlPressed()) {
        np.set("ctrl", true);
        modifier = true;
      }
    }

    if (event.isShiftPressed()) {
      np.set("shift", true);
    }

    int specialKey = SpecialKeysMap.get(keyCode, -1);

    if (specialKey != -1) {
      np.set("specialKey", specialKey);
    } else if (event.getDisplayLabel() != 0 && modifier) {
      // Alt will change the utf symbol to non-ascii characters, we want the plain original letter
      // Since getDisplayLabel will always have a value, we have to check for special keys before
      char keyCharacter = event.getDisplayLabel();
      np.set("key", new String(new char[] {keyCharacter}).toLowerCase());
    } else {
      // A normal key, but still not handled by the KeyInputConnection (happens with numbers)
      np.set("key", new String(new char[] {(char) event.getUnicodeChar()}));
    }

    sendKeyPressPackage(np);
    return true;
  }
Exemplo n.º 18
0
  @Override
  protected int getItemBottom(int pos) {

    if (isHeaderOrFooterPosition(pos))
      return mFixedColumn.getTop(); // header view should be place above
    // the first column item.

    int colIndex = mItems.get(pos, -1);
    if (colIndex == -1) return getFillChildTop();

    return mColumns[colIndex].getTop();
  }
  public void setEmergency(final int code) {
    int res = emergencyStringMap.get(code);

    if (res != 0) {
      txtAlert.setText(context.getString(res));
      txtAlert.setVisibility(Text.VISIBLE);
      txtAlert.blink(true);
    } else {
      txtAlert.setVisibility(Text.INVISIBLE);
      txtAlert.blink(false);
    }
  }
Exemplo n.º 20
0
  @Override
  protected int getItemTop(int pos) {

    if (isHeaderOrFooterPosition(pos))
      return mFixedColumn.getBottom(); // footer view should be placed
    // below the last column.

    int colIndex = mItems.get(pos, -1);
    if (colIndex == -1) return getFillChildBottom();

    return mColumns[colIndex].getBottom();
  }
Exemplo n.º 21
0
 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;
 }
Exemplo n.º 22
0
  View getVirtualChildAt(int index) {
    // TODO add provider info
    if (provider == null) {
      getChildAt(index);
    }

    if (mPageToChildIndex == null) {
      mapPagesAndIndexs();
    }

    final int deflectedIndex = mPageToChildIndex.get(index, -1);
    if (deflectedIndex != -1) {
      return getChildAt(deflectedIndex);
    }

    return null;
  }
Exemplo n.º 23
0
 public int sound(int action, int sound, float config) {
   int result = 0;
   if (this.config.sound) {
     //		float volume = this.volume.getStreamVolume(AudioManager.STREAM_MUSIC);
     //		volume = volume / this.volume.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
     switch (action) {
       case Sound.PLAY:
         result = this.sound.play(sounds.get(sound), 1, 1, 1, (int) config, 1f);
         break;
       case Sound.STOP:
         System.out.println("stopping play " + sound);
         this.sound.stop(sound);
         break;
     }
   }
   return result;
 }
Exemplo n.º 24
0
 public void removeItemTemp(int paramInt)
 {
   this.mHasRemovedItem = true;
   int i = getCount();
   int j = paramInt;
   while (true)
   {
     if (j >= i)
       return;
     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;
   }
 }
  /**
   * Capture a still picture. This method should be called when we get a response in {@link
   * #mCaptureCallback} from both {@link #lockFocus()}.
   */
  private void captureStillPicture() {
    try {
      final Activity activity = getActivity();
      if (null == activity || null == mCameraDevice) {
        return;
      }
      // This is the CaptureRequest.Builder that we use to take a picture.
      final CaptureRequest.Builder captureBuilder =
          mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
      captureBuilder.addTarget(mImageReader.getSurface());

      // Use the same AE and AF modes as the preview.
      captureBuilder.set(
          CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
      captureBuilder.set(
          CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

      // Orientation
      int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
      captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

      CameraCaptureSession.CaptureCallback CaptureCallback =
          new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(
                CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
              unlockFocus();
              // On capturing send the file back to the previous activity
              Intent resultIntent = new Intent();
              resultIntent.putExtra("resultFilePath", mFile.getAbsolutePath());
              activity.setResult(Activity.RESULT_OK, resultIntent);
              activity.finish();
            }
          };

      mCaptureSession.stopRepeating();
      mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 26
0
  private void parseKeyboardAttributes(
      Context askContext, Resources res, XmlResourceParser parser) {
    TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), remoteKeyboardLayoutStyleable);
    Resources askRes = askContext.getResources();
    // some defaults
    mDefaultWidth = mDisplayWidth / 10;
    mDefaultHeightCode = -1;
    mDefaultHorizontalGap = 0;
    mDefaultVerticalGap = askRes.getDimensionPixelOffset(R.dimen.default_key_vertical_gap);
    // now reading from XML
    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:
            mDefaultWidth =
                getDimensionOrFraction(a, remoteIndex, mDisplayWidth, mDisplayWidth / 10);
            break;
          case android.R.attr.keyHeight:
            mDefaultHeightCode = getKeyHeightCode(a, remoteIndex, -1);
            break;
          case android.R.attr.horizontalGap:
            mDefaultHorizontalGap = getDimensionOrFraction(a, remoteIndex, mDisplayWidth, 0);
            break;
          case android.R.attr.verticalGap:
            mDefaultVerticalGap =
                getDimensionOrFraction(a, remoteIndex, mDisplayWidth, mDefaultVerticalGap);
            break;
        }
      } catch (Exception e) {
        Log.w(TAG, "Failed to set data from XML!", e);
      }
    }
    a.recycle();

    mProximityThreshold = (int) (mDefaultWidth * SEARCH_DISTANCE);
    // Square it for comparison
    mProximityThreshold = mProximityThreshold * mProximityThreshold;
  }
Exemplo n.º 27
0
  // flow If flow is true, align top edge to y. If false, align bottom edge to
  // y.
  private Column getNextColumn(boolean flow, int position) {

    // we already have this item...
    int colIndex = mItems.get(position, -1);
    if (colIndex != -1) {
      return mColumns[colIndex];
    }

    // adjust position (exclude headers...)
    position = Math.max(0, position - getHeaderViewsCount());

    final int lastVisiblePos = Math.max(0, position);
    if (lastVisiblePos < getColumnNumber()) return mColumns[lastVisiblePos];

    if (flow) {
      // find column which has the smallest bottom value.
      return gettBottomColumn();
    } else {
      // find column which has the smallest top value.
      return getTopColumn();
    }
  }
Exemplo n.º 28
0
 public int getSectionForPosition(int position) {
   return sectionOfPosition.get(position);
 }
  @Override
  protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    super.onScrollChanged(l, t, oldl, oldt);
    if (mCallbacks != null) {
      if (getChildCount() > 0) {
        int firstVisiblePosition = getChildPosition(getChildAt(0));
        int lastVisiblePosition = getChildPosition(getChildAt(getChildCount() - 1));
        for (int i = firstVisiblePosition, j = 0; i <= lastVisiblePosition; i++, j++) {
          if (mChildrenHeights.indexOfKey(i) < 0
              || getChildAt(j).getHeight() != mChildrenHeights.get(i)) {
            mChildrenHeights.put(i, getChildAt(j).getHeight());
          }
        }

        View firstVisibleChild = getChildAt(0);
        if (firstVisibleChild != null) {
          if (mPrevFirstVisiblePosition < firstVisiblePosition) {
            // scroll down
            int skippedChildrenHeight = 0;
            if (firstVisiblePosition - mPrevFirstVisiblePosition != 1) {
              for (int i = firstVisiblePosition - 1; i > mPrevFirstVisiblePosition; i--) {
                if (0 < mChildrenHeights.indexOfKey(i)) {
                  skippedChildrenHeight += mChildrenHeights.get(i);
                } else {
                  // Approximate each item's height to the first visible child.
                  // It may be incorrect, but without this, scrollY will be broken
                  // when scrolling from the bottom.
                  skippedChildrenHeight += firstVisibleChild.getHeight();
                }
              }
            }
            mPrevScrolledChildrenHeight += mPrevFirstVisibleChildHeight + skippedChildrenHeight;
            mPrevFirstVisibleChildHeight = firstVisibleChild.getHeight();
          } else if (firstVisiblePosition < mPrevFirstVisiblePosition) {
            // scroll up
            int skippedChildrenHeight = 0;
            if (mPrevFirstVisiblePosition - firstVisiblePosition != 1) {
              for (int i = mPrevFirstVisiblePosition - 1; i > firstVisiblePosition; i--) {
                if (0 < mChildrenHeights.indexOfKey(i)) {
                  skippedChildrenHeight += mChildrenHeights.get(i);
                } else {
                  // Approximate each item's height to the first visible child.
                  // It may be incorrect, but without this, scrollY will be broken
                  // when scrolling from the bottom.
                  skippedChildrenHeight += firstVisibleChild.getHeight();
                }
              }
            }
            mPrevScrolledChildrenHeight -= firstVisibleChild.getHeight() + skippedChildrenHeight;
            mPrevFirstVisibleChildHeight = firstVisibleChild.getHeight();
          } else if (firstVisiblePosition == 0) {
            mPrevFirstVisibleChildHeight = firstVisibleChild.getHeight();
          }
          if (mPrevFirstVisibleChildHeight < 0) {
            mPrevFirstVisibleChildHeight = 0;
          }
          mScrollY = mPrevScrolledChildrenHeight - firstVisibleChild.getTop();
          mPrevFirstVisiblePosition = firstVisiblePosition;

          mCallbacks.onScrollChanged(mScrollY, mFirstScroll, mDragging);
          if (mFirstScroll) {
            mFirstScroll = false;
          }

          if (mPrevScrollY < mScrollY) {
            // down
            mScrollState = ScrollState.UP;
          } else if (mScrollY < mPrevScrollY) {
            // up
            mScrollState = ScrollState.DOWN;
          } else {
            mScrollState = ScrollState.STOP;
          }
          mPrevScrollY = mScrollY;
        }
      }
    }
  }
Exemplo n.º 30
0
 /**
  * opengl has its own image id while app has its own to get opengls image id we use image method
  *
  * @param resource
  * @return
  */
 public int image(int resource) {
   return images.get(resource);
 }