List of usage examples for android.widget Gallery setSelection
@Override public void setSelection(int position)
From source file:net.evendanan.android.hagarfingerpainting.HagarFingerpaintingActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_NEW_PAPER: final Dialog newPaper = new Dialog(this); newPaper.setTitle(R.string.new_paper_dialog_title); newPaper.setContentView(R.layout.new_paper_dialog); newPaper.setCancelable(true);/*from ww w . j a va2 s . com*/ final EditText painterName = (EditText) newPaper.findViewById(R.id.painter_name_input_text); Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/schoolbell.ttf"); painterName.setTypeface(tf); final Gallery colors = (Gallery) newPaper.findViewById(R.id.colors_list); colors.setAdapter(new PaperColorListAdapter(getApplicationContext())); colors.setOnItemSelectedListener(new OnItemSelectedListener() { private View mSelectedItem = null; @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { if (mSelectedItem != null) mSelectedItem.setBackgroundDrawable(null); mSelectedItem = v; if (mSelectedItem != null) mSelectedItem.setBackgroundResource(R.drawable.selected_color_background); } @Override public void onNothingSelected(AdapterView<?> arg0) { if (mSelectedItem != null) mSelectedItem.setBackgroundDrawable(null); } }); colors.setSelection(2); View createButton = newPaper.findViewById(R.id.new_paper_create_button); createButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Editor e = sp.edit(); final CharSequence painterNameFromUI = painterName.getText().toString(); final String newPainterName = TextUtils.isEmpty(painterNameFromUI) ? getString(R.string.settings_key_painter_name_default_value) : painterNameFromUI.toString(); e.putString(getString(R.string.settings_key_painter_name), newPainterName); e.commit(); PaperBackground paper = (PaperBackground) colors.getSelectedItem(); newPaper.dismiss(); createNewPaper(paper); } }); View cancelButton = newPaper.findViewById(R.id.new_paper_cancel_button); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { newPaper.dismiss(); if (!mPaperCreated) HagarFingerpaintingActivity.this.finish(); } }); newPaper.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!mPaperCreated) HagarFingerpaintingActivity.this.finish(); } }); return newPaper; default: return super.onCreateDialog(id); } }
From source file:org.planetmono.dcuploader.ActivityUploader.java
private void initViews() { WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); if (wm.getDefaultDisplay().getOrientation() == 0) setContentView(R.layout.upload_portrait); else/* w ww . java 2 s .c om*/ setContentView(R.layout.upload_landscape); EditText uploadTarget = (EditText) findViewById(R.id.upload_target); EditText uploadTitle = (EditText) findViewById(R.id.upload_title); EditText uploadText = (EditText) findViewById(R.id.upload_text); Button uploadVisit = (Button) findViewById(R.id.upload_visit); Button uploadPhotoTake = (Button) findViewById(R.id.upload_photo_take); Button uploadPhotoAdd = (Button) findViewById(R.id.upload_photo_add); Button uploadPhotoDelete = (Button) findViewById(R.id.upload_photo_delete); CheckBox uploadEnclosePosition = (CheckBox) findViewById(R.id.upload_enclose_position); Button uploadOk = (Button) findViewById(R.id.upload_ok); Button uploadCancel = (Button) findViewById(R.id.upload_cancel); /* set button behavior */ if (passThrough) uploadTarget.setClickable(false); else { uploadTarget.setClickable(true); registerForContextMenu(uploadTarget); } uploadTarget.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (!passThrough) openContextMenu(v); } }); registerForContextMenu(uploadVisit); uploadVisit.setOnClickListener(new OnClickListener() { public void onClick(View v) { openContextMenu(v); } }); uploadPhotoTake.setOnClickListener(new OnClickListener() { public void onClick(View v) { try { tempFile = File.createTempFile("dcuploader_photo_", ".jpg"); } catch (IOException e) { Toast.makeText(ActivityUploader.this, " ?? .", Toast.LENGTH_SHORT).show(); tempFile = null; return; } Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (tempFile != null) i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); startActivityForResult(i, Application.ACTION_TAKE_PHOTO); } }); uploadPhotoAdd.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("image/*"); i.addCategory(Intent.CATEGORY_DEFAULT); startActivityForResult(i, Application.ACTION_ADD_PHOTO); } }); uploadPhotoDelete.setOnClickListener(new OnClickListener() { public void onClick(View v) { Gallery g = (Gallery) findViewById(R.id.upload_images); int pos = g.getSelectedItemPosition(); if (pos == -1) return; contents.remove(pos); bitmaps.remove(pos); updateGallery(); updateImageButtons(); if (contents.size() == 0) pos = -1; else if (pos >= contents.size()) --pos; g.setSelection(pos); } }); uploadOk.setOnClickListener(proceedHandler); uploadCancel.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); uploadEnclosePosition.setChecked(formLocation); uploadEnclosePosition.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { locationEnabled = isChecked; queryLocation(isChecked); } }); /* restore data when orientation changes */ if (formGallery != null) { if (target != null) { uploadTarget.setText(formGallery); formGallery = null; } } if (formTitle != null) { uploadTitle.setText(formTitle); formTitle = null; } if (formBody != null) { uploadText.setText(formBody); formBody = null; } updateImageButtons(); updateGallery(); }
From source file:org.planetmono.dcuploader.ActivityUploader.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { if (requestCode == Application.ACTION_ADD_PHOTO || requestCode == Application.ACTION_TAKE_PHOTO) { /* add photo */ if (contents.size() == 5) return; Uri selectedImage;/* w ww. j a v a2s . c o m*/ Bitmap tbm; if (requestCode == Application.ACTION_ADD_PHOTO) { selectedImage = data.getData(); tbm = getBitmapThumbnail(selectedImage); } /*else if (requestCode == Application.ACTION_TAKE_PHOTO && data != null && data.hasExtra("data")) { Bundle b = data.getExtras(); String mpath = null; Bitmap bitmap = (Bitmap) b.get("data"); try { if (tempFile == null) { File f = File.createTempFile("dcuploader_photo_", ".jpg", Environment .getDownloadCacheDirectory()); FileOutputStream fo = new FileOutputStream(f); mpath = f.getAbsolutePath(); bitmap.compress(CompressFormat.JPEG, 90, fo); fo.close(); } else { mpath = tempFile.getAbsolutePath(); tempFile = null; } } catch (IOException e) { e.printStackTrace(); return; } selectedImage = Uri.parse("file://" + mpath); tempFiles.add(mpath); tbm = getBitmapThumbnail(bitmap); bitmap.recycle(); } */else { /* take photo */ selectedImage = Uri.fromFile(tempFile); tempFiles.add(tempFile.getAbsolutePath()); tbm = getBitmapThumbnail(selectedImage); } Gallery g = (Gallery) findViewById(R.id.upload_images); int npos = 0; int pos = g.getSelectedItemPosition(); if (pos == -1 || pos == 3) { contents.add(selectedImage); bitmaps.add(tbm); if (pos == 3) npos = pos + 1; } else { contents.add(pos + 1, selectedImage); bitmaps.add(pos + 1, tbm); npos = pos + 1; } updateGallery(); updateImageButtons(); g.setSelection(npos); galleryChanged = true; } else if (requestCode == Application.ACTION_ADD_GALLERY) { /* add gallery */ DatabaseHelper db = new DatabaseHelper(ActivityUploader.this); db.setFavorites(data.getStringArrayExtra("result")); db.close(); openContextMenu(findViewById(R.id.upload_target)); } else if (requestCode == Application.ACTION_SIGN_ON) { /* when signed on, go on. */ publish(); } else if (requestCode == Application.ACTION_PREFERENCES) { /* apply preferences */ Log.d(Application.TAG, "reloading configuration..."); reloadConfigurations(); setDefaultImage(); queryLocation(formLocation); } } }