RootInfo.java revision ae9b51bfa313c51a31af30875a71255d7b6d2e61
1/* 2 * Copyright (C) 2013 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 17package com.android.documentsui.model; 18 19import static com.android.documentsui.model.DocumentInfo.getCursorInt; 20import static com.android.documentsui.model.DocumentInfo.getCursorLong; 21import static com.android.documentsui.model.DocumentInfo.getCursorString; 22 23import android.content.Context; 24import android.content.pm.PackageManager; 25import android.content.pm.ProviderInfo; 26import android.database.Cursor; 27import android.graphics.drawable.Drawable; 28import android.provider.DocumentsContract.Root; 29 30/** 31 * Representation of a {@link Root}. 32 */ 33public class RootInfo { 34 public String authority; 35 public String rootId; 36 public int rootType; 37 public int flags; 38 public int icon; 39 public String title; 40 public String summary; 41 public String documentId; 42 public long availableBytes; 43 44 public static RootInfo fromRootsCursor(String authority, Cursor cursor) { 45 final RootInfo root = new RootInfo(); 46 root.authority = authority; 47 root.rootId = getCursorString(cursor, Root.COLUMN_ROOT_ID); 48 root.rootType = getCursorInt(cursor, Root.COLUMN_ROOT_TYPE); 49 root.flags = getCursorInt(cursor, Root.COLUMN_FLAGS); 50 root.icon = getCursorInt(cursor, Root.COLUMN_ICON); 51 root.title = getCursorString(cursor, Root.COLUMN_TITLE); 52 root.summary = getCursorString(cursor, Root.COLUMN_SUMMARY); 53 root.documentId = getCursorString(cursor, Root.COLUMN_DOCUMENT_ID); 54 root.availableBytes = getCursorLong(cursor, Root.COLUMN_AVAILABLE_BYTES); 55 return root; 56 } 57 58 public Drawable loadIcon(Context context) { 59 if (icon != 0) { 60 if (authority != null) { 61 final PackageManager pm = context.getPackageManager(); 62 final ProviderInfo info = pm.resolveContentProvider(authority, 0); 63 if (info != null) { 64 return pm.getDrawable(info.packageName, icon, info.applicationInfo); 65 } 66 } else { 67 return context.getResources().getDrawable(icon); 68 } 69 } 70 return null; 71 } 72} 73