List of usage examples for android.widget ImageView setScaleType
public void setScaleType(ScaleType scaleType)
From source file:org.kontalk.ui.AbstractComposeFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // setListAdapter() is post-poned ListView list = getListView(); setMultiChoiceModeListener(this); // add header view (this must be done before setting the adapter) mHeaderView = LayoutInflater.from(getActivity()).inflate(R.layout.message_list_header, list, false); mNextPageButton = mHeaderView.findViewById(R.id.load_next_page); mNextPageButton.setOnClickListener(new View.OnClickListener() { @Override//from ww w .ja v a2s . com public void onClick(View v) { // disable button in the meantime enableHeaderView(false); // start query for the next page startMessagesQuery(mQueryHandler.getLastId()); } }); list.addHeaderView(mHeaderView, null, false); // set custom background (if any) ImageView background = (ImageView) getView().findViewById(R.id.background); Drawable bg = Preferences.getConversationBackground(getActivity()); if (bg != null) { background.setScaleType(ImageView.ScaleType.CENTER_CROP); background.setImageDrawable(bg); } else { background.setScaleType(ImageView.ScaleType.FIT_XY); background.setImageResource(R.drawable.app_background_tile); } processArguments(savedInstanceState); initAttachmentView(); }
From source file:com.listviewaddheader.cache.ImageDownloader.java
/** * Same as {@link #download(String, ImageView)}, with the possibility to * provide an additional cookie that will be used when the image will be * retrieved./*from w ww . jav a 2 s. co m*/ * * @param url * The URL of the image to download. * @param imageView * The ImageView to bind the downloaded image to. * @param cookie * A cookie String that will be used by the http connection. */ public void download(String url, ImageView imageView, String cookie, int defaultPicType) { // Logger.i(TAG, "download url:" + url); // resetPurgeTimer(); // Logger.d(TAG, ":" + System.currentTimeMillis()); Bitmap bitmap = getBitmapFromCache(url);// // Logger.d(TAG, ":" + System.currentTimeMillis()); if (bitmap == null) { // Logger.d(TAG, "get image from SD card:" + // System.currentTimeMillis()); bitmap = loadFromSDCache(url);// SD+ // Logger.d(TAG, "SD:" + System.currentTimeMillis()); } // else{ // Logger.d(TAG, "get image from cache:" + System.currentTimeMillis()); // } if (bitmap == null) { // Logger.d(TAG, "get image from network:" + // System.currentTimeMillis()); forceDownload(url, imageView, cookie, defaultPicType);// // Logger.d(TAG, ":" + System.currentTimeMillis()); } else { // Logger.d(TAG, // "got image from SD card, cancel potential download:" + // System.currentTimeMillis()); if (imageView != null) { cancelPotentialDownload(url, imageView); } // , // if (imageView instanceof MulitPointTouchImageView) { // ((MulitPointTouchImageView) imageView).setImageBitmap(bitmap); // } else { // imageView.setImageBitmap(bitmap);// // } if (mScaleType != null && imageView != null) { imageView.setScaleType(mScaleType); } if (imageView != null) { imageView.setImageBitmap(bitmap);// } // if (isImageViewCache) { // mImageViewCache.put(url, imageView); // } } // Log // Collection<Bitmap> hardValues = mHardBitmapCache.values(); // int hardTotalSize = 0; // for (Bitmap hartbitmap : hardValues) { // // hardTotalSize += (hartbitmap.getHeight() * hartbitmap.getWidth() * 4) // / 1024; // Logger.d(TAG, "hartbitmap Height:" + hartbitmap.getHeight() // + "hartbitmap Width:" + hartbitmap.getWidth()); // } // Collection<SoftReference<Bitmap>> softValues = mSoftBitmapCache // .values(); // int softTotalSize = 0; // for (SoftReference<Bitmap> softbitmap : softValues) { // // if (softbitmap != null && softbitmap.get() != null) { // softTotalSize += (softbitmap.get().getHeight() // * softbitmap.get().getWidth() * 4) / 1024; // Logger.d(TAG, "softbitmap Height:" // + softbitmap.get().getHeight() + "softbitmap Width:" // + softbitmap.get().getWidth()); // } // // } // Logger.d(TAG, "==>download() bitmap :" + hardTotalSize // + "KB :" + softTotalSize + "KB"); }
From source file:com.geeker.door.imgcache.ImageDownloader.java
/** * Same as {@link #download(String, ImageView)}, with the possibility to * provide an additional cookie that will be used when the image will be * retrieved.//from w ww .jav a2 s .co m * * @param url * The URL of the image to download. * @param imageView * The ImageView to bind the downloaded image to. * @param cookie * A cookie String that will be used by the http connection. */ public void download(String url, ImageView imageView, String cookie, int defaultPicType) { // Logger.i(TAG, "download url:" + url); // ? resetPurgeTimer(); // Logger.d(TAG, ":" + System.currentTimeMillis()); Bitmap bitmap = getBitmapFromCache(url);// // Logger.d(TAG, "?:" + System.currentTimeMillis()); if (bitmap == null) { // Logger.d(TAG, "get image from SD card:" + // System.currentTimeMillis()); bitmap = loadFromSDCache(url);// SD?+ // Logger.d(TAG, "SD??:" + System.currentTimeMillis()); } // else{ // Logger.d(TAG, "get image from cache:" + System.currentTimeMillis()); // } if (bitmap == null) { // Logger.d(TAG, "get image from network:" + // System.currentTimeMillis()); forceDownload(url, imageView, cookie, defaultPicType);// // Logger.d(TAG, "?:" + System.currentTimeMillis()); } else { // Logger.d(TAG, // "got image from SD card, cancel potential download:" + // System.currentTimeMillis()); if (imageView != null) { cancelPotentialDownload(url, imageView); } // ,? // if (imageView instanceof MulitPointTouchImageView) { // ((MulitPointTouchImageView) imageView).setImageBitmap(bitmap); // } else { // imageView.setImageBitmap(bitmap);// // } if (mScaleType != null && imageView != null) { imageView.setScaleType(mScaleType); } if (imageView != null) { imageView.setImageBitmap(bitmap);// } // if (isImageViewCache) { // mImageViewCache.put(url, imageView); // } } // Log // Collection<Bitmap> hardValues = mHardBitmapCache.values(); // int hardTotalSize = 0; // for (Bitmap hartbitmap : hardValues) { // // hardTotalSize += (hartbitmap.getHeight() * hartbitmap.getWidth() * 4) // / 1024; // Logger.d(TAG, "hartbitmap Height:" + hartbitmap.getHeight() // + "hartbitmap Width:" + hartbitmap.getWidth()); // } // Collection<SoftReference<Bitmap>> softValues = mSoftBitmapCache // .values(); // int softTotalSize = 0; // for (SoftReference<Bitmap> softbitmap : softValues) { // // if (softbitmap != null && softbitmap.get() != null) { // softTotalSize += (softbitmap.get().getHeight() // * softbitmap.get().getWidth() * 4) / 1024; // Logger.d(TAG, "softbitmap Height:" // + softbitmap.get().getHeight() + "softbitmap Width:" // + softbitmap.get().getWidth()); // } // // } // Logger.d(TAG, "?==>download() bitmap ?:" + hardTotalSize // + "KB ?:" + softTotalSize + "KB"); }
From source file:de.ub0r.android.websms.WebSMS.java
/** * Create a Emoticons {@link Dialog}./*ww w . j a v a 2 s . c om*/ * * @return Emoticons {@link Dialog} */ private Dialog createEmoticonsDialog() { final Dialog d = new Dialog(this); d.setTitle(R.string.emo_); d.setContentView(R.layout.emo); d.setCancelable(true); final String[] emoticons = this.getResources().getStringArray(R.array.emoticons); final GridView gridview = (GridView) d.findViewById(R.id.gridview); gridview.setAdapter(new BaseAdapter() { // references to our images // keep order and count synced with string-array! private Integer[] mThumbIds = { R.drawable.emo_im_angel, R.drawable.emo_im_cool, R.drawable.emo_im_crying, R.drawable.emo_im_foot_in_mouth, R.drawable.emo_im_happy, R.drawable.emo_im_kissing, R.drawable.emo_im_laughing, R.drawable.emo_im_lips_are_sealed, R.drawable.emo_im_money_mouth, R.drawable.emo_im_sad, R.drawable.emo_im_surprised, R.drawable.emo_im_tongue_sticking_out, R.drawable.emo_im_undecided, R.drawable.emo_im_winking, R.drawable.emo_im_wtf, R.drawable.emo_im_yelling }; @Override public long getItemId(final int position) { return 0; } @Override public Object getItem(final int position) { return null; } @Override public int getCount() { return this.mThumbIds.length; } @Override public View getView(final int position, final View convertView, final ViewGroup parent) { ImageView imageView; if (convertView == null) { // if it's not recycled, // initialize some attributes imageView = new ImageView(WebSMS.this); imageView.setLayoutParams(new GridView.LayoutParams(EMOTICONS_SIZE, EMOTICONS_SIZE)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(EMOTICONS_PADDING, EMOTICONS_PADDING, EMOTICONS_PADDING, EMOTICONS_PADDING); } else { imageView = (ImageView) convertView; } imageView.setImageResource(this.mThumbIds[position]); return imageView; } }); gridview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> adapter, final View v, final int id, final long arg3) { EditText et = WebSMS.this.etText; final String e = emoticons[id]; int i = et.getSelectionStart(); int j = et.getSelectionEnd(); if (i > j) { int x = i; i = j; j = x; } String t = et.getText().toString(); et.setText(t.substring(0, i) + e + t.substring(j)); et.setSelection(i + e.length()); d.dismiss(); et.requestFocus(); } }); return d; }
From source file:org.akvo.caddisfly.sensor.colorimetry.strip.ui.BrandInfoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_brand_info); final Activity activity = this; coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout); ImageView imageBrandLabel = (ImageView) findViewById(R.id.imageBrandLabel); // To start Camera Button buttonPrepareTest = (Button) findViewById(R.id.button_prepare); buttonPrepareTest.setOnClickListener(new View.OnClickListener() { @Override//from w ww. j a va 2 s . c om public void onClick(View view) { if (!ApiUtil.hasPermissions(activity, PERMISSIONS)) { ActivityCompat.requestPermissions(activity, PERMISSIONS, PERMISSION_ALL); } else { startCamera(); } } }); // To display Instructions Button buttonInstruction = (Button) findViewById(R.id.button_instructions); buttonInstruction.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(getBaseContext(), InstructionActivity.class); intent.putExtra(Constant.UUID, mUuid); startActivity(intent); } }); mUuid = getIntent().getStringExtra(Constant.UUID); if (mUuid != null) { StripTest stripTest = new StripTest(); // Display the brand in title setTitle(stripTest.getBrand(mUuid).getName()); // try { // imageBrandLabel.setBackgroundColor(Color.parseColor(stripTest.getBrand(this, mUuid).getBackground())); // } catch (Exception ignored) { // // } // Display the brand photo InputStream ims = null; try { Drawable drawable; String image = stripTest.getBrand(mUuid).getImage(); if (image.contains(File.separator)) { if (!image.contains(".")) { image = image + ".webp"; } drawable = Drawable.createFromPath(image); } else { String path = getResources().getString(R.string.striptest_images); ims = getAssets().open(path + File.separator + image + ".webp"); drawable = Drawable.createFromStream(ims, null); } imageBrandLabel.setImageDrawable(drawable); imageBrandLabel.setScaleType(stripTest.getBrand(mUuid).getImageScale().equals("centerCrop") ? ImageView.ScaleType.CENTER_CROP : ImageView.ScaleType.FIT_CENTER); } catch (Exception ex) { Timber.e(ex); } finally { if (ims != null) { try { ims.close(); } catch (IOException e) { Timber.e(e); } } } JSONArray instructions = stripTest.getBrand(mUuid).getInstructions(); if (instructions == null || instructions.length() == 0) { buttonInstruction.setVisibility(View.INVISIBLE); } } }
From source file:org.kontalk.ui.ComposeMessageFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // setListAdapter() is post-poned ListView list = getListView(); list.setFastScrollEnabled(true);//from ww w . j ava 2 s .co m setMultiChoiceModeListener(this); // add header view (this must be done before setting the adapter) mHeaderView = LayoutInflater.from(getActivity()).inflate(R.layout.message_list_header, list, false); mNextPageButton = mHeaderView.findViewById(R.id.load_next_page); mNextPageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // disable button in the meantime enableHeaderView(false); // start query for the next page startMessagesQuery(mQueryHandler.getLastId()); } }); list.addHeaderView(mHeaderView); // set custom background (if any) ImageView background = (ImageView) getView().findViewById(R.id.background); Drawable bg = Preferences.getConversationBackground(getActivity()); if (bg != null) { background.setScaleType(ImageView.ScaleType.CENTER_CROP); background.setImageDrawable(bg); } else { background.setScaleType(ImageView.ScaleType.FIT_XY); background.setImageResource(R.drawable.app_background_tile); } processArguments(savedInstanceState); initAttachmentView(); }
From source file:com.vonglasow.michael.satstat.MainActivity.java
private final void addWifiResult(ScanResult result) { final ScanResult r = result; android.view.View.OnClickListener clis = new android.view.View.OnClickListener() { @Override/*from w ww . j a v a2 s. c o m*/ public void onClick(View v) { onWifiEntryClick(r.BSSID); } }; View divider = new View(wifiAps.getContext()); divider.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 1)); divider.setBackgroundColor(getResources().getColor(android.R.color.tertiary_text_dark)); divider.setOnClickListener(clis); wifiAps.addView(divider); LinearLayout wifiLayout = new LinearLayout(wifiAps.getContext()); wifiLayout.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); wifiLayout.setOrientation(LinearLayout.HORIZONTAL); wifiLayout.setWeightSum(22); wifiLayout.setMeasureWithLargestChildEnabled(false); ImageView wifiType = new ImageView(wifiAps.getContext()); wifiType.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 3)); if (WifiCapabilities.isAdhoc(result)) { wifiType.setImageResource(R.drawable.ic_content_wifi_adhoc); } else if ((WifiCapabilities.isEnterprise(result)) || (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.EAP)) { wifiType.setImageResource(R.drawable.ic_content_wifi_eap); } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.PSK) { wifiType.setImageResource(R.drawable.ic_content_wifi_psk); } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.WEP) { wifiType.setImageResource(R.drawable.ic_content_wifi_wep); } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.OPEN) { wifiType.setImageResource(R.drawable.ic_content_wifi_open); } else { wifiType.setImageResource(R.drawable.ic_content_wifi_unknown); } wifiType.setScaleType(ScaleType.CENTER); wifiLayout.addView(wifiType); TableLayout wifiDetails = new TableLayout(wifiAps.getContext()); wifiDetails.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19)); TableRow innerRow1 = new TableRow(wifiAps.getContext()); TextView newMac = new TextView(wifiAps.getContext()); newMac.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 14)); newMac.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium); newMac.setText(result.BSSID); innerRow1.addView(newMac); TextView newCh = new TextView(wifiAps.getContext()); newCh.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2)); newCh.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium); newCh.setText(getChannelFromFrequency(result.frequency)); innerRow1.addView(newCh); TextView newLevel = new TextView(wifiAps.getContext()); newLevel.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3)); newLevel.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium); newLevel.setText(String.valueOf(result.level)); innerRow1.addView(newLevel); innerRow1.setOnClickListener(clis); wifiDetails.addView(innerRow1, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); TableRow innerRow2 = new TableRow(wifiAps.getContext()); TextView newSSID = new TextView(wifiAps.getContext()); newSSID.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19)); newSSID.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Small); newSSID.setText(result.SSID); innerRow2.addView(newSSID); innerRow2.setOnClickListener(clis); wifiDetails.addView(innerRow2, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); wifiLayout.addView(wifiDetails); wifiLayout.setOnClickListener(clis); wifiAps.addView(wifiLayout); }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
@SuppressLint("InlinedApi") private void openGridGallery() { final int tnSize = resources.getDimensionPixelSize(R.dimen.post_thumbnail_size); class GridGalleryAdapter extends ArrayAdapter<Triple<AttachmentModel, String, String>> implements View.OnClickListener, AbsListView.OnScrollListener { private final GridView view; private boolean selectingMode = false; private boolean[] isSelected = null; private volatile boolean isBusy = false; public GridGalleryAdapter(GridView view, List<Triple<AttachmentModel, String, String>> list) { super(activity, 0, list); this.view = view; this.isSelected = new boolean[list.size()]; }// w w w . j a v a2 s . c o m @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { if (isBusy) setNonBusy(); isBusy = false; } else isBusy = true; } private void setNonBusy() { if (!downloadThumbnails()) return; for (int i = 0; i < view.getChildCount(); ++i) { View v = view.getChildAt(i); Object tnTag = v.findViewById(R.id.post_thumbnail_image).getTag(); if (tnTag == null || tnTag == Boolean.FALSE) fill(view.getPositionForView(v), v, false); } } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = new FrameLayout(activity); convertView.setLayoutParams(new AbsListView.LayoutParams(tnSize, tnSize)); ImageView tnImage = new ImageView(activity); tnImage.setLayoutParams(new FrameLayout.LayoutParams(tnSize, tnSize, Gravity.CENTER)); tnImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); tnImage.setId(R.id.post_thumbnail_image); ((FrameLayout) convertView).addView(tnImage); } convertView.setTag(getItem(position).getLeft()); safeRegisterForContextMenu(convertView); convertView.setOnClickListener(this); fill(position, convertView, isBusy); if (isSelected[position]) { /*ImageView overlay = new ImageView(activity); overlay.setImageResource(android.R.drawable.checkbox_on_background);*/ FrameLayout overlay = new FrameLayout(activity); overlay.setBackgroundColor(Color.argb(128, 0, 255, 0)); if (((FrameLayout) convertView).getChildCount() < 2) ((FrameLayout) convertView).addView(overlay); } else { if (((FrameLayout) convertView).getChildCount() > 1) ((FrameLayout) convertView).removeViewAt(1); } return convertView; } private void safeRegisterForContextMenu(View view) { try { view.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { if (presentationModel == null) { Fragment currentFragment = MainApplication .getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) { currentFragment.onCreateContextMenu(menu, v, menuInfo); } } else { BoardFragment.this.onCreateContextMenu(menu, v, menuInfo); } } }); } catch (Exception e) { Logger.e(TAG, e); } } @Override public void onClick(View v) { if (selectingMode) { int position = view.getPositionForView(v); isSelected[position] = !isSelected[position]; notifyDataSetChanged(); } else { BoardFragment fragment = BoardFragment.this; if (presentationModel == null) { Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) fragment = (BoardFragment) currentFragment; } fragment.openAttachment((AttachmentModel) v.getTag()); } } private void fill(int position, View view, boolean isBusy) { AttachmentModel attachment = getItem(position).getLeft(); String attachmentHash = getItem(position).getMiddle(); ImageView tnImage = (ImageView) view.findViewById(R.id.post_thumbnail_image); if (attachment.thumbnail == null || attachment.thumbnail.length() == 0) { tnImage.setTag(Boolean.TRUE); tnImage.setImageResource(Attachments.getDefaultThumbnailResId(attachment.type)); return; } tnImage.setTag(Boolean.FALSE); CancellableTask imagesDownloadTask = BoardFragment.this.imagesDownloadTask; ExecutorService imagesDownloadExecutor = BoardFragment.this.imagesDownloadExecutor; if (presentationModel == null) { Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) { imagesDownloadTask = ((BoardFragment) currentFragment).imagesDownloadTask; imagesDownloadExecutor = ((BoardFragment) currentFragment).imagesDownloadExecutor; } } bitmapCache.asyncGet(attachmentHash, attachment.thumbnail, tnSize, chan, localFile, imagesDownloadTask, tnImage, imagesDownloadExecutor, Async.UI_HANDLER, downloadThumbnails() && !isBusy, downloadThumbnails() ? (isBusy ? 0 : R.drawable.thumbnail_error) : Attachments.getDefaultThumbnailResId(attachment.type)); } public void setSelectingMode(boolean selectingMode) { this.selectingMode = selectingMode; if (!selectingMode) { Arrays.fill(isSelected, false); notifyDataSetChanged(); } } public void selectAll() { if (selectingMode) { Arrays.fill(isSelected, true); notifyDataSetChanged(); } } public void downloadSelected(final Runnable onFinish) { final Dialog progressDialog = ProgressDialog.show(activity, resources.getString(R.string.grid_gallery_dlg_title), resources.getString(R.string.grid_gallery_dlg_message), true, false); Async.runAsync(new Runnable() { @Override public void run() { BoardFragment fragment = BoardFragment.this; if (fragment.presentationModel == null) { Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) fragment = (BoardFragment) currentFragment; } boolean flag = false; for (int i = 0; i < isSelected.length; ++i) if (isSelected[i]) if (!fragment.downloadFile(getItem(i).getLeft(), true)) flag = true; final boolean toast = flag; activity.runOnUiThread(new Runnable() { @Override public void run() { if (toast) Toast.makeText(activity, R.string.notification_download_exists_or_in_queue, Toast.LENGTH_LONG).show(); progressDialog.dismiss(); onFinish.run(); } }); } }); } } try { List<Triple<AttachmentModel, String, String>> list = presentationModel.getAttachments(); if (list == null) { Toast.makeText(activity, R.string.notifacation_updating_now, Toast.LENGTH_LONG).show(); return; } GridView grid = new GridView(activity); final GridGalleryAdapter gridAdapter = new GridGalleryAdapter(grid, list); grid.setNumColumns(GridView.AUTO_FIT); grid.setColumnWidth(tnSize); int spacing = (int) (resources.getDisplayMetrics().density * 5 + 0.5f); grid.setVerticalSpacing(spacing); grid.setHorizontalSpacing(spacing); grid.setPadding(spacing, spacing, spacing, spacing); grid.setAdapter(gridAdapter); grid.setOnScrollListener(gridAdapter); grid.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)); final Button btnToSelecting = new Button(activity); btnToSelecting.setText(R.string.grid_gallery_select); CompatibilityUtils.setTextAppearance(btnToSelecting, android.R.style.TextAppearance_Small); btnToSelecting.setSingleLine(); btnToSelecting.setVisibility(View.VISIBLE); btnToSelecting.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final LinearLayout layoutSelectingButtons = new LinearLayout(activity); layoutSelectingButtons.setOrientation(LinearLayout.HORIZONTAL); layoutSelectingButtons.setWeightSum(10f); Button btnDownload = new Button(activity); btnDownload.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3.25f)); btnDownload.setText(R.string.grid_gallery_download); CompatibilityUtils.setTextAppearance(btnDownload, android.R.style.TextAppearance_Small); btnDownload.setSingleLine(); Button btnSelectAll = new Button(activity); btnSelectAll.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3.75f)); btnSelectAll.setText(android.R.string.selectAll); CompatibilityUtils.setTextAppearance(btnSelectAll, android.R.style.TextAppearance_Small); btnSelectAll.setSingleLine(); Button btnCancel = new Button(activity); btnCancel.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3f)); btnCancel.setText(android.R.string.cancel); CompatibilityUtils.setTextAppearance(btnCancel, android.R.style.TextAppearance_Small); btnCancel.setSingleLine(); layoutSelectingButtons.addView(btnDownload); layoutSelectingButtons.addView(btnSelectAll); layoutSelectingButtons.addView(btnCancel); layoutSelectingButtons.setVisibility(View.GONE); layoutSelectingButtons.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); btnToSelecting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { btnToSelecting.setVisibility(View.GONE); layoutSelectingButtons.setVisibility(View.VISIBLE); gridAdapter.setSelectingMode(true); } }); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { btnToSelecting.setVisibility(View.VISIBLE); layoutSelectingButtons.setVisibility(View.GONE); gridAdapter.setSelectingMode(false); } }); btnSelectAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { gridAdapter.selectAll(); } }); btnDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { gridAdapter.downloadSelected(new Runnable() { @Override public void run() { btnToSelecting.setVisibility(View.VISIBLE); layoutSelectingButtons.setVisibility(View.GONE); gridAdapter.setSelectingMode(false); } }); } }); LinearLayout dlgLayout = new LinearLayout(activity); dlgLayout.setOrientation(LinearLayout.VERTICAL); dlgLayout.addView(btnToSelecting); dlgLayout.addView(layoutSelectingButtons); dlgLayout.addView(grid); Dialog gridDialog = new Dialog(activity); gridDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); gridDialog.setContentView(dlgLayout); gridDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); gridDialog.show(); } catch (OutOfMemoryError oom) { MainApplication.freeMemory(); Logger.e(TAG, oom); Toast.makeText(activity, R.string.error_out_of_memory, Toast.LENGTH_LONG).show(); } }
From source file:self.philbrown.droidQuery.$.java
/** * Adds an Image over each selected View as a mask. * In most cases, this mask can be retrieved by querying siblings. For example: * <pre>//from ww w . j a v a2 s .c o m * ImageView mask = (ImageView) $.with(myView).parent().selectChildren().selectImages().view(0); * </pre> * @param mask the bitmap to draw * @return this */ public $ mask(Bitmap mask) { for (View v : views) { ImageView image = new ImageView(context); image.setImageBitmap(mask); image.setScaleType(ScaleType.FIT_XY); ViewParent parent = v.getParent(); if (parent != null && parent instanceof ViewGroup) { image.setLayoutParams(v.getLayoutParams()); ((ViewGroup) parent).addView(image); } else if (v instanceof ViewGroup) { image.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ((ViewGroup) v).addView(image); } } return this; }
From source file:self.philbrown.droidQuery.$.java
/** * Adds an Image over each selected View as a mask. * In most cases, this mask can be retrieved by querying siblings. For example: * <pre>//from ww w .j a v a 2s .co m * ImageView mask = (ImageView) $.with(myView).parent().selectChildren().selectImages().view(0); * </pre> * @param mask the drawable to draw * @return this */ public $ mask(Drawable mask) { for (View v : views) { ImageView image = new ImageView(context); image.setImageDrawable(mask); image.setScaleType(ScaleType.FIT_XY); ViewParent parent = v.getParent(); if (parent != null && parent instanceof ViewGroup) { image.setLayoutParams(v.getLayoutParams()); ((ViewGroup) parent).addView(image); } else if (v instanceof ViewGroup) { image.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ((ViewGroup) v).addView(image); } } return this; }