Android Open Source - sana Notification Viewer






From Project

Back to project page sana.

License

The source code is released under:

Copyright (c) 2010, Moca All rights reserved. The source code for Moca is licensed under the BSD license as follows: Redistribution and use in source and binary forms, with or without modification, ...

If you think the Android project sana listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.moca.activity;
//from   ww  w. j a va 2s.co m
import org.moca.db.MocaDB.NotificationSQLFormat;

import android.app.Activity;
import android.app.NotificationManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * NotificationViewer builds the interface for viewing a single received notification. This 
 * displays the diagnosis, pertaining patient, and allows the user to dismiss the notification 
 * if desired.
 */
public class NotificationViewer extends Activity implements OnClickListener {
  
  private static String TAG = NotificationViewer.class.toString();

  private static final String[] PROJECTION = new String[] { NotificationSQLFormat._ID,
      NotificationSQLFormat.PROCEDURE_ID, NotificationSQLFormat.PATIENT_ID, NotificationSQLFormat.FULL_MESSAGE};
  
  private Button dismiss, save;
  
  private Uri notification;
  
  public void onCreate(Bundle instance) {
        super.onCreate(instance);
        notification = getIntent().getData();
        
        Cursor cursor = managedQuery(getIntent().getData(), PROJECTION, null,
                null, NotificationSQLFormat.DEFAULT_SORT_ORDER);
        
        cursor.moveToFirst();
        String procedureIdentifier = cursor.getString(cursor.getColumnIndex(NotificationSQLFormat.PROCEDURE_ID));
        String patientId = cursor.getString(cursor.getColumnIndex(NotificationSQLFormat.PATIENT_ID));
        String message = cursor.getString(cursor.getColumnIndex(NotificationSQLFormat.FULL_MESSAGE));
        cursor.close();
        /*
        cursor = managedQuery(SavedProcedureSQLFormat.CONTENT_URI, new String[] {SavedProcedureSQLFormat._ID, SavedProcedureSQLFormat.PROCEDURE_ID, SavedProcedureSQLFormat.PROCEDURE_STATE},
            SavedProcedureSQLFormat.GUID + " = ?",
            new String[] { procedureIdentifier }, null);
        
        if(cursor.getCount() == 0) {
          // doh
          
        }
        cursor.moveToFirst();
        int spId = cursor.getInt(0);
        int procedureId = cursor.getInt(1);
        String answers = cursor.getString(2);
        cursor.close();
        Uri savedUri = ContentUris.withAppendedId(SavedProcedureSQLFormat.CONTENT_URI, spId);
        
        Uri procedureUri = ContentUris.withAppendedId(ProcedureSQLFormat.CONTENT_URI, procedureId);
        Log.i(TAG, "Getting procedure " + procedureUri.toString());
        cursor = getContentResolver().query(procedureUri, new String[] { ProcedureSQLFormat.PROCEDURE }, null, null, null);
        cursor.moveToFirst();
        String procedureXml = cursor.getString(0);
        cursor.deactivate();
        
        Map<String, Map<String,String>> questionsAnswers = new HashMap<String, Map<String,String>>();
        try{
          Procedure p = Procedure.fromXMLString(procedureXml);
          p.setInstanceUri(savedUri);
          
          JSONTokener tokener = new JSONTokener(answers);
          JSONObject answersDict = new JSONObject(tokener);
  
          Map<String,String> answersMap = new HashMap<String,String>();
          Iterator it = answersDict.keys();
          while(it.hasNext()) {
            String key = (String)it.next();
            answersMap.put(key, answersDict.getString(key));
            Log.i(TAG, "onCreate() : answer '" + key + "' : '" + answersDict.getString(key) +"'");
          }
          Log.i(TAG, "onCreate() : restoreAnswers");
          p.restoreAnswers(answersMap);
          questionsAnswers = p.toQAMap();
        } catch(ProcedureParseException e) {
          
        } catch(JSONException e) {
          
        } catch (IOException e) {

    } catch (ParserConfigurationException e) {

    } catch (SAXException e) {

    }
        */
        LinearLayout notifView = new LinearLayout(this);
        notifView.setOrientation(LinearLayout.VERTICAL);
        TextView tv1 = new TextView(this);
        tv1.setText("Diagnosis for Patient " + patientId);
        tv1.setTextAppearance(this, android.R.style.TextAppearance_Large);
        tv1.setGravity(Gravity.CENTER_HORIZONTAL);
        TextView tv2 = new TextView(this);
        tv2.setText("");
        tv2.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        TextView tv4 = new TextView(this);
        tv4.setText("");
        tv4.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        TextView tv3 = new TextView(this);
        tv3.setText(message);
        tv3.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        dismiss = new Button(this);
        dismiss.setText("Dismiss");
        dismiss.setOnClickListener(this);
        save = new Button(this);
        save.setText("Save");
        save.setOnClickListener(this);
        LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.HORIZONTAL);      
        ll.addView(dismiss,new LinearLayout.LayoutParams(-2,-1, 0.5f));
        ll.addView(save,new LinearLayout.LayoutParams(-2,-1, 0.5f));
        notifView.setWeightSum(1.0f);
        ll.setGravity(Gravity.BOTTOM);
        notifView.addView(tv1);
        notifView.addView(tv2);
        notifView.addView(tv3);
        notifView.addView(tv4);
        notifView.addView(ll);
        this.setContentView(notifView);
  }

  /**
   * If a user elects to dismiss the notification, the status bar will be cleared of ALL 
   * notification alerts. This employs a "only the latest notification in status bar" policy.
   */
  public void onClick(View v) {
    if (v == dismiss) {
      this.getContentResolver().delete(notification, null, null);
      ((NotificationManager)this.getSystemService(NOTIFICATION_SERVICE)).cancelAll();
      this.finish();
    } else if (v == save) {
      ((NotificationManager)this.getSystemService(NOTIFICATION_SERVICE)).cancelAll();
      this.finish();
    }
  }
}




