• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.android.documentsui.inspector;
17 
18 import static com.android.internal.util.Preconditions.checkArgument;
19 
20 import android.app.Fragment;
21 import android.content.Intent;
22 import android.net.Uri;
23 import android.os.Bundle;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.widget.ScrollView;
28 
29 import com.android.documentsui.R;
30 import com.android.documentsui.inspector.InspectorController.DataSupplier;
31 
32 /**
33  * Displays the Properties view in Files.
34  */
35 public class InspectorFragment extends Fragment {
36 
37     private static final String DOC_URI_ARG = "docUri";
38     private InspectorController mController;
39     private ScrollView mView;
40 
41     @Override
onCreate(Bundle savedInstanceState)42     public void onCreate(Bundle savedInstanceState) {
43         super.onCreate(savedInstanceState);
44     }
45 
46     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)47     public View onCreateView(LayoutInflater inflater, ViewGroup container,
48         Bundle savedInstanceState) {
49         final DataSupplier loader = new RuntimeDataSupplier(getActivity(), getLoaderManager());
50 
51         mView = (ScrollView) inflater.inflate(R.layout.inspector_fragment,
52                 container, false);
53         mController = new InspectorController(getActivity(), loader, mView, getArguments());
54         return mView;
55     }
56 
57     @Override
onStart()58     public void onStart() {
59         super.onStart();
60         Uri uri = (Uri) getArguments().get(DOC_URI_ARG);
61         mController.loadInfo(uri);
62     }
63 
64     @Override
onStop()65     public void onStop() {
66         super.onStop();
67         mController.reset();
68     }
69 
70     /**
71      * Creates a fragment with the appropriate args.
72      */
newInstance(Intent intent)73     public static InspectorFragment newInstance(Intent intent) {
74 
75         Bundle extras = intent.getExtras();
76         extras = extras != null ? extras : Bundle.EMPTY;
77         Bundle args = extras.deepCopy();
78 
79         Uri uri = intent.getData();
80         checkArgument(uri.getScheme().equals("content"));
81         args.putParcelable(DOC_URI_ARG, uri);
82 
83         InspectorFragment fragment = new InspectorFragment();
84         fragment.setArguments(args);
85         return fragment;
86     }
87 }
88