├── example
├── res
│ ├── drawable
│ │ ├── shade_handlebar.9.png
│ │ └── shade_handlebar_vertical.9.png
│ ├── values
│ │ └── strings.xml
│ └── layout
│ │ └── main.xml
├── AndroidManifest.xml
├── build.properties
├── proguard.cfg
├── src
│ └── com
│ │ └── fsck
│ │ └── example
│ │ └── splitview
│ │ └── Home.java
└── build.xml
├── lib
├── res
│ ├── values
│ │ ├── strings.xml
│ │ └── attrs.xml
│ └── layout
│ │ └── main.xml
├── AndroidManifest.xml
├── build.properties
├── proguard.cfg
├── build.xml
└── src
│ └── com
│ └── fsck
│ └── splitview
│ └── SplitView.java
└── NOTICE
/example/res/drawable/shade_handlebar.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/k9mail/splitview/HEAD/example/res/drawable/shade_handlebar.9.png
--------------------------------------------------------------------------------
/example/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Home
4 |
5 |
--------------------------------------------------------------------------------
/example/res/drawable/shade_handlebar_vertical.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/k9mail/splitview/HEAD/example/res/drawable/shade_handlebar_vertical.9.png
--------------------------------------------------------------------------------
/lib/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | ACTIVITY_ENTRY_NAME
4 |
5 |
--------------------------------------------------------------------------------
/lib/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/lib/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/example/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/lib/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/lib/build.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked in Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 |
18 |
--------------------------------------------------------------------------------
/example/build.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked in Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 |
18 | android.library.reference.1=../lib
19 |
20 |
--------------------------------------------------------------------------------
/lib/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembernames class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembernames class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers enum * {
30 | public static **[] values();
31 | public static ** valueOf(java.lang.String);
32 | }
33 |
34 | -keep class * implements android.os.Parcelable {
35 | public static final android.os.Parcelable$Creator *;
36 | }
37 |
--------------------------------------------------------------------------------
/example/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembernames class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembernames class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers enum * {
30 | public static **[] values();
31 | public static ** valueOf(java.lang.String);
32 | }
33 |
34 | -keep class * implements android.os.Parcelable {
35 | public static final android.os.Parcelable$Creator *;
36 | }
37 |
--------------------------------------------------------------------------------
/example/src/com/fsck/example/splitview/Home.java:
--------------------------------------------------------------------------------
1 | package com.fsck.example.splitview;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 | import android.view.View.OnClickListener;
8 | import com.fsck.splitview.SplitView;
9 |
10 | public class Home extends Activity
11 | {
12 | private Button mHalves;
13 | private Button mMaximizePrimaryContent;
14 | private Button mMaximizeSecondaryContent;
15 |
16 | /** Called when the activity is first created. */
17 | @Override
18 | public void onCreate(Bundle savedInstanceState)
19 | {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.main);
22 |
23 | mMaximizePrimaryContent = (Button)findViewById(R.id.maximize_primary);
24 | mMaximizePrimaryContent.setOnClickListener( new OnClickListener() {
25 | @Override public void onClick(View v) {
26 | ((SplitView)findViewById(R.id.split_view)).maximizePrimaryContent();
27 | }
28 |
29 | });
30 |
31 | mMaximizeSecondaryContent = (Button)findViewById(R.id.maximize_secondary);
32 | mMaximizeSecondaryContent.setOnClickListener( new OnClickListener() {
33 | @Override public void onClick(View v) {
34 | ((SplitView)findViewById(R.id.split_view)).maximizeSecondaryContent();
35 | }
36 |
37 | });
38 |
39 | mHalves = (Button)findViewById(R.id.halves);
40 | mHalves.setOnClickListener( new OnClickListener() {
41 | @Override public void onClick(View v) {
42 | ((SplitView)findViewById(R.id.split_view)).setPrimaryContentSize(200);
43 | }
44 |
45 | });
46 |
47 |
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/example/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
23 |
27 |
31 |
36 |
37 |
43 |
53 |
59 |
60 |
65 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/lib/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
27 |
28 |
29 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
42 |
54 |
55 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/example/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
27 |
28 |
29 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
42 |
54 |
55 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) 2011 Jesse Vincent
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 |
7 | Unless required by applicable law or agreed to in writing, software
8 | distributed under the License is distributed on an "AS IS" BASIS,
9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | See the License for the specific language governing permissions and
11 | limitations under the License.
12 |
13 |
14 | Apache License
15 | Version 2.0, January 2004
16 | http://www.apache.org/licenses/
17 |
18 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
19 |
20 | 1. Definitions.
21 |
22 | "License" shall mean the terms and conditions for use, reproduction,
23 | and distribution as defined by Sections 1 through 9 of this document.
24 |
25 | "Licensor" shall mean the copyright owner or entity authorized by
26 | the copyright owner that is granting the License.
27 |
28 | "Legal Entity" shall mean the union of the acting entity and all
29 | other entities that control, are controlled by, or are under common
30 | control with that entity. For the purposes of this definition,
31 | "control" means (i) the power, direct or indirect, to cause the
32 | direction or management of such entity, whether by contract or
33 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
34 | outstanding shares, or (iii) beneficial ownership of such entity.
35 |
36 | "You" (or "Your") shall mean an individual or Legal Entity
37 | exercising permissions granted by this License.
38 |
39 | "Source" form shall mean the preferred form for making modifications,
40 | including but not limited to software source code, documentation
41 | source, and configuration files.
42 |
43 | "Object" form shall mean any form resulting from mechanical
44 | transformation or translation of a Source form, including but
45 | not limited to compiled object code, generated documentation,
46 | and conversions to other media types.
47 |
48 | "Work" shall mean the work of authorship, whether in Source or
49 | Object form, made available under the License, as indicated by a
50 | copyright notice that is included in or attached to the work
51 | (an example is provided in the Appendix below).
52 |
53 | "Derivative Works" shall mean any work, whether in Source or Object
54 | form, that is based on (or derived from) the Work and for which the
55 | editorial revisions, annotations, elaborations, or other modifications
56 | represent, as a whole, an original work of authorship. For the purposes
57 | of this License, Derivative Works shall not include works that remain
58 | separable from, or merely link (or bind by name) to the interfaces of,
59 | the Work and Derivative Works thereof.
60 |
61 | "Contribution" shall mean any work of authorship, including
62 | the original version of the Work and any modifications or additions
63 | to that Work or Derivative Works thereof, that is intentionally
64 | submitted to Licensor for inclusion in the Work by the copyright owner
65 | or by an individual or Legal Entity authorized to submit on behalf of
66 | the copyright owner. For the purposes of this definition, "submitted"
67 | means any form of electronic, verbal, or written communication sent
68 | to the Licensor or its representatives, including but not limited to
69 | communication on electronic mailing lists, source code control systems,
70 | and issue tracking systems that are managed by, or on behalf of, the
71 | Licensor for the purpose of discussing and improving the Work, but
72 | excluding communication that is conspicuously marked or otherwise
73 | designated in writing by the copyright owner as "Not a Contribution."
74 |
75 | "Contributor" shall mean Licensor and any individual or Legal Entity
76 | on behalf of whom a Contribution has been received by Licensor and
77 | subsequently incorporated within the Work.
78 |
79 | 2. Grant of Copyright License. Subject to the terms and conditions of
80 | this License, each Contributor hereby grants to You a perpetual,
81 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
82 | copyright license to reproduce, prepare Derivative Works of,
83 | publicly display, publicly perform, sublicense, and distribute the
84 | Work and such Derivative Works in Source or Object form.
85 |
86 | 3. Grant of Patent License. Subject to the terms and conditions of
87 | this License, each Contributor hereby grants to You a perpetual,
88 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
89 | (except as stated in this section) patent license to make, have made,
90 | use, offer to sell, sell, import, and otherwise transfer the Work,
91 | where such license applies only to those patent claims licensable
92 | by such Contributor that are necessarily infringed by their
93 | Contribution(s) alone or by combination of their Contribution(s)
94 | with the Work to which such Contribution(s) was submitted. If You
95 | institute patent litigation against any entity (including a
96 | cross-claim or counterclaim in a lawsuit) alleging that the Work
97 | or a Contribution incorporated within the Work constitutes direct
98 | or contributory patent infringement, then any patent licenses
99 | granted to You under this License for that Work shall terminate
100 | as of the date such litigation is filed.
101 |
102 | 4. Redistribution. You may reproduce and distribute copies of the
103 | Work or Derivative Works thereof in any medium, with or without
104 | modifications, and in Source or Object form, provided that You
105 | meet the following conditions:
106 |
107 | (a) You must give any other recipients of the Work or
108 | Derivative Works a copy of this License; and
109 |
110 | (b) You must cause any modified files to carry prominent notices
111 | stating that You changed the files; and
112 |
113 | (c) You must retain, in the Source form of any Derivative Works
114 | that You distribute, all copyright, patent, trademark, and
115 | attribution notices from the Source form of the Work,
116 | excluding those notices that do not pertain to any part of
117 | the Derivative Works; and
118 |
119 | (d) If the Work includes a "NOTICE" text file as part of its
120 | distribution, then any Derivative Works that You distribute must
121 | include a readable copy of the attribution notices contained
122 | within such NOTICE file, excluding those notices that do not
123 | pertain to any part of the Derivative Works, in at least one
124 | of the following places: within a NOTICE text file distributed
125 | as part of the Derivative Works; within the Source form or
126 | documentation, if provided along with the Derivative Works; or,
127 | within a display generated by the Derivative Works, if and
128 | wherever such third-party notices normally appear. The contents
129 | of the NOTICE file are for informational purposes only and
130 | do not modify the License. You may add Your own attribution
131 | notices within Derivative Works that You distribute, alongside
132 | or as an addendum to the NOTICE text from the Work, provided
133 | that such additional attribution notices cannot be construed
134 | as modifying the License.
135 |
136 | You may add Your own copyright statement to Your modifications and
137 | may provide additional or different license terms and conditions
138 | for use, reproduction, or distribution of Your modifications, or
139 | for any such Derivative Works as a whole, provided Your use,
140 | reproduction, and distribution of the Work otherwise complies with
141 | the conditions stated in this License.
142 |
143 | 5. Submission of Contributions. Unless You explicitly state otherwise,
144 | any Contribution intentionally submitted for inclusion in the Work
145 | by You to the Licensor shall be under the terms and conditions of
146 | this License, without any additional terms or conditions.
147 | Notwithstanding the above, nothing herein shall supersede or modify
148 | the terms of any separate license agreement you may have executed
149 | with Licensor regarding such Contributions.
150 |
151 | 6. Trademarks. This License does not grant permission to use the trade
152 | names, trademarks, service marks, or product names of the Licensor,
153 | except as required for reasonable and customary use in describing the
154 | origin of the Work and reproducing the content of the NOTICE file.
155 |
156 | 7. Disclaimer of Warranty. Unless required by applicable law or
157 | agreed to in writing, Licensor provides the Work (and each
158 | Contributor provides its Contributions) on an "AS IS" BASIS,
159 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
160 | implied, including, without limitation, any warranties or conditions
161 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
162 | PARTICULAR PURPOSE. You are solely responsible for determining the
163 | appropriateness of using or redistributing the Work and assume any
164 | risks associated with Your exercise of permissions under this License.
165 |
166 | 8. Limitation of Liability. In no event and under no legal theory,
167 | whether in tort (including negligence), contract, or otherwise,
168 | unless required by applicable law (such as deliberate and grossly
169 | negligent acts) or agreed to in writing, shall any Contributor be
170 | liable to You for damages, including any direct, indirect, special,
171 | incidental, or consequential damages of any character arising as a
172 | result of this License or out of the use or inability to use the
173 | Work (including but not limited to damages for loss of goodwill,
174 | work stoppage, computer failure or malfunction, or any and all
175 | other commercial damages or losses), even if such Contributor
176 | has been advised of the possibility of such damages.
177 |
178 | 9. Accepting Warranty or Additional Liability. While redistributing
179 | the Work or Derivative Works thereof, You may choose to offer,
180 | and charge a fee for, acceptance of support, warranty, indemnity,
181 | or other liability obligations and/or rights consistent with this
182 | License. However, in accepting such obligations, You may act only
183 | on Your own behalf and on Your sole responsibility, not on behalf
184 | of any other Contributor, and only if You agree to indemnify,
185 | defend, and hold each Contributor harmless for any liability
186 | incurred by, or claims asserted against, such Contributor by reason
187 | of your accepting any such warranty or additional liability.
188 |
189 | END OF TERMS AND CONDITIONS
190 |
191 |
--------------------------------------------------------------------------------
/lib/src/com/fsck/splitview/SplitView.java:
--------------------------------------------------------------------------------
1 | package com.fsck.splitview;
2 |
3 | import com.fsck.splitview.R;
4 |
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.os.SystemClock;
8 | import android.util.Log;
9 | import android.util.AttributeSet;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.widget.TextView;
13 | import android.view.ViewGroup;
14 | import android.view.View.OnTouchListener;
15 | import android.widget.LinearLayout;
16 |
17 | public class SplitView extends LinearLayout implements OnTouchListener {
18 |
19 | private int mHandleId;
20 | private View mHandle;
21 |
22 | private int mPrimaryContentId;
23 | private View mPrimaryContent;
24 |
25 | private int mSecondaryContentId;
26 | private View mSecondaryContent;
27 |
28 | private int mLastPrimaryContentSize;
29 |
30 | private boolean mDragging;
31 | private long mDraggingStarted;
32 | private float mDragStartX;
33 | private float mDragStartY;
34 |
35 | private float mPointerOffset;
36 |
37 | final static private int MAXIMIZED_VIEW_TOLERANCE_DIP = 30;
38 | final static private int TAP_DRIFT_TOLERANCE = 3;
39 | final static private int SINGLE_TAP_MAX_TIME = 175;
40 |
41 | public SplitView(Context context, AttributeSet attrs) {
42 | super(context, attrs);
43 |
44 | TypedArray viewAttrs = context.obtainStyledAttributes(attrs, R.styleable.SplitView);
45 |
46 | RuntimeException e = null;
47 | mHandleId = viewAttrs.getResourceId(R.styleable.SplitView_handle, 0);
48 | if (mHandleId == 0) {
49 | e = new IllegalArgumentException(viewAttrs.getPositionDescription() +
50 | ": The required attribute handle must refer to a valid child view.");
51 | }
52 |
53 | mPrimaryContentId = viewAttrs.getResourceId(R.styleable.SplitView_primaryContent, 0);
54 | if (mPrimaryContentId == 0) {
55 | e = new IllegalArgumentException(viewAttrs.getPositionDescription() +
56 | ": The required attribute primaryContent must refer to a valid child view.");
57 | }
58 |
59 |
60 | mSecondaryContentId = viewAttrs.getResourceId(R.styleable.SplitView_secondaryContent, 0);
61 | if (mSecondaryContentId == 0) {
62 | e = new IllegalArgumentException(viewAttrs.getPositionDescription() +
63 | ": The required attribute secondaryContent must refer to a valid child view.");
64 | }
65 |
66 | viewAttrs.recycle();
67 |
68 | if (e != null) {
69 | throw e;
70 | }
71 | }
72 |
73 | @Override
74 | public void onFinishInflate() {
75 | super.onFinishInflate();
76 | mHandle = findViewById(mHandleId);
77 | if (mHandle == null) {
78 | String name = getResources().getResourceEntryName(mHandleId);
79 | throw new RuntimeException("Your Panel must have a child View whose id attribute is 'R.id." + name + "'");
80 |
81 | }
82 | mPrimaryContent = findViewById(mPrimaryContentId);
83 | if (mPrimaryContent == null) {
84 | String name = getResources().getResourceEntryName(mPrimaryContentId);
85 | throw new RuntimeException("Your Panel must have a child View whose id attribute is 'R.id." + name + "'");
86 |
87 | }
88 |
89 | mLastPrimaryContentSize = getPrimaryContentSize();
90 |
91 | mSecondaryContent = findViewById(mSecondaryContentId);
92 | if (mSecondaryContent == null) {
93 | String name = getResources().getResourceEntryName(mSecondaryContentId);
94 | throw new RuntimeException("Your Panel must have a child View whose id attribute is 'R.id." + name + "'");
95 |
96 | }
97 |
98 | mHandle.setOnTouchListener(this);
99 |
100 | }
101 | @Override
102 | public boolean onTouch(View view, MotionEvent me) {
103 | // Only capture drag events if we start
104 | if (view != mHandle) {
105 | return false;
106 | }
107 | //Log.v("foo", "at "+SystemClock.elapsedRealtime()+" got touch event " + me);
108 | if (me.getAction() == MotionEvent.ACTION_DOWN) {
109 | mDragging = true;
110 | mDraggingStarted = SystemClock.elapsedRealtime();
111 | mDragStartX = me.getX();
112 | mDragStartY = me.getY();
113 | if (getOrientation() == VERTICAL) {
114 | mPointerOffset = me.getRawY() - getPrimaryContentSize();
115 | } else {
116 | mPointerOffset = me.getRawX() - getPrimaryContentSize();
117 | }
118 | return true;
119 | }
120 | else if (me.getAction() == MotionEvent.ACTION_UP) {
121 | mDragging = false;
122 | if (
123 | mDragStartX <(me.getX()+TAP_DRIFT_TOLERANCE) &&
124 | mDragStartX > (me.getX() -TAP_DRIFT_TOLERANCE) &&
125 | mDragStartY < (me.getY() + TAP_DRIFT_TOLERANCE) &&
126 | mDragStartY > (me.getY() - TAP_DRIFT_TOLERANCE) &&
127 | ((SystemClock.elapsedRealtime() - mDraggingStarted) < SINGLE_TAP_MAX_TIME)) {
128 | if (isPrimaryContentMaximized() || isSecondaryContentMaximized()) {
129 | setPrimaryContentSize(mLastPrimaryContentSize);
130 | } else {
131 | maximizeSecondaryContent();
132 | }
133 | }
134 | return true;
135 | } else if (me.getAction() == MotionEvent.ACTION_MOVE) {
136 | if (getOrientation() == VERTICAL) {
137 | setPrimaryContentHeight( (int)(me.getRawY() - mPointerOffset));
138 | } else {
139 | setPrimaryContentWidth( (int)(me.getRawX() - mPointerOffset));
140 | }
141 | }
142 | return true;
143 | }
144 |
145 |
146 | public View getHandle() {
147 | return mHandle;
148 | }
149 |
150 | public int getPrimaryContentSize() {
151 | if (getOrientation() == VERTICAL) {
152 | return mPrimaryContent.getMeasuredHeight();
153 | } else {
154 | return mPrimaryContent.getMeasuredWidth();
155 | }
156 |
157 | }
158 |
159 | public boolean setPrimaryContentSize(int newSize) {
160 | if (getOrientation() == VERTICAL) {
161 | return setPrimaryContentHeight(newSize);
162 | } else {
163 | return setPrimaryContentWidth(newSize);
164 | }
165 | }
166 |
167 |
168 | private boolean setPrimaryContentHeight(int newHeight) {
169 | // the new primary content height should not be less than 0 to make the
170 | // handler always visible
171 | newHeight = Math.max(0, newHeight);
172 | // the new primary content height should not be more than the SplitView
173 | // height minus handler height to make the handler always visible
174 | newHeight = Math.min(newHeight, getMeasuredHeight() - mHandle.getMeasuredHeight());
175 | LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mPrimaryContent
176 | .getLayoutParams();
177 | if (mSecondaryContent.getMeasuredHeight() < 1 && newHeight > params.height) {
178 | return false;
179 | }
180 | if (newHeight >= 0) {
181 | params.height = newHeight;
182 | // set the primary content parameter to do not stretch anymore and
183 | // use the height specified in the layout params
184 | params.weight = 0;
185 | }
186 | unMinimizeSecondaryContent();
187 | mPrimaryContent.setLayoutParams(params);
188 | return true;
189 |
190 | }
191 |
192 | private boolean setPrimaryContentWidth(int newWidth) {
193 | // the new primary content width should not be less than 0 to make the
194 | // handler always visible
195 | newWidth = Math.max(0, newWidth);
196 | // the new primary content width should not be more than the SplitView
197 | // width minus handler width to make the handler always visible
198 | newWidth = Math.min(newWidth, getMeasuredWidth() - mHandle.getMeasuredWidth());
199 | LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mPrimaryContent
200 | .getLayoutParams();
201 |
202 |
203 | if (mSecondaryContent.getMeasuredWidth() < 1 && newWidth > params.width) {
204 | return false;
205 | }
206 | if (newWidth >= 0) {
207 | params.width = newWidth;
208 | // set the primary content parameter to do not stretch anymore and
209 | // use the width specified in the layout params
210 | params.weight = 0;
211 | }
212 | unMinimizeSecondaryContent();
213 | mPrimaryContent.setLayoutParams(params);
214 | return true;
215 | }
216 | public boolean isPrimaryContentMaximized() {
217 | if ( (getOrientation() == VERTICAL && (mSecondaryContent.getMeasuredHeight() < MAXIMIZED_VIEW_TOLERANCE_DIP) ) ||
218 | (getOrientation() == HORIZONTAL && (mSecondaryContent.getMeasuredWidth() < MAXIMIZED_VIEW_TOLERANCE_DIP) )) {
219 | return true;
220 | } else {
221 | return false;
222 | }
223 |
224 | }
225 |
226 |
227 | public boolean isSecondaryContentMaximized() {
228 | if ( (getOrientation() == VERTICAL && (mPrimaryContent.getMeasuredHeight() < MAXIMIZED_VIEW_TOLERANCE_DIP) ) ||
229 | (getOrientation() == HORIZONTAL && (mPrimaryContent.getMeasuredWidth() < MAXIMIZED_VIEW_TOLERANCE_DIP) )) {
230 | return true;
231 | } else {
232 | return false;
233 | }
234 | }
235 |
236 | public void maximizePrimaryContent() {
237 | maximizeContentPane(mPrimaryContent, mSecondaryContent);
238 | }
239 |
240 | public void maximizeSecondaryContent() {
241 | maximizeContentPane(mSecondaryContent, mPrimaryContent);
242 | }
243 |
244 |
245 |
246 | private void maximizeContentPane(View toMaximize, View toUnMaximize) {
247 | mLastPrimaryContentSize = getPrimaryContentSize();
248 |
249 | LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) toUnMaximize
250 | .getLayoutParams();
251 | LinearLayout.LayoutParams secondaryParams = (LinearLayout.LayoutParams) toMaximize
252 | .getLayoutParams();
253 | // set the primary content parameter to do not stretch anymore and use
254 | // the height/width specified in the layout params
255 | params.weight = 0;
256 | // set the secondary content parameter to use all the available space
257 | secondaryParams.weight = 1;
258 | if (getOrientation() == VERTICAL) {
259 | params.height = 1;
260 | } else {
261 | params.width = 1;
262 | }
263 | toUnMaximize.setLayoutParams(params);
264 | toMaximize.setLayoutParams(secondaryParams);
265 |
266 |
267 |
268 | }
269 |
270 | private void unMinimizeSecondaryContent() {
271 | LinearLayout.LayoutParams secondaryParams = (LinearLayout.LayoutParams) mSecondaryContent
272 | .getLayoutParams();
273 | // set the secondary content parameter to use all the available space
274 | secondaryParams.weight = 1;
275 | mSecondaryContent.setLayoutParams(secondaryParams);
276 |
277 | }
278 |
279 | };
280 |
--------------------------------------------------------------------------------