Java Source Code List

.Moca.java
org.moca.Constants.java
org.moca.ImagePreviewDialog.java
org.moca.ScalingImageAdapter.java
org.moca.SelectableImageView.java
org.moca.activity.NotificationList.java
org.moca.activity.NotificationViewer.java
org.moca.activity.PatientInfoDialog.java
org.moca.activity.ProcedureRunner.java
org.moca.activity.ProceduresList.java
org.moca.activity.SavedProcedureList.java
org.moca.activity.Settings.java
org.moca.db.EncounterDAO.java
org.moca.db.EventDAO.java
org.moca.db.EventProvider.java
org.moca.db.Event.java
org.moca.db.ImageProvider.java
org.moca.db.MocaDB.java
org.moca.db.NotificationMessage.java
org.moca.db.NotificationProvider.java
org.moca.db.PatientInfo.java
org.moca.db.PatientProvider.java
org.moca.db.PatientValidator.java
org.moca.db.ProcedureDAO.java
org.moca.db.ProcedureProvider.java
org.moca.db.SavedProcedureProvider.java
org.moca.db.SoundProvider.java
org.moca.media.AudioPlayer.java
org.moca.net.MDSCode.java
org.moca.net.MDSInterface.java
org.moca.net.MDSNotification.java
org.moca.net.MDSResult.java
org.moca.net.SMSReceive.java
org.moca.procedure.BinaryUploadElement.java
org.moca.procedure.DateElement.java
org.moca.procedure.GpsElement.java
org.moca.procedure.MultiSelectElement.java
org.moca.procedure.PatientIdElement.java
org.moca.procedure.PictureElement.java
org.moca.procedure.ProcedureElement.java
org.moca.procedure.ProcedurePage.java
org.moca.procedure.ProcedureParseException.java
org.moca.procedure.Procedure.java
org.moca.procedure.RadioElement.java
org.moca.procedure.SelectElement.java
org.moca.procedure.SoundElement.java
org.moca.procedure.TextElement.java
org.moca.procedure.TextEntryElement.java
org.moca.procedure.ValidationError.java
org.moca.procedure.branching.Criteria.java
org.moca.procedure.branching.Criterion.java
org.moca.procedure.branching.LogicAnd.java
org.moca.procedure.branching.LogicBase.java
org.moca.procedure.branching.LogicNot.java
org.moca.procedure.branching.LogicOr.java
org.moca.service.BackgroundUploader.java
org.moca.service.QueueManager.java
org.moca.service.ServiceConnector.java
org.moca.service.ServiceListener.java
org.moca.task.CheckCredentialsTask.java
org.moca.task.ImageProcessingTaskRequest.java
org.moca.task.ImageProcessingTask.java
org.moca.task.MDSSyncTask.java
org.moca.task.PatientLookupListener.java
org.moca.task.PatientLookupTask.java
org.moca.task.ResetDatabaseTask.java
org.moca.task.ValidationListener.java
org.moca.util.MocaUtil.java
org.moca.util.UserDatabase.java