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 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;
 }
 // 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;
 }
Пример #4
0
  public void setCurSetGrpIdx(int idx) {
    mCurSetsGrpIdx = idx;
    //			arg1.requestFocus();
    mSetsHList.setSelection(idx);
    //		mSetsAdapter.notifyDataSetChanged();

    // 访问数据
    int pgidx = idx + 1;
    if (pgidx == mCurPg) return;

    if (mHadDataGetArr.indexOfKey(pgidx) >= 0) {
      mHListView.setSelection(idx * PAGE_SIZE);
    } else {
      queryPlayList(pgidx);
    }
  }
 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");
       }
     }
   }
 }
 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");
       }
     }
   }
 }
 /**
  * Returns a localized character sequence describing what will happen when the specified key is
  * pressed based on its key code point.
  *
  * @param context The package's context.
  * @param codePoint The code point from which to obtain a description.
  * @return a character sequence describing the code point.
  */
 public String getDescriptionForCodePoint(final Context context, final int codePoint) {
   // If the key description should be obscured, now is the time to do it.
   final int index = mKeyCodeMap.indexOfKey(codePoint);
   if (index >= 0) {
     return context.getString(mKeyCodeMap.valueAt(index));
   }
   final String accentedLetter = getSpokenAccentedLetterDescription(context, codePoint);
   if (accentedLetter != null) {
     return accentedLetter;
   }
   // Here, <code>code</code> may be a base (non-accented) letter.
   final String unsupportedSymbol = getSpokenSymbolDescription(context, codePoint);
   if (unsupportedSymbol != null) {
     return unsupportedSymbol;
   }
   final String emojiDescription = getSpokenEmojiDescription(context, codePoint);
   if (emojiDescription != null) {
     return emojiDescription;
   }
   if (Character.isDefined(codePoint) && !Character.isISOControl(codePoint)) {
     return StringUtils.newSingleCodePointString(codePoint);
   }
   return null;
 }
  @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;
        }
      }
    }
  }
Пример #9
0
 private static int updateHistogramCounter(final SparseIntArray histogram, final int key) {
   final int index = histogram.indexOfKey(key);
   final int count = (index >= 0 ? histogram.get(key) : 0) + 1;
   histogram.put(key, count);
   return count;
 }
Пример #10
0
  /**
   * Figures out whether the item at the specified position represents a stand-alone element, a
   * group or a group child. Also computes the corresponding cursor position.
   */
  public void obtainPositionMetadata(PositionMetadata metadata, int position) {

    // If the description object already contains requested information, just return
    if (metadata.listPosition == position) {
      return;
    }

    int listPosition = 0;
    int cursorPosition = 0;
    int firstGroupToCheck = 0;

    // Check cache for the supplied position.  What we are looking for is
    // the group descriptor immediately preceding the supplied position.
    // Once we have that, we will be able to tell whether the position
    // is the header of the group, a member of the group or a standalone item.
    if (mLastCachedListPosition != -1) {
      if (position <= mLastCachedListPosition) {

        // Have SparceIntArray do a binary search for us.
        int index = mPositionCache.indexOfKey(position);

        // If we get back a positive number, the position corresponds to
        // a group header.
        if (index < 0) {

          // We had a cache miss, but we did obtain valuable information anyway.
          // The negative number will allow us to compute the location of
          // the group header immediately preceding the supplied position.
          index = ~index - 1;

          if (index >= mPositionCache.size()) {
            index--;
          }
        }

        // A non-negative index gives us the position of the group header
        // corresponding or preceding the position, so we can
        // search for the group information at the supplied position
        // starting with the cached group we just found
        if (index >= 0) {
          listPosition = mPositionCache.keyAt(index);
          firstGroupToCheck = mPositionCache.valueAt(index);
          long descriptor = mGroupMetadata[firstGroupToCheck];
          cursorPosition = (int) (descriptor & GROUP_OFFSET_MASK);
        }
      } else {

        // If we haven't examined groups beyond the supplied position,
        // we will start where we left off previously
        firstGroupToCheck = mLastCachedGroup;
        listPosition = mLastCachedListPosition;
        cursorPosition = mLastCachedCursorPosition;
      }
    }

    for (int i = firstGroupToCheck; i < mGroupCount; i++) {
      long group = mGroupMetadata[i];
      int offset = (int) (group & GROUP_OFFSET_MASK);

      // Move pointers to the beginning of the group
      listPosition += (offset - cursorPosition);
      cursorPosition = offset;

      if (i > mLastCachedGroup) {
        mPositionCache.append(listPosition, i);
        mLastCachedListPosition = listPosition;
        mLastCachedCursorPosition = cursorPosition;
        mLastCachedGroup = i;
      }

      // Now we have several possibilities:
      // A) The requested position precedes the group
      if (position < listPosition) {
        metadata.itemType = ITEM_TYPE_STANDALONE;
        metadata.cursorPosition = cursorPosition - (listPosition - position);
        return;
      }

      boolean expanded = (group & EXPANDED_GROUP_MASK) != 0;
      int size = (int) ((group & GROUP_SIZE_MASK) >> 32);

      // B) The requested position is a group header
      if (position == listPosition) {
        metadata.itemType = ITEM_TYPE_GROUP_HEADER;
        metadata.groupPosition = i;
        metadata.isExpanded = expanded;
        metadata.childCount = size;
        metadata.cursorPosition = offset;
        return;
      }

      if (expanded) {
        // C) The requested position is an element in the expanded group
        if (position < listPosition + size + 1) {
          metadata.itemType = ITEM_TYPE_IN_GROUP;
          metadata.cursorPosition = cursorPosition + (position - listPosition) - 1;
          return;
        }

        // D) The element is past the expanded group
        listPosition += size + 1;
      } else {

        // E) The element is past the collapsed group
        listPosition++;
      }

      // Move cursor past the group
      cursorPosition += size;
    }

    // The required item is past the last group
    metadata.itemType = ITEM_TYPE_STANDALONE;
    metadata.cursorPosition = cursorPosition + (position - listPosition);
  }
