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.actions; 17 18 import android.content.Context; 19 import android.graphics.drawable.Drawable; 20 import android.util.AttributeSet; 21 import android.view.LayoutInflater; 22 import android.view.View; 23 import android.widget.ImageButton; 24 import android.widget.ImageView; 25 import android.widget.LinearLayout; 26 import android.widget.TextView; 27 28 import com.android.documentsui.R; 29 import com.android.documentsui.inspector.InspectorController; 30 31 /** 32 * Displays different actions to the user. The action that's displayed depends on what Action is 33 * passed in to init. 34 */ 35 public final class ActionView extends LinearLayout implements InspectorController.ActionDisplay { 36 37 private final TextView mHeader; 38 private final ImageView mAppIcon; 39 private final TextView mAppName; 40 private final ImageButton mActionButton; 41 private Action mAction; 42 ActionView(Context context)43 public ActionView(Context context) { 44 this(context, null); 45 } 46 ActionView(Context context, AttributeSet attrs)47 public ActionView(Context context, AttributeSet attrs) { 48 this(context, attrs, 0); 49 } 50 ActionView(Context context, AttributeSet attrs, int defStyleAttr)51 public ActionView(Context context, AttributeSet attrs, int defStyleAttr) { 52 super(context, attrs, defStyleAttr); 53 LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( 54 Context.LAYOUT_INFLATER_SERVICE); 55 View view = inflater.inflate(R.layout.inspector_action_view, null); 56 addView(view); 57 58 mHeader = (TextView) findViewById(R.id.action_header); 59 mAppIcon = (ImageView) findViewById(R.id.app_icon); 60 mAppName = (TextView) findViewById(R.id.app_name); 61 mActionButton = (ImageButton) findViewById(R.id.inspector_action_button); 62 } 63 64 @Override init(Action action, OnClickListener listener)65 public void init(Action action, OnClickListener listener) { 66 mAction = action; 67 setActionHeader(mAction.getHeader()); 68 69 setAppIcon(mAction.getAppIcon()); 70 setAppName(mAction.getAppName()); 71 72 mActionButton.setOnClickListener(listener); 73 showAction(true); 74 } 75 76 @Override setVisible(boolean visible)77 public void setVisible(boolean visible) { 78 setVisibility(visible ? View.VISIBLE : View.GONE); 79 } 80 81 @Override setActionHeader(String header)82 public void setActionHeader(String header) { 83 mHeader.setText(header); 84 } 85 86 @Override setAppIcon(Drawable icon)87 public void setAppIcon(Drawable icon) { 88 mAppIcon.setImageDrawable(icon); 89 } 90 91 @Override setAppName(String name)92 public void setAppName(String name) { 93 mAppName.setText(name); 94 } 95 96 @Override showAction(boolean visible)97 public void showAction(boolean visible) { 98 99 if (visible) { 100 mActionButton.setImageResource(mAction.getButtonIcon()); 101 mActionButton.setVisibility(View.VISIBLE); 102 } else { 103 mActionButton.setVisibility(View.GONE); 104 } 105 } 106 }