List of usage examples for android.app AlertDialog.Builder setView
public void setView(View view)
From source file:com.example.android.lightcontrol.MainActivity.java
private void fadetime() { LayoutInflater inflater = LayoutInflater.from(this); final View v = inflater.inflate(R.layout.fadetime, null); final AlertDialog.Builder dialog = new AlertDialog.Builder(this); Spinner fade_time = (Spinner) v.findViewById(R.id.fade_time); ArrayAdapter<String> fadetimelist; final String[] fadetime = { "No Fade Time", "0.7sec", "1sec", "1.4sec", "2sec", "2.8sec", "4sec" }; fadetimelist = new ArrayAdapter<String>(this, R.layout.my_spinner, fadetime); fade_time.setAdapter(fadetimelist);/* ww w. j a v a2 s.c o m*/ fade_time.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (fadetime[i].equals("No Fade Time")) { GlobalVariable.fade_time = "00"; GlobalVariable.t = 50; } if (fadetime[i].equals("0.7sec")) { GlobalVariable.fade_time = "01"; GlobalVariable.t = 700; } if (fadetime[i].equals("1sec")) { GlobalVariable.fade_time = "02"; GlobalVariable.t = 1000; } if (fadetime[i].equals("1.4sec")) { GlobalVariable.fade_time = "03"; GlobalVariable.t = 1400; } if (fadetime[i].equals("2sec")) { GlobalVariable.fade_time = "04"; GlobalVariable.t = 2000; } if (fadetime[i].equals("2.8sec")) { GlobalVariable.fade_time = "05"; GlobalVariable.t = 2800; } if (fadetime[i].equals("4sec")) { GlobalVariable.fade_time = "06"; GlobalVariable.t = 4000; } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); dialog.setCancelable(false); dialog.setTitle(R.string.about_title); dialog.setView(v); dialog.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { //aa 55 07 01 00 00 00 de 00 xx chk String send_mode_1 = GlobalVariable.by1_AA + GlobalVariable.by2_55 + "07" + GlobalVariable.by4_01 + "00" + "00" + "00" + "de" + "00" + GlobalVariable.fade_time; int checksum = ((Integer.parseInt(GlobalVariable.by1_AA, 16)) + (Integer.parseInt(GlobalVariable.by2_55, 16)) + (Integer.parseInt("07", 16)) + (Integer.parseInt(GlobalVariable.by4_01, 16)) + (Integer.parseInt("de", 16)) // + (Integer.parseInt(GlobalVariable.OnSpinnerItemSelectedOfShort.substring(0, 2), 16)) // + (Integer.parseInt(GlobalVariable.OnSpinnerItemSelectedOfShort.substring(2, 4), 16)) + (Integer.parseInt(GlobalVariable.fade_time, 16))) % 256; if (D) Log.e(TAG, "checksum" + checksum); String send_group_on1 = send_mode_1 + Integer.toHexString(checksum); if (D) Log.e(TAG, "send_group_on1" + send_group_on1); sendMessage(send_group_on1); try { Thread.sleep(150); } catch (InterruptedException ignored) { } } }); dialog.show(); }
From source file:com.guardtrax.ui.screens.HomeScreen.java
private void displaytourInfo() { String message = ""; int i = 0;/*from ww w. j a va2 s .c om*/ int tagCount = 0; boolean singleDisplay = false; //indicates that only 1 item is to be displayed in the tour list List<Boolean> tourtagsIncluded = new ArrayList<Boolean>(); List<Boolean> tourtagsScanned = new ArrayList<Boolean>(); List<Integer> tourOrder = new ArrayList<Integer>(); List<String> messageList = new ArrayList<String>(); //check if this is a single display (second last character of tour name is a space) singleDisplay = isSingleRandomTour(); tourDB.open(); Cursor c = tourDB.getRecordByTour(GTConstants.tourName); if (c != null && c.moveToFirst()) { tourtagsScanned = refreshtourtagList(c.getCount(), false, true, false, false); tourtagsIncluded = refreshtourtagList(c.getCount(), false, false, true, false); tourOrder = gettourOrder(c.getCount()); //initialize the message array which wil be used to display the messages in the random order while (messageList.size() < c.getCount()) messageList.add(""); for (i = 0; i < c.getCount(); i++) { if (tourtagsScanned.get(i) && tourtagsIncluded.get(i) && !singleDisplay) messageList.add(tourOrder.get(i), "<br><font color='#00FF00'>" + c.getString(2) + "</font><br/>"); else if (!tourtagsScanned.get(i) && !Utility.istourOntime(tourEnd) && Utility.getcurrentState().equals(GTConstants.onShift) && tourtagsIncluded.get(i) && !singleDisplay) messageList.add(tourOrder.get(i), "<br><font color='#FF0000'>" + c.getString(2) + "</font><br/>"); else if (!tourtagsScanned.get(i) && tourtagsIncluded.get(i) && !singleDisplay) messageList.add(tourOrder.get(i), "<br><font color='#FFFFFF'>" + c.getString(2) + "</font><br/>"); else if (singleDisplay && i == touritemNumber) messageList.add(tourOrder.get(i), "<br><font color='#FFFFFF'>" + c.getString(2) + "</font><br/>"); //get the number of tags included if (tourtagsIncluded.get(i)) tagCount++; c.moveToNext(); } } tourDB.close(); //create the message string for (i = 0; i < messageList.size(); i++) if (messageList.get(i).length() > 1) message = message + messageList.get(i); LayoutInflater inflater = LayoutInflater.from(HomeScreen.this); View view = inflater.inflate(R.layout.scroll_dialog, null); TextView textview = (TextView) view.findViewById(R.id.dialogtext); textview.setText(Html.fromHtml(message)); AlertDialog.Builder alertDialog = new AlertDialog.Builder(HomeScreen.this); //create custom title TextView title = new TextView(HomeScreen.this); //if this is a single display tour then do not indicate how many tags are in the tour if (isSingleRandomTour()) //this is a single display tour title.setText(GTConstants.tourName + CRLF + tourTime + CRLF); else title.setText(GTConstants.tourName + CRLF + tourTime + CRLF + String.valueOf(tagCount) + " Tags"); title.setPadding(10, 10, 10, 10); title.setGravity(Gravity.CENTER); title.setTextColor(Color.parseColor("#79ABFF")); title.setTextSize(20); alertDialog.setCustomTitle(title); //alertDialog.setTitle(tourName + CRLF + String.valueOf(i-1) + " Tags"); alertDialog.setView(view); alertDialog.setPositiveButton("OK", null); AlertDialog alert = alertDialog.create(); alert.show(); }
From source file:com.irccloud.android.activity.MainActivity.java
public void onIRCEvent(int what, Object obj) { super.onIRCEvent(what, obj); Integer event_bid = 0;//from ww w . j ava 2 s .c o m final IRCCloudJSONObject event; final Object o = obj; switch (what) { case NetworkConnection.EVENT_DEBUG: runOnUiThread(new Runnable() { @Override public void run() { errorMsg.setVisibility(View.VISIBLE); errorMsg.setText(o.toString()); } }); break; case NetworkConnection.EVENT_PROGRESS: final float progress = (Float) obj; if (progressBar.getProgress() < progress) { runOnUiThread(new Runnable() { @Override public void run() { progressBar.setIndeterminate(false); progressBar.setProgress((int) progress); } }); } break; case NetworkConnection.EVENT_BACKLOG_START: runOnUiThread(new Runnable() { @Override public void run() { progressBar.setProgress(0); } }); break; case NetworkConnection.EVENT_RENAMECONVERSATION: if (buffer != null && (Integer) obj == buffer.bid) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); } }); } break; case NetworkConnection.EVENT_CHANNELTOPICIS: event = (IRCCloudJSONObject) obj; if (buffer != null && buffer.cid == event.cid() && buffer.name.equalsIgnoreCase(event.getString("chan"))) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); show_topic_popup(); } }); } break; case NetworkConnection.EVENT_LINKCHANNEL: event = (IRCCloudJSONObject) obj; if (event != null && cidToOpen == event.cid() && event.has("invalid_chan") && event.has("valid_chan") && event.getString("invalid_chan").equalsIgnoreCase(bufferToOpen)) { bufferToOpen = event.getString("valid_chan"); obj = BuffersDataSource.getInstance().getBuffer(event.bid()); } else { bufferToOpen = null; return; } case NetworkConnection.EVENT_MAKEBUFFER: BuffersDataSource.Buffer b = (BuffersDataSource.Buffer) obj; if (cidToOpen == b.cid && (bufferToOpen == null || (b.name.equalsIgnoreCase(bufferToOpen) && (buffer == null || !bufferToOpen.equalsIgnoreCase(buffer.name))))) { server = null; final int bid = b.bid; runOnUiThread(new Runnable() { @Override public void run() { onBufferSelected(bid); } }); bufferToOpen = null; cidToOpen = -1; } break; case NetworkConnection.EVENT_OPENBUFFER: event = (IRCCloudJSONObject) obj; try { bufferToOpen = event.getString("name"); cidToOpen = event.cid(); b = BuffersDataSource.getInstance().getBufferByName(cidToOpen, bufferToOpen); if (b != null && !bufferToOpen.equalsIgnoreCase(buffer.name)) { server = null; bufferToOpen = null; cidToOpen = -1; final int bid = b.bid; runOnUiThread(new Runnable() { @Override public void run() { onBufferSelected(bid); } }); } } catch (Exception e2) { e2.printStackTrace(); } break; case NetworkConnection.EVENT_CONNECTIVITY: runOnUiThread(new Runnable() { @Override public void run() { updateReconnecting(); } }); if (conn != null) { if (conn.getState() == NetworkConnection.STATE_CONNECTED) { for (EventsDataSource.Event e : pendingEvents.values()) { try { e.expiration_timer.cancel(); } catch (Exception ex) { //Task already cancellled } e.expiration_timer = null; e.failed = true; e.bg_color = R.color.error; } if (drawerLayout != null && NetworkConnection.getInstance().ready) { runOnUiThread(new Runnable() { @Override public void run() { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); getSupportActionBar().setHomeButtonEnabled(true); updateUsersListFragmentVisibility(); } }); } if (server != null && messageTxt.getText() != null && messageTxt.getText().length() > 0) { runOnUiThread(new Runnable() { @Override public void run() { sendBtn.setEnabled(true); if (Build.VERSION.SDK_INT >= 11) sendBtn.setAlpha(1); } }); } } else { runOnUiThread(new Runnable() { @Override public void run() { if (drawerLayout != null && !NetworkConnection.getInstance().ready) { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); getSupportActionBar().setHomeButtonEnabled(false); } sendBtn.setEnabled(false); if (Build.VERSION.SDK_INT >= 11) sendBtn.setAlpha(0.5f); photoBtn.setEnabled(false); if (Build.VERSION.SDK_INT >= 11) photoBtn.setAlpha(0.5f); } }); } } break; case NetworkConnection.EVENT_BANLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { if (event != null && event.cid() == buffer.cid) { Bundle args = new Bundle(); args.putInt("cid", event.cid()); BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBufferByName(event.cid(), event.getString("channel")); if (b != null) args.putInt("bid", b.bid); args.putString("mode", "b"); args.putString("placeholder", "No bans in effect.\n\nYou can ban someone by tapping their nickname in the user list, long-pressing a message, or by using /ban."); args.putString("mask", "mask"); args.putString("list", "bans"); args.putString("title", "Ban list for " + event.getString("channel")); args.putString("event", event.toString()); ChannelModeListFragment channelModeList = (ChannelModeListFragment) getSupportFragmentManager() .findFragmentByTag("banlist"); if (channelModeList == null) { channelModeList = new ChannelModeListFragment(); channelModeList.setArguments(args); try { channelModeList.show(getSupportFragmentManager(), "banlist"); } catch (IllegalStateException e) { //App lost focus already } } else { channelModeList.setArguments(args); } } } }); break; case NetworkConnection.EVENT_QUIETLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { if (event != null && event.cid() == buffer.cid) { Bundle args = new Bundle(); args.putInt("cid", event.cid()); BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBufferByName(event.cid(), event.getString("channel")); if (b != null) args.putInt("bid", b.bid); args.putString("mode", "q"); args.putString("placeholder", "Empty quiet list."); args.putString("mask", "quiet_mask"); args.putString("list", "list"); args.putString("title", "Quiet list for " + event.getString("channel")); args.putString("event", event.toString()); ChannelModeListFragment channelModeList = (ChannelModeListFragment) getSupportFragmentManager() .findFragmentByTag("quietlist"); if (channelModeList == null) { channelModeList = new ChannelModeListFragment(); channelModeList.setArguments(args); try { channelModeList.show(getSupportFragmentManager(), "quietlist"); } catch (IllegalStateException e) { //App lost focus already } } else { channelModeList.setArguments(args); } } } }); break; case NetworkConnection.EVENT_BANEXCEPTIONLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { if (event != null && event.cid() == buffer.cid) { Bundle args = new Bundle(); args.putInt("cid", event.cid()); BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBufferByName(event.cid(), event.getString("channel")); if (b != null) args.putInt("bid", b.bid); args.putString("mode", "e"); args.putString("placeholder", "Empty exception list."); args.putString("mask", "mask"); args.putString("list", "exceptions"); args.putString("title", "Exception list for " + event.getString("channel")); args.putString("event", event.toString()); ChannelModeListFragment channelModeList = (ChannelModeListFragment) getSupportFragmentManager() .findFragmentByTag("exceptionlist"); if (channelModeList == null) { channelModeList = new ChannelModeListFragment(); channelModeList.setArguments(args); try { channelModeList.show(getSupportFragmentManager(), "exceptionlist"); } catch (IllegalStateException e) { //App lost focus already } } else { channelModeList.setArguments(args); } } } }); break; case NetworkConnection.EVENT_INVITELIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { if (event != null && event.cid() == buffer.cid) { Bundle args = new Bundle(); args.putInt("cid", event.cid()); BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBufferByName(event.cid(), event.getString("channel")); if (b != null) args.putInt("bid", b.bid); args.putString("mode", "I"); args.putString("placeholder", "Empty invite list"); args.putString("mask", "mask"); args.putString("list", "list"); args.putString("title", "Invite list for " + event.getString("channel")); args.putString("event", event.toString()); ChannelModeListFragment channelModeList = (ChannelModeListFragment) getSupportFragmentManager() .findFragmentByTag("invitelist"); if (channelModeList == null) { channelModeList = new ChannelModeListFragment(); channelModeList.setArguments(args); try { channelModeList.show(getSupportFragmentManager(), "invitelist"); } catch (IllegalStateException e) { //App lost focus already } } else { channelModeList.setArguments(args); } } } }); break; case NetworkConnection.EVENT_ACCEPTLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { if (event != null && event.cid() == buffer.cid) { Bundle args = new Bundle(); args.putInt("cid", buffer.cid); args.putString("event", event.toString()); AcceptListFragment acceptList = (AcceptListFragment) getSupportFragmentManager() .findFragmentByTag("acceptlist"); if (acceptList == null) { acceptList = new AcceptListFragment(); acceptList.setArguments(args); try { acceptList.show(getSupportFragmentManager(), "acceptlist"); } catch (IllegalStateException e) { //App lost focus already } } else { acceptList.setArguments(args); } } } }); break; case NetworkConnection.EVENT_WHOLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { Bundle args = new Bundle(); args.putString("event", event.toString()); WhoListFragment whoList = (WhoListFragment) getSupportFragmentManager() .findFragmentByTag("wholist"); if (whoList == null) { whoList = new WhoListFragment(); whoList.setArguments(args); try { whoList.show(getSupportFragmentManager(), "wholist"); } catch (IllegalStateException e) { //App lost focus already } } else { whoList.setArguments(args); } } }); break; case NetworkConnection.EVENT_NAMESLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { Bundle args = new Bundle(); args.putString("event", event.toString()); NamesListFragment namesList = (NamesListFragment) getSupportFragmentManager() .findFragmentByTag("nameslist"); if (namesList == null) { namesList = new NamesListFragment(); namesList.setArguments(args); try { namesList.show(getSupportFragmentManager(), "nameslist"); } catch (IllegalStateException e) { //App lost focus already } } else { namesList.setArguments(args); } } }); break; case NetworkConnection.EVENT_SERVERMAPLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { Bundle args = new Bundle(); args.putString("event", event.toString()); ServerMapListFragment serversList = (ServerMapListFragment) getSupportFragmentManager() .findFragmentByTag("serverslist"); if (serversList == null) { serversList = new ServerMapListFragment(); serversList.setArguments(args); try { serversList.show(getSupportFragmentManager(), "serverslist"); } catch (IllegalStateException e) { //App lost focus already } } else { serversList.setArguments(args); } } }); break; case NetworkConnection.EVENT_WHOIS: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { Bundle args = new Bundle(); args.putString("event", event.toString()); WhoisFragment whois = (WhoisFragment) getSupportFragmentManager().findFragmentByTag("whois"); if (whois == null) { whois = new WhoisFragment(); whois.setArguments(args); try { whois.show(getSupportFragmentManager(), "whois"); } catch (IllegalStateException e) { //App lost focus already } } else { whois.setArguments(args); } } }); break; case NetworkConnection.EVENT_LISTRESPONSEFETCHING: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { String dialogtitle = "List of channels on " + ServersDataSource.getInstance().getServer(event.cid()).hostname; if (channelsListDialog == null) { Context ctx = MainActivity.this; final AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); builder.setView(getLayoutInflater().inflate(R.layout.dialog_channelslist, null)); builder.setTitle(dialogtitle); builder.setNegativeButton("Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); channelsListDialog = builder.create(); channelsListDialog.setOwnerActivity(MainActivity.this); } else { channelsListDialog.setTitle(dialogtitle); } try { channelsListDialog.show(); } catch (IllegalStateException e) { //App lost focus already } ChannelListFragment channels = (ChannelListFragment) getSupportFragmentManager() .findFragmentById(R.id.channelListFragment); Bundle args = new Bundle(); args.putInt("cid", event.cid()); channels.setArguments(args); } }); break; case NetworkConnection.EVENT_USERINFO: runOnUiThread(new Runnable() { @Override public void run() { updateUsersListFragmentVisibility(); supportInvalidateOptionsMenu(); if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); } }); if (launchBid == -1 && server == null && conn != null && conn.getUserInfo() != null) launchBid = conn.getUserInfo().last_selected_bid; break; case NetworkConnection.EVENT_STATUSCHANGED: try { event = (IRCCloudJSONObject) obj; if (event != null && server != null && event.cid() == server.cid) { runOnUiThread(new Runnable() { @Override public void run() { supportInvalidateOptionsMenu(); } }); } } catch (Exception e1) { e1.printStackTrace(); } break; case NetworkConnection.EVENT_MAKESERVER: ServersDataSource.Server s = (ServersDataSource.Server) obj; if (server != null && s != null && s.cid == server.cid) { runOnUiThread(new Runnable() { @Override public void run() { supportInvalidateOptionsMenu(); update_subtitle(); } }); } else { cidToOpen = s.cid; bufferToOpen = "*"; } break; case NetworkConnection.EVENT_BUFFERARCHIVED: case NetworkConnection.EVENT_BUFFERUNARCHIVED: event_bid = (Integer) obj; if (buffer != null && event_bid == buffer.bid) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); } }); } if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); break; case NetworkConnection.EVENT_JOIN: event = (IRCCloudJSONObject) obj; if (event != null && buffer != null && event.bid() == buffer.bid && event.type().equals("you_joined_channel")) { runOnUiThread(new Runnable() { @Override public void run() { supportInvalidateOptionsMenu(); updateUsersListFragmentVisibility(); } }); } break; case NetworkConnection.EVENT_PART: case NetworkConnection.EVENT_KICK: event = (IRCCloudJSONObject) obj; if (event != null && buffer != null && event.bid() == buffer.bid && event.type().toLowerCase().startsWith("you_")) { runOnUiThread(new Runnable() { @Override public void run() { supportInvalidateOptionsMenu(); updateUsersListFragmentVisibility(); } }); } break; case NetworkConnection.EVENT_CHANNELINIT: ChannelsDataSource.Channel channel = (ChannelsDataSource.Channel) obj; if (channel != null && buffer != null && channel.bid == buffer.bid) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); supportInvalidateOptionsMenu(); updateUsersListFragmentVisibility(); } }); } break; case NetworkConnection.EVENT_BACKLOG_END: runOnUiThread(new Runnable() { @Override public void run() { errorMsg.setVisibility(View.GONE); error = null; if (progressBar.getVisibility() == View.VISIBLE) { if (Build.VERSION.SDK_INT >= 16) { progressBar.animate().alpha(0).setDuration(200).withEndAction(new Runnable() { @Override public void run() { progressBar.setVisibility(View.GONE); } }); } else { progressBar.setVisibility(View.GONE); } } getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowCustomEnabled(true); if (drawerLayout != null) { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); getSupportActionBar().setHomeButtonEnabled(true); updateUsersListFragmentVisibility(); } if (ServersDataSource.getInstance().count() < 1) { Crashlytics.log(Log.DEBUG, "IRCCloud", "No servers configured, launching add dialog"); addNetwork(); } else { if (server == null || launchURI != null || launchBid != -1) { Crashlytics.log(Log.DEBUG, "IRCCloud", "Backlog loaded and we're waiting for a buffer, switching now"); if (launchURI == null || !open_uri(launchURI)) { if (launchBid == -1 || !open_bid(launchBid)) { if (conn == null || conn.getUserInfo() == null || !open_bid(conn.getUserInfo().last_selected_bid)) { if (!open_bid(BuffersDataSource.getInstance().firstBid())) { if (drawerLayout != null && NetworkConnection.getInstance().ready && findViewById(R.id.usersListFragment2) == null) { drawerLayout.openDrawer(Gravity.LEFT); } } } } } } update_subtitle(); } if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); photoBtn.setEnabled(true); if (Build.VERSION.SDK_INT >= 11) photoBtn.setAlpha(1); } }); //TODO: prune and pop the back stack if the current BID has disappeared break; case NetworkConnection.EVENT_CONNECTIONDELETED: case NetworkConnection.EVENT_DELETEBUFFER: Integer id = (Integer) obj; if (what == NetworkConnection.EVENT_DELETEBUFFER) { synchronized (backStack) { for (int i = 0; i < backStack.size(); i++) { if (backStack.get(i).equals(id)) { backStack.remove(i); i--; } } } } if (buffer != null && id == ((what == NetworkConnection.EVENT_CONNECTIONDELETED) ? buffer.cid : buffer.bid)) { synchronized (backStack) { while (backStack != null && backStack.size() > 0) { final Integer bid = backStack.get(0); backStack.remove(0); b = BuffersDataSource.getInstance().getBuffer(bid); if (b != null) { runOnUiThread(new Runnable() { @Override public void run() { onBufferSelected(bid); if (backStack.size() > 0) backStack.remove(0); } }); return; } } } runOnUiThread(new Runnable() { @Override public void run() { if (BuffersDataSource.getInstance().count() == 0) { startActivity(new Intent(MainActivity.this, EditConnectionActivity.class)); finish(); } else { if ((NetworkConnection.getInstance().getUserInfo() == null || !open_bid(NetworkConnection.getInstance().getUserInfo().last_selected_bid)) && !open_bid(BuffersDataSource.getInstance().firstBid())) finish(); } } }); } runOnUiThread(new Runnable() { @Override public void run() { if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); } }); break; case NetworkConnection.EVENT_CHANNELMODE: case NetworkConnection.EVENT_CHANNELTOPIC: event = (IRCCloudJSONObject) obj; if (event != null && buffer != null && event.bid() == buffer.bid) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); } }); } break; case NetworkConnection.EVENT_SELFBACK: case NetworkConnection.EVENT_AWAY: try { event = (IRCCloudJSONObject) obj; if (event != null && buffer != null && event.cid() == buffer.cid && event.getString("nick").equalsIgnoreCase(buffer.name)) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); } }); } } catch (Exception e1) { e1.printStackTrace(); } break; case NetworkConnection.EVENT_HEARTBEATECHO: boolean shouldRefresh = false; event = (IRCCloudJSONObject) obj; JsonNode seenEids = event.getJsonNode("seenEids"); Iterator<Map.Entry<String, JsonNode>> iterator = seenEids.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); JsonNode eids = entry.getValue(); Iterator<Map.Entry<String, JsonNode>> j = eids.fields(); while (j.hasNext()) { Map.Entry<String, JsonNode> eidentry = j.next(); Integer bid = Integer.valueOf(eidentry.getKey()); if (buffer != null && bid != buffer.bid) { shouldRefresh = true; } } } if (shouldRefresh) { runOnUiThread(new Runnable() { @Override public void run() { if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); } }); } break; case NetworkConnection.EVENT_FAILURE_MSG: event = (IRCCloudJSONObject) obj; if (event != null && event.has("_reqid")) { int reqid = event.getInt("_reqid"); if (pendingEvents.containsKey(reqid)) { EventsDataSource.Event e = pendingEvents.get(reqid); EventsDataSource.getInstance().deleteEvent(e.eid, e.bid); pendingEvents.remove(event.getInt("_reqid")); e.failed = true; e.bg_color = R.color.error; if (e.expiration_timer != null) e.expiration_timer.cancel(); conn.notifyHandlers(NetworkConnection.EVENT_BUFFERMSG, e); } } else { if (event.getString("message").equalsIgnoreCase("auth")) { conn.logout(); Intent i = new Intent(MainActivity.this, LoginActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); finish(); } if (event.getString("message").equalsIgnoreCase("set_shard")) { NetworkConnection.getInstance().disconnect(); NetworkConnection.getInstance().ready = false; SharedPreferences.Editor editor = getSharedPreferences("prefs", 0).edit(); editor.putString("session_key", event.getString("cookie")); if (event.has("websocket_host")) { NetworkConnection.IRCCLOUD_HOST = event.getString("websocket_host"); NetworkConnection.IRCCLOUD_PATH = event.getString("websocket_path"); } editor.putString("host", NetworkConnection.IRCCLOUD_HOST); editor.putString("path", NetworkConnection.IRCCLOUD_PATH); editor.commit(); NetworkConnection.getInstance().connect(event.getString("cookie")); } } try { error = event.getString("message"); if (error.equals("temp_unavailable")) error = "Your account is temporarily unavailable"; runOnUiThread(new Runnable() { @Override public void run() { updateReconnecting(); } }); } catch (Exception ex) { ex.printStackTrace(); } break; case NetworkConnection.EVENT_BUFFERMSG: try { EventsDataSource.Event e = (EventsDataSource.Event) obj; if (e != null && buffer != null) { if (e.bid != buffer.bid && upDrawable != null) { BuffersDataSource.Buffer buf = BuffersDataSource.getInstance().getBuffer(e.bid); if (e.isImportant(buf.type)) { if (upDrawable.getColor() != redColor && (e.highlight || buf.type.equals("conversation"))) { runOnUiThread(new Runnable() { @Override public void run() { upDrawable.setColor(redColor); } }); } else if (upDrawable.getColor() == greyColor) { JSONObject channelDisabledMap = null; JSONObject bufferDisabledMap = null; if (NetworkConnection.getInstance().getUserInfo() != null && NetworkConnection.getInstance().getUserInfo().prefs != null) { try { if (NetworkConnection.getInstance().getUserInfo().prefs .has("channel-disableTrackUnread")) channelDisabledMap = NetworkConnection.getInstance().getUserInfo().prefs .getJSONObject("channel-disableTrackUnread"); if (NetworkConnection.getInstance().getUserInfo().prefs .has("buffer-disableTrackUnread")) bufferDisabledMap = NetworkConnection.getInstance().getUserInfo().prefs .getJSONObject("buffer-disableTrackUnread"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } if (buf.type.equalsIgnoreCase("channel") && channelDisabledMap != null && channelDisabledMap.has(String.valueOf(buf.bid)) && channelDisabledMap.getBoolean(String.valueOf(buf.bid))) break; else if (bufferDisabledMap != null && bufferDisabledMap.has(String.valueOf(buf.bid)) && bufferDisabledMap.getBoolean(String.valueOf(buf.bid))) break; runOnUiThread(new Runnable() { @Override public void run() { upDrawable.setColor(blueColor); } }); } } } if (e.from.equalsIgnoreCase(buffer.name)) { pendingEvents.clear(); } else if (pendingEvents.containsKey(e.reqid)) { pendingEvents.remove(e.reqid); } } } catch (Exception e1) { } break; } }
From source file:com.cognizant.trumobi.PersonaLauncher.java
@SuppressWarnings("unused") void addSearch() { final PersonaWidget info = PersonaWidget.makeSearch(); final PersonaCellLayout.CellInfo cellInfo = mAddItemCellInfo; final int[] xy = mCellCoordinates; final int spanX = info.spanX; final int spanY = info.spanY; AlertDialog.Builder builder; AlertDialog alertDialog;// ww w . j a va 2 s .co m final View dlg_layout = View.inflate(PersonaLauncher.this, R.layout.pr_widget_span_setup, null); final PersonaNumberPicker ncols = (PersonaNumberPicker) dlg_layout.findViewById(R.id.widget_columns_span); ncols.setRange(1, mWorkspace.currentDesktopColumns()); ncols.setCurrent(spanX); final PersonaNumberPicker nrows = (PersonaNumberPicker) dlg_layout.findViewById(R.id.widget_rows_span); nrows.setRange(1, mWorkspace.currentDesktopRows()); nrows.setCurrent(spanY); builder = new AlertDialog.Builder(PersonaLauncher.this); builder.setView(dlg_layout); alertDialog = builder.create(); alertDialog.setTitle(getResources().getString(R.string.widget_config_dialog_title)); alertDialog.setMessage(getResources().getString(R.string.widget_config_dialog_summary)); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { int spanX = ncols.getCurrent(); int spanY = nrows.getCurrent(); // realAddSearch(info,cellInfo,xy,spanX,spanY); } }); alertDialog.show(); }
From source file:com.if3games.chessonline.DroidFish.java
private final Dialog moveListMenuDialog() { final int EDIT_HEADERS = 0; final int EDIT_COMMENTS = 1; final int REMOVE_SUBTREE = 2; final int MOVE_VAR_UP = 3; final int MOVE_VAR_DOWN = 4; final int ADD_NULL_MOVE = 5; List<CharSequence> lst = new ArrayList<CharSequence>(); List<Integer> actions = new ArrayList<Integer>(); lst.add(getString(R.string.edit_headers)); actions.add(EDIT_HEADERS);/*from w w w .java2s .com*/ if (ctrl.humansTurn()) { lst.add(getString(R.string.edit_comments)); actions.add(EDIT_COMMENTS); } lst.add(getString(R.string.truncate_gametree)); actions.add(REMOVE_SUBTREE); if (ctrl.numVariations() > 1) { lst.add(getString(R.string.move_var_up)); actions.add(MOVE_VAR_UP); lst.add(getString(R.string.move_var_down)); actions.add(MOVE_VAR_DOWN); } boolean allowNullMove = gameMode.analysisMode() || (gameMode.playerWhite() && gameMode.playerBlack() && !gameMode.clocksActive()); if (allowNullMove) { lst.add(getString(R.string.add_null_move)); actions.add(ADD_NULL_MOVE); } final List<Integer> finalActions = actions; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.edit_game); builder.setItems(lst.toArray(new CharSequence[lst.size()]), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (finalActions.get(item)) { case EDIT_HEADERS: { final TreeMap<String, String> headers = new TreeMap<String, String>(); ctrl.getHeaders(headers); AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this); builder.setTitle(R.string.edit_headers); View content = View.inflate(DroidFish.this, R.layout.edit_headers, null); builder.setView(content); final TextView event, site, date, round, white, black; event = (TextView) content.findViewById(R.id.ed_header_event); site = (TextView) content.findViewById(R.id.ed_header_site); date = (TextView) content.findViewById(R.id.ed_header_date); round = (TextView) content.findViewById(R.id.ed_header_round); white = (TextView) content.findViewById(R.id.ed_header_white); black = (TextView) content.findViewById(R.id.ed_header_black); event.setText(headers.get("Event")); site.setText(headers.get("Site")); date.setText(headers.get("Date")); round.setText(headers.get("Round")); white.setText(headers.get("White")); black.setText(headers.get("Black")); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { headers.put("Event", event.getText().toString().trim()); headers.put("Site", site.getText().toString().trim()); headers.put("Date", date.getText().toString().trim()); headers.put("Round", round.getText().toString().trim()); headers.put("White", white.getText().toString().trim()); headers.put("Black", black.getText().toString().trim()); ctrl.setHeaders(headers); setBoardFlip(true); } }); builder.show(); break; } case EDIT_COMMENTS: { AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this); builder.setTitle(R.string.edit_comments); View content = View.inflate(DroidFish.this, R.layout.edit_comments, null); builder.setView(content); DroidChessController.CommentInfo commInfo = ctrl.getComments(); final TextView preComment, moveView, nag, postComment; preComment = (TextView) content.findViewById(R.id.ed_comments_pre); moveView = (TextView) content.findViewById(R.id.ed_comments_move); nag = (TextView) content.findViewById(R.id.ed_comments_nag); postComment = (TextView) content.findViewById(R.id.ed_comments_post); preComment.setText(commInfo.preComment); postComment.setText(commInfo.postComment); moveView.setText(commInfo.move); String nagStr = Node.nagStr(commInfo.nag).trim(); if ((nagStr.length() == 0) && (commInfo.nag > 0)) nagStr = String.format(Locale.US, "%d", commInfo.nag); nag.setText(nagStr); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String pre = preComment.getText().toString().trim(); String post = postComment.getText().toString().trim(); int nagVal = Node.strToNag(nag.getText().toString()); DroidChessController.CommentInfo commInfo = new DroidChessController.CommentInfo(); commInfo.preComment = pre; commInfo.postComment = post; commInfo.nag = nagVal; ctrl.setComments(commInfo); } }); builder.show(); break; } case REMOVE_SUBTREE: ctrl.removeSubTree(); break; case MOVE_VAR_UP: ctrl.moveVariation(-1); break; case MOVE_VAR_DOWN: ctrl.moveVariation(1); break; case ADD_NULL_MOVE: ctrl.makeHumanNullMove(); break; } moveListMenuDlg = null; } }); AlertDialog alert = builder.create(); moveListMenuDlg = alert; return alert; }
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 w w .j a va 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:com.android.launcher3.Launcher.java
@Override public boolean onLongClick(View v) { if (!isDraggingEnabled()) return false; if (isWorkspaceLocked()) return false; if (mState != State.WORKSPACE) return false; if (creation != null) creation.clearAllLayout();//from www . j a v a 2s.co m if ((FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && v instanceof PageIndicator) || (v == mAllAppsButton && mAllAppsButton != null)) { onLongClickAllAppsButton(v); return true; } if (v instanceof Workspace) { if (!mWorkspace.isInOverviewMode()) { if (!mWorkspace.isTouchActive()) { showOverviewMode(true); mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); return true; } else { return false; } } else { return false; } } CellLayout.CellInfo longClickCellInfo = null; View itemUnderLongClick = null; if (v.getTag() instanceof ItemInfo) { ItemInfo info = (ItemInfo) v.getTag(); longClickCellInfo = new CellLayout.CellInfo(v, info); itemUnderLongClick = longClickCellInfo.cell; mPendingRequestArgs = null; } // The hotseat touch handling does not go through Workspace, and we always allow long press // on hotseat items. if (!mDragController.isDragging()) { if (itemUnderLongClick == null) { // User long pressed on empty space mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); if (mWorkspace.isInOverviewMode()) { mWorkspace.startReordering(v); } else { showOverviewMode(true); } } else { final boolean isAllAppsButton = !FeatureFlags.NO_ALL_APPS_ICON && isHotseatLayout(v) && mDeviceProfile.inv.isAllAppsButtonRank( mHotseat.getOrderInHotseat(longClickCellInfo.cellX, longClickCellInfo.cellY)); if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) { // User long pressed on an item DragOptions dragOptions = new DragOptions(); if (itemUnderLongClick instanceof BubbleTextView) { BubbleTextView icon = (BubbleTextView) itemUnderLongClick; if (icon.hasDeepShortcuts()) { DeepShortcutsContainer dsc = DeepShortcutsContainer.showForIcon(icon); if (dsc != null) { dragOptions.deferDragCondition = dsc.createDeferDragCondition(null); } } } int positionInGrid = mHotseat.getOrderInHotseat(longClickCellInfo.cellX, longClickCellInfo.cellY); List<Shortcuts> shortcutses = new ArrayList<Shortcuts>(); if (creation != null) creation.clearAllLayout(); mWorkspace.startDrag(longClickCellInfo, dragOptions); //Get selected app info final Object tag = v.getTag(); final ShortcutInfo shortcut; try { shortcut = (ShortcutInfo) tag; Drawable icon; if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcut.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcut.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), shortcut.getIcon(new IconCache(Launcher.this, getDeviceProfile().inv))); } shortcutses = ShortcutsManager.getShortcutsBasedOnTag(Launcher.this.getApplicationContext(), Launcher.this, shortcut, icon); ShortcutsBuilder builder = new ShortcutsBuilder.Builder(this, masterLayout) .launcher3Shortcuts(gridSize, positionInGrid, (int) v.getY(), v.getBottom(), Hotseat.isHotseatTouched, Utilities.getDockSizeDefaultValue(getApplicationContext())) .setOptionLayoutStyle(StyleOption.NONE).setPackageImage(icon) .setShortcutsList(shortcutses).build(); creation = new ShortcutsCreation(builder); creation.init(); Hotseat.isHotseatTouched = false; } catch (ClassCastException e) { Log.e(TAG, "Clicked on Folder/Widget!"); positionInGrid = mHotseat.getOrderInHotseat(longClickCellInfo.cellX, longClickCellInfo.cellY); try { //Get selected folder info final View f = v; final Object tagF = v.getTag(); final FolderInfo folder; folder = (FolderInfo) tagF; shortcutses = new ArrayList<Shortcuts>(); shortcutses.add(new Shortcuts(R.drawable.ic_folder_open_black_24dp, getString(R.string.folder_open), new OnClickListener() { @Override public void onClick(View view) { if (f instanceof FolderIcon) { onClickFolderIcon(f); creation.clearAllLayout(); } } })); shortcutses.add(new Shortcuts(R.drawable.ic_title_black_24dp, getString(R.string.folder_rename), new OnClickListener() { @Override public void onClick(View view) { if (f instanceof FolderIcon) { AlertDialog.Builder alert = new AlertDialog.Builder( new ContextThemeWrapper(Launcher.this, R.style.AlertDialogCustom)); LinearLayout layout = new LinearLayout(getApplicationContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(100, 50, 100, 100); final EditText titleBox = new EditText(Launcher.this); titleBox.getBackground().mutate() .setColorFilter( ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary), PorterDuff.Mode.SRC_ATOP); alert.setMessage(getString(R.string.folder_title)); alert.setTitle(getString(R.string.folder_enter_title)); layout.addView(titleBox); alert.setView(layout); alert.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { folder.setTitle(titleBox.getText().toString()); LauncherModel.updateItemInDatabase( Launcher.getLauncherActivity(), folder); } }); alert.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { creation.clearAllLayout(); } }); alert.show(); creation.clearAllLayout(); } } })); ShortcutsBuilder builder = new ShortcutsBuilder.Builder(this, masterLayout) .launcher3Shortcuts(gridSize, positionInGrid, (int) v.getY(), v.getBottom(), Hotseat.isHotseatTouched, Utilities.getDockSizeDefaultValue(getApplicationContext())) .setOptionLayoutStyle(0) .setPackageImage( ContextCompat.getDrawable(Launcher.this, R.mipmap.ic_launcher_home)) .setShortcutsList(shortcutses).build(); creation = new ShortcutsCreation(builder); creation.init(); } catch (ClassCastException ee) { } } } } } return true; }
From source file:com.example.android.lightcontrol.MainActivity.java
private void theme_to_who() { LayoutInflater inflater = LayoutInflater.from(this); final View v = inflater.inflate(R.layout.theme_to_who, null); final AlertDialog.Builder dialog = new AlertDialog.Builder(this); Spinner theme_to_who = (Spinner) v.findViewById(R.id.theme_to_who); final Spinner theme_to_area1 = (Spinner) v.findViewById(R.id.area_1); final Spinner theme_to_area2 = (Spinner) v.findViewById(R.id.area_2); final TextView region1 = (TextView) v.findViewById(R.id.textView16); final TextView region2 = (TextView) v.findViewById(R.id.textView17); ArrayAdapter<String> arr_theme_to_who_list; ArrayAdapter<String> arr_theme_to_area1_list; ArrayAdapter<String> arr_theme_to_area2_list; final String[] theme_to_who_list = { "All Lights", "Group" }; final String[] theme_to_area1_list = { "Group 1" }; final String[] theme_to_area2_list = { "Group 2" }; arr_theme_to_who_list = new ArrayAdapter<String>(this, R.layout.my_spinner, theme_to_who_list); theme_to_who.setAdapter(arr_theme_to_who_list); arr_theme_to_area1_list = new ArrayAdapter<String>(this, R.layout.my_spinner, theme_to_area1_list); theme_to_area1.setAdapter(arr_theme_to_area1_list); arr_theme_to_area2_list = new ArrayAdapter<String>(this, R.layout.my_spinner, theme_to_area2_list); theme_to_area2.setAdapter(arr_theme_to_area2_list); theme_to_who.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override//from ww w . j a v a 2 s . com public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (theme_to_who_list[i].equals("All Lights")) { theme_to_area1.setVisibility(View.INVISIBLE); theme_to_area2.setVisibility(View.INVISIBLE); region1.setVisibility(View.INVISIBLE); region2.setVisibility(View.INVISIBLE); GlobalVariable.Theme_to_group_or_all = "ff"; GlobalVariable.Theme_to_area1_group_8X = ""; GlobalVariable.Theme_to_area2_group_8X = ""; } if (theme_to_who_list[i].equals("Group")) { GlobalVariable.Theme_to_group_or_all = "8"; theme_to_area1.setVisibility(View.VISIBLE); theme_to_area2.setVisibility(View.VISIBLE); region1.setVisibility(View.VISIBLE); region2.setVisibility(View.VISIBLE); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); theme_to_area1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (theme_to_area1_list[i].equals("Group 1")) { GlobalVariable.Theme_to_area1_group_8X = "1"; } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); theme_to_area2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (theme_to_area2_list[i].equals("Group 2")) { GlobalVariable.Theme_to_area2_group_8X = "3"; } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); dialog.setCancelable(false); dialog.setTitle(R.string.about_title); dialog.setView(v); dialog.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { } }); dialog.show(); }
From source file:dev.memento.MementoBrowser.java
@Override protected Dialog onCreateDialog(int id) { Dialog dialog = null;//from www .ja v a 2 s. com AlertDialog.Builder builder = new AlertDialog.Builder(this); switch (id) { case DIALOG_DATE: dialog = new DatePickerDialog(this, mDateSetListener, mDateChosen.getYear(), mDateChosen.getMonth() - 1, mDateChosen.getDay()); break; case DIALOG_ERROR: builder = new AlertDialog.Builder(this); builder.setMessage("error message").setCancelable(false).setPositiveButton("OK", null); dialog = builder.create(); break; case DIALOG_MEMENTO_YEARS: builder = new AlertDialog.Builder(this); final CharSequence[] years = mMementos.getAllYears(); // Select the year of the Memento currently displayed int selectedYear = -1; for (int i = 0; i < years.length; i++) { if (mDateDisplayed.getYear() == Integer.parseInt(years[i].toString())) { selectedYear = i; break; } } builder.setSingleChoiceItems(years, selectedYear, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); mSelectedYear = Integer.parseInt(years[item].toString()); showDialog(DIALOG_MEMENTO_DATES); } }); dialog = builder.create(); // Cause the dialog to be freed whenever it is dismissed. // This is necessary because the items are dynamic. dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { removeDialog(DIALOG_MEMENTO_YEARS); } }); break; case DIALOG_MEMENTO_DATES: builder = new AlertDialog.Builder(this); final CharSequence[] dates; if (mSelectedYear == 0) dates = mMementos.getAllDates(); else dates = mMementos.getDatesForYear(mSelectedYear); Log.d(LOG_TAG, "Number of dates = " + dates.length); // This shouldn't happen, but just in case. if (dates.length == 0) { showToast("No Mementos to select from."); return null; } int selected = -1; // Select the radio button for the current Memento if it's in the selected year. if (mSelectedYear == 0 || mSelectedYear == mDateDisplayed.getYear()) { int index = mMementos.getIndex(mDateDisplayed); if (index < 0) Log.d(LOG_TAG, "Could not find Memento in the list with date " + mDateDisplayed); else mMementos.setCurrentIndex(index); Memento m = mMementos.getCurrent(); if (m != null) { for (int i = 0; i < dates.length; i++) { if (m.getDateTime().dateAndTimeFormatted().equals(dates[i])) { selected = i; break; } } } else Log.d(LOG_TAG, "There is no current Memento"); } Log.d(LOG_TAG, "Selected index = " + selected); builder.setSingleChoiceItems(dates, selected, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); int index = mMementos.getIndex(dates[item].toString()); Memento m = mMementos.get(index); if (m == null) { Log.e(LOG_TAG, "Could not find Memento with date " + mDateChosen + "."); displayError("The date selected could not be accessed. Please select another."); } else { // Display this Memento Log.d(LOG_TAG, "index for [" + dates[item] + "] is " + index); SimpleDateTime d = m.getDateTime(); setChosenDate(d); if (index == mMementos.getCurrentIndex()) { showToast("Memento is already displayed."); } else { mMementos.setCurrentIndex(index); showToast("Time travelling to " + mDateChosen.dateFormatted()); // Find the Memento URL for the selected date mDateDisplayed = new SimpleDateTime(mDateChosen); String redirectUrl = m.getUrl(); Log.d(LOG_TAG, "Sending browser to " + redirectUrl); mWebview.loadUrl(redirectUrl); setEnableForNextPrevButtons(); } } } }); dialog = builder.create(); // Cause the dialog to be freed whenever it is dismissed. // This is necessary because the items are dynamic. I couldn't find // a better way to solve this problem. dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { removeDialog(DIALOG_MEMENTO_DATES); } }); break; case DIALOG_HELP: Context context = getApplicationContext(); LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.about_dialog, null); builder.setView(layout); builder.setPositiveButton("OK", null); dialog = builder.create(); break; } return dialog; }
From source file:com.irccloud.android.activity.MainActivity.java
private void show_topic_popup() { if (buffer == null) return;/*w w w .j a v a 2 s .c o m*/ ChannelsDataSource.Channel c = ChannelsDataSource.getInstance().getChannelForBuffer(buffer.bid); if (c != null) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); View v = getLayoutInflater().inflate(R.layout.dialog_topic, null); if (c.topic_text.length() > 0) { String author = ""; if (c.topic_author != null && c.topic_author.length() > 0) { author = " Set by " + c.topic_author; if (c.topic_time > 0) { author += " on " + DateFormat.getDateTimeInstance().format(new Date(c.topic_time * 1000)); } v.findViewById(R.id.setBy).setVisibility(View.VISIBLE); ((TextView) v.findViewById(R.id.setBy)).setText(author); } ((TextView) v.findViewById(R.id.topic)).setText(ColorFormatter.html_to_spanned( ColorFormatter.emojify(ColorFormatter.irc_to_html(TextUtils.htmlEncode(c.topic_text))), true, server)); } else { ((TextView) v.findViewById(R.id.topic)).setText("No topic set."); } if (c.mode.length() > 0) { v.findViewById(R.id.mode).setVisibility(View.VISIBLE); ((TextView) v.findViewById(R.id.mode)).setText("Mode: +" + c.mode); for (ChannelsDataSource.Mode m : c.modes) { switch (m.mode) { case "i": v.findViewById(R.id.mode_i).setVisibility(View.VISIBLE); break; case "k": v.findViewById(R.id.mode_k).setVisibility(View.VISIBLE); ((TextView) v.findViewById(R.id.key)).setText(m.param); break; case "m": v.findViewById(R.id.mode_m).setVisibility(View.VISIBLE); break; case "n": v.findViewById(R.id.mode_n).setVisibility(View.VISIBLE); break; case "p": v.findViewById(R.id.mode_p).setVisibility(View.VISIBLE); break; case "s": v.findViewById(R.id.mode_s).setVisibility(View.VISIBLE); break; case "t": v.findViewById(R.id.mode_t).setVisibility(View.VISIBLE); break; } } } builder.setView(v); builder.setNegativeButton("Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); boolean canEditTopic; if (c.hasMode("t")) { UsersDataSource.User self_user = UsersDataSource.getInstance().getUser(buffer.bid, server.nick); canEditTopic = (self_user != null && (self_user.mode.contains(server != null ? server.MODE_OPER : "Y") || self_user.mode.contains(server != null ? server.MODE_OWNER : "q") || self_user.mode.contains(server != null ? server.MODE_ADMIN : "a") || self_user.mode.contains(server != null ? server.MODE_OP : "o") || self_user.mode.contains(server != null ? server.MODE_HALFOP : "h"))); } else { canEditTopic = true; } if (canEditTopic) { builder.setPositiveButton("Edit Topic", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); editTopic(); } }); } final AlertDialog dialog = builder.create(); dialog.setOwnerActivity(MainActivity.this); dialog.show(); ((TextView) v.findViewById(R.id.topic)).setMovementMethod(new LinkMovementMethod() { @Override public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) { if (super.onTouchEvent(widget, buffer, event) && event.getAction() == MotionEvent.ACTION_UP) { dialog.dismiss(); return true; } return false; } }); } }