blob: fac8fcf0d0efe2a6e0e5311e25fa65fea69e3928 [file] [log] [blame]
Garfield Tan7d75f7b2016-09-20 16:33:24 -07001/*
2 * Copyright (C) 2016 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.picker;
18
19import android.content.Intent;
20import android.content.pm.ResolveInfo;
21import android.net.Uri;
22import android.provider.Settings;
Steve McKay6d20d192016-09-21 17:57:10 -070023import android.util.Log;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070024
Steve McKay739f94b2016-09-22 14:54:23 -070025import com.android.documentsui.AbstractActionHandler;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070026import com.android.documentsui.Metrics;
Steve McKay6d20d192016-09-21 17:57:10 -070027import com.android.documentsui.base.DocumentInfo;
Steve McKay739f94b2016-09-22 14:54:23 -070028import com.android.documentsui.base.DocumentStack;
29import com.android.documentsui.base.RootInfo;
Steve McKay6d20d192016-09-21 17:57:10 -070030import com.android.documentsui.dirlist.DocumentDetails;
31import com.android.documentsui.dirlist.FragmentTuner;
32import com.android.documentsui.dirlist.Model;
33import com.android.documentsui.dirlist.MultiSelectManager;
34
35import javax.annotation.Nullable;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070036
37/**
38 * Provides {@link PickActivity} action specializations to fragments.
39 */
Steve McKay739f94b2016-09-22 14:54:23 -070040class ActionHandler extends AbstractActionHandler<PickActivity> {
Garfield Tan7d75f7b2016-09-20 16:33:24 -070041
Steve McKay6d20d192016-09-21 17:57:10 -070042 private static final String TAG = "PickerActionHandler";
43
44 private final FragmentTuner mTuner;
45 private final Config mConfig;
46
47 ActionHandler(PickActivity activity, FragmentTuner tuner) {
Garfield Tan7d75f7b2016-09-20 16:33:24 -070048 super(activity);
Steve McKay6d20d192016-09-21 17:57:10 -070049 mTuner = tuner;
50 mConfig = new Config();
Garfield Tan7d75f7b2016-09-20 16:33:24 -070051 }
52
53 @Override
54 public void showAppDetails(ResolveInfo info) {
55 final Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
56 intent.setData(Uri.fromParts("package", info.activityInfo.packageName, null));
57 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
58 mActivity.startActivity(intent);
59 }
60
61 @Override
Steve McKay739f94b2016-09-22 14:54:23 -070062 public void openInNewWindow(DocumentStack path) {
63 // Open new window support only depends on vanilla Activity, so it is
64 // implemented in our parent class. But we don't support that in
65 // picking. So as a matter of defensiveness, we override that here.
66 throw new UnsupportedOperationException("Can't open in new window");
67 }
68
69 @Override
70 public void openRoot(RootInfo root) {
71 Metrics.logRootVisited(mActivity, root);
72 mActivity.onRootPicked(root);
73 }
74
75 @Override
Steve McKay6d20d192016-09-21 17:57:10 -070076 public void openRoot(ResolveInfo info) {
Garfield Tan7d75f7b2016-09-20 16:33:24 -070077 Metrics.logAppVisited(mActivity, info);
78 mActivity.onAppPicked(info);
79 }
Steve McKay6d20d192016-09-21 17:57:10 -070080
Steve McKay5f296942016-09-23 08:40:07 -070081
82 @Override
83 public boolean viewDocument(DocumentDetails details) {
84 return openDocument(details);
85 }
86
Steve McKay6d20d192016-09-21 17:57:10 -070087 @Override
88 public boolean openDocument(DocumentDetails details) {
89 DocumentInfo doc = mConfig.model.getDocument(details.getModelId());
90 if (doc == null) {
91 Log.w(TAG,
92 "Can't view item. No Document available for modeId: " + details.getModelId());
93 return false;
94 }
95
96 if (mTuner.isDocumentEnabled(doc.mimeType, doc.flags)) {
97 mActivity.onDocumentPicked(doc, mConfig.model);
98 mConfig.selectionMgr.clearSelection();
99 return true;
100 }
101 return false;
102 }
103
104 ActionHandler reset(Model model, MultiSelectManager selectionMgr) {
105 mConfig.reset(model, selectionMgr);
106 return this;
107 }
108
109 private static final class Config {
110
111 @Nullable Model model;
112 @Nullable MultiSelectManager selectionMgr;
113
114 public void reset(Model model, MultiSelectManager selectionMgr) {
115 assert(model != null);
116 assert(selectionMgr != null);
117
118 this.model = model;
119 this.selectionMgr = selectionMgr;
120 }
121 }
Garfield Tan7d75f7b2016-09-20 16:33:24 -0700122}