Android Create Backdrop Selection

Android Create Backdrop Selection


1. Project Structure


2. Gradle

plugins {
  id 'com.android.application'
}

android {
  compileSdkVersion 30
  buildToolsVersion "30.0.3"

  defaultConfig {
    applicationId "com.backdrop.selection"
    minSdkVersion 19
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  }

  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

dependencies {
  implementation 'com.balysv:material-ripple:1.0.2'
  implementation 'androidx.appcompat:appcompat:1.3.0'
  implementation 'com.google.android.material:material:1.4.0'
  implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
  testImplementation 'junit:junit:4.+'
  androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}


3. Main Activity

package com.backdrop.selection;

import android.animation.ObjectAnimator;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import com.backdrop.selection.utils.BackdropViewAnimation;
import com.backdrop.selection.utils.Tools;

public class MainActivity extends AppCompatActivity {

  private BackdropViewAnimation backdropAnimation;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_backdrop_selection);

    initComponent();
  }

  private void initComponent() {
    Tools.setSystemBarColor(this, R.color.deep_purple_700);
    ImageView action_menu = findViewById(R.id.action_menu);

    backdropAnimation = new BackdropViewAnimation(this, findViewById(R.id.backdrop_view), findViewById(R.id.content));
    backdropAnimation.addStateListener(new BackdropViewAnimation.StateListener() {
      @Override
      public void onOpen(ObjectAnimator animator) {
        action_menu.setImageResource(R.drawable.ic_close);
      }

      @Override
      public void onClose(ObjectAnimator animator) {
        action_menu.setImageResource(R.drawable.ic_tune);
      }
    });
    action_menu.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        backdropAnimation.toggle();
      }
    });

    new Handler(this.getMainLooper()).postDelayed(new Runnable() {
      @Override
      public void run() {
        backdropAnimation.toggle();
      }
    }, 600);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_more_exit, menu);
    Tools.changeMenuIconColor(menu, Color.WHITE);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_close) {
      finish();
    }
    return super.onOptionsItemSelected(item);
  }

  @Override
  public void onBackPressed() {
    if (backdropAnimation.isBackdropShown()) {
      backdropAnimation.close();
    } else {
      super.onBackPressed();
    }
  }
}


4. Layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/deep_purple_A700"
  android:clipChildren="false"
  android:clipToPadding="false">

  <LinearLayout
    android:id="@+id/backdrop_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="?android:attr/actionBarSize"
      android:gravity="center_vertical"
      android:orientation="horizontal">

      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="@dimen/spacing_smlarge"
        android:text="Selection control"
        android:textAppearance="@style/TextAppearance.AppCompat.Title"
        android:textColor="@android:color/white" />

      <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />

      <ImageView
        android:id="@+id/action_menu"
        android:layout_width="?android:attr/actionBarSize"
        android:layout_height="?android:attr/actionBarSize"
        android:padding="@dimen/spacing_large"
        app:srcCompat="@drawable/ic_tune"
        app:tint="@android:color/white" />

    </LinearLayout>

    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingHorizontal="@dimen/spacing_large"
      android:paddingTop="@dimen/spacing_medium"
      android:paddingBottom="@dimen/spacing_large">

      <com.google.android.material.checkbox.MaterialCheckBox
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_xmlarge"
        android:paddingHorizontal="@dimen/spacing_mlarge"
        android:text="Shoes"
        android:textColor="@android:color/white"
        app:buttonTint="@android:color/white" />

      <com.google.android.material.checkbox.MaterialCheckBox
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_xmlarge"
        android:checked="true"
        android:paddingHorizontal="@dimen/spacing_mlarge"
        android:text="Dresses"
        android:textColor="@android:color/white"
        app:buttonTint="@android:color/white" />

      <com.google.android.material.checkbox.MaterialCheckBox
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_xmlarge"
        android:paddingHorizontal="@dimen/spacing_mlarge"
        android:text="Shirt"
        android:textColor="@android:color/white"
        app:buttonTint="@android:color/white" />

      <com.google.android.material.checkbox.MaterialCheckBox
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_xmlarge"
        android:paddingHorizontal="@dimen/spacing_mlarge"
        android:text="Accessories"
        android:textColor="@android:color/white"
        app:buttonTint="@android:color/white" />

    </LinearLayout>

    <View
      android:layout_width="match_parent"
      android:layout_height="1dp"
      android:layout_marginHorizontal="@dimen/spacing_smlarge"
      android:background="@color/overlay_light_20" />

    <RadioGroup
      android:id="@+id/group_order_by"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingHorizontal="@dimen/spacing_large"
      android:paddingVertical="@dimen/spacing_large">

      <com.google.android.material.radiobutton.MaterialRadioButton
        android:id="@+id/order_by_1"
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_xmlarge"
        android:paddingHorizontal="@dimen/spacing_mlarge"
        android:text="Popular"
        android:textColor="@android:color/white"
        app:buttonTint="@android:color/white" />

      <com.google.android.material.radiobutton.MaterialRadioButton
        android:id="@+id/order_by_2"
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_xmlarge"
        android:checked="true"
        android:paddingHorizontal="@dimen/spacing_mlarge"
        android:text="New Arrival"
        android:textColor="@android:color/white"
        app:buttonTint="@android:color/white" />

      <com.google.android.material.radiobutton.MaterialRadioButton
        android:id="@+id/order_by_3"
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_xmlarge"
        android:paddingHorizontal="@dimen/spacing_mlarge"
        android:text="Featured"
        android:textColor="@android:color/white"
        app:buttonTint="@android:color/white" />

    </RadioGroup>

  </LinearLayout>

  <androidx.cardview.widget.CardView
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?android:attr/actionBarSize"
    android:visibility="visible"
    app:cardBackgroundColor="@android:color/white"
    app:cardCornerRadius="6dp"
    app:cardElevation="8dp">

    <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent">

      <LinearLayout
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:paddingBottom="@dimen/spacing_xxlarge"
        android:gravity="center"
        android:orientation="vertical">

        <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal">

          <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginEnd="@dimen/spacing_mlarge"
            android:layout_marginRight="@dimen/spacing_mlarge"
            android:src="@drawable/shape_circle"
            app:tint="@color/grey_20" />

          <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <View
              android:layout_width="70dp"
              android:layout_height="@dimen/spacing_middle"
              android:background="@color/grey_20" />

            <View
              android:layout_width="match_parent"
              android:layout_height="@dimen/spacing_middle"
              android:layout_marginTop="@dimen/spacing_middle"
              android:background="@color/grey_20" />

            <View
              android:layout_width="40dp"
              android:layout_height="@dimen/spacing_middle"
              android:layout_marginTop="@dimen/spacing_middle"
              android:background="@color/grey_20" />

          </LinearLayout>

        </LinearLayout>

        <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="@dimen/spacing_large"
          android:orientation="horizontal">

          <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginEnd="@dimen/spacing_mlarge"
            android:layout_marginRight="@dimen/spacing_xlarge"
            android:src="@drawable/shape_circle"
            app:tint="@color/grey_10" />

          <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <View
              android:layout_width="100dp"
              android:layout_height="@dimen/spacing_middle"
              android:background="@color/grey_10" />

            <View
              android:layout_width="match_parent"
              android:layout_height="@dimen/spacing_middle"
              android:layout_marginTop="@dimen/spacing_middle"
              android:background="@color/grey_10" />

            <View
              android:layout_width="40dp"
              android:layout_height="@dimen/spacing_middle"
              android:layout_marginTop="@dimen/spacing_middle"
              android:background="@color/grey_10" />

          </LinearLayout>

        </LinearLayout>

        <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="@dimen/spacing_large"
          android:text="Opps, search item not found"
          android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
          android:textColor="@color/grey_40" />

      </LinearLayout>

    </RelativeLayout>

  </androidx.cardview.widget.CardView>

</FrameLayout>


5. Value

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:ns1="urn:oasis:names:tc:xliff:document:1.2">

  <style name="TextAppearance.AppCompat.Title" parent="Base.TextAppearance.AppCompat.Title"/>
  <style name="Base.TextAppearance.AppCompat.Small">
    <item name="android:textSize">@dimen/abc_text_size_small_material</item>
    <item name="android:textColor">?android:attr/textColorTertiary</item>
  </style>

  <color name="deep_purple_A700">#6200EA</color>
  <color name="overlay_light_20">#33FFFFFF</color>
  <color name="grey_10">#e6e6e6</color>
  <color name="grey_20">#cccccc</color>
  <color name="grey_40">#999999</color>

</resources>