Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reveal Color View Demo
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="3">
<at.markushi.ui.RevealColorView
android:id="@+id/reveal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#212121"/>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="64dip"
android:fontFamily="sans-serif-light"
android:paddingBottom="16dip"
android:paddingLeft="72dip"
android:text="Reveal Color Demo"
android:textColor="#DDFFFFFF"
android:textSize="36sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dip"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:layout_marginBottom="8dip"
android:paddingLeft="72dip"
android:paddingRight="16dip">
<Button
android:id="@+id/btn_1"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selectable_item_selector"
android:tag="#8bc34a"
android:layout_marginRight="8dip"
android:text="1"
android:textColor="@android:color/white"/>
<Button
android:id="@+id/btn_2"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selectable_item_selector"
android:tag="#3f51b5"
android:layout_marginRight="8dip"
android:text="2"
android:textColor="@android:color/white"/>
<Button
android:id="@+id/btn_3"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selectable_item_selector"
android:tag="#00bcd4"
android:text="3"
android:layout_marginRight="8dip"
android:textColor="@android:color/white"/>
<Button
android:id="@+id/btn_4"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selectable_item_selector"
android:tag="#e91e63"
android:text="4"
android:textColor="@android:color/white"/>
</LinearLayout>
</FrameLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="3"
android:paddingLeft="72dip"
android:text="A simple demo on how to use reveal color view."
android:paddingTop="16dip"/>
</LinearLayout>
package at.markushi.reveal;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
import android.view.View;
import at.markushi.ui.RevealColorView;
public class MyActivity extends Activity implements View.OnClickListener {
private RevealColorView revealColorView;
private View selectedView;
private int backgroundColor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
revealColorView = (RevealColorView) findViewById(R.id.reveal);
backgroundColor = Color.parseColor("#212121");
findViewById(R.id.btn_1).setOnClickListener(this);
findViewById(R.id.btn_2).setOnClickListener(this);
findViewById(R.id.btn_3).setOnClickListener(this);
findViewById(R.id.btn_4).setOnClickListener(this);
}
@Override
public void onClick(View v) {
final int color = getColor(v);
final Point p = getLocationInView(revealColorView, v);
if (selectedView == v) {
revealColorView.hide(p.x, p.y, backgroundColor, 0, 300, null);
selectedView = null;
} else {
revealColorView.reveal(p.x, p.y, color, v.getHeight() / 2, 340, null);
selectedView = v;
}
}
private Point getLocationInView(View src, View target) {
final int[] l0 = new int[2];
src.getLocationOnScreen(l0);
final int[] l1 = new int[2];
target.getLocationOnScreen(l1);
l1[0] = l1[0] - l0[0] + target.getWidth() / 2;
l1[1] = l1[1] - l0[1] + target.getHeight() / 2;
return new Point(l1[0], l1[1]);
}
private int getColor(View view) {
return Color.parseColor((String) view.getTag());
}
}
@ulohani90

This comment has been minimized.

Copy link

@ulohani90 ulohani90 commented Mar 18, 2015

Hi ,
Can I use a proper layout to animate as the color view reveals up...Seeing at the code . It shows that it is a ViewGroup..

@interfacekun

This comment has been minimized.

Copy link

@interfacekun interfacekun commented Mar 29, 2016

good

@ZLdeSpirit

This comment has been minimized.

Copy link

@ZLdeSpirit ZLdeSpirit commented May 11, 2016

好的

@XiongKe94

This comment has been minimized.

Copy link

@XiongKe94 XiongKe94 commented Oct 25, 2017

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.