Back to project page Android-Universal-Notifier.
The source code is released under:
Apache License
If you think the Android project Android-Universal-Notifier listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mairos.universalnotifier.UI; //from w w w.j a v a 2 s.c o m import com.mairos.universalnotifier.R; import com.mairos.universalnotifier.model.NotificationTask; import com.mairos.universalnotifier.model.TasksQueue; import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.Fragment; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; public class TasksFragmentTab extends Fragment { View m_rootView = null; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { m_rootView = inflater.inflate(R.layout.tasks_layout, container, false); EditText et = (EditText) m_rootView.findViewById(R.id.editText); et.setKeyListener(null); setPreText(MainActivity.getPreTasksText()); setTasks(TasksQueue.getInstance(getActivity()).getTasksArray()); return m_rootView; } @Override public void onResume() { setPreText(MainActivity.getPreTasksText()); super.onResume(); } public void setPreText(String m_currentTasksStr) { if (m_rootView != null){ EditText et = (EditText) m_rootView.findViewById(R.id.editText); et.setText(m_currentTasksStr); } } public void setTasks(NotificationTask[] f_nt_array){ if (m_rootView != null){ ListView menu = (ListView) m_rootView.findViewById(R.id.tasksList); if (f_nt_array != null && this.isAdded()) { TasksArrayAdapter menu_adapter = new TasksArrayAdapter(getActivity(), f_nt_array); menu.setAdapter(menu_adapter); } else menu.setAdapter(null); } } public class TasksArrayAdapter extends ArrayAdapter<NotificationTask> { private final Context m_context; private final NotificationTask[] m_taskinfo; public TasksArrayAdapter(Context f_context, NotificationTask[] f_taskinfo) { super(f_context, R.layout.task_info_layout, f_taskinfo); m_context = f_context; m_taskinfo = f_taskinfo; } @SuppressLint("ViewHolder") @Override public View getView(int position, View convertView, ViewGroup parent) { NotificationTask currentTask = m_taskinfo[position]; LayoutInflater inflater = (LayoutInflater) m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.task_info_layout, parent, false); TextView textView1 = (TextView) rowView.findViewById(R.id.taskDescription); textView1.setText(currentTask.getName()); TextView textView2 = (TextView) rowView.findViewById(R.id.taskExecTime); String nextTime; if (currentTask.isScheduled()){ if (!currentTask.getRepeatable()) nextTime = currentTask.getStartTime().toString(); else nextTime = TasksQueue.getNearestTime(currentTask.getStartTime(), currentTask.getInterval()).toString(); } else { nextTime = "passed"; } textView2.setText("Next launch: " + nextTime); Button infoButton = (Button) rowView.findViewById(R.id.butInfo); infoButton.setTag(currentTask); infoButton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { Intent intent = new Intent(getActivity().getApplicationContext(), TaskInfoActivity.class); NotificationTask ti = (NotificationTask) v.getTag(); intent.putExtra("taskDescription", ti.toString()); startActivity(intent); } }); Button startButton = (Button) rowView.findViewById(R.id.butExec); startButton.setTag(currentTask); startButton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { NotificationTask ti = (NotificationTask) v.getTag(); TasksQueue.getInstance(getActivity()).executeTask(ti.getName()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("note"); builder.setMessage("task '" + ti.getName() + "' executed! Show log for details"); builder.setCancelable(true); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show(); } }); return rowView; } } }