Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: talk/examples/android/src/org/appspot/apprtc/PercentFrameLayout.java

Issue 1257043004: AppRTCDemo: Render each video in a separate SurfaceView (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * libjingle
3 * Copyright 2015 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 package org.appspot.apprtc;
29
30 import android.content.Context;
31 import android.util.AttributeSet;
32 import android.view.View;
33 import android.view.ViewGroup;
34
35 /**
36 * Simple container that confines the children to a subrectangle specified as pe rcentage values of
37 * the container size. The children are centered horizontally and vertically ins ide the confined
38 * space.
39 */
40 public class PercentFrameLayout extends ViewGroup {
41 private int xPercent = 0;
42 private int yPercent = 0;
43 private int widthPercent = 100;
44 private int heightPercent = 100;
45
46 public PercentFrameLayout(Context context) {
47 super(context);
48 }
49
50 public PercentFrameLayout(Context context, AttributeSet attrs) {
51 super(context, attrs);
52 }
53
54 public PercentFrameLayout(Context context, AttributeSet attrs, int defStyleAtt r) {
55 super(context, attrs, defStyleAttr);
56 }
57
58 public void setPosition(int xPercent, int yPercent, int widthPercent, int heig htPercent) {
59 this.xPercent = xPercent;
60 this.yPercent = yPercent;
61 this.widthPercent = widthPercent;
62 this.heightPercent = heightPercent;
63 }
64
65 @Override
66 public boolean shouldDelayChildPressedState() {
67 return false;
68 }
69
70 @Override
71 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
72 final int width = getDefaultSize(Integer.MAX_VALUE, widthMeasureSpec);
73 final int height = getDefaultSize(Integer.MAX_VALUE, heightMeasureSpec);
74 setMeasuredDimension(
75 MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
76 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
77
78 final int childWidthMeasureSpec =
79 MeasureSpec.makeMeasureSpec(width * widthPercent / 100, MeasureSpec.AT_M OST);
80 final int childHeightMeasureSpec =
81 MeasureSpec.makeMeasureSpec(height * heightPercent / 100, MeasureSpec.AT _MOST);
82 for (int i = 0; i < getChildCount(); ++i) {
83 final View child = getChildAt(i);
84 if (child.getVisibility() != GONE) {
85 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
86 }
87 }
88 }
89
90 @Override
91 protected void onLayout(boolean changed, int left, int top, int right, int bot tom) {
92 final int width = right - left;
93 final int height = bottom - top;
94 // Sub-rectangle specified by percentage values.
95 final int subWidth = width * widthPercent / 100;
96 final int subHeight = height * heightPercent / 100;
97 final int subLeft = left + width * xPercent / 100;
98 final int subTop = top + height * yPercent / 100;
99
100 for (int i = 0; i < getChildCount(); ++i) {
101 final View child = getChildAt(i);
102 if (child.getVisibility() != GONE) {
103 final int childWidth = child.getMeasuredWidth();
104 final int childHeight = child.getMeasuredHeight();
105 // Center child both vertically and horizontally.
106 final int childLeft = subLeft + (subWidth - childWidth) / 2;
107 final int childTop = subTop + (subHeight - childHeight) / 2;
108 child.layout(childLeft, childTop, childLeft + childWidth, childTop + chi ldHeight);
109 }
110 }
111 }
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698