Example usage for android.app Dialog setCancelable

List of usage examples for android.app Dialog setCancelable

Introduction

In this page you can find the example usage for android.app Dialog 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:com.kaixin.android.service.UpdateApp.java

private void showCompulsoryDialog() {
    Dialog dialog = new AlertDialog.Builder(context).setTitle(context.getString(R.string.update_com_dialog_tit))
            .setMessage(context.getString(R.string.update_old_txt) + ApplicationUtil.getVerName(context)
                    + context.getString(R.string.update_new_txt) + mUpCodeName + "\n \n"
                    + mUpInfo + context.getString(R.string.update_com_up_txt))
            .setPositiveButton(context.getString(R.string.update_ok_txt),
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            Beginning();
                            dialog.dismiss();
                        }//  w ww. j  a va2  s .  c o  m
                    })
            .setNegativeButton(context.getString(R.string.update_com_no_txt),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            ApplicationUtil.onExitApplication((Activity) context);
                        }
                    })
            .create();
    dialog.show();
    dialog.setCancelable(false);
}

From source file:com.birdeye.MainActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!Prefs.usernames.isSet()) {
        Prefs.usernames.set(Twitter.getSessionManager().getActiveSession().getUserName());
    }/*w ww  .j  av a  2s .c om*/

    setContentView(R.layout.main);
    ButterKnife.bind(this);

    // hideSystemUI(this);
    Chartboost.startWithAppId(MainActivity.this, "57552756f6cd4526e365b9d1",
            "239b2e3aa657ccdcdf0b9674c8750f077b5e0aed");
    Chartboost.setLoggingLevel(CBLogging.Level.ALL);
    Chartboost.setDelegate(delegate);
    Chartboost.onCreate(this);

    tv_cancel = (TextView) findViewById(R.id.tv_cancel);
    tvSetTimer = (Button) findViewById(R.id.tvSetTimer);

    if (!BillingProcessor.isIabServiceAvailable(MainActivity.this)) {
        // showToast("In-app billing service is unavailable, please upgrade Android Market/Play to version >= 3.9.16");
        onBackPressed();
    }

    bp = new BillingProcessor(this, LICENSE_KEY, MERCHANT_ID, new BillingProcessor.IBillingHandler() {
        @Override
        public void onProductPurchased(String productId, TransactionDetails details) {
            showToast("onProductPurchased: " + productId);
            // updateTextViews();
        }

        @Override
        public void onBillingError(int errorCode, Throwable error) {
            showToast("onBillingError: " + Integer.toString(errorCode));
        }

        @Override
        public void onBillingInitialized() {
            showToast("onBillingInitialized");
            readyToPurchase = true;
            //updateTextViews();
        }

        @Override
        public void onPurchaseHistoryRestored() {
            showToast("onPurchaseHistoryRestored");
            for (String sku : bp.listOwnedProducts())
                Log.d(LOG_TAG, "Owned Managed Product: " + sku);
            for (String sku : bp.listOwnedSubscriptions())
                Log.d(LOG_TAG, "Owned Subscription: " + sku);
            //updateTextViews();
            Log.i(LOG_TAG, String.format("%s is%s subscribed", SUBSCRIPTION_ID,
                    bp.isSubscribed(SUBSCRIPTION_ID) ? "" : " not"));
        }
    });

    subs = bp.getSubscriptionListingDetails(SUBSCRIPTION_ID);
    // showToast(subs != null ? subs.toString() : "Failed to load subscription details");

    if (subs == null) {
        //  showToast(subs != null ? subs.toString() : "Failed to load subscription details");
        Globals.hasPaid = false;
    } else {
        Globals.hasPaid = true;
    }

    if (Globals.hasPaid) {
        tvSetTimer.setVisibility(View.VISIBLE);

        message4.setVisibility(View.VISIBLE);
        message5.setVisibility(View.VISIBLE);
        message6.setVisibility(View.VISIBLE);
        message7.setVisibility(View.VISIBLE);
        message8.setVisibility(View.VISIBLE);
        message9.setVisibility(View.VISIBLE);
        message10.setVisibility(View.VISIBLE);
        message11.setVisibility(View.VISIBLE);
        message12.setVisibility(View.VISIBLE);
        message13.setVisibility(View.VISIBLE);
        message14.setVisibility(View.VISIBLE);
        message15.setVisibility(View.VISIBLE);
        message16.setVisibility(View.VISIBLE);
        message17.setVisibility(View.VISIBLE);
        message18.setVisibility(View.VISIBLE);
        message19.setVisibility(View.VISIBLE);
        message20.setVisibility(View.VISIBLE);
        message21.setVisibility(View.VISIBLE);
        message22.setVisibility(View.VISIBLE);
        message23.setVisibility(View.VISIBLE);
        message24.setVisibility(View.VISIBLE);
        message25.setVisibility(View.VISIBLE);

        ets = Arrays.asList(usernames, hashtags, message1, message2, message3, message4, message5, message6,
                message7, message8, message9, message10, message11, message12, message13, message14, message15,
                message16, message17, message18, message19, message20, message21, message22, message23,
                message24, message25);

    } else {
        tvSetTimer.setVisibility(View.GONE);
        message4.setVisibility(View.GONE);
        message5.setVisibility(View.GONE);
        message6.setVisibility(View.GONE);
        message7.setVisibility(View.GONE);
        message8.setVisibility(View.GONE);
        message9.setVisibility(View.GONE);
        message10.setVisibility(View.GONE);
        message11.setVisibility(View.GONE);
        message12.setVisibility(View.GONE);
        message13.setVisibility(View.GONE);
        message14.setVisibility(View.GONE);
        message15.setVisibility(View.GONE);
        message16.setVisibility(View.GONE);
        message17.setVisibility(View.GONE);
        message18.setVisibility(View.GONE);
        message19.setVisibility(View.GONE);
        message20.setVisibility(View.GONE);
        message21.setVisibility(View.GONE);
        message22.setVisibility(View.GONE);
        message23.setVisibility(View.GONE);
        message24.setVisibility(View.GONE);
        message25.setVisibility(View.GONE);
        ets = Arrays.asList(usernames, hashtags, message1, message2, message3);
    }

    tvSetTimer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final Dialog dialog = new Dialog(MainActivity.this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
            dialog.setContentView(R.layout.input_time);
            dialog.setCancelable(true);

            Button bt_set = (Button) dialog.findViewById(R.id.bt_set);
            final EditText et_time = (EditText) dialog.findViewById(R.id.et_time);

            bt_set.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (et_time.getText().toString().equalsIgnoreCase("")) {
                        Toast.makeText(MainActivity.this, "Please enter time to auto shut down",
                                Toast.LENGTH_SHORT).show();
                    }

                    else {

                        int valueTimer = Integer.parseInt(et_time.getText().toString()) * 1000;

                        initateCounter(valueTimer);
                        tv_cancel.setText("Auto ShutDown started");
                        tvSetTimer.setVisibility(View.GONE);
                        tv_cancel.setVisibility(View.VISIBLE);
                        dialog.dismiss();
                    }

                }
            });

            dialog.show();

        }
    });

    cameras.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Facing.values()));
    //noinspection ConstantConditions
    cameras.setSelection(Prefs.facing.get().ordinal());
    cameras.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Prefs.facing.set(Facing.values()[position]);
        }

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

    for (TextInputEditText et : ets) {
        DrawableCompat.setTint(et.getBackground(), ContextCompat.getColor(this, R.color.colorAccent));
        final TextInputLayout til = textLayout(et);
        til.setError(null);
        til.setErrorEnabled(false);
    }

    TextViews.setText(usernames, Prefs.usernames.get());
    TextViews.setText(hashtags, Prefs.hashtags.get());
    TextViews.setText(message1, Prefs.message1.get());
    TextViews.setText(message2, Prefs.message2.get());
    TextViews.setText(message3, Prefs.message3.get());

    TextViews.setText(message4, Prefs.message4.get());
    TextViews.setText(message5, Prefs.message5.get());
    TextViews.setText(message6, Prefs.message6.get());
    TextViews.setText(message7, Prefs.message7.get());
    TextViews.setText(message8, Prefs.message8.get());
    TextViews.setText(message9, Prefs.message9.get());
    TextViews.setText(message10, Prefs.message10.get());
    TextViews.setText(message11, Prefs.message11.get());
    TextViews.setText(message12, Prefs.message12.get());
    TextViews.setText(message13, Prefs.message13.get());
    TextViews.setText(message14, Prefs.message14.get());
    TextViews.setText(message15, Prefs.message15.get());
    TextViews.setText(message16, Prefs.message16.get());
    TextViews.setText(message17, Prefs.message17.get());
    TextViews.setText(message18, Prefs.message18.get());
    TextViews.setText(message19, Prefs.message19.get());
    TextViews.setText(message20, Prefs.message20.get());
    TextViews.setText(message21, Prefs.message21.get());
    TextViews.setText(message22, Prefs.message22.get());
    TextViews.setText(message23, Prefs.message23.get());
    TextViews.setText(message24, Prefs.message24.get());
    TextViews.setText(message25, Prefs.message25.get());

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    getWindow().setBackgroundDrawableResource(R.color.bg);

    mAdView = (AdView) findViewById(R.id.adView);
    mInterstitialAd = new InterstitialAd(this);

    // set the ad unit ID
    mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));

    adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            // Check the LogCat to get your test device ID
            .addTestDevice("EB02375D2DA62FFA0F6F145AD2302B3D").build();

    // adRequest = new AdRequest.Builder().build();

    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
        }

        @Override
        public void onAdClosed() {
            //   Toast.makeText(getApplicationContext(), "Ad is closed!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            //  Toast.makeText(getApplicationContext(), "Ad failed to load! error code: " + errorCode, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdLeftApplication() {
            //  Toast.makeText(getApplicationContext(), "Ad left application!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdOpened() {
            super.onAdOpened();
        }
    });

    mAdView.loadAd(adRequest);
    mInterstitialAd.loadAd(adRequest);

    mInterstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            showInterstitial();
        }

        @Override
        public void onAdClosed() {
            Toast.makeText(getApplicationContext(), "Ad is closed!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(getApplicationContext(), "Ad failed to load! error code: " + errorCode,
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdLeftApplication() {
            Toast.makeText(getApplicationContext(), "Ad left application!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdOpened() {
            Toast.makeText(getApplicationContext(), "Ad is opened!", Toast.LENGTH_SHORT).show();
        }
    });

    if (Globals.hasPaid) {
        tv_cancel.setVisibility(View.GONE);
        mAdView.setVisibility(View.GONE);
    } else {

        // initateCounter(120000);
        startRepeatingTask();
        mAdView.setVisibility(View.VISIBLE);
    }

}

