Android Open Source - Android-Print-SDK Address Edit Activity






From Project

Back to project page Android-Print-SDK.

License

The source code is released under:

MIT License

If you think the Android project Android-Print-SDK 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 ly.kite.address;
// w  ww  . j a v a 2s  . co m
import android.app.Activity;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

import java.util.List;
import java.util.Locale;

import ly.kite.R;

public class AddressEditActivity extends Activity {

    public static final String EXTRA_ADDRESS = "ly.kite.EXTRA_ADDRESS";

    private Address address;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_address_edit);

        address = getIntent().getParcelableExtra(EXTRA_ADDRESS);
        if (address == null) {
            address = new Address();
            address.setCountry(Country.getInstance(Locale.getDefault()));
            setTitle(R.string.manual_add_address);
        } else {
            setTitle(R.string.title_activity_address_edit);
        }

        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment(address))
                    .commit();
        }

        // hide keyboard initially
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.address_edit, 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();
        if (id == R.id.action_save) {
            onButtonSaveClicked(null);
            return true;
        } else if (id == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void onButtonSaveClicked(View view) {
        address.setRecipientName(((EditText) findViewById(R.id.edit_text_recipient_name)).getText().toString());
        address.setLine1(((EditText) findViewById(R.id.edit_text_address_line1)).getText().toString());
        address.setLine2(((EditText) findViewById(R.id.edit_text_address_line2)).getText().toString());
        address.setCity(((EditText) findViewById(R.id.edit_text_address_city)).getText().toString());
        address.setStateOrCounty(((EditText) findViewById(R.id.edit_text_address_county)).getText().toString());
        address.setZipOrPostalCode(((EditText) findViewById(R.id.edit_text_address_postcode)).getText().toString());

        Intent output = new Intent();
        output.putExtra(EXTRA_ADDRESS, (Parcelable) address);
        setResult(RESULT_OK, output);
        finish();
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        private final Address address;

        public PlaceholderFragment(Address address) {
            this.address = address;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_address_edit, container, false);
            return rootView;
        }

        @Override
        public void onViewCreated(View view, Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);

            ((EditText) view.findViewById(R.id.edit_text_recipient_name)).setText(address.getRecipientName());
            ((EditText) view.findViewById(R.id.edit_text_address_line1)).setText(address.getLine1());
            ((EditText) view.findViewById(R.id.edit_text_address_line2)).setText(address.getLine2());
            ((EditText) view.findViewById(R.id.edit_text_address_city)).setText(address.getCity());
            ((EditText) view.findViewById(R.id.edit_text_address_county)).setText(address.getStateOrCounty());
            ((EditText) view.findViewById(R.id.edit_text_address_postcode)).setText(address.getZipOrPostalCode());

            final List<Country> countries = Country.COUNTRIES;
            int selected = countries.indexOf(address.getCountry());
            Spinner spinner = (Spinner) view.findViewById(R.id.spinner_country);
            spinner.setAdapter(new ArrayAdapter<Country>(getActivity(), android.R.layout.simple_spinner_dropdown_item, countries));
            spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int position, long i) {
                    if (i >= 0 && i < countries.size()) {
                        Country c = countries.get((int) i);
                        address.setCountry(c);
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> adapterView) {}
            });

            spinner.setSelection(selected);
        }
    }

}




Java Source Code List

co.oceanlabs.sample.MainActivity.java
ly.kite.address.AddressBookActivity.java
ly.kite.address.AddressEditActivity.java
ly.kite.address.AddressSearchActivity.java
ly.kite.address.AddressSearchRequestListener.java
ly.kite.address.AddressSearchRequest.java
ly.kite.address.Address.java
ly.kite.address.Country.java
ly.kite.checkout.CheckoutActivity.java
ly.kite.checkout.OrderReceiptActivity.java
ly.kite.checkout.PaymentActivity.java
ly.kite.checkout.PrintOrderSummaryListAdapter.java
ly.kite.payment.CheckPromoCodeRequestListener.java
ly.kite.payment.CheckPromoRequest.java
ly.kite.payment.PayPalCardChargeListener.java
ly.kite.payment.PayPalCardVaultStorageListener.java
ly.kite.payment.PayPalCard.java
ly.kite.print.ApplyPromoCodeListener.java
ly.kite.print.AssetGetBytesLengthListener.java
ly.kite.print.AssetGetBytesListener.java
ly.kite.print.AssetUploadRequestListener.java
ly.kite.print.AssetUploadRequest.java
ly.kite.print.Asset.java
ly.kite.print.BaseRequest.java
ly.kite.print.KitePrintSDKException.java
ly.kite.print.KitePrintSDK.java
ly.kite.print.PrintJob.java
ly.kite.print.PrintOrderSubmissionListener.java
ly.kite.print.PrintOrder.java
ly.kite.print.PrintsPrintJob.java
ly.kite.print.ProductType.java
ly.kite.print.SubmitPrintOrderRequestListener.java
ly.kite.print.SubmitPrintOrderRequest.java