Example usage for android.app AlertDialog.Builder setCancelable

List of usage examples for android.app AlertDialog.Builder setCancelable

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setCancelable.

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:jp.watnow.plugins.dialog.Notification.java

/**
 * //from  ww w.j  a  v  a 2  s  .  com
 * @param message
 * @param title
 * @param buttonLabels
 * @param defaultTexts
 * @param callbackContext
 */
public synchronized void login(final String title, final String message, final JSONArray buttonLabels,
        final JSONArray defaultTexts, final CallbackContext callbackContext) {

    final CordovaInterface cordova = this.cordova;

    Runnable runnable = new Runnable() {
        public void run() {
            LinearLayout layout = new LinearLayout(cordova.getActivity());
            layout.setOrientation(LinearLayout.VERTICAL);
            layout.setPadding(10, 0, 10, 0);
            final EditText usernameInput = new EditText(cordova.getActivity());
            usernameInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
            final EditText passwordInput = new EditText(cordova.getActivity());
            passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            try {
                usernameInput.setHint("ID");
                usernameInput.setText(defaultTexts.getString(0));
                passwordInput.setHint("PASSWORD");
                passwordInput.setText(defaultTexts.getString(1));
            } catch (JSONException e1) {
            }

            layout.addView(usernameInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            layout.addView(passwordInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));

            AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);

            dlg.setView(layout);

            final JSONObject result = new JSONObject();

            try {
                dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        try {
                            result.put("buttonIndex", 1);
                            result.put("input1", usernameInput.getText());
                            result.put("input2", passwordInput.getText());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                    }
                });
            } catch (JSONException e) {
            }

            try {
                dlg.setPositiveButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        try {
                            result.put("buttonIndex", 3);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                    }
                });
            } catch (JSONException e) {
            }

            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    try {
                        result.put("buttonIndex", 0);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                }
            });

            changeTextDirection(dlg);
        };
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.nks.nksmod.otaupdater.OTAUpdaterActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Context context = getApplicationContext();
    cfg = Config.getInstance(context);//from  w ww. j a  va 2s  .  c  om
    final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 0;

    if (ContextCompat.checkSelfPermission(OTAUpdaterActivity.this,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        if (ActivityCompat.shouldShowRequestPermissionRationale(OTAUpdaterActivity.this,
                android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.alert_permission_storage);
            builder.setMessage(R.string.alert_permission_storage_message);
            builder.setCancelable(false);
            builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    finish();
                }
            });
            builder.setNeutralButton(R.string.enable_permission, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    ActivityCompat.requestPermissions(OTAUpdaterActivity.this,
                            new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE },
                            MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
                }
            });

            final AlertDialog dlg = builder.create();

            dlg.setOnShowListener(new DialogInterface.OnShowListener() {
                @Override
                public void onShow(DialogInterface dialog) {
                    onDialogShown(dlg);
                }
            });
            dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    onDialogClosed(dlg);
                }
            });
            dlg.show();

        } else {
            ActivityCompat.requestPermissions(OTAUpdaterActivity.this,
                    new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);

            if (ActivityCompat.shouldShowRequestPermissionRationale(OTAUpdaterActivity.this,
                    android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle(R.string.alert_permission_storage);
                builder.setMessage(R.string.alert_permission_storage_message);
                builder.setCancelable(false);
                builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        finish();
                    }
                });

                final AlertDialog dlg = builder.create();

                dlg.setOnShowListener(new DialogInterface.OnShowListener() {
                    @Override
                    public void onShow(DialogInterface dialog) {
                        onDialogShown(dlg);
                    }
                });
                dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        onDialogClosed(dlg);
                    }
                });
                dlg.show();

            }
        }
    }

    boolean data = Utils.dataAvailable(this);
    boolean wifi = Utils.wifiConnected(this);

    if (!data || !wifi) {
        final boolean nodata = !data && !wifi;

        if ((nodata && !cfg.getIgnoredDataWarn()) || (!nodata && !cfg.getIgnoredWifiWarn())) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(nodata ? R.string.alert_nodata_title : R.string.alert_nowifi_title);
            builder.setMessage(nodata ? R.string.alert_nodata_message : R.string.alert_nowifi_message);
            builder.setCancelable(false);
            builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    finish();
                }
            });
            builder.setNeutralButton(R.string.alert_wifi_settings, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    Intent i = new Intent(Settings.ACTION_WIFI_SETTINGS);
                    startActivity(i);
                }
            });
            builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (nodata) {
                        cfg.setIgnoredDataWarn(true);
                    } else {
                        cfg.setIgnoredWifiWarn(true);
                    }
                    dialog.dismiss();
                }
            });

            final AlertDialog dlg = builder.create();

            dlg.setOnShowListener(new DialogInterface.OnShowListener() {
                @Override
                public void onShow(DialogInterface dialog) {
                    onDialogShown(dlg);
                }
            });
            dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    onDialogClosed(dlg);
                }
            });
            dlg.show();
        }
    }

    Utils.updateDeviceRegistration(this);
    CheckinReceiver.setDailyAlarm(this);

    setContentView(R.layout.main);
    ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);

    bar = getActionBar();
    assert bar != null;

    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
    bar.setTitle(R.string.app_name);

    TabsAdapter mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.main_about), AboutTab.class);

    ActionBar.Tab romTab = bar.newTab().setText(R.string.main_rom);
    if (cfg.hasStoredRomUpdate())
        romTab.setIcon(R.drawable.ic_action_warning);
    romTabIdx = mTabsAdapter.addTab(romTab, ROMTab.class);

    /* ActionBar.Tab kernelTab = bar.newTab().setText(R.string.main_kernel);
    if (cfg.hasStoredKernelUpdate()) kernelTab.setIcon(R.drawable.ic_action_warning);
    kernelTabIdx = mTabsAdapter.addTab(kernelTab, KernelTab.class); */

    if (!handleNotifAction(getIntent())) {
        if (cfg.hasStoredRomUpdate() && !cfg.isDownloadingRom()) {
            cfg.getStoredRomUpdate().showUpdateNotif(this);
        }

        /* if (cfg.hasStoredKernelUpdate() && !cfg.isDownloadingKernel()) {
        cfg.getStoredKernelUpdate().showUpdateNotif(this);
        } */

        if (savedInstanceState != null) {
            bar.setSelectedNavigationItem(savedInstanceState.getInt(KEY_TAB, 0));
        }
    }
}

