List of usage examples for android.widget TextView setEnabled
@android.view.RemotableViewMethod @Override public void setEnabled(boolean enabled)
From source file:org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { TextView vKeyId = (TextView) view.findViewById(R.id.subkey_item_key_id); TextView vKeyDetails = (TextView) view.findViewById(R.id.subkey_item_details); TextView vKeyExpiry = (TextView) view.findViewById(R.id.subkey_item_expiry); ImageView vCertifyIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_certify); ImageView vSignIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_sign); ImageView vEncryptIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_encrypt); ImageView vAuthenticateIcon = (ImageView) view.findViewById(R.id.subkey_item_ic_authenticate); ImageView vEditImage = (ImageView) view.findViewById(R.id.subkey_item_edit_image); ImageView vStatus = (ImageView) view.findViewById(R.id.subkey_item_status); // not used:/*from w w w .j av a 2 s. c om*/ ImageView deleteImage = (ImageView) view.findViewById(R.id.subkey_item_delete_button); deleteImage.setVisibility(View.GONE); long keyId = cursor.getLong(INDEX_KEY_ID); vKeyId.setText(KeyFormattingUtils.beautifyKeyId(keyId)); // may be set with additional "stripped" later on SpannableStringBuilder algorithmStr = new SpannableStringBuilder(); algorithmStr.append(KeyFormattingUtils.getAlgorithmInfo(context, cursor.getInt(INDEX_ALGORITHM), cursor.getInt(INDEX_KEY_SIZE), cursor.getString(INDEX_KEY_CURVE_OID))); SubkeyChange change = mSaveKeyringParcel != null ? mSaveKeyringParcel.getSubkeyChange(keyId) : null; if (change != null && (change.mDummyStrip || change.mMoveKeyToSecurityToken)) { if (change.mDummyStrip) { algorithmStr.append(", "); final SpannableString boldStripped = new SpannableString(context.getString(R.string.key_stripped)); boldStripped.setSpan(new StyleSpan(Typeface.BOLD), 0, boldStripped.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); algorithmStr.append(boldStripped); } if (change.mMoveKeyToSecurityToken) { algorithmStr.append(", "); final SpannableString boldDivert = new SpannableString(context.getString(R.string.key_divert)); boldDivert.setSpan(new StyleSpan(Typeface.BOLD), 0, boldDivert.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); algorithmStr.append(boldDivert); } } else { switch (SecretKeyType.fromNum(cursor.getInt(INDEX_HAS_SECRET))) { case GNU_DUMMY: algorithmStr.append(", "); algorithmStr.append(context.getString(R.string.key_stripped)); break; case DIVERT_TO_CARD: algorithmStr.append(", "); algorithmStr.append(context.getString(R.string.key_divert)); break; case PASSPHRASE_EMPTY: algorithmStr.append(", "); algorithmStr.append(context.getString(R.string.key_no_passphrase)); break; case UNAVAILABLE: // don't show this on pub keys //algorithmStr += ", " + context.getString(R.string.key_unavailable); break; } } vKeyDetails.setText(algorithmStr, TextView.BufferType.SPANNABLE); boolean isMasterKey = cursor.getInt(INDEX_RANK) == 0; if (isMasterKey) { vKeyId.setTypeface(null, Typeface.BOLD); } else { vKeyId.setTypeface(null, Typeface.NORMAL); } // Set icons according to properties vCertifyIcon.setVisibility(cursor.getInt(INDEX_CAN_CERTIFY) != 0 ? View.VISIBLE : View.GONE); vEncryptIcon.setVisibility(cursor.getInt(INDEX_CAN_ENCRYPT) != 0 ? View.VISIBLE : View.GONE); vSignIcon.setVisibility(cursor.getInt(INDEX_CAN_SIGN) != 0 ? View.VISIBLE : View.GONE); vAuthenticateIcon.setVisibility(cursor.getInt(INDEX_CAN_AUTHENTICATE) != 0 ? View.VISIBLE : View.GONE); boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0; Date expiryDate = null; if (!cursor.isNull(INDEX_EXPIRY)) { expiryDate = new Date(cursor.getLong(INDEX_EXPIRY) * 1000); } // for edit key if (mSaveKeyringParcel != null) { boolean revokeThisSubkey = (mSaveKeyringParcel.mRevokeSubKeys.contains(keyId)); if (revokeThisSubkey) { if (!isRevoked) { isRevoked = true; } } SaveKeyringParcel.SubkeyChange subkeyChange = mSaveKeyringParcel.getSubkeyChange(keyId); if (subkeyChange != null) { if (subkeyChange.mExpiry == null || subkeyChange.mExpiry == 0L) { expiryDate = null; } else { expiryDate = new Date(subkeyChange.mExpiry * 1000); } } vEditImage.setVisibility(View.VISIBLE); } else { vEditImage.setVisibility(View.GONE); } boolean isExpired; if (expiryDate != null) { isExpired = expiryDate.before(new Date()); Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiryCal.setTime(expiryDate); // convert from UTC to time zone of device expiryCal.setTimeZone(TimeZone.getDefault()); vKeyExpiry.setText(context.getString(R.string.label_expiry) + ": " + DateFormat.getDateFormat(context).format(expiryCal.getTime())); } else { isExpired = false; vKeyExpiry.setText(context.getString(R.string.label_expiry) + ": " + context.getString(R.string.none)); } // if key is expired or revoked... boolean isInvalid = isRevoked || isExpired; if (isInvalid) { vStatus.setVisibility(View.VISIBLE); vCertifyIcon.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); vSignIcon.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); vEncryptIcon.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); vAuthenticateIcon.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); if (isRevoked) { vStatus.setImageResource(R.drawable.status_signature_revoked_cutout_24dp); vStatus.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); } else if (isExpired) { vStatus.setImageResource(R.drawable.status_signature_expired_cutout_24dp); vStatus.setColorFilter(mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); } } else { vStatus.setVisibility(View.GONE); vKeyId.setTextColor(mDefaultTextColor); vKeyDetails.setTextColor(mDefaultTextColor); vKeyExpiry.setTextColor(mDefaultTextColor); vCertifyIcon.clearColorFilter(); vSignIcon.clearColorFilter(); vEncryptIcon.clearColorFilter(); vAuthenticateIcon.clearColorFilter(); } vKeyId.setEnabled(!isInvalid); vKeyDetails.setEnabled(!isInvalid); vKeyExpiry.setEnabled(!isInvalid); }
From source file:com.roselism.bottomsheet.BottomSheet.java
private void init(final Context context) { setCanceledOnTouchOutside(cancelOnTouchOutside); final ClosableSlidingLayout mDialogView = (ClosableSlidingLayout) View.inflate(context, R.layout.bottom_sheet_dialog, null); LinearLayout mainLayout = (LinearLayout) mDialogView.findViewById(R.id.bs_main); mainLayout.addView(View.inflate(context, mHeaderLayoutId, null), 0); setContentView(mDialogView);/* w ww.j a va2 s . c o m*/ if (!cancelOnSwipeDown) { mDialogView.swipeable = cancelOnSwipeDown; } mDialogView.setSlideListener(new ClosableSlidingLayout.SlideListener() { @Override public void onClosed() { BottomSheet.this.dismiss(); } @Override public void onOpened() { showFullItems(); } }); super.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { if (showListener != null) { showListener.onShow(dialogInterface); } list.setAdapter(adapter); list.startLayoutAnimation(); if (builder.icon == null) { icon.setVisibility(View.GONE); } else { icon.setVisibility(View.VISIBLE); icon.setImageDrawable(builder.icon); } } }); int[] location = new int[2]; mDialogView.getLocationOnScreen(location); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mDialogView.setPadding(0, location[0] == 0 ? helper.mStatusBarHeight : 0, 0, 0); mDialogView.getChildAt(0).setPadding(0, 0, 0, helper.mNavBarAvailable ? helper.getNavigationBarHeight(getContext()) + mDialogView.getPaddingBottom() : 0); } final TextView title = (TextView) mDialogView.findViewById(R.id.bottom_sheet_title); if (builder.title != null) { title.setVisibility(View.VISIBLE); title.setText(builder.title); // title.setGravity(mHasContent ? Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL // : Gravity.LEFT); // ??? } icon = (ImageView) mDialogView.findViewById(R.id.bottom_sheet_title_image); list = (GridView) mDialogView.findViewById(R.id.bottom_sheet_gridview); mDialogView.mTarget = list; if (!builder.grid) { list.setNumColumns(1); } if (builder.grid) { for (int i = 0; i < getMenu().size(); i++) { if (getMenu().getItem(i).getIcon() == null) { throw new IllegalArgumentException("You must set icon for each items in grid style"); } } } if (builder.limit > 0) { limit = builder.limit * getNumColumns(); } else { limit = Integer.MAX_VALUE; } mDialogView.setCollapsible(false); actions = builder.menu; menuItem = actions; // over the initial numbers if (getMenu().size() > limit) { fullMenuItem = builder.menu; menuItem = builder.menu.clone(limit - 1); ActionMenuItem item = new ActionMenuItem(context, 0, R.id.bs_more, 0, limit - 1, moreText); item.setIcon(more); menuItem.add(item); actions = menuItem; mDialogView.setCollapsible(true); } BaseAdapter baseAdapter = new BaseAdapter() { @Override public int getCount() { return actions.size() - hidden.size(); } @Override public MenuItem getItem(int position) { return actions.getItem(position); } @Override public int getItemViewType(int position) { MenuItem item = getItem(position); String json = item.getTitle().toString(); int type = parseItemType(json) == null ? -1 : parseItemType(json); switch (type) { case ONE: return ONE; case TWO: return TWO; case NORMAL: return NORMAL; default: return NORMAL; } } @Override public long getItemId(int position) { return position; } @Override public int getViewTypeCount() { return 3; } @Override public boolean isEnabled(int position) { return getItem(position).isEnabled(); } @Override public boolean areAllItemsEnabled() { return false; } @Override public View getView(int position, View convertView, ViewGroup parent) { int type = getItemViewType(position); if (type == ONE) { OneItemViewHolder holder; if (convertView == null) { convertView = View.inflate(context, builder.grid ? mGridItemLayoutId : R.layout.bs_list_entry_hor_one, null); holder = new OneItemViewHolder(convertView); convertView.setTag(holder); } else { holder = (OneItemViewHolder) convertView.getTag(); } for (int i = 0; i < hidden.size(); i++) { if (hidden.valueAt(i) <= position) { position++; } } holder.bindData2View(position); } else if (type == TWO) { TwoItemViewHolder holder; if (convertView == null) { convertView = View.inflate(context, builder.grid ? mGridItemLayoutId : R.layout.bs_list_entry_hor_two, null); holder = new TwoItemViewHolder(convertView); convertView.setTag(holder); } else { holder = (TwoItemViewHolder) convertView.getTag(); } for (int i = 0; i < hidden.size(); i++) { if (hidden.valueAt(i) <= position) { position++; } } holder.bindData2View(position); } else if (type == NORMAL) { NormalItemViewHolder holder; if (convertView == null) { convertView = View.inflate(context, builder.grid ? mGridItemLayoutId : R.layout.bs_list_entry_normal, null); holder = new NormalItemViewHolder(convertView); convertView.setTag(holder); } else { holder = (NormalItemViewHolder) convertView.getTag(); } for (int i = 0; i < hidden.size(); i++) { if (hidden.valueAt(i) <= position) { position++; } } holder.bindData2View(position); } return convertView; } @Nullable private String parseItemTitle(String json) { try { JSONObject jsonObject = new JSONObject(json); String jsonTitle = jsonObject.getString("title"); return jsonTitle; } catch (JSONException e) { e.printStackTrace(); return null; } } private String parseItemContent(String json) { try { JSONObject jsonObject = new JSONObject(json); String content = jsonObject.getString("mContent"); return content; } catch (JSONException e) { e.printStackTrace(); return ""; } } @Nullable private Integer parseItemType(String json) { try { JSONObject jsonObject = new JSONObject(json); Integer type = jsonObject.getInt("type"); return type; } catch (JSONException e) { e.printStackTrace(); return null; } } class TwoItemViewHolder { private TextView divider; private TextView title; private TextView mContent; private ImageView image; public TwoItemViewHolder(View convertView) { title = (TextView) convertView.findViewById(R.id.bs_list_title); image = (ImageView) convertView.findViewById(R.id.bs_list_image); mContent = (TextView) convertView.findViewById(R.id.bs_list_content); divider = (TextView) convertView.findViewById(R.id.bs_list_divider); } private void bindData2View(int position) { MenuItem item = getItem(position); String json = item.getTitle().toString(); // title.setText(json); if (item.getIcon() == null) { image.setVisibility(collapseListIcons ? View.GONE : View.INVISIBLE); } else { image.setVisibility(View.VISIBLE); image.setImageDrawable(item.getIcon()); } boolean showDivider = getCount() > 1 && position != getCount() - 1; divider.setVisibility(showDivider ? View.VISIBLE : View.GONE); String itemTitle = parseItemTitle(json); String contentText = parseItemContent(json); title.setText(parseItemTitle(json)); if (contentText != null && !contentText.trim().isEmpty()) { mContent.setText(contentText); mContent.setVisibility(View.VISIBLE); mContent.setEnabled(true); } else { mContent.setVisibility(View.INVISIBLE); } image.setEnabled(item.isEnabled()); title.setEnabled(item.isEnabled()); } } class NormalItemViewHolder { private TextView title; private ImageView image; public NormalItemViewHolder(View convertView) { title = (TextView) convertView.findViewById(R.id.bs_list_title); image = (ImageView) convertView.findViewById(R.id.bs_list_image); } private void bindData2View(int position) { MenuItem item = getItem(position); String json = item.getTitle().toString(); String titleText = parseItemTitle(json) == null ? json : parseItemTitle(json); title.setText(titleText); if (item.getIcon() == null) { image.setVisibility(collapseListIcons ? View.GONE : View.INVISIBLE); } else { image.setVisibility(View.VISIBLE); image.setImageDrawable(item.getIcon()); } image.setEnabled(item.isEnabled()); title.setEnabled(item.isEnabled()); } } // class MenuItemViewHolder { // // private TextView title; // private ImageView image; // // public MenuItemViewHolder(View convertView) { // title = (TextView) convertView.findViewById(R.id.bs_list_title); // image = (ImageView) convertView.findViewById(R.id.bs_list_image); // } // // private void bindData2View(int position) { // MenuItem item = getItem(position); // String titleText = item.getTitle().toString(); //// String titleText = parseItemTitle(json); // // title.setText(titleText); // if (item.getIcon() == null) { // image.setVisibility(collapseListIcons ? View.GONE : View.INVISIBLE); // } else { // image.setVisibility(View.VISIBLE); // image.setImageDrawable(item.getIcon()); // } // // image.setEnabled(item.isEnabled()); // title.setEnabled(item.isEnabled()); // } // } class OneItemViewHolder { private TextView divider; private TextView title; private ImageView image; public OneItemViewHolder(View convertView) { title = (TextView) convertView.findViewById(R.id.bs_list_title); image = (ImageView) convertView.findViewById(R.id.bs_list_image); divider = (TextView) convertView.findViewById(R.id.bs_list_divider); } private void bindData2View(int position) { MenuItem item = getItem(position); String json = item.getTitle().toString(); title.setText(json); if (item.getIcon() == null) { image.setVisibility(collapseListIcons ? View.GONE : View.INVISIBLE); } else { image.setVisibility(View.VISIBLE); image.setImageDrawable(item.getIcon()); } boolean showDivider = getCount() > 1 && position != getCount() - 1; divider.setVisibility(showDivider ? View.VISIBLE : View.GONE); String itemTitle = parseItemTitle(json); String content = parseItemContent(json); title.setText(parseItemTitle(json)); image.setEnabled(item.isEnabled()); title.setEnabled(item.isEnabled()); } } }; adapter = new SimpleSectionedGridAdapter(context, baseAdapter, R.layout.bs_list_divider, R.id.headerlayout, R.id.header); list.setAdapter(adapter); adapter.setGridView(list); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (((MenuItem) adapter.getItem(position)).getItemId() == R.id.bs_more) { showFullItems(); mDialogView.setCollapsible(false); return; } if (!((ActionMenuItem) adapter.getItem(position)).invoke()) { if (builder.menu.getClickListener() != null) { builder.menu.getClickListener().get(position).onClick(view); } else { if (builder.menulistener != null) { builder.menulistener.onMenuItemClick((MenuItem) adapter.getItem(position)); } else if (builder.listener != null) { builder.listener.onClick(BottomSheet.this, ((MenuItem) adapter.getItem(position)).getItemId()); } } } dismiss(); } }); if (builder.dismissListener != null) { setOnDismissListener(builder.dismissListener); } setListLayout(); }