List of usage examples for android.app AlertDialog.Builder create
public void create()
From source file:de.j4velin.wifiAutoOff.Locations.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); Database db = Database.getInstance(this); locations = db.getLocations();//from ww w . ja v a2 s .c o m db.close(); setContentView(R.layout.locations); findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (PREMIUM_ENABLED || locations.size() < 1) { startActivityForResult(new Intent(Locations.this, Map.class), REQUEST_LOCATION); } else { AlertDialog.Builder builder = new AlertDialog.Builder(Locations.this); builder.setMessage(R.string.buy_pro); builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { try { Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), "de.j4velin.wifiautomatic.billing.pro", "inapp", getPackageName()); if (buyIntentBundle.getInt("RESPONSE_CODE") == 0) { PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT"); startIntentSenderForResult(pendingIntent.getIntentSender(), REQUEST_BUY, null, 0, 0, 0); } } catch (Exception e) { if (BuildConfig.DEBUG) Logger.log(e); Toast.makeText(Locations.this, e.getClass().getName() + ": " + e.getMessage(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } dialog.dismiss(); } }); builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } } }); mRecyclerView = (RecyclerView) findViewById(R.id.locations); mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); mAdapter = new LocationsAdapter(); mRecyclerView.setAdapter(mAdapter); PREMIUM_ENABLED |= getSharedPreferences("settings", Context.MODE_PRIVATE).getBoolean("pro", false); if (!PREMIUM_ENABLED) { bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND") .setPackage("com.android.vending"), mServiceConn, Context.BIND_AUTO_CREATE); } findViewById(R.id.timeoutwarning).setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { getSharedPreferences(getPackageName() + "_preferences", Context.MODE_MULTI_PROCESS).edit() .putInt("no_network_timeout", 5).commit(); v.setVisibility(View.GONE); } }); }
From source file:com.google.example.eightbitartist.DrawingActivity.java
@Override public void onInvitationReceived(final Invitation invitation) { Log.d(TAG, "onInvitationReceived:" + invitation); final String inviterName = invitation.getInviter().getDisplayName(); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this).setTitle("Invitation") .setMessage("Would you like to play a new game with " + inviterName + "?") .setNegativeButton("No", new DialogInterface.OnClickListener() { @Override/* w w w .java 2 s. c o m*/ public void onClick(DialogInterface dialog, int which) { Games.RealTimeMultiplayer.declineInvitation(mGoogleApiClient, invitation.getInvitationId()); } }).setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { acceptInvitation(invitation); } }); mAlertDialog = alertDialogBuilder.create(); mAlertDialog.show(); }
From source file:com.otaupdater.OTAUpdaterActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = getApplicationContext(); cfg = Config.getInstance(context);//www.j av a 2s .c om if (!cfg.hasProKey()) { bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), billingSrvConn = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { billingSrvConn = null; } @Override public void onServiceConnected(ComponentName name, IBinder binder) { IInAppBillingService service = IInAppBillingService.Stub.asInterface(binder); try { Bundle owned = service.getPurchases(3, getPackageName(), "inapp", null); ArrayList<String> ownedItems = owned.getStringArrayList("INAPP_PURCHASE_ITEM_LIST"); ArrayList<String> ownedItemData = owned .getStringArrayList("INAPP_PURCHASE_DATA_LIST"); if (ownedItems != null && ownedItemData != null) { for (int q = 0; q < ownedItems.size(); q++) { if (ownedItems.get(q).equals(Config.PROKEY_SKU)) { JSONObject itemData = new JSONObject(ownedItemData.get(q)); cfg.setKeyPurchaseToken(itemData.getString("purchaseToken")); break; } } } } catch (RemoteException ignored) { } catch (JSONException e) { e.printStackTrace(); } unbindService(this); billingSrvConn = null; } }, Context.BIND_AUTO_CREATE); } 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); if (!PropUtils.isRomOtaEnabled() && !PropUtils.isKernelOtaEnabled() && !cfg.getIgnoredUnsupportedWarn()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.alert_unsupported_title); builder.setMessage(R.string.alert_unsupported_message); builder.setCancelable(false); builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cfg.setIgnoredUnsupportedWarn(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(); } setContentView(R.layout.main); Fragment adFragment = getFragmentManager().findFragmentById(R.id.ads); if (adFragment != null) getFragmentManager().beginTransaction().hide(adFragment).commit(); 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.mobicage.rogerthat.registration.RegistrationActivity2.java
@Override protected void onServiceBound() { T.UI();//from w w w.j av a 2 s.c o m if (mNotYetProcessedIntent != null) { processIntent(mNotYetProcessedIntent); mNotYetProcessedIntent = null; } setContentView(R.layout.registration2); //Apply Fonts TextUtils.overrideFonts(this, findViewById(android.R.id.content)); final Typeface faTypeFace = Typeface.createFromAsset(getAssets(), "FontAwesome.ttf"); final int[] visibleLogos; final int[] goneLogos; if (AppConstants.FULL_WIDTH_HEADERS) { visibleLogos = FULL_WIDTH_ROGERTHAT_LOGOS; goneLogos = NORMAL_WIDTH_ROGERTHAT_LOGOS; View viewFlipper = findViewById(R.id.registration_viewFlipper); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) viewFlipper.getLayoutParams(); params.setMargins(0, 0, 0, 0); } else { visibleLogos = NORMAL_WIDTH_ROGERTHAT_LOGOS; goneLogos = FULL_WIDTH_ROGERTHAT_LOGOS; } for (int id : visibleLogos) findViewById(id).setVisibility(View.VISIBLE); for (int id : goneLogos) findViewById(id).setVisibility(View.GONE); handleScreenOrientation(getResources().getConfiguration().orientation); ScrollView rc = (ScrollView) findViewById(R.id.registration_container); Resources resources = getResources(); if (CloudConstants.isRogerthatApp()) { rc.setBackgroundColor(resources.getColor(R.color.mc_page_dark)); } else { rc.setBackgroundColor(resources.getColor(R.color.mc_homescreen_background)); } TextView rogerthatWelcomeTextView = (TextView) findViewById(R.id.rogerthat_welcome); TextView tosTextView = (TextView) findViewById(R.id.registration_tos); Typeface FONT_THIN_ITALIC = Typeface.createFromAsset(getAssets(), "fonts/lato_light_italic.ttf"); tosTextView.setTypeface(FONT_THIN_ITALIC); tosTextView.setTextColor(ContextCompat.getColor(RegistrationActivity2.this, R.color.mc_words_color)); Button agreeBtn = (Button) findViewById(R.id.registration_agree_tos); TextView tvRegistration = (TextView) findViewById(R.id.registration); tvRegistration.setText(getString(R.string.registration_city_app_sign_up, getString(R.string.app_name))); mEnterEmailAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.registration_enter_email); if (CloudConstants.isEnterpriseApp()) { rogerthatWelcomeTextView .setText(getString(R.string.rogerthat_welcome_enterprise, getString(R.string.app_name))); tosTextView.setVisibility(View.GONE); agreeBtn.setText(R.string.start_registration); mEnterEmailAutoCompleteTextView.setHint(R.string.registration_enter_email_hint_enterprise); } else { rogerthatWelcomeTextView .setText(getString(R.string.registration_welcome_text, getString(R.string.app_name))); tosTextView.setText(Html.fromHtml( "<a href=\"" + CloudConstants.TERMS_OF_SERVICE_URL + "\">" + tosTextView.getText() + "</a>")); tosTextView.setMovementMethod(LinkMovementMethod.getInstance()); agreeBtn.setText(R.string.registration_btn_agree_tos); mEnterEmailAutoCompleteTextView.setHint(R.string.registration_enter_email_hint); } agreeBtn.getBackground().setColorFilter(Message.GREEN_BUTTON_COLOR, PorterDuff.Mode.MULTIPLY); agreeBtn.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { sendRegistrationStep(RegistrationWizard2.REGISTRATION_STEP_AGREED_TOS); mWiz.proceedToNextPage(); } }); initLocationUsageStep(faTypeFace); View.OnClickListener emailLoginListener = new View.OnClickListener() { @Override public void onClick(View v) { sendRegistrationStep(RegistrationWizard2.REGISTRATION_STEP_EMAIL_LOGIN); mWiz.proceedToNextPage(); } }; findViewById(R.id.login_via_email).setOnClickListener(emailLoginListener); Button facebookButton = (Button) findViewById(R.id.login_via_fb); View.OnClickListener facebookLoginListener = new View.OnClickListener() { @Override public void onClick(View v) { // Check network connectivity if (!mService.getNetworkConnectivityManager().isConnected()) { UIUtils.showNoNetworkDialog(RegistrationActivity2.this); return; } sendRegistrationStep(RegistrationWizard2.REGISTRATION_STEP_FACEBOOK_LOGIN); FacebookUtils.ensureOpenSession(RegistrationActivity2.this, AppConstants.PROFILE_SHOW_GENDER_AND_BIRTHDATE ? Arrays.asList("email", "user_friends", "user_birthday") : Arrays.asList("email", "user_friends"), PermissionType.READ, new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { if (session != Session.getActiveSession()) { session.removeCallback(this); return; } if (exception != null) { session.removeCallback(this); if (!(exception instanceof FacebookOperationCanceledException)) { L.bug("Facebook SDK error during registration", exception); AlertDialog.Builder builder = new AlertDialog.Builder( RegistrationActivity2.this); builder.setMessage(R.string.error_please_try_again); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } } else if (session.isOpened()) { session.removeCallback(this); if (session.getPermissions().contains("email")) { registerWithAccessToken(session.getAccessToken()); } else { AlertDialog.Builder builder = new AlertDialog.Builder( RegistrationActivity2.this); builder.setMessage(R.string.facebook_registration_email_missing); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } } } }, false); } ; }; facebookButton.setOnClickListener(facebookLoginListener); final Button getAccountsButton = (Button) findViewById(R.id.get_accounts); if (configureEmailAutoComplete()) { // GET_ACCOUNTS permission is granted getAccountsButton.setVisibility(View.GONE); } else { getAccountsButton.setTypeface(faTypeFace); getAccountsButton.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { ActivityCompat.requestPermissions(RegistrationActivity2.this, new String[] { Manifest.permission.GET_ACCOUNTS }, PERMISSION_REQUEST_GET_ACCOUNTS); } }); } mEnterPinEditText = (EditText) findViewById(R.id.registration_enter_pin); mEnterPinEditText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (s.length() == PIN_LENGTH) onPinEntered(); } }); Button requestNewPinButton = (Button) findViewById(R.id.registration_request_new_pin); requestNewPinButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mWiz.setEmail(null); hideNotification(); mWiz.reInit(); mWiz.goBackToPrevious(); mEnterEmailAutoCompleteTextView.setText(""); } }); mWiz = RegistrationWizard2.getWizard(mService); mWiz.setFlipper((ViewFlipper) findViewById(R.id.registration_viewFlipper)); setFinishHandler(); addAgreeTOSHandler(); addIBeaconUsageHandler(); addChooseLoginMethodHandler(); addEnterPinHandler(); mWiz.run(); mWiz.setDeviceId(Installation.id(this)); handleEnterEmail(); if (mWiz.getBeaconRegions() != null && mBeaconManager == null) { bindBeaconManager(); } if (CloudConstants.USE_GCM_KICK_CHANNEL && GoogleServicesUtils.checkPlayServices(this, true)) { GoogleServicesUtils.registerGCMRegistrationId(mService, new GCMRegistrationIdFoundCallback() { @Override public void idFound(String registrationId) { mGCMRegistrationId = registrationId; } }); } }
From source file:com.balakrish.gpstracker.WaypointsListActivity.java
/** * Delete waypoint by id with confirmation dialog * /*from w w w.j a v a 2 s. c om*/ * @param wpid */ private void deleteWaypoint(long wpid) { final long waypointId = wpid; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.are_you_sure).setCancelable(true) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // delete waypoint from db Waypoints.delete(app.getDatabase(), waypointId); // cursor.requery(); updateWaypointsArray(); waypointsArrayAdapter.setItems(waypoints); waypointsArrayAdapter.notifyDataSetChanged(); Toast.makeText(WaypointsListActivity.this, R.string.waypoint_deleted, Toast.LENGTH_SHORT) .show(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:com.vegnab.vegnab.MainVNActivity.java
void alert(String message) { AlertDialog.Builder bld = new AlertDialog.Builder(this); bld.setMessage(message);/*from w w w .j a v a 2 s. c o m*/ bld.setNeutralButton("OK", null); if (LDebug.ON) Log.d(LOG_TAG, "Showing alert dialog: " + message); bld.create().show(); }
From source file:com.paramonod.kikos.MainActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); FirebaseDatabase.getInstance().setPersistenceEnabled(true); myRef = FirebaseDatabase.getInstance().getReference("Shops"); //ShopInterface shopInterface = new ShopInterface("asas","qaqa","wdwdwd","12","11","11"); //myRef.child("Shops").child("1").setValue(shopInterface); //mAuth.signInAnonymously(); myRef.keepSynced(true);//from w ww . ja v a2 s .c o m myRef.orderByValue().addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot snapshot, String previousChild) { Log.e("here", Integer.toString(shopInterfaces.size() - 1)); shopInterfaces.add(snapshot.getValue(ShopInterface.class)); Log.e("here", Integer.toString(shopInterfaces.size() - 1)); main.setupMap(); //System.out.println(shopInterfaces.get(1).getCoordX()); } @Override public void onChildChanged(DataSnapshot dataSnapshot, String s) { } @Override public void onChildRemoved(DataSnapshot dataSnapshot) { } @Override public void onChildMoved(DataSnapshot dataSnapshot, String s) { } @Override public void onCancelled(DatabaseError databaseError) { } }); //mAuth.signOut(); main = this; setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); toolbar.setTitle("OrgShop"); DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); final Display display = getWindowManager().getDefaultDisplay(); android.graphics.Point size = new android.graphics.Point(); display.getSize(size); X = size.x; Y = size.y; // Y = displaymetrics.heightPixels; // X = displaymetrics.widthPixels; System.out.println(X + " " + Y); // Adding Toolbar to Main screen int ii = 0; places.clear(); while (true) { String connectionsJSONString = getPreferences(MODE_PRIVATE).getString("places" + ii, null); Pair p = new Gson().fromJson(connectionsJSONString, Pair.class); if (p != null) places.add(p); else break; ii++; } placesIDX = ii; bottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation); Manager.findFragmentById(R.id.fragment1); bottomNavigationView .setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { //AsyncTask asyncTask = new NewAsyncTask(); switch (item.getItemId()) { case R.id.Map: // Manager.beginTransaction() // .replace(R.id.fragment1, PrFr) // .commit(); Manager.beginTransaction().replace(R.id.fragment1, MapFr).addToBackStack("Map") .commit(); //asyncTask.execute(R.id.Map); break; case R.id.Shops: // Manager.beginTransaction() // .replace(R.id.fragment1, PrFr) // .commit(); // Listfr.flag = 0; Manager.beginTransaction().replace(R.id.fragment1, CatFr).addToBackStack("Categories") .commit(); //x = R.id.Shops; //asyncTask.execute(); break; case R.id.Third: // Manager.beginTransaction() // .replace(R.id.fragment1, PrFr) // .commit(); // Manager.beginTransaction() // .replace(R.id.fragment1, PrFr) // .commit(); // System.out.println(0); int idx[] = new int[shopInterfaces.size()]; for (int i = 0; i < idx.length; i++) { idx[i] = i; } try { updateMyLoc(); idx = sortArraywithGeo(idx, myLoc); } catch (Exception e) { e.printStackTrace(); } CardContentFragment.flag = 1; CardContentFragment.idx = idx; Manager.beginTransaction().replace(R.id.fragment1, Cardfr).addToBackStack(null) .commit(); //new ImageLoad().execute(); //while (AsyncTest == 0){} //System.out.println(1); //Picturex(); //AsyncTest = -1; /* Manager.beginTransaction() .replace(R.id.fragment1, Listfr) .commit(); */ // asyncTask.execute(R.id.Third); break; } return false; } }); // Setting ViewPager for each Tabs // Set Tabs inside Toolbar // Create Navigation drawer and inlfate layout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); // Adding menu icon to Toolbar ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme()); indicator.setTint(ResourcesCompat.getColor(getResources(), R.color.white, getTheme())); supportActionBar.setHomeAsUpIndicator(indicator); supportActionBar.setDisplayHomeAsUpEnabled(true); } //Set behavior of Navigation drawer navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setCheckedItem(R.id.mapButton); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override public boolean onNavigationItemSelected(MenuItem menuItem) { // Set item in checked state menuItem.setChecked(true); if (menuItem.getItemId() == R.id.favorite_button) { sPref = getPreferences(MODE_PRIVATE); String savedText = sPref.getString("q", ""); boolean w = true; for (int i = 0; i < 10; i++) { if (savedText.contains(Integer.toString(i))) { w = false; } } if (w) { Toast.makeText(main, " ? ", Toast.LENGTH_LONG).show(); SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit(); editor.putString("q", ""); editor.commit(); } else { String[] q = savedText.split(" "); int[] a = new int[q.length]; for (int i = 0; i < q.length; i++) { a[i] = Integer.parseInt(q[i]); System.out.println(a[i]); } try { updateMyLoc(); a = sortArraywithGeo(a, myLoc); } catch (Exception e) { e.printStackTrace(); } ListContentFragment l = new ListContentFragment(); l.flag = 1; l.idx = a; // Manager.beginTransaction() // .replace(R.id.fragment1, PrFr) // .commit(); Manager.beginTransaction().replace(R.id.fragment1, l).addToBackStack("favorite").commit(); } } if (menuItem.getItemId() == R.id.mapButton) { // Manager.beginTransaction() // .replace(R.id.fragment1, PrFr) // .commit(); Manager.beginTransaction().replace(R.id.fragment1, MapFr).addToBackStack("map").commit(); } if (menuItem.getItemId() == R.id.clear_button) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("").setMessage( "? ? ?? ? ? aka KiKoS, aka paramomnod") .setIcon(R.drawable.itkerk).setCancelable(false) .setNegativeButton(" :)", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } if (menuItem.getItemId() == R.id.login_button) { int ii = 0; places.clear(); while (true) { String connectionsJSONString = getPreferences(MODE_PRIVATE).getString("places" + ii, null); Pair p = new Gson().fromJson(connectionsJSONString, Pair.class); if (p != null) places.add(p); else break; ii++; } if (places.size() == 0) { Toast.makeText(main, " ? ?", Toast.LENGTH_LONG).show(); } else { String q[] = new String[places.size()]; for (int i = 0; i < q.length; i++) { q[i] = places.get(i).first; } new AlertDialog.Builder(main).setSingleChoiceItems(q, 0, null) .setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); int selectedPosition = ((AlertDialog) dialog).getListView() .getCheckedItemPosition(); Pair p = places.get(selectedPosition); GeoPoint geo = p.second; int[] idx = new int[shopInterfaces.size()]; for (int i = 0; i < idx.length; i++) { idx[i] = i; } idx = sortArraywithGeo(idx, geo); CardContentFragment c = new CardContentFragment(); CardContentFragment.flag = 1; CardContentFragment.idx = idx; Manager.beginTransaction().replace(R.id.fragment1, c).addToBackStack("map") .commit(); } }).setNegativeButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); int selectedPosition = ((AlertDialog) dialog).getListView() .getCheckedItemPosition(); places.remove(selectedPosition); placesIDX--; for (int i = 0; i < placesIDX; i++) { SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit(); String connectionsJSONString1 = new Gson().toJson(places.get(i)); editor.putString("places" + i, connectionsJSONString1); editor.commit(); } SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit(); editor.putString("places" + placesIDX, null); editor.commit(); } }).show(); } } /* if (menuItem.getItemId() == R.id.login_button) { if (mAuth.getCurrentUser() == null) { startActivity(new Intent(MainActivity.this, LoginActivity.class)); } else { startActivity(new Intent(MainActivity.this, AccountActivity.class)); } } */ // Closing drawer on item click mDrawerLayout.closeDrawers(); return true; } }); // Adding Floating Action Button to bottom right of main view /*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Snackbar.make(v, "Hello Snackbar!", Snackbar.LENGTH_LONG).show(); } });*/ Manager.beginTransaction().replace(R.id.fragment1, MapFr).commit(); }
From source file:ota.otaupdates.MainActivity.java
private void trigger_autoinstall(final String file_path) { final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); final CoordinatorLayout coordinator_root = (CoordinatorLayout) findViewById(R.id.coordinator_root); if (sharedPreferences.getBoolean("enable_auto_install", true)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.auto_install_title)); builder.setMessage(getString(R.string.auto_install_message)); builder.setPositiveButton(getString(R.string.button_yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (Shell.SU.available()) { Shell.SU.run("rm -rf /cache/recovery/openrecoveryscript"); Shell.SU.run("echo \"install " + file_path + "\" >> /cache/recovery/openrecoveryscript"); if (sharedPreferences.getBoolean("wipe_cache", true)) Shell.SU.run("echo \"wipe cache\" >> /cache/recovery/openrecoveryscript"); if (sharedPreferences.getBoolean("wipe_dalvik", true)) Shell.SU.run("echo \"wipe dalvik\" >> /cache/recovery/openrecoveryscript"); if (sharedPreferences.getBoolean("auto_reboot", true)) Shell.SU.run("reboot recovery"); } else { sb_no_su = Snackbar.make(coordinator_root, "SU access is not available", Snackbar.LENGTH_SHORT); sb_no_su.getView()/*from w ww .j ava2 s . c om*/ .setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorSecond)); sb_no_su.show(); } } }); builder.setNegativeButton(getString(R.string.button_no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); AlertDialog alert = builder.create(); alert.setCancelable(false); alert.show(); } }
From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java
public void openDialog() { // get prompts.xml view LayoutInflater li = LayoutInflater.from(GetAllVehicalDetails.this); View promptsView = li.inflate(R.layout.prompt, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(GetAllVehicalDetails.this); // set prompts.xml to alertdialog builder alertDialogBuilder.setView(promptsView); alertDialogBuilder.setTitle("Why you want to stop this"); final EditText userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput); // 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 //result.setText(userInput.getText()); if (!userInput.getText().toString().trim().isEmpty()) { reason = userInput.getText().toString().trim(); getUserData(reason);/*w w w .ja v a 2 s.c o m*/ } else { Toast.makeText(GetAllVehicalDetails.this, "Please fill your reason", Toast.LENGTH_LONG).show(); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }
From source file:com.balakrish.gpstracker.WaypointsListActivity.java
/** * // ww w.j a v a2 s . co m */ @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.deleteWaypointsMenuItem: // clear all waypoints with confirmation dialog AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.are_you_sure).setCancelable(true) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { Waypoints.deleteAll(app.getDatabase()); updateWaypointsArray();// cursor.requery(); waypointsArrayAdapter.setItems(waypoints); waypointsArrayAdapter.notifyDataSetChanged(); Toast.makeText(WaypointsListActivity.this, R.string.all_waypoints_deleted, Toast.LENGTH_SHORT).show(); } }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); return true; // import waypoints from external file case R.id.importMenuItem: // this.importFromTextFile(); this.importFromXMLFile(); return true; case R.id.exportMenuItem: exportWaypoints(); return true; case R.id.showMapMenuItem: // startActivity(new Intent(this, WaypointsMapActivity.class)); Intent i = new Intent(this, MyMapActivity.class); // using Bundle to pass track id into new activity Bundle b = new Bundle(); b.putInt("mode", Constants.SHOW_ALL_WAYPOINTS); i.putExtras(b); startActivity(i); return true; default: return super.onOptionsItemSelected(item); } }