Example usage for android.app ProgressDialog ProgressDialog

List of usage examples for android.app ProgressDialog ProgressDialog

Introduction

In this page you can find the example usage for android.app ProgressDialog ProgressDialog.

Prototype

public ProgressDialog(Context context) 

Source Link

Document

Creates a Progress dialog.

Usage

From source file:com.wenwen.chatuidemo.activity.PersonFragment.java

private void initData() {
    // TODO Auto-generated method stub
    pd = new ProgressDialog(getActivity());
    pd.setMessage("?...");
    RequestParams params = new RequestParams();
    params.put("uid", DemoApplication.getInstance().getUserUid());
    params.put("flag", "1");
    HttpClientRequest.post(Urls.GETUSERDETAILS, params, 3000, new AsyncHttpResponseHandler() {
        @Override/* w w  w  . ja  v  a  2 s .  c o  m*/
        public void onStart() {
            // TODO Auto-generated method stub
            super.onStart();
            pd.show();
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            // TODO Auto-generated method stub
            /*
             *  * @ret int 0 ? 1 ? -1 ? -2 ?? -3 
             */
            try {
                String res = new String(arg2);
                DebugLog.i("res", res);
                final JSONObject result = new JSONObject(res);
                switch (Integer.valueOf(result.getString("ret"))) {
                case 1:
                    uname.setText(result.getString("account_name"));
                    break;
                default:
                    break;

                }
            } catch (NumberFormatException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        @Override
        public void onFinish() {
            // TODO Auto-generated method stub
            super.onFinish();
            pd.dismiss();
        }

        @Override
        public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            // TODO Auto-generated method stub

        }
    });
}

From source file:com.example.prasadnr.traquad.TraQuad.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tra_quad);
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(TraQuad.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    Builder alert = new AlertDialog.Builder(TraQuad.this);

    WifiManager managerWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    Method[] wmMethods = managerWifi.getClass().getDeclaredMethods();
    for (Method method : wmMethods) {
        if (method.getName().equals("isWifiApEnabled")) {

            try {
                isWifiAPenabled = (boolean) method.invoke(managerWifi);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();/*from  w w w. j av a 2 s .c  om*/
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }

    final ProgressDialog pDialog;
    MediaController mediaController = new MediaController(this);

    pDialog = new ProgressDialog(TraQuad.this);
    pDialog.setTitle("TraQuad app (Connecting...)");
    pDialog.setMessage("Buffering...Please wait...");
    pDialog.setCancelable(true);

    if (!isWifiAPenabled) {

        alert.setTitle("WiFi Hotspot Settings");
        alert.setMessage("Can you please connect WiFi-hotspot?");
        alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                irritation = true;
                startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                pDialog.show();
            }
        });
        alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //Dismiss AlertDialog
                pDialog.show();
                Toast.makeText(getApplicationContext(), "Please connect your WiFi!", Toast.LENGTH_LONG).show();
            }
        });
        alert.setCancelable(false);
        AlertDialog alertDialog = alert.create();
        alertDialog.show();
    }

    WebView webView = (WebView) findViewById(R.id.webView);

    if (irritation == true | isWifiAPenabled) {
        pDialog.show();
    }

    mediaController.setAnchorView(webView);
    mediaController.setVisibility(View.GONE);

    extra = getIntent().getStringExtra("VideosId");
    webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);

    final GlobalClass globalVariable = (GlobalClass) getApplicationContext();
    final String IPaddressNew = globalVariable.getIP();
    final String httpString = "http://";
    final String commandPort = String.valueOf(1500);
    final String streamPort = String.valueOf(8080);
    final String IPaddressStream = httpString + IPaddressNew + ":" + streamPort;
    final String IPaddressCommand = httpString + IPaddressNew + ":" + commandPort;
    TextView sendCharacter = (TextView) findViewById(R.id.sendCharacter);

    try {
        webView.loadUrl(IPaddressStream);
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), IPaddressNew + ":Error!", Toast.LENGTH_LONG).show();
    }

    webView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            pDialog.dismiss();
        }
    });

    final Button switchact = (Button) findViewById(R.id.btn2);
    switchact.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent act1 = new Intent(view.getContext(), Joypad.class);
            startActivity(act1);

        }
    });

    final Button hometraquad = (Button) findViewById(R.id.button5);

    hometraquad.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Intent acthometraquad = new Intent(TraQuad.this, MainActivity.class);
            startActivity(acthometraquad);
        }
    });

}

