List of usage examples for android.widget ImageView setId
public void setId(@IdRes int id)
From source file:app.sunstreak.yourpisd.LoginActivity.java
/** * Shows the progress UI and hides the login form. *///from w w w . j a v a 2 s . c o m @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) private void showProgress(final boolean show) { // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow // for very easy animations. If available, use these APIs to fade-in // the progress spinner. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); mLoginFormView.setVisibility(View.VISIBLE); mLoginFormView.animate().setDuration(shortAnimTime) //.translationY(-200) .alpha(show ? 0 : 1).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); } }); mLoginStatusView.setVisibility(View.VISIBLE); mLoginStatusView.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE); } }); // mLoginFormView.setVisibility(View.VISIBLE); // mLoginFormView.animate().setDuration(500).setInterpolator(new DecelerateInterpolator()) // .translationY(height*(show? -1 : 1)).setListener(new AnimatorListenerAdapter() { // @Override // public void onAnimationEnd(Animator animation) { // mLoginFormView.setVisibility(show ? View.INVISIBLE // : View.VISIBLE); // } // }); // mLoginStatusView.setVisibility(View.VISIBLE); // mLoginStatusView.animate().setDuration(shortAnimTime).translationY(0) // .setListener(new AnimatorListenerAdapter() { // @Override // public void onAnimationEnd(Animator animation) { // mLoginStatusView.setVisibility(show ? View.VISIBLE // : View.INVISIBLE); // System.out.println("show loading: " + show); // } // }); if (DateHelper.isAprilFools()) { mLoginStatusView.removeAllViews(); try { ImageView img = new ImageView(this); //noinspection ResourceType img.setId(1337); InputStream is = getAssets().open("nyan.png"); img.setImageBitmap(BitmapFactory.decodeStream(is)); is.close(); TextView april = new TextView(this); april.setText( "Today and tomorrow, we shall pay \"homage\" to the numerous poor designs of the internet"); april.setGravity(Gravity.CENTER_HORIZONTAL); mLoginStatusView.addView(img); mLoginStatusView.addView(april); RotateAnimation rotateAnimation1 = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation1.setInterpolator(new LinearInterpolator()); rotateAnimation1.setDuration(500); rotateAnimation1.setRepeatCount(Animation.INFINITE); img.startAnimation(rotateAnimation1); } catch (Exception e) { e.printStackTrace(); return; } } // mLoginStatusView.animate().setDuration(shortAnimTime) // .alpha(show ? 1 : 0) // .setListener(new AnimatorListenerAdapter() { // @Override // public void onAnimationEnd(Animator animation) { // mLoginStatusView.setVisibility(show ? View.VISIBLE // : View.GONE); // } // }); // mLoginFormView.setVisibility(View.VISIBLE); // mLoginFormView.animate().setDuration(shortAnimTime) // .alpha(show ? 0 : 1) // .setListener(new AnimatorListenerAdapter() { // @Override // public void onAnimationEnd(Animator animation) { // mLoginFormView.setVisibility(show ? View.GONE // : View.VISIBLE); // } // }); } /* else if(getIntent().getExtras().getBoolean("Refresh")){ // The ViewPropertyAnimator APIs are not available, so simply show // and hide the relevant UI components. mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE); mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); }*/ }
From source file:org.egov.android.view.activity.ComplaintDetailActivity.java
/** * Function called when the activity was created to show the images attached * with the complaints Get the files from the complaint folder path and show * that images in horizontal scroll view */// ww w . j ava 2s.co m private void _showComplaintImages() { File folder = new File(complaintFolderName); if (!folder.exists()) { return; } File[] listOfFiles = folder.listFiles(); int imageidx = 0; for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { Log.d("EGOV_JOB", "File path" + complaintFolderName + File.separator + listOfFiles[i].getName()); if (listOfFiles[i].getName().startsWith("photo_")) { continue; } ImageView image = new ImageView(this); Bitmap bmp = _getBitmapImage(complaintFolderName + File.separator + listOfFiles[i].getName()); image.setImageBitmap(bmp); image.setId(imageidx); imageidx = imageidx + 1; image.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent photo_viewer = new Intent(ComplaintDetailActivity.this, PhotoViewerActivity.class); photo_viewer.putExtra("path", complaintFolderName); photo_viewer.putExtra("complaintId", complaintId); photo_viewer.putExtra("imageId", v.getId()); startActivity(photo_viewer); } }); LinearLayout.LayoutParams inner_container_params = new LinearLayout.LayoutParams(_dpToPix(90), _dpToPix(90)); inner_container_params.setMargins(0, 0, 10, 0); image.setLayoutParams(inner_container_params); image.setPadding(2, 2, 2, 2); image.setBackgroundDrawable(getResources().getDrawable(R.drawable.edittext_border)); image.setScaleType(ScaleType.CENTER_INSIDE); imageCntainer.addView(image); } } }
From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java
/** * Drop money from the top of the layout to the bottom simulating that a * coin or bill is inserted in the moneybox. * /* w w w. j a va2 s . co m*/ * @param leftMargin * Left side of the coin/bill * @param width * Width of the image to slide down * @param m * Movement with the value of the money to drop */ protected void dropMoney(int leftMargin, int width, Movement m) { ImageView money; AnimationSet moneyDrop; RelativeLayout layout; RelativeLayout.LayoutParams lpParams; Rect r; Activity parent; CurrencyValueDef curr; parent = getActivity(); curr = CurrencyManager.getCurrencyDef(Math.abs(m.getAmount())); r = curr.getDrawable().getBounds(); money = new ImageView(parent); money.setVisibility(View.INVISIBLE); money.setImageDrawable(curr.getDrawable().getConstantState().newDrawable()); money.setTag(curr); money.setId((int) m.getIdMovement()); layout = findLayout(); lpParams = new RelativeLayout.LayoutParams(r.width(), r.height()); lpParams.leftMargin = leftMargin; lpParams.rightMargin = layout.getWidth() - (leftMargin + width); lpParams.topMargin = 0; lpParams.bottomMargin = r.height(); layout.addView(money, lpParams); moneyDrop = createDropAnimation(money, layout, curr); money.setVisibility(View.VISIBLE); SoundsManager.playMoneySound(curr.getType()); VibratorManager.vibrateMoneyDrop(curr.getType()); money.startAnimation(moneyDrop); }
From source file:com.retroteam.studio.retrostudio.EditorLandscape.java
/** * Create all the views associated with a track. * @param waveDrawableID/* w ww . j a v a2 s . c o m*/ * @param projectLoad * @return */ private ImageView addTrack(int waveDrawableID, boolean projectLoad) { //add the track with the measure adder to the view //get layout LinearLayout track_layout = (LinearLayout) findViewById(R.id.track_layout); //create track container HorizontalScrollView track_container = new HorizontalScrollView(getApplicationContext()); track_container.setLayoutParams(new HorizontalScrollView.LayoutParams( HorizontalScrollView.LayoutParams.MATCH_PARENT, displaysize.y / 4)); track_container.setBackground(getResources().getDrawable(R.color.track_container_bg)); //create grid layout GridLayout track_grid = new GridLayout(getApplicationContext()); track_grid.setColumnCount(100); track_grid.setRowCount(1); track_grid.setOrientation(GridLayout.HORIZONTAL); track_grid.setId(R.id.track_grid); //create linear layout for track id and wave LinearLayout track_identifier = new LinearLayout(getApplicationContext()); track_identifier.setLayoutParams(new LinearLayout.LayoutParams(displaysize.x / 14, displaysize.y / 4)); track_identifier.setOrientation(LinearLayout.VERTICAL); track_identifier.setBackgroundColor(getResources().getColor(R.color.black_overlay)); //create textview for linear layout TextView track_num = new TextView(getApplicationContext()); track_num.setText("1"); track_num.setTextSize(45); track_num.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL); //create imageview for linear layout ImageView track_type = new ImageView(getApplicationContext()); track_type.setImageResource(waveDrawableID); track_type.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); //create "add measure" for grid layout ImageView add_measure = new ImageView(getApplicationContext()); add_measure.setImageResource(R.drawable.measure_new); add_measure.setLayoutParams(new LinearLayout.LayoutParams((int) (displaysize.x / 3.32), LinearLayout.LayoutParams.MATCH_PARENT)); if (projectLoad) { add_measure.setTag(R.id.TAG_ROW, trackReloadCounter); add_measure.setId(trackReloadCounter + 4200); } else { add_measure.setTag(R.id.TAG_ROW, theproject.size() - 1); add_measure.setId(theproject.size() - 1 + 4200); } add_measure.setTag(R.id.TAG_COLUMN, 0); add_measure.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { addMeasure(v, false); } }); track_identifier.addView(track_num); if (projectLoad) { track_num.setText(Integer.toString(trackReloadCounter + 1)); trackReloadCounter += 1; } else { track_num.setText(Integer.toString(theproject.size())); } track_num.setTextSize(45); track_identifier.addView(track_type); track_grid.addView(track_identifier); track_grid.addView(add_measure); track_container.addView(track_grid); track_layout.addView(track_container); return add_measure; }
From source file:com.wallerlab.compcellscope.Image_Gallery.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image__gallery); counter = 0;/* w w w. j a va 2 s . c o m*/ final ImageView currPic = new ImageView(this); DisplayMetrics metrics = this.getResources().getDisplayMetrics(); final int screen_width = metrics.widthPixels; SharedPreferences settings = getSharedPreferences(Folder_Chooser.PREFS_NAME, 0); //SharedPreferences.Editor edit = settings.edit(); String path = settings.getString(Folder_Chooser.location_name, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString()); //Log.d(LOG, " | " + path + " | "); TextView text1 = (TextView) findViewById(R.id.text1); final TextView text2 = (TextView) findViewById(R.id.text2); text1.setText(path); File directory = new File(path); // get all the files from a directory File[] dump_files = directory.listFiles(); Log.d(LOG, dump_files.length + " "); final File[] fList = removeElements(dump_files, "info.json"); Log.d(LOG, "Filtered Length: " + fList.length); Arrays.sort(fList, new Comparator<File>() { @Override public int compare(File file, File file2) { String one = file.toString(); String two = file2.toString(); //Log.d(LOG, "one: " + one); //Log.d(LOG, "two: " + two); int num_one = Integer.parseInt(one.substring(one.lastIndexOf("(") + 1, one.lastIndexOf(")"))); int num_two = Integer.parseInt(two.substring(two.lastIndexOf("(") + 1, two.lastIndexOf(")"))); return num_one - num_two; } }); try { writeJsonFile(fList); } catch (JSONException e) { Log.d(LOG, "JSON WRITE FAILED"); } //List names programattically LinearLayout myLinearLayout = (LinearLayout) findViewById(R.id.linear_table); final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, screen_width + 4); myLinearLayout.setOrientation(LinearLayout.VERTICAL); if (fList != null) { File cur_pic = fList[0]; BitmapFactory.Options opts = new BitmapFactory.Options(); Log.d(LOG, "\n File Location: " + cur_pic.getAbsolutePath() + " \n" + " Parent: " + cur_pic.getParent().toString() + "\n"); Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); currPic.setLayoutParams(params); currPic.setImageBitmap(myImage); currPic.setId(View.generateViewId()); text2.setText(cur_pic.getName()); } myLinearLayout.addView(currPic); //Seekbar seekBar = (SeekBar) findViewById(R.id.seekBar); seekBar.setEnabled(true); seekBar.setMax(fList.length - 1); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { int progress = 0; int length = fList.length; @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { setCounter(i); if (getCounter() <= fList.length) { File cur_pic = fList[getCounter()]; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); int image_width = opts.outWidth; int image_height = opts.outHeight; int sampleSize = image_width / screen_width; opts.inSampleSize = sampleSize; text2.setText(cur_pic.getName()); opts.inJustDecodeBounds = false; myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); currPic.setImageBitmap(myImage); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); //Make Button Layout LinearLayout buttonLayout = new LinearLayout(this); buttonLayout.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams LLParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f); buttonLayout.setLayoutParams(LLParams); buttonLayout.setId(View.generateViewId()); //Button Layout Params LinearLayout.LayoutParams param_button = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f); //Prev Pic Button prevPic = new Button(this); prevPic.setText("Previous"); prevPic.setId(View.generateViewId()); prevPic.setLayoutParams(param_button); prevPic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (fList != null) { decrementCounter(); if (getCounter() >= 0) { File cur_pic = fList[getCounter()]; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); int image_width = opts.outWidth; int image_height = opts.outHeight; int sampleSize = image_width / screen_width; opts.inSampleSize = sampleSize; text2.setText(cur_pic.getName()); opts.inJustDecodeBounds = false; myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); //Log.d(LOG, getCounter() + ""); seekBar.setProgress(getCounter()); currPic.setImageBitmap(myImage); } else { setCounter(0); } } else { Toast.makeText(Image_Gallery.this, "There are no pictures in this folder", Toast.LENGTH_SHORT); setCounter(getCounter() - 1); } } }); buttonLayout.addView(prevPic); // Next Picture Button Button nextPic = new Button(this); nextPic.setText("Next"); nextPic.setId(View.generateViewId()); nextPic.setLayoutParams(param_button); buttonLayout.addView(nextPic); nextPic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (fList != null) { incrementCounter(); if (getCounter() < fList.length) { File cur_pic = fList[getCounter()]; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); int image_width = opts.outWidth; int image_height = opts.outHeight; int sampleSize = image_width / screen_width; opts.inSampleSize = sampleSize; text2.setText(cur_pic.getName()); opts.inJustDecodeBounds = false; myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts); //Log.d(LOG, getCounter() + ""); seekBar.setProgress(getCounter()); currPic.setImageBitmap(myImage); } else { setCounter(getCounter() - 1); } } else { Toast.makeText(Image_Gallery.this, "There are no pictures in this folder", Toast.LENGTH_SHORT); setCounter(getCounter() - 1); } } }); myLinearLayout.addView(buttonLayout); }
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()]; }//from w ww . j ava 2 s . com @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(); } }