Giter Site home page Giter Site logo

android-slices-demo's Introduction

Android-Slices-Demo

This project explains how to use Android Jetpack to create Slices.

Topic covered:

  1. Basic slices shared data through slices with activity

  2. Advance Slices :

  • Live List
  • Grid
  • Header
  • Toggle Switches
  • Multiple Actions passing
  • Live Slider
  • Live Progress Bar &
  • Complex Slices

Follow the steps to get started with slices from blog: http://hiteshsahu.com/blogs/android_slices

Android Slices Tutorial

Continuing in last post here I gone explain how to create Slices for your application. If you have not read it please go through my previous post Understanding Slices to get your setup ready.

First Get your setup ready

You need to install Slice Viewer apk to view your slices. Download latest relase of slice viewer apk from https://github.com/googlesamples/android-SliceViewer/releases & install it using command:

adb install -r -t slice-viewer.apk

where :

  • -r: replaces existing application
  • -t: allow test packages

Now you can view your Slice by running the following command:

adb shell am start -a android.intent.action.VIEW -d slice-content://com.hiteshsahu.slicedemo/

It is pretty much like loading different pages of a website by changing URLS

For example:

  • content://com.hiteshsahu.slicedemo/ : will gone load home slice
  • content://com.hiteshsahu.slicedemo/about : will gone load about slice
  • content://com.hiteshsahu.slicedemo/contact : will gone load contact slice

and so on see the result below.

Every time you gone launch a new slice with this adb command then that slice will be automatically get added in Slice Viewer demo app. Which you can see any time later.

Same can be achieve with the help of Android studio but I prefer command line tool. COmmand line tool is less complicate and less overhead.

Uninstall sliceviewer

If you have uninstalled sliceviewer.apk by drag and drop in Launcher app then chances are you might no longer will be able to install it back via adb command. This is a weird bug I found. In that case you will need to uninstall sliceviewer using this command.

 adb  uninstall com.example.android.sliceviewer

Building Custom Slices

As already described in my previous post Understanding SLices you can use Android Studio to create Slices as shown in pic below:

Steps to build slices

  1. Install SliceViewer APK:
 adb install -r -t slice-viewer.apk
  1. Download, Build, Install & Launch this project.

  1. Execute this command from adb termainal:
  adb shell am start -a android.intent.action.VIEW -d slice-<uri_from_below>

For example to Launch Home screen from Slice execute. Note the "-" after slice.

  adb shell am start -a android.intent.action.VIEW -d slice-content://com.hiteshsahu.slicedemo/

Basic SLices

BasicSliceProvider class contain example of how we can create aslice and use Peending Intent to send data to the App

Similarly replace <uri_from_below> with this uris to launch Slice mapped to screens.

  • home

        content://com.hiteshsahu.slicedemo/ 
    
  • about

       content://com.hiteshsahu.slicedemo/about 
    
  • contact

        content://com.hiteshsahu.slicedemo/contact  
    
  • ERROR 404

        content://com.hiteshsahu.slicedemo/etc : 
    

Advance Slices

Use this uri to launch complex slices with live data

  • SLICE WITH HEADER : this uri launch a Slice with a header and 3 custom Actions. Each action can be send to App with the help of Pending Intents. Click on Actions to see how App handle them.

        content://com.hiteshsahu.slicedemo.advance/ 
    
  • SLICE WITH TOGGLE Show how to use toggle switch to turn on/off Wifi

      content://com.hiteshsahu.slicedemo.advance/toggle 
    

  • SLICE WITH RANGE SLIDER & PROGRESS BAR Show how to show progress bar and Slider in Slices & control Media Volume of the device

       content://com.hiteshsahu.slicedemo.advance/slider  
    

  • SLICE WITH GRID Show how to show Grid of Images in Slices

       content://com.hiteshsahu.slicedemo.advance/grid  
    

  • SLICE WITH WIFI LIST Show how to show List of Wifi along with show more option.

       content://com.hiteshsahu.slicedemo.advance/list  
    

  • COMPLEX SLICE: Complex slice with more than one grid and row

         content://com.hiteshsahu.slicedemo.advance/combine  
    

android-slices-demo's People

Contributors

hiteshsahu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

rohitnotes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.