private boolean clickSign() { String username = txtUsername.getText().toString(); String password = txtPassword.getText().toString(); String host = getText(R.string.server_url).toString(); String urlReq = host + getText(R.string.url_login).toString(); Log.i(TAG, "username: "******"urlReq: " + urlReq); String prefFileName = (String) getText(R.string.pref_file_name); RequestTool requestTool = RequestTool.getInstance(this.getSharedPreferences(prefFileName, MODE_PRIVATE)); // setup params Map<String, String> paramsMap = new HashMap<String, String>(); paramsMap.put("login", username); paramsMap.put("password", password); // make the request Document doc = requestTool.makePostRequest(urlReq, paramsMap, true, 200); if (doc != null) { // store the details in the sharedPreferences so // other activities can use it. putUserDetailsIntoPreferences(username, password, doc); return true; } return false; }
void putUserDetailsIntoPreferences(String username, String password, Document doc) { if (doc != null) { NodeList profiles = doc.getElementsByTagName("profile"); Element profileEl = (Element) profiles.item(0); Profile profile = Profile.constructFromXml(profileEl); CacheDBAdapter cache = new CacheDBAdapter(this); cache.open(); cache.insertProfileDetails(profile); cache.close(); String prefFileName = (String) getText(R.string.pref_file_name); SharedPreferences pref = this.getSharedPreferences(prefFileName, MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); String profileIdStr = profile.getId() + "-" + username; // TODO: have to change how the backend expects profile id // profile id format (I think) is <profile_id>-<username> editor.putString(SeekYouConstants.ProfileId, profileIdStr); editor.putString(SeekYouConstants.Username, username); editor.putString(SeekYouConstants.Password, password); String photoFileName = profileIdStr + "." + profile.photoFileExtension(); Bitmap photo = BitmapFactory.decodeFile("/data/data/com.cq/files/" + photoFileName); // making sure you have the photo and you have the photo file name if (photo == null && profile.getPhotoFileName() != null && profile.getPhotoFileName().length() > 0) { editor.putString(SeekYouConstants.PhotoFileName, photoFileName); String fileUrl = getString(R.string.server_url) + "/images/" + "/thumb/" + profileIdStr + "." + profile.photoFileExtension(); photo = RequestTool.getInstance(pref).downloadImage(fileUrl); photo = ImageTool.resize(photo, 50, 50); try { FileOutputStream fos = getApplicationContext().openFileOutput(photoFileName, MODE_PRIVATE); BufferedOutputStream bos = new BufferedOutputStream(fos); photo.compress(CompressFormat.JPEG, 75, bos); bos.flush(); bos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.w("no profile picture found", e); } catch (IOException e) { e.printStackTrace(); Log.w("error writeing photo", e); } } if (profile.getStatus() == null) { profile.setStatus(""); } editor.putString(SeekYouConstants.Status, profile.getStatus()); editor.commit(); } }