/** * ORcycle, Copyright 2014, 2015, PSU Transportation, Technology, and People Lab. * * @author Robin Murray <robin5@pdx.edu> (code) * @author Miguel Figliozzi <figliozzi@pdx.edu> and ORcycle team (general app * design and features, report questionnaires and new ORcycle features) * * For more information on the project, go to * http://www.pdx.edu/transportation-lab/orcycle and http://www.pdx.edu/transportation-lab/app-development * * Updated/modified for Oregon pilot study and app deployment. * * ORcycle 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 any later version. * ORcycle 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 * ORcycle. If not, see <http://www.gnu.org/licenses/>. * */ package edu.pdx.cecs.orcycle; import android.content.Context; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; import android.widget.Toast; public class CustomToast { private final Context context; private final String message; private final int numShows; public CustomToast(Context context, String message, int numShows) { this.context = context; this.message = message; this.numShows = numShows; } public void show() { for (int i = 0; i < numShows; ++i) { makeCustomToast().show(); } } private Toast makeCustomToast() { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.toast_layout_root)); View layout = inflater.inflate(R.layout.custom_toast, null); TextView text = (TextView) layout.findViewById(R.id.custom_toast_text); text.setText(message); Toast toast = new Toast(context); toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); return toast; } }