Android Create Dashboard Statistic

Android Create Dashboard Statistic


1. Project Structure


2. Gradle

plugins {
  id 'com.android.application'
}

android {
  compileSdkVersion 30
  buildToolsVersion "30.0.3"

  defaultConfig {
    applicationId "com.dashboard.statistic"
    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'
  implementation 'com.crystal:crystalrangeseekbar:1.1.3'
  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.dashboard.statistic;

import android.graphics.PorterDuff;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.dashboard.statistic.utils.Tools;

public class MainActivity extends AppCompatActivity {

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

  private void initToolbar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_menu);
    toolbar.getNavigationIcon().setColorFilter(getResources().getColor(R.color.grey_60), PorterDuff.Mode.SRC_ATOP);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    Tools.setSystemBarColor(this, R.color.grey_5);
    Tools.setSystemBarLight(this);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search_setting, menu);
    Tools.changeMenuIconColor(menu, getResources().getColor(R.color.grey_60));
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
      finish();
    } else {
      Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
    }
    return super.onOptionsItemSelected(item);
  }
}


4. Layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/grey_5"
  android:fitsSystemWindows="true"
  android:orientation="vertical">

  <com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white">

    <androidx.appcompat.widget.Toolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="?android:attr/actionBarSize"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
      app:contentInsetStartWithNavigation="0dp"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
      app:theme="@style/Toolbar.Light"
      app:title="Dashboard" />

  </com.google.android.material.appbar.AppBarLayout>

  <androidx.core.widget.NestedScrollView
    android:id="@+id/nested_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none"
    android:scrollingCache="true">

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

      <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_large" />

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="@dimen/spacing_middle"
        android:paddingRight="@dimen/spacing_middle">

        <androidx.cardview.widget.CardView
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginBottom="@dimen/spacing_xsmall"
          android:layout_marginLeft="@dimen/spacing_xsmall"
          android:layout_marginRight="@dimen/spacing_xsmall"
          android:layout_marginTop="@dimen/spacing_xsmall"
          android:layout_weight="1"
          android:visibility="visible"
          app:cardCornerRadius="2dp"
          app:cardElevation="2dp">

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

            <RelativeLayout
              android:layout_width="40dp"
              android:layout_height="40dp">

              <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true"
                android:tint="@color/orange_400"
                app:srcCompat="@drawable/shape_circle" />

              <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_centerInParent="true"
                android:tint="@android:color/white"
                app:srcCompat="@drawable/ic_person" />

            </RelativeLayout>

            <View
              android:layout_width="@dimen/spacing_middle"
              android:layout_height="0dp" />

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

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="92776"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
                android:textColor="@color/grey_60"
                android:textStyle="bold" />

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Viewer"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            </LinearLayout>

          </LinearLayout>

        </androidx.cardview.widget.CardView>

        <View
          android:layout_width="@dimen/spacing_middle"
          android:layout_height="0dp" />

        <androidx.cardview.widget.CardView
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginBottom="@dimen/spacing_xsmall"
          android:layout_marginLeft="@dimen/spacing_xsmall"
          android:layout_marginRight="@dimen/spacing_xsmall"
          android:layout_marginTop="@dimen/spacing_xsmall"
          android:layout_weight="1"
          android:visibility="visible"
          app:cardCornerRadius="2dp"
          app:cardElevation="2dp">

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

            <RelativeLayout
              android:layout_width="40dp"
              android:layout_height="40dp">

              <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true"
                android:tint="@color/indigo_400"
                app:srcCompat="@drawable/shape_circle" />

              <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_centerInParent="true"
                android:tint="@android:color/white"
                app:srcCompat="@drawable/ic_file_download" />

            </RelativeLayout>

            <View
              android:layout_width="@dimen/spacing_middle"
              android:layout_height="0dp" />

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

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:text="52791"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
                android:textColor="@color/grey_60"
                android:textStyle="bold" />

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Downloads"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            </LinearLayout>

          </LinearLayout>

        </androidx.cardview.widget.CardView>

      </LinearLayout>

      <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_middle" />

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="@dimen/spacing_middle"
        android:paddingRight="@dimen/spacing_middle">

        <androidx.cardview.widget.CardView
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginBottom="@dimen/spacing_xsmall"
          android:layout_marginLeft="@dimen/spacing_xsmall"
          android:layout_marginRight="@dimen/spacing_xsmall"
          android:layout_marginTop="@dimen/spacing_xsmall"
          android:layout_weight="1"
          android:visibility="visible"
          app:cardCornerRadius="2dp"
          app:cardElevation="2dp">

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

            <RelativeLayout
              android:layout_width="40dp"
              android:layout_height="40dp">

              <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true"
                android:tint="@color/red_300"
                app:srcCompat="@drawable/shape_circle" />

              <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_centerInParent="true"
                android:tint="@android:color/white"
                app:srcCompat="@drawable/ic_shopping_basket" />

            </RelativeLayout>

            <View
              android:layout_width="@dimen/spacing_middle"
              android:layout_height="0dp" />

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

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:text="4000+"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
                android:textColor="@color/grey_60"
                android:textStyle="bold" />

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Products"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            </LinearLayout>

          </LinearLayout>

        </androidx.cardview.widget.CardView>

        <View
          android:layout_width="@dimen/spacing_middle"
          android:layout_height="0dp" />

        <androidx.cardview.widget.CardView
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginBottom="@dimen/spacing_xsmall"
          android:layout_marginLeft="@dimen/spacing_xsmall"
          android:layout_marginRight="@dimen/spacing_xsmall"
          android:layout_marginTop="@dimen/spacing_xsmall"
          android:layout_weight="1"
          android:visibility="visible"
          app:cardCornerRadius="2dp"
          app:cardElevation="2dp">

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

            <RelativeLayout
              android:layout_width="40dp"
              android:layout_height="40dp">

              <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerInParent="true"
                android:tint="@color/light_green_500"
                app:srcCompat="@drawable/shape_circle" />

              <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_centerInParent="true"
                android:tint="@android:color/white"
                app:srcCompat="@drawable/ic_description" />

            </RelativeLayout>

            <View
              android:layout_width="@dimen/spacing_middle"
              android:layout_height="0dp" />

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

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:text="4429"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
                android:textColor="@color/grey_60"
                android:textStyle="bold" />

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Reports"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Caption"
                android:textColor="@color/grey_40" />

            </LinearLayout>

          </LinearLayout>

        </androidx.cardview.widget.CardView>

      </LinearLayout>

      <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_middle" />

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="@dimen/spacing_middle"
        android:paddingRight="@dimen/spacing_middle">

        <androidx.cardview.widget.CardView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginBottom="@dimen/spacing_xsmall"
          android:layout_marginLeft="@dimen/spacing_xsmall"
          android:layout_marginRight="@dimen/spacing_xsmall"
          android:layout_marginTop="@dimen/spacing_xsmall"
          android:visibility="visible"
          app:cardCornerRadius="2dp"
          app:cardElevation="2dp">

          <LinearLayout
            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">

              <View
                android:layout_width="@dimen/spacing_large"
                android:layout_height="0dp" />

              <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Recent Activity"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
                android:textColor="@color/grey_60"
                android:textStyle="bold" />

              <ImageButton
                android:layout_width="?android:attr/actionBarSize"
                android:layout_height="?android:attr/actionBarSize"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:tint="@color/colorPrimary"
                app:srcCompat="@drawable/ic_add" />

            </LinearLayout>

            <View
              android:layout_width="match_parent"
              android:layout_height="1dp"
              android:background="@color/grey_10" />

            <View
              android:layout_width="0dp"
              android:layout_height="@dimen/spacing_middle" />

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="@dimen/spacing_xmlarge"
              android:gravity="center_vertical"
              android:orientation="horizontal">

              <View
                android:layout_width="@dimen/spacing_large"
                android:layout_height="0dp" />

              <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Post a Product"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Body2"
                android:textColor="@color/grey_60" />

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="16 Feb 18"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Body2"
                android:textColor="@color/grey_40" />

              <View
                android:layout_width="@dimen/spacing_large"
                android:layout_height="0dp" />

            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="@dimen/spacing_xmlarge"
              android:gravity="center_vertical"
              android:orientation="horizontal">

              <View
                android:layout_width="@dimen/spacing_large"
                android:layout_height="0dp" />

              <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Update Report"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Body2"
                android:textColor="@color/grey_60" />

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="28 Jan 18"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Body2"
                android:textColor="@color/grey_40" />

              <View
                android:layout_width="@dimen/spacing_large"
                android:layout_height="0dp" />

            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="@dimen/spacing_xmlarge"
              android:gravity="center_vertical"
              android:orientation="horizontal">

              <View
                android:layout_width="@dimen/spacing_large"
                android:layout_height="0dp" />

              <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Share Story"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Body2"
                android:textColor="@color/grey_60" />

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="17 Jan 18"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Body2"
                android:textColor="@color/grey_40" />

              <View
                android:layout_width="@dimen/spacing_large"
                android:layout_height="0dp" />

            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="@dimen/spacing_xmlarge"
              android:gravity="center_vertical"
              android:orientation="horizontal">

              <View
                android:layout_width="@dimen/spacing_large"
                android:layout_height="0dp" />

              <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Monthly Download"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Body2"
                android:textColor="@color/grey_60" />

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="10 Jan 18"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Body2"
                android:textColor="@color/grey_40" />

              <View
                android:layout_width="@dimen/spacing_large"
                android:layout_height="0dp" />

            </LinearLayout>

            <View
              android:layout_width="0dp"
              android:layout_height="@dimen/spacing_middle" />

            <View
              android:layout_width="match_parent"
              android:layout_height="1dp"
              android:background="@color/grey_10" />

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="?android:attr/actionBarSize"
              android:background="?attr/selectableItemBackground"
              android:clickable="true"
              android:gravity="center"
              android:orientation="horizontal">

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="See More"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
                android:textColor="@color/colorPrimary" />

            </LinearLayout>

          </LinearLayout>

        </androidx.cardview.widget.CardView>

      </LinearLayout>

      <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_middle" />

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="@dimen/spacing_middle"
        android:paddingRight="@dimen/spacing_middle">

        <androidx.cardview.widget.CardView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginBottom="@dimen/spacing_medium"
          android:layout_marginLeft="@dimen/spacing_xsmall"
          android:layout_marginRight="@dimen/spacing_xsmall"
          android:layout_marginTop="@dimen/spacing_xsmall"
          android:visibility="visible"
          app:cardCornerRadius="2dp"
          app:cardElevation="2dp">

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

            <ImageView
              android:layout_width="40dp"
              android:layout_height="40dp"
              android:foreground="?attr/selectableItemBackground"
              android:src="@drawable/img_social_twitter" />

            <View
              android:layout_width="@dimen/spacing_large"
              android:layout_height="0dp" />

            <ImageView
              android:layout_width="40dp"
              android:layout_height="40dp"
              android:foreground="?attr/selectableItemBackground"
              android:src="@drawable/img_social_youtube" />

            <View
              android:layout_width="@dimen/spacing_large"
              android:layout_height="0dp" />

            <ImageView
              android:layout_width="40dp"
              android:layout_height="40dp"
              android:foreground="?attr/selectableItemBackground"
              android:src="@drawable/img_social_facebook" />

            <View
              android:layout_width="@dimen/spacing_large"
              android:layout_height="0dp" />

            <ImageView
              android:layout_width="40dp"
              android:layout_height="40dp"
              android:foreground="?attr/selectableItemBackground"
              android:src="@drawable/img_social_instagram" />

          </LinearLayout>

        </androidx.cardview.widget.CardView>

      </LinearLayout>

      <View
        android:layout_width="0dp"
        android:layout_height="@dimen/spacing_large" />

    </LinearLayout>

  </androidx.core.widget.NestedScrollView>

</LinearLayout>


5. Value

<?xml version="1.0" encoding="utf-8"?>
<resources>

  <style name="ThemeOverlay.AppCompat.Dark.ActionBar" parent="Base.ThemeOverlay.AppCompat.Dark.ActionBar"/>
  <style name="ThemeOverlay.AppCompat.DayNight" parent="ThemeOverlay.AppCompat.Light"/>
  <style name="Base.TextAppearance.AppCompat.Subhead" parent="android:TextAppearance.Material.Subhead"/>
  <style name="Base.TextAppearance.AppCompat.Caption" parent="android:TextAppearance.Material.Caption"/>
  <style name="Base.TextAppearance.AppCompat.Body2" parent="android:TextAppearance.Material.Body2"/>

  <color name="orange_400">#FFA726</color>
  <color name="grey_10">#e6e6e6</color>
  <color name="grey_40">#999999</color>
  <color name="grey_60">#666666</color>
  <color name="indigo_400">#5C6BC0</color>
  <color name="red_300">#E57373</color>
  <color name="light_green_500">#8BC34A</color>

</resources>