Пример #11
0
  @Override
  protected void onPostHandle(
      int requestType,
      Object data,
      boolean status,
      int paramInt2,
      Object paramObject2,
      Object paramObject3) {
    // TODO Auto-generated method stub
    super.onPostHandle(requestType, data, status, paramInt2, paramObject2, paramObject3);
    if (data == null) {
      mLoading.cancel();
      mBReqing = false;
      return;
    }

    ResHeadAndBody rslt = (ResHeadAndBody) data;

    if (mUaMap.size() == 0) {
      List<ExtraEntry> extra = rslt.getHeader().getExtra();
      if (extra != null && extra.size() > 0) {
        for (ExtraEntry en : extra) {
          Logger.LOGD("++extra: " + en.getKey() + ", " + en.getValue());
          mUaMap.put(en.getKey(), en.getValue());
        }
      }
    }

    // gson 将请求的数据,转为了ResponePList数据类型
    ResponePList plist = (ResponePList) rslt.getBody();
    List<PlayItemEntity> pList = plist.getpList();
    // 如果数据空,则页面相关信息不会被变更
    if (pList == null || pList.isEmpty()) {
      mLoading.cancel();
      mBReqing = false;
      return;
    }

    ResponsePager pg = (ResponsePager) rslt.getPage();
    if (pg != null) {
      if (mTotalPage == 0) {
        mTotalPage = pg.getPageCount();

        // 更新 集数分组
        mSetsAdapter.setSetCnt(pg.getCount()); // 总集数
        mSetsAdapter.notifyDataSetChanged();
        mSetsHList.setVisibility(View.VISIBLE);
      }

      mCurPg = pg.getPageIndex();
      if (mHadDataGetArr.indexOfKey(mCurPg) < 0) {
        mHadDataGetArr.put(mCurPg, 1); // 入库,即存在

        ArrayList<Integer> keys = new ArrayList<Integer>();
        for (int i = 0; i < mHadDataGetArr.size(); i++) {
          keys.add(mHadDataGetArr.keyAt(i));
        }

        // 计算 insertIdx,根据带插入的列表的集码对应的位置,进行计算在mData中的插入位置
        Collections.sort(keys);
        int curIdx = keys.indexOf(mCurPg);
        int insertIdx = PAGE_SIZE * curIdx; // [insertIdx, --)

        // 数据入库
        mData.addAll(insertIdx, plist.getpList()); // 在mData中insertIdx之前插入 plist.getpList()

        if (!mBfirstData) mHListView.setSelection(insertIdx);
      }
    }

    if (mBfirstData) {
      mHListView.setClickPos(0);
      mBfirstData = false;
      myPlay(mHListView.getClickPos());
    }

    /////////// 放在底部  每次请求要保存状态,保存状态  /////////////
    saveState(plist.getpList());

    mLoading.cancel();
    mBReqing = false;
  }
