List of usage examples for android.util Log DEBUG
int DEBUG
To view the source code for android.util Log DEBUG.
Click Source Link
From source file:finalproject.ece558.edu.pdx.ece.brailleblackjack.PlayBlackJackGameFragment.java
/** * Set-up the listener once an Android Wear (smartwatch) device is connected * @param bundle Bundle object//ww w . j a v a 2 s . c om */ @Override public void onConnected(Bundle bundle) { Log.d(TAG, "Connected to Google Api Service"); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Connected to Google Api Service"); } Wearable.MessageApi.addListener(mGoogleApiClient, this); }
From source file:com.android.contacts.ContactSaveService.java
private void sleepForDebugging(Intent intent) { long duration = intent.getLongExtra(EXTRA_SLEEP_DURATION, 1000); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "sleeping for " + duration + "ms"); }/* w w w.j a v a2 s.com*/ try { Thread.sleep(duration); } catch (InterruptedException e) { e.printStackTrace(); } if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "finished sleeping"); } }
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 .ja va 2s. c om*/ 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.irccloud.android.NetworkConnection.java
public String fetch(URL url, String postdata, String sk, String token, HashMap<String, String> headers) throws Exception { HttpURLConnection conn = null; Proxy proxy = null;// www . ja v a 2s . co m String host = null; int port = -1; if (Build.VERSION.SDK_INT < 11) { Context ctx = IRCCloudApplication.getInstance().getApplicationContext(); if (ctx != null) { host = android.net.Proxy.getHost(ctx); port = android.net.Proxy.getPort(ctx); } } else { host = System.getProperty("http.proxyHost", null); try { port = Integer.parseInt(System.getProperty("http.proxyPort", "8080")); } catch (NumberFormatException e) { port = -1; } } if (host != null && host.length() > 0 && !host.equalsIgnoreCase("localhost") && !host.equalsIgnoreCase("127.0.0.1") && port > 0) { InetSocketAddress proxyAddr = new InetSocketAddress(host, port); proxy = new Proxy(Proxy.Type.HTTP, proxyAddr); } if (host != null && host.length() > 0 && !host.equalsIgnoreCase("localhost") && !host.equalsIgnoreCase("127.0.0.1") && port > 0) { Crashlytics.log(Log.DEBUG, TAG, "Requesting: " + url + " via proxy: " + host); } else { Crashlytics.log(Log.DEBUG, TAG, "Requesting: " + url); } if (url.getProtocol().toLowerCase().equals("https")) { HttpsURLConnection https = (HttpsURLConnection) ((proxy != null) ? url.openConnection(proxy) : url.openConnection(Proxy.NO_PROXY)); if (url.getHost().equals(IRCCLOUD_HOST)) https.setSSLSocketFactory(IRCCloudSocketFactory); conn = https; } else { conn = (HttpURLConnection) ((proxy != null) ? url.openConnection(proxy) : url.openConnection(Proxy.NO_PROXY)); } conn.setConnectTimeout(5000); conn.setReadTimeout(5000); conn.setUseCaches(false); conn.setRequestProperty("User-Agent", useragent); conn.setRequestProperty("Accept", "application/json"); if (headers != null) { for (String key : headers.keySet()) { conn.setRequestProperty(key, headers.get(key)); } } if (sk != null) conn.setRequestProperty("Cookie", "session=" + sk); if (token != null) conn.setRequestProperty("x-auth-formtoken", token); if (postdata != null) { conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded"); OutputStream ostr = null; try { ostr = conn.getOutputStream(); ostr.write(postdata.getBytes()); } catch (Exception e) { e.printStackTrace(); } finally { if (ostr != null) ostr.close(); } } BufferedReader reader = null; String response = ""; try { ConnectivityManager cm = (ConnectivityManager) IRCCloudApplication.getInstance() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) { Crashlytics.log(Log.DEBUG, TAG, "Loading via WiFi"); } else { Crashlytics.log(Log.DEBUG, TAG, "Loading via mobile"); } } catch (Exception e) { } try { if (conn.getInputStream() != null) { reader = new BufferedReader(new InputStreamReader(conn.getInputStream()), 512); } } catch (IOException e) { if (conn.getErrorStream() != null) { reader = new BufferedReader(new InputStreamReader(conn.getErrorStream()), 512); } } if (reader != null) { response = toString(reader); reader.close(); } conn.disconnect(); return response; }
From source file:com.irccloud.android.NetworkConnection.java
public Bitmap fetchImage(URL url, boolean cacheOnly) throws Exception { HttpURLConnection conn = null; Proxy proxy = null;//from ww w . j av a2s . c o m String host = null; int port = -1; if (Build.VERSION.SDK_INT < 11) { Context ctx = IRCCloudApplication.getInstance().getApplicationContext(); if (ctx != null) { host = android.net.Proxy.getHost(ctx); port = android.net.Proxy.getPort(ctx); } } else { host = System.getProperty("http.proxyHost", null); try { port = Integer.parseInt(System.getProperty("http.proxyPort", "8080")); } catch (NumberFormatException e) { port = -1; } } if (host != null && host.length() > 0 && !host.equalsIgnoreCase("localhost") && !host.equalsIgnoreCase("127.0.0.1") && port > 0) { InetSocketAddress proxyAddr = new InetSocketAddress(host, port); proxy = new Proxy(Proxy.Type.HTTP, proxyAddr); } if (host != null && host.length() > 0 && !host.equalsIgnoreCase("localhost") && !host.equalsIgnoreCase("127.0.0.1") && port > 0) { Crashlytics.log(Log.DEBUG, TAG, "Requesting: " + url + " via proxy: " + host); } else { Crashlytics.log(Log.DEBUG, TAG, "Requesting: " + url); } if (url.getProtocol().toLowerCase().equals("https")) { HttpsURLConnection https = (HttpsURLConnection) ((proxy != null) ? url.openConnection(proxy) : url.openConnection(Proxy.NO_PROXY)); if (url.getHost().equals(IRCCLOUD_HOST)) https.setSSLSocketFactory(IRCCloudSocketFactory); conn = https; } else { conn = (HttpURLConnection) ((proxy != null) ? url.openConnection(proxy) : url.openConnection(Proxy.NO_PROXY)); } conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.setUseCaches(true); conn.setRequestProperty("User-Agent", useragent); if (cacheOnly) conn.addRequestProperty("Cache-Control", "only-if-cached"); Bitmap bitmap = null; try { ConnectivityManager cm = (ConnectivityManager) IRCCloudApplication.getInstance() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) { Crashlytics.log(Log.DEBUG, TAG, "Loading via WiFi"); } else { Crashlytics.log(Log.DEBUG, TAG, "Loading via mobile"); } } catch (Exception e) { e.printStackTrace(); } try { if (conn.getInputStream() != null) { bitmap = BitmapFactory.decodeStream(conn.getInputStream()); } } catch (FileNotFoundException e) { return null; } catch (IOException e) { e.printStackTrace(); } conn.disconnect(); return bitmap; }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private boolean handleForwardedMessage() { Intent intent = getIntent();//from w ww.java2 s.com // If this is a forwarded message, it will have an Intent extra // indicating so. If not, bail out. if (!mForwardMessageMode) { if (mConversation != null) { mConversation.setHasMmsForward(false); } return false; } if (mConversation != null) { mConversation.setHasMmsForward(true); String recipientNumber = intent.getStringExtra("msg_recipient"); mConversation.setForwardRecipientNumber(recipientNumber); } Uri uri = intent.getParcelableExtra("msg_uri"); if (Log.isLoggable(LogTag.APP, Log.DEBUG)) { log("" + uri); } if (uri != null) { mWorkingMessage = WorkingMessage.load(this, uri); mWorkingMessage.setSubject(intent.getStringExtra("subject"), false); } else { mWorkingMessage.setText(intent.getStringExtra("sms_body")); } // let's clear the message thread for forwarded messages mMsgListAdapter.changeCursor(null); return true; }
From source file:com.irccloud.android.activity.MainActivity.java
@Override public void onBufferSelected(int bid) { launchBid = -1;/*from w w w .j a v a 2 s . c om*/ launchURI = null; cidToOpen = -1; bufferToOpen = null; setIntent(new Intent(this, MainActivity.class)); if (suggestionsTimerTask != null) suggestionsTimerTask.cancel(); sortedChannels = null; sortedUsers = null; if (drawerLayout != null) { drawerLayout.closeDrawers(); } if (bid != -1 && conn != null && conn.getUserInfo() != null) { conn.getUserInfo().last_selected_bid = bid; } for (int i = 0; i < backStack.size(); i++) { if (buffer != null && backStack.get(i) == buffer.bid) backStack.remove(i); } if (buffer != null && buffer.bid >= 0 && bid != buffer.bid) { backStack.add(0, buffer.bid); buffer.draft = messageTxt.getText().toString(); } if (buffer == null || buffer.bid == -1 || buffer.cid == -1 || buffer.bid == bid) shouldFadeIn = false; else shouldFadeIn = true; buffer = BuffersDataSource.getInstance().getBuffer(bid); if (buffer != null) { Crashlytics.log(Log.DEBUG, "IRCCloud", "Buffer selected: cid" + buffer.cid + " bid" + bid + " shouldFadeIn: " + shouldFadeIn); server = ServersDataSource.getInstance().getServer(buffer.cid); try { TreeMap<Long, EventsDataSource.Event> events = EventsDataSource.getInstance() .getEventsForBuffer(buffer.bid); if (events != null) { events = (TreeMap<Long, EventsDataSource.Event>) events.clone(); for (EventsDataSource.Event e : events.values()) { if (e != null && e.highlight && e.from != null) { UsersDataSource.User u = UsersDataSource.getInstance().getUser(buffer.bid, e.from); if (u != null && u.last_mention < e.eid) u.last_mention = e.eid; } } } } catch (Exception e) { Crashlytics.logException(e); } try { if (Build.VERSION.SDK_INT >= 16 && buffer != null && server != null) { NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); if (nfc != null) { String uri = "irc"; if (server.ssl > 0) uri += "s"; uri += "://" + server.hostname + ":" + server.port; if (buffer.type.equals("channel")) { uri += "/" + URLEncoder.encode(buffer.name, "UTF-8"); ChannelsDataSource.Channel c = ChannelsDataSource.getInstance() .getChannelForBuffer(buffer.bid); if (c != null && c.hasMode("k")) uri += "," + c.paramForMode("k"); } nfc.setNdefPushMessage(new NdefMessage(NdefRecord.createUri(uri)), this); } } } catch (Exception e) { } } else { Crashlytics.log(Log.DEBUG, "IRCCloud", "Buffer selected but not found: bid" + bid + " shouldFadeIn: " + shouldFadeIn); server = null; } update_subtitle(); final Bundle b = new Bundle(); if (buffer != null) b.putInt("cid", buffer.cid); b.putInt("bid", bid); b.putBoolean("fade", shouldFadeIn); BuffersListFragment blf = (BuffersListFragment) getSupportFragmentManager() .findFragmentById(R.id.BuffersList); final MessageViewFragment mvf = (MessageViewFragment) getSupportFragmentManager() .findFragmentById(R.id.messageViewFragment); UsersListFragment ulf = (UsersListFragment) getSupportFragmentManager() .findFragmentById(R.id.usersListFragment); UsersListFragment ulf2 = (UsersListFragment) getSupportFragmentManager() .findFragmentById(R.id.usersListFragment2); if (mvf != null) mvf.ready = false; if (blf != null) blf.setSelectedBid(bid); if (ulf != null) ulf.setArguments(b); if (ulf2 != null) ulf2.setArguments(b); if (shouldFadeIn) { Crashlytics.log(Log.DEBUG, "IRCCloud", "Fade Out"); if (Build.VERSION.SDK_INT < 16) { AlphaAnimation anim = new AlphaAnimation(1, 0); anim.setDuration(150); anim.setFillAfter(true); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (mvf != null) mvf.setArguments(b); messageTxt.setText(""); if (buffer != null && buffer.draft != null) messageTxt.append(buffer.draft); } @Override public void onAnimationRepeat(Animation animation) { } }); try { mvf.getListView().startAnimation(anim); ulf.getListView().startAnimation(anim); } catch (Exception e) { } } else { mvf.getListView().animate().alpha(0).withEndAction(new Runnable() { @Override public void run() { if (mvf != null) mvf.setArguments(b); messageTxt.setText(""); if (buffer != null && buffer.draft != null) messageTxt.append(buffer.draft); } }); ulf.getListView().animate().alpha(0); } mvf.showSpinner(true); } else { if (mvf != null) mvf.setArguments(b); messageTxt.setText(""); if (buffer != null && buffer.draft != null) messageTxt.append(buffer.draft); } updateUsersListFragmentVisibility(); supportInvalidateOptionsMenu(); if (excludeBIDTask != null) excludeBIDTask.cancel(true); excludeBIDTask = new ExcludeBIDTask(); excludeBIDTask.execute(bid); if (drawerLayout != null) new RefreshUpIndicatorTask().execute((Void) null); if (buffer != null && buffer.cid != -1) { if (drawerLayout != null) { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT); getSupportActionBar().setHomeButtonEnabled(true); } } update_suggestions(false); }
From source file:com.irccloud.android.activity.MainActivity.java
@Override public void onMessageViewReady() { if (shouldFadeIn) { Crashlytics.log(Log.DEBUG, "IRCCloud", "Fade In"); MessageViewFragment mvf = (MessageViewFragment) getSupportFragmentManager() .findFragmentById(R.id.messageViewFragment); UsersListFragment ulf = (UsersListFragment) getSupportFragmentManager() .findFragmentById(R.id.usersListFragment); if (Build.VERSION.SDK_INT < 16) { AlphaAnimation anim = new AlphaAnimation(0, 1); anim.setDuration(150);/*from w w w . jav a 2 s. c om*/ anim.setFillAfter(true); if (mvf != null && mvf.getListView() != null) mvf.getListView().startAnimation(anim); if (ulf != null && ulf.getListView() != null) ulf.getListView().startAnimation(anim); } else { if (mvf != null && mvf.getListView() != null) mvf.getListView().animate().alpha(1); if (ulf != null && ulf.getListView() != null) ulf.getListView().animate().alpha(1); } if (mvf != null && mvf.getListView() != null) { if (mvf.buffer != buffer && buffer != null && BuffersDataSource.getInstance().getBuffer(buffer.bid) != null) { Bundle b = new Bundle(); b.putInt("cid", buffer.cid); b.putInt("bid", buffer.bid); b.putBoolean("fade", false); mvf.setArguments(b); } mvf.showSpinner(false); } shouldFadeIn = false; } }