From source file:com.thingsee.tracker.MainActivity.java

@Override
public void onMapReady(GoogleMap map) {
    mMap = map;//from w w w. ja v a  2 s.c o m

    TileProvider wmsTileProvider = TileProviderFactory.getKapsiWmsTileProvider();
    mMap.addTileOverlay(new TileOverlayOptions().tileProvider(wmsTileProvider).fadeIn(true));

    initGoogleMap();

    trackerList = (HorizontalScrollView) this.findViewById(R.id.tracker_scroll_area);
    mTrackerItemLayout = (LinearLayout) findViewById(R.id.trackers);

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mainari, 16));
    Marker mark = mMap.addMarker(new MarkerOptions().position(mainari));

    ImageView locateButton = (ImageView) findViewById(R.id.app_icon);

    //set the ontouch listener
    locateButton.setOnTouchListener(new OnTouchListener() {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                ImageView view = (ImageView) v;
                view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                if (onChildOnMapView) {
                    onUpPressed();
                } else {
                    userZoomAndPanOnMap = false;
                    zoomToBoundingBox();
                }
            case MotionEvent.ACTION_CANCEL: {
                ImageView view = (ImageView) v;
                //clear the overlay
                view.getDrawable().setColorFilter(mResources.getColor(R.color.white_effect),
                        PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            }

            return true;
        }
    });

    ImageView settingsButton = (ImageView) findViewById(R.id.header_settings_icon);

    //set the ontouch listener
    settingsButton.setOnTouchListener(new OnTouchListener() {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                ImageView view = (ImageView) v;
                //overlay is black with transparency of 0x77 (119)
                view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                final Dialog verificationQuery = new Dialog(mContext,
                        android.R.style.Theme_Translucent_NoTitleBar);
                verificationQuery.requestWindowFeature(Window.FEATURE_NO_TITLE);
                verificationQuery.setCancelable(false);
                verificationQuery.setContentView(R.layout.request_admin_code);
                ClearTextView ok = (ClearTextView) verificationQuery.findViewById(R.id.ok);
                ok.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        verificationQuery.dismiss();
                        EditText code = (EditText) verificationQuery.findViewById(R.id.verification_code);
                        if (code.getText().toString().equalsIgnoreCase("password")) {
                            Intent intent = new Intent(MainActivity.this, MenuActivity.class);
                            startActivity(intent);
                        }
                    }
                });
                ClearTextView cancel = (ClearTextView) verificationQuery.findViewById(R.id.cancel);
                cancel.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        verificationQuery.dismiss();
                    }
                });
                verificationQuery.show();
                verificationQuery.getWindow().setDimAmount(0.5f);
                verificationQuery.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            case MotionEvent.ACTION_CANCEL: {
                ImageView view = (ImageView) v;
                //clear the overlay
                view.getDrawable().setColorFilter(mResources.getColor(R.color.white_effect),
                        PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            }

            return true;
        }
    });

    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng position) {
            if (onChildOnMapView) {
                if (trackerModelWithMarker != null) {
                    trackerModelWithMarker.getMarker().showInfoWindow();
                }
            }
        }
    });

    mMap.setOnMarkerClickListener(new OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            if (trackersActive) {
                LatLng latlng = marker.getPosition();
                userZoomAndPanOnMap = false;
                if ((latlng.latitude == mainari.latitude) && (latlng.longitude == mainari.longitude)) {
                    if (onChildOnMapView) {
                        if (trackerModelWithMarker != null) {
                            trackerModelWithMarker.getMarker().showInfoWindow();
                        }
                    }
                } else {
                    if (!onChildOnMapView) {
                        trackerModelWithMarker = null;
                        // Zoom to marker tapped
                        zoomToMarker(latlng);
                        //Remove other markers
                        for (String key : trackers.keySet()) {
                            TrackerModel trackerModel = trackers.get(key);
                            if (trackerModel.getLatestLatLng() != null) {
                                if ((trackerModel.getLatestLatLng().latitude == latlng.latitude)
                                        && (trackerModel.getLatestLatLng().longitude == latlng.longitude)) {
                                    focusOnChildOnMap(trackerModel.getSerialNumber());
                                    trackerModelWithMarker = trackerModel;
                                    trackerModelWithMarker.getMarker().showInfoWindow();
                                }
                            }
                        }
                    } else {
                        trackerModelWithMarker.getMarker().showInfoWindow();
                        for (String key : trackers.keySet()) {
                            TrackerModel trackerModel = trackers.get(key);
                            if (trackerModel.getLatestLatLng() != null) {
                                if ((trackerModel.getLatestLatLng().latitude == latlng.latitude)
                                        && (trackerModel.getLatestLatLng().longitude == latlng.longitude)) {
                                    onBackPressed();
                                }
                            }
                        }
                    }
                }
            }
            return true;
        }
    });
    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

        // Defines the contents of the InfoWindow
        @Override
        public View getInfoContents(Marker arg0) {

            // Getting view from the layout file info_window_layout
            View v = null;

            for (String key : trackers.keySet()) {
                TrackerModel trackerModel = trackers.get(key);
                if (trackerModel.getLatestLatLng() != null) {
                    if ((trackerModel.getLatestLatLng().latitude == arg0.getPosition().latitude)
                            && (trackerModel.getLatestLatLng().longitude == arg0.getPosition().longitude)) {
                        v = getLayoutInflater().inflate(R.layout.info_window, null);
                        trackerModelWithMarker = trackerModel;
                        TextView trackerAccuracy = (TextView) v
                                .findViewById(R.id.tracker_marker_popup_accuracy);
                        if (trackerModelWithMarker.getAccuracy() != -1) {
                            trackerAccuracy
                                    .setText(String.format(mResources.getString(R.string.tracker_accuracy),
                                            trackerModelWithMarker.getAccuracy()));
                        } else {
                            trackerAccuracy.setText(
                                    String.format(mResources.getString(R.string.tracker_accuracy), 0.0f));
                        }
                        TextView trackerDistanceTs = (TextView) v
                                .findViewById(R.id.tracker_marker_popup_update_timestamp);
                        if (trackerModelWithMarker.getLastLocationUpdate() != 0) {
                            String timeStampText = Utilities.getSmartTimeStampString(mContext, mResources,
                                    trackerModelWithMarker.getLastLocationUpdate());
                            trackerDistanceTs.setText(
                                    mResources.getString(R.string.tracker_timestamp) + " " + timeStampText);
                        } else {
                            trackerDistanceTs.setText(mResources.getString(R.string.tracker_timestamp) + " - ");
                        }
                        trackerInfoWindow = v;
                    }
                }
            }
            // Returning the view containing InfoWindow contents
            return v;
        }
    });
    IntentFilter statusIntentFilter = new IntentFilter(CommonConstants.BROADCAST_ACTION);
    statusIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
    mFetchCloudDataStateReceiver = new FetchCloudDataStateReceiver();
    LocalBroadcastManager.getInstance(this).registerReceiver(mFetchCloudDataStateReceiver, statusIntentFilter);

    mapLoaded = true;
    if (splashReady) {
        mSplashHandler.postDelayed(splashScreenOffFromDisplay, 0);
    }
}

From source file:com.gpsmobitrack.gpstracker.MenuItems.SettingsPage.java

/**
 *  Profile is Public ON or OFF //from w w  w. ja v  a 2 s . c  o  m
 */
private void showPublicAlert(String Message, String Title, final int alertCode) {
    final Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCancelable(false);
    dialog.setContentView(R.layout.alert_dialog_main);
    final TextView alertTitle = (TextView) dialog.findViewById(R.id.alert_title);
    final TextView alertMsg = (TextView) dialog.findViewById(R.id.alert_msg);
    final EditText alertEditTxt = (EditText) dialog.findViewById(R.id.alert_edit_txt);
    Button okBtn = (Button) dialog.findViewById(R.id.alert_ok_btn);
    Button cancelBtn = (Button) dialog.findViewById(R.id.alert_cancel_btn);
    alertTitle.setText(Title);
    alertMsg.setText(Message);
    alertEditTxt.setVisibility(View.GONE);
    cancelBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            if (alertCode == 7) {
                publicPrivacy.setChecked(true);
                editor.putBoolean(AppConstants.IS_ENABLED_PROFILE_PRIVACY, true);
                editor.commit();

            }
        }
    });
    okBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            if (alertCode == 7) {
                publicPrivacy.setChecked(false);
                editor.putBoolean(AppConstants.IS_ENABLED_PROFILE_PRIVACY, false);
                editor.commit();

            }
        }
    });
    dialog.show();
}

