├── SlidingMenuDemo
├── .gitignore
├── res
│ ├── drawable
│ │ └── fb_menu.png
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── values
│ │ └── strings.xml
│ ├── layout
│ │ ├── list_item.xml
│ │ ├── horz_scroll_menu.xml
│ │ ├── horz_scroll_with_list_menu.xml
│ │ ├── horz_scroll_app.xml
│ │ ├── test_slide_activity.xml
│ │ ├── animation_stacked_frames.xml
│ │ ├── horz_scroll_with_image_menu.xml
│ │ ├── activity_menu.xml
│ │ ├── dummy_menu.xml
│ │ ├── slide_animation_then_call_layout.xml
│ │ └── push_left_push_right_animation.xml
│ └── anim
│ │ ├── push_left_in.xml
│ │ ├── push_left_in_80.xml
│ │ ├── push_left_out.xml
│ │ ├── push_right_in.xml
│ │ ├── push_right_out.xml
│ │ └── push_right_out_80.xml
├── README.rst
├── .classpath
├── project.properties
├── .project
├── proguard.cfg
├── AndroidManifest.xml
├── src
│ └── grimbo
│ │ └── android
│ │ └── demo
│ │ └── slidingmenu
│ │ ├── TestSlideActivity.java
│ │ ├── MenuActivity.java
│ │ ├── ViewUtils.java
│ │ ├── HorzScrollWithImageMenu.java
│ │ ├── PushLeftPushRightAnimation.java
│ │ ├── AnimationStackedFrames.java
│ │ ├── SlideAnimationThenCallLayout.java
│ │ ├── HorzScrollWithListMenu.java
│ │ └── MyHorizontalScrollView.java
└── LICENSE.txt
└── README.rst
/SlidingMenuDemo/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/*
2 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/drawable/fb_menu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gitgrimbo/android-sliding-menu-demo/HEAD/SlidingMenuDemo/res/drawable/fb_menu.png
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gitgrimbo/android-sliding-menu-demo/HEAD/SlidingMenuDemo/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gitgrimbo/android-sliding-menu-demo/HEAD/SlidingMenuDemo/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gitgrimbo/android-sliding-menu-demo/HEAD/SlidingMenuDemo/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Sliding Menu Demo
4 |
5 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | ========
2 | README
3 | ========
4 |
5 | What is it?
6 | ===========
7 |
8 | This is a demo project to explore how to implement a sliding menu like Facebook and others use.
9 |
10 | License
11 | =======
12 |
13 | Released under version 2.0 of the `Apache License `_
14 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/README.rst:
--------------------------------------------------------------------------------
1 | ========
2 | README
3 | ========
4 |
5 | What is it?
6 | ===========
7 |
8 | This is a demo project to explore how to implement a sliding menu like Facebook and others use.
9 |
10 | License
11 | =======
12 |
13 | Released under version 2.0 of the `Apache License `_
14 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-8
12 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/horz_scroll_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/horz_scroll_with_list_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | SlidingMenuDemo
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/anim/push_left_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/anim/push_left_in_80.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/anim/push_left_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/anim/push_right_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/anim/push_right_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/anim/push_right_out_80.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/horz_scroll_app.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
7 |
9 |
10 |
11 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/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 | -keepclasseswithmembers class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembers class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers class * extends android.app.Activity {
30 | public void *(android.view.View);
31 | }
32 |
33 | -keepclassmembers enum * {
34 | public static **[] values();
35 | public static ** valueOf(java.lang.String);
36 | }
37 |
38 | -keep class * implements android.os.Parcelable {
39 | public static final android.os.Parcelable$Creator *;
40 | }
41 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/test_slide_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
11 |
12 |
14 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/animation_stacked_frames.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
8 |
10 |
12 |
14 |
15 |
16 |
19 |
20 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/horz_scroll_with_image_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
10 |
11 |
15 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/activity_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/dummy_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
7 |
9 |
11 |
13 |
15 |
17 |
19 |
21 |
22 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/slide_animation_then_call_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
7 |
9 |
11 |
13 |
15 |
17 |
19 |
21 |
23 |
24 |
26 |
28 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/src/grimbo/android/demo/slidingmenu/TestSlideActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * SlidingMenuDemo
4 | * $Id:$
5 | * $HeadURL:$
6 | * %%
7 | * Copyright (C) 2012 Paul Grime
8 | * %%
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | * #L%
21 | */
22 | package grimbo.android.demo.slidingmenu;
23 |
24 | import android.app.Activity;
25 | import android.os.Bundle;
26 | import android.view.LayoutInflater;
27 | import android.view.View;
28 | import android.view.View.OnClickListener;
29 | import android.view.ViewGroup;
30 | import android.widget.Button;
31 | import android.widget.LinearLayout;
32 |
33 | /**
34 | * This demo does not work.
35 | */
36 | public class TestSlideActivity extends Activity {
37 | ViewGroup parentLayout;
38 | LinearLayout layout1;
39 | LinearLayout layout2;
40 | boolean layout1Shown = true;
41 |
42 | class ClickListener implements OnClickListener {
43 | @Override
44 | public void onClick(View v) {
45 | ViewUtils.printView("parentLayout", parentLayout);
46 | ViewUtils.printView("layout1", layout1);
47 | ViewUtils.printView("layout2", layout2);
48 | if (layout1Shown) {
49 | parentLayout.scrollTo(-parentLayout.getWidth(), 0);
50 | } else {
51 | parentLayout.scrollTo(0, 0);
52 | }
53 | layout1Shown = !layout1Shown;
54 | }
55 | }
56 |
57 | @Override
58 | public void onCreate(Bundle savedInstanceState) {
59 | super.onCreate(savedInstanceState);
60 |
61 | View contentView = LayoutInflater.from(this).inflate(R.layout.test_slide_activity, null);
62 | setContentView(contentView);
63 |
64 | parentLayout = (ViewGroup) findViewById(R.id.ParentLayout);
65 | layout1 = (LinearLayout) findViewById(R.id.Layout1);
66 | layout2 = (LinearLayout) findViewById(R.id.Layout2);
67 | ViewUtils.setViewWidths(layout1, new View[] { layout2 });
68 |
69 | Button btnSlide = (Button) findViewById(R.id.BtnSlide);
70 | btnSlide.setOnClickListener(new ClickListener());
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/src/grimbo/android/demo/slidingmenu/MenuActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * SlidingMenuDemo
4 | * $Id:$
5 | * $HeadURL:$
6 | * %%
7 | * Copyright (C) 2012 Paul Grime
8 | * %%
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | * #L%
21 | */
22 | package grimbo.android.demo.slidingmenu;
23 |
24 | import android.app.Activity;
25 | import android.content.Context;
26 | import android.content.Intent;
27 | import android.os.Bundle;
28 | import android.view.LayoutInflater;
29 | import android.view.View;
30 | import android.view.View.OnClickListener;
31 | import android.view.ViewGroup;
32 | import android.widget.Button;
33 | import android.widget.Toast;
34 |
35 | /**
36 | * Simple Activity that uses each Button in the layout to invoke an Activity.
37 | */
38 | public class MenuActivity extends Activity {
39 | @Override
40 | public void onCreate(Bundle savedInstanceState) {
41 | super.onCreate(savedInstanceState);
42 |
43 | final String packageName = this.getClass().getPackage().getName();
44 | final Context context = this;
45 |
46 | // ScrollView
47 | ViewGroup contentView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.activity_menu, null);
48 |
49 | // Layout containing Buttons
50 | ViewGroup g = (ViewGroup) contentView.getChildAt(0);
51 | int count = g.getChildCount();
52 |
53 | for (int i = 0; i < count; i++) {
54 | Button btn = (Button) g.getChildAt(i);
55 | final String text = btn.getText().toString();
56 | btn.setOnClickListener(new OnClickListener() {
57 | @Override
58 | public void onClick(View v) {
59 | try {
60 | Class c = Class.forName(packageName + "." + text);
61 | startActivity(new Intent(context, c));
62 | } catch (ClassNotFoundException e) {
63 | Toast.makeText(context, String.valueOf(e), 5000).show();
64 | }
65 | }
66 | });
67 | }
68 |
69 | setContentView(contentView);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/src/grimbo/android/demo/slidingmenu/ViewUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * SlidingMenuDemo
4 | * $Id:$
5 | * $HeadURL:$
6 | * %%
7 | * Copyright (C) 2012 Paul Grime
8 | * %%
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | * #L%
21 | */
22 | package grimbo.android.demo.slidingmenu;
23 |
24 | import android.content.Context;
25 | import android.view.View;
26 | import android.widget.AdapterView;
27 | import android.widget.AdapterView.OnItemClickListener;
28 | import android.widget.ArrayAdapter;
29 | import android.widget.ListView;
30 | import android.widget.Toast;
31 |
32 | /**
33 | * Utility methods for Views.
34 | */
35 | public class ViewUtils {
36 | private ViewUtils() {
37 | }
38 |
39 | public static void setViewWidths(View view, View[] views) {
40 | int w = view.getWidth();
41 | int h = view.getHeight();
42 | for (int i = 0; i < views.length; i++) {
43 | View v = views[i];
44 | v.layout((i + 1) * w, 0, (i + 2) * w, h);
45 | printView("view[" + i + "]", v);
46 | }
47 | }
48 |
49 | public static void printView(String msg, View v) {
50 | System.out.println(msg + "=" + v);
51 | if (null == v) {
52 | return;
53 | }
54 | System.out.print("[" + v.getLeft());
55 | System.out.print(", " + v.getTop());
56 | System.out.print(", w=" + v.getWidth());
57 | System.out.println(", h=" + v.getHeight() + "]");
58 | System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight());
59 | System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]");
60 | }
61 |
62 | public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) {
63 | // By using setAdpater method in listview we an add string array in list.
64 | String[] arr = new String[numItems];
65 | for (int i = 0; i < arr.length; i++) {
66 | arr[i] = prefix + (i + 1);
67 | }
68 | listView.setAdapter(new ArrayAdapter(context, layout, arr));
69 | listView.setOnItemClickListener(new OnItemClickListener() {
70 | @Override
71 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
72 | Context context = view.getContext();
73 | String msg = "item[" + position + "]=" + parent.getItemAtPosition(position);
74 | Toast.makeText(context, msg, 1000).show();
75 | System.out.println(msg);
76 | }
77 | });
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/src/grimbo/android/demo/slidingmenu/HorzScrollWithImageMenu.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * SlidingMenuDemo
4 | * $Id:$
5 | * $HeadURL:$
6 | * %%
7 | * Copyright (C) 2012 Paul Grime
8 | * %%
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | * #L%
21 | */
22 | package grimbo.android.demo.slidingmenu;
23 |
24 | import android.app.Activity;
25 | import android.os.Bundle;
26 | import android.os.Handler;
27 | import android.view.LayoutInflater;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 | import android.widget.ImageView;
31 | import android.widget.ListView;
32 | import android.widget.TextView;
33 |
34 | /**
35 | * This example uses a FrameLayout to display a menu View and a HorizontalScrollView (HSV).
36 | *
37 | * The HSV has a transparent View as the first child, which means the menu will show through when the HSV is scrolled.
38 | */
39 | public class HorzScrollWithImageMenu extends Activity {
40 | MyHorizontalScrollView scrollView;
41 | View menu;
42 | View app;
43 | ImageView btnSlide;
44 | boolean menuOut = false;
45 | Handler handler = new Handler();
46 | int btnWidth;
47 |
48 | @Override
49 | public void onCreate(Bundle savedInstanceState) {
50 | super.onCreate(savedInstanceState);
51 |
52 | LayoutInflater inflater = LayoutInflater.from(this);
53 | setContentView(inflater.inflate(R.layout.horz_scroll_with_image_menu, null));
54 |
55 | scrollView = (MyHorizontalScrollView) findViewById(R.id.myScrollView);
56 | menu = findViewById(R.id.menu);
57 | app = inflater.inflate(R.layout.horz_scroll_app, null);
58 | ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar);
59 |
60 | ListView listView = (ListView) app.findViewById(R.id.list);
61 | ViewUtils.initListView(this, listView, "Item ", 30, android.R.layout.simple_list_item_1);
62 |
63 | btnSlide = (ImageView) tabBar.findViewById(R.id.BtnSlide);
64 | btnSlide.setOnClickListener(new HorzScrollWithListMenu.ClickListenerForScrolling(scrollView, menu));
65 |
66 | // Create a transparent view that pushes the other views in the HSV to the right.
67 | // This transparent view allows the menu to be shown when the HSV is scrolled.
68 | View transparent = new TextView(this);
69 | transparent.setBackgroundColor(android.R.color.transparent);
70 |
71 | final View[] children = new View[] { transparent, app };
72 |
73 | // Scroll to app (view[1]) when layout finished.
74 | int scrollToViewIdx = 1;
75 | scrollView.initViews(children, scrollToViewIdx, new HorzScrollWithListMenu.SizeCallbackForMenu(btnSlide));
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/src/grimbo/android/demo/slidingmenu/PushLeftPushRightAnimation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * SlidingMenuDemo
4 | * $Id:$
5 | * $HeadURL:$
6 | * %%
7 | * Copyright (C) 2012 Paul Grime
8 | * %%
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | * #L%
21 | */
22 | package grimbo.android.demo.slidingmenu;
23 |
24 | import android.app.Activity;
25 | import android.content.Context;
26 | import android.os.Bundle;
27 | import android.view.View;
28 | import android.view.View.OnClickListener;
29 | import android.view.animation.Animation;
30 | import android.view.animation.Animation.AnimationListener;
31 | import android.view.animation.AnimationUtils;
32 | import android.widget.ViewFlipper;
33 |
34 | /**
35 | * Demo of a push left/push right animation. Note that Android Animations do not move a View, they only alter the rendering of
36 | * the View.
37 | */
38 | public class PushLeftPushRightAnimation extends Activity implements AnimationListener {
39 | ViewFlipper mFlipper;
40 | Animation in;
41 | Animation out;
42 |
43 | class ClickListener implements OnClickListener {
44 | @Override
45 | public void onClick(View v) {
46 | PushLeftPushRightAnimation me = PushLeftPushRightAnimation.this;
47 | Context context = me;
48 | int curView = mFlipper.getCurrentView().getId();
49 | if (R.id.view1 == curView) {
50 | in = AnimationUtils.loadAnimation(context, R.anim.push_right_in);
51 | out = AnimationUtils.loadAnimation(context, R.anim.push_right_out);
52 | } else {
53 | in = AnimationUtils.loadAnimation(context, R.anim.push_left_in);
54 | out = AnimationUtils.loadAnimation(context, R.anim.push_left_out);
55 | }
56 | in.setAnimationListener(me);
57 | out.setAnimationListener(me);
58 | mFlipper.setInAnimation(in);
59 | mFlipper.setOutAnimation(out);
60 | mFlipper.showNext();
61 | }
62 | }
63 |
64 | @Override
65 | public void onCreate(Bundle savedInstanceState) {
66 | super.onCreate(savedInstanceState);
67 | setContentView(R.layout.push_left_push_right_animation);
68 |
69 | mFlipper = (ViewFlipper) findViewById(R.id.flipper);
70 |
71 | findViewById(R.id.BtnSlide).setOnClickListener(new ClickListener());
72 | }
73 |
74 | @Override
75 | public void onAnimationEnd(Animation animation) {
76 | System.out.println("onAnimationEnd " + (in == animation ? "in" : "out"));
77 | }
78 |
79 | @Override
80 | public void onAnimationRepeat(Animation animation) {
81 | System.out.println("onAnimationRepeat " + (in == animation ? "in" : "out"));
82 | }
83 |
84 | @Override
85 | public void onAnimationStart(Animation animation) {
86 | System.out.println("onAnimationStart " + (in == animation ? "in" : "out"));
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/res/layout/push_left_push_right_animation.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
8 |
9 |
11 |
13 |
15 |
17 |
19 |
21 |
23 |
25 |
27 |
29 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/src/grimbo/android/demo/slidingmenu/AnimationStackedFrames.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * SlidingMenuDemo
4 | * $Id:$
5 | * $HeadURL:$
6 | * %%
7 | * Copyright (C) 2012 Paul Grime
8 | * %%
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | * #L%
21 | */
22 | package grimbo.android.demo.slidingmenu;
23 |
24 | import android.app.Activity;
25 | import android.content.Context;
26 | import android.os.Bundle;
27 | import android.view.View;
28 | import android.view.View.OnClickListener;
29 | import android.view.animation.Animation;
30 | import android.view.animation.Animation.AnimationListener;
31 | import android.view.animation.AnimationUtils;
32 | import android.widget.FrameLayout;
33 | import android.widget.ListView;
34 |
35 | /**
36 | * Animates the menu view over the app view in a FrameLayout.
37 | *
38 | * As this uses animations, after the menu has moved over the app, touch events are still passed to the app, as the menu View
39 | * actually hasn't moved. The animation just renders the menu in a different location to its real position.
40 | */
41 | public class AnimationStackedFrames extends Activity implements AnimationListener {
42 | FrameLayout mFrameLayout;
43 | View menu;
44 | View app;
45 | boolean menuOut = false;
46 |
47 | class ClickListener implements OnClickListener {
48 | @Override
49 | public void onClick(View v) {
50 | AnimationStackedFrames me = AnimationStackedFrames.this;
51 | Context context = me;
52 | Animation anim;
53 | if (!menuOut) {
54 | menu.setVisibility(View.VISIBLE);
55 | ViewUtils.printView("menu", menu);
56 | anim = AnimationUtils.loadAnimation(context, R.anim.push_right_in);
57 | } else {
58 | anim = AnimationUtils.loadAnimation(context, R.anim.push_left_out);
59 | }
60 | anim.setAnimationListener(me);
61 | // out.setAnimationListener(me);
62 | menu.startAnimation(anim);
63 | }
64 | }
65 |
66 | static class ViewMover implements OnClickListener {
67 | View v;
68 | int dx = 1;
69 |
70 | public ViewMover(View v, int dx) {
71 | this.v = v;
72 | this.dx = dx;
73 | }
74 |
75 | @Override
76 | public void onClick(View v) {
77 | move(this.v);
78 | }
79 |
80 | public void move(View v) {
81 | v.layout(v.getLeft() + dx, 0, v.getLeft() + dx + v.getWidth(), v.getHeight());
82 | ViewUtils.printView("menu", v);
83 | }
84 | }
85 |
86 | @Override
87 | public void onCreate(Bundle savedInstanceState) {
88 | super.onCreate(savedInstanceState);
89 | setContentView(R.layout.animation_stacked_frames);
90 |
91 | mFrameLayout = (FrameLayout) this.findViewById(R.id.flipper);
92 | menu = mFrameLayout.findViewById(R.id.menu);
93 | app = mFrameLayout.findViewById(R.id.app);
94 |
95 | ViewUtils.printView("menu", menu);
96 | ViewUtils.printView("app", app);
97 |
98 | ListView listView = (ListView) app;
99 | ViewUtils.initListView(this, listView, "Item ", 30, android.R.layout.simple_list_item_1);
100 |
101 | View btns = findViewById(R.id.btns);
102 | btns.findViewById(R.id.BtnSlide).setOnClickListener(new ClickListener());
103 | btns.findViewById(R.id.BtnIncX).setOnClickListener(new ViewMover(menu, 5));
104 | btns.findViewById(R.id.BtnDecX).setOnClickListener(new ViewMover(menu, -5));
105 | }
106 |
107 | @Override
108 | public void onAnimationEnd(Animation animation) {
109 | System.out.println("onAnimationEnd " + animation);
110 | System.out.println("menuOut=" + menuOut);
111 | ViewUtils.printView("menu", menu);
112 | ViewUtils.printView("app", app);
113 | menuOut = !menuOut;
114 | if (!menuOut) {
115 | menu.setVisibility(View.INVISIBLE);
116 | }
117 | }
118 |
119 | @Override
120 | public void onAnimationRepeat(Animation animation) {
121 | System.out.println("onAnimationRepeat " + animation);
122 | System.out.println("menuOut=" + menuOut);
123 | }
124 |
125 | @Override
126 | public void onAnimationStart(Animation animation) {
127 | System.out.println("onAnimationStart " + animation);
128 | System.out.println("menuOut=" + menuOut);
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/src/grimbo/android/demo/slidingmenu/SlideAnimationThenCallLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * SlidingMenuDemo
4 | * $Id:$
5 | * $HeadURL:$
6 | * %%
7 | * Copyright (C) 2012 Paul Grime
8 | * %%
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | * #L%
21 | */
22 | package grimbo.android.demo.slidingmenu;
23 |
24 | import java.util.Date;
25 |
26 | import android.app.Activity;
27 | import android.content.Context;
28 | import android.os.Bundle;
29 | import android.view.View;
30 | import android.view.View.OnClickListener;
31 | import android.view.animation.Animation;
32 | import android.view.animation.Animation.AnimationListener;
33 | import android.view.animation.TranslateAnimation;
34 | import android.widget.ListView;
35 |
36 | /**
37 | * Removed the flicker
38 | *
39 | */
40 | public class SlideAnimationThenCallLayout extends Activity implements AnimationListener {
41 | View menu;
42 | View app;
43 | boolean menuOut = false;
44 | AnimParams animParams = new AnimParams();
45 |
46 | class ClickListener implements OnClickListener {
47 | @Override
48 | public void onClick(View v) {
49 | System.out.println("onClick " + new Date());
50 | SlideAnimationThenCallLayout me = SlideAnimationThenCallLayout.this;
51 | Context context = me;
52 | Animation anim;
53 |
54 | int w = app.getMeasuredWidth();
55 | int h = app.getMeasuredHeight();
56 | int left = (int) (app.getMeasuredWidth() * 0.8);
57 |
58 | if (!menuOut) {
59 | // anim = AnimationUtils.loadAnimation(context, R.anim.push_right_out_80);
60 | anim = new TranslateAnimation(0, left, 0, 0);
61 | menu.setVisibility(View.VISIBLE);
62 | animParams.init(left, 0, left + w, h);
63 | } else {
64 | // anim = AnimationUtils.loadAnimation(context, R.anim.push_left_in_80);
65 | anim = new TranslateAnimation(0, -left, 0, 0);
66 | animParams.init(0, 0, w, h);
67 | }
68 |
69 | anim.setDuration(500);
70 | anim.setAnimationListener(me);
71 | //Tell the animation to stay as it ended (we are going to set the app.layout first than remove this property)
72 | anim.setFillAfter(true);
73 |
74 |
75 | // Only use fillEnabled and fillAfter if we don't call layout ourselves.
76 | // We need to do the layout ourselves and not use fillEnabled and fillAfter because when the anim is finished
77 | // although the View appears to have moved, it is actually just a drawing effect and the View hasn't moved.
78 | // Therefore clicking on the screen where the button appears does not work, but clicking where the View *was* does
79 | // work.
80 | // anim.setFillEnabled(true);
81 | // anim.setFillAfter(true);
82 |
83 | app.startAnimation(anim);
84 | }
85 | }
86 |
87 | @Override
88 | public void onCreate(Bundle savedInstanceState) {
89 | super.onCreate(savedInstanceState);
90 | setContentView(R.layout.slide_animation_then_call_layout);
91 |
92 | menu = findViewById(R.id.menu);
93 | app = findViewById(R.id.app);
94 |
95 | ViewUtils.printView("menu", menu);
96 | ViewUtils.printView("app", app);
97 |
98 | ListView listView = (ListView) app.findViewById(R.id.list);
99 | ViewUtils.initListView(this, listView, "Item ", 30, android.R.layout.simple_list_item_1);
100 |
101 | app.findViewById(R.id.BtnSlide).setOnClickListener(new ClickListener());
102 | }
103 |
104 | void layoutApp(boolean menuOut) {
105 | System.out.println("layout [" + animParams.left + "," + animParams.top + "," + animParams.right + ","
106 | + animParams.bottom + "]");
107 | app.layout(animParams.left, animParams.top, animParams.right, animParams.bottom);
108 | //Now that we've set the app.layout property we can clear the animation, flicker avoided :)
109 | app.clearAnimation();
110 |
111 | }
112 |
113 | @Override
114 | public void onAnimationEnd(Animation animation) {
115 | System.out.println("onAnimationEnd");
116 | ViewUtils.printView("menu", menu);
117 | ViewUtils.printView("app", app);
118 | menuOut = !menuOut;
119 | if (!menuOut) {
120 | menu.setVisibility(View.INVISIBLE);
121 | }
122 | layoutApp(menuOut);
123 | }
124 |
125 | @Override
126 | public void onAnimationRepeat(Animation animation) {
127 | System.out.println("onAnimationRepeat");
128 | }
129 |
130 | @Override
131 | public void onAnimationStart(Animation animation) {
132 | System.out.println("onAnimationStart");
133 | }
134 |
135 | static class AnimParams {
136 | int left, right, top, bottom;
137 |
138 | void init(int left, int top, int right, int bottom) {
139 | this.left = left;
140 | this.top = top;
141 | this.right = right;
142 | this.bottom = bottom;
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/src/grimbo/android/demo/slidingmenu/HorzScrollWithListMenu.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * SlidingMenuDemo
4 | * $Id:$
5 | * $HeadURL:$
6 | * %%
7 | * Copyright (C) 2012 Paul Grime
8 | * %%
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | * #L%
21 | */
22 | package grimbo.android.demo.slidingmenu;
23 |
24 | import grimbo.android.demo.slidingmenu.MyHorizontalScrollView.SizeCallback;
25 |
26 | import java.util.Date;
27 |
28 | import android.app.Activity;
29 | import android.content.Context;
30 | import android.os.Bundle;
31 | import android.os.Handler;
32 | import android.view.LayoutInflater;
33 | import android.view.View;
34 | import android.view.View.OnClickListener;
35 | import android.view.ViewGroup;
36 | import android.widget.HorizontalScrollView;
37 | import android.widget.ImageView;
38 | import android.widget.ListView;
39 | import android.widget.Toast;
40 |
41 | /**
42 | * This demo uses a custom HorizontalScrollView that ignores touch events, and therefore does NOT allow manual scrolling.
43 | *
44 | * The only scrolling allowed is scrolling in code triggered by the menu button.
45 | *
46 | * When the button is pressed, both the menu and the app will scroll. So the menu isn't revealed from beneath the app, it
47 | * adjoins the app and moves with the app.
48 | */
49 | public class HorzScrollWithListMenu extends Activity {
50 | MyHorizontalScrollView scrollView;
51 | View menu;
52 | View app;
53 | ImageView btnSlide;
54 | boolean menuOut = false;
55 | Handler handler = new Handler();
56 | int btnWidth;
57 |
58 | @Override
59 | public void onCreate(Bundle savedInstanceState) {
60 | super.onCreate(savedInstanceState);
61 |
62 | LayoutInflater inflater = LayoutInflater.from(this);
63 | scrollView = (MyHorizontalScrollView) inflater.inflate(R.layout.horz_scroll_with_list_menu, null);
64 | setContentView(scrollView);
65 |
66 | menu = inflater.inflate(R.layout.horz_scroll_menu, null);
67 | app = inflater.inflate(R.layout.horz_scroll_app, null);
68 | ViewGroup tabBar = (ViewGroup) app.findViewById(R.id.tabBar);
69 |
70 | ListView listView = (ListView) app.findViewById(R.id.list);
71 | ViewUtils.initListView(this, listView, "Item ", 30, android.R.layout.simple_list_item_1);
72 |
73 | listView = (ListView) menu.findViewById(R.id.list);
74 | ViewUtils.initListView(this, listView, "Menu ", 30, android.R.layout.simple_list_item_1);
75 |
76 | btnSlide = (ImageView) tabBar.findViewById(R.id.BtnSlide);
77 | btnSlide.setOnClickListener(new ClickListenerForScrolling(scrollView, menu));
78 |
79 | final View[] children = new View[] { menu, app };
80 |
81 | // Scroll to app (view[1]) when layout finished.
82 | int scrollToViewIdx = 1;
83 | scrollView.initViews(children, scrollToViewIdx, new SizeCallbackForMenu(btnSlide));
84 | }
85 |
86 | /**
87 | * Helper for examples with a HSV that should be scrolled by a menu View's width.
88 | */
89 | static class ClickListenerForScrolling implements OnClickListener {
90 | HorizontalScrollView scrollView;
91 | View menu;
92 | /**
93 | * Menu must NOT be out/shown to start with.
94 | */
95 | boolean menuOut = false;
96 |
97 | public ClickListenerForScrolling(HorizontalScrollView scrollView, View menu) {
98 | super();
99 | this.scrollView = scrollView;
100 | this.menu = menu;
101 | }
102 |
103 | @Override
104 | public void onClick(View v) {
105 | Context context = menu.getContext();
106 | String msg = "Slide " + new Date();
107 | Toast.makeText(context, msg, 1000).show();
108 | System.out.println(msg);
109 |
110 | int menuWidth = menu.getMeasuredWidth();
111 |
112 | // Ensure menu is visible
113 | menu.setVisibility(View.VISIBLE);
114 |
115 | if (!menuOut) {
116 | // Scroll to 0 to reveal menu
117 | int left = 0;
118 | scrollView.smoothScrollTo(left, 0);
119 | } else {
120 | // Scroll to menuWidth so menu isn't on screen.
121 | int left = menuWidth;
122 | scrollView.smoothScrollTo(left, 0);
123 | }
124 | menuOut = !menuOut;
125 | }
126 | }
127 |
128 | /**
129 | * Helper that remembers the width of the 'slide' button, so that the 'slide' button remains in view, even when the menu is
130 | * showing.
131 | */
132 | static class SizeCallbackForMenu implements SizeCallback {
133 | int btnWidth;
134 | View btnSlide;
135 |
136 | public SizeCallbackForMenu(View btnSlide) {
137 | super();
138 | this.btnSlide = btnSlide;
139 | }
140 |
141 | @Override
142 | public void onGlobalLayout() {
143 | btnWidth = btnSlide.getMeasuredWidth();
144 | System.out.println("btnWidth=" + btnWidth);
145 | }
146 |
147 | @Override
148 | public void getViewSize(int idx, int w, int h, int[] dims) {
149 | dims[0] = w;
150 | dims[1] = h;
151 | final int menuIdx = 0;
152 | if (idx == menuIdx) {
153 | dims[0] = w - btnWidth;
154 | }
155 | }
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/src/grimbo/android/demo/slidingmenu/MyHorizontalScrollView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * #%L
3 | * SlidingMenuDemo
4 | * $Id:$
5 | * $HeadURL:$
6 | * %%
7 | * Copyright (C) 2012 Paul Grime
8 | * %%
9 | * Licensed under the Apache License, Version 2.0 (the "License");
10 | * you may not use this file except in compliance with the License.
11 | * You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing, software
16 | * distributed under the License is distributed on an "AS IS" BASIS,
17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | * See the License for the specific language governing permissions and
19 | * limitations under the License.
20 | * #L%
21 | */
22 | package grimbo.android.demo.slidingmenu;
23 |
24 | import android.content.Context;
25 | import android.os.Handler;
26 | import android.util.AttributeSet;
27 | import android.view.MotionEvent;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 | import android.view.ViewTreeObserver.OnGlobalLayoutListener;
31 | import android.widget.HorizontalScrollView;
32 |
33 | /**
34 | * A HorizontalScrollView (HSV) implementation that disallows touch events (so no scrolling can be done by the user).
35 | *
36 | * This HSV MUST contain a single ViewGroup as its only child, and this ViewGroup will be used to display the children Views
37 | * passed in to the initViews() method.
38 | */
39 | public class MyHorizontalScrollView extends HorizontalScrollView {
40 | public MyHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
41 | super(context, attrs, defStyle);
42 | init(context);
43 | }
44 |
45 | public MyHorizontalScrollView(Context context, AttributeSet attrs) {
46 | super(context, attrs);
47 | init(context);
48 | }
49 |
50 | public MyHorizontalScrollView(Context context) {
51 | super(context);
52 | init(context);
53 | }
54 |
55 | void init(Context context) {
56 | // remove the fading as the HSV looks better without it
57 | setHorizontalFadingEdgeEnabled(false);
58 | setVerticalFadingEdgeEnabled(false);
59 | }
60 |
61 | /**
62 | * @param children
63 | * The child Views to add to parent.
64 | * @param scrollToViewIdx
65 | * The index of the View to scroll to after initialisation.
66 | * @param sizeCallback
67 | * A SizeCallback to interact with the HSV.
68 | */
69 | public void initViews(View[] children, int scrollToViewIdx, SizeCallback sizeCallback) {
70 | // A ViewGroup MUST be the only child of the HSV
71 | ViewGroup parent = (ViewGroup) getChildAt(0);
72 |
73 | // Add all the children, but add them invisible so that the layouts are calculated, but you can't see the Views
74 | for (int i = 0; i < children.length; i++) {
75 | children[i].setVisibility(View.INVISIBLE);
76 | parent.addView(children[i]);
77 | }
78 |
79 | // Add a layout listener to this HSV
80 | // This listener is responsible for arranging the child views.
81 | OnGlobalLayoutListener listener = new MyOnGlobalLayoutListener(parent, children, scrollToViewIdx, sizeCallback);
82 | getViewTreeObserver().addOnGlobalLayoutListener(listener);
83 | }
84 |
85 | @Override
86 | public boolean onTouchEvent(MotionEvent ev) {
87 | // Do not allow touch events.
88 | return false;
89 | }
90 |
91 | @Override
92 | public boolean onInterceptTouchEvent(MotionEvent ev) {
93 | // Do not allow touch events.
94 | return false;
95 | }
96 |
97 | /**
98 | * An OnGlobalLayoutListener impl that passes on the call to onGlobalLayout to a SizeCallback, before removing all the Views
99 | * in the HSV and adding them again with calculated widths and heights.
100 | */
101 | class MyOnGlobalLayoutListener implements OnGlobalLayoutListener {
102 | ViewGroup parent;
103 | View[] children;
104 | int scrollToViewIdx;
105 | int scrollToViewPos = 0;
106 | SizeCallback sizeCallback;
107 |
108 | /**
109 | * @param parent
110 | * The parent to which the child Views should be added.
111 | * @param children
112 | * The child Views to add to parent.
113 | * @param scrollToViewIdx
114 | * The index of the View to scroll to after initialisation.
115 | * @param sizeCallback
116 | * A SizeCallback to interact with the HSV.
117 | */
118 | public MyOnGlobalLayoutListener(ViewGroup parent, View[] children, int scrollToViewIdx, SizeCallback sizeCallback) {
119 | this.parent = parent;
120 | this.children = children;
121 | this.scrollToViewIdx = scrollToViewIdx;
122 | this.sizeCallback = sizeCallback;
123 | }
124 |
125 | @Override
126 | public void onGlobalLayout() {
127 | // System.out.println("onGlobalLayout");
128 |
129 | final HorizontalScrollView me = MyHorizontalScrollView.this;
130 |
131 | // The listener will remove itself as a layout listener to the HSV
132 | me.getViewTreeObserver().removeGlobalOnLayoutListener(this);
133 |
134 | // Allow the SizeCallback to 'see' the Views before we remove them and re-add them.
135 | // This lets the SizeCallback prepare View sizes, ahead of calls to SizeCallback.getViewSize().
136 | sizeCallback.onGlobalLayout();
137 |
138 | parent.removeViewsInLayout(0, children.length);
139 |
140 | final int w = me.getMeasuredWidth();
141 | final int h = me.getMeasuredHeight();
142 |
143 | // System.out.println("w=" + w + ", h=" + h);
144 |
145 | // Add each view in turn, and apply the width and height returned by the SizeCallback.
146 | int[] dims = new int[2];
147 | scrollToViewPos = 0;
148 | for (int i = 0; i < children.length; i++) {
149 | sizeCallback.getViewSize(i, w, h, dims);
150 | // System.out.println("addView w=" + dims[0] + ", h=" + dims[1]);
151 | children[i].setVisibility(View.VISIBLE);
152 | parent.addView(children[i], dims[0], dims[1]);
153 | if (i < scrollToViewIdx) {
154 | scrollToViewPos += dims[0];
155 | }
156 | }
157 |
158 | // For some reason we need to post this action, rather than call immediately.
159 | // If we try immediately, it will not scroll.
160 | new Handler().post(new Runnable() {
161 | @Override
162 | public void run() {
163 | me.scrollBy(scrollToViewPos, 0);
164 | }
165 | });
166 | }
167 | }
168 |
169 | /**
170 | * Callback interface to interact with the HSV.
171 | */
172 | public interface SizeCallback {
173 | /**
174 | * Used to allow clients to measure Views before re-adding them.
175 | */
176 | public void onGlobalLayout();
177 |
178 | /**
179 | * Used by clients to specify the View dimensions.
180 | *
181 | * @param idx
182 | * Index of the View.
183 | * @param w
184 | * Width of the parent View.
185 | * @param h
186 | * Height of the parent View.
187 | * @param dims
188 | * dims[0] should be set to View width. dims[1] should be set to View height.
189 | */
190 | public void getViewSize(int idx, int w, int h, int[] dims);
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/SlidingMenuDemo/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------