From source file:com.remobile.dialogs.Notification.java

/**
 * Builds and shows a native Android alert with given Strings
 *
 * @param message         The message the alert should display
 * @param title           The title of the alert
 * @param buttonLabel     The label of the button
 * @param callbackContext The callback context
 *///from   w w w . j a v a  2s .com
public synchronized void alert(final String message, final String title, final String buttonLabel,
        final CallbackContext callbackContext) {
    Runnable runnable = new Runnable() {
        public void run() {

            AlertDialog.Builder dlg = createDialog(); // new AlertDialog.Builder(this.cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);
            dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });
            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });

            changeTextDirection(dlg);
        }

        ;
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:cl.smartcities.isci.transportinspector.dialogs.BusSelectionDialog.java

@NonNull
@Override/*from  w w w .  j av a 2  s  .  com*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

    LayoutInflater inflater = this.getActivity().getLayoutInflater();
    final View dialog_view = inflater.inflate(R.layout.bus_selection_dialog, null);
    final Typeface iconTypeface = Typeface.createFromAsset(this.getContext().getAssets(),
            getActivity().getString(R.string.icon_font));
    ((TextView) dialog_view.findViewById(R.id.suggestion_icon)).setTypeface(iconTypeface);

    builder.setView(dialog_view);
    builder.setCancelable(false);
    dialog = builder.create();

    final Bundle bundle = getArguments();
    ArrayList<Bus> buses = null;

    if (bundle != null) {
        buses = bundle.getParcelableArrayList(NotificationState.BUSES);
    }

    if (buses != null && !buses.isEmpty()) {
        dialog_view.findViewById(R.id.list_view).setVisibility(View.VISIBLE);
        setBusMap(buses);
        ArrayList<String> serviceList = new ArrayList<>();
        serviceList.addAll(this.busMap.keySet());
        BusSelectionAdapter adapter = new BusSelectionAdapter(this.getContext(), serviceList, busMap,
                new BusSelectionAdapter.ListViewAdapterListener() {
                    @Override
                    public void onPositiveClick(Bus bus) {
                        dialog.cancel();
                        listener.onPositiveClick(bus);
                    }

                    @Override
                    public void onNegativeClick() {
                        dialog.cancel();
                        listener.onNegativeClick();
                    }
                });
        ListView listView = (ListView) dialog_view.findViewById(R.id.list_view);

        listView.setAdapter(adapter);

        if (adapter.getCount() > VISIBLE_BUSES) {
            View item = adapter.getView(0, null, listView);
            item.measure(0, 0);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    (int) ((VISIBLE_BUSES + 0.5) * item.getMeasuredHeight()));
            listView.setLayoutParams(params);
        }

    }

    Button otherAcceptButton = (Button) dialog_view.findViewById(R.id.accept);
    otherAcceptButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText serviceEditText = (EditText) dialog_view.findViewById(R.id.service_edit_text);
            EditText licensePlateEditText = (EditText) dialog_view.findViewById(R.id.license_plate_edit_text);
            String service = serviceEditText.getText().toString();
            String licensePlate = licensePlateEditText.getText().toString();
            ServiceHelper helper = new ServiceHelper(getContext());

            if (ServiceValidator.validate(service) && helper.getColorId(Util.formatServiceName(service)) != 0) {
                service = Util.formatServiceName(service);
                if (licensePlate.equals("")) {
                    licensePlate = Constants.DUMMY_LICENSE_PLATE;
                } else if (!LicensePlateValidator.validate(licensePlate)) {
                    Toast.makeText(getContext(), R.string.bus_selection_warning_plate, Toast.LENGTH_SHORT)
                            .show();
                    return;
                }
            } else {
                Toast.makeText(getContext(), R.string.bus_selection_warning_service, Toast.LENGTH_SHORT).show();
                return;
            }

            final Bus bus = new Bus(Util.formatServiceName(service), licensePlate);
            InputMethodManager imm = (InputMethodManager) getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

            Log.d("BusSelectionDialog", "hiding soft input");

            Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    BusSelectionDialog.this.getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            dialog.cancel();
                            listener.onPositiveClick(bus);
                        }
                    });
                }
            }, 500);
            //dialog.cancel();
            // TODO(aantoine): This call is to quick, some times the keyboard is not
            // out of the window when de sliding panel shows up.
            //listener.onPositiveClick(bus);
        }
    });

    /* set cancel button to close dialog */
    dialog_view.findViewById(R.id.close_dialog).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.cancel();
            listener.onNegativeClick();
        }
    });
    ((Button) dialog_view.findViewById(R.id.close_dialog)).setTypeface(iconTypeface);
    dialog.setCanceledOnTouchOutside(false);

    return dialog;
}

