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.deskclock.ringtone;
18 
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22 import android.widget.ImageView;
23 import android.widget.TextView;
24 
25 import com.android.deskclock.ItemAdapter.ItemViewHolder;
26 import com.android.deskclock.R;
27 
28 import static android.view.View.GONE;
29 
30 final class AddCustomRingtoneViewHolder extends ItemViewHolder<AddCustomRingtoneHolder>
31         implements View.OnClickListener {
32 
33     static final int VIEW_TYPE_ADD_NEW = Integer.MIN_VALUE;
34     static final int CLICK_ADD_NEW = VIEW_TYPE_ADD_NEW;
35 
AddCustomRingtoneViewHolder(View itemView)36     private AddCustomRingtoneViewHolder(View itemView) {
37         super(itemView);
38         itemView.setOnClickListener(this);
39 
40         final View selectedView = itemView.findViewById(R.id.sound_image_selected);
41         selectedView.setVisibility(GONE);
42 
43         final TextView nameView = (TextView) itemView.findViewById(R.id.ringtone_name);
44         nameView.setText(itemView.getContext().getString(R.string.add_new_sound));
45         nameView.setAlpha(0.63f);
46 
47         final ImageView imageView = (ImageView) itemView.findViewById(R.id.ringtone_image);
48         imageView.setImageResource(R.drawable.ic_add_white_24dp);
49         imageView.setAlpha(0.63f);
50     }
51 
52     @Override
onClick(View view)53     public void onClick(View view) {
54         notifyItemClicked(AddCustomRingtoneViewHolder.CLICK_ADD_NEW);
55     }
56 
57     public static class Factory implements ItemViewHolder.Factory {
58 
59         private final LayoutInflater mInflater;
60 
Factory(LayoutInflater inflater)61         Factory(LayoutInflater inflater) {
62             mInflater = inflater;
63         }
64 
65         @Override
createViewHolder(ViewGroup parent, int viewType)66         public ItemViewHolder<?> createViewHolder(ViewGroup parent, int viewType) {
67             final View itemView = mInflater.inflate(R.layout.ringtone_item_sound, parent, false);
68             return new AddCustomRingtoneViewHolder(itemView);
69         }
70     }
71 }