From source file:com.imalu.alyou.activity.LoginActivity.java

/**
 * //from   w  w  w  .  j  a  v  a 2s  .c  o  m
 * 
 * @param view
 */
public void login(View view) {
    if (!CommonUtils.isNetWorkConnected(this)) {
        Toast.makeText(this, R.string.network_isnot_available, Toast.LENGTH_SHORT).show();
        return;
    }

    final String username = usernameEditText.getText().toString();
    final String password = passwordEditText.getText().toString();
    //AlUApplication.currentUserNick = usernameEditText.getText().toString();

    if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password)) {

        progressShow = true;
        final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
        pd.setCanceledOnTouchOutside(false);
        pd.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                progressShow = false;
            }
        });
        pd.setMessage("...");
        pd.show();

        LoginRequest loginReq = new LoginRequest();
        loginReq.setUsername(username);
        loginReq.setPassword(password);

        NetManager.execute(NetManager.LOGIN_REQUEST_OPERATION, loginReq, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

                try {

                    pd.dismiss();
                    Log.e("login_check", " response:" + response.toString());

                    UserInfo userInfo = new UserInfo();
                    userInfo.setJsonObject(response);

                    AlUApplication.getMyInfo().setPhoneNum(username);
                    AlUApplication.getMyInfo().setPassword(password);
                    AlUApplication.getMyInfo().setHxname(userInfo.getHXName());
                    AlUApplication.getMyInfo().setId(userInfo.getID());
                    AlUApplication.getMyInfo().setUsername(userInfo.getUserName());
                    AlUApplication.getMyInfo().setKey(userInfo.getKey());
                    AlUApplication.getMyInfo().setJifen(userInfo.getJifen());
                    AlUApplication.getMyInfo().setAge(userInfo.getAge());
                    AlUApplication.getMyInfo().setLocus(userInfo.getLocus());
                    AlUApplication.getMyInfo().setRealname(userInfo.getRealName());
                    AlUApplication.getMyInfo().setSex(userInfo.getSex());
                    AlUApplication.getMyInfo().setSocietykey(userInfo.getSocietyKey());
                    AlUApplication.getMyInfo().setJiarugonghuikey(userInfo.getJiaruGonghuiKey());
                    AlUApplication.getMyInfo().setSocietyName(userInfo.getSocietyName());

                    PersonalInfoResponse personal = new PersonalInfoResponse();
                    personal.setJsonObject(response);
                    AlUApplication.getUserfans().setId(personal.getId());
                    AlUApplication.getUserfans().setJifen(personal.getJifen());
                    AlUApplication.getUserfans().setUserName(personal.getUserName());
                    AlUApplication.getUserfans().setSocietyName(personal.getSocietyName());

                    // ?????
                    AlUApplication.getInstance().setUserName(username);
                    AlUApplication.getInstance().setPassword(password);

                    User user = new User();
                    user.setId((long) userInfo.getID());
                    user.setUsername(username);
                    user.setPassword(password);
                    user.setChatuser(userInfo.getHXName());
                    saveUserToDB(user);

                    /*
                    runOnUiThread(new Runnable() {
                       public void run() {
                          pd.setMessage("...");
                       }
                    });
                    */

                    EMChatManager.getInstance().login(userInfo.getHXName(), userInfo.getHXPwd(),
                            new EMCallBack() {

                                @Override
                                public void onSuccess() {
                                    EMChatManager.getInstance().loadAllConversations();
                                }

                                @Override
                                public void onProgress(int progress, String status) {
                                    // TODO Auto-generated method stub
                                }

                                @Override
                                public void onError(int code, String message) {
                                    // TODO Auto-generated method stub
                                }
                            });

                    // ** ?logout??
                    // ** manually load all local groups and
                    // conversations in case we are auto login
                    //EMGroupManager.getInstance().loadAllGroups();

                    // demo??????username??
                    /*List<String> usernames = EMContactManager.getInstance().getContactUserNames();
                    EMLog.d("roster", "contacts size: " + usernames.size());
                            
                    for (String username : usernames) {
                       User user = new User();
                       user.setUsername(username);
                       setUserHearder(username, user);
                       userlist.put(username, user);
                    }*/
                    /*Map<String, User> userlist = new HashMap<String, User>();
                    // user""
                    User newFriends = new User();
                    newFriends.setUsername(Constant.NEW_FRIENDS_USERNAME);
                    newFriends.setNick("");
                    newFriends.setHeader("");
                    userlist.put(Constant.NEW_FRIENDS_USERNAME, newFriends);
                    // "?"
                    User groupUser = new User();
                    groupUser.setUsername(Constant.GROUP_USERNAME);
                    groupUser.setNick("?");
                    groupUser.setHeader("");
                    userlist.put(Constant.GROUP_USERNAME, groupUser);*/

                    // 
                    //AlUApplication.getInstance().setContactList(userlist);
                    // db
                    //UserDao dao = new UserDao(LoginActivity.this);
                    //List<User> users = new ArrayList<User>(userlist.values());
                    //dao.saveContactList(users);

                    // ??(??groupidgroupname????members),sdkdb
                    //EMGroupManager.getInstance().getGroupsFromServer();*/
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //?nickname ios?nick
                //boolean updatenick = EMChatManager.getInstance().updateCurrentUserNick(AlUApplication.currentUserNick);
                //if (!updatenick) {
                //   EMLog.e("LoginActivity", "update current user nick fail");
                //}

                //if (!LoginActivity.this.isFinishing())
                //pd.dismiss();
                // ?
                startActivity(new Intent(LoginActivity.this, MainActivity.class));
                finish();
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, final String responseString,
                    Throwable throwable) {
                if (!progressShow) {
                    return;
                }
                pd.dismiss();
                runOnUiThread(new Runnable() {
                    public void run() {
                        //pd.dismiss();
                        //Toast.makeText(getApplicationContext(), ": " + responseString, 0).show();

                    }
                });
            }
        });
    }
}

