aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGriffin Millender <griffinn.millender@gmail.com>2016-10-17 21:47:25 -0500
committerGriffin Millender <griffinn.millender@gmail.com>2016-10-20 14:01:43 -0500
commit0c1327e6f27c67d8916ef96317f3fe502a91a8c3 (patch)
treefc41225bb9c4caa53b777fce53e5c89050f365bc
parent0127e9ab2e14c29de7234bb736c0aee33cf9caf3 (diff)
Add new options menu
Change-Id: I566f3391c832dc0a0b5584838a53c9ec6f6746c9
-rw-r--r--Android.mk3
-rw-r--r--res/layout/card_layout.xml32
-rw-r--r--res/layout/card_main.xml46
-rw-r--r--res/layout/card_options.xml13
-rw-r--r--src/com/android/cards/internal/Card.java4
-rw-r--r--src/com/android/cards/internal/base/BaseCard.java16
-rw-r--r--src/com/android/cards/view/CardView.java97
-rw-r--r--src/com/android/cards/view/CardViewNative.java10
-rw-r--r--src/com/android/cards/view/base/CardViewWrapper.java6
9 files changed, 203 insertions, 24 deletions
diff --git a/Android.mk b/Android.mk
index 4df58fa..b2238d2 100644
--- a/Android.mk
+++ b/Android.mk
@@ -17,7 +17,8 @@ include $(CLEAR_VARS)
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-v4 \
- android-support-v7-cardview
+ android-support-v7-cardview \
+ org.slim.framework
LOCAL_JAVA_LIBRARIES := \
android-support-v7-recyclerview
diff --git a/res/layout/card_layout.xml b/res/layout/card_layout.xml
index e0a128f..a67e459 100644
--- a/res/layout/card_layout.xml
+++ b/res/layout/card_layout.xml
@@ -25,32 +25,18 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
- <!-- Card visible layout -->
- <LinearLayout
- android:id="@+id/card_main_layout"
- style="@style/card.main_layout"
- android:orientation="vertical"
+ <FrameLayout
+ android:id="@+id/card_reveal_layout"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- >
+ android:layout_height="match_parent">
- <!-- Compound view for Header Card
- If you want to customize this element use attr card:card_header_layout_resourceID
- You can also use your CardHeader subclass-->
- <com.android.cards.view.component.CardHeaderView
- style="@style/card.header_outer_layout"
- android:id="@+id/card_header_layout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
+ <include layout="@layout/card_main"
+ android:id="@+id/card_main" />
- <!-- Main Content View -->
- <FrameLayout
- android:id="@+id/card_main_content_layout"
- style="@style/card.content_outer_layout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
+ <include layout="@layout/card_options"
+ android:id="@+id/card_options" />
- </LinearLayout>
+ </FrameLayout>
<!-- Compound view for Shadow
If you want to customize this element use attr card:card_shadow_layout_resourceID -->
@@ -72,4 +58,4 @@
</FrameLayout>
-</LinearLayout> \ No newline at end of file
+</LinearLayout>
diff --git a/res/layout/card_main.xml b/res/layout/card_main.xml
new file mode 100644
index 0000000..effcbc8
--- /dev/null
+++ b/res/layout/card_main.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ *******************************************************************************
+ ~ Copyright (c) 2013-2014 Gabriele Mariotti.
+ ~
+ ~ 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.
+ ~ *****************************************************************************
+ -->
+<!-- Card visible layout -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:card="http://schemas.android.com/apk/res-auto"
+ android:id="@+id/card_main_layout"
+ style="@style/card.main_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ >
+
+ <!-- Compound view for Header Card
+ If you want to customize this element use attr card:card_header_layout_resourceID
+ You can also use your CardHeader subclass-->
+ <com.android.cards.view.component.CardHeaderView
+ style="@style/card.header_outer_layout"
+ android:id="@+id/card_header_layout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <!-- Main Content View -->
+ <FrameLayout
+ android:id="@+id/card_main_content_layout"
+ style="@style/card.content_outer_layout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+</LinearLayout>
diff --git a/res/layout/card_options.xml b/res/layout/card_options.xml
new file mode 100644
index 0000000..fd9829d
--- /dev/null
+++ b/res/layout/card_options.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:card="http://schemas.android.com/apk/res-auto"
+ android:id="@+id/card_main_layout"
+ style="@style/card.main_layout"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#00000000"
+ >
+
+</LinearLayout>
diff --git a/src/com/android/cards/internal/Card.java b/src/com/android/cards/internal/Card.java
index 9830593..b9ca66d 100644
--- a/src/com/android/cards/internal/Card.java
+++ b/src/com/android/cards/internal/Card.java
@@ -29,6 +29,7 @@ import java.util.HashMap;
import com.android.cards.R;
import com.android.cards.internal.base.BaseCard;
+import com.android.cards.view.CardView;
/**
* Main Card Model
@@ -1212,4 +1213,7 @@ public class Card extends BaseCard {
public int getBackgroundColorResourceId() {
return mBackgroundColorResourceId;
}
+
+ public void setupOptionsItems(CardView cv) {
+ }
}
diff --git a/src/com/android/cards/internal/base/BaseCard.java b/src/com/android/cards/internal/base/BaseCard.java
index 98eb26d..68ec170 100644
--- a/src/com/android/cards/internal/base/BaseCard.java
+++ b/src/com/android/cards/internal/base/BaseCard.java
@@ -228,4 +228,20 @@ public abstract class BaseCard implements CardUIInferface {
public void setType(int type) {
this.type = type;
}
+
+ public void showOptions(int x, int y) {
+ if (mCardView != null) {
+ mCardView.showOptions(x, y);
+ }
+ }
+
+ public void hideOptions(int x, int y) {
+ if (mCardView != null) {
+ mCardView.hideOptions(x, y);
+ }
+ }
+
+ public boolean isOptionsVisible() {
+ return mCardView.isOptionsVisible();
+ }
}
diff --git a/src/com/android/cards/view/CardView.java b/src/com/android/cards/view/CardView.java
index 6150480..5f39735 100644
--- a/src/com/android/cards/view/CardView.java
+++ b/src/com/android/cards/view/CardView.java
@@ -29,12 +29,18 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Build;
+import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
+import android.view.MotionEvent;
import android.view.View;
+import android.view.ViewAnimationUtils;
+import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewTreeObserver;
+import android.view.animation.PathInterpolator;
+import android.widget.FrameLayout;
import java.util.HashMap;
@@ -154,6 +160,8 @@ public class CardView extends BaseCardView implements CardViewWrapper {
*/
protected View mInternalExpandInnerView;
+ private FrameLayout mRevealLayout;
+
/** Animator to expand/collapse */
protected Animator mExpandAnimator;
@@ -164,6 +172,9 @@ public class CardView extends BaseCardView implements CardViewWrapper {
*/
protected OnExpandListAnimatorListener mOnExpandListAnimatorListener;
+ private boolean mOptionsShown = false;
+ private int mUpX, mUpY;
+
//--------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------
@@ -310,6 +321,8 @@ public class CardView extends BaseCardView implements CardViewWrapper {
super.retrieveLayoutIDs();
+ mRevealLayout = (FrameLayout) findViewById(R.id.card_reveal_layout);
+
//Main Layout
mInternalMainCardLayout = (View) findViewById(R.id.card_main_layout);
@@ -326,6 +339,65 @@ public class CardView extends BaseCardView implements CardViewWrapper {
mInternalThumbnailLayout = (CardThumbnailView) findViewById(R.id.card_thumbnail_layout);
}
+ public void showOptions(int x, int y) {
+ mCard.setupOptionsItems(this);
+
+ final View options = findViewById(R.id.card_options);
+
+ if (x == -1 || y == -1) {
+ options.setVisibility(View.VISIBLE);
+ return;
+ }
+
+ final double horz = Math.max(getWidth() - x, x);
+ final double vert = Math.max(getHeight() - y, y);
+ final float r = (float) Math.hypot(horz, vert);
+
+ final Animator a = ViewAnimationUtils.createCircularReveal(options, x, y, 0, r);
+ a.setDuration(700);
+ a.setInterpolator(new PathInterpolator(0f, 0f, 0.2f, 1f));
+ a.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ mOptionsShown = true;
+ }
+ });
+ options.setVisibility(View.VISIBLE);
+ a.start();
+ }
+
+ public void hideOptions(int x, int y) {
+
+ final View options = findViewById(R.id.card_options);
+
+ if (x == -1 || y == -1) {
+ options.setVisibility(View.GONE);
+ return;
+ }
+
+ final double horz = Math.max(getWidth() - x, x);
+ final double vert = Math.max(getHeight() - y, y);
+ final float r = (float) Math.hypot(horz, vert);
+
+ final Animator a = ViewAnimationUtils.createCircularReveal(options, x, y, r, 0);
+ a.setDuration(700);
+ a.setInterpolator(new PathInterpolator(0f, 0f, 0.2f, 1f));
+ a.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ mOptionsShown = false;
+ options.setVisibility(View.GONE);
+ }
+ });
+ a.start();
+ }
+
+ public boolean isOptionsVisible() {
+ return mOptionsShown;
+ }
+
/**
* Setup Header View
*/
@@ -565,6 +637,31 @@ public class CardView extends BaseCardView implements CardViewWrapper {
} else {
this.setLongClickable(false);
}
+
+ mRevealLayout.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ mUpX = (int) event.getRawX();
+ mUpY = (int) event.getRawY();
+ return false;
+ }
+ });
+ mRevealLayout.setOnLongClickListener(new View.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ int[] temp = new int[2];
+ getLocationOnScreen(temp);
+ int x = mUpX - temp[0];
+ int y = mUpY - temp[1];
+ if (isOptionsVisible()) {
+ hideOptions(x, y);
+ } else {
+ showOptions(x, y);
+ }
+ return true;
+ }
+ });
+ addGlobalClickListener(mRevealLayout);
}
private void addGlobalClickListener(View view) {
diff --git a/src/com/android/cards/view/CardViewNative.java b/src/com/android/cards/view/CardViewNative.java
index e8062b8..2f07e17 100644
--- a/src/com/android/cards/view/CardViewNative.java
+++ b/src/com/android/cards/view/CardViewNative.java
@@ -331,6 +331,16 @@ public class CardViewNative extends android.support.v7.widget.CardView implement
buildUI();
}
+ public void showOptions(int x, int y) {
+ }
+
+ public void hideOptions(int x, int y) {
+ }
+
+ public boolean isOptionsVisible() {
+ return false;
+ }
+
/**
* Refreshes the card content (it doesn't inflate layouts again)
*
diff --git a/src/com/android/cards/view/base/CardViewWrapper.java b/src/com/android/cards/view/base/CardViewWrapper.java
index 6c2687c..d632fda 100644
--- a/src/com/android/cards/view/base/CardViewWrapper.java
+++ b/src/com/android/cards/view/base/CardViewWrapper.java
@@ -175,4 +175,10 @@ public interface CardViewWrapper {
public ViewParent getCardParent();
public View getCardView();
+
+ public void showOptions(int x, int y);
+
+ public void hideOptions(int x, int y);
+
+ public boolean isOptionsVisible();
}