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

Side by Side Diff: webrtc/examples/androidapp/src/org/appspot/apprtc/PercentFrameLayout.java

Issue 2682943006: Add support for swapping feeds in Android AppRTCMobile. (Closed)
Patch Set: Remove an empty line, add comments. Created 3 years, 10 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
« no previous file with comments | « webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 package org.appspot.apprtc;
12
13 import android.content.Context;
14 import android.util.AttributeSet;
15 import android.view.View;
16 import android.view.ViewGroup;
17
18 /**
19 * Simple container that confines the children to a subrectangle specified as pe rcentage values of
20 * the container size. The children are centered horizontally and vertically ins ide the confined
21 * space.
22 */
23 public class PercentFrameLayout extends ViewGroup {
24 private int xPercent = 0;
25 private int yPercent = 0;
26 private int widthPercent = 100;
27 private int heightPercent = 100;
28
29 public PercentFrameLayout(Context context) {
30 super(context);
31 }
32
33 public PercentFrameLayout(Context context, AttributeSet attrs) {
34 super(context, attrs);
35 }
36
37 public PercentFrameLayout(Context context, AttributeSet attrs, int defStyleAtt r) {
38 super(context, attrs, defStyleAttr);
39 }
40
41 public void setPosition(int xPercent, int yPercent, int widthPercent, int heig htPercent) {
42 this.xPercent = xPercent;
43 this.yPercent = yPercent;
44 this.widthPercent = widthPercent;
45 this.heightPercent = heightPercent;
46 }
47
48 @Override
49 public boolean shouldDelayChildPressedState() {
50 return false;
51 }
52
53 @Override
54 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
55 final int width = getDefaultSize(Integer.MAX_VALUE, widthMeasureSpec);
56 final int height = getDefaultSize(Integer.MAX_VALUE, heightMeasureSpec);
57 setMeasuredDimension(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY) ,
58 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
59
60 final int childWidthMeasureSpec =
61 MeasureSpec.makeMeasureSpec(width * widthPercent / 100, MeasureSpec.AT_M OST);
62 final int childHeightMeasureSpec =
63 MeasureSpec.makeMeasureSpec(height * heightPercent / 100, MeasureSpec.AT _MOST);
64 for (int i = 0; i < getChildCount(); ++i) {
65 final View child = getChildAt(i);
66 if (child.getVisibility() != GONE) {
67 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
68 }
69 }
70 }
71
72 @Override
73 protected void onLayout(boolean changed, int left, int top, int right, int bot tom) {
74 final int width = right - left;
75 final int height = bottom - top;
76 // Sub-rectangle specified by percentage values.
77 final int subWidth = width * widthPercent / 100;
78 final int subHeight = height * heightPercent / 100;
79 final int subLeft = left + width * xPercent / 100;
80 final int subTop = top + height * yPercent / 100;
81
82 for (int i = 0; i < getChildCount(); ++i) {
83 final View child = getChildAt(i);
84 if (child.getVisibility() != GONE) {
85 final int childWidth = child.getMeasuredWidth();
86 final int childHeight = child.getMeasuredHeight();
87 // Center child both vertically and horizontally.
88 final int childLeft = subLeft + (subWidth - childWidth) / 2;
89 final int childTop = subTop + (subHeight - childHeight) / 2;
90 child.layout(childLeft, childTop, childLeft + childWidth, childTop + chi ldHeight);
91 }
92 }
93 }
94 }
OLDNEW
« no previous file with comments | « webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698