Android Open Source - FishApp Vendor Activity






From Project

Back to project page FishApp.

License

The source code is released under:

Apache License

If you think the Android project FishApp 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.tschuy.fishapp;
//  w w w  . java  2s  .  c o m
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.MarkerOptions;

import java.util.Iterator;
import java.util.Locale;


public class VendorActivity extends Activity implements VendorProductListFragment.OnFragmentInteractionListener {

    Vendor vendor;

    MapFragment map_fragment;
    VendorProductListFragment list;
    GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vendor);
        Bundle b = getIntent().getExtras();
        vendor = b.getParcelable("com.tschuy.materialtest.Vendor");

        list = new VendorProductListFragment();
        getFragmentManager().beginTransaction()
                .replace(R.id.contentFrame, list).commit();
        getFragmentManager().executePendingTransactions();

        map_fragment = (MapFragment) getFragmentManager().findFragmentById(R.id.vendor_map);
        map = map_fragment.getMap();

        map.addMarker(new MarkerOptions().position(vendor.location).title(vendor.name)).getId();
        CameraUpdate center=
                CameraUpdateFactory.newLatLng(vendor.location);
        CameraUpdate zoom=CameraUpdateFactory.zoomTo(13);

        map.moveCamera(center);
        map.animateCamera(zoom);

        setTitle(vendor.name);
        ((TextView) findViewById(R.id.vendor_description)).setText(vendor.description);

        if("".equals(vendor.contact_name)) {
            findViewById(R.id.contact_name).setVisibility(View.GONE);
            findViewById(R.id.contact_name_label).setVisibility(View.GONE);

        } else {
            ((TextView) findViewById(R.id.contact_name)).setText(vendor.contact_name);
        }

        if("".equals(vendor.email)) {
            findViewById(R.id.email).setVisibility(View.GONE);
            findViewById(R.id.email_label).setVisibility(View.GONE);
        } else {
            ((TextView) findViewById(R.id.email)).setText(vendor.email);
        }

        StringBuilder address = new StringBuilder(5);
        address.append(vendor.city).append(", ").append(vendor.state).append(" ").append(vendor.zip);
        ((TextView) findViewById(R.id.street_address)).setText(vendor.street);

        ((TextView) findViewById(R.id.rest_address)).setText(address.toString());

        if("".equals(vendor.location_description)) {
            findViewById(R.id.location_description).setVisibility(View.GONE);
        } else {
            ((TextView) findViewById(R.id.location_description)).setText(vendor.location_description);
        }

        ImageButton navigation = (ImageButton) findViewById(R.id.map_button);
        navigation.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                String encoded_string = String.format(Locale.ENGLISH, "%s, %s %s %s", vendor.street, vendor.city, vendor.state, vendor.zip);
                String uri = String.format(Locale.ENGLISH, "geo:0,0f?q=%s",
                        encoded_string);
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                startActivity(intent);
            }
        });

        Iterator<VendorProduct> product_iterator = vendor.products.iterator();
        while(product_iterator.hasNext()) {
            list.addItem(product_iterator.next());
        }
    }

    @Override
    public void onFragmentInteractionVP(VendorProduct vp)
    {
        return;
    }

    public void vpClicked(VendorProduct vp) {
        Intent i = new Intent(this, ProductActivity.class);
        i.putExtra("product_key", vp.product_id);
        startActivity(i);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_vendor, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}




Java Source Code List

com.tschuy.fishapp.ApplicationTest.java
com.tschuy.fishapp.MainActivity.java
com.tschuy.fishapp.NavigationDrawerFragment.java
com.tschuy.fishapp.ProductActivity.java
com.tschuy.fishapp.Product.java
com.tschuy.fishapp.Utils.java
com.tschuy.fishapp.VendorActivity.java
com.tschuy.fishapp.VendorListFragment.java
com.tschuy.fishapp.VendorProductListFragment.java
com.tschuy.fishapp.Vendor.java