@SuppressWarnings("NewApi") @Override protected void initLayout(View v) { mRecyclerView = (RecyclerView) v.findViewById(R.id.recyclerview); LinearLayoutManager lm = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false); mRecyclerView.setLayoutManager(lm); mAdapter = new MultiListPreferenceAdapter(); mRecyclerView.setAdapter(mAdapter); Button clearButton = (Button) v.findViewById(R.id.clear_button); clearButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mAdapter.mDataset == null) { return; } try { for (int i = 0; i < mAdapter.mDataset.size(); i++) { AppContainer item = mAdapter.mDataset.get(i); item.setChecked(false); mAdapter.mDataset.set(i, item); } mAdapter.notifyDataSetChanged(); } catch (Exception e) { Log.e(TAG, "Illegal recyclerview state: " + e.toString()); } } }); Button okButton = (Button) v.findViewById(R.id.ok_button); okButton.setTextColor(mAccentColor); okButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mListener != null) { mListener.onItemsSaved(mAdapter.getSelectedItems()); } close(); } }); mProgressBar = (ProgressBar) v.findViewById(R.id.progressbar); if (Utils.isLollipop()) { mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(mAccentColor)); } update(); }
protected void updateLayout() { if (mViewHeight == 0) { mViewHeight = (int) getResources().getDimension(R.dimen.min_listview_height); } ViewGroup.LayoutParams lp = mRecyclerView.getLayoutParams(); lp.height = Math.min( Math.min(mEntries.size(), 8) * mViewHeight, Utils.getScreenHeight(getContext()) - (mViewHeight * 2)); mRecyclerView.setLayoutParams(lp); mRecyclerView.requestLayout(); lp = mCard.getLayoutParams(); lp.height = ViewGroup.LayoutParams.WRAP_CONTENT; mCard.requestLayout(); }