List of usage examples for android.widget TableRow getContext
@ViewDebug.CapturedViewProperty public final Context getContext()
From source file:de.uulm.graphicalpasswords.openuyi.UYICreatePasswordActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_uyi_create_password); // Show the Up button in the action bar. setupActionBar();/* w ww . j av a2s .c o m*/ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); length = Integer.parseInt(sharedPref.getString("uyi_length", "10")); originalViews = new ImageView[length]; distortedViews = new ImageView[length]; selectedPictures = new Picture[length]; Bundle bundle = new Bundle(); bundle.putInt("length", length); DialogFragment intro = new IntroDialogFragment(); intro.setArguments(bundle); intro.show(getFragmentManager(), "intro"); vibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE); Arrays.fill(selectedPictures, null); gallery = (Gallery) findViewById(R.id.uyi_gallery_originals); gallery.setAdapter(new UYIImageAdapter(this)); gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { ImageView viewOriginal = new ImageView(UYICreatePasswordActivity.this); ImageView viewDistorted = new ImageView(UYICreatePasswordActivity.this); int i = 0; for (; i < selectedPictures.length; i++) { if (i == selectedPictures.length - 1 && selectedPictures[i] != null) { removePicture(i); } if (selectedPictures[i] == null || i == selectedPictures.length - 1) { viewOriginal = originalViews[i]; viewDistorted = distortedViews[i]; selectedPictures[i] = ((UYIImageAdapter) parent.getAdapter()).getPicture(position); vibrator.vibrate(100); ScrollView sv = (ScrollView) findViewById(R.id.uyi_choosepi_scrollview); int height = originalViews[0].getMeasuredHeight(); sv.scrollTo(0, (i * height) - 200); break; } } int originalImageResource = ((UYIImageAdapter) parent.getAdapter()).getImageResource(position); viewOriginal.setImageResource(originalImageResource); viewDistorted.setImageResource( ((UYIImageAdapter) parent.getAdapter()).getDistortedImageResource(position)); ((UYIImageAdapter) parent.getAdapter()).removePicture(position); OnLongClickListener listener = new OnLongClickListener() { @Override public boolean onLongClick(View v) { vibrator.vibrate(200); int viewid = v.getId(); int index = -1; for (int i = 0; i < originalViews.length; i++) { if (originalViews[i].getId() == viewid) { index = i; break; } else if (distortedViews[i].getId() == viewid) { index = i; break; } } Bundle bundle = new Bundle(); bundle.putInt("index", index); DialogFragment dialog = new DeleteImageDialogFragment(); dialog.setArguments(bundle); dialog.show(getFragmentManager(), "delete"); return false; } }; viewOriginal.setOnLongClickListener(listener); viewDistorted.setOnLongClickListener(listener); // Check int count = 0; for (int j = 0; j < selectedPictures.length; j++) { if (selectedPictures[j] != null) { count++; } } if (count == selectedPictures.length) { findViewById(R.id.uyi_save).setClickable(true); findViewById(R.id.uyi_save).setEnabled(true); } } }); table = (TableLayout) findViewById(R.id.uyi_choosepi_tablelayout); LayoutParams params = new LayoutParams(android.widget.TableRow.LayoutParams.WRAP_CONTENT, android.widget.TableRow.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER; for (int i = 0; i < length; i++) { TableRow row = new TableRow(table.getContext()); originalViews[i] = new ImageView(row.getContext()); originalViews[i].setAdjustViewBounds(true); originalViews[i].setScaleType(ScaleType.FIT_XY); originalViews[i].setPadding(3, 3, 3, 3); originalViews[i].setImageResource(R.drawable.oempty); originalViews[i].setId(100 + i); distortedViews[i] = new ImageView(row.getContext()); distortedViews[i].setAdjustViewBounds(true); distortedViews[i].setScaleType(ScaleType.FIT_XY); distortedViews[i].setPadding(3, 3, 3, 3); distortedViews[i].setImageResource(R.drawable.wempty); distortedViews[i].setId(1000 + i); ImageView arrow = new ImageView(row.getContext()); arrow.setAdjustViewBounds(true); arrow.setScaleType(ScaleType.FIT_XY); arrow.setMaxWidth(80); arrow.setPadding(3, 3, 3, 3); arrow.setImageResource(R.drawable.arrow_active); arrow.setLayoutParams(params); row.addView(originalViews[i]); row.addView(arrow); row.addView(distortedViews[i]); table.addView(row); } }