1012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander/* 2012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * Copyright (C) 2017 The Android Open Source Project 3012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * 4012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * Licensed under the Apache License, Version 2.0 (the "License"); 5012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * you may not use this file except in compliance with the License. 6012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * You may obtain a copy of the License at 7012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * 8012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * http://www.apache.org/licenses/LICENSE-2.0 9012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * 10012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * Unless required by applicable law or agreed to in writing, software 11012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * distributed under the License is distributed on an "AS IS" BASIS, 12012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * See the License for the specific language governing permissions and 14012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * limitations under the License. 15012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander */ 16012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderpackage com.android.documentsui.inspector.actions; 17012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 18012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport android.content.Context; 19012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport android.graphics.drawable.Drawable; 20012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport android.util.AttributeSet; 21012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport android.view.LayoutInflater; 22012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport android.view.View; 23012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport android.widget.ImageButton; 24012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport android.widget.ImageView; 25012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport android.widget.LinearLayout; 26012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport android.widget.TextView; 27f433d20a7759775dfc848fdd50da2a3f01219a54Steve McKay 28012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport com.android.documentsui.R; 29012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderimport com.android.documentsui.inspector.InspectorController; 30012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 31012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander/** 32012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * Displays different actions to the user. The action that's displayed depends on what Action is 33012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander * passed in to init. 34012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander */ 35012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolanderpublic final class ActionView extends LinearLayout implements InspectorController.ActionDisplay { 36012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 37012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander private final TextView mHeader; 38012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander private final ImageView mAppIcon; 39012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander private final TextView mAppName; 40012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander private final ImageButton mActionButton; 41012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander private Action mAction; 42012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 43012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander public ActionView(Context context) { 44012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander this(context, null); 45012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } 46012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 47012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander public ActionView(Context context, AttributeSet attrs) { 48012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander this(context, attrs, 0); 49012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } 50012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 51012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander public ActionView(Context context, AttributeSet attrs, int defStyleAttr) { 52012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander super(context, attrs, defStyleAttr); 53012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( 54012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander Context.LAYOUT_INFLATER_SERVICE); 55012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander View view = inflater.inflate(R.layout.inspector_action_view, null); 56012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander addView(view); 57012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 58012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mHeader = (TextView) findViewById(R.id.action_header); 59012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mAppIcon = (ImageView) findViewById(R.id.app_icon); 60012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mAppName = (TextView) findViewById(R.id.app_name); 61012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mActionButton = (ImageButton) findViewById(R.id.inspector_action_button); 62012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } 63012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 64012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander @Override 65012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander public void init(Action action, OnClickListener listener) { 66012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mAction = action; 67012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander setActionHeader(mAction.getHeader()); 68012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 69012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander setAppIcon(mAction.getAppIcon()); 70012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander setAppName(mAction.getAppName()); 71012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 72012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mActionButton.setOnClickListener(listener); 73012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander showAction(true); 74012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } 75012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 76012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander @Override 77012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander public void setVisible(boolean visible) { 78012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander setVisibility(visible ? View.VISIBLE : View.GONE); 79012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } 80012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 81012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander @Override 82012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander public void setActionHeader(String header) { 83012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mHeader.setText(header); 84012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } 85012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 86012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander @Override 87012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander public void setAppIcon(Drawable icon) { 88012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mAppIcon.setImageDrawable(icon); 89012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } 90012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 91012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander @Override 92012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander public void setAppName(String name) { 93012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mAppName.setText(name); 94012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } 95012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 96012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander @Override 97012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander public void showAction(boolean visible) { 98012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander 99012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander if (visible) { 100012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mActionButton.setImageResource(mAction.getButtonIcon()); 101012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mActionButton.setVisibility(View.VISIBLE); 102012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } else { 103012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander mActionButton.setVisibility(View.GONE); 104012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } 105012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander } 106012e8bac5af5bb79838a90c6be2d37af3b8a6093Austin Kolander}