Пример #12
0
  private boolean queryPlayList(int pgIdx /* , int pgSize */) {
    if (mRunMode == Configer.RunMode.MODE_LOCAL) {
      if (!mBfirstData) return false;

      new Thread(
              new Runnable() {
                @Override
                public void run() {
                  // TODO Auto-generated method stub
                  mData.clear();
                  mCurPg = 0;

                  File f = new File(mCurLocalPath);
                  File[] l = f.listFiles(new FileNameSelector());
                  if (l == null) {
                    // Toast.makeText(this, mCurLocalPath+ " 目录下没有内容", Toast.LENGTH_SHORT).show();
                    onExitProc();
                    return;
                  }

                  if (!mCurLocalPath.endsWith("/")) mCurLocalPath += "/";

                  for (File file : l) {
                    // Logger.LOGD("", mCurLocalPath+file);
                    if (file.isDirectory()) continue;

                    String name = file.getName();
                    int pos = name.lastIndexOf(".");
                    if (pos < 0 || (pos >= (name.length() - 1))) continue;

                    PlayItemEntity pie = new PlayItemEntity();
                    pie.setName(name);

                    List<UrlInfoEntry> ulist = new ArrayList<UrlInfoEntry>();
                    UrlInfoEntry u = new UrlInfoEntry();
                    u.setUrl(mCurLocalPath + name);
                    ulist.add(u);
                    pie.setUrlList(ulist);
                    // pie.setDownUrl(mCurLocalPath+name);
                    mData.add(pie);
                  }
                  mBfirstData = false;

                  runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          // TODO Auto-generated method stub
                          // mHListView.initDatas(mAdapter);
                          // initHScrollView(-1);
                          mHListView.setClickPos(0);
                          myPlay(mHListView.getClickPos());
                        }
                      });
                }
              })
          .start();

      return true;
    } else {
      if (mBReqing) return true;

      // 如果已经请求过了,则不再请求。
      if (mHadDataGetArr.indexOfKey(pgIdx) >= 0) return true;

      mBReqing = true;
      if (!mLoading.isShowing()) mLoading.show();

      HashMap<String, Object> bodyRequest = new HashMap<String, Object>();
      bodyRequest.put("id", mCurCateId);
      bodyRequest.put("pageindex", pgIdx);
      bodyRequest.put("pagesize", PAGE_SIZE);
      bodyRequest.put("type", mReqType);
      HttpManger http = new HttpManger(this, bHandler, this);
      return http.httpRequest(
          Configer.REQ_VIDEO_PLAYLIST, bodyRequest, false, ResponePList.class, false, false, true);
    }
  }
  private static void processWindow(
      Context context,
      SparseIntArray attrs,
      int textColorPrimaryOriginal,
      int textColorPrimaryOverridden) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) return;
    boolean isLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;

    int materialPrimaryIndex = attrs.indexOfKey(R.attr.materialPrimary);
    int materialPrimaryDarkIndex = attrs.indexOfKey(R.attr.materialPrimaryDark);
    int materialNavigationBarIndex = attrs.indexOfKey(R.attr.materialNavigationBar);
    boolean overrideActionbarColor = materialPrimaryIndex >= 0;
    boolean overridePanelsColor =
        Math.max(materialPrimaryDarkIndex, materialNavigationBarIndex) >= 0;

    boolean overrideTextColor = textColorPrimaryOriginal != textColorPrimaryOverridden;
    if (!overrideTextColor && !overrideActionbarColor && !overridePanelsColor) return;

    Window window = ((Activity) context).getWindow();
    final View decorView = window.getDecorView();
    Resources resources = context.getResources();

    if (overrideActionbarColor) {
      try {
        Drawable background = new ColorDrawable(attrs.valueAt(materialPrimaryIndex));
        Object actionBar = context.getClass().getMethod("getActionBar").invoke(context);
        actionBar
            .getClass()
            .getMethod("setBackgroundDrawable", Drawable.class)
            .invoke(actionBar, background);
      } catch (Exception e) {
        Logger.e(TAG, e);
      }
    }

    if (overrideTextColor) {
      int id = resources.getIdentifier("action_bar_title", "id", "android");
      if (id != 0) {
        View v = decorView.findViewById(id);
        if (v instanceof TextView) ((TextView) v).setTextColor(textColorPrimaryOverridden);
      }
    }

    if (isLollipop && overrideTextColor) {
      try {
        int id = resources.getIdentifier("action_bar", "id", "android");
        if (id == 0) throw new Exception("'android:id/action_bar' identifier not found");
        View v = decorView.findViewById(id);
        if (v == null) throw new Exception("view with id 'android:id/action_bar' not found");
        Class<?> toolbarClass = Class.forName("android.widget.Toolbar");
        if (!toolbarClass.isInstance(v))
          throw new Exception(
              "view 'android:id/action_bar' is not instance of android.widget.Toolbar");
        toolbarClass
            .getMethod("setTitleTextColor", int.class)
            .invoke(v, textColorPrimaryOverridden);
        setLollipopMenuOverflowIconColor((ViewGroup) v, textColorPrimaryOverridden);
      } catch (Exception e) {
        Logger.e(TAG, e);
      }
    }

    if (isLollipop && overridePanelsColor) {
      try {
        if (materialPrimaryDarkIndex >= 0) {
          window
              .getClass()
              .getMethod("setStatusBarColor", int.class)
              .invoke(window, attrs.valueAt(materialPrimaryDarkIndex));
        }
        if (materialNavigationBarIndex >= 0) {
          window
              .getClass()
              .getMethod("setNavigationBarColor", int.class)
              .invoke(window, attrs.valueAt(materialNavigationBarIndex));
        }
      } catch (Exception e) {
        Logger.e(TAG, e);
      }
    }
  }
  @Override
  public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    int mappingCount = 0;
    if (attrs != null) {
      for (int i = 0, size = attrs.getAttributeCount(); i < size; ++i) {
        String value = attrs.getAttributeValue(i);
        if (!value.startsWith("?")) continue;
        int attrId =
            resources.getIdentifier(
                value.substring(1), null, null); // Integer.parseInt(value.substring(1));
        if (attrId == 0) {
          Logger.e(TAG, "couldn't get id for attribute: " + value);
          continue;
        }
        int index = customAttrs.indexOfKey(attrId);
        if (index >= 0) {
          mappingKeys[mappingCount] = attrs.getAttributeNameResource(i);
          mappingValues[mappingCount] = customAttrs.valueAt(index);
          ++mappingCount;
        }
      }
    }

    if (mappingCount == 0 && textColorPrimaryOverridden == textColorPrimaryOriginal) return null;

    View view = instantiate(name, context, attrs);
    if (view == null) return null;

    boolean shouldOverrideTextColor =
        textColorPrimaryOverridden != textColorPrimaryOriginal && view instanceof TextView;
    for (int i = 0; i < mappingCount; ++i) {
      switch (mappingKeys[i]) {
        case android.R.attr.background:
          view.setBackgroundColor(mappingValues[i]);
          break;
        case android.R.attr.textColor:
          if (view instanceof TextView) {
            ((TextView) view).setTextColor(mappingValues[i]);
            shouldOverrideTextColor = false;
          } else {
            Logger.e(
                TAG,
                "couldn't apply attribute 'textColor' on class "
                    + name
                    + " (not instance of TextView)");
          }
          break;
        case android.R.attr.divider:
          if (view instanceof ListView) {
            ListView listView = (ListView) view;
            int dividerHeight = listView.getDividerHeight();
            listView.setDivider(new ColorDrawable(mappingValues[i]));
            listView.setDividerHeight(dividerHeight);
          } else {
            Logger.e(
                TAG,
                "couldn't apply attribute 'divider' on class "
                    + name
                    + " (not instance of ListView)");
          }
          break;
        default:
          String attrResName = null;
          try {
            attrResName = resources.getResourceName(mappingKeys[i]);
          } catch (Exception e) {
            attrResName = Integer.toString(mappingKeys[i]);
          }
          Logger.e(TAG, "couldn't apply attribure '" + attrResName + "' on class " + name);
      }
    }

    if (shouldOverrideTextColor) {
      TextView tv = (TextView) view;
      if (tv.getCurrentTextColor() == textColorPrimaryOriginal) {
        tv.setTextColor(textColorPrimaryOverridden);
      }
    }

    return view;
  }