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