[Android] UI: introduce ExpandableLayout

Sébastien Toque git at videolan.org
Tue Apr 2 20:54:08 CEST 2013


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Tue Apr  2 20:15:48 2013 +0200| [0a6b5ac8ca02284feb6643cb0b98f8a2781e58e9] | committer: Sébastien Toque

UI: introduce ExpandableLayout

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=0a6b5ac8ca02284feb6643cb0b98f8a2781e58e9
---

 vlc-android/res/layout/expandable_layout.xml       |   58 ++++++++++++
 .../org/videolan/vlc/widget/ExpandableLayout.java  |   99 ++++++++++++++++++++
 2 files changed, 157 insertions(+)

diff --git a/vlc-android/res/layout/expandable_layout.xml b/vlc-android/res/layout/expandable_layout.xml
new file mode 100644
index 0000000..9aae2ab
--- /dev/null
+++ b/vlc-android/res/layout/expandable_layout.xml
@@ -0,0 +1,58 @@
+<?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:layout_margin="5dp"
+    android:orientation="vertical" >
+
+    <LinearLayout
+        android:id="@+id/header_layout"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal" >
+
+        <ImageView
+            android:id="@+id/icon"
+            android:layout_width="40dp"
+            android:layout_height="40dp"
+            android:visibility="gone" />
+
+        <LinearLayout
+            android:layout_width="0dip"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical"
+            android:layout_weight="1"
+            android:orientation="vertical" >
+
+            <TextView
+                android:id="@+id/title"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/title"
+                android:textAppearance="?android:attr/textAppearanceMedium" />
+
+            <TextView
+                android:id="@+id/text"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/title"
+                android:textAppearance="?android:attr/textAppearanceSmall"
+                android:visibility="gone" />
+        </LinearLayout>
+
+        <ImageView
+            android:id="@+id/more"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical|right"
+            android:layout_marginRight="15dip"
+            android:src="@drawable/ic_down" />
+    </LinearLayout>
+
+    <LinearLayout
+        android:id="@+id/content"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center_horizontal" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/widget/ExpandableLayout.java b/vlc-android/src/org/videolan/vlc/widget/ExpandableLayout.java
new file mode 100644
index 0000000..d2d5c3c
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/widget/ExpandableLayout.java
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * ExpandableLayout.java
+ *****************************************************************************
+ * Copyright © 2013 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+package org.videolan.vlc.widget;
+
+import org.videolan.vlc.R;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class ExpandableLayout extends LinearLayout {
+
+    private final View mHeaderLayout;
+    private final ImageView mIcon;
+    private final TextView mTitle;
+    private final TextView mText;
+    private final ImageView mMore;
+    private final LinearLayout mContent;
+    private Boolean mExpanded;
+
+    public ExpandableLayout(Context context, AttributeSet attrs) {
+        super(context, attrs);
+
+        LayoutInflater.from(context).inflate(R.layout.expandable_layout, this, true);
+
+        mHeaderLayout = findViewById(R.id.header_layout);
+        mIcon = (ImageView) findViewById(R.id.icon);
+        mTitle = (TextView) findViewById(R.id.title);
+        mText = (TextView) findViewById(R.id.text);
+        mMore = (ImageView) findViewById(R.id.more);
+        mContent = (LinearLayout) findViewById(R.id.content);
+
+        mHeaderLayout.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                SetState(!mExpanded);
+            }
+        });
+
+        SetState(isInEditMode());
+    }
+
+    private void SetState(Boolean expanded) {
+        mExpanded = expanded;
+        mMore.setImageResource(expanded ? R.drawable.ic_up : R.drawable.ic_down);
+        mContent.setVisibility(expanded ? View.VISIBLE : View.GONE);
+    }
+
+    public void setTitle(int resid) {
+        mTitle.setText(resid);
+    }
+
+    public void setText(String text) {
+        mText.setText(text);
+        mText.setVisibility(text != null ? View.VISIBLE : View.GONE);
+    }
+
+    public void setIcon(int resid) {
+        mIcon.setImageResource(resid);
+        mIcon.setVisibility(View.VISIBLE);
+    }
+
+    public void setContent(Context context, int resid) {
+        View view = LayoutInflater.from(context).inflate(resid, null, true);
+        mContent.addView(view);
+    }
+
+    public void Expand()
+    {
+        SetState(true);
+    }
+
+    public void Collapse()
+    {
+        SetState(false);
+    }
+}



More information about the Android mailing list