From source file:jp.watnow.plugins.dialog.Notification.java

/**
 * Builds and shows a native Android prompt dialog with given title, message, buttons.
 * This dialog only shows up to 3 buttons.  Any labels after that will be ignored.
 * The following results are returned to the JavaScript callback identified by callbackId:
 *     buttonIndex         Index number of the button selected
 *     input1            The text entered in the prompt dialog box
 *
 * @param message           The message the dialog should display
 * @param title             The title of the dialog
 * @param buttonLabels      A comma separated list of button labels (Up to 3 buttons)
 * @param callbackContext   The callback context.
 *///from   www .  ja va 2 s .c  o m
public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels,
        final String defaultText, final String dialogType, final CallbackContext callbackContext) {

    final CordovaInterface cordova = this.cordova;

    Runnable runnable = new Runnable() {
        public void run() {
            final EditText promptInput = new EditText(cordova.getActivity());
            promptInput.setHint(defaultText);
            Log.d("DialogPlugin", dialogType);
            if (dialogType.equals(INPUT_SECURE)) {
                promptInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            }
            AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);

            dlg.setView(promptInput);

            final JSONObject result = new JSONObject();

            // First button
            if (buttonLabels.length() > 0) {
                try {
                    dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            try {
                                result.put("buttonIndex", 1);
                                result.put("input1",
                                        promptInput.getText().toString().trim().length() == 0 ? defaultText
                                                : promptInput.getText());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                        }
                    });
                } catch (JSONException e) {
                }
            }

            // Second button
            if (buttonLabels.length() > 1) {
                try {
                    dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            try {
                                result.put("buttonIndex", 2);
                                result.put("input1",
                                        promptInput.getText().toString().trim().length() == 0 ? defaultText
                                                : promptInput.getText());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                        }
                    });
                } catch (JSONException e) {
                }
            }

            // Third button
            if (buttonLabels.length() > 2) {
                try {
                    dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            try {
                                result.put("buttonIndex", 3);
                                result.put("input1",
                                        promptInput.getText().toString().trim().length() == 0 ? defaultText
                                                : promptInput.getText());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                        }
                    });
                } catch (JSONException e) {
                }
            }
            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    try {
                        result.put("buttonIndex", 0);
                        result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText
                                : promptInput.getText());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                }
            });

            changeTextDirection(dlg);
        };
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.alivenet.dmvtaxi.fragment.FragmentRateYourRide.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.trip_completed, container, false);

    ratingBar = (RatingBar) view.findViewById(R.id.ratingbar);
    Text_tripcomplete_pickuplocation = (TextView) view.findViewById(R.id.tripcomplete_pickuplocation);
    Text_tripcomplete_dropoff_location = (TextView) view.findViewById(R.id.tripcomplete_dropoff_location);
    mname = (TextView) view.findViewById(R.id.tv_name);
    Text_tripcharged = (TextView) view.findViewById(R.id.tripcharged);
    mlicenceplate = (TextView) view.findViewById(R.id.tv_licenceplate);
    mtaname = (TextView) view.findViewById(R.id.tv_taname);
    mcommentbox = (EditText) view.findViewById(R.id.et_commentbox);
    btntip = (Button) view.findViewById(R.id.btntip);
    btnsubmit = (Button) view.findViewById(R.id.btnsubmit);
    icon = (ImageView) view.findViewById(R.id.tripcompltd_icons);

    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);
    mUserId = mPref.getString("userId", null);
    prgDialog = new ProgressDialog(getActivity());
    prgDialog.setMessage("Please wait...");
    prgDialog.setCancelable(false);//from  ww  w  . ja  va  2s .co m
    btntip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (MyApplication.RateyourRide == false) {

                LayoutInflater li = LayoutInflater.from(getContext());
                View promptsView = li.inflate(R.layout.prompts, null);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                alertDialogBuilder.setView(promptsView);
                tipValue = (EditText) promptsView.findViewById(R.id.edittip_value);
                // set dialog message
                alertDialogBuilder.setCancelable(false)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // get user input and set it to result
                                // edit text
                                if (tipValue.getText().toString().trim().length() == 0) {

                                } else {
                                    btntip.setText(String.format("Tip: $ %.2f",
                                            Double.valueOf(tipValue.getText().toString())));

                                }
                            }
                        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();

                getToken(mUserId);

            }

        }
    });
    rideDriverComplete = sharedPreference.getDriverRidercompleate(getActivity());
    String rideId = MyApplication.RideId;
    if (rideDriverComplete == null && rideId != null) {

        ValidateRidecomplet(mUserId, rideId);
    }

    if (MyApplication.RateyourRide == true) {
        btnsubmit.setVisibility(View.GONE);
        mcommentbox.setVisibility(View.GONE);
    }

    if (rideDriverComplete != null) {

        if (rideDriverComplete.getPickupaddress() != null && rideDriverComplete.getPickupaddress() != " "
                && rideDriverComplete.getDestinationaddress() != null
                && rideDriverComplete.getDestinationaddress() != " ") {
            Text_tripcomplete_pickuplocation.setText(rideDriverComplete.getPickupaddress());
            Text_tripcomplete_dropoff_location.setText(rideDriverComplete.getDestinationaddress());
        }
        try {

            Picasso.with(getActivity()).load(MyPreferences.getActiveInstance(getActivity()).getImageUrl())
                    .error(R.mipmap.avtar).placeholder(R.mipmap.avtar).into(icon);
        } catch (Exception e) {
            e.printStackTrace();
        }

        mname.setText(rideDriverComplete.driverNameride);
        mlicenceplate.setText(rideDriverComplete.licenseId);
        mtaname.setText(rideDriverComplete.vehicle);
        Text_tripcharged
                .setText("$" + rideDriverComplete.getTotalfare() + "  HAS BEEN CHARGED TO YOUR CREDIT CARD");

        btnsubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String totalStars = "Total Stars:: " + ratingBar.getNumStars();
                String rating = "Rating :: " + ratingBar.getRating();
                String tip = "";
                if (rideDriverComplete != null) {

                    String driverid = rideDriverComplete.getDriverIdride();
                    String rideId = rideDriverComplete.getRideId();
                    if (tipValue != null)
                        tip = tipValue.getText().toString();

                    String comment = mcommentbox.getText().toString();
                    if (driverid != null && rideId != null && totalStars != null && tip != null) {

                        validateRideRating(mUserId, driverid, rideId, totalStars, tip, comment);
                    }

                }
            }
        });
    }

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                // handle back button's click listener

                if (keyCode == KeyEvent.KEYCODE_BACK) {

                    Fragment homeFragment = new FragmentMainScreen();
                    FragmentManager frgManager;
                    frgManager = getFragmentManager();
                    frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit();

                    return true;
                }

                return true;
            }
            return false;
        }
    });

    return view;

}

