Guest User

Untitled

a guest
Jul 9th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 KB | None | 0 0
  1. final AlertDialog.Builder alert = new AlertDialog.Builder(this);
  2. LinearLayout login = new LinearLayout(this);
  3. TextView tvUserName = new TextView(this);
  4. TextView tvPassword = new TextView(this);
  5. TextView tvURL = new TextView(this);
  6. final EditText etUserName = new EditText(this);
  7. final EditText etPassword = new EditText(this);
  8. final EditText etURL = new EditText(this);
  9. login.setOrientation(1); // 1 is for vertical orientation
  10. tvUserName.setText(getResources().getString(R.string.username));
  11. tvPassword.setText(getResources().getString(R.string.password));
  12. tvURL.setText("SiteURL");
  13. login.addView(tvURL);
  14. login.addView(etURL);
  15. login.addView(tvUserName);
  16. login.addView(etUserName);
  17. login.addView(tvPassword);
  18. etPassword.setInputType(InputType.TYPE_CLASS_TEXT
  19. | InputType.TYPE_TEXT_VARIATION_PASSWORD);
  20. login.addView(etPassword);
  21. alert.setView(login);
  22. alert.setTitle(getResources().getString(R.string.login));
  23. alert.setCancelable(true);
  24. alert.setPositiveButton(getResources().getString(R.string.login),
  25. new DialogInterface.OnClickListener() {
  26. public void onClick(final DialogInterface dialog,
  27. int whichButton) {
  28. strhwdXml = etURL.getText().toString();
  29. strUserName = etUserName.getText().toString();
  30. XmlUtil.username = strUserName;
  31. strPassword = etPassword.getText().toString();
  32. if ((strUserName.length() == 0)
  33. && (strPassword.length() == 0)
  34. && (strhwdXml.length() == 0)) {
  35. Toast.makeText(
  36. getBaseContext(),
  37. getResources().getString(
  38. R.string.userPassword),
  39. Toast.LENGTH_SHORT).show();
  40. onStart();
  41. } else {
  42. final SharedPreferences prefs = PreferenceManager
  43. .getDefaultSharedPreferences(getApplicationContext());
  44. SharedPreferences.Editor prefsEditor = prefs
  45. .edit();
  46. try {
  47. StringBuffer inStreamBuf = new StringBuffer();
  48. inStreamBuf = XmlUtil
  49. .getLoginAuthResponse(strUserName,
  50. strPassword, strhwdXml);
  51. strXmlResponse = inStreamBuf.toString();
  52. Log.e("Response:", strXmlResponse);
  53. String parsedXML = ParseResponse(strXmlResponse);
  54. if (parsedXML
  55. .equalsIgnoreCase(getResources()
  56. .getString(R.string.success))) {
  57. }
  58.  
  59. ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "",
  60. "Loading. Please wait...", true);
  61.  
  62. dialog.dismiss();
  63.  
  64. //the first thing you need to to is to initialize the progressDialog Class like this
  65.  
  66. final ProgressDialog progressBarDialog= new ProgressDialog(this);
  67.  
  68. //set the icon, title and progress style..
  69.  
  70. progressBarDialog.setIcon(R.drawable.ic_launcher);
  71.  
  72. progressBarDialog.setTitle("Showing progress...");
  73.  
  74. progressBarDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
  75.  
  76.  
  77. //setting the OK Button
  78. progressBarDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener(){
  79. public void onClick(DialogInterface dialog,
  80. int whichButton){
  81. Toast.makeText(getBaseContext(),
  82. "OK clicked!", Toast.LENGTH_SHORT).show();
  83. }
  84. });
  85.  
  86. //set the Cancel button
  87. progressBarDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener(){
  88. public void onClick(DialogInterface dialog, int whichButton){
  89. Toast.makeText(getApplicationContext(), "Cancel clicked", Toast.LENGTH_SHORT).show();
  90. }
  91. });
  92. //initialize the dialog..
  93. progressBarDialog.setProgress(0);
  94.  
  95. //setup a thread for long running processes
  96. new Thread(new Runnable(){
  97. public void run(){
  98. for (int i=0; i<=15; i++){
  99. try{
  100. Thread.sleep(1000);
  101. progressBarDialog.incrementProgressBy((int)(5));
  102. }
  103. catch(InterruptedException e){
  104. e.printStackTrace();
  105. }
  106. }
  107. //dismiss the dialog
  108. progressBarDialog.dismiss();
  109. }
  110. });
  111.  
  112. //show the dialog
  113. progressBarDialog.show();
  114.  
  115. private class DownloadingProgressTask extends
  116. AsyncTask<String, Void, Boolean> {
  117.  
  118. private ProgressDialog dialog = new ProgressDialog(ShowDescription.this);
  119.  
  120. /** progress dialog to show user that the backup is processing. */
  121.  
  122. /** application context. */
  123.  
  124. protected void onPreExecute() {
  125. this.dialog.setMessage("Please wait");
  126. this.dialog.show();
  127. }
  128.  
  129. protected Boolean doInBackground(final String... args) {
  130. try {
  131. // write your request code here
  132.  
  133.  
  134. **StringBuffer inStreamBuf = new StringBuffer();
  135. inStreamBuf = XmlUtil
  136. .getLoginAuthResponse(strUserName,
  137. strPassword, strhwdXml);
  138. strXmlResponse = inStreamBuf.toString();
  139. Log.e("Response:", strXmlResponse);
  140. String parsedXML = ParseResponse(strXmlResponse);
  141. if (parsedXML
  142. .equalsIgnoreCase(getResources()
  143. .getString(R.string.success))) {**
  144.  
  145. return true;
  146. } catch (Exception e) {
  147. Log.e("tag", "error", e);
  148. return false;
  149. }
  150. }
  151.  
  152. @Override
  153. protected void onPostExecute(final Boolean success) {
  154.  
  155. if (dialog.isShowing()) {
  156. dialog.dismiss();
  157. }
  158.  
  159. if (success) {
  160. Toast.makeText(ShowDescription.this,
  161. "File successfully downloaded", Toast.LENGTH_LONG)
  162. .show();
  163. imgDownload.setVisibility(8);
  164. } else {
  165. Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG)
  166. .show();
  167. }
  168. }
  169.  
  170. }
  171.  
  172. new DownloadingProgressTask().execute();
Add Comment
Please, Sign In to add comment