List of usage examples for android.view View getTag
@ViewDebug.ExportedProperty
public Object getTag()
From source file:cn.incongress.continuestudyeducation.adapter.CourseListAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null;/* www . jav a 2 s. co m*/ if (convertView == null) { holder = new ViewHolder(); convertView = LayoutInflater.from(mContext).inflate(R.layout.item_plate_course, null); holder.tvCourseName = (TextView) convertView.findViewById(R.id.tv_course_name); holder.ivVideoInfo = (ImageView) convertView.findViewById(R.id.iv_video_pic); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.tvCourseName.setText(mCoursesName.get(position).getCoursewareTitle()); if (!mCoursesName.get(position).getPicUrl().equals(holder.ivVideoInfo.getTag())) { holder.ivVideoInfo.setTag(mCoursesName.get(position).getPicUrl()); ImageLoader.getInstance().displayImage(mCoursesName.get(position).getPicUrl(), holder.ivVideoInfo); } return convertView; }
From source file:codingpractice.renard314.com.products.ProductGridAdapter.java
@Override public View getView(int position, View convertView, ViewGroup viewGroup) { final ProductViewHolder holder; if (convertView == null) { convertView = mLayoutInflater.inflate(R.layout.product_grid_item, viewGroup, false); holder = new ProductViewHolder(convertView); convertView.setTag(holder);//from www .j a v a 2 s . c o m } else { holder = (ProductViewHolder) convertView.getTag(); } final Product product = mProducts.get(position); startLoadImage(convertView, holder, product); //US $ or Singapore $ looks the same to me but a proper shopping app handles currencies differently. NumberFormat format = NumberFormat.getCurrencyInstance(Locale.US); holder.priceView.setText(format.format(product.pricing.price)); holder.titleView.setText(product.title); holder.mMeasureView.setText(product.measure.wt_or_vol); return convertView; }
From source file:com.android.launcher3.accessibility.WorkspaceAccessibilityHelper.java
/** * Find the virtual view id corresponding to the top left corner of any drop region by which * the passed id is contained. For an icon, this is simply *//*from w ww . j a v a 2 s. co m*/ @Override protected int intersectsValidDropTarget(int id) { int mCountX = mView.getCountX(); int mCountY = mView.getCountY(); int x = id % mCountX; int y = id / mCountX; LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo(); if (dragInfo.dragType == DragType.WIDGET && mView.isHotseat()) { return INVALID_POSITION; } if (dragInfo.dragType == DragType.WIDGET) { // For a widget, every cell must be vacant. In addition, we will return any valid // drop target by which the passed id is contained. boolean fits = false; // These represent the amount that we can back off if we hit a problem. They // get consumed as we move up and to the right, trying new regions. int spanX = dragInfo.info.spanX; int spanY = dragInfo.info.spanY; for (int m = 0; m < spanX; m++) { for (int n = 0; n < spanY; n++) { fits = true; int x0 = x - m; int y0 = y - n; if (x0 < 0 || y0 < 0) continue; for (int i = x0; i < x0 + spanX; i++) { if (!fits) break; for (int j = y0; j < y0 + spanY; j++) { if (i >= mCountX || j >= mCountY || mView.isOccupied(i, j)) { fits = false; break; } } } if (fits) { return x0 + mCountX * y0; } } } return INVALID_POSITION; } else { // For an icon, we simply check the view directly below View child = mView.getChildAt(x, y); if (child == null || child == dragInfo.item) { // Empty cell. Good for an icon or folder. return id; } else if (dragInfo.dragType != DragType.FOLDER) { // For icons, we can consider cells that have another icon or a folder. ItemInfo info = (ItemInfo) child.getTag(); if (info instanceof AppInfo || info instanceof FolderInfo || info instanceof ShortcutInfo) { return id; } } return INVALID_POSITION; } }
From source file:com.nttec.everychan.http.recaptcha.Recaptcha2fallback.java
@Override public void handle(final Activity activity, final CancellableTask task, final Callback callback) { try {//from w ww. j a v a 2 s.c om final HttpClient httpClient = ((HttpChanModule) MainApplication.getInstance().getChanModule(chanName)) .getHttpClient(); final String usingURL = scheme + RECAPTCHA_FALLBACK_URL + publicKey + (sToken != null && sToken.length() > 0 ? ("&stoken=" + sToken) : ""); String refererURL = baseUrl != null && baseUrl.length() > 0 ? baseUrl : usingURL; Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, refererURL) }; String htmlChallenge; if (lastChallenge != null && lastChallenge.getLeft().equals(usingURL)) { htmlChallenge = lastChallenge.getRight(); } else { htmlChallenge = HttpStreamer.getInstance().getStringFromUrl(usingURL, HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient, null, task, false); } lastChallenge = null; Matcher challengeMatcher = Pattern.compile("name=\"c\" value=\"([\\w-]+)").matcher(htmlChallenge); if (challengeMatcher.find()) { final String challenge = challengeMatcher.group(1); HttpResponseModel responseModel = HttpStreamer.getInstance().getFromUrl( scheme + RECAPTCHA_IMAGE_URL + challenge + "&k=" + publicKey, HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient, null, task); try { InputStream imageStream = responseModel.stream; final Bitmap challengeBitmap = BitmapFactory.decodeStream(imageStream); final String message; Matcher messageMatcher = Pattern.compile("imageselect-message(?:.*?)>(.*?)</div>") .matcher(htmlChallenge); if (messageMatcher.find()) message = RegexUtils.removeHtmlTags(messageMatcher.group(1)); else message = null; final Bitmap candidateBitmap; Matcher candidateMatcher = Pattern .compile("fbc-imageselect-candidates(?:.*?)src=\"data:image/(?:.*?);base64,([^\"]*)\"") .matcher(htmlChallenge); if (candidateMatcher.find()) { Bitmap bmp = null; try { byte[] imgData = Base64.decode(candidateMatcher.group(1), Base64.DEFAULT); bmp = BitmapFactory.decodeByteArray(imgData, 0, imgData.length); } catch (Exception e) { } candidateBitmap = bmp; } else candidateBitmap = null; activity.runOnUiThread(new Runnable() { final int maxX = 3; final int maxY = 3; final boolean[] isSelected = new boolean[maxX * maxY]; @SuppressLint("InlinedApi") @Override public void run() { LinearLayout rootLayout = new LinearLayout(activity); rootLayout.setOrientation(LinearLayout.VERTICAL); if (candidateBitmap != null) { ImageView candidateView = new ImageView(activity); candidateView.setImageBitmap(candidateBitmap); int picSize = (int) (activity.getResources().getDisplayMetrics().density * 50 + 0.5f); candidateView.setLayoutParams(new LinearLayout.LayoutParams(picSize, picSize)); candidateView.setScaleType(ImageView.ScaleType.FIT_XY); rootLayout.addView(candidateView); } if (message != null) { TextView textView = new TextView(activity); textView.setText(message); CompatibilityUtils.setTextAppearance(textView, android.R.style.TextAppearance); textView.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); rootLayout.addView(textView); } FrameLayout frame = new FrameLayout(activity); frame.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final ImageView imageView = new ImageView(activity); imageView.setLayoutParams(new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageBitmap(challengeBitmap); frame.addView(imageView); final LinearLayout selector = new LinearLayout(activity); selector.setLayoutParams(new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); AppearanceUtils.callWhenLoaded(imageView, new Runnable() { @Override public void run() { selector.setLayoutParams(new FrameLayout.LayoutParams(imageView.getWidth(), imageView.getHeight())); } }); selector.setOrientation(LinearLayout.VERTICAL); selector.setWeightSum(maxY); for (int y = 0; y < maxY; ++y) { LinearLayout subSelector = new LinearLayout(activity); subSelector.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)); subSelector.setOrientation(LinearLayout.HORIZONTAL); subSelector.setWeightSum(maxX); for (int x = 0; x < maxX; ++x) { FrameLayout switcher = new FrameLayout(activity); switcher.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); switcher.setTag(new int[] { x, y }); switcher.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int[] coord = (int[]) v.getTag(); int index = coord[1] * maxX + coord[0]; isSelected[index] = !isSelected[index]; v.setBackgroundColor(isSelected[index] ? Color.argb(128, 0, 255, 0) : Color.TRANSPARENT); } }); subSelector.addView(switcher); } selector.addView(subSelector); } frame.addView(selector); rootLayout.addView(frame); Button checkButton = new Button(activity); checkButton.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); checkButton.setText(android.R.string.ok); rootLayout.addView(checkButton); ScrollView dlgView = new ScrollView(activity); dlgView.addView(rootLayout); final Dialog dialog = new Dialog(activity); dialog.setTitle("Recaptcha"); dialog.setContentView(dlgView); dialog.setCanceledOnTouchOutside(false); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!task.isCancelled()) { callback.onError("Cancelled"); } } }); dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); dialog.show(); checkButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); if (task.isCancelled()) return; Async.runAsync(new Runnable() { @Override public void run() { try { List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("c", challenge)); for (int i = 0; i < isSelected.length; ++i) if (isSelected[i]) pairs.add(new BasicNameValuePair("response", Integer.toString(i))); HttpRequestModel request = HttpRequestModel.builder() .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")) .setCustomHeaders(new Header[] { new BasicHeader(HttpHeaders.REFERER, usingURL) }) .build(); String response = HttpStreamer.getInstance().getStringFromUrl( usingURL, request, httpClient, null, task, false); String hash = ""; Matcher matcher = Pattern.compile( "fbc-verification-token(?:.*?)<textarea[^>]*>([^<]*)<", Pattern.DOTALL).matcher(response); if (matcher.find()) hash = matcher.group(1); if (hash.length() > 0) { Recaptcha2solved.push(publicKey, hash); activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onSuccess(); } }); } else { lastChallenge = Pair.of(usingURL, response); throw new RecaptchaException( "incorrect answer (hash is empty)"); } } catch (final Exception e) { Logger.e(TAG, e); if (task.isCancelled()) return; handle(activity, task, callback); } } }); } }); } }); } finally { responseModel.release(); } } else throw new Exception("can't parse recaptcha challenge answer"); } catch (final Exception e) { Logger.e(TAG, e); if (!task.isCancelled()) { activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onError(e.getMessage() != null ? e.getMessage() : e.toString()); } }); } } }
From source file:com.frostwire.android.gui.adapters.TransferListAdapter.java
private MenuAdapter getMenuAdapter(View view) { Object tag = view.getTag(); String title = ""; List<MenuAction> items = new ArrayList<>(); if (tag instanceof BittorrentDownload) { title = populateBittorrentDownloadMenuActions((BittorrentDownload) tag, items); } else if (tag instanceof Transfer) { title = populateCloudDownloadMenuActions(tag, items); }//from w w w . j a v a2 s. c o m return items.size() > 0 ? new MenuAdapter(contextRef.get(), title, items) : null; }
From source file:net.openwatch.acluaz.fragment.FormFragment.java
public void clearForm(ViewGroup container) { View view; for (int x = 0; x < container.getChildCount(); x++) { view = container.getChildAt(x);// ww w . j a v a2 s.co m if (EditText.class.isInstance(view)) { if (view.getTag() != null) { ((EditText) view).setText(""); } } } }
From source file:com.android.inputmethod.keyboard.emoji.EmojiPalettesView.java
/** * Called from {@link EmojiPageKeyboardView} through {@link android.view.View.OnTouchListener} * interface to handle touch events from View-based elements such as the space bar. * Note that this method is used only for observing {@link MotionEvent#ACTION_DOWN} to trigger * {@link KeyboardActionListener#onPressKey}. {@link KeyboardActionListener#onReleaseKey} will * be covered by {@link #onClick} as long as the event is not canceled. *//*from w w w . ja va 2 s .com*/ @Override public boolean onTouch(final View v, final MotionEvent event) { if (event.getActionMasked() != MotionEvent.ACTION_DOWN) { return false; } final Object tag = v.getTag(); if (!(tag instanceof Integer)) { return false; } final int code = (Integer) tag; mKeyboardActionListener.onPressKey(code, 0 /* repeatCount */, true /* isSinglePointer */); // It's important to return false here. Otherwise, {@link #onClick} and touch-down visual // feedback stop working. return false; }
From source file:com.blueverdi.rosietheriveter.MoreFragment.java
public void onClick(View v) { switch (v.getId()) { case R.id.infoButton: Intent i = new Intent(getActivity(), SiteActivity.class); i.putExtra(Site.PARCEL_NAME, (Site) v.getTag()); startActivity(i);//w ww.j ava 2 s . com getActivity().overridePendingTransition(R.anim.zoom_in, 0); break; case R.id.tourButton: Site s = (Site) v.getTag(); if (myTour.getSiteByName(s.getString(Site.NAME)) == null) { myTour.addSite(s); } Toast.makeText(getActivity(), getString(R.string.added_to_tour), Toast.LENGTH_SHORT).show(); } }
From source file:com.akop.bach.fragment.playstation.TrophiesFragment.java
@Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { ViewHolder vh = (ViewHolder) arg1.getTag(); showTrophyDetails(vh.title.getText(), vh.description.getText()); }
From source file:gov.in.bloomington.georeporter.adapters.ServersAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder;/* ww w . j av a2 s .c o m*/ if (convertView == null) { convertView = mInflater.inflate(R.layout.list_item_servers, null); holder = new ViewHolder(); holder.name = (TextView) convertView.findViewById(android.R.id.text1); holder.url = (TextView) convertView.findViewById(android.R.id.text2); holder.radio = (RadioButton) convertView.findViewById(R.id.radio); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } String name = mServers.optJSONObject(position).optString("name"); String url = mServers.optJSONObject(position).optString("url"); if (name.equals(mCurrentServerName)) { holder.radio.setChecked(true); } else { holder.radio.setChecked(false); } holder.name.setText(name); holder.url.setText(url); return convertView; }