Android Open Source - mitlocate Settings 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.tabs;
//from  www.jav a2 s.  co m
import org.json.JSONException;
import org.json.JSONObject;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import edu.mit.locate.MITHttpsClient;
import edu.mit.locate.R;

public class SettingsTab extends NavigationTab {
  private final String TAG = "SettingsTab";
  
  private ProgressDialog pd;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.tab_settings, container, false);

    TextView mAboutButton = (TextView) v.findViewById(R.id.settings_about);
    TextView mFeedbackButton = (TextView) v.findViewById(R.id.settings_feedback);
    TextView mSharingModeButton = (TextView) v.findViewById(R.id.settings_sharingMode);
    TextView mDeactivateButton = (TextView) v.findViewById(R.id.settings_deactivate);


    mAboutButton.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View v) {
        new AlertDialog.Builder(getActivity())
        .setIcon(android.R.drawable.ic_dialog_info)
        .setTitle("About")
        .setMessage(Html.fromHtml("<b>Marauder's App</b><br><br>Authorized user:<br>"+prefs.getString("FullName", null)+"<br>"+prefs.getString("Email", null)+"<br><br><small>Created by Aidan Bevacqua<br>Massachusetts Institute of Technology</small>"))
        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
            // User clicked OK button
          }
        }).create().show();
      }
    });

    mFeedbackButton.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View v) {
        final View feedbackView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_feedback, null);

        new AlertDialog.Builder(getActivity())
        .setView(feedbackView)
        .setIcon(android.R.drawable.ic_dialog_email)
        .setTitle("Send Feedback")
        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {}
        })
        .setPositiveButton("Send", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {
            final String message = ((EditText) feedbackView.findViewById(R.id.feedbackText)).getText().toString();
            if(message.length() > 0){
              pd = ProgressDialog.show(getActivity(), "Sending", "Please wait...");
              JSONObject params = new JSONObject();
              try {
                params.put("UUID", prefs.getString("DeviceID", null));
                params.put("message", message);
              } catch (JSONException e) {
                e.printStackTrace();
              }

              new MITHttpsClient("feedback", getActivity(), true){
                @Override
                protected void onPostExecute(JSONObject response){
                  if(response!=null && response.optBoolean("success")){
                    Toast.makeText(getActivity(), "Thanks!", Toast.LENGTH_SHORT).show();
                  } else {
                    Log.e(TAG,"Fail: "+response);
                    Toast.makeText(getActivity(), "Sending feedback failed.", Toast.LENGTH_SHORT).show();
                  }
                  pd.dismiss();
                }
              }.execute(params);
            } else {
              Toast.makeText(getActivity(), "Feedback can't be empty.", Toast.LENGTH_SHORT).show();
            }
          }
        }).create().show();
      }
    });

    mSharingModeButton.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View v) {
        final View chooseSharingModeView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_sharing_mode, null);
        AlertDialog.Builder adb = new AlertDialog.Builder(getActivity()).setView(chooseSharingModeView);

        ((RadioButton) chooseSharingModeView.findViewById(R.id.radio0)).setText(Html.fromHtml(getString(R.string.radio0)));
        ((RadioButton) chooseSharingModeView.findViewById(R.id.radio1)).setText(Html.fromHtml(getString(R.string.radio1)));
        ((RadioButton) chooseSharingModeView.findViewById(R.id.radio2)).setText(Html.fromHtml(getString(R.string.radio2)));
        //((RadioButton) chooseSharingModeView.findViewById(R.id.radio3)).setText(Html.fromHtml(getString(R.string.radio3)));
        final RadioGroup modes = (RadioGroup) chooseSharingModeView.findViewById(R.id.shareModeRadioGroup);


        switch(prefs.getInt("SharingMode",1)){
        case 0: modes.check(R.id.radio0);break;
        case 1: modes.check(R.id.radio1);break;
        case 2: modes.check(R.id.radio2);break;
        //case 3: modes.check(R.id.radio3);break;
        }

        adb.setTitle("Choose sharing mode")
        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {}

        })
        .setPositiveButton("Save", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {
            pd = ProgressDialog.show(getActivity(), "Saving", "Please wait...");
            final int index = modes.indexOfChild(chooseSharingModeView.findViewById(modes.getCheckedRadioButtonId()));

            Log.w(TAG,Integer.toString(index));
            JSONObject params = new JSONObject();
            try {
              params.put("UUID", prefs.getString("DeviceID", null));
              params.put("mode", Integer.toString(index));
            } catch (JSONException e) {
              e.printStackTrace();
            }

            new MITHttpsClient("sharing", getActivity(), true){
              @Override
              protected void onPostExecute(JSONObject response){
                if(response!=null && response.optBoolean("success")){
                  editor = prefs.edit();
                  editor.putInt("SharingMode",index).commit();
                  Toast.makeText(getActivity(),"Sharing mode updated.",Toast.LENGTH_SHORT).show();
                } else {
                  Log.e(TAG,"Fail: "+response);
                  Toast.makeText(getActivity(), "Saving sharing mode failed!", Toast.LENGTH_SHORT).show();
                }
                pd.dismiss();
              }
            }.execute(params);
          }
        }).create().show();
      }
    });

    mDeactivateButton.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View v) {
        new AlertDialog.Builder(getActivity())
        .setIcon(android.R.drawable.ic_dialog_alert)
        .setTitle("Are you sure?")
        .setMessage(Html.fromHtml("You'll need to enter a new code at <b>locate.mit.edu</b> on your computer if you decide to reactivate the app."))
        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {}

        })
        .setPositiveButton("Deactivate", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {
            pd = ProgressDialog.show(getActivity(), "Deactivating", "Please wait...");
            JSONObject params = new JSONObject();
            try {
              params.put("UUID", prefs.getString("DeviceID", null));
            } catch (JSONException e) {
              e.printStackTrace();
            }
            new MITHttpsClient("deactivate", getActivity(), true){
              @Override
              protected void onPostExecute(JSONObject response){
                if(response!=null && response.optBoolean("success")){
                  editor = prefs.edit();
                  editor.clear().commit();
                  Toast.makeText(getActivity(),"Deactivated.",Toast.LENGTH_SHORT).show();
                  getActivity().finish();
                } else {
                  Log.e(TAG,"Fail: "+response);
                  Toast.makeText(getActivity(), "Deactivation failed.", Toast.LENGTH_SHORT).show();
                }
                pd.dismiss();
              }
            }.execute(params);
          }
        }).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