From source file:auribises.com.visitorbook.Activites.AdminEntryActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_admin_entry);

    ButterKnife.inject(this);

    preferences = getSharedPreferences(Util.PREFS_NAME, MODE_PRIVATE);
    editor = preferences.edit();//from   w ww .  j  a  v a2s .  c  o  m

    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("Please Wait..");
    progressDialog.setCancelable(false);

    adminentry = new Adminentry();

    adapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item);
    adapter1.add("--Select IDProof--");
    adapter1.add("Aadhar Card");
    adapter1.add("License");
    adapter1.add("PAN Card");
    adapter1.add("Voter Card");

    spIDProof.setAdapter(adapter1);

    spIDProof.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (i != 0) {
                adminentry.setIDProof(adapter1.getItem(i));
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item);
    adapter2.add("--Vehicle Type--");
    adapter2.add("None");
    adapter2.add("Car");
    adapter2.add("Bike");
    adapter2.add("Activa");

    spVehicle.setAdapter(adapter2);

    spVehicle.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (i != 0) {
                adminentry.setVehicle(adapter2.getItem(i));
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    rbMale.setOnCheckedChangeListener(this);
    rbFemale.setOnCheckedChangeListener(this);

    resolver = getContentResolver();

    requestQueue = Volley.newRequestQueue(this);

    Intent rcv = getIntent();
    updateMode = rcv.hasExtra("keyAdminentry");

    if (updateMode) {
        rcvAdminentry = (Adminentry) rcv.getSerializableExtra("keyAdminentry");
        eTxtName.setText(rcvAdminentry.getName());
        eTxtPhone.setText(rcvAdminentry.getPhone());
        eTxtEmail.setText(rcvAdminentry.getEmail());
        eTxtAddress.setText(rcvAdminentry.getAddress());
        eTxtPurpose.setText(rcvAdminentry.getPurpose());
        eTxtDate.setText(rcvAdminentry.getDate());
        eTxtTime.setText(rcvAdminentry.getTime());
        eTxtAdmin.setText(rcvAdminentry.getAdmin());
        eTxtIDProofNumber.setText(rcvAdminentry.getIDProofnumber());
        eTxtVehicleNumber.setText(rcvAdminentry.getVehiclenumber());

        if (rcvAdminentry.getGender().equals("Male")) {
            rbMale.setChecked(true);
        } else {
            rbFemale.setChecked(true);
        }

        int q = 0;
        for (int i = 0; i < adapter1.getCount(); i++) {
            if (adapter1.getItem(i).equals(rcvAdminentry.getIDProof())) {
                Log.i("TEST2", adapter1.getItem(i) + " - " + rcvAdminentry.getIDProof());
                q = i;
                break;
            }
        }
        spIDProof.setSelection(q);

        int r = 0;
        for (int i = 0; i < adapter2.getCount(); i++) {
            if (adapter2.getItem(i).equals(rcvAdminentry.getVehicle())) {
                Log.i("TEST3", adapter2.getItem(i) + " - " + rcvAdminentry.getVehicle());
                r = i;
                break;
            }
        }
        spVehicle.setSelection(r);

        btnSubmit.setText("Update");
    }
}