From source file:com.gpsmobitrack.gpstracker.MenuItems.SettingsPage.java

/**
 *  Background updates show ON or OFF//from www.  ja v a 2s  .  c  o m
 */
private void showAlert(String Message, String Title, final int alertCode) {
    final Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCancelable(false);
    dialog.setContentView(R.layout.alert_dialog_main);
    final TextView alertTitle = (TextView) dialog.findViewById(R.id.alert_title);
    final TextView alertMsg = (TextView) dialog.findViewById(R.id.alert_msg);
    final EditText alertEditTxt = (EditText) dialog.findViewById(R.id.alert_edit_txt);
    Button okBtn = (Button) dialog.findViewById(R.id.alert_ok_btn);
    Button cancelBtn = (Button) dialog.findViewById(R.id.alert_cancel_btn);
    alertTitle.setText(Title);
    alertMsg.setText(Message);
    alertEditTxt.setVisibility(View.GONE);
    if (alertCode == 0 || alertCode == UPDATE_INT || alertCode == 7) {
        cancelBtn.setVisibility(View.VISIBLE);
    } else {
        cancelBtn.setVisibility(View.GONE);
    }
    cancelBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            if (alertCode == 7) {
                backUpdateToggle.setChecked(true);
                editor.putBoolean(AppConstants.IS_SERVICE_ENABLED_PREF, true);
                editor.commit();
            }
        }
    });
    okBtn.setOnClickListener(new OnClickListener() {
        @SuppressWarnings("unused")
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            if (alertCode == 3 || alertCode == 4) {

                session.logoutUser(getActivity());
                Intent i = new Intent(getActivity(), Login.class);
                startActivity(i);
                getActivity().finish();
            } else if (alertCode == 0) {
                deactivateAcc();
            } else if (alertCode == UPDATE_INT) {
                getActivity().finish();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("market://details?id=com.gpstracker.pro"));
                startActivity(intent);
            } else if (alertCode == 7) {
                backUpdateToggle.setChecked(false);
                editor.putBoolean(AppConstants.IS_SERVICE_ENABLED_PREF, false);
                editor.commit();
                AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
                Calendar cal = Calendar.getInstance();
                Intent intent2 = new Intent(getActivity(), BackgroundService.class);
                PendingIntent pintent = PendingIntent.getService(getActivity(), 0, intent2, 0);
                if (PendingIntent.getService(getActivity(), 0, intent2, PendingIntent.FLAG_NO_CREATE) != null) {
                    alarm.cancel(pintent);
                }
            }
        }
    });
    dialog.show();
}

From source file:org.telegram.ui.TwoStepVerificationActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//from www .ja v a  2 s . c  o  m
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                processDone();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));

    ActionBarMenu menu = actionBar.createMenu();
    doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    scrollView = new ScrollView(context);
    scrollView.setFillViewport(true);
    frameLayout.addView(scrollView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) scrollView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    scrollView.setLayoutParams(layoutParams);

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    scrollView.addView(linearLayout);
    ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
    layoutParams2.width = ScrollView.LayoutParams.MATCH_PARENT;
    layoutParams2.height = ScrollView.LayoutParams.WRAP_CONTENT;
    linearLayout.setLayoutParams(layoutParams2);

    titleTextView = new TextView(context);
    //titleTextView.setTextColor(0xff757575);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    linearLayout.addView(titleTextView);
    LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) titleTextView.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams3.topMargin = AndroidUtilities.dp(38);
    titleTextView.setLayoutParams(layoutParams3);

    passwordEditText = new EditText(context);
    passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    //passwordEditText.setTextColor(0xff000000);
    passwordEditText.setMaxLines(1);
    passwordEditText.setLines(1);
    passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordEditText.setSingleLine(true);
    passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEditText.setTypeface(Typeface.DEFAULT);
    AndroidUtilities.clearCursorDrawable(passwordEditText);
    linearLayout.addView(passwordEditText);
    layoutParams3 = (LinearLayout.LayoutParams) passwordEditText.getLayoutParams();
    layoutParams3.topMargin = AndroidUtilities.dp(32);
    layoutParams3.height = AndroidUtilities.dp(36);
    layoutParams3.leftMargin = AndroidUtilities.dp(40);
    layoutParams3.rightMargin = AndroidUtilities.dp(40);
    layoutParams3.gravity = Gravity.TOP | Gravity.LEFT;
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    passwordEditText.setLayoutParams(layoutParams3);
    passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_NEXT || i == EditorInfo.IME_ACTION_DONE) {
                processDone();
                return true;
            }
            return false;
        }
    });
    passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });

    bottomTextView = new TextView(context);
    //bottomTextView.setTextColor(0xff757575);
    bottomTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    bottomTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    bottomTextView.setText(LocaleController.getString("YourEmailInfo", R.string.YourEmailInfo));
    linearLayout.addView(bottomTextView);
    layoutParams3 = (LinearLayout.LayoutParams) bottomTextView.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
    layoutParams3.topMargin = AndroidUtilities.dp(30);
    layoutParams3.leftMargin = AndroidUtilities.dp(40);
    layoutParams3.rightMargin = AndroidUtilities.dp(40);
    bottomTextView.setLayoutParams(layoutParams3);

    LinearLayout linearLayout2 = new LinearLayout(context);
    linearLayout2.setGravity(Gravity.BOTTOM | Gravity.CENTER_VERTICAL);
    linearLayout.addView(linearLayout2);
    layoutParams3 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.MATCH_PARENT;
    linearLayout2.setLayoutParams(layoutParams3);

    bottomButton = new TextView(context);
    bottomButton.setTextColor(0xff4d83b3);
    bottomButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    bottomButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM);
    bottomButton.setText(LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip));
    bottomButton.setPadding(0, AndroidUtilities.dp(10), 0, 0);
    linearLayout2.addView(bottomButton);
    layoutParams3 = (LinearLayout.LayoutParams) bottomButton.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
    layoutParams3.bottomMargin = AndroidUtilities.dp(14);
    layoutParams3.leftMargin = AndroidUtilities.dp(40);
    layoutParams3.rightMargin = AndroidUtilities.dp(40);
    bottomButton.setLayoutParams(layoutParams3);
    bottomButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (type == 0) {
                if (currentPassword.has_recovery) {
                    needShowProgress();
                    TLRPC.TL_auth_requestPasswordRecovery req = new TLRPC.TL_auth_requestPasswordRecovery();
                    ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                        @Override
                        public void run(final TLObject response, final TLRPC.TL_error error) {
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public void run() {
                                    needHideProgress();
                                    if (error == null) {
                                        final TLRPC.TL_auth_passwordRecovery res = (TLRPC.TL_auth_passwordRecovery) response;
                                        AlertDialog.Builder builder = new AlertDialog.Builder(
                                                getParentActivity());
                                        builder.setMessage(LocaleController.formatString("RestoreEmailSent",
                                                R.string.RestoreEmailSent, res.email_pattern));
                                        builder.setTitle(
                                                LocaleController.getString("AppName", R.string.AppName));
                                        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialogInterface,
                                                            int i) {
                                                        TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(
                                                                1);
                                                        fragment.currentPassword = currentPassword;
                                                        fragment.currentPassword.email_unconfirmed_pattern = res.email_pattern;
                                                        fragment.passwordSetState = 4;
                                                        presentFragment(fragment);
                                                    }
                                                });
                                        Dialog dialog = showDialog(builder.create());
                                        if (dialog != null) {
                                            dialog.setCanceledOnTouchOutside(false);
                                            dialog.setCancelable(false);
                                        }
                                    } else {
                                        if (error.text.startsWith("FLOOD_WAIT")) {
                                            int time = Utilities.parseInt(error.text);
                                            String timeString;
                                            if (time < 60) {
                                                timeString = LocaleController.formatPluralString("Seconds",
                                                        time);
                                            } else {
                                                timeString = LocaleController.formatPluralString("Minutes",
                                                        time / 60);
                                            }
                                            showAlertWithText(
                                                    LocaleController.getString("AppName", R.string.AppName),
                                                    LocaleController.formatString("FloodWaitTime",
                                                            R.string.FloodWaitTime, timeString));
                                        } else {
                                            showAlertWithText(
                                                    LocaleController.getString("AppName", R.string.AppName),
                                                    error.text);
                                        }
                                    }
                                }
                            });
                        }
                    }, ConnectionsManager.RequestFlagFailOnServerErrors
                            | ConnectionsManager.RequestFlagWithoutLogin);
                } else {
                    showAlertWithText(
                            LocaleController.getString("RestorePasswordNoEmailTitle",
                                    R.string.RestorePasswordNoEmailTitle),
                            LocaleController.getString("RestorePasswordNoEmailText",
                                    R.string.RestorePasswordNoEmailText));
                }
            } else {
                if (passwordSetState == 4) {
                    showAlertWithText(
                            LocaleController.getString("RestorePasswordNoEmailTitle",
                                    R.string.RestorePasswordNoEmailTitle),
                            LocaleController.getString("RestoreEmailTroubleText",
                                    R.string.RestoreEmailTroubleText));
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setMessage(LocaleController.getString("YourEmailSkipWarningText",
                            R.string.YourEmailSkipWarningText));
                    builder.setTitle(
                            LocaleController.getString("YourEmailSkipWarning", R.string.YourEmailSkipWarning));
                    builder.setPositiveButton(
                            LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    email = "";
                                    setNewPassword(false);
                                }
                            });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    showDialog(builder.create());
                }
            }
        }
    });

    if (type == 0) {
        progressView = new FrameLayout(context);
        frameLayout.addView(progressView);
        layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        progressView.setLayoutParams(layoutParams);
        progressView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        ProgressBar progressBar = new ProgressBar(context);
        progressView.addView(progressBar);
        layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER;
        progressView.setLayoutParams(layoutParams);

        listView = new ListView(context);
        listView.setDivider(null);
        listView.setEmptyView(progressView);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == setPasswordRow || i == changePasswordRow) {
                    TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1);
                    fragment.currentPasswordHash = currentPasswordHash;
                    fragment.currentPassword = currentPassword;
                    presentFragment(fragment);
                } else if (i == setRecoveryEmailRow || i == changeRecoveryEmailRow) {
                    TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1);
                    fragment.currentPasswordHash = currentPasswordHash;
                    fragment.currentPassword = currentPassword;
                    fragment.emailOnly = true;
                    fragment.passwordSetState = 3;
                    presentFragment(fragment);
                } else if (i == turnPasswordOffRow || i == abortPasswordRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setMessage(LocaleController.getString("TurnPasswordOffQuestion",
                            R.string.TurnPasswordOffQuestion));
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    setNewPassword(true);
                                }
                            });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    showDialog(builder.create());
                }
            }
        });

        updateRows();

        actionBar.setTitle(LocaleController.getString("TwoStepVerification", R.string.TwoStepVerification));
        titleTextView.setText(
                LocaleController.getString("PleaseEnterCurrentPassword", R.string.PleaseEnterCurrentPassword));
    } else if (type == 1) {
        setPasswordSetState(passwordSetState);
    }

    return fragmentView;
}

