Android Open Source - mitlocate Alerts Tab






From Project

Back to project page mitlocate.

License

The source code is released under:

MIT License

If you think the Android project mitlocate 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 edu.mit.locate.alerts;
/*  w ww.  jav  a2  s . c  o m*/
import java.util.ArrayList;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import edu.mit.locate.R;
import edu.mit.locate.tabs.NavigationTab;

public class AlertsTab extends NavigationTab {
    private final String TAG = "AlertsTab";
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.tab_alerts, container, false);
        
        //TODO: move this to onSuccess of an HttpRequest fetching friends, or broadcastreceiver
        
        final ListView lv = (ListView) v.findViewById(R.id.alertsList);
        ArrayList<Alert> friends = new ArrayList<Alert>();
        
        String serverData =
        "8,Andre Aboulian,Simmons Hall,leaves;" +
        "6,Christina Curlette,Simmons Hall,enters;" +
        "2,Luis Hong Sanchez,MIT Shuttle 1200,enters;" +
        "5,Tyler Hallada,Sidney Pacific - Room 846B,enters";
        String[] alertsList = serverData.split(";");

        for(String alert : alertsList){
            String[] alertData=alert.split(",", -1);
            Alert sr = new Alert();
            sr.setID(alertData[0]);
            sr.setName(alertData[1]);
            sr.setLocation(alertData[2]);
            sr.setType(alertData[3]);
            friends.add(sr);
        }
        lv.setAdapter(new AlertsListAdapter(getActivity().getApplicationContext(), friends));

        TextView mInviteButton = (TextView) v.findViewById(R.id.newAlertButton);
        mInviteButton.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {
                View newAlertView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_new_alert, null);
                new AlertDialog.Builder(getActivity())
                .setView(newAlertView)
                .setIcon(android.R.drawable.ic_dialog_email)
                .setTitle("Invite Friends")
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // User cancelled the dialog
                    }

                })
                .setPositiveButton("Set", new DialogInterface.OnClickListener() {
                  @Override
                    public void onClick(DialogInterface dialog, int id) {
                        SharedPreferences prefs = getActivity().getSharedPreferences("MITLOCATE", 0);
                        String installID = prefs.getString("InstallID", null);
                        //RequestParams params = new RequestParams();
                        Dialog d = (Dialog) dialog;
                        String username = ((EditText) d.findViewById(R.id.username)).getText().toString();
                        if(!username.equals("")){
//                            params.put("UUID",installID);
//                            params.put("username",username);
//                            MITHttpsClient.post("alerts/", params, new AsyncHttpResponseHandler() {
//                                @Override
//                                public void onSuccess(String response) {
//                                    if(response.equals("OK")){
//                                        if(getActivity() != null)
//                                            Toast.makeText(getActivity(), "Invite sent!", Toast.LENGTH_SHORT).show();
//                                    } else {
//                                        if(getActivity() != null)
//                                            Toast.makeText(getActivity(), "Server error!", Toast.LENGTH_SHORT).show();
//                                    }
//                                }
//
//                                @Override
//                                public void onFailure(Throwable e, String response) {
//                                    Toast.makeText(getActivity(), "Invite failed!", Toast.LENGTH_SHORT).show();
//                                }
//                            });
                        } else {
                            Toast.makeText(getActivity(), "No username entered", Toast.LENGTH_SHORT).show();
                        }
                    }
                }).create().show();
            }
        });
        return v;
    }
}




Java Source Code List

edu.mit.locate.APEditorActivity.java
edu.mit.locate.BootLocationService.java
edu.mit.locate.LoginActivity.java
edu.mit.locate.MITHttpsClient.java
edu.mit.locate.MITLocationService.java
edu.mit.locate.MainActivity.java
edu.mit.locate.alerts.Alert.java
edu.mit.locate.alerts.AlertsListAdapter.java
edu.mit.locate.alerts.AlertsTab.java
edu.mit.locate.apeditor.APListAdapter.java
edu.mit.locate.apeditor.APScanResult.java
edu.mit.locate.friends.FriendActivity.java
edu.mit.locate.friends.Friend.java
edu.mit.locate.friends.FriendsListAdapter.java
edu.mit.locate.friends.FriendsTab.java
edu.mit.locate.tabs.IconPagerAdapter.java
edu.mit.locate.tabs.IcsLinearLayout.java
edu.mit.locate.tabs.NavigationTab.java
edu.mit.locate.tabs.PageIndicator.java
edu.mit.locate.tabs.SearchTab.java
edu.mit.locate.tabs.SettingsTab.java
edu.mit.locate.tabs.TabPageIndicator.java
edu.mit.locate.tabs.TabPagerAdapter.java