From source file:com.herokuapp.pushdemoandroid.DemoActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_register);
    txtName = (EditText) findViewById(R.id.txtName);
    txtEmail = (EditText) findViewById(R.id.txtEmail);
    btnRegister = (Button) findViewById(R.id.btnRegister);
    txtPassword = (EditText) findViewById(R.id.txtPassword);
    mDisplay = (TextView) findViewById(R.id.tvDisplay);
    btnLinkToLoginScreen = (Button) findViewById(R.id.btnLinkToLoginScreen);

    // Check if Internet present
    cd = new ConnectionDetector(getApplicationContext());
    // SQLite database handler
    db = new DatabaseManager(getApplicationContext());

    if (!cd.isConnectingToInternet()) {
        // Internet Connection is not present
        alert.showAlertDialog(DemoActivity.this, "Internet Connection Error",
                "Please connect to working Internet connection", false);
        // stop executing code by return
        return;/*from   ww  w .ja  v  a2s.  c  o m*/
    }

    context = getApplicationContext();
    session = new SessionManager(getApplicationContext());
    pDialog = new ProgressDialog(this);
    pDialog.setCancelable(false);

    // Check device for Play Services APK. If check succeeds, proceed with GCM registration.
    if (checkPlayServices()) {
        gcm = GoogleCloudMessaging.getInstance(this);
        regid = CommonUtilities.getRegistrationId(context);

        if (regid.isEmpty()) {
            registerInBackground();
        } else if (session.isLoggedIn()) {
            Intent i = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(i);
            finish();
        }
    } else {
        Log.i(CommonUtilities.TAG, "No valid Google Play Services APK found.");
    }

    /*
     * Click event on Register button
     * */
    btnRegister.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            username = txtName.getText().toString();
            email = txtEmail.getText().toString();
            password = txtPassword.getText().toString();

            // Check for empty data in the form
            if (email.trim().length() > 0 && password.trim().length() > 0) {
                // login user
                sendPostRequest();
            } else {
                // Prompt user to enter credentials
                Toast.makeText(getApplicationContext(), "Please enter the credentials!", Toast.LENGTH_LONG)
                        .show();
            }
        }
    });

    /*
    * Click event on LinkToLogin button
    * */
    btnLinkToLoginScreen.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(i);
            finish();
        }
    });
}

