List of usage examples for android.app ProgressDialog ProgressDialog
public ProgressDialog(Context context)
From source file:tm.veriloft.mapsplayground.MapsActivity.java
private void fetchAndDrawRoute(final LatLng... latLngs) { final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(SERVER_PORT); final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setMessage("Loading.."); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { @Override//from w w w.j a va 2s . co m public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { asyncHttpClient.cancelRequests(MapsActivity.this, true); showCenteredToast("Drawing route got cancelled"); } }); final RequestParams requestParams = new RequestParams(); for (LatLng latLng : latLngs) { requestParams.add("loc", latLng.latitude + "," + latLng.longitude); l("Added latLng to request, " + latLng); } asyncHttpClient.get(this, SERVER, requestParams, new JsonHttpResponseHandler() { @Override public void onStart() { progressDialog.show(); } @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { try { ArrayList<LatLng> route = MapUtils.decodePoly(response.getString("route_geometry")); PolylineOptions routeOptions = new PolylineOptions(); for (int i = 0; i < route.size(); i++) { routeOptions.add(route.get(i)); l("Returned point " + route.get(i)); if (returnedPointsMarkers) addedMarkers.add(mMap.addMarker(new MarkerOptions().position(route.get(i)) .title("#" + i + " point of #" + drawnRoutes.size()))); } routeOptions.width(ROUTE_WIDTH).color(ROUTE_COLOR); drawnRoutes.add(mMap.addPolyline(routeOptions)); List<LatLng> points = routeOptions.getPoints(); if (focusAfterRouteDraw) focusTo(points.get(0), 13); if (endMarkerRouteDraw) { LatLng trueEndPoint = MapUtils.findTrueEndPoint(latLngs[latLngs.length - 1], route.get(0), route.get(route.size() - 1)); addedMarkers.add(mMap.addMarker( new MarkerOptions().position(trueEndPoint).title("End of #" + drawnRoutes.size()))); } if (requestedPointMarkerRouteDraw) addedMarkers.add(mMap.addMarker(new MarkerOptions().position(latLngs[latLngs.length - 1]) .title("Requested point of #" + drawnRoutes.size()))); } catch (JSONException exception) { exception.printStackTrace(); showCenteredToast("Exception while parsing! Error: " + exception.getLocalizedMessage()); } } @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) { showCenteredToast("Network error! Error: " + throwable.getLocalizedMessage()); } @Override public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { showCenteredToast("Network error! Server returned non-json response, response: " + responseString + ", Error: " + throwable.getLocalizedMessage()); } @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { showCenteredToast("Network error! Error: " + throwable.getLocalizedMessage()); } @Override public void onFinish() { progressDialog.dismiss(); } }); }
From source file:org.ednovo.goorusearchwidget.SearchResults_resource.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_results_resource); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); Bundle extra = getIntent().getExtras(); if (extra != null) { searchKeyword = extra.getString("keyWord").trim(); }//from w w w . j ava2 s.c om prefsPrivate = getSharedPreferences(PREFS_PRIVATE, Context.MODE_PRIVATE); token = prefsPrivate.getString("token", ""); imageViewClose = (ImageView) findViewById(R.id.imageViewClose); imageViewSearch = (ImageView) findViewById(R.id.imageViewSearch); editTextSearchResults = (EditText) findViewById(R.id.textViewSearch); switchResColl = (Switch) findViewById(R.id.switchResColl); dialog1 = new Dialog(this); editTextSearchResults.setText(searchKeyword); imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE); dialog = new ProgressDialog(this); dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); if (checkInternetConnection()) { new getResources().execute(); } else { showDialog("Please Check Internet connection"); new getResources().execute(); } // scroll views videoScroll = (HorizontalScrollView) findViewById(R.id.videoScroll); interactiveScroll = (HorizontalScrollView) findViewById(R.id.interactiveScroll); websiteScroll = (HorizontalScrollView) findViewById(R.id.websiteScroll); textbookScroll = (HorizontalScrollView) findViewById(R.id.textbookScroll); examScroll = (HorizontalScrollView) findViewById(R.id.examScroll); handoutScroll = (HorizontalScrollView) findViewById(R.id.handoutScroll); slideScroll = (HorizontalScrollView) findViewById(R.id.slideScroll); lessonScroll = (HorizontalScrollView) findViewById(R.id.lessonScroll); // category image load more resources videoRight = (ImageView) findViewById(R.id.videoRight); interactiveRight = (ImageView) findViewById(R.id.interactiveRight); websiteRight = (ImageView) findViewById(R.id.websiteRight); textbookRight = (ImageView) findViewById(R.id.textbookRight); examRight = (ImageView) findViewById(R.id.examRight); handoutRight = (ImageView) findViewById(R.id.handoutRight); slideRight = (ImageView) findViewById(R.id.slideRight); lessonRight = (ImageView) findViewById(R.id.lessonRight); videoRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { videoCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5Videos().execute(); } else { showDialog("Please Check Internet connection"); } } }); interactiveRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { interactiveCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5interactive().execute(); } else { showDialog("Please Check Internet connection"); } } }); imageViewSearch.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String searchKeyword = editTextSearchResults.getText().toString().trim(); if (searchKeyword.length() > 0) { Intent intentResResults = new Intent(getBaseContext(), SearchResults_resource.class); searchKeyword = editTextSearchResults.getText().toString().trim(); Log.i("Search :", searchKeyword); Bundle extras = new Bundle(); extras.putString("keyWord", searchKeyword); intentResResults.putExtras(extras); startActivity(intentResResults); finish(); } else { dialog1.setTitle("Please enter a Search keyword"); dialog1.show(); } } }); websiteRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { websiteCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5website().execute(); } else { showDialog("Please Check Internet connection"); } } }); textbookRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { textbookCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5textbook().execute(); } else { showDialog("Please Check Internet connection"); } } }); examRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { examCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5exam().execute(); } else { showDialog("Please Check Internet connection"); } } }); handoutRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { handoutCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5handout().execute(); } else { showDialog("Please Check Internet connection"); } } }); slideRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { slideCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5slide().execute(); } else { showDialog("Please Check Internet connection"); } } }); lessonRight.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (checkInternetConnection()) { lessonCount++; dialog.setTitle("gooru"); dialog.setMessage("Please wait while loading..."); dialog.setCancelable(false); dialog.show(); new getNext5lesson().execute(); } else { showDialog("Please Check Internet connection"); } } }); editTextSearchResults.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: String searchKeyword = editTextSearchResults.getText().toString().trim(); if (searchKeyword.length() > 0) { Log.i("Resources", searchKeyword); Intent intentResResults = new Intent(getBaseContext(), SearchResults_resource.class); Bundle extras = new Bundle(); extras.putString("keyWord", searchKeyword); intentResResults.putExtras(extras); startActivity(intentResResults); finish(); } else { dialog1.setTitle("Please enter a Search keyword"); dialog1.show(); } return true; default: break; } } return false; } }); imageViewClose.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { finish(); } }); }
From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java
private void showProgressDialog(CharSequence message) { if (this.progressDialog == null) { this.progressDialog = new ProgressDialog(this); this.progressDialog.setIndeterminate(true); }//from w w w. j a va 2 s . co m this.progressDialog.setMessage(message); this.progressDialog.show(); }
From source file:com.sssemil.sonyirremote.ir.ir.java
public void learnAction(final String filename) { mProgressDialog = new ProgressDialog(ir.this); mProgressDialog.setMessage(getString(R.string.waiting_for_signal)); mProgressDialog.setIndeterminate(true); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); mProgressDialog.show();/* w w w .j ava 2s .c o m*/ new Thread(new Runnable() { public void run() { mProgressDialog.show(); restartIR(); state = learnKey(filename); if (state < 0) { runOnUiThread(new Runnable() { @Override public void run() { errorT(getString(R.string.failed_lk) + filename); } }); } mProgressDialog.cancel(); } }).start(); }
From source file:com.piusvelte.wapdroid.MapData.java
public void mapData() { mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setTitle(R.string.loading); mLoadingDialog.setMessage((mPair == 0 ? Wapdroid.Ranges.NETWORK : Wapdroid.Ranges.CELL)); mLoadingDialog.setCancelable(true);/* www . ja v a 2 s. c om*/ mLoadingDialog.setOnCancelListener(this); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this); mLoadingDialog.show(); mThread = new Thread() { public void run() { String ssid = "", bssid = "", towers = ""; int ctr = 0; List<Overlay> mapOverlays = mMView.getOverlays(); GeoPoint point = new GeoPoint(0, 0); Cursor pairs = MapData.this.getContentResolver().query(Wapdroid.Ranges.CONTENT_URI, new String[] { Wapdroid.Ranges._ID, Wapdroid.Ranges.SSID, Wapdroid.Ranges.BSSID, Wapdroid.Ranges.CID, Wapdroid.Ranges.LAC, Wapdroid.Ranges.RSSI_MIN, Wapdroid.Ranges.RSSI_MAX }, mPair == 0 ? Wapdroid.Ranges.NETWORK + "=" + mNetwork : Wapdroid.Ranges._ID + "=" + mPair, null, null); int ct = pairs.getCount(); if (pairs.moveToFirst()) { WapdroidItemizedOverlay pinOverlays = new WapdroidItemizedOverlay((MapData) mContext, ct); while (!interrupted() && !pairs.isAfterLast()) { ctr++; int cid = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.CID)), lac = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.LAC)), rssi_min = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.RSSI_MIN)), rssi_max = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.RSSI_MAX)), rssi_avg = Math.round((rssi_min + rssi_max) / 2), rssi_range = Math.abs(rssi_min) - Math.abs(rssi_max); mMsg = string_cellWarning + Wapdroid.Ranges.CELL + " " + Integer.toString(ctr) + " of " + Integer.toString(ct); mHandler.post(mUpdtDialog); String tower = "{" + String.format(SAddInt, cell_id, cid) + "," + String.format(SAddInt, location_area_code, lac) + "," + String.format(SAddInt, mcc, mMCC) + "," + String.format(SAddInt, mnc, mMNC); if (rssi_avg != Wapdroid.UNKNOWN_RSSI) tower += "," + String.format(SAddInt, signal_strength, rssi_avg); tower += "}"; if (ssid == "") ssid = pairs.getString(pairs.getColumnIndex(Wapdroid.Ranges.SSID)); if (bssid == "") bssid = pairs.getString(pairs.getColumnIndex(Wapdroid.Ranges.BSSID)); if (towers != "") towers += ","; towers += tower; point = getGeoPoint(bldRequest(tower, bssid)); pinOverlays.addOverlay(new WapdroidOverlayItem(point, Wapdroid.Ranges.CELL, string_cid + Integer.toString(cid) + string_linefeed + string_lac + Integer.toString(lac) + string_linefeed + string_range + Integer.toString(rssi_min) + string_colon + Integer.toString(rssi_max), mNetwork, pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges._ID)), rssi_avg, rssi_range)); pairs.moveToNext(); } if (mPair == 0) { mMsg = Wapdroid.Ranges.NETWORK + ": " + ssid; mHandler.post(mUpdtDialog); point = getGeoPoint(bldRequest(towers, bssid)); Location location = new Location(""); location.setLatitude(point.getLatitudeE6() / 1e6); location.setLongitude(point.getLongitudeE6() / 1e6); pinOverlays.addOverlay( new WapdroidOverlayItem(point, Wapdroid.Ranges.NETWORK, ssid, mNetwork), drawable_network); pinOverlays.setDistances(location); } mapOverlays.add(pinOverlays); mMController.setCenter(point); } pairs.close(); mLoadingDialog.dismiss(); interrupt(); } }; mThread.start(); }
From source file:com.oscarsalguero.solartracker.MainActivity.java
protected void showProgressDialog(String message) { if (progressDialog == null) { if (this != null) { if (!this.isFinishing()) { progressDialog = new ProgressDialog(this); progressDialog.setMessage(message); progressDialog.setCancelable(false); progressDialog.show();//from w w w .j a v a 2 s.c o m } } } }
From source file:eu.operando.operandoapp.OperandoProxyStatus.java
@Override protected void onCreate(Bundle savedInstanceState) { MainUtil.initializeMainContext(getApplicationContext()); Settings settings = mainContext.getSettings(); settings.initializeDefaultValues();/* w w w . jav a 2s .c o m*/ setCurrentThemeStyle(settings.getThemeStyle()); setTheme(getCurrentThemeStyle().themeAppCompatStyle()); super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); settings.registerOnSharedPreferenceChangeListener(this); webView = (WebView) findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); //region Floating Action Button fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class) && !MainUtil.isProxyPaused(mainContext)) { //Update Preferences to BypassProxy MainUtil.setProxyPaused(mainContext, true); fab.setImageResource(android.R.drawable.ic_media_play); //Toast.makeText(mainContext.getContext(), "-- bypass (disable) proxy --", Toast.LENGTH_SHORT).show(); } else if (MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class) && MainUtil.isProxyPaused(mainContext)) { MainUtil.setProxyPaused(mainContext, false); fab.setImageResource(android.R.drawable.ic_media_pause); //Toast.makeText(mainContext.getContext(), "-- re-enable proxy --", Toast.LENGTH_SHORT).show(); } else if (!mainContext.getAuthority() .aliasFile(BouncyCastleSslEngineSource.KEY_STORE_FILE_EXTENSION).exists()) { try { installCert(); } catch (RootCertificateException | GeneralSecurityException | OperatorCreationException | IOException ex) { Logger.error(this, ex.getMessage(), ex.getCause()); } } } }); //endregion //region TabHost final TabHost tabHost = (TabHost) findViewById(R.id.tabHost2); tabHost.setup(); TabHost.TabSpec tabSpec = tabHost.newTabSpec("wifi_ap"); tabSpec.setContent(R.id.WifiAndAccessPointsScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_home)); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("response_domain_filters"); tabSpec.setContent(R.id.ResponseAndDomainFiltersScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_filter)); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("pending_notifications"); tabSpec.setContent(R.id.PendingNotificationsScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_pending_notification)); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("logs"); tabSpec.setContent(R.id.LogsScrollView); tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_report)); tabHost.addTab(tabSpec); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { switch (tabId) { case "pending_notifications": //region Load Tab3 ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.PendingNotificationsScrollView)) .getChildAt(0)).getChildAt(1)).removeAllViews(); LoadPendingNotificationsTab(); //endregion break; case "logs": //region Load Tab 4 //because it is a heavy task it is being loaded asynchronously ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)).getChildAt(0)) .getChildAt(1)).removeAllViews(); new AsyncTask() { private ProgressDialog mProgress; private List<String[]> apps; @Override protected void onPreExecute() { super.onPreExecute(); mProgress = new ProgressDialog(MainActivity.this); mProgress.setCancelable(false); mProgress.setCanceledOnTouchOutside(false); mProgress.setTitle("Fetching Application Data Logs"); mProgress.show(); } @Override protected Object doInBackground(Object[] params) { apps = new ArrayList(); for (String[] app : getInstalledApps(false)) { apps.add(new String[] { app[0], GetDataForApp(Integer.parseInt(app[1])) }); } return null; } @Override protected void onPostExecute(Object o) { super.onPostExecute(o); mProgress.dismiss(); for (String[] app : apps) { if (app[0].contains(".")) { continue; } TextView tv = new TextView(MainActivity.this); tv.setTextSize(18); tv.setText(app[0] + " || " + app[1]); ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)) .getChildAt(0)).getChildAt(1)).addView(tv); View separator = new View(MainActivity.this); separator.setBackgroundColor(Color.BLACK); separator.setLayoutParams( new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 5)); ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)) .getChildAt(0)).getChildAt(1)).addView(separator); } } }.execute(); //endregion break; } } }); //endregion //region Buttons WiFiAPButton = (Button) findViewById(R.id.WiFiAPButton); WiFiAPButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent i = new Intent(mainContext.getContext(), AccessPointsActivity.class); startActivity(i); } }); responseFiltersButton = (Button) findViewById(R.id.responseFiltersButton); responseFiltersButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), ResponseFiltersActivity.class); startActivity(i); } }); domainFiltersButton = (Button) findViewById(R.id.domainFiltersButton); domainFiltersButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), DomainFiltersActivity.class); startActivity(i); } }); domainManagerButton = (Button) findViewById(R.id.domainManagerButton); domainManagerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), DomainManagerActivity.class); startActivity(i); } }); permissionsPerDomainButton = (Button) findViewById(R.id.permissionsPerDomainButton); permissionsPerDomainButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), PermissionsPerDomainActivity.class); startActivity(i); } }); trustedAccessPointsButton = (Button) findViewById(R.id.trustedAccessPointsButton); trustedAccessPointsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), TrustedAccessPointsActivity.class); startActivity(i); } }); updateButton = (Button) findViewById(R.id.updateButton); updateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // mark first time has not runned and update like it's initial . final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("firstTime", true); editor.commit(); DownloadInitialSettings(); } }); statisticsButton = (Button) findViewById(R.id.statisticsButton); statisticsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(mainContext.getContext(), StatisticsActivity.class); startActivity(i); } }); //endregion //region Action Bar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { setTitle(R.string.app_name); } //endregion //region Send Cached Settings //send cached settings if exist... BufferedReader br = null; try { File file = new File(MainContext.INSTANCE.getContext().getFilesDir(), "resend.inf"); StringBuilder content = new StringBuilder(); br = new BufferedReader(new FileReader(file)); String line; while ((line = br.readLine()) != null) { content.append(line); } if (content.toString().equals("1")) { File f = new File(file.getCanonicalPath()); f.delete(); new DatabaseHelper(MainActivity.this) .sendSettingsToServer(new RequestFilterUtil(MainActivity.this).getIMEI()); } } catch (Exception ex) { ex.getMessage(); } finally { try { br.close(); } catch (Exception ex) { ex.getMessage(); } } //endregion initializeProxyService(); }
From source file:com.umeng.message.example.MainActivity.java
public void showLoading() { if (dialog == null) { dialog = new ProgressDialog(this); dialog.setMessage("Loading"); }/*from w w w.ja va 2 s . c om*/ dialog.show(); }
From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java
/** * this function will initialize the ui showing the current image and reload * everything to make sure it is shown correctly *///from w w w .ja va 2 s .c o m private void initUI() { // set the actionBar title and subtitle if (actionBar != null) { actionBar.setTitle(R.string.send_image); actionBar.setSubtitle(name); // actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor // (R.color.action_bar_transparent))); // // set the statusBar color // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) // getActivity().getWindow().setStatusBarColor(getResources().getColor(R // .color.action_bar_transparent)); } // instantiate the ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.send_image_view_pager); viewPager.setAdapter(new MyPagerAdapter()); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { changePage(position, false, false); } @Override public void onPageScrollStateChanged(int state) { } }); //Cancel button pressed getView().findViewById(R.id.send_image_cancel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // just return to the chatFragment mListener.onReturnClick(); } }); //Send button pressed getView().findViewById(R.id.send_image_send).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // create the progressDialog that is to be shown while saving // the image ProgressDialog progressDialog = new ProgressDialog(getContext()); if (images.size() > 1) progressDialog.setTitle( String.format(getResources().getString(R.string.sending_images), images.size())); else progressDialog.setTitle(R.string.sending_image); // run the sendImage in a new thread because I am saving the // image and this should be done in a new thread new Thread(new SendImagesRunnable(new Handler(), getContext(), progressDialog)).start(); } }); // generate the overview only if there are at least 2 images if (images.size() > 1) { // the layoutParams for the imageView which has the following attributes: // width = height = 65dp // margin = 5dp getActivity().findViewById(R.id.send_image_overview).setVisibility(View.VISIBLE); int a = Constants.dipToPixel(getContext(), 65); RelativeLayout.LayoutParams imageViewParams = new RelativeLayout.LayoutParams(a, a); int b = Constants.dipToPixel(getContext(), 5); imageViewParams.setMargins(b, b, b, b); // the layoutParams for the backgroundView which has the following // attributes: // width = height = 71dp // margin = 2dp int c = Constants.dipToPixel(getContext(), 71); RelativeLayout.LayoutParams backgroundParams = new RelativeLayout.LayoutParams(c, c); int d = Constants.dipToPixel(getContext(), 2); backgroundParams.setMargins(d, d, d, d); // the layoutParams for the relativeLayout containing the image and // the background which has the following attributes: // width = height = wrap_content LinearLayout.LayoutParams relativeLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout linearLayout = (LinearLayout) getActivity().findViewById(R.id.send_image_overview_content); linearLayout.removeAllViewsInLayout(); int i = 0; for (Message msg : images) { // set up the imageView ImageView imageView = new ImageView(getContext()); imageView.setLayoutParams(imageViewParams); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); // load the bitmap async AsyncDrawable.BitmapWorkerTask bitmapWorker = new AsyncDrawable.BitmapWorkerTask(imageView, a, a, true); imageView.setImageDrawable(new AsyncDrawable(getResources(), null, bitmapWorker)); imageView.setOnClickListener(new overviewSelectListener(i++)); bitmapWorker.execute(FileUtils.getFile(getContext(), msg.getImageUri())); // set up the background View background = new View(getContext()); background.setLayoutParams(backgroundParams); background.setBackgroundColor(getActivity().getResources().getColor(R.color.colorPrimaryDark)); // make it invisible in the beginning background.setVisibility(View.GONE); // create the relativeLayout containing them RelativeLayout relativeLayout = new RelativeLayout(getContext()); relativeLayout.setLayoutParams(relativeLayoutParams); relativeLayout.addView(background); relativeLayout.addView(imageView); // combination of Message and overviewViews msg.setLayout(relativeLayout); msg.setBackground(background); linearLayout.addView(relativeLayout); } } else getActivity().findViewById(R.id.send_image_overview).setVisibility(View.GONE); changePage(current, true, true); showSystemUI(); }