From source file:com.pcinpact.ListeArticlesActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    // On dfinit la vue
    setContentView(R.layout.liste_articles);
    // On rcupre les lments
    monListView = (ListView) this.findViewById(R.id.listeArticles);
    monSwipeRefreshLayout = (SwipeRefreshLayout) this.findViewById(R.id.swipe_container);
    headerTextView = (TextView) findViewById(R.id.header_text);

    setSupportProgressBarIndeterminateVisibility(false);

    // onRefresh/*w ww. j  a  v  a 2  s  .  c o  m*/
    monSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            telechargeListeArticles();
        }
    });

    monItemsAdapter = new ItemsAdapter(this, mesArticles);
    monListView.setAdapter(monItemsAdapter);
    monListView.setOnItemClickListener(this);

    // On active le SwipeRefreshLayout uniquement si on est en haut de la listview
    monListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            int topRowVerticalPosition;

            if (monListView == null || monListView.getChildCount() == 0) {
                topRowVerticalPosition = 0;
            } else {
                topRowVerticalPosition = monListView.getChildAt(0).getTop();
            }
            monSwipeRefreshLayout.setEnabled(topRowVerticalPosition >= 0);
        }
    });

    // J'active la BDD
    monDAO = DAO.getInstance(getApplicationContext());
    // Je charge mes articles
    mesArticles.addAll(monDAO.chargerArticlesTriParDate());
    // Mise  jour de l'affichage
    monItemsAdapter.updateListeItems(prepareAffichage());

    // Message d'accueil pour la premire utilisation
    final SharedPreferences mesPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    // Est-ce la premiere utilisation de l'application ?
    Boolean premiereUtilisation = mesPrefs.getBoolean(getString(R.string.idOptionPremierLancementApplication),
            getResources().getBoolean(R.bool.defautOptionPremierLancementApplication));

    // Si premire utilisation : on affiche un disclaimer
    if (premiereUtilisation) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        // Titre
        builder.setTitle(getResources().getString(R.string.app_name));
        // Contenu
        builder.setMessage(getResources().getString(R.string.disclaimerContent));
        // Bouton d'action
        builder.setCancelable(false);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                // Enregistrement que le message a dj t affich
                Editor editor = mesPrefs.edit();
                editor.putBoolean(getString(R.string.idOptionPremierLancementApplication), false);
                editor.commit();

                // Affichage de l'cran de configuration de l'application
                Intent intentOptions = new Intent(getApplicationContext(), OptionsActivity.class);
                startActivity(intentOptions);
            }
        });
        // On cre & affiche
        builder.create().show();

        // Lancement d'un tlchargement des articles
        telechargeListeArticles();
    }
}