From source file:com.mEmoZz.qrgen.MainActivity.java

public void mCore() {

    Toast.makeText(getApplicationContext(), "Generating code...", Toast.LENGTH_SHORT).show();

    new CountDownTimer(3000, 1000) {
        public void onTick(long millisUntilFinished) {
        }//from   ww  w.  j  a  va  2s .  co  m

        public void onFinish() {
            Button yupBtn, delBtn, shareBtn;

            Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();

            final Dialog dialog = new Dialog(MainActivity.this);
            dialog.setContentView(R.layout.dialog);

            dialog.setTitle("Want to save?");

            iv = (ImageView) dialog.findViewById(R.id.iv);
            iv.setImageBitmap(bm);

            shareBtn = (Button) dialog.findViewById(R.id.shareBtn);
            shareBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    shareIt();
                }
            });

            yupBtn = (Button) dialog.findViewById(R.id.btn1);
            yupBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    mStream();

                    dialog.dismiss();
                }
            });

            delBtn = (Button) dialog.findViewById(R.id.btn2);
            delBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();

                    Toast.makeText(getApplicationContext(), "Deleted!", Toast.LENGTH_SHORT).show();
                }
            });

            dialog.show();
            dialog.setCancelable(false);
            keepDialog(dialog);
        }
    }.start();

}

From source file:com.gpsmobitrack.gpstracker.MenuItems.SettingsPage.java

/**
 * Show frequency dialog//  w w w  .  jav a 2  s  . com
 */
