@Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // these session managers have users input data!
    name_sex_session = new SessionManager(getApplicationContext());
    location_session = new LocationSessionManager(getApplicationContext());

    // check whethe ruser has logged in or filled details
    name_sex_session
        .checkLogin(); // if he hasnt, user will be automatically redirected to login activity
    location_session.checkLogin();

    // get user data from SessionManager : data : name and sex_age
    HashMap<String, String> user = name_sex_session.getUserDetails();
    user_name = user.get(SessionManager.KEY_NAME);
    user_sex_age = user.get(SessionManager.KEY_EMAIL);

    // get user data from LocationSessionManager : data : lat and lon
    HashMap<String, String> user_2 = location_session.getUserDetails();
    user_lat = user_2.get(LocationSessionManager.KEY_NAME);
    user_lon = user_2.get(LocationSessionManager.KEY_EMAIL);

    // Toast.makeText(MainActivity.this, "Welcome " + user_name, Toast.LENGTH_SHORT).show();

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);
    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
  }
Exemplo n.º 2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_one, container, false);

    // Get user's login data from session
    session = new SessionManager(getActivity().getApplicationContext());
    session.checkLogin();
    HashMap<String, String> user = session.getUserDetails();
    name = user.get(SessionManager.KEY_NAME);
    number = user.get(SessionManager.KEY_EMAIL);

    // Loading Font Face
    Typeface mont_reg =
        Typeface.createFromAsset(getActivity().getAssets(), "fonts/Montserrat-Regular.otf");

    // bt_ride = (Button)view.findViewById(R.id.bt_ride);
    bt_sms = (Button) view.findViewById(R.id.bt_smsHelp);
    bt_call = (Button) view.findViewById(R.id.bt_callHelp);
    bt_emerg = (Button) view.findViewById(R.id.bt_emergencyButton_one);

    bt_sms.setText("Send Help SMS to : " + number);
    bt_call.setText("Make a Call to : " + number);
    bt_emerg.setText("Emergency Numbers");

    // bt_ride.setTypeface(mont_reg);
    bt_sms.setTypeface(mont_reg);
    bt_call.setTypeface(mont_reg);
    bt_emerg.setTypeface(mont_reg);

    // Location Tracker
    gps = new GPSTracker(getActivity());

    // check if GPS enabled
    if (gps.canGetLocation()) {
      lat = gps.getLatitude();
      lon = gps.getLongitude();
    } else {
      // can't get location or GPS or Network is not enabled then Ask user to enable GPS/network in
      // settings
      // gps.showSettingsAlert();
    }

    bt_sms.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            try {
              // check if GPS enabled
              if (gps.canGetLocation()) {
              } else {
                //                        gps.showSettingsAlert();
              }

              AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());

              // Setting Dialog Title
              alertDialog.setTitle("Send Help SMS?");

              // Setting Dialog Message
              alertDialog.setMessage(
                  "\nSend SMS to "
                      + number
                      + " ?\n\n\nContent of SMS : \n\n"
                      + "Contact "
                      + name
                      + ", he/she is not in a condition to drive & needs your help to get back home from location : \'Google Maps URL of your location\' \n\n");

              alertDialog.setNegativeButton(
                  "No",
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      // Write your code here to invoke NO event
                    }
                  });

              alertDialog.setPositiveButton(
                  "Yes",
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      // Write your code here to invoke NO event

                      SmsManager smsManager_2 = SmsManager.getDefault();
                      String smsBody;
                      smsBody = "http://maps.google.com/?q=" + lat + "," + lon;
                      smsManager_2.sendTextMessage(
                          number,
                          null,
                          "Contact "
                              + name
                              + ", he/she is not in a condition to drive & needs your help to get back home from location : "
                              + smsBody,
                          null,
                          null);
                      Toast.makeText(
                              getActivity().getApplicationContext(),
                              "SMS successfully sent!",
                              Toast.LENGTH_LONG)
                          .show();
                    }
                  });

              // Showing Alert Message
              alertDialog.show();
            } catch (Exception e) {
              Toast.makeText(
                      getActivity().getApplicationContext(),
                      "SMS failed, please try again.",
                      Toast.LENGTH_LONG)
                  .show();
              e.printStackTrace();
            }
          }
        });

    bt_call.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());

            // Setting Dialog Title
            alertDialog.setTitle("Are you sure ?");

            // Setting Dialog Message
            alertDialog.setMessage("Make a call to " + number + " ?");

            alertDialog.setNegativeButton(
                "No",
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    // Write your code here to invoke NO event
                  }
                });

            alertDialog.setPositiveButton(
                "Yes",
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    // Write your code here to invoke NO event
                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:" + number));
                    startActivity(callIntent);
                  }
                });

            alertDialog.show();
          }
        });

    bt_emerg.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent i = new Intent(getActivity(), EmergencyNumbers.class);
            startActivity(i);
          }
        });

    // Inflate the layout for this fragment
    return view;
  }
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tabbed);

    session = new SessionManager(getApplicationContext());
    if (!session.checkLogin()) {
      finish();
      return;
    }

    userState = PreferenceManager.getDefaultSharedPreferences(this);
    sp = this.getSharedPreferences(userState.getString("username", "username"), 0);
    edit = sp.edit();
    alertBMI = new AlertDialog.Builder(this);
    alertQuiz = new AlertDialog.Builder(this);

    // ini typefaces
    tfGS = Typeface.createFromAsset(getAssets(), "fonts/GillSans.ttc");
    tfNV = Typeface.createFromAsset(getAssets(), "fonts/Nevis.otf");

    // textviews, progress bar, edittext ini
    expBar = (ProgressBar) findViewById(R.id.progress); // test
    level = (TextView) findViewById(R.id.currentLvl);
    experience = (TextView) findViewById(R.id.currentExp);
    BMI_fb = (TextView) findViewById(R.id.BMI_feedback);
    BMI = (TextView) findViewById(R.id.BMI_value);
    exsCmplt = (TextView) findViewById(R.id.completedExs);
    progressOf = (TextView) findViewById(R.id.text_progressOf);
    progressOf.setText("Progress of " + userState.getString("username", "username"));
    suggestion = (TextView) findViewById(R.id.text_suggestion);
    suggestion.setTypeface(tfGS);

    height = (EditText) findViewById(R.id.editHeight);
    weight = (EditText) findViewById(R.id.editWeight);
    // fback = (TextView) findViewById(R.id.feedback);--

    // layout ini
    scroll = (ScrollView) findViewById(R.id.sv_tab2);

    // buttons ini
    calculateBMI = (Button) findViewById(R.id.button_calcBMI);
    exerButton = (Button) findViewById(R.id.exButton);
    dietButton = (Button) findViewById(R.id.dButton);
    qButton = (Button) findViewById(R.id.qBtn);

    // listeners ini
    calculateBMI.setOnClickListener(this);
    exerButton.setOnClickListener(this);
    dietButton.setOnClickListener(this);
    qButton.setOnClickListener(this); // test
    BMI.setOnClickListener(this);

    // tab ini
    tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();
    TabSpec spec1 = tabHost.newTabSpec("Tab 1");
    spec1.setContent(R.id.tab1);
    spec1.setIndicator("");
    TabSpec spec2 = tabHost.newTabSpec("Tab 2");
    spec2.setIndicator("");
    spec2.setContent(R.id.tab2);
    TabSpec spec3 = tabHost.newTabSpec("Tab 3");
    spec3.setIndicator("");
    spec3.setContent(R.id.tab3);
    tabHost.addTab(spec1);
    tabHost.addTab(spec2);
    tabHost.addTab(spec3);
    intent = getIntent();
    tabHost.setCurrentTab(1);
    tabHost.setOnTabChangedListener(this);

    tess = new TabEssentials(tabHost);
    tess.alignTextInTabs();
    tess.setupTabs(
        "#000000", "#dadada", "#ffffff", 14, tabHost.getTabWidget().getChildCount(), tfNV);

    alignTextInTabs();
    loadProgressInfo();
  }