List of usage examples for android.util Log v
public static int v(String tag, String msg)
From source file:com.phoneToPc.Http.java
/** * Connects to the server,//w w w . j a va2s. c o m * @return String request response (or null) */ //CommandE 0 URL public static String httpReq(CommandE command) { final HttpResponse resp; String ResString = null; final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); assert (command.GetPropertyNum() >= 2); String url = command.GetProperty(1).GetPropertyContext(); Log.d("HTTP", "httpReq : "); for (int i = 0; i < command.GetPropertyNum(); i++) { Log.d("HTTP", command.GetProperty(i).GetPropertyName() + " " + command.GetProperty(i).GetPropertyContext()); } for (int i = 2; i < command.GetPropertyNum(); i++) { params.add(new BasicNameValuePair(command.GetProperty(i).GetPropertyName(), command.GetProperty(i).GetPropertyContext())); } final HttpEntity entity; try { entity = new UrlEncodedFormEntity(params, HTTP.UTF_8); } catch (final UnsupportedEncodingException e) { // this should never happen. throw new IllegalStateException(e); } Log.i(TAG, "connect url = " + url); final HttpPost post = new HttpPost(url); post.addHeader(entity.getContentType()); post.setEntity(entity); try { resp = getHttpClient().execute(post); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { InputStream istream = (resp.getEntity() != null) ? resp.getEntity().getContent() : null; if (istream != null) { BufferedReader ireader = new BufferedReader(new InputStreamReader(istream)); ResString = ireader.readLine().trim(); Log.e(TAG, "Http Resp = " + ResString); } } else { Log.e(TAG, "getStatusCode = " + resp.getStatusLine().getStatusCode()); } } catch (final IOException e) { Log.e(TAG, "getHttpClient().execute(post)", e); return null; } finally { Log.v(TAG, "getAuthtoken completing"); } return ResString; }
From source file:org.mythtv.service.channel.v27.ChannelHelperV27.java
public boolean process(final Context context, final LocationProfile locationProfile) { Log.v(TAG, "process : enter"); if (!NetworkHelper.getInstance().isMasterBackendConnected(context, locationProfile)) { Log.w(TAG, "process : Master Backend '" + locationProfile.getHostname() + "' is unreachable"); return false; }/*from w ww.j a va2 s .co m*/ mMythServicesTemplate = (MythServicesTemplate) MythAccessFactory.getServiceTemplateApiByVersion(mApiVersion, locationProfile.getUrl()); if (null == mMythServicesTemplate) { Log.w(TAG, "process : Master Backend '" + locationProfile.getHostname() + "' is unreachable"); return false; } boolean passed = true; try { EtagInfoDelegate etag = mEtagDaoHelper.findByEndpointAndDataId(context, locationProfile, "GetVideoSourceList", null); ResponseEntity<VideoSourceList> responseEntity = mMythServicesTemplate.channelOperations() .getVideoSourceList(etag); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Log.i(TAG, "process : response returned HTTP 200"); VideoSourceList videoSourceList = responseEntity.getBody(); if (null != videoSourceList) { // holder for all downloaded channel lists List<ChannelInfo> allChannelLists = new ArrayList<ChannelInfo>(); int nap = 1000; // 500ms & 1ms fail int count = 0; for (VideoSource videoSource : videoSourceList.getVideoSources()) { Log.i(TAG, "process : videoSourceId = '" + videoSource.getId() + "'"); DateTime date = mEtagDaoHelper.findDateByEndpointAndDataId(context, locationProfile, "GetChannelInfoList", String.valueOf(videoSource.getId())); if (null != date) { DateTime now = new DateTime(DateTimeZone.UTC); if (now.getMillis() - date.getMillis() > 86400000) { // Download the channel listing, return list Log.v(TAG, "process : downloading channels"); ChannelInfo[] channelInfos = downloadChannels(context, locationProfile, videoSource.getId()); if (null != channelInfos) { allChannelLists.addAll(Arrays.asList(channelInfos)); } // wait a second before downloading the next one (if there are more than one video source) if (count < videoSourceList.getVideoSources().length - 1) { Log.i(TAG, "process : sleeping " + nap + " ms"); Thread.sleep(nap); } count++; } } else { // Download the channel listing, return list Log.v(TAG, "process : downloading channels"); ChannelInfo[] channelInfos = downloadChannels(context, locationProfile, videoSource.getId()); if (null != channelInfos) { allChannelLists.addAll(Arrays.asList(channelInfos)); } // wait a second before downloading the next one (if there are more than one video source) if (count < videoSourceList.getVideoSources().length - 1) { Log.i(TAG, "process : sleeping " + nap + " ms"); Thread.sleep(nap); } count++; } } // Process the combined lists of downloaded channels if (null != allChannelLists && !allChannelLists.isEmpty()) { Log.i(TAG, "process : process all channels"); int channelsProcessed = load(context, locationProfile, allChannelLists); Log.v(TAG, "process : channelsProcessed=" + channelsProcessed); } } } } catch (Exception e) { Log.e(TAG, "process : error", e); passed = false; } Log.v(TAG, "downloadVideoSources : exit"); return passed; }
From source file:org.mythtv.service.myth.v25.StorageGroupHelperV25.java
private List<StorageGroupDirectory> downloadStorageGroups(final LocationProfile locationProfile, final String storageGroupName) { Log.v(TAG, "downloadStorageGroups : enter"); List<StorageGroupDirectory> storageGroupDirectories = null; try {// w ww . j a v a 2 s. c o m ResponseEntity<org.mythtv.services.api.v025.beans.StorageGroupDirList> responseEntity = mMythServicesTemplate .mythOperations().getStorageGroupDirs(storageGroupName, locationProfile.getHostname(), ETagInfo.createEmptyETag()); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { org.mythtv.services.api.v025.beans.StorageGroupDirList storageGroupDirectoryList = responseEntity .getBody(); if (null != storageGroupDirectoryList.getStorageGroupDirs()) { if (null != storageGroupDirectoryList.getStorageGroupDirs() && storageGroupDirectoryList.getStorageGroupDirs().length > 0) { storageGroupDirectories = load(storageGroupDirectoryList.getStorageGroupDirs()); } } } } catch (Exception e) { Log.w(TAG, "downloadStorageGroups : error", e); } Log.v(TAG, "downloadStorageGroups : exit"); return storageGroupDirectories; }
From source file:org.mythtv.service.myth.v26.StorageGroupHelperV26.java
private List<StorageGroupDirectory> downloadStorageGroups(final LocationProfile locationProfile, final String storageGroupName) { Log.v(TAG, "downloadStorageGroups : enter"); List<StorageGroupDirectory> storageGroupDirectories = null; try {/* w w w . j av a 2s .c o m*/ ResponseEntity<org.mythtv.services.api.v026.beans.StorageGroupDirList> responseEntity = mMythServicesTemplate .mythOperations().getStorageGroupDirs(storageGroupName, locationProfile.getHostname(), ETagInfo.createEmptyETag()); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { org.mythtv.services.api.v026.beans.StorageGroupDirList storageGroupDirectoryList = responseEntity .getBody(); if (null != storageGroupDirectoryList.getStorageGroupDirs()) { if (null != storageGroupDirectoryList.getStorageGroupDirs() && storageGroupDirectoryList.getStorageGroupDirs().length > 0) { storageGroupDirectories = load(storageGroupDirectoryList.getStorageGroupDirs()); } } } } catch (Exception e) { Log.w(TAG, "downloadStorageGroups : error", e); } Log.v(TAG, "downloadStorageGroups : exit"); return storageGroupDirectories; }
From source file:org.mythtv.service.myth.v27.StorageGroupHelperV27.java
private List<StorageGroupDirectory> downloadStorageGroups(final LocationProfile locationProfile, final String storageGroupName) { Log.v(TAG, "downloadStorageGroups : enter"); List<StorageGroupDirectory> storageGroupDirectories = null; try {/*from ww w.j a va2 s. com*/ ResponseEntity<org.mythtv.services.api.v027.beans.StorageGroupDirList> responseEntity = mMythServicesTemplate .mythOperations().getStorageGroupDirs(storageGroupName, locationProfile.getHostname(), ETagInfo.createEmptyETag()); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { org.mythtv.services.api.v027.beans.StorageGroupDirList storageGroupDirectoryList = responseEntity .getBody(); if (null != storageGroupDirectoryList.getStorageGroupDirs()) { if (null != storageGroupDirectoryList.getStorageGroupDirs() && storageGroupDirectoryList.getStorageGroupDirs().length > 0) { storageGroupDirectories = load(storageGroupDirectoryList.getStorageGroupDirs()); } } } } catch (Exception e) { Log.w(TAG, "downloadStorageGroups : error", e); } Log.v(TAG, "downloadStorageGroups : exit"); return storageGroupDirectories; }
From source file:edu.csh.coursebrowser.CourseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_course); // Show the Up button in the action bar. this.getActionBar().setHomeButtonEnabled(false); map_item = new HashMap<String, Course>(); map = new ArrayList<String>(); Bundle args = this.getIntent().getExtras(); this.setTitle(args.getCharSequence("title")); try {//from w w w. ja va 2 s . co m JSONObject jso = new JSONObject(args.get("args").toString()); JSONArray jsa = new JSONArray(jso.getString("courses")); ListView lv = (ListView) this.findViewById(R.id.course_list); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map); for (int i = 0; i < jsa.length(); ++i) { String s = jsa.getString(i); JSONObject obj = new JSONObject(s); Course course = new Course(obj.getString("title"), obj.getString("department"), obj.getString("course"), obj.getString("description"), obj.getString("id")); addItem(course); Log.v("Added", course.toString()); } lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String s = ((TextView) arg1).getText().toString(); final Course course = map_item.get(s); new AsyncTask<String, String, String>() { ProgressDialog p; protected void onPreExecute() { p = new ProgressDialog(CourseActivity.this); p.setTitle("Fetching Info"); p.setMessage("Contacting Server..."); p.setCancelable(false); p.show(); } protected String doInBackground(String... dep) { String params = "action=getSections&course=" + course.id; Log.v("Params", params); URL url; String back = ""; try { url = new URL("http://iota.csh.rit" + ".edu/schedule/js/browseAjax" + ".php"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(params); writer.flush(); String line; BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { Log.v("Back:", line); back += line; } writer.close(); reader.close(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); p.dismiss(); return null; } return back; } protected void onPostExecute(String s) { if (s == null || s == "") { new AlertError(CourseActivity.this, "IO Error!").show(); return; } try { JSONObject jso = new JSONObject(s); JSONArray jsa = new JSONArray(jso.getString("sections")); } catch (JSONException e) { e.printStackTrace(); new AlertError(CourseActivity.this, "Invalid JSON From Server").show(); p.dismiss(); return; } Intent intent = new Intent(CourseActivity.this, SectionsActivity.class); intent.putExtra("title", course.title); intent.putExtra("id", course.id); intent.putExtra("description", course.description); intent.putExtra("args", s); startActivity(intent); p.dismiss(); } }.execute(course.id); } }); } catch (JSONException e) { // TODO Auto-generated catch block new AlertError(this, "Invalid JSON"); e.printStackTrace(); } }
From source file:com.carreygroup.JARVIS.Demon.java
/******************************ConnectionListener******************************/ public void AddConnectionListener(ConnectionListener listener) { try {//from w w w . jav a 2 s . c o m for (ConnectionListener ConnListener : mConnListeners) { if (listener == ConnListener) return; } mConnListeners.add(listener); if (Connected()) { listener.onConnected(this); } } catch (Exception e) { Log.v("_DEBUG", e.getLocalizedMessage()); } }
From source file:fi.mikuz.boarder.connection.ConnectionManager.java
public ConnectionManager(ConnectionListener connectionListener, final String url, final HashMap<String, String> sendList) { this.connectionListener = connectionListener; Thread t = new Thread() { public void run() { JSONObject json = new JSONObject(); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); if (sendList != null) { for (String key : sendList.keySet()) { json.put(key, sendList.get(key)); }//w w w . j a v a 2 s .c om } json.put(InternetMenu.HTML_FILTER, false); StringEntity se = new StringEntity(json.toString()); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); if (GlobalSettings.getSensitiveLogging()) Log.v(TAG, "Sending to " + url + ": " + json.toString()); HttpResponse response = httpclient.execute(httppost); InputStream in = response.getEntity().getContent(); //Get the data in the entity String result = convertStreamToString(in); try { if (GlobalSettings.getSensitiveLogging()) Log.v(TAG, "Got from " + url + ": " + result); else Log.v(TAG, "Got answer from " + url); connectionSuccessfulResponse = new ConnectionSuccessfulResponse(new JSONObject(result), ConnectionUtils.getUrlConnectionId(url)); mHandler.post(connectionSuccessful); } catch (JSONException e) { Log.e(TAG, "Couldn't convert to JSON object", e); connectionErrorResponse = new ConnectionErrorResponse(Html.fromHtml(result).toString(), url); mHandler.post(connectionError); } } catch (Exception e) { String error = "Cannot establish connection"; Log.e(TAG, error); connectionErrorResponse = new ConnectionErrorResponse(error, ConnectionUtils.getUrlConnectionId(url)); mHandler.post(connectionError); } } }; t.start(); }
From source file:com.example.fypv2.dataprocessor.TwitterDataProcessor.java
@Override public List<Marker> load(String rawData, int taskId, int colour) throws JSONException { List<Marker> markers = new ArrayList<Marker>(); JSONObject root = convertToJSON(rawData); JSONArray dataArray = root.getJSONArray("results"); int top = Math.min(MAX_JSON_OBJECTS, dataArray.length()); for (int i = 0; i < top; i++) { JSONObject jo = dataArray.getJSONObject(i); Marker ma = null;// w w w . ja v a 2 s. co m if (jo.has("geo")) { Double lat = null, lon = null; if (!jo.isNull("geo")) { JSONObject geo = jo.getJSONObject("geo"); JSONArray coordinates = geo.getJSONArray("coordinates"); lat = Double.parseDouble(coordinates.getString(0)); lon = Double.parseDouble(coordinates.getString(1)); } else if (jo.has("location")) { // Regex pattern to match location information // from the location setting, like: // iPhone: 12.34,56.78 // T: 12.34,56.78 // 12.34,56.78 Pattern pattern = Pattern.compile("\\D*([0-9.]+),\\s?([0-9.]+)"); Matcher matcher = pattern.matcher(jo.getString("location")); if (matcher.find()) { lat = Double.parseDouble(matcher.group(1)); lon = Double.parseDouble(matcher.group(2)); } } if (lat != null) { Log.v(MainFrame.TAG, "processing Twitter JSON object"); String user = jo.getString("from_user"); String url = "http://twitter.com/" + user; //no ID is needed, since identical tweet by identical user may be safely merged into one. ma = new SocialMarker("", user + ": " + jo.getString("text"), lat, lon, 0, url, taskId, colour); markers.add(ma); } } } return markers; }
From source file:com.huison.DriverAssistant_Web.util.LoginHelper.java
public static void login(final BaseActivity activity, final String username, final String password, final boolean autoLogin) { Log.i(TAG, "call login func:" + username + "/" + password); ctx = activity;/*w ww . j av a 2 s. c o m*/ UmengEventSender.sendEvent(activity, UmengEventTypes.login); final ProgressDialog pd = new ProgressDialog(activity); pd.setMessage(activity.getString(R.string.logging_wait)); pd.show(); AsyncHttpClient client = activity.getAsyncHttpClient(); RequestParams params = new RequestParams(); try { JSONObject p = new JSONObject(); p.put("mobile", username); p.put("password", password); p.put("method", "login"); p.put("version", activity.getVersionName()); p.put("devicetype", "android"); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date curDate = new Date(System.currentTimeMillis()); String time = formatter.format(curDate); p.put("time", time); Log.i(TAG, "request parameters: " + p.toString()); String data = Util.DesJiaMi(p.toString(), "czxms520"); Log.i(TAG, "post data:" + data); params.put("data", data); } catch (Exception e) { activity.showMessageBox(activity.getString(R.string.wrong_profile)); Log.e(TAG, e.getMessage()); e.printStackTrace(); return; } // params.put("xml", BaseActivity.getXML(map)); Log.i(TAG, "AsyncHttpClient post:" + BaseActivity.REQUESTURL); client.post(BaseActivity.REQUESTURL, params, new JsonHttpResponseHandler() { @Override public void onDispatchSuccess(int statusCode, Header[] headers, String result) { Log.i(TAG, "onDispatchSuccess: " + result); pd.dismiss(); try { Log.i(TAG, "decrypting..."); result = Util.decrypt(result, "czxms520"); Log.v(TAG, "result decrypted :" + result); JSONObject jo = new JSONObject(result); String code = jo.getString("code"); String msg = getJSONValueAsString(jo, "message"); if (code.equals("0")) { jo = new JSONObject(jo.getString("data")); // String loginTime = getJSONValueAsString(jo, "LastLogin"); // String lastLoginTime = getJSONValueAsString(jo, "LastLogin"); // SESSIONKEY /* * String sessionKey = getJSONValueAsString( jo, * "sessionkey"); */ // String urlHead = getJSONValueAsString(jo, "PhotoUrl"); String photoUrl = getJSONValueAsString(jo, "PhotoUrl"); String phone = getJSONValueAsString(jo, "Mobile"); Boolean vip = false; if (String.valueOf(jo.getInt("Vip")).equals("1")) { vip = true; } else { vip = false; } Env.isLogined = BaseActivity.isLogined = true; Log.v(TAG, ":1"); activity.markLogin(phone, phone, password, autoLogin, "", loginTime, lastLoginTime, vip); if (!photoUrl.equals("")) { String finalHeadUrl = URLDecoder.decode(photoUrl, "utf-8"); BaseActivity.setUserHeadUrl(finalHeadUrl); BaseActivity.setUserHeadDrawable(null); } else { BaseActivity.setUserHeadUrl(""); BaseActivity.setUserHeadDrawable(null); } // sendMsg(ConfigActivity.thiz,0); // start HomeActivity.now_mobile = phone; // end // // Log.v("", "kk" + phone); LoginActivity.instance.finish(); Util.saveFile(phone, Environment.getExternalStorageDirectory() + "/xmsphone.txt"); SharedPreferences.Editor sharedata = activity.getSharedPreferences("MyData", 0).edit(); sharedata.putString("isJZMM_czxms", "true"); sharedata.commit(); Log.i(TAG, ":2"); sendMsg(0); sendMsg(ConfigActivity.thiz, 2); activity.finish(); } else { Log.e(TAG, "server notify failed: error:" + msg); LoginActivity.pw.setText(""); activity.showMessageBox(msg); } } catch (JSONException e) { Log.e(TAG, "login error" + Log.getStackTraceString(e)); e.printStackTrace(); activity.showMessageBox(activity.getText(R.string.server404)); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); //e.printStackTrace(); activity.showMessageBox(",."); } } @Override public void onFailureAnyway(int statusCode, Header[] headers, Throwable throwable, BaseBinaryResponse jsonResponse) { Log.i(TAG, "onFailureAnyway: " + statusCode); pd.dismiss(); activity.showMessageBox(activity.getText(R.string.server404)); } @Override public void onSuccessAnyway(int statusCode, Header[] headers, BaseBinaryResponse jsonResponse) { Log.i(TAG, "onSuccessAnyway: " + statusCode); } }); TimeCounter.countTime(activity, pd); }