Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Intent i = new Intent(Intent.ACTION_GET_CONTENT, null); i.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); startActivityForResult(i, INTENT_CODE_IMAGE_GALLERY1);
okHttpClient.interceptors().add(new Interceptor() { @Override public Response intercept(Interceptor.Chain chain)throws IOException { Request original = chain.request();
// Request customization: add request headers Request.Builder requestBuilder = original.newBuilder() .header("headerkey", "header-value"); // <-- this is the important line
/** * 重写onMeasure方法是为了确定最终的大小 * @param widthMeasureSpec * @param heightMeasureSpec */ @Override protectedvoidonMeasure(int widthMeasureSpec, int heightMeasureSpec){ int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec); int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec); int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); int paddingTop = getPaddingTop(); int paddingBottom = getPaddingBottom(); //处理Padding属性,让当前的ViewGroup支持Padding int widthUsed = paddingLeft + paddingRight; int heightUsed = paddingTop + paddingBottom;
int childMaxHeightOfThisLine = 0; int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); if (child.getVisibility() != GONE) { // 已用的宽度 int childUsedWidth = 0; // 已用的高度 int childUsedHeight = 0; // 调用ViewGroup自身的方法测量孩子的宽度和高度,我们也可以自己根据MeasureMode来测量 measureChild(child,widthMeasureSpec,heightMeasureSpec); childUsedWidth += child.getMeasuredWidth(); childUsedHeight += child.getMeasuredHeight(); //处理Margin,支持孩子的Margin属性 Rect marginRect = getMarginRect(child); int leftMargin=marginRect.left; int rightMargin=marginRect.right; int topMargin=marginRect.top; int bottomMargin=marginRect.bottom;
@Override protectedvoidonLayout(boolean changed, int l, int t, int r, int b){ int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); int paddingTop = getPaddingTop(); int paddingBottom = getPaddingBottom();
/** * 为了 支持Padding属性 */ int childStartLayoutX = paddingLeft; int childStartLayoutY = paddingTop;
int widthUsed = paddingLeft + paddingRight;
int childMaxHeight = 0;
int childCount = getChildCount(); //摆放每一个孩子的高度 for (int i = 0; i < childCount; i++) { View child = getChildAt(i); if (child.getVisibility() != GONE) { int childNeededWidth, childNeedHeight; int left, top, right, bottom;
int childMeasuredWidth = child.getMeasuredWidth(); int childMeasuredHeight = child.getMeasuredHeight();
Rect marginRect = getMarginRect(child); int leftMargin=marginRect.left; int rightMargin=marginRect.right; int topMargin=marginRect.top; int bottomMargin=marginRect.bottom; childNeededWidth = leftMargin + rightMargin + childMeasuredWidth; childNeedHeight = topMargin + topMargin + childMeasuredHeight;
// 没有超过本行 if (widthUsed + childNeededWidth <= r - l) { if (childNeedHeight > childMaxHeight) { childMaxHeight = childNeedHeight; } left = childStartLayoutX + leftMargin; top = childStartLayoutY + topMargin; right = left + childMeasuredWidth; bottom = top + childMeasuredHeight; widthUsed += childNeededWidth; childStartLayoutX += childNeededWidth; } else { childStartLayoutY += childMaxHeight + verticalSpacing; childStartLayoutX = paddingLeft; widthUsed = paddingLeft + paddingRight; left = childStartLayoutX + leftMargin; top = childStartLayoutY + topMargin; right = left + childMeasuredWidth; bottom = top + childMeasuredHeight; widthUsed += childNeededWidth; childStartLayoutX += childNeededWidth; childMaxHeight = childNeedHeight; } child.layout(left, top, right, bottom); } } }
private Rect getMarginRect(View child){ LayoutParams layoutParams = child.getLayoutParams(); int leftMargin = 0; int rightMargin = 0; int topMargin = 0; int bottomMargin = 0; if (layoutParams instanceof MarginLayoutParams) { MarginLayoutParams marginLayoutParams = (MarginLayoutParams) layoutParams; leftMargin = marginLayoutParams.leftMargin; rightMargin = marginLayoutParams.rightMargin; topMargin = marginLayoutParams.topMargin; bottomMargin = marginLayoutParams.bottomMargin;
int widthUsed = paddingLeft + paddingRight; int heightUsed = paddingTop + paddingBottom; ---------- if (widthUsed + childUsedWidth < widthSpecSize) { widthUsed += childUsedWidth; if (childUsedHeight > childMaxHeightOfThisLine) { childMaxHeightOfThisLine = childUsedHeight; } }
为了支持子控件的margin属性,我们同样也做了处理
1 2 3 4 5 6 7 8
Rect marginRect = getMarginRect(child); int leftMargin=marginRect.left; int rightMargin=marginRect.right; int topMargin=marginRect.top; int bottomMargin=marginRect.bottom; childUsedWidth += leftMargin + rightMargin; childUsedHeight += topMargin + bottomMargin;
/** * 放置每个子控件的位置 * * @param changed * @param l * @param t * @param r * @param b */ @Override protectedvoidonLayout(boolean changed, int l, int t, int r, int b){ l += getPaddingLeft(); t += getPaddingTop(); for (int i = 0; i < mLines.size(); i++) { Line line = mLines.get(i); //设置每一行的位置,每一行的子控件由其自己去分配 line.onLayout(l, t); //距离最顶端的距离,即每一行高度和垂直间距的累加 t += line.getHeight() + verticalSpacing; } }