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