Add SimonVT's android-menudrawer. This will be used in the menu interface for Dolphin Android.
No files matched your search
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="net.simonvt.menudrawer.samples"
|
||||
android:versionCode="3"
|
||||
android:versionName="2.0.1">
|
||||
|
||||
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17" />
|
||||
|
||||
<application
|
||||
android:label="@string/app_name"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:theme="@style/SampleTheme">
|
||||
|
||||
<activity
|
||||
android:name="SamplesActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="net.simonvt.menudrawer.samples.WindowSample" />
|
||||
<activity android:name="net.simonvt.menudrawer.samples.ContentSample" />
|
||||
<activity android:name="net.simonvt.menudrawer.samples.ListActivitySample" />
|
||||
<activity android:name="net.simonvt.menudrawer.samples.ActionBarOverlaySample" />
|
||||
<activity android:name="net.simonvt.menudrawer.samples.ViewPagerSample" />
|
||||
<activity
|
||||
android:name="net.simonvt.menudrawer.samples.RightMenuSample"
|
||||
android:theme="@style/SampleTheme.RightDrawer" />
|
||||
<activity
|
||||
android:name="net.simonvt.menudrawer.samples.TopMenuSample"
|
||||
android:theme="@style/SampleTheme.TopDrawer">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="net.simonvt.menudrawer.samples.SamplesActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name="net.simonvt.menudrawer.samples.BottomMenuSample"
|
||||
android:theme="@style/SampleTheme.BottomDrawer" />
|
||||
<activity
|
||||
android:name="net.simonvt.menudrawer.samples.LayoutSample"
|
||||
android:theme="@style/SampleTheme.TopDrawer" />
|
||||
<activity android:name="net.simonvt.menudrawer.samples.StaticDrawerSample" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="menudrawersamples" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- if sdk.dir was not set from one of the property file, then
|
||||
get it from the ANDROID_HOME env var.
|
||||
This must be done before we load project.properties since
|
||||
the proguard config can use sdk.dir -->
|
||||
<property environment="env" />
|
||||
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
|
||||
<isset property="env.ANDROID_HOME" />
|
||||
</condition>
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.simonvt</groupId>
|
||||
<artifactId>android-menudrawer-parent</artifactId>
|
||||
<version>2.0.3-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>android-menudrawer-sample</artifactId>
|
||||
<name>Android MenuDrawer Sample</name>
|
||||
<packaging>apk</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>android</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.simonvt</groupId>
|
||||
<artifactId>android-menudrawer</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>support-v4</artifactId>
|
||||
<version>${android-support.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
|
||||
<artifactId>android-maven-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,15 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-17
|
||||
android.library.reference.1=../library
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 148 B |
|
After Width: | Height: | Size: 173 B |
|
After Width: | Height: | Size: 191 B |
|
After Width: | Height: | Size: 154 B |
|
After Width: | Height: | Size: 159 B |
|
After Width: | Height: | Size: 189 B |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 891 B |
|
After Width: | Height: | Size: 904 B |
|
After Width: | Height: | Size: 862 B |
|
After Width: | Height: | Size: 878 B |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 131 B |
|
After Width: | Height: | Size: 165 B |
|
After Width: | Height: | Size: 171 B |
|
After Width: | Height: | Size: 151 B |
|
After Width: | Height: | Size: 158 B |
|
After Width: | Height: | Size: 172 B |
|
After Width: | Height: | Size: 869 B |
|
After Width: | Height: | Size: 887 B |
|
After Width: | Height: | Size: 855 B |
|
After Width: | Height: | Size: 835 B |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 184 B |
|
After Width: | Height: | Size: 179 B |
|
After Width: | Height: | Size: 203 B |
|
After Width: | Height: | Size: 158 B |
|
After Width: | Height: | Size: 163 B |
|
After Width: | Height: | Size: 190 B |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<transition xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/md__list_pressed_holo_dark" />
|
||||
<item android:drawable="@drawable/md__list_longpressed_holo" />
|
||||
</transition>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:state_window_focused="false" android:drawable="@color/md__transparent" />
|
||||
|
||||
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
|
||||
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/md__list_selector_disabled_holo_dark" />
|
||||
<item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/md__list_selector_disabled_holo_dark" />
|
||||
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/md__list_selector_background_transition_holo_dark" />
|
||||
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/md__list_selector_background_transition_holo_dark" />
|
||||
<item android:state_focused="true" android:drawable="@drawable/md__list_focused_holo" />
|
||||
</selector>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sample_bottommenu" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contentText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sample_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contentText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<net.simonvt.menudrawer.TopDrawer xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/drawer"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mdMenuSize="64dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@id/mdMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item1"
|
||||
style="@style/MenuDrawer.Widget.Title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawableLeft="@drawable/ic_action_refresh_dark"
|
||||
android:onClick="onDrawerItemClick"
|
||||
android:tag="Item no. 1"
|
||||
android:text="Item 1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item2"
|
||||
style="@style/MenuDrawer.Widget.Title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawableLeft="@drawable/ic_action_select_all_dark"
|
||||
android:onClick="onDrawerItemClick"
|
||||
android:tag="Item no. 2"
|
||||
android:text="Item 2" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@id/mdContent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sample_layout" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contentText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</net.simonvt.menudrawer.TopDrawer>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sample_rightmenu" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contentText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sample_static" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contentText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sample_topmenu" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contentText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/view_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/sample_window" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contentText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="64dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingTop="8dp"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/summary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/windowSample"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Window sample" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/overlayWindowSample"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Action Bar overlay window sample" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/contentSample"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Content sample" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/listActivitySample"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="ListActivity sample" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item1"
|
||||
style="@style/MenuDrawer.Widget.Title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawableLeft="@drawable/ic_action_refresh_dark"
|
||||
android:onClick="onDrawerItemClick"
|
||||
android:tag="Item no. 1"
|
||||
android:text="Item 1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item2"
|
||||
style="@style/MenuDrawer.Widget.Title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawableLeft="@drawable/ic_action_select_all_dark"
|
||||
android:onClick="onDrawerItemClick"
|
||||
android:tag="Item no. 2"
|
||||
android:text="Item 2" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/MenuDrawer.Widget.Category" />
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/MenuDrawer.Widget.Title" />
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableLeft="@drawable/ic_action_refresh_dark"
|
||||
android:text="Item 1"
|
||||
style="@style/MenuDrawer.Widget.Title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableLeft="@drawable/ic_action_select_all_dark"
|
||||
android:text="Item 2"
|
||||
style="@style/MenuDrawer.Widget.Title" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Cat 1"
|
||||
style="@style/MenuDrawer.Widget.Category" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableLeft="@drawable/ic_action_refresh_dark"
|
||||
android:text="Item 3"
|
||||
style="@style/MenuDrawer.Widget.Title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableLeft="@drawable/ic_action_select_all_dark"
|
||||
android:text="Item 4"
|
||||
style="@style/MenuDrawer.Widget.Title" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Cat 2"
|
||||
style="@style/MenuDrawer.Widget.Category" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableLeft="@drawable/ic_action_refresh_dark"
|
||||
android:text="Item 5"
|
||||
style="@style/MenuDrawer.Widget.Title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item6"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableLeft="@drawable/ic_action_select_all_dark"
|
||||
android:text="Item 6"
|
||||
style="@style/MenuDrawer.Widget.Title" />
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item1"
|
||||
style="@style/MenuDrawer.Widget.Title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawableLeft="@drawable/ic_action_refresh_dark"
|
||||
android:onClick="onDrawerItemClick"
|
||||
android:tag="Item no. 1"
|
||||
android:text="Item 1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item2"
|
||||
style="@style/MenuDrawer.Widget.Title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:drawableLeft="@drawable/ic_action_select_all_dark"
|
||||
android:onClick="onDrawerItemClick"
|
||||
android:tag="Item no. 2"
|
||||
android:text="Item 2" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,4 @@
|
||||
<resources>
|
||||
|
||||
<color name="windowBackground">#FFE8E8E8</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,7 @@
|
||||
<resources>
|
||||
|
||||
<style name="SampleBase" parent="@android:style/Theme.Holo.Light">
|
||||
<item name="android:windowBackground">@color/windowBackground</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,6 @@
|
||||
<resources>
|
||||
|
||||
<color name="md__transparent">#00000000</color>
|
||||
|
||||
<color name="md__defaultBackground">#FF555555</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">MenuDrawerSamples</string>
|
||||
|
||||
<string name="sample_content">Sample of dragging the content.\nThe menu consists of a ListView, for which the
|
||||
active position is saved through configuration changes.\nAdditionally, if the menu is open, a back press will
|
||||
close it.
|
||||
</string>
|
||||
|
||||
<string name="sample_window">Sample of dragging the entire window.\nThe menu is a simple ScrollView, with a click
|
||||
listener set on each item.\nThe drawer will animate slightly open, to make it more discoverable.\nAdditionally,
|
||||
if the menu is open, a back press will close it.
|
||||
</string>
|
||||
|
||||
<string name="sample_listactivity">Sample of how to use the drawer with ListActivity.\nWhen running on ICS or
|
||||
greater, the ActionBar up button will blink until clicked by the user. This is done to make the menu more
|
||||
discoverable.\nAdditionally, if the menu is open, a back press will close it.
|
||||
</string>
|
||||
|
||||
<string name="sample_rightmenu">This sample shows how to position the menu to the right of the content.\nRun on
|
||||
an API14+ device to see how it interacts with the overflow button.
|
||||
</string>
|
||||
|
||||
<string name="sample_topmenu">This sample shows how to position the menu above the content.</string>
|
||||
|
||||
<string name="sample_bottommenu">This sample shows how to position the menu below the content.</string>
|
||||
|
||||
<string name="sample_layout">This sample shows how to use the drawer in a layout file.
|
||||
\nThe top drawer is used in this sample.
|
||||
</string>
|
||||
|
||||
<string name="sample_static">This sample shows how to attach a drawer that is always visible.</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,55 @@
|
||||
<resources>
|
||||
|
||||
<style name="MenuDrawer" />
|
||||
|
||||
<style name="MenuDrawer.Widget" />
|
||||
|
||||
<style name="MenuDrawer.Widget.Category">
|
||||
<item name="android:textStyle">bold</item>
|
||||
<item name="android:textColor">?android:attr/textColorSecondaryInverse</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:textAllCaps">true</item>
|
||||
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
<item name="android:paddingLeft">16dp</item>
|
||||
<item name="android:background">@drawable/md__category_background</item>
|
||||
|
||||
<item name="android:singleLine">true</item>
|
||||
<item name="android:ellipsize">end</item>
|
||||
</style>
|
||||
|
||||
<style name="MenuDrawer.Widget.Title">
|
||||
<item name="android:background">@drawable/md__list_selector_holo_dark</item>
|
||||
<item name="android:textAppearance">?android:attr/textAppearance</item>
|
||||
<item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
|
||||
<item name="android:textSize">18sp</item>
|
||||
<item name="android:paddingLeft">16dp</item>
|
||||
<item name="android:paddingRight">32dp</item>
|
||||
<item name="android:paddingTop">8dp</item>
|
||||
<item name="android:paddingBottom">8dp</item>
|
||||
<item name="android:drawablePadding">16dp</item>
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
</style>
|
||||
|
||||
<style name="MenuDrawerStyle" parent="Widget.MenuDrawer">
|
||||
<item name="mdActiveIndicator">@drawable/menu_arrow</item>
|
||||
<item name="mdMenuSize">250dp</item>
|
||||
</style>
|
||||
|
||||
<style name="MenuDrawerStyle.Right" parent="Widget.MenuDrawer">
|
||||
<item name="mdActiveIndicator">@drawable/menu_arrow_right</item>
|
||||
<item name="mdMenuSize">150dp</item>
|
||||
</style>
|
||||
|
||||
<style name="MenuDrawerStyle.Top" parent="Widget.MenuDrawer">
|
||||
<item name="mdActiveIndicator">@drawable/menu_arrow_top</item>
|
||||
<item name="mdMenuSize">64dp</item>
|
||||
<item name="mdAllowIndicatorAnimation">true</item>
|
||||
</style>
|
||||
|
||||
<style name="MenuDrawerStyle.Bottom" parent="Widget.MenuDrawer">
|
||||
<item name="mdActiveIndicator">@drawable/menu_arrow_bottom</item>
|
||||
<item name="mdMenuSize">64dp</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,23 @@
|
||||
<resources>
|
||||
|
||||
<style name="SampleBase" parent="@android:style/Theme.Light" />
|
||||
|
||||
<style name="SampleTheme" parent="SampleBase">
|
||||
|
||||
<item name="menuDrawerStyle">@style/MenuDrawerStyle</item>
|
||||
</style>
|
||||
|
||||
<style name="SampleTheme.RightDrawer" parent="SampleBase">
|
||||
|
||||
<item name="menuDrawerStyle">@style/MenuDrawerStyle.Right</item>
|
||||
</style>
|
||||
|
||||
<style name="SampleTheme.TopDrawer" parent="SampleBase">
|
||||
<item name="menuDrawerStyle">@style/MenuDrawerStyle.Top</item>
|
||||
</style>
|
||||
|
||||
<style name="SampleTheme.BottomDrawer" parent="SampleBase">
|
||||
<item name="menuDrawerStyle">@style/MenuDrawerStyle.Bottom</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.Window;
|
||||
|
||||
public class ActionBarOverlaySample extends WindowSample {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle inState) {
|
||||
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
|
||||
super.onCreate(inState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import net.simonvt.menudrawer.MenuDrawer;
|
||||
import net.simonvt.menudrawer.Position;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Sample class illustrating how to add a menu drawer above the content area.
|
||||
*/
|
||||
public class BottomMenuSample extends Activity implements OnClickListener {
|
||||
|
||||
private MenuDrawer mMenuDrawer;
|
||||
private TextView mContentTextView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle inState) {
|
||||
super.onCreate(inState);
|
||||
|
||||
mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_CONTENT, Position.BOTTOM);
|
||||
mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
|
||||
mMenuDrawer.setContentView(R.layout.activity_bottommenu);
|
||||
mMenuDrawer.setMenuView(R.layout.menu_bottom);
|
||||
|
||||
mContentTextView = (TextView) findViewById(R.id.contentText);
|
||||
findViewById(R.id.item1).setOnClickListener(this);
|
||||
findViewById(R.id.item2).setOnClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Click handler for bottom drawer items.
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String tag = (String) v.getTag();
|
||||
mContentTextView.setText(String.format("%s clicked.", tag));
|
||||
mMenuDrawer.setActiveView(v);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import net.simonvt.menudrawer.MenuDrawer;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ContentSample extends Activity {
|
||||
|
||||
private static final String STATE_ACTIVE_POSITION = "net.simonvt.menudrawer.samples.ContentSample.activePosition";
|
||||
private static final String STATE_CONTENT_TEXT = "net.simonvt.menudrawer.samples.ContentSample.contentText";
|
||||
|
||||
private MenuDrawer mMenuDrawer;
|
||||
|
||||
private MenuAdapter mAdapter;
|
||||
private ListView mList;
|
||||
|
||||
private int mActivePosition = -1;
|
||||
private String mContentText;
|
||||
private TextView mContentTextView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle inState) {
|
||||
super.onCreate(inState);
|
||||
|
||||
if (inState != null) {
|
||||
mActivePosition = inState.getInt(STATE_ACTIVE_POSITION);
|
||||
mContentText = inState.getString(STATE_CONTENT_TEXT);
|
||||
}
|
||||
|
||||
mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_CONTENT);
|
||||
mMenuDrawer.setContentView(R.layout.activity_contentsample);
|
||||
mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
|
||||
|
||||
List<Object> items = new ArrayList<Object>();
|
||||
items.add(new Item("Item 1", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 2", R.drawable.ic_action_select_all_dark));
|
||||
items.add(new Category("Cat 1"));
|
||||
items.add(new Item("Item 3", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 4", R.drawable.ic_action_select_all_dark));
|
||||
items.add(new Category("Cat 2"));
|
||||
items.add(new Item("Item 5", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 6", R.drawable.ic_action_select_all_dark));
|
||||
items.add(new Category("Cat 3"));
|
||||
items.add(new Item("Item 7", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 8", R.drawable.ic_action_select_all_dark));
|
||||
items.add(new Category("Cat 4"));
|
||||
items.add(new Item("Item 9", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 10", R.drawable.ic_action_select_all_dark));
|
||||
|
||||
mList = new ListView(this);
|
||||
mAdapter = new MenuAdapter(items);
|
||||
mList.setAdapter(mAdapter);
|
||||
mList.setOnItemClickListener(mItemClickListener);
|
||||
|
||||
mMenuDrawer.setMenuView(mList);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
mContentTextView = (TextView) findViewById(R.id.contentText);
|
||||
mContentTextView.setText(mContentText);
|
||||
|
||||
mMenuDrawer.setOnInterceptMoveEventListener(new MenuDrawer.OnInterceptMoveEventListener() {
|
||||
@Override
|
||||
public boolean isViewDraggable(View v, int dx, int x, int y) {
|
||||
return v instanceof SeekBar;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
mActivePosition = position;
|
||||
mMenuDrawer.setActiveView(view, position);
|
||||
mContentTextView.setText(((TextView) view).getText());
|
||||
mMenuDrawer.closeMenu();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(STATE_ACTIVE_POSITION, mActivePosition);
|
||||
outState.putString(STATE_CONTENT_TEXT, mContentText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
mMenuDrawer.toggleMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
final int drawerState = mMenuDrawer.getDrawerState();
|
||||
if (drawerState == MenuDrawer.STATE_OPEN || drawerState == MenuDrawer.STATE_OPENING) {
|
||||
mMenuDrawer.closeMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
private static class Item {
|
||||
|
||||
String mTitle;
|
||||
int mIconRes;
|
||||
|
||||
Item(String title, int iconRes) {
|
||||
mTitle = title;
|
||||
mIconRes = iconRes;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Category {
|
||||
|
||||
String mTitle;
|
||||
|
||||
Category(String title) {
|
||||
mTitle = title;
|
||||
}
|
||||
}
|
||||
|
||||
private class MenuAdapter extends BaseAdapter {
|
||||
|
||||
private List<Object> mItems;
|
||||
|
||||
MenuAdapter(List<Object> items) {
|
||||
mItems = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mItems.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return getItem(position) instanceof Item ? 0 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return getItem(position) instanceof Item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
Object item = getItem(position);
|
||||
|
||||
if (item instanceof Category) {
|
||||
if (v == null) {
|
||||
v = getLayoutInflater().inflate(R.layout.menu_row_category, parent, false);
|
||||
}
|
||||
|
||||
((TextView) v).setText(((Category) item).mTitle);
|
||||
|
||||
} else {
|
||||
if (v == null) {
|
||||
v = getLayoutInflater().inflate(R.layout.menu_row_item, parent, false);
|
||||
}
|
||||
|
||||
TextView tv = (TextView) v;
|
||||
tv.setText(((Item) item).mTitle);
|
||||
tv.setCompoundDrawablesWithIntrinsicBounds(((Item) item).mIconRes, 0, 0, 0);
|
||||
}
|
||||
|
||||
v.setTag(R.id.mdActiveViewPosition, position);
|
||||
|
||||
if (position == mActivePosition) {
|
||||
mMenuDrawer.setActiveView(v, position);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import net.simonvt.menudrawer.MenuDrawer;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class LayoutSample extends Activity implements View.OnClickListener {
|
||||
|
||||
private MenuDrawer mDrawer;
|
||||
private TextView mContentTextView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_layoutsample);
|
||||
mDrawer = (MenuDrawer) findViewById(R.id.drawer);
|
||||
mDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
|
||||
|
||||
mContentTextView = (TextView) findViewById(R.id.contentText);
|
||||
findViewById(R.id.item1).setOnClickListener(this);
|
||||
findViewById(R.id.item2).setOnClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Click handler for top drawer items.
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String tag = (String) v.getTag();
|
||||
mContentTextView.setText(String.format("%s clicked.", tag));
|
||||
mDrawer.setActiveView(v);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import net.simonvt.menudrawer.MenuDrawer;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.Gravity;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListActivitySample extends ListActivity {
|
||||
|
||||
private static final String STATE_MENUDRAWER = "net.simonvt.menudrawer.samples.ListActivitySample.menuDrawer";
|
||||
|
||||
private MenuDrawer mMenuDrawer;
|
||||
|
||||
private Handler mHandler;
|
||||
private Runnable mToggleUpRunnable;
|
||||
private boolean mDisplayUp = true;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle inState) {
|
||||
super.onCreate(inState);
|
||||
|
||||
mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_CONTENT);
|
||||
|
||||
TextView menuView = new TextView(this);
|
||||
menuView.setGravity(Gravity.CENTER);
|
||||
menuView.setTextColor(0xFFFFFFFF);
|
||||
final int padding = dpToPx(16);
|
||||
menuView.setPadding(padding, padding, padding, padding);
|
||||
menuView.setText(R.string.sample_listactivity);
|
||||
mMenuDrawer.setMenuView(menuView);
|
||||
mMenuDrawer.setOffsetMenuEnabled(false);
|
||||
|
||||
List<String> items = new ArrayList<String>();
|
||||
for (int i = 1; i <= 20; i++) {
|
||||
items.add("Item " + i);
|
||||
}
|
||||
|
||||
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
|
||||
}
|
||||
|
||||
private int dpToPx(int dp) {
|
||||
return (int) (getResources().getDisplayMetrics().density * dp + 0.5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(int layoutResID) {
|
||||
// This override is only needed when using MENU_DRAG_CONTENT.
|
||||
mMenuDrawer.setContentView(layoutResID);
|
||||
onContentChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
String str = (String) getListAdapter().getItem(position);
|
||||
Toast.makeText(this, "Clicked: " + str, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
mMenuDrawer.toggleMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
final int drawerState = mMenuDrawer.getDrawerState();
|
||||
if (drawerState == MenuDrawer.STATE_OPEN || drawerState == MenuDrawer.STATE_OPENING) {
|
||||
mMenuDrawer.closeMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import net.simonvt.menudrawer.MenuDrawer;
|
||||
import net.simonvt.menudrawer.Position;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RightMenuSample extends Activity {
|
||||
|
||||
private static final String STATE_ACTIVE_POSITION = "net.simonvt.menudrawer.samples.RightMenuSample.activePosition";
|
||||
private static final String STATE_CONTENT_TEXT = "net.simonvt.menudrawer.samples.RightMenuSample.contentText";
|
||||
|
||||
private static final int MENU_OVERFLOW = 1;
|
||||
|
||||
private MenuDrawer mMenuDrawer;
|
||||
|
||||
private MenuAdapter mAdapter;
|
||||
private ListView mList;
|
||||
|
||||
private int mActivePosition = -1;
|
||||
private String mContentText;
|
||||
private TextView mContentTextView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle inState) {
|
||||
super.onCreate(inState);
|
||||
|
||||
if (inState != null) {
|
||||
mActivePosition = inState.getInt(STATE_ACTIVE_POSITION);
|
||||
mContentText = inState.getString(STATE_CONTENT_TEXT);
|
||||
}
|
||||
|
||||
mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_CONTENT, Position.RIGHT);
|
||||
mMenuDrawer.setContentView(R.layout.activity_rightmenu);
|
||||
|
||||
List<Object> items = new ArrayList<Object>();
|
||||
items.add(new Item("Item 1", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 2", R.drawable.ic_action_select_all_dark));
|
||||
items.add(new Category("Cat 1"));
|
||||
items.add(new Item("Item 3", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 4", R.drawable.ic_action_select_all_dark));
|
||||
items.add(new Category("Cat 2"));
|
||||
items.add(new Item("Item 5", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 6", R.drawable.ic_action_select_all_dark));
|
||||
|
||||
// A custom ListView is needed so the drawer can be notified when it's scrolled. This is to update the position
|
||||
// of the arrow indicator.
|
||||
mList = new ListView(this);
|
||||
mAdapter = new MenuAdapter(items);
|
||||
mList.setAdapter(mAdapter);
|
||||
mList.setOnItemClickListener(mItemClickListener);
|
||||
|
||||
mMenuDrawer.setMenuView(mList);
|
||||
|
||||
mContentTextView = (TextView) findViewById(R.id.contentText);
|
||||
mContentTextView.setText(mContentText);
|
||||
}
|
||||
|
||||
private AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
mActivePosition = position;
|
||||
mMenuDrawer.setActiveView(view, position);
|
||||
mContentTextView.setText(((TextView) view).getText());
|
||||
mMenuDrawer.closeMenu();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(STATE_ACTIVE_POSITION, mActivePosition);
|
||||
outState.putString(STATE_CONTENT_TEXT, mContentText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuItem overflowItem = menu.add(0, MENU_OVERFLOW, 0, null);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
overflowItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
}
|
||||
overflowItem.setIcon(R.drawable.ic_menu_moreoverflow_normal_holo_light);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case MENU_OVERFLOW:
|
||||
mMenuDrawer.toggleMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
final int drawerState = mMenuDrawer.getDrawerState();
|
||||
if (drawerState == MenuDrawer.STATE_OPEN || drawerState == MenuDrawer.STATE_OPENING) {
|
||||
mMenuDrawer.closeMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
private static class Item {
|
||||
|
||||
String mTitle;
|
||||
int mIconRes;
|
||||
|
||||
Item(String title, int iconRes) {
|
||||
mTitle = title;
|
||||
mIconRes = iconRes;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Category {
|
||||
|
||||
String mTitle;
|
||||
|
||||
Category(String title) {
|
||||
mTitle = title;
|
||||
}
|
||||
}
|
||||
|
||||
private class MenuAdapter extends BaseAdapter {
|
||||
|
||||
private List<Object> mItems;
|
||||
|
||||
MenuAdapter(List<Object> items) {
|
||||
mItems = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mItems.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return getItem(position) instanceof Item ? 0 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return getItem(position) instanceof Item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
Object item = getItem(position);
|
||||
|
||||
if (item instanceof Category) {
|
||||
if (v == null) {
|
||||
v = getLayoutInflater().inflate(R.layout.menu_row_category, parent, false);
|
||||
}
|
||||
|
||||
((TextView) v).setText(((Category) item).mTitle);
|
||||
|
||||
} else {
|
||||
if (v == null) {
|
||||
v = getLayoutInflater().inflate(R.layout.menu_row_item, parent, false);
|
||||
}
|
||||
|
||||
TextView tv = (TextView) v;
|
||||
tv.setText(((Item) item).mTitle);
|
||||
tv.setCompoundDrawablesWithIntrinsicBounds(((Item) item).mIconRes, 0, 0, 0);
|
||||
}
|
||||
|
||||
v.setTag(R.id.mdActiveViewPosition, position);
|
||||
|
||||
if (position == mActivePosition) {
|
||||
mMenuDrawer.setActiveView(v, position);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SamplesActivity extends ListActivity {
|
||||
|
||||
private SamplesAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mAdapter = new SamplesAdapter();
|
||||
|
||||
mAdapter.addSample("Content sample", "Only the content area is dragged.", ContentSample.class);
|
||||
mAdapter.addSample("ListActivity sample", "Shows how to use the drawer with a ListActivity.",
|
||||
ListActivitySample.class);
|
||||
mAdapter.addSample("Window sample", "The entire window is dragged.", WindowSample.class);
|
||||
mAdapter.addSample("ActionBar overlay sample", "A window sample, where the ActionBar is an overlay",
|
||||
ActionBarOverlaySample.class);
|
||||
mAdapter.addSample("Right menu", "The menu is positioned to the right of the content", RightMenuSample.class);
|
||||
mAdapter.addSample("Top menu", "The menu is positioned above the content", TopMenuSample.class);
|
||||
mAdapter.addSample("Bottom menu", "The menu is positioned below the content", BottomMenuSample.class);
|
||||
mAdapter.addSample("Touch Mode", "The menu touch behavior change according to different"
|
||||
+ " content view state (Ex: View Pager)", ViewPagerSample.class);
|
||||
mAdapter.addSample("Layout xml", "The drawer and its menu and content is defined in XML", LayoutSample.class);
|
||||
mAdapter.addSample("Static drawer", "The drawer is always visible", StaticDrawerSample.class);
|
||||
|
||||
setListAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
SampleItem sample = (SampleItem) mAdapter.getItem(position);
|
||||
Intent i = new Intent(this, sample.mClazz);
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
private static class SampleItem {
|
||||
|
||||
String mTitle;
|
||||
String mSummary;
|
||||
Class mClazz;
|
||||
|
||||
public SampleItem(String title, String summary, Class clazz) {
|
||||
mTitle = title;
|
||||
mSummary = summary;
|
||||
mClazz = clazz;
|
||||
}
|
||||
}
|
||||
|
||||
public class SamplesAdapter extends BaseAdapter {
|
||||
|
||||
private List<SampleItem> mSamples = new ArrayList<SampleItem>();
|
||||
|
||||
public void addSample(String title, String summary, Class clazz) {
|
||||
mSamples.add(new SampleItem(title, summary, clazz));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mSamples.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mSamples.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
SampleItem sample = (SampleItem) getItem(position);
|
||||
|
||||
View v = convertView;
|
||||
if (v == null) {
|
||||
v = getLayoutInflater().inflate(R.layout.list_row_sample, parent, false);
|
||||
}
|
||||
|
||||
((TextView) v.findViewById(R.id.title)).setText(sample.mTitle);
|
||||
((TextView) v.findViewById(R.id.summary)).setText(sample.mSummary);
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import net.simonvt.menudrawer.MenuDrawer;
|
||||
import net.simonvt.menudrawer.Position;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StaticDrawerSample extends Activity {
|
||||
|
||||
private static final String STATE_ACTIVE_POSITION = "net.simonvt.menudrawer.samples.ContentSample.activePosition";
|
||||
private static final String STATE_CONTENT_TEXT = "net.simonvt.menudrawer.samples.ContentSample.contentText";
|
||||
|
||||
private MenuDrawer mMenuDrawer;
|
||||
|
||||
private MenuAdapter mAdapter;
|
||||
private ListView mList;
|
||||
|
||||
private int mActivePosition = -1;
|
||||
private String mContentText;
|
||||
private TextView mContentTextView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle inState) {
|
||||
super.onCreate(inState);
|
||||
|
||||
if (inState != null) {
|
||||
mActivePosition = inState.getInt(STATE_ACTIVE_POSITION);
|
||||
mContentText = inState.getString(STATE_CONTENT_TEXT);
|
||||
}
|
||||
|
||||
mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_CONTENT, Position.LEFT, true);
|
||||
mMenuDrawer.setContentView(R.layout.activity_contentsample);
|
||||
|
||||
List<Object> items = new ArrayList<Object>();
|
||||
items.add(new Item("Item 1", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 2", R.drawable.ic_action_select_all_dark));
|
||||
items.add(new Category("Cat 1"));
|
||||
items.add(new Item("Item 3", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 4", R.drawable.ic_action_select_all_dark));
|
||||
items.add(new Category("Cat 2"));
|
||||
items.add(new Item("Item 5", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 6", R.drawable.ic_action_select_all_dark));
|
||||
|
||||
mList = new ListView(this);
|
||||
mAdapter = new MenuAdapter(items);
|
||||
mList.setAdapter(mAdapter);
|
||||
mList.setOnItemClickListener(mItemClickListener);
|
||||
|
||||
mMenuDrawer.setMenuView(mList);
|
||||
|
||||
mContentTextView = (TextView) findViewById(R.id.contentText);
|
||||
mContentTextView.setText(mContentText);
|
||||
}
|
||||
|
||||
private AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
mActivePosition = position;
|
||||
mMenuDrawer.setActiveView(view, position);
|
||||
mContentTextView.setText(((TextView) view).getText());
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(STATE_ACTIVE_POSITION, mActivePosition);
|
||||
outState.putString(STATE_CONTENT_TEXT, mContentText);
|
||||
}
|
||||
|
||||
private static class Item {
|
||||
|
||||
String mTitle;
|
||||
int mIconRes;
|
||||
|
||||
Item(String title, int iconRes) {
|
||||
mTitle = title;
|
||||
mIconRes = iconRes;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Category {
|
||||
|
||||
String mTitle;
|
||||
|
||||
Category(String title) {
|
||||
mTitle = title;
|
||||
}
|
||||
}
|
||||
|
||||
private class MenuAdapter extends BaseAdapter {
|
||||
|
||||
private List<Object> mItems;
|
||||
|
||||
MenuAdapter(List<Object> items) {
|
||||
mItems = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mItems.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return getItem(position) instanceof Item ? 0 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return getItem(position) instanceof Item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
Object item = getItem(position);
|
||||
|
||||
if (item instanceof Category) {
|
||||
if (v == null) {
|
||||
v = getLayoutInflater().inflate(R.layout.menu_row_category, parent, false);
|
||||
}
|
||||
|
||||
((TextView) v).setText(((Category) item).mTitle);
|
||||
|
||||
} else {
|
||||
if (v == null) {
|
||||
v = getLayoutInflater().inflate(R.layout.menu_row_item, parent, false);
|
||||
}
|
||||
|
||||
TextView tv = (TextView) v;
|
||||
tv.setText(((Item) item).mTitle);
|
||||
tv.setCompoundDrawablesWithIntrinsicBounds(((Item) item).mIconRes, 0, 0, 0);
|
||||
}
|
||||
|
||||
v.setTag(R.id.mdActiveViewPosition, position);
|
||||
|
||||
if (position == mActivePosition) {
|
||||
mMenuDrawer.setActiveView(v, position);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import net.simonvt.menudrawer.MenuDrawer;
|
||||
import net.simonvt.menudrawer.Position;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Sample class illustrating how to add a menu drawer above the content area.
|
||||
*/
|
||||
public class TopMenuSample extends Activity implements OnClickListener {
|
||||
|
||||
private static final int MENU_OVERFLOW = 1;
|
||||
|
||||
private MenuDrawer mMenuDrawer;
|
||||
private TextView mContentTextView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle inState) {
|
||||
super.onCreate(inState);
|
||||
|
||||
mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_CONTENT, Position.TOP);
|
||||
mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
|
||||
mMenuDrawer.setContentView(R.layout.activity_topmenu);
|
||||
mMenuDrawer.setMenuView(R.layout.menu_top);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
mContentTextView = (TextView) findViewById(R.id.contentText);
|
||||
findViewById(R.id.item1).setOnClickListener(this);
|
||||
findViewById(R.id.item2).setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuItem overflowItem = menu.add(0, MENU_OVERFLOW, 0, null);
|
||||
MenuItemCompat.setShowAsAction(overflowItem, MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
|
||||
overflowItem.setIcon(R.drawable.ic_menu_moreoverflow_normal_holo_light);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
NavUtils.navigateUpFromSameTask(this);
|
||||
return true;
|
||||
case MENU_OVERFLOW:
|
||||
mMenuDrawer.toggleMenu();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Click handler for top drawer items.
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String tag = (String) v.getTag();
|
||||
mContentTextView.setText(String.format("%s clicked.", tag));
|
||||
mMenuDrawer.setActiveView(v);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import net.simonvt.menudrawer.MenuDrawer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ViewPagerSample extends FragmentActivity {
|
||||
|
||||
private static final String STATE_ACTIVE_POSITION = "net.simonvt.menudrawer.samples.ContentSample.activePosition";
|
||||
|
||||
private MenuDrawer mMenuDrawer;
|
||||
|
||||
private MenuAdapter mAdapter;
|
||||
private ListView mList;
|
||||
|
||||
private int mActivePosition = -1;
|
||||
private PagerAdapter mPagerAdapter;
|
||||
private ViewPager mViewPager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle inState) {
|
||||
super.onCreate(inState);
|
||||
|
||||
if (inState != null) {
|
||||
mActivePosition = inState.getInt(STATE_ACTIVE_POSITION);
|
||||
}
|
||||
|
||||
mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_CONTENT);
|
||||
mMenuDrawer.setContentView(R.layout.activity_viewpagersample);
|
||||
|
||||
List<Object> items = new ArrayList<Object>();
|
||||
items.add(new Item("Item 1", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 2", R.drawable.ic_action_select_all_dark));
|
||||
items.add(new Category("Cat 1"));
|
||||
items.add(new Item("Item 3", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 4", R.drawable.ic_action_select_all_dark));
|
||||
items.add(new Category("Cat 2"));
|
||||
items.add(new Item("Item 5", R.drawable.ic_action_refresh_dark));
|
||||
items.add(new Item("Item 6", R.drawable.ic_action_select_all_dark));
|
||||
|
||||
// A custom ListView is needed so the drawer can be notified when it's
|
||||
// scrolled. This is to update the position
|
||||
// of the arrow indicator.
|
||||
mList = new ListView(this);
|
||||
mAdapter = new MenuAdapter(items);
|
||||
mList.setAdapter(mAdapter);
|
||||
mList.setOnItemClickListener(mItemClickListener);
|
||||
|
||||
mMenuDrawer.setMenuView(mList);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
|
||||
|
||||
mViewPager = (ViewPager) findViewById(R.id.view_pager);
|
||||
mViewPager
|
||||
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(final int position) {
|
||||
mMenuDrawer.setTouchMode(position == 0
|
||||
? MenuDrawer.TOUCH_MODE_FULLSCREEN
|
||||
: MenuDrawer.TOUCH_MODE_NONE);
|
||||
}
|
||||
});
|
||||
|
||||
mPagerAdapter = new PagerAdapter(this);
|
||||
mPagerAdapter.addTab(TextViewFragment.class, null);
|
||||
mPagerAdapter.addTab(TextViewFragment.class, null);
|
||||
mPagerAdapter.addTab(TextViewFragment.class, null);
|
||||
|
||||
mViewPager.setAdapter(mPagerAdapter);
|
||||
}
|
||||
|
||||
private AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
mActivePosition = position;
|
||||
mMenuDrawer.setActiveView(view, position);
|
||||
mMenuDrawer.closeMenu();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(STATE_ACTIVE_POSITION, mActivePosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
mMenuDrawer.toggleMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
final int drawerState = mMenuDrawer.getDrawerState();
|
||||
if (drawerState == MenuDrawer.STATE_OPEN
|
||||
|| drawerState == MenuDrawer.STATE_OPENING) {
|
||||
mMenuDrawer.closeMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
private static final class Item {
|
||||
|
||||
String mTitle;
|
||||
int mIconRes;
|
||||
|
||||
Item(String title, int iconRes) {
|
||||
mTitle = title;
|
||||
mIconRes = iconRes;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class Category {
|
||||
|
||||
String mTitle;
|
||||
|
||||
Category(String title) {
|
||||
mTitle = title;
|
||||
}
|
||||
}
|
||||
|
||||
private class MenuAdapter extends BaseAdapter {
|
||||
|
||||
private List<Object> mItems;
|
||||
|
||||
MenuAdapter(List<Object> items) {
|
||||
mItems = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mItems.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return getItem(position) instanceof Item ? 0 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return getItem(position) instanceof Item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
Object item = getItem(position);
|
||||
|
||||
if (item instanceof Category) {
|
||||
if (v == null) {
|
||||
v = getLayoutInflater().inflate(R.layout.menu_row_category,
|
||||
parent, false);
|
||||
}
|
||||
|
||||
((TextView) v).setText(((Category) item).mTitle);
|
||||
|
||||
} else {
|
||||
if (v == null) {
|
||||
v = getLayoutInflater().inflate(R.layout.menu_row_item,
|
||||
parent, false);
|
||||
}
|
||||
|
||||
TextView tv = (TextView) v;
|
||||
tv.setText(((Item) item).mTitle);
|
||||
tv.setCompoundDrawablesWithIntrinsicBounds(
|
||||
((Item) item).mIconRes, 0, 0, 0);
|
||||
}
|
||||
|
||||
v.setTag(R.id.mdActiveViewPosition, position);
|
||||
|
||||
if (position == mActivePosition) {
|
||||
mMenuDrawer.setActiveView(v, position);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a helper class that implements the management of tabs and all
|
||||
* details of connecting a ViewPager with associated TabHost. It relies on a
|
||||
* trick. Normally a tab host has a simple API for supplying a View or
|
||||
* Intent that each tab will show. This is not sufficient for switching
|
||||
* between pages. So instead we make the content part of the tab host 0dp
|
||||
* high (it is not shown) and the TabsAdapter supplies its own dummy view to
|
||||
* show as the tab content. It listens to changes in tabs, and takes care of
|
||||
* switch to the correct paged in the ViewPager whenever the selected tab
|
||||
* changes.
|
||||
*/
|
||||
public static class PagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private final Context mContext;
|
||||
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
|
||||
|
||||
static final class TabInfo {
|
||||
|
||||
private final Class<?> mClss;
|
||||
private final Bundle mArgs;
|
||||
|
||||
TabInfo(Class<?> aClass, Bundle args) {
|
||||
mClss = aClass;
|
||||
mArgs = args;
|
||||
}
|
||||
}
|
||||
|
||||
public PagerAdapter(FragmentActivity activity) {
|
||||
super(activity.getSupportFragmentManager());
|
||||
mContext = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mTabs.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
TabInfo info = mTabs.get(position);
|
||||
return Fragment.instantiate(mContext, info.mClss.getName(),
|
||||
info.mArgs);
|
||||
}
|
||||
|
||||
public void addTab(Class<?> clss, Bundle args) {
|
||||
TabInfo info = new TabInfo(clss, args);
|
||||
mTabs.add(info);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class TextViewFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
FrameLayout frameLayout = new FrameLayout(getActivity());
|
||||
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT, Gravity.CENTER));
|
||||
|
||||
TextView tv = new TextView(getActivity());
|
||||
tv.setText("This is an example of a Fragment in a View Pager");
|
||||
frameLayout.addView(tv);
|
||||
return frameLayout;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package net.simonvt.menudrawer.samples;
|
||||
|
||||
import net.simonvt.menudrawer.MenuDrawer;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class WindowSample extends Activity implements View.OnClickListener {
|
||||
|
||||
private static final String STATE_MENUDRAWER = "net.simonvt.menudrawer.samples.WindowSample.menuDrawer";
|
||||
private static final String STATE_ACTIVE_VIEW_ID = "net.simonvt.menudrawer.samples.WindowSample.activeViewId";
|
||||
|
||||
private MenuDrawer mMenuDrawer;
|
||||
private TextView mContentTextView;
|
||||
|
||||
private int mActiveViewId;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle inState) {
|
||||
super.onCreate(inState);
|
||||
if (inState != null) {
|
||||
mActiveViewId = inState.getInt(STATE_ACTIVE_VIEW_ID);
|
||||
}
|
||||
|
||||
mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_WINDOW);
|
||||
mMenuDrawer.setContentView(R.layout.activity_windowsample);
|
||||
mMenuDrawer.setMenuView(R.layout.menu_scrollview);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
mContentTextView = (TextView) findViewById(R.id.contentText);
|
||||
|
||||
findViewById(R.id.item1).setOnClickListener(this);
|
||||
findViewById(R.id.item2).setOnClickListener(this);
|
||||
findViewById(R.id.item3).setOnClickListener(this);
|
||||
findViewById(R.id.item4).setOnClickListener(this);
|
||||
findViewById(R.id.item5).setOnClickListener(this);
|
||||
findViewById(R.id.item6).setOnClickListener(this);
|
||||
|
||||
TextView activeView = (TextView) findViewById(mActiveViewId);
|
||||
if (activeView != null) {
|
||||
mMenuDrawer.setActiveView(activeView);
|
||||
mContentTextView.setText("Active item: " + activeView.getText());
|
||||
}
|
||||
|
||||
// This will animate the drawer open and closed until the user manually drags it. Usually this would only be
|
||||
// called on first launch.
|
||||
mMenuDrawer.peekDrawer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle inState) {
|
||||
super.onRestoreInstanceState(inState);
|
||||
mMenuDrawer.restoreState(inState.getParcelable(STATE_MENUDRAWER));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(STATE_MENUDRAWER, mMenuDrawer.saveState());
|
||||
outState.putInt(STATE_ACTIVE_VIEW_ID, mActiveViewId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
mMenuDrawer.toggleMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
final int drawerState = mMenuDrawer.getDrawerState();
|
||||
if (drawerState == MenuDrawer.STATE_OPEN || drawerState == MenuDrawer.STATE_OPENING) {
|
||||
mMenuDrawer.closeMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mMenuDrawer.setActiveView(v);
|
||||
mContentTextView.setText("Active item: " + ((TextView) v).getText());
|
||||
mMenuDrawer.closeMenu();
|
||||
mActiveViewId = v.getId();
|
||||
}
|
||||
}
|
||||