Android Open Source - Android_Yellow_Pages_App_TDD Main Activity






From Project

Back to project page Android_Yellow_Pages_App_TDD.

License

The source code is released under:

Apache License

If you think the Android project Android_Yellow_Pages_App_TDD 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.tddrampup.activities;
//w  w w  .jav  a2  s. c  o  m
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;

import com.google.inject.Inject;
import com.tddrampup.R;
import com.tddrampup.fragments.DetailFragment;
import com.tddrampup.fragments.GoogleMapFragment;
import com.tddrampup.fragments.HomeFragment;
import com.tddrampup.fragments.ListFragment;
import com.tddrampup.models.Listing;
import com.tddrampup.serviceLayers.VolleyServiceLayer;
import com.tddrampup.serviceLayers.VolleyServiceLayerCallback;
import com.tddrampup.singletons.ListingsInterface;

import java.util.List;

import roboguice.activity.RoboFragmentActivity;

public class MainActivity extends RoboFragmentActivity implements HomeFragment.onItemClickedListener, ListFragment.onListViewItemClickedListener {

    private VolleyServiceLayer volleyServiceLayer;
    private ProgressDialog mProgressDialog;

    @Inject
    ListingsInterface mListings;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        volleyServiceLayer = new VolleyServiceLayer(getApplicationContext());
        mProgressDialog = new ProgressDialog(this);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction().add(R.id.main_activity, new HomeFragment(), "MY_HOME_FRAGMENT").commit();
        }
    }

    @Override
    public void onListButtonClicked(){
        ListFragment listFragment = new ListFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.main_activity, listFragment, "MY_LIST_FRAGMENT");
        transaction.addToBackStack(null);
        transaction.commit();
    }

    @Override
    public void onMapButtonClicked(){
        GoogleMapFragment googleMapFragment = new GoogleMapFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.main_activity, googleMapFragment, "MY_GOOGLE_MAP_FRAGMENT");
        transaction.addToBackStack(null);
        transaction.commit();
    }

    @Override
    public void onSearchButtonClicked() {
        EditText whatEditText = (EditText) findViewById(R.id.what_editText);
        EditText whereEditText = (EditText) findViewById(R.id.where_editText);

        String what = whatEditText.getText().toString();
        String where = whereEditText.getText().toString();

        InputMethodManager imm = (InputMethodManager)getSystemService(
                Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow((whatEditText.isSelected() ? whatEditText : whereEditText).getWindowToken(), 0);

        if(!what.isEmpty() && !where.isEmpty()) {
            ListFragment searchFragment = new ListFragment(what, where);
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.replace(R.id.main_activity, searchFragment, "MY_SEARCH_FRAGMENT");
            transaction.addToBackStack(null);
            transaction.commit();
        } else {
            Toast.makeText(this, "Please fill in both fields!", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onListViewItemClicked(int position) {
        showLoading();
        Listing listing = mListings.getListings().get(position);
        volleyServiceLayer.volleyServiceLayerCallback = new Callback();
        volleyServiceLayer.GetListing(listing.getId());
    }

    public class Callback implements VolleyServiceLayerCallback {
        public void listCallbackCall(List<Listing> listings) {
            // do nothing
        }

        @Override
        public void itemCallbackCall(Listing listing) {
            hideLoading();
            DetailFragment detailFragment = new DetailFragment(listing);
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.replace(R.id.main_activity, detailFragment, "MY_DETAIL_FRAGMENT");
            transaction.addToBackStack(null);
            transaction.commit();
        }
    }

    private void showLoading() {
        mProgressDialog.setTitle("Loading:");
        mProgressDialog.setMessage("Fetching details...");
        mProgressDialog.show();
    }

    private void hideLoading() {
        mProgressDialog.dismiss();
    }

    public boolean isProgressDialogShowing() {
        return mProgressDialog.isShowing();
    }
}




Java Source Code List

android.UnusedStub.java
com.tddrampup.ApplicationModule.java
com.tddrampup.YellowApplication.java
com.tddrampup.activities.MainActivity.java
com.tddrampup.adapters.ListingAdapter.java
com.tddrampup.factories.CameraUpdateFactoryWrapperInterface.java
com.tddrampup.factories.CameraUpdateFactoryWrapper.java
com.tddrampup.factories.MarkerOptionsFactoryWrapperInterface.java
com.tddrampup.factories.MarkerOptionsFactoryWrapper.java
com.tddrampup.fragments.DetailFragment.java
com.tddrampup.fragments.GoogleMapFragment.java
com.tddrampup.fragments.HomeFragment.java
com.tddrampup.fragments.ListFragment.java
com.tddrampup.models.Address.java
com.tddrampup.models.GeoCode.java
com.tddrampup.models.Keywords.java
com.tddrampup.models.Listing.java
com.tddrampup.models.Phone.java
com.tddrampup.models.Products.java
com.tddrampup.models.Profile.java
com.tddrampup.models.Summary.java
com.tddrampup.models.YellowResponse.java
com.tddrampup.serviceLayers.VolleyServiceLayerCallback.java
com.tddrampup.serviceLayers.VolleyServiceLayer.java
com.tddrampup.singletons.ListingsInterface.java
com.tddrampup.singletons.Listings.java
com.tddrampup.views.MapView.java