Home | History | Annotate | Download | only in autofillframework
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.example.android.autofillframework
     17 
     18 import android.os.Bundle
     19 import java.util.Arrays
     20 
     21 object CommonUtil {
     22 
     23     val TAG = "AutofillSample"
     24 
     25     val EXTRA_DATASET_NAME = "dataset_name"
     26     val EXTRA_FOR_RESPONSE = "for_response"
     27 
     28     private fun bundleToString(builder: StringBuilder, data: Bundle) {
     29         val keySet = data.keySet()
     30         builder.append("[Bundle with ").append(keySet.size).append(" keys:")
     31         for (key in keySet) {
     32             builder.append(' ').append(key).append('=')
     33             val value = data.get(key)
     34             if (value is Bundle) {
     35                 bundleToString(builder, value)
     36             } else {
     37                 val string = if (value is Array<*>) Arrays.toString(value) else value
     38                 builder.append(string)
     39             }
     40         }
     41         builder.append(']')
     42     }
     43 
     44     fun bundleToString(data: Bundle?): String {
     45         if (data == null) {
     46             return "N/A"
     47         }
     48         val builder = StringBuilder()
     49         bundleToString(builder, data)
     50         return builder.toString()
     51     }
     52 }