• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.settings.password;
18 
19 import android.support.v7.widget.RecyclerView;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.TextView;
24 
25 import com.android.settings.R;
26 import com.android.settings.password.PasswordRequirementAdapter.PasswordRequirementViewHolder;
27 
28 /**
29  * Used in {@link ChooseLockPassword} to show password requirements.
30  */
31 public class PasswordRequirementAdapter extends
32         RecyclerView.Adapter<PasswordRequirementViewHolder> {
33     private String[] mRequirements;
34 
PasswordRequirementAdapter()35     public PasswordRequirementAdapter() {
36         setHasStableIds(true);
37     }
38 
39     @Override
onCreateViewHolder(ViewGroup parent, int viewType)40     public PasswordRequirementViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
41         View v = LayoutInflater.from(parent.getContext())
42                 .inflate(R.layout.password_requirement_item, parent, false);
43         return new PasswordRequirementViewHolder(v);
44     }
45 
46     @Override
getItemCount()47     public int getItemCount() {
48         return  mRequirements.length;
49     }
50 
setRequirements(String[] requirements)51     public void setRequirements(String[] requirements) {
52         mRequirements = requirements;
53         notifyDataSetChanged();
54     }
55 
56     @Override
getItemId(int position)57     public long getItemId(int position) {
58         return mRequirements[position].hashCode();
59     }
60 
61     @Override
onBindViewHolder(PasswordRequirementViewHolder holder, int position)62     public void onBindViewHolder(PasswordRequirementViewHolder holder, int position) {
63         holder.mDescriptionText.setText(mRequirements[position]);
64     }
65 
66     public static class PasswordRequirementViewHolder extends RecyclerView.ViewHolder {
67         private TextView mDescriptionText;
68 
PasswordRequirementViewHolder(View itemView)69         public PasswordRequirementViewHolder(View itemView) {
70             super(itemView);
71             mDescriptionText = (TextView) itemView;
72         }
73     }
74 
75 }
76