List of usage examples for android.app AlertDialog dismiss
@Override public void dismiss()
From source file:com.juick.android.MessageMenu.java
protected void runActions() { if (!isDialogMode()) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); final CharSequence[] items = new CharSequence[menuActions.size()]; for (int j = 0; j < items.length; j++) { items[j] = menuActions.get(j).title; }/* w ww .ja v a 2 s. c om*/ builder.setItems(items, this); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity); ColorDrawable divider = new ColorDrawable( colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF)); alertDialog.getListView().setDivider(divider); alertDialog.getListView().setDividerHeight(1); } }); alertDialog.show(); final ListAdapter adapter = alertDialog.getListView().getAdapter(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final boolean compressedMenu = sp.getBoolean("compressedMenu", false); final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false); final float finalMenuFontScale = menuFontScale; final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight(); alertDialog.getListView().setAdapter(new ListAdapter() { @Override public boolean areAllItemsEnabled() { return adapter.areAllItemsEnabled(); } @Override public boolean isEnabled(int position) { return adapter.isEnabled(position); } @Override public void registerDataSetObserver(DataSetObserver observer) { adapter.registerDataSetObserver(observer); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { adapter.unregisterDataSetObserver(observer); } @Override public int getCount() { return items.length; } @Override public Object getItem(int position) { return adapter.getItem(position); } @Override public long getItemId(int position) { return adapter.getItemId(position); } @Override public boolean hasStableIds() { return adapter.hasStableIds(); } @Override public View getView(int position, View convertView, ViewGroup parent) { View retval = adapter.getView(position, null, parent); if (retval instanceof TextView) { TextView tv = (TextView) retval; if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } if (singleLineMenu) { tv.setSingleLine(true); tv.setEllipsize(TextUtils.TruncateAt.MIDDLE); } tv.setTextSize(22 * finalMenuFontScale); } return retval; } @Override public int getItemViewType(int position) { return adapter.getItemViewType(position); } @Override public int getViewTypeCount() { return adapter.getViewTypeCount(); } @Override public boolean isEmpty() { return adapter.isEmpty(); } }); } else { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(activity, R.style.Theme_Sherlock)); View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null); builder.setView(dialogView); builder.setCancelable(true); int width = activity.getWindowManager().getDefaultDisplay().getWidth(); View scrollView = dialogView.findViewById(R.id.scrollView); scrollView.getLayoutParams().width = (int) (width * 0.90); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView()); } }); TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no); messageNo.setText(listSelectedItem.getDisplayMessageNo()); Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url); Button singleURL = (Button) dialogView.findViewById(R.id.single_url); if (urls != null && urls.size() == 1) { singleURL.setVisibility(View.VISIBLE); openUrl.setVisibility(View.GONE); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(0)); sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); singleURL.setText(sb); singleURL.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(0)); } }); } else if (urls != null && urls.size() > 0) { singleURL.setVisibility(View.GONE); openUrl.setVisibility(View.VISIBLE); openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(position)); } } @Override public void onNothingSelected(AdapterView<?> parent) { //To change body of implemented methods use File | Settings | File Templates. } }); urls.add(0, activity.getString(R.string.ClickToSelectURL)); openUrl.setAdapter(new BaseAdapter() { @Override public int getCount() { return urls.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView textView = (TextView) rowView.findViewById(android.R.id.text1); textView.setSingleLine(false); textView.setMaxLines(5); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(position)); if (position == 0) { textView.setTextColor(0xFF808080); } else { sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } textView.setText(sb); return rowView; } }); } else { openUrl.setVisibility(View.GONE); singleURL.setVisibility(View.GONE); } final String UName = listSelectedItem.User.UName; View recommendMessage = dialogView.findViewById(R.id.recommend_message); View deleteMessage = dialogView.findViewById(R.id.delete_message); View saveMessage = dialogView.findViewById(R.id.save_message); View unsaveMessage = dialogView.findViewById(R.id.unsave_message); //View subscribeUser = dialogView.findViewById(R.id.subscribe_user); View subscribeMessage = dialogView.findViewById(R.id.subscribe_message); //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user); View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message); View translateMessage = dialogView.findViewById(R.id.translate_message); View shareMessage = dialogView.findViewById(R.id.share_message); //View blacklistUser = dialogView.findViewById(R.id.blacklist_user); //View filterUser = dialogView.findViewById(R.id.filter_user); //View userBlog = dialogView.findViewById(R.id.user_blog); //View userStats = dialogView.findViewById(R.id.user_stats); View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser); Button userCenter = (Button) dialogView.findViewById(R.id.user_center); if (null == dialogView.findViewById(R.id.column_3)) { // only for portrait userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText()); } unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0); subscribeMessage.setEnabled(listSelectedItem.getRID() == 0); unsaveMessage.setEnabled(listSelectedItem.getRID() == 0); recommendMessage.setEnabled(listSelectedItem.getRID() == 0); if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) { recommendMessage.setVisibility(View.GONE); } else { deleteMessage.setVisibility(View.GONE); } if (messagesSource instanceof SavedMessagesSource) { saveMessage.setVisibility(View.GONE); } else { unsaveMessage.setVisibility(View.GONE); } recommendMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionRecommendMessage(); } }); deleteMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionDeleteMessage(); } }); saveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSaveMessage(); } }); unsaveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsaveMessage(); } }); // subscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionSubscribeUser(); // } // }); subscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSubscribeMessage(); } }); // unsubscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUnsubscribeUser(); // } // }); unsubscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsubscribeMessage(); } }); translateMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionTranslateMessage(); } }); shareMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionShareMessage(); } }); // blacklistUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionBlacklistUser(); // } // }); // filterUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionFilterUser(UName); // } // }); // userBlog.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserBlog(); // } // }); // userStats.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserStats(); // } // }); openMessageInBrowser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionOpenMessageInBrowser(); } }); userCenter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUserCenter(); } }); completeInitDialogMode(alertDialog, dialogView); alertDialog.show(); } }
From source file:it.unipr.ce.dsg.gamidroid.activities.NAM4JAndroidActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); context = this; isTablet = Utils.isTablet(this); // Setting the default network sharedPreferences = getSharedPreferences(Constants.PREFERENCES, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putString(Constants.NETWORK, Constants.DEFAULT_NETWORK); editor.commit();/*from w w w . jav a 2 s.co m*/ // Starting the resources monitoring service startService(new Intent(this, DeviceMonitorService.class)); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); // Settings menu elements ArrayList<MenuListElement> listElements = new ArrayList<MenuListElement>(); listElements.add(new MenuListElement(getResources().getString(R.string.connectMenuTitle), getResources().getString(R.string.connectMenuSubTitle))); listElements.add(new MenuListElement(getResources().getString(R.string.settingsMenuTitle), getResources().getString(R.string.settingsMenuSubTitle))); listElements.add(new MenuListElement(getResources().getString(R.string.exitMenuTitle), getResources().getString(R.string.exitMenuSubTitle))); listView = (ListView) findViewById(R.id.ListViewContent); MenuListAdapter adapter = new MenuListAdapter(this, R.layout.menu_list_view_row, listElements); listView.setAdapter(adapter); listView.setOnItemClickListener(new ListItemClickListener()); mainRL = (RelativeLayout) findViewById(R.id.rlContainer); listRL = (RelativeLayout) findViewById(R.id.listContainer); cpuBar = (LinearLayout) findViewById(R.id.CpuBar); memoryBar = (LinearLayout) findViewById(R.id.MemoryBar); titleBarRL = (RelativeLayout) findViewById(R.id.titleLl); // Adding swipe gesture listener to the top bar titleBarRL.setOnTouchListener(new SwipeAndClickListener()); menuButton = (Button) findViewById(R.id.menuButton); menuButton.setOnTouchListener(new SwipeAndClickListener()); infoButton = (Button) findViewById(R.id.infoButton); infoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog dialog = new AlertDialog(NAM4JAndroidActivity.this) { @Override public boolean dispatchTouchEvent(MotionEvent event) { dismiss(); return false; } }; String text = getResources().getString(R.string.aboutApp); String title = getResources().getString(R.string.nam4j); dialog.setMessage(text); dialog.setTitle(title); dialog.setCanceledOnTouchOutside(true); dialog.show(); } }); centerButton = (Button) findViewById(R.id.centerButton); centerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { centerMap(); } }); isTablet = Utils.isTablet(context); int[] screenSize = Utils.getScreenSize(context, getWindow()); screenWidth = screenSize[0]; screenHeight = screenSize[1]; // Updates the display orientation each time the device is rotated if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { screenOrientation = Orientation.LANDSCAPE; } else { screenOrientation = Orientation.PORTRAIT; } // If the device is portrait, the menu button is displayed, the menu is // hidden and the swipe listener is added to the menu bar if (screenOrientation == Orientation.PORTRAIT) { menuButton.setVisibility(View.VISIBLE); // Adding swipe gesture listener to the top bar titleBarRL.setOnTouchListener(new SwipeAndClickListener()); if (isTablet) { menuWidth = 0.35; } else { menuWidth = 0.6; } } else { // If the device is a tablet in landscape, the menu button is // hidden, the menu is displayed, the swipe listener is not added to // the menu bar and the mainRL width is set to the window's width // minus the menu's width if (isTablet) { menuWidth = 0.2; menuButton.setVisibility(View.INVISIBLE); RelativeLayout.LayoutParams menuListLP = (LayoutParams) mainRL.getLayoutParams(); // Setting the main view width as the container width without // the menu menuListLP.width = (int) (screenWidth * (1 - menuWidth)); mainRL.setLayoutParams(menuListLP); displaySideMenu(); } else { menuWidth = 0.4; menuButton.setVisibility(View.VISIBLE); // Adding swipe gesture listener to the top bar titleBarRL.setOnTouchListener(new SwipeAndClickListener()); } } // Check if the device has the Google Play Services installed and // updated. They are necessary to use Google Maps int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); if (code != ConnectionResult.SUCCESS) { showErrorDialog(code); System.out.println("Google Play Services error"); FrameLayout fl = (FrameLayout) findViewById(R.id.frameId); fl.removeAllViews(); } else { // Create a new global location parameters object mLocationRequest = new LocationRequest(); // Set the update interval mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS); // Use high accuracy mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Set the interval ceiling to one minute mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS); bitmapDescriptorBlue = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE); blueCircle = BitmapDescriptorFactory .fromBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.blue_circle)); bitmapDescriptorRed = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED); // Create a new location client, using the enclosing class to handle // callbacks mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapview)).getMap(); if (map != null) { // Set default map center and zoom on Parma double lat = 44.7950156; double lgt = 10.32547; map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lgt), 12.0f)); // Adding listeners to the map respectively for zoom level // change and onTap event map.setOnCameraChangeListener(getCameraChangeListener()); map.setOnMapClickListener(getOnMapClickListener()); // Set map type as normal (i.e. not the satellite view) map.setMapType(com.google.android.gms.maps.GoogleMap.MAP_TYPE_NORMAL); // Hide traffic layer map.setTrafficEnabled(false); // Enable the 'my-location' layer, which continuously draws an // indication of a user's current location and bearing, and // displays UI controls that allow the interaction with the // location itself // map.setMyLocationEnabled(true); ml = new HashMap<String, Marker>(); // Get file manager for config files fileManager = FileManager.getFileManager(); fileManager.createFiles(); map.setOnMarkerClickListener(this); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setMessage("The map cannot be initialized."); dialog.setCancelable(true); dialog.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); dialog.show(); } } }