Last active
May 3, 2020 22:50
-
-
Save markushi/68ce8df77bed164b6275 to your computer and use it in GitHub Desktop.
Reveal Color View Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice