Android Open Source - final_year_frontend Notification Activity






From Project

Back to project page final_year_frontend.

License

The source code is released under:

MIT License

If you think the Android project final_year_frontend 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 com.james.erebus.core;
/*  w  w w.  j ava2  s.  c  o  m*/
/**
 * The java file for the {@link com.james.erebus.core.Notification} activity screen - this screen shows all the current notifications
 * 
 */

import java.util.ArrayList;
import java.util.Arrays;

import com.james.erebus.JSONJava.JSONObject;
import com.james.erebus.misc.AppConsts;
import com.james.erebus.misc.MiscJsonHelpers;
import com.james.erebus.networking.NotificationManager;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.LinearLayout.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.support.v4.app.NavUtils;

public class NotificationActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.james.erebus.R.layout.activity_notification);
    this.setTitle("Notifications");
    // Show the Up button in the action bar.
    //getActionBar().setDisplayHomeAsUpEnabled(true);
    displayNotifications(new View(this));
  }
  
  @Override
  public void onResume()
  {
    AppConsts.currentActivity = this;
    super.onResume();
  }


  /**
   * Displays all of the {@link com.james.erebus.core.Notification notifications} on screen
   * @param v The current {@link android.view.View}
   */
  public void displayNotifications(View v)
  {
     EditText et = (EditText) findViewById(com.james.erebus.R.id.searchTextNotifications);
    ArrayList<String> searchWords = new ArrayList<String>(Arrays.asList(et.getText().toString().split(" ")));
    
    final LinearLayout notifsL = (LinearLayout) findViewById(com.james.erebus.R.id.notificationsLayout);
    ArrayList<Notification> notifications = NotificationManager.getNotifcations();
    notifsL.removeAllViews();
    for(final Notification n : notifications)
    {
      boolean notifShouldBeDisplayed = false;
      if(!searchWords.isEmpty())
      {
        for(String s : searchWords)
        {
          if(n.getText().contains(s))
          {
            notifShouldBeDisplayed = true;
          }
        }
      }
      if(!notifShouldBeDisplayed)
        continue;
      final Context c = notifsL.getContext();
      final LinearLayout notifL = new LinearLayout(c);
      final TextView tv = new TextView(c);
      tv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f));
      tv.setText(n.getText());
      final Button viewButton = new Button(c);
      viewButton.setText("View");
      viewButton.setOnClickListener(new OnClickListener()
      {

        @Override
        public void onClick(View v) {
          if(n.tournyOrMatch() == 0)
          {
            JSONObject values = MiscJsonHelpers.matchToJson(n.getMatch());
            Intent intent = new Intent(c, MatchButtonActivity.class);
            intent.putExtra("com.james.erebus.MatchButtonActivity.dataValues", values);
            startActivity(intent);
          }
          else if(n.tournyOrMatch() == 1)
          {
            JSONObject values = MiscJsonHelpers.tournamentToJson(n.getTournament());
            Intent intent = new Intent(c, TournamentButtonActivity.class);
            intent.putExtra("com.james.erebus.TournamentButtonActivity.dataValues", values);
            startActivity(intent);
          }
        }
        
      });
      final Button clearButton = new Button(c);
      clearButton.setText("Clear");
      clearButton.setOnClickListener(new OnClickListener()
      {
        @Override
        public void onClick(View v)
        {
          NotificationManager.removeNotification(n);
          notifsL.removeView(notifL);
        }
      });
      notifL.addView(tv);
      notifL.addView(clearButton);
      notifL.addView(viewButton);
      notifsL.addView(notifL, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    }
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
      // This ID represents the Home or Up button. In the case of this
      // activity, the Up button is shown. Use NavUtils to allow users
      // to navigate up one level in the application structure. For
      // more details, see the Navigation pattern on Android Design:
      //
      // http://developer.android.com/design/patterns/navigation.html#up-vs-back
      //
      NavUtils.navigateUpFromSameTask(this);
      return true;
    }
    return super.onOptionsItemSelected(item);
  }

}




Java Source Code List

com.james.erebus.GCMIntentService.java
com.james.erebus.JSONJava.CDL.java
com.james.erebus.JSONJava.CookieList.java
com.james.erebus.JSONJava.Cookie.java
com.james.erebus.JSONJava.HTTPTokener.java
com.james.erebus.JSONJava.HTTP.java
com.james.erebus.JSONJava.JSONArray.java
com.james.erebus.JSONJava.JSONException.java
com.james.erebus.JSONJava.JSONML.java
com.james.erebus.JSONJava.JSONObject.java
com.james.erebus.JSONJava.JSONString.java
com.james.erebus.JSONJava.JSONStringer.java
com.james.erebus.JSONJava.JSONTokener.java
com.james.erebus.JSONJava.JSONWriter.java
com.james.erebus.JSONJava.XMLTokener.java
com.james.erebus.JSONJava.XML.java
com.james.erebus.core.C2DMRegistrationReceiver.java
com.james.erebus.core.CustomOnItemSelectedListener.java
com.james.erebus.core.MainActivity.java
com.james.erebus.core.MatchActivity.java
com.james.erebus.core.MatchButtonActivity.java
com.james.erebus.core.MatchOptions.java
com.james.erebus.core.MatchPreferencesFragment.java
com.james.erebus.core.Match.java
com.james.erebus.core.NotificationActivity.java
com.james.erebus.core.Notification.java
com.james.erebus.core.ParentPreferencesFragment.java
com.james.erebus.core.TournamentActivity.java
com.james.erebus.core.TournamentButtonActivity.java
com.james.erebus.core.TournamentFactory.java
com.james.erebus.core.TournamentPreferencesFragment.java
com.james.erebus.core.Tournament.java
com.james.erebus.core.TournyMatchOptions.java
com.james.erebus.misc.AppConsts.java
com.james.erebus.misc.MiscJsonHelpers.java
com.james.erebus.misc.misc.java
com.james.erebus.networking.AddDeviceTask.java
com.james.erebus.networking.AddMatchSubscriptionTask.java
com.james.erebus.networking.AddTournamentSubscriptionToServerTask.java
com.james.erebus.networking.GcmRegisterDeviceTask.java
com.james.erebus.networking.GetMatchesTask.java
com.james.erebus.networking.GetTournamentsTask.java
com.james.erebus.networking.MatchRetriever.java
com.james.erebus.networking.MatchSubscriptionManager.java
com.james.erebus.networking.MiscNetworkingHelpers.java
com.james.erebus.networking.NotificationManager.java
com.james.erebus.networking.RemoveMatchSubscriptionFromServerTask.java
com.james.erebus.networking.RemoveTournamentSubscriptionFromServerTask.java
com.james.erebus.networking.Retriever.java
com.james.erebus.networking.SubscriptionManager.java
com.james.erebus.networking.SubscriptionRetriever.java
com.james.erebus.networking.TournamentRetriever.java
com.james.erebus.networking.TournamentSubscriptionManager.java