From source file:com.nextgis.mobile.map.LocalGeoJsonLayer.java

/**
 * Create a LocalGeoJsonLayer from the GeoJson data submitted by uri.
 *//* ww  w .  j a v a 2s .  c om*/
protected static void create(final MapBase map, String layerName, Uri uri) {

    String sErr = map.getContext().getString(R.string.error_occurred);
    ProgressDialog progressDialog = new ProgressDialog(map.getContext());

    try {
        InputStream inputStream = map.getContext().getContentResolver().openInputStream(uri);
        if (inputStream != null) {

            progressDialog.setMessage(map.getContext().getString(R.string.message_loading_progress));
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setCancelable(true);
            progressDialog.show();

            int nSize = inputStream.available();
            int nIncrement = 0;
            progressDialog.setMax(nSize);

            //read all geojson
            BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));

            StringBuilder responseStrBuilder = new StringBuilder();

            String inputStr;
            while ((inputStr = streamReader.readLine()) != null) {
                nIncrement += inputStr.length();
                progressDialog.setProgress(nIncrement);
                responseStrBuilder.append(inputStr);
            }

            progressDialog.setMessage(map.getContext().getString(R.string.message_opening_progress));

            JSONObject geoJSONObject = new JSONObject(responseStrBuilder.toString());

            if (!geoJSONObject.has(GEOJSON_TYPE)) {
                sErr += ": " + map.getContext().getString(R.string.error_geojson_unsupported);
                Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
                progressDialog.hide();
                return;
            }

            //check crs
            boolean isWGS84 = true; //if no crs tag - WGS84 CRS

            if (geoJSONObject.has(GEOJSON_CRS)) {
                JSONObject crsJSONObject = geoJSONObject.getJSONObject(GEOJSON_CRS);

                //the link is unsupported yet.
                if (!crsJSONObject.getString(GEOJSON_TYPE).equals(GEOJSON_NAME)) {
                    sErr += ": " + map.getContext().getString(R.string.error_geojson_crs_unsupported);
                    Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
                    progressDialog.hide();
                    return;
                }

                JSONObject crsPropertiesJSONObject = crsJSONObject.getJSONObject(GEOJSON_PROPERTIES);
                String crsName = crsPropertiesJSONObject.getString(GEOJSON_NAME);

                if (crsName.equals("urn:ogc:def:crs:OGC:1.3:CRS84")) { // WGS84
                    isWGS84 = true;
                } else if (crsName.equals("urn:ogc:def:crs:EPSG::3857")) { //Web Mercator
                    isWGS84 = false;
                } else {
                    sErr += ": " + map.getContext().getString(R.string.error_geojson_crs_unsupported);
                    Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
                    progressDialog.hide();
                    return;
                }
            }

            //load contents to memory and reproject if needed
            JSONArray geoJSONFeatures = geoJSONObject.getJSONArray(GEOJSON_TYPE_FEATURES);

            if (0 == geoJSONFeatures.length()) {
                sErr += ": " + map.getContext().getString(R.string.error_geojson_crs_unsupported);
                Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
                progressDialog.hide();
                return;
            }

            List<Feature> features = geoJSONFeaturesToFeatures(geoJSONFeatures, isWGS84, map.getContext(),
                    progressDialog);

            create(map, layerName, features);
        }

    } catch (UnsupportedEncodingException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    } catch (FileNotFoundException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    } catch (IOException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    } catch (JSONException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    }

    progressDialog.hide();
    //if we here something wrong occurred
    Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
}

