/* Swisscom Safe Connect Copyright (C) 2015 Swisscom This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.swisscom.safeconnect.view; import android.content.Context; import android.preference.Preference; import android.preference.PreferenceScreen; import android.support.v7.widget.Toolbar; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.swisscom.safeconnect.R; public class ToolbarPreference extends Preference { protected TextView tvTitle; private ImageView imgBackBtn; private View actionBarView; private ImageView imgNova; private View.OnClickListener listener; public ToolbarPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected View onCreateView(ViewGroup parent) { parent.setPadding(0, 0, 0, 0); LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.settings_toolbar, parent, false); Toolbar toolbar = (Toolbar) layout.findViewById(R.id.toolbar); actionBarView = inflater.inflate(R.layout.actionbar, null); TextView tvTitle = (TextView) actionBarView.findViewById(R.id.tv_title); tvTitle.setText(getTitle()); imgBackBtn = (ImageView) actionBarView.findViewById(R.id.img_back_btn); imgNova = (ImageView) actionBarView.findViewById(R.id.img_nova); imgNova.setVisibility(View.GONE); if (listener != null) { actionBarView.setOnClickListener(listener); } else { actionBarView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PreferenceScreen prefScreen = (PreferenceScreen) getPreferenceManager().findPreference(getKey()); prefScreen.getDialog().dismiss(); } }); } Toolbar.LayoutParams layoutParams = new Toolbar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); toolbar.addView(actionBarView, layoutParams); return layout; } public void setOnClickListener(View.OnClickListener listener) { this.listener = listener; if (actionBarView != null) { actionBarView.setOnClickListener(listener); } } }