blob: fbad7646ea5b231d3040587d98d52fd6eb643a01 [file] [log] [blame]
Garfield Tanb47b4b52017-05-16 12:48:53 -07001/*
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
17package com.android.documentsui;
18
Jeff Sharkey6396c472019-02-19 14:43:04 -070019import android.content.ContentResolver;
Garfield Tanb47b4b52017-05-16 12:48:53 -070020import android.content.Context;
Garfield Tanb47b4b52017-05-16 12:48:53 -070021
22import com.android.documentsui.base.Lookup;
Garfield Tanb47b4b52017-05-16 12:48:53 -070023
24/**
25 * A map from mime type to user friendly type string.
26 */
27public class FileTypeMap implements Lookup<String, String> {
Jeff Sharkey6396c472019-02-19 14:43:04 -070028 private final ContentResolver mResolver;
Garfield Tanb47b4b52017-05-16 12:48:53 -070029
30 FileTypeMap(Context context) {
Jeff Sharkey6396c472019-02-19 14:43:04 -070031 mResolver = context.getContentResolver();
Garfield Tanb47b4b52017-05-16 12:48:53 -070032 }
33
34 @Override
35 public String lookup(String mimeType) {
Jeff Sharkey6396c472019-02-19 14:43:04 -070036 if (mimeType == null) return null;
37 return String.valueOf(mResolver.getTypeInfo(mimeType).getLabel());
Garfield Tanb47b4b52017-05-16 12:48:53 -070038 }
39}