From source file:edu.csh.coursebrowser.SchoolActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_course_browser);
    ListView lv = (ListView) this.findViewById(R.id.schools);
    this.setTitle("Course Browser");

    map_items = new HashMap<String, School>();
    map = new ArrayList<String>();
    this.sp = getPreferences(MODE_WORLD_READABLE);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map);
    this.setTitle("Course Browser");

    if (!sp.contains("firstRun")) {
        SharedPreferences.Editor e = sp.edit();
        e.putBoolean("firstRun", false);
        e.commit();//  www .j  a  v  a2  s .  c  om
        Intent intent = new Intent(SchoolActivity.this, AboutActivity.class);
        startActivity(intent);
    }

    addItem(new School("01", "Saunder's College of Business"));
    addItem(new School("03", "College of Engineering"));
    addItem(new School("05", "College of Liberal Arts"));
    addItem(new School("06", "Applied Science & Technology"));
    addItem(new School("08", "NTID"));
    addItem(new School("10", "College of Science"));
    addItem(new School("11", "Wellness"));
    addItem(new School("17", "Academic Services"));
    addItem(new School("20", "Imaging Arts and Sciences"));
    addItem(new School("30", "Interdisciplinary Studies"));
    addItem(new School("40", "GCCIS"));
    addItem(new School("50", "Institute for Sustainability"));

    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 School school = map_items.get(s);
            new AsyncTask<String, String, String>() {
                ProgressDialog p;

                protected void onPreExecute() {
                    p = new ProgressDialog(SchoolActivity.this);
                    p.setTitle("Fetching Info");
                    p.setMessage("Contacting Server...");
                    p.setCancelable(false);
                    p.show();
                }

                protected String doInBackground(String... school) {
                    String params = "action=getDepartments&school=" + school[0] + "&quarter=20123";
                    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();
                        return null;
                    }
                    return back;
                }

                protected void onPostExecute(String s) {
                    if (s == null || s == "") {
                        new AlertError(SchoolActivity.this, "IO Error!").show();
                        return;
                    }

                    try {
                        JSONObject jso = new JSONObject(s);
                        JSONArray jsa = new JSONArray(jso.getString("departments"));
                        ArrayList<Department> depts = new ArrayList<Department>();
                        for (int i = 0; i < jsa.length(); ++i) {
                            JSONObject obj = new JSONObject(jsa.get(i).toString());
                            depts.add(new Department(obj.getString("title"), obj.getString("id"),
                                    obj.getString("code")));
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                        new AlertError(SchoolActivity.this, "Invalid JSON From Server").show();
                        p.dismiss();
                        return;
                    }

                    Intent intent = new Intent(SchoolActivity.this, DepartmentActivity.class);
                    intent.putExtra("from", school.deptName);
                    intent.putExtra("args", s);
                    intent.putExtra("qCode", sp.getString("quarter", "20122"));
                    startActivity(intent);
                    p.dismiss();
                }
            }.execute(school.deptNum);
        }

    });

}

From source file:it.sasabz.android.sasabus.InfoActivity.java

/**
 * fills the list_view with the modes which are offered to the user
 *//*w w w.  ja v a2s . c  o m*/
public void fillData() {
    SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
    int infocity = Integer.parseInt(shared.getString("infos", "0"));

    progdial = new ProgressDialog(this);

    progdial.setMessage(getResources().getText(R.string.waiting));
    progdial.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progdial.setCancelable(false);
    progdial.show();

    InformationList info = new InformationList(this);
    info.execute(Integer.valueOf(infocity));
}

