com.zen.bodybuildingdiet.More.java Source code

Java tutorial

Introduction

Here is the source code for com.zen.bodybuildingdiet.More.java

Source

package com.zen.bodybuildingdiet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Calendar;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.ParseException;
import android.os.Bundle;
import android.preference.PreferenceManager;

import android.view.View;

import android.view.View.OnClickListener;
import android.widget.Button;

import android.widget.TextView;
import android.widget.Toast;

public class More extends Activity {

    Button buttonTabSummary, buttonTabDay, buttonTabWeek, buttonTabShare, buttonTabMore, buttonSendFeedback,
            buttonDietFaq, buttonWeightsFaq, buttonCardioFaq, buttonOtherFaq, buttonUpgradeToPro, buttonPrivacy,
            buttonLicense, buttonTabWelcome, buttonLogOut, buttonRateApp, buttonFoodList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.more);
        // initialize buttons
        initialize();

        addListenerButton();
    }

    void initialize() {

        buttonSendFeedback = (Button) findViewById(R.id.buttonSendFeedback);
        buttonDietFaq = (Button) findViewById(R.id.buttonDietFaq);
        buttonWeightsFaq = (Button) findViewById(R.id.buttonWeightsFaq);
        buttonCardioFaq = (Button) findViewById(R.id.buttonCardioFaq);
        buttonOtherFaq = (Button) findViewById(R.id.buttonOtherFaq);
        buttonUpgradeToPro = (Button) findViewById(R.id.buttonUpgradeToPro);
        buttonTabSummary = (Button) findViewById(R.id.buttonTabSummary);
        buttonTabDay = (Button) findViewById(R.id.buttonTabDay);
        buttonTabWeek = (Button) findViewById(R.id.buttonTabWeek);
        buttonTabShare = (Button) findViewById(R.id.buttonTabShare);
        buttonTabMore = (Button) findViewById(R.id.buttonTabMore);
        buttonPrivacy = (Button) findViewById(R.id.buttonPrivacy);
        buttonLicense = (Button) findViewById(R.id.buttonLicense);
        buttonTabWelcome = (Button) findViewById(R.id.buttonTabWelcome);
        buttonLogOut = (Button) findViewById(R.id.buttonLogOut);
        buttonRateApp = (Button) findViewById(R.id.buttonRateApp);
        buttonFoodList = (Button) findViewById(R.id.buttonFoodList);

    }

    public void addListenerButton() {

        buttonPrivacy.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, Privacy.class);
                startActivity(intent);
            }
        });

        buttonLicense.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, Terms.class);
                startActivity(intent);
            }
        });

        buttonSendFeedback.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, Feedback.class);
                startActivity(intent);
            }
        });
        buttonDietFaq.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, DietFaq.class);
                startActivity(intent);
            }
        });
        buttonWeightsFaq.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, WeightsFaq.class);
                startActivity(intent);
            }
        });
        buttonCardioFaq.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, CardioFaq.class);
                startActivity(intent);
            }
        });

        buttonOtherFaq.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, OtherFaq.class);
                startActivity(intent);
            }
        });

        buttonUpgradeToPro.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, Upgrade.class);
                startActivity(intent);
            }
        });

        buttonTabDay.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, Diet.class);
                startActivity(intent);
            }
        });

        buttonTabWeek.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                // launch intent
                Intent intent = new Intent(More.this, Week.class);
                startActivity(intent);
            }
        });

        buttonTabShare.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                // launch intent
                Intent intent = new Intent(More.this, Share.class);
                startActivity(intent);
            }
        });

        buttonTabMore.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, DietFaq.class);
                startActivity(intent);
            }
        });

        buttonTabSummary.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, InputsRecap.class);
                startActivity(intent);

            }
        });

        buttonTabWelcome.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, UserGuide.class);
                startActivity(intent);

            }
        });

        buttonLogOut.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                savePrefs("RESTARTED", false);
                Intent intent = new Intent(More.this, IntroScreen.class);
                startActivity(intent);

            }
        });

        buttonRateApp.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, RateApp.class);
                startActivity(intent);

            }
        });

        buttonFoodList.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // launch intent
                Intent intent = new Intent(More.this, FoodList.class);
                startActivity(intent);

            }
        });

    }

    private void savePrefs(String key, boolean value) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        Editor edit = sp.edit();
        edit.putBoolean(key, value);
        edit.commit();
    }

    //   public void onBackPressed() {
    //      ProgressDialog dialog = new ProgressDialog(this);
    //      if (dialog.isShowing()) {
    //         dialog.dismiss();
    //      }
    //
    //   }

    public void onStart() {
        super.onStart();
    }

    public void onRestart() {
        super.onRestart();

        setContentView(R.layout.more);
        // initialize buttons
        initialize();

        addListenerButton();
    }

    public void onResume() {
        super.onResume();

    }

    public void onPause() {
        super.onPause();
    }

    public void onStop() {
        super.onStop();
    }

    public void onDestroy() {
        super.onDestroy();
    }

    // save user's state
    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        // Save the user's current state
        // savedInstanceState.putInt(key, value);

        // Always call the superclass so it can save the view hierarchy state
        super.onSaveInstanceState(savedInstanceState);
    }

    // recover user's state using meta-data stored on InstanceState
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        // Always call the superclass so it can restore the view hierarchy
        super.onRestoreInstanceState(savedInstanceState);

        // Restore state members from saved instance
        // value = savedInstanceState.getInt(key);
    }

}