private void showFrequencyPurchaseDialog(final int value) {
    final Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCancelable(false);
    dialog.setContentView(R.layout.alert_dialog_main);
    final TextView alertTitle = (TextView) dialog.findViewById(R.id.alert_title);
    final TextView alertMsg = (TextView) dialog.findViewById(R.id.alert_msg);
    final EditText alertEditTxt = (EditText) dialog.findViewById(R.id.alert_edit_txt);
    Button okBtn = (Button) dialog.findViewById(R.id.alert_ok_btn);
    Button cancelBtn = (Button) dialog.findViewById(R.id.alert_cancel_btn);
    final RadioGroup radioGroup = (RadioGroup) dialog.findViewById(R.id.myRadioGroup);

    final RadioButton radioOneMonth = (RadioButton) dialog.findViewById(R.id.oneMonth);
    final RadioButton radioThreeMonth = (RadioButton) dialog.findViewById(R.id.threeMonth);
    final RadioButton radioSixMonth = (RadioButton) dialog.findViewById(R.id.sixMonth);
    final RadioButton radioOneYear = (RadioButton) dialog.findViewById(R.id.oneYear);

    //long updateTime = pref.getLong(AppConstants.FREQ_UPDATE_PREF, AppConstants.DEFAULT_TIME_INTERVAL);
    radioGroup.setVisibility(View.VISIBLE);
    alertTitle.setText("Purchase Product");
    if (value == updateDurationValue[0]) {
        alertMsg.setText("Buy Update Frequency for 1 Minutes");
        //radioOneMonth.setChecked(true);
        if (userType == PurchaseStatus.FULL_ACCESS_USER) {
            if (duration.equalsIgnoreCase("OneMonth")) {
                radioOneMonth.setChecked(true);
            } else {
                radioOneMonth.setChecked(false);
                ;
            }
            if (duration.equalsIgnoreCase("ThreeMonth")) {
                radioThreeMonth.setChecked(true);
            } else {
                radioThreeMonth.setChecked(false);
            }
            if (duration.equalsIgnoreCase("SixMonth")) {
                radioSixMonth.setChecked(true);
            } else {
                radioSixMonth.setChecked(false);
            }
            if (duration.equalsIgnoreCase("OneYear")) {
                radioOneYear.setChecked(true);
            } else {
                radioOneYear.setChecked(false);
            }
        }
    } else if (value == updateDurationValue[1]) {
        alertMsg.setText("Buy Update Frequency for 2 Minutes");
        if (userType == PurchaseStatus.SEMI_FULL_ACCESS_USER) {
            if (duration.equalsIgnoreCase("OneMonth")) {
                radioOneMonth.setChecked(true);
            } else {
                radioOneMonth.setChecked(false);
                ;
            }
            if (duration.equalsIgnoreCase("ThreeMonth")) {
                radioThreeMonth.setChecked(true);
            } else {
                radioThreeMonth.setChecked(false);
            }
            if (duration.equalsIgnoreCase("SixMonth")) {
                radioSixMonth.setChecked(true);
            } else {
                radioSixMonth.setChecked(false);
            }
            if (duration.equalsIgnoreCase("OneYear")) {
                radioOneYear.setChecked(true);
            } else {
                radioOneYear.setChecked(false);
            }
        }
    } else if (value == updateDurationValue[2]) {
        alertMsg.setText("Buy Update Frequency for 3 Minutes");

        if (userType == PurchaseStatus.PARTIAL_ACCESS_USER) {
            if (duration.equalsIgnoreCase("OneMonth")) {
                radioOneMonth.setChecked(true);
            } else {
                radioOneMonth.setChecked(false);
                ;
            }
            if (duration.equalsIgnoreCase("ThreeMonth")) {
                radioThreeMonth.setChecked(true);
            } else {
                radioThreeMonth.setChecked(false);
            }
            if (duration.equalsIgnoreCase("SixMonth")) {
                radioSixMonth.setChecked(true);
            } else {
                radioSixMonth.setChecked(false);
            }
            if (duration.equalsIgnoreCase("OneYear")) {
                radioOneYear.setChecked(true);
            } else {
                radioOneYear.setChecked(false);
            }
        }
    }
    alertEditTxt.setVisibility(View.GONE);

    radioOneMonth.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (value == updateDurationValue[0]) {
                purchaseClicked = PurchaseClicked.ONE_MIN_ONE_MONTH;
            } else if (value == updateDurationValue[1]) {
                purchaseClicked = PurchaseClicked.TWO_MIN_ONE_MONTH;
            } else if (value == updateDurationValue[2]) {
                purchaseClicked = PurchaseClicked.THREE_MIN_ONE_MONTH;
            }
        }
    });
    radioThreeMonth.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (value == updateDurationValue[0]) {
                purchaseClicked = PurchaseClicked.ONE_MIN_THREE_MONTH;
            } else if (value == updateDurationValue[1]) {
                purchaseClicked = PurchaseClicked.TWO_MIN_THREE_MONTH;
            } else if (value == updateDurationValue[2]) {
                purchaseClicked = PurchaseClicked.THREE_MIN_THREE_MONTH;
            }
        }
    });
    radioSixMonth.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (value == updateDurationValue[0]) {
                purchaseClicked = PurchaseClicked.ONE_MIN_SIX_MONTH;
            } else if (value == updateDurationValue[1]) {
                purchaseClicked = PurchaseClicked.TWO_MIN_SIX_MONTH;
            } else if (value == updateDurationValue[2]) {
                purchaseClicked = PurchaseClicked.THREE_MIN_SIX_MONTH;
            }
        }
    });
    radioOneYear.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (value == updateDurationValue[0]) {
                purchaseClicked = PurchaseClicked.ONE_MIN_ONE_YEAR;
            } else if (value == updateDurationValue[1]) {
                purchaseClicked = PurchaseClicked.TWO_MIN_ONE_YEAR;
            } else if (value == updateDurationValue[2]) {
                purchaseClicked = PurchaseClicked.THREE_MIN_ONE_YEAR;
            }
        }
    });
    cancelBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            long updateTime = pref.getLong(AppConstants.FREQ_UPDATE_PREF, AppConstants.DEFAULT_TIME_INTERVAL);

            // Set Spinner
            setSpinnerUpdateTime(updateTime);
            firstSelect = false;
        }
    });
    okBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (radioOneMonth.isChecked() || radioThreeMonth.isChecked() || radioSixMonth.isChecked()
                    || radioOneYear.isChecked()) {
                // One min update
                if (value == updateDurationValue[0] && radioOneMonth.isChecked()) {
                    fullPurchaseOneMonth();
                    purchaseClicked = PurchaseClicked.ONE_MIN_ONE_MONTH;
                    //startUpdatePurchaseStatus();
                } else if (value == updateDurationValue[0] && radioThreeMonth.isChecked()) {
                    fullPurchaseThreeMonth();
                    purchaseClicked = PurchaseClicked.ONE_MIN_THREE_MONTH;
                    //startUpdatePurchaseStatus();
                } else if (value == updateDurationValue[0] && radioSixMonth.isChecked()) {
                    fullPurchaseSixMonth();
                    purchaseClicked = PurchaseClicked.ONE_MIN_SIX_MONTH;
                    //startUpdatePurchaseStatus();
                } else if (value == updateDurationValue[0] && radioOneYear.isChecked()) {
                    fullPurchaseOneYear();
                    purchaseClicked = PurchaseClicked.ONE_MIN_ONE_YEAR;
                    //startUpdatePurchaseStatus();
                }
                // Two min update
                else if (value == updateDurationValue[1] && radioOneMonth.isChecked()) {
                    semiparticalPurchaseOneMonth();
                    purchaseClicked = PurchaseClicked.TWO_MIN_ONE_MONTH;
                    //startUpdatePurchaseStatus();
                } else if (value == updateDurationValue[1] && radioThreeMonth.isChecked()) {
                    semiparticalPurchaseThreeMonth();
                    purchaseClicked = PurchaseClicked.TWO_MIN_THREE_MONTH;
                    //startUpdatePurchaseStatus();
                } else if (value == updateDurationValue[1] && radioSixMonth.isChecked()) {
                    semiparticalPurchaseSixMonth();
                    purchaseClicked = PurchaseClicked.TWO_MIN_SIX_MONTH;
                    //startUpdatePurchaseStatus();
                } else if (value == updateDurationValue[1] && radioOneYear.isChecked()) {
                    semiparticalPurchaseOneYear();
                    purchaseClicked = PurchaseClicked.TWO_MIN_ONE_YEAR;
                    //startUpdatePurchaseStatus();
                }
                // Three min update
                else if (value == updateDurationValue[2] && radioOneMonth.isChecked()) {
                    particalPurchaseOneMonth();
                    purchaseClicked = PurchaseClicked.THREE_MIN_ONE_MONTH;
                    //startUpdatePurchaseStatus();
                } else if (value == updateDurationValue[2] && radioThreeMonth.isChecked()) {
                    particalPurchaseThreeMonth();
                    purchaseClicked = PurchaseClicked.THREE_MIN_THREE_MONTH;
                    //startUpdatePurchaseStatus();
                } else if (value == updateDurationValue[2] && radioSixMonth.isChecked()) {
                    particalPurchaseSixMonth();
                    purchaseClicked = PurchaseClicked.THREE_MIN_SIX_MONTH;
                    //startUpdatePurchaseStatus();
                } else if (value == updateDurationValue[2] && radioOneYear.isChecked()) {
                    particalPurchaseOneYear();
                    purchaseClicked = PurchaseClicked.THREE_MIN_ONE_YEAR;
                    //startUpdatePurchaseStatus();
                }

                long updateTime = pref.getLong(AppConstants.FREQ_UPDATE_PREF,
                        AppConstants.DEFAULT_TIME_INTERVAL);
                // Set Spinner
                setSpinnerUpdateTime(updateTime);
                firstSelect = false;
                dialog.dismiss();
            } else {
                dialog.show();
                Utils.showToast("Select durations");
                //Toast.makeText(getActivity(), "Select durations", Toast.LENGTH_LONG).show();
            }
        }
    });
    dialog.show();
}

