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 va2s .c o m import com.mairos.universalnotifier.R; import com.mairos.universalnotifier.model.Const; import com.mairos.universalnotifier.model.NotificationService; import com.mairos.universalnotifier.model.TasksQueue; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.Activity; import android.app.AlertDialog; import android.app.Fragment; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.os.ResultReceiver; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends Activity { private UpdateTasksListBroadcastReceiver m_readyToUpdate; private static String m_currentTasksStr = ""; public static String getPreTasksText(){ return m_currentTasksStr; } private boolean messageClosed = true; Tab m_tasksTab; Tab m_logTab; Fragment m_tasksFragmentTab = new TasksFragmentTab(); Fragment m_logFragmentTab = new LogFragmentTab(); public class UpdateTasksListBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getStringExtra(Const.DIALOG_MESSAGE) != null && messageClosed){ showDialog(intent.getStringExtra(Const.DIALOG_MESSAGE)); messageClosed = false; } else { String textF = ""; if (intent.getStringExtra(Const.TF_MESSAGE) != null){ textF = intent.getStringExtra(Const.TF_MESSAGE); } if (textF != "") m_currentTasksStr = textF /*+ TasksQueue.getInstance(context).toString()*/; ((TasksFragmentTab) m_tasksFragmentTab).setPreText(m_currentTasksStr); ((TasksFragmentTab) m_tasksFragmentTab).setTasks(TasksQueue.getInstance(context).getTasksArray()); } } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Asking for the default ActionBar element that our platform supports. ActionBar actionBar = getActionBar(); // Screen handling while hiding ActionBar icon. actionBar.setDisplayShowHomeEnabled(true); // Screen handling while hiding Actionbar title. actionBar.setDisplayShowTitleEnabled(false); // Creating ActionBar tabs. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Setting custom tab icons. m_tasksTab = actionBar.newTab().setText("Tasks"); m_logTab = actionBar.newTab().setText("Log"); // Setting tab listeners. m_tasksTab.setTabListener(new TabListener(m_tasksFragmentTab)); m_logTab.setTabListener(new TabListener(m_logFragmentTab)); // Adding tabs to the ActionBar. actionBar.addTab(m_tasksTab); actionBar.addTab(m_logTab); // update task list after MainActivity re-creation TasksQueue tq = TasksQueue.getInstance(this); ((TasksFragmentTab) m_tasksFragmentTab).setPreText(m_currentTasksStr); ((TasksFragmentTab) m_tasksFragmentTab).setTasks(tq.getTasksArray()); Intent intent = new Intent(getBaseContext(), NotificationService.class); // response from Service, which is in charge for keeping logs intent.putExtra(NotificationService.SERVICE_RESPONSE, new ResultReceiver(null) { @Override protected void onReceiveResult(int resultCode, Bundle resultData) { if (resultCode == NotificationService.UPDATE_LOG) { ((LogFragmentTab) m_logFragmentTab).setLogText(NotificationService.getCurrentLog()); } } }); // NotificationService - starts AlarmService for regularly update TasksQueue (via AlarmManagerBroadcastReceiver), // init TasksQueue and keeps logs startService(intent); } @Override protected void onPause() { getApplicationContext().unregisterReceiver(m_readyToUpdate); super.onPause(); } @Override protected void onResume() { // BroadcastReceiver registration m_readyToUpdate = new UpdateTasksListBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(Const.ACTION_SHOW_CURRENT_TASKS); getApplicationContext().registerReceiver(m_readyToUpdate, intentFilter); super.onResume(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { Intent intent = new Intent(); intent.setClass(this, SettingsActivity.class); startActivity(intent); return super.onOptionsItemSelected(item); } else if (id == R.id.action_clearLog){ NotificationService.clearLog(); ((LogFragmentTab) m_logFragmentTab).setLogText(NotificationService.getCurrentLog()); } else if (id == R.id.action_sendLog){ Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/html"); intent.putExtra(Intent.EXTRA_SUBJECT, "UniversalNotifier log"); intent.putExtra(Intent.EXTRA_TEXT, NotificationService.getCurrentLog()); startActivity(Intent.createChooser(intent, "Send Email")); } else if (id == R.id.action_updateFromFolder){ TasksQueue.getInstance(this).loadAndScheduleCurrentTasks(Const.FROM_FOLDER); } return super.onOptionsItemSelected(item); } private void showDialog(String f_message){ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Important message!") .setMessage(f_message) .setIcon(R.drawable.ic_launcher) .setCancelable(false) .setNegativeButton("??", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); messageClosed = true; Intent set_intent = new Intent(); set_intent.setClass(getBaseContext(), SettingsActivity.class); startActivity(set_intent); } }); AlertDialog alert = builder.create(); alert.show(); } }