List of usage examples for android.widget ImageView ImageView
public ImageView(Context context)
From source file:com.team.formal.eyeshopping.MainActivity.java
private void setUiPageViewController() { dotsCount = mAdapter.getCount();/* w w w .j a v a 2s . c o m*/ dots = new ImageView[dotsCount]; for (int i = 0; i < dotsCount; i++) { dots[i] = new ImageView(this); dots[i].setImageDrawable(getResources().getDrawable(R.drawable.main_pager_non_selecteditem_dot)); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(4, 0, 4, 0); pager_indicator.addView(dots[i], params); } dots[0].setImageDrawable(getResources().getDrawable(R.drawable.main_pager_selecteditem_dot)); }
From source file:com.my.math_quiz.SingelPlayerGameActivity.java
private void restartLevel() { additionalPage = 0;//www. ja va 2 s .c om numberOfTasksInRound = ApplicationClass.getSPCurrentNumberOfGamesInOneRound(); layoutForIndicators.removeAllViews(); //TODO move this out of constructor to restart method because if i change the number of //test in round i must also change the number and the sizes of indicators else I rrecive exception imageViews = new ImageView[numberOfTasksInRound]; int oneIndicatorWidth = ApplicationClass.getDisplaySize().x / numberOfTasksInRound; int oneIndicatorHeight = ApplicationClass.getDisplaySize().x / ApplicationClass.getMaximumNumberOfGamesInOneRound(); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(oneIndicatorWidth, oneIndicatorHeight); for (int i = 0; i < imageViews.length; i++) { imageViews[i] = new ImageView(this); imageViews[i].setLayoutParams(layoutParams); imageViews[i].setImageBitmap(taskIndicatorNotSelectedAnswer); imageViews[i].setScaleType(ScaleType.CENTER_INSIDE); layoutForIndicators.addView(imageViews[i]); } imageViews[0].setImageBitmap(taskIndicatorCurrent); titleBar.setTitle(1 + "/" + numberOfTasksInRound); levelData.clearLevelData(); tasks = levelData.getTests(numberOfTasksInRound); adapterForViewPager = new MyAdapterForSingelPLayerGameActivity(numberOfTasksInRound); pager.setAdapter(adapterForViewPager); levelData.startTimingLevel(); }
From source file:org.apache.cordova.splashscreen.SplashScreen.java
/** * Shows the splash screen over the full Activity *//* w ww .j a v a2 s .co m*/ @SuppressWarnings("deprecation") private void showSplashScreen(final boolean hideAfterDelay) { final int splashscreenTime = preferences.getInteger("SplashScreenDelay", 3000); final int drawableId = preferences.getInteger("SplashDrawableId", 0); // If the splash dialog is showing don't try to show it again if (splashDialog != null && splashDialog.isShowing()) { return; } if (drawableId == 0 || (splashscreenTime <= 0 && hideAfterDelay)) { return; } cordova.getActivity().runOnUiThread(new Runnable() { public void run() { // Get reference to display Display display = cordova.getActivity().getWindowManager().getDefaultDisplay(); Context context = webView.getContext(); // Use an ImageView to render the image because of its flexible scaling options. splashImageView = new ImageView(context); splashImageView.setImageResource(drawableId); LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); splashImageView.setLayoutParams(layoutParams); splashImageView.setMinimumHeight(display.getHeight()); splashImageView.setMinimumWidth(display.getWidth()); // TODO: Use the background color of the webView's parent instead of using the preference. splashImageView.setBackgroundColor(preferences.getInteger("backgroundColor", Color.BLACK)); if (isMaintainAspectRatio()) { // CENTER_CROP scale mode is equivalent to CSS "background-size:cover" splashImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); } else { // FIT_XY scales image non-uniformly to fit into image view. splashImageView.setScaleType(ImageView.ScaleType.FIT_XY); } // Create and show the dialog splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar); // check to see if the splash screen should be full screen if ((cordova.getActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) { splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } splashDialog.setContentView(splashImageView); splashDialog.setCancelable(false); splashDialog.show(); // Set Runnable to remove splash screen just in case if (hideAfterDelay) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { removeSplashScreen(); } }, splashscreenTime); } } }); }
From source file:com.jgkj.bxxc.fragment.IndexFragment2.java
/** * viewPager+ImageView//from w ww. j av a2 s.c o m * ? */ private void getImage() { OkHttpUtils.post().url(url).build().execute(new StringCallback() { @Override public void onError(Call call, Exception e, int i) { Toast.makeText(getActivity(), "??,????", Toast.LENGTH_LONG).show(); } @Override public void onResponse(String s, int i) { Gson gson = new Gson(); Picture pic = gson.fromJson(s, Picture.class); if (pic.getCode() == 200) { final List<String> list = pic.getResult(); if (list != null) { // listView List<View> listView = new ArrayList<View>(); for (int k = 0; k < list.size(); k++) { imageView = new ImageView(getActivity()); Glide.with(getActivity()).load(list.get(k)).placeholder(R.drawable.coach_pic) .error(R.drawable.coach_pic).into(imageView); imageView.setTag(list.get(k)); imageView.setScaleType(ImageView.ScaleType.FIT_XY); listView.add(imageView); } adapter = new MyAdapter(getActivity(), listView); SharedPreferences sp = getActivity().getSharedPreferences("PicCount", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); editor.putInt("Count", list.size()); editor.commit(); viewpager.setAdapter(adapter); } } } }); }
From source file:ca.ualberta.cs.swapmyride.View.AddInventoryActivity.java
/** * In this function (prescribed by Android), we collect all information * about the new vehicle and input it into a vehicle object. * This is then saved.// ww w .ja va 2s . c o m * * @param savedInstanceState */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.addinventory); toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar); uController = new UserController(getApplicationContext()); // TODO: Needs to smell more MVCish //vehicleImage = (ImageButton) findViewById(R.id.vehicleImage); gallery = (LinearLayout) findViewById(R.id.addinventorygallery); delete = (Button) findViewById(R.id.delete); vehicleName = (EditText) findViewById(R.id.vehicleField); vehicleQuantity = (EditText) findViewById(R.id.quantityField); vehicleComments = (EditText) findViewById(R.id.commentsField); vehiclePublic = (Switch) findViewById(R.id.ispublic); done = (Button) findViewById(R.id.button); location = (EditText) findViewById(R.id.locationField); vehicle = new Vehicle(); //Assign and display the current location geolocation = new Geolocation(); try { current = geolocation.getCurrentLocation(getApplicationContext(), this); location.setText(current.getPostalCode()); } catch (IllegalArgumentException e) { location.setText("Geolocation cannot be determined."); } /** * Using spinners to select category and quality of a vehicle - taking from the enumeration * classes we have elsewhere. This function was adapted from Biraj Zalavadia on StackOverflow * Accessed 2015-11-01 * @see <a href="http://stackoverflow.com/questions/21600781/onitemclicklistener-of-spinner">stackOverflow</a> */ categorySpinner = (Spinner) findViewById(R.id.categorySpinner); categorySpinner.setAdapter(new ArrayAdapter<VehicleCategory>(this, android.R.layout.simple_spinner_dropdown_item, VehicleCategory.values())); categorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { vehicleCategory = (VehicleCategory) categorySpinner.getSelectedItem(); } @Override public void onNothingSelected(AdapterView<?> arg0) { // What if nothing selected? } }); /** * Using spinners to select category and quality of a vehicle - taking from the enumeration * classes we have elsewhere. This function was adapted from Biraj Zalavadia on StackOverflow * Accessed 2015-11-01 * @see <a href="http://stackoverflow.com/questions/21600781/onitemclicklistener-of-spinner">stackOverflow</a> */ qualitySpinner = (Spinner) findViewById(R.id.qualitySpinner); qualitySpinner.setAdapter(new ArrayAdapter<VehicleQuality>(this, android.R.layout.simple_spinner_dropdown_item, VehicleQuality.values())); qualitySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { vehicleQuality = (VehicleQuality) qualitySpinner.getSelectedItem(); } @Override public void onNothingSelected(AdapterView<?> arg0) { // What if nothing selected? } }); final boolean loadVehicle = getIntent().hasExtra("vehiclePosition"); Vehicle loaded; if (loadVehicle) { position = getIntent().getIntExtra("vehiclePosition", 0); loaded = UserSingleton.getCurrentUser().getInventory().getList().get(position); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first vehicle.setPhotoIds(loaded.getPhotoIds()); vehicleName.setText(loaded.getName()); vehicleQuantity.setText(loaded.getQuantity().toString()); vehicleComments.setText(loaded.getComments()); vehiclePublic.setChecked(loaded.getPublic()); qualitySpinner.setSelection(loaded.getQuality().getPosition()); categorySpinner.setSelection(loaded.getCategory().getPosition()); // TODO: Fix null error issue //location.setText(loaded.getLocation().getPostalCode()); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); for (UniqueID uid : vehicle.getPhotoIds()) { photos.add(ldm.loadPhoto(uid.getID())); } for (Photo photo : photos) { ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } } //default the photo to a new photo if we are not loading a vehicle else { // TODO: Default photo? Here or set in Vehicle? Photo photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); vehicle.deletePhotoArrayList(getApplicationContext()); } LocalDataManager ldm = new LocalDataManager(getApplicationContext()); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first for (UniqueID uid : vehicle.getPhotoIds()) { Photo photo; if (UserSingleton.getDownloadPhotos()) { photo = ldm.loadPhoto(uid.getID()); } else { photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); } ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } /** * This onClick listener implements the function that clicking on the default * image box at the top of the vehicle page will open the camera and allow the * user to take a photo which will be saved directly to the vehicle object */ gallery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dispatchTakePictureIntent(); } }); /** * This onClick listener occurs when someone clicks delete. This will delete the photo * that is initialized in the view. */ delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //vehicle.setPhoto(new Photo(getApplicationContext())); //vehicleImage.setBackground(new BitmapDrawable(getResources(), vehicle.getPhoto().getImage())); vehicle.deletePhotoArrayList(getApplicationContext()); gallery.removeAllViews(); Photo photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); for (Photo photo1 : photos) { ldm.deletePhoto(photo1.getUid().getID()); } photos.clear(); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first if (vehicle.getPhotoIds().size() > 0 && UserSingleton.getDownloadPhotos()) { gallery.removeAllViews(); } for (UniqueID uid : vehicle.getPhotoIds()) { if (UserSingleton.getDownloadPhotos()) { photo = ldm.loadPhoto(uid.getID()); } newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } } }); /** * This onClick listener occurs after done button is clicked. This would save * the object to inventory -- which then makes it appear in the inventory tab. * * Taken from Oracle Documentation - we found we were required to catch the * possibility that a number might be the wrong format, or not even a number * at all. Accessed November 3, 2015. * * @see <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int-">Oracle</a> */ done.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // vehicle.setPhoto(vehicleImage); Geolocation geolocation1 = new Geolocation(); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); if (vehicleName.getText().toString().equals("")) { Toast.makeText(AddInventoryActivity.this, "Please enter name", Toast.LENGTH_SHORT).show(); return; } if (vehicleQuantity.getText().toString().equals("0") || vehicleQuantity.getText().toString().equals("")) { Toast.makeText(AddInventoryActivity.this, "Quantity cannot be 0", Toast.LENGTH_SHORT).show(); return; } vehicle.setName(vehicleName.getText().toString()); vehicle.setCategory(vehicleCategory); vehicle.setQuality(vehicleQuality); vehicle.setLocation(geolocation1.setSpecificLocation(getApplicationContext(), AddInventoryActivity.this, location.getText().toString())); //http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int- //Nov. 3/ 2015 //the error should never occur as we force the user to input a numeric value, but //we are required to catch it anyway try { vehicle.setQuantity(Integer.parseInt(vehicleQuantity.getText().toString())); } catch (NumberFormatException e) { e.printStackTrace(); } vehicle.setComments(vehicleComments.getText().toString()); vehicle.setPublic(vehiclePublic.isChecked()); vehicle.setBelongsTo(UserSingleton.getCurrentUser().getUserName()); for (Photo photo : photos) { vehicle.addPhoto(photo.getUid()); ldm.savePhoto(photo); } //add the vehicle to our current user. if (loadVehicle) { //UserSingleton.getCurrentUser().getInventory().getList().add(position, vehicle); uController.getUserInventoryItems().add(position, vehicle); //UserSingleton.getCurrentUser().getInventory().getList().remove(position+1); uController.getUserInventoryItems().remove(position + 1); } else { //UserSingleton.getCurrentUser().addItem(vehicle); uController.getCurrentUser().addItem(vehicle); } //save the user to ensure all changes are updated uController.saveCurrentUser(); Gson gson = new Gson(); String s = gson.toJson(vehicle); Log.i("SizeOfCar", Integer.toString(s.length())); /* //dont start a new activity if we are editing a vehicle if(!loadVehicle) { Intent intent = new Intent(AddInventoryActivity.this, MainMenu.class); startActivity(intent); }*/ finish(); } }); gallery.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { vehicle.deletePhotoArrayList(getApplicationContext()); gallery.removeAllViews(); LocalDataManager ldm = new LocalDataManager(getApplicationContext()); //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE //load the picture from the first for (UniqueID uid : vehicle.getPhotoIds()) { Photo photo; if (UserSingleton.getDownloadPhotos()) { photo = ldm.loadPhoto(uid.getID()); } else { photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto(); } ImageView newImage = new ImageView(getApplicationContext()); newImage.setImageBitmap(photo.getImage()); newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); newImage.setAdjustViewBounds(true); gallery.addView(newImage); } return true; } }); }
From source file:com.brodev.socialapp.view.MarketPlaceDetail.java
private void initView() { ImageView userImage = (ImageView) this.findViewById(R.id.image_user); if (!"".equals(marketPlace.getUser_image_path())) { networkUntil.drawImageUrl(userImage, marketPlace.getUser_image_path(), R.drawable.loading); }// ww w. j av a2 s.co m userImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class); intent.putExtra("user_id", marketPlace.getUser_id()); startActivity(intent); return false; } }); // set title TextView title = (TextView) this.findViewById(R.id.title); title.setText(marketPlace.getTitle()); colorView.changeColorText(title, user.getColor()); // set content TextView content = (TextView) this.findViewById(R.id.content); // interesting part starts from here here: Html.ImageGetter ig = imageGetter.create(0, marketPlace.getText(), content); content.setTag(0); content.setText(Html.fromHtml(marketPlace.getText(), ig, null)); TextView timestampTxt = (TextView) findViewById(R.id.txtTimestamp); timestampTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_on")); TextView timestamp = (TextView) findViewById(R.id.time_stamp); timestamp.setText(marketPlace.getTime_stamp()); TextView price = (TextView) this.findViewById(R.id.price); if (marketPlace.getPrice() == 0) { price.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.free")); } else { price.setText(marketPlace.getCurrency() + " " + marketPlace.getPrice()); } TextView locationTxt = (TextView) findViewById(R.id.txtLocation); locationTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.location")); TextView txtLocation = (TextView) this.findViewById(R.id.location); String location = marketPlace.getCountry_name(); if (!marketPlace.getCountry_child_name().equals("")) { location += " > " + marketPlace.getCountry_child_name(); } if (!marketPlace.getCity_name().equals("")) { location += " > " + marketPlace.getCity_name(); } txtLocation.setText(location); // set short text TextView fullnameTxt = (TextView) findViewById(R.id.txtFullname); fullnameTxt.setText(phraseManager.getPhrase(getApplicationContext(), "marketplace.posted_by")); TextView shortText = (TextView) findViewById(R.id.fullName); shortText.setText(marketPlace.getFull_name()); colorView.changeColorText(shortText, user.getColor()); shortText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { Intent intent = new Intent(MarketPlaceDetail.this, FriendTabsPager.class); intent.putExtra("user_id", marketPlace.getUser_id()); startActivity(intent); return false; } }); TextView total_like = (TextView) findViewById(R.id.total_like); total_like.setText(String.valueOf(marketPlace.getTotal_like())); colorView.changeColorText(total_like, user.getColor()); TextView total_comment = (TextView) findViewById(R.id.total_comment); total_comment.setText(String.valueOf(marketPlace.getTotal_comment())); colorView.changeColorText(total_comment, user.getColor()); ImageView likeImg = (ImageView) this.findViewById(R.id.likes_feed_txt); ImageView commentImg = (ImageView) this.findViewById(R.id.comments_feed_txt); colorView.changeColorLikeCommnent(likeImg, commentImg, user.getColor()); //get list images if (!marketPlace.getImages().equals("")) { LinearLayout listImages = (LinearLayout) findViewById(R.id.listImages); JSONObject objOutputImage = null; try { JSONArray objImages = new JSONArray(marketPlace.getImages()); for (int i = 0; i < objImages.length(); i++) { objOutputImage = objImages.getJSONObject(i); ImageView imageView = new ImageView(getApplicationContext()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( (int) getResources().getDimension(R.dimen.marketplace_image), (int) getResources().getDimension(R.dimen.marketplace_image)); lp.setMargins(5, 5, 5, 0); imageView.setLayoutParams(lp); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); final String imagePath = objOutputImage.getString("image_path"); networkUntil.drawImageUrl(imageView, imagePath, R.drawable.loading); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), ImageActivity.class); intent.putExtra("image", imagePath); intent.putExtra("title", marketPlace.getTitle()); startActivity(intent); } }); listImages.addView(imageView); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { this.findViewById(R.id.horizontalScrollView1).setVisibility(View.GONE); this.findViewById(R.id.marketplace_list_image_view).setVisibility(View.GONE); } }
From source file:dk.nordfalk.aktivitetsliste.PagerSlidingTabStrip.java
private void addIconTabBdeTekstOgBillede(final int position, int resId, String title) { FrameLayout tabfl = new FrameLayout(getContext()); ImageView tabi = new ImageView(getContext()); tabi.setContentDescription(title);//from w w w . j av a2s .c o m tabi.setImageResource(resId); tabi.setVisibility(View.INVISIBLE); TextView tabt = new TextView(getContext()); tabt.setText(title); tabt.setGravity(Gravity.CENTER); tabt.setSingleLine(); tabfl.addView(tabi); tabfl.addView(tabt); LayoutParams lp = (LayoutParams) tabi.getLayoutParams(); lp.gravity = Gravity.CENTER; lp = (LayoutParams) tabt.getLayoutParams(); lp.width = lp.height = ViewGroup.LayoutParams.MATCH_PARENT; lp.gravity = Gravity.CENTER; addTab(position, tabfl); }
From source file:com.loongsoft.qingzhou.WelcomeActivity.java
private void addDot() { ImageView dotImageView = new ImageView(this); dotImageView.setImageDrawable(getResources().getDrawable(R.drawable.welcome_dot_normal)); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(15, 15); params.setMargins(5, 5, 5, 5);/*ww w. ja v a 2 s . c o m*/ dotImageView.setLayoutParams(params); LinearLayout welcome_dots_layout = (LinearLayout) findViewById(R.id.welcome_dots); welcome_dots_layout.addView(dotImageView); mDots.add(dotImageView); }
From source file:com.yojiokisoft.yumekanow.activity.MakeCardActivity.java
/** * ???/*from www .j av a 2s. c om*/ * * @param list */ private void setBackImageList(List<BackImageEntity> list) { int cnt = mBackImgContainer.getChildCount(); if (cnt > 0) { mBackImgContainer.removeAllViews(); } int w = MyResource.dip2Px(53); int h = MyResource.dip2Px(80); int p = MyResource.dip2Px(3); int size = list.size(); for (int i = 0; i < size; i++) { ImageView image = new ImageView(this); MyImage.setImageThum(image, list.get(i)); image.setLayoutParams(new LinearLayout.LayoutParams(w, h)); image.setPadding(p, p, p, p); image.setTag(i); image.setOnClickListener(mBackImageClicked); mBackImgContainer.addView(image); } }
From source file:busradar.madison.StopDialog.java
StopDialog(final Context ctx, final int stopid, final int lat, final int lon) { super(ctx);/*from w w w. j av a 2s . c o m*/ this.stopid = stopid; // getWindow().requestFeature(Window.FEATURE_LEFT_ICON); getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); final String name = DB.getStopName(stopid); setTitle(name); routes = get_time_urls(StopDialog.this.stopid); // getWindow().setLayout(LayoutParams.FILL_PARENT, // LayoutParams.FILL_PARENT); setContentView(new RelativeLayout(ctx) { { addView(new TextView(ctx) { { setId(stop_num_id); setText(Html.fromHtml(String.format( "[<a href='http://www.cityofmadison.com/metro/BusStopDepartures/StopID/%04d.pdf'>%04d</a>]", stopid, stopid))); setPadding(0, 0, 5, 0); this.setMovementMethod(LinkMovementMethod.getInstance()); } }, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT) { { addRule(ALIGN_PARENT_RIGHT); } }); addView(new ImageView(ctx) { boolean enabled; @Override public void setEnabled(boolean e) { enabled = e; setImageResource(e ? R.drawable.love_enabled : R.drawable.love_disabled); if (e) { G.favorites.add_favorite_stop(stopid, name, lat, lon); Toast.makeText(ctx, "Added stop to Favorites", Toast.LENGTH_SHORT).show(); } else { G.favorites.remove_favorite_stop(stopid); Toast.makeText(ctx, "Removed stop from Favorites", Toast.LENGTH_SHORT).show(); } } { enabled = G.favorites.is_stop_favorite(stopid); setImageResource(enabled ? R.drawable.love_enabled : R.drawable.love_disabled); setPadding(0, 0, 10, 0); setOnClickListener(new OnClickListener() { public void onClick(View v) { setEnabled(!enabled); } }); } }, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT) { { addRule(LEFT_OF, stop_num_id); setMargins(0, -3, 0, 0); } }); addView(cur_loading_text = new TextView(ctx) { { setText("Loading..."); setPadding(5, 0, 0, 0); } }); addView(new HorizontalScrollView(ctx) { { setId(route_list_id); setHorizontalScrollBarEnabled(false); addView(new LinearLayout(ctx) { float text_size; Button cur_button; { int last_route = -1; for (int i = 0; i < routes.length; i++) { final RouteURL route = routes[i]; if (route.route == last_route) continue; last_route = route.route; addView(new Button(ctx) { public void setEnabled(boolean e) { if (e) { setBackgroundColor(0xff000000 | G.route_points[route.route].color); setTextSize(TypedValue.COMPLEX_UNIT_PX, text_size * 1.5f); } else { setBackgroundColor(0x90000000 | G.route_points[route.route].color); setTextSize(TypedValue.COMPLEX_UNIT_PX, text_size); } } { setText(G.route_points[route.route].name); setTextColor(0xffffffff); setTypeface(Typeface.DEFAULT_BOLD); text_size = getTextSize(); if (G.active_route == route.route) { setEnabled(true); cur_button = this; } else setEnabled(false); final Button b = this; setOnClickListener(new OnClickListener() { public void onClick(View v) { if (cur_button != null) { cur_button.setEnabled(false); } if (cur_button == b) { cur_button.setEnabled(false); cur_button = null; selected_route = null; update_time_display(); } else { cur_button = b; cur_button.setEnabled(true); selected_route = route; update_time_display(); } } }); } }); } } }); } }, new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) { { addRule(RelativeLayout.BELOW, stop_num_id); addRule(RelativeLayout.CENTER_HORIZONTAL); } }); addView(status_text = new TextView(ctx) { { setText(""); } }, new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) { { addRule(RelativeLayout.BELOW, route_list_id); addRule(RelativeLayout.CENTER_HORIZONTAL); } }); addView(list_view = new ListView(ctx) { { setId(time_list_id); setVerticalScrollBarEnabled(false); setAdapter(times_adapter = new BaseAdapter() { public View getView(final int position, View convertView, ViewGroup parent) { CellView v; if (convertView == null) v = new CellView(ctx); else v = (CellView) convertView; RouteTime rt = curr_times.get(position); v.setBackgroundColor(G.route_points[rt.route].color | 0xff000000); v.route_textview.setText(G.route_points[rt.route].name); if (rt.dir != null) v.dir_textview.setText("to " + rt.dir); v.time_textview.setText(rt.time); return v; } public int getCount() { return curr_times.size(); } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } }); } }, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT) { { addRule(RelativeLayout.BELOW, route_list_id); } }); } }); TextView title = (TextView) findViewById(android.R.id.title); title.setEllipsize(TextUtils.TruncateAt.MARQUEE); title.setSelected(true); title.setTextColor(0xffffffff); title.setMarqueeRepeatLimit(-1); // getWindow().set, value) // getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, // android.R.drawable.ic_dialog_info); // title.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL); if (G.active_route >= 0) for (int i = 0; i < routes.length; i++) if (routes[i].route == G.active_route) { selected_route = routes[i]; RouteURL[] rnew = new RouteURL[routes.length]; rnew[0] = selected_route; for (int j = 0, k = 1; j < routes.length; j++) if (j != i) rnew[k++] = routes[j]; routes = rnew; break; } update_time_display(); }