From source file:dong.lan.tuyi.activity.MainActivity.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.toolbar_community:
        startActivity(new Intent(MainActivity.this, TuyiHomeActivity.class));
        overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
        break;//from ww w  .j a  va 2  s .c  o m
    case R.id.toolbar_tuyi:
        startActivity(new Intent(MainActivity.this, TuMapActivity.class));
        overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
        break;
    case R.id.my_Favorite:
        startActivity(new Intent(MainActivity.this, FavoriteActivity.class));
        overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
        break;
    case R.id.user_des:
        isGetWeather = true;
        break;
    case R.id.offline_tuyi:
        startActivityForResult(new Intent(MainActivity.this, OfflineTuyiActivity.class), 100);
        overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
        break;
    case R.id.user_community:
        Lock.canPop = false;
        startActivityForResult(new Intent(MainActivity.this, TuyiCommunityActivity.class), 100);
        overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
        break;
    case R.id.user_head:
        if (Config.tUser == null) {
            Show("????");
            return;
        }
        Lock.canPop = false;
        final Dialog dialog = new AlertDialog.Builder(MainActivity.this).create();
        dialog.setCancelable(true);
        dialog.show();
        dialog.getWindow().setContentView(R.layout.dialog_set_head_img);
        TextView msg = (TextView) dialog.findViewById(R.id.dialog_msg);
        msg.setText("?");
        TextView dialog_left = (TextView) dialog.findViewById(R.id.dialog_left);
        TextView dialog_right = (TextView) dialog.findViewById(R.id.dialog_right);
        dialog_left.setText("");
        dialog_right.setText("");
        dialog_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                File dir = new File(Constant.PICTURE_PATH);
                if (!dir.exists()) {
                    dir.mkdirs();
                }
                // 
                File file = new File(dir,
                        username + "_head_" + new SimpleDateFormat(TimeUtil.FORMAT_NORMAL).format(new Date()));
                filePath = file.getAbsolutePath();// ??
                Uri imageUri = Uri.fromFile(file);

                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                startActivityForResult(intent, Constant.REQUESTCODE_UPLOADAVATAR_CAMERA);
            }
        });
        dialog_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                Intent intent = new Intent(Intent.ACTION_PICK, null);
                intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
                startActivityForResult(intent, Constant.REQUESTCODE_UPLOADAVATAR_LOCATION);
            }
        });

        break;
    case R.id.user_center:
        if (Config.tUser != null) {
            Lock.canPop = false;
            startActivityForResult(
                    new Intent(MainActivity.this, UserCenter.class).putExtra("USER", Config.tUser), 100);
            overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
        }
        break;
    case R.id.user_albums:
        startActivityForResult(new Intent(MainActivity.this, TuyiPlayActivity.class), 100);
        overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
        break;
    case R.id.user_setting:
        startActivityForResult(new Intent(MainActivity.this, MyRadarActivity.class), 100);
        break;
    case R.id.my_interested:
        startActivityForResult(new Intent(MainActivity.this, MyInterestedActivity.class), 100);
        overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
        break;

    }
}

From source file:com.birdeye.MainActivity.java

private void removeAdsDialog() {

    final Dialog dialog = new Dialog(MainActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    dialog.setContentView(R.layout.progress_pre);

    TextView tv_pay15 = (TextView) dialog.findViewById(R.id.tv_pay15);

    tv_pay15.setOnClickListener(new View.OnClickListener() {
        @Override/*from w  ww.  jav  a  2s.  com*/
        public void onClick(View v) {

            if (!BillingProcessor.isIabServiceAvailable(MainActivity.this)) {
                showToast(
                        "In-app billing service is unavailable, please upgrade Android Market/Play to version >= 3.9.16");
            }

            else {

                //    asdasd

                //  onFuturePaymentPressed(v);
                bp.subscribe(MainActivity.this, SUBSCRIPTION_ID);

            }

            dialog.dismiss();

        }
    });

    dialog.setCancelable(true);

    dialog.show();

}