From source file:auribises.com.visitorbook.Activites.VisitorEntryActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_visitor_entry);

    ButterKnife.inject(this);

    preferences = getSharedPreferences(Util.PREFS_NAME, MODE_PRIVATE);
    editor = preferences.edit();/*from   ww  w  .ja  v a2s  .  co  m*/

    progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("Please Wait..");
    progressDialog.setCancelable(false);

    visitorentry = new Visitorentry();

    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item);
    adapter.add("--Select Branch--");
    adapter.add("Applied Sciences");
    adapter.add("Civil Engineering");
    adapter.add("Electrical Engineering");
    adapter.add("Mechanical Engineering");
    adapter.add("Electroncis & Communication Engineering");
    adapter.add("Computer Science & Engineering");
    adapter.add("Information Technology");
    adapter.add("Production Engineering");
    adapter.add("Business Administration");
    adapter.add("Computer Applications");
    ;

    spBranch.setAdapter(adapter);

    spBranch.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (i != 0) {
                visitorentry.setBranch(adapter.getItem(i));
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    adapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item);
    adapter1.add("--Select IDProof--");
    adapter1.add("Aadhar Card");
    adapter1.add("License");
    adapter1.add("PAN Card");
    adapter1.add("Voter Card");

    spIDProof.setAdapter(adapter1);

    spIDProof.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (i != 0) {
                visitorentry.setIDProof(adapter1.getItem(i));
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item);
    adapter2.add("--Vehicle Type--");
    adapter2.add("Car");
    adapter2.add("Bike");
    adapter2.add("Activa");
    adapter2.add("Auto");
    adapter2.add("Bus");

    spVehicle.setAdapter(adapter2);

    spVehicle.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (i != 0) {
                visitorentry.setVehicle(adapter2.getItem(i));
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    rbMale.setOnCheckedChangeListener(this);
    rbFemale.setOnCheckedChangeListener(this);

    resolver = getContentResolver();

    requestQueue = Volley.newRequestQueue(this);

    Intent rcv = getIntent();
    updateMode = rcv.hasExtra("keyVisitorentry");

    if (updateMode) {
        rcvVisitorentry = (Visitorentry) rcv.getSerializableExtra("keyVisitorentry");
        eTxtName.setText(rcvVisitorentry.getName());
        eTxtPhone.setText(rcvVisitorentry.getPhone());
        eTxtEmail.setText(rcvVisitorentry.getEmail());
        eTxtAddress.setText(rcvVisitorentry.getAddress());
        eTxtPurpose.setText(rcvVisitorentry.getPurpose());
        eTxtDate.setText(rcvVisitorentry.getDate());
        eTxtTime.setText(rcvVisitorentry.getTime());
        eTxtTeacher.setText(rcvVisitorentry.getTeacher());
        eTxtIDProofNumber.setText(rcvVisitorentry.getIDProofnumber());
        eTxtVehicleNumber.setText(rcvVisitorentry.getVehiclenumber());

        if (rcvVisitorentry.getGender().equals("Male")) {
            rbMale.setChecked(true);
        } else {
            rbFemale.setChecked(true);
        }

        Log.i("TEST", adapter + " - " + rcvVisitorentry.getBranch() + " - " + rcvVisitorentry.getIDProof()
                + " - " + rcvVisitorentry.getVehicle());

        int p = 0;
        for (int i = 0; i < adapter.getCount(); i++) {
            if (adapter.getItem(i).equals(rcvVisitorentry.getBranch())) {
                Log.i("TEST1", adapter.getItem(i) + " - " + rcvVisitorentry.getBranch());
                p = i;
                break;
            }
        }
        spBranch.setSelection(p);

        int q = 0;
        for (int i = 0; i < adapter1.getCount(); i++) {
            if (adapter1.getItem(i).equals(rcvVisitorentry.getIDProof())) {
                Log.i("TEST2", adapter1.getItem(i) + " - " + rcvVisitorentry.getIDProof());
                q = i;
                break;
            }
        }
        spIDProof.setSelection(q);

        int r = 0;
        for (int i = 0; i < adapter2.getCount(); i++) {
            if (adapter2.getItem(i).equals(rcvVisitorentry.getVehicle())) {
                Log.i("TEST3", adapter2.getItem(i) + " - " + rcvVisitorentry.getVehicle());
                r = i;
                break;
            }
        }
        spVehicle.setSelection(r);

        btnSubmit.setText("Update");
    }
}