Home | History | Annotate | Download | only in sidebar
      1 /*
      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 
     17 package com.android.documentsui.sidebar;
     18 
     19 import android.annotation.LayoutRes;
     20 import android.view.DragEvent;
     21 import android.view.LayoutInflater;
     22 import android.view.Menu;
     23 import android.view.MenuInflater;
     24 import android.view.View;
     25 import android.view.ViewGroup;
     26 
     27 import com.android.documentsui.MenuManager;
     28 import com.android.documentsui.R;
     29 
     30 /**
     31  * Describes a root navigation point of documents. Each one of them is presented as an item in the
     32  * sidebar
     33  */
     34 abstract class Item {
     35     private final @LayoutRes int mLayoutId;
     36 
     37     final String stringId;
     38 
     39     public Item(@LayoutRes int layoutId, String stringId) {
     40         mLayoutId = layoutId;
     41         this.stringId = stringId;
     42     }
     43 
     44     public View getView(View convertView, ViewGroup parent) {
     45         if (convertView == null
     46                 || (Integer) convertView.getTag(R.id.layout_id_tag) != mLayoutId) {
     47             convertView = LayoutInflater.from(parent.getContext())
     48                     .inflate(mLayoutId, parent, false);
     49         }
     50         convertView.setTag(R.id.layout_id_tag, mLayoutId);
     51         bindView(convertView);
     52         return convertView;
     53     }
     54 
     55     abstract void bindView(View convertView);
     56 
     57     abstract boolean isRoot();
     58 
     59     abstract void open();
     60 
     61     boolean isDropTarget() {
     62         return isRoot();
     63     }
     64 
     65     boolean dropOn(DragEvent event) {
     66         return false;
     67     }
     68 
     69     boolean showAppDetails() {
     70         return false;
     71     }
     72 
     73     void createContextMenu(Menu menu, MenuInflater inflater, MenuManager menuManager) {}
     74 }
     75