Android Open Source - taxitwin-app Leave Taxi Twin Alert Dialog Fragment






From Project

Back to project page taxitwin-app.

License

The source code is released under:

GNU General Public License

If you think the Android project taxitwin-app 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 kimle.michal.android.taxitwin.dialog.alert;
//from  w  w w .j  av  a  2 s  .  c  o  m
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import kimle.michal.android.taxitwin.R;
import kimle.michal.android.taxitwin.activity.MainActivity;
import kimle.michal.android.taxitwin.application.TaxiTwinApplication;
import kimle.michal.android.taxitwin.contentprovider.TaxiTwinContentProvider;
import kimle.michal.android.taxitwin.db.DbContract;
import kimle.michal.android.taxitwin.enumerate.UserState;
import kimle.michal.android.taxitwin.gcm.GcmHandler;

public class LeaveTaxiTwinAlertDialogFragment extends DialogFragment {

    private static final String OWNER_KEY = "owner";

    public static LeaveTaxiTwinAlertDialogFragment newInstance(boolean owner) {
        LeaveTaxiTwinAlertDialogFragment frag = new LeaveTaxiTwinAlertDialogFragment();
        Bundle args = new Bundle();
        args.putBoolean(OWNER_KEY, owner);
        frag.setArguments(args);
        return frag;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final boolean owner = getArguments().getBoolean(OWNER_KEY);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.leave_taxitwin_alert_message)
                .setTitle(R.string.leave_taxitwin_alert_title)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        GcmHandler gcmHandler = new GcmHandler(getActivity());
                        gcmHandler.leaveTaxiTwin();

                        long taxitwinId = 0;
                        String[] projection = {DbContract.DbEntry.TAXITWIN_ID_COLUMN};
                        Cursor cursor = getActivity().getContentResolver().query(TaxiTwinContentProvider.RIDES_URI, projection, null, null, null);
                        if (cursor != null && cursor.getCount() != 0) {
                            cursor.moveToFirst();
                            taxitwinId = cursor.getLong(cursor.getColumnIndexOrThrow(DbContract.DbEntry._ID));
                        }

                        if (taxitwinId != 0) {
                            if (owner) {
                                Uri uri = Uri.parse(TaxiTwinContentProvider.TAXITWINS_URI + "/" + taxitwinId);
                                getActivity().getContentResolver().delete(uri, null, null);
                            } else {
                                String[] proj = {DbContract.DbEntry.OFFER_ID_COLUMN};
                                String selection = DbContract.DbEntry.OFFER_TAXITWIN_ID_COLUMN + " = ?";
                                String[] selectionArgs = {String.valueOf(taxitwinId)};
                                Cursor c = getActivity().getContentResolver().query(TaxiTwinContentProvider.OFFERS_URI, proj, selection, selectionArgs, null);
                                if (c != null && c.getCount() != 0) {
                                    c.moveToFirst();
                                    long offerId = c.getLong(c.getColumnIndexOrThrow(DbContract.DbEntry._ID));

                                    Uri uri = Uri.parse(TaxiTwinContentProvider.OFFERS_URI + "/" + offerId);
                                    ContentValues contentValues = new ContentValues();
                                    contentValues.put(DbContract.DbEntry.OFFER_PASSENGERS_COLUMN, 0);
                                    getActivity().getContentResolver().update(uri, contentValues, null, null);
                                }
                            }
                        }

                        getActivity().getContentResolver().delete(TaxiTwinContentProvider.RIDES_URI, null, null);

                        Intent intent = new Intent(getActivity(), MainActivity.class);
                        intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
                        getActivity().startActivity(intent);
                        getActivity().finish();
                        TaxiTwinApplication.setUserState(UserState.SUBSCRIBED);
                        dismiss();
                    }
                })
                .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dismiss();
                    }
                });
        return builder.create();
    }
}




Java Source Code List

kimle.michal.android.taxitwin.activity.LauncherActivity.java
kimle.michal.android.taxitwin.activity.MainActivity.java
kimle.michal.android.taxitwin.activity.MyTaxiTwinActivity.java
kimle.michal.android.taxitwin.activity.OfferDetailActivity.java
kimle.michal.android.taxitwin.activity.ResponseDetailActivity.java
kimle.michal.android.taxitwin.activity.ResponsesActivity.java
kimle.michal.android.taxitwin.adapter.TaxiTwinPlacesAutoCompleteAdapter.java
kimle.michal.android.taxitwin.application.TaxiTwinApplication.java
kimle.michal.android.taxitwin.contentprovider.TaxiTwinContentProvider.java
kimle.michal.android.taxitwin.db.DbContract.java
kimle.michal.android.taxitwin.db.DbHelper.java
kimle.michal.android.taxitwin.dialog.alert.AddressAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.GPSAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.GooglePlayServicesAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.InternetAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.LeaveTaxiTwinAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.ServicesAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.TaxiTwinAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.TaxiTwinNoLongerAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.GooglePlayServicesErrorDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.OfferErrorDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.PlaceErrorDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.ResponseErrorDialogFragment.java
kimle.michal.android.taxitwin.entity.Place.java
kimle.michal.android.taxitwin.enumerate.UserState.java
kimle.michal.android.taxitwin.fragment.TaxiTwinListFragment.java
kimle.michal.android.taxitwin.fragment.TaxiTwinMapFragment.java
kimle.michal.android.taxitwin.gcm.GcmBroadcastReceiver.java
kimle.michal.android.taxitwin.gcm.GcmConnector.java
kimle.michal.android.taxitwin.gcm.GcmHandler.java
kimle.michal.android.taxitwin.gcm.GcmIntentService.java
kimle.michal.android.taxitwin.popup.SettingsPopup.java
kimle.michal.android.taxitwin.services.ServicesManagement.java
kimle.michal.android.taxitwin.view.TaxiTwinAutoCompleteTextView.java