From source file:com.almunt.jgcaap.systemupdater.MainActivity.java

public void DeleteZip(final String filename) {
    AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
    builder1.setTitle("Delete Zip?");
    builder1.setMessage("Are you sure you want to delete " + filename);
    builder1.setCancelable(true);
    builder1.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            File file = new File(Environment.getExternalStorageDirectory() + "/JgcaapUpdates/" + filename);
            file.delete();/*ww  w . j av a  2  s.c  o m*/
            RefreshLinks();
        }
    });
    builder1.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });
    AlertDialog alert11 = builder1.create();
    alert11.show();
}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.ReportAccident.ReportAccidentForm.java

public void dataSent() {
    android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(this);
    dialog.setCancelable(false);
    dialog.setTitle("Alert");
    dialog.setMessage("Data Sent Successfully" + "\n\n"
            + "Thank-you for your request. A TLC rep will contact you shortly with payment and details.");
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override// w w  w  . j av  a  2 s . c om
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(ReportAccidentForm.this, ThankYouScreen.class);
            startActivity(intent);
        }
    }).setNegativeButton("", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Action for "Cancel".
        }
    });

    final android.app.AlertDialog alert = dialog.create();
    alert.show();
}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Insurance.ReportAccident.java

public void dataSent() {
    android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(this);
    dialog.setCancelable(false);
    dialog.setTitle("Alert");
    dialog.setMessage("Data Sent Successfully");
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override//w ww .j  av a 2 s.c  o m
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(ReportAccident.this, ThankYouScreen.class);
            startActivity(intent);
        }
    }).setNegativeButton("", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Action for "Cancel".
        }
    });

    final android.app.AlertDialog alert = dialog.create();
    alert.show();
}