Java Code Examples for android.widget.TextView#setFocusableInTouchMode()

The following examples show how to use android.widget.TextView#setFocusableInTouchMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridItemPresenter.java    From androidtv-Leanback with Apache License 2.0 6 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.grid_item_width);
    int height = res.getDimensionPixelSize(R.dimen.grid_item_height);

    view.setLayoutParams(new ViewGroup.LayoutParams(width, height));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(parent.getContext(),
            R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 2
Source File: GridItemPresenter.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.grid_item_width);
    int height = res.getDimensionPixelSize(R.dimen.grid_item_height);

    view.setLayoutParams(new ViewGroup.LayoutParams(width, height));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(parent.getContext(),
            R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 3
Source File: AxisMappingDialogPreference.java    From crazyflie-android-client with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected View onCreateDialogView() {
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    LinearLayout layout = new LinearLayout(getContext());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setPadding(6,6,6,6);

    TextView promptTextView = new TextView(getContext());
    promptTextView.setText(R.string.preferences_axis_mapping_dialog_text);
    promptTextView.setGravity(Gravity.CENTER_HORIZONTAL);

    mValueTextView = new TextView(getContext());
    mValueTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
    mValueTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    mValueTextView.setPadding(0, 12, 0, 12);


    mValueTextView.setOnGenericMotionListener(this);
    //TODO: is there an easier way to make this work?
    //motion events are not captured when view is not focusable
    mValueTextView.setFocusableInTouchMode(true);
    //if focus is not set, right analog stick events are only recognized after the left analog stick is moved!?!
    mValueTextView.requestFocus();

    layout.addView(promptTextView, params);
    layout.addView(mValueTextView, params);

    return layout;
}
 
Example 4
Source File: FloatingToolbar.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private View createMenuItemButton(Context context, MenuItem menuItem, int iconTextSpacing) {
    LinearLayout menuItemButton = new LinearLayout(context);
    menuItemButton.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    menuItemButton.setOrientation(LinearLayout.HORIZONTAL);
    menuItemButton.setMinimumWidth(AndroidUtilities.dp(48));
    menuItemButton.setMinimumHeight(AndroidUtilities.dp(48));
    menuItemButton.setPaddingRelative(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    textView.setFocusable(false);
    textView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    textView.setFocusableInTouchMode(false);
    if (currentStyle == STYLE_DIALOG) {
        textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    } else if (currentStyle == STYLE_BLACK) {
        textView.setTextColor(0xfffafafa);
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(0x40ffffff, false));
    } else if (currentStyle == STYLE_THEME) {
        textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    }
    textView.setPaddingRelative(AndroidUtilities.dp(11), 0, 0, 0);
    menuItemButton.addView(textView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, AndroidUtilities.dp(48)));
    if (menuItem != null) {
        updateMenuItemButton(menuItemButton, menuItem, iconTextSpacing);
    }
    return menuItemButton;
}
 
Example 5
Source File: TVDemoFragment.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(200, 200));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(getResources().getColor(R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 6
Source File: TVDemoFragment.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(200, 200));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(getResources().getColor(R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 7
Source File: TVDemoFragment.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(200, 200));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(getResources().getColor(R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 8
Source File: UI.java    From Android-Commons with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the given `TextView` to be read-only or read-and-write
 *
 * @param view a `TextView` or one of its subclasses
 * @param readOnly whether the view should be read-only or not
 */
public static void setReadOnly(final TextView view, final boolean readOnly) {
	view.setFocusable(!readOnly);
	view.setFocusableInTouchMode(!readOnly);
	view.setClickable(!readOnly);
	view.setLongClickable(!readOnly);
	view.setCursorVisible(!readOnly);
}
 
Example 9
Source File: PreferenceCardPresenter.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(
            parent.getResources().getInteger( R.integer.preference_square_size ),
            parent.getResources().getInteger( R.integer.preference_square_size ) ) );
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor( parent.getContext().getResources().getColor(R.color.default_background) );
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 10
Source File: GridItemPresenter.java    From Amphitheatre with Apache License 2.0 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(240, 240));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(mContext.getResources().getColor(R.color.primary));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 11
Source File: FloatingToolbar.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private View createMenuItemButton(Context context, MenuItem menuItem, int iconTextSpacing) {
    LinearLayout menuItemButton = new LinearLayout(context);
    menuItemButton.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    menuItemButton.setOrientation(LinearLayout.HORIZONTAL);
    menuItemButton.setMinimumWidth(AndroidUtilities.dp(48));
    menuItemButton.setMinimumHeight(AndroidUtilities.dp(48));
    menuItemButton.setPaddingRelative(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    textView.setFocusable(false);
    textView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    textView.setFocusableInTouchMode(false);
    if (currentStyle == STYLE_DIALOG) {
        textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    } else if (currentStyle == STYLE_BLACK) {
        textView.setTextColor(0xfffafafa);
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(0x40ffffff, false));
    } else if (currentStyle == STYLE_THEME) {
        textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        menuItemButton.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    }
    textView.setPaddingRelative(AndroidUtilities.dp(11), 0, 0, 0);
    menuItemButton.addView(textView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, AndroidUtilities.dp(48)));
    if (menuItem != null) {
        updateMenuItemButton(menuItemButton, menuItem, iconTextSpacing);
    }
    return menuItemButton;
}
 
Example 12
Source File: SimpleClockDreamSettingsFragment.java    From androidtv-daydream with Apache License 2.0 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(getResources().getColor(R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 13
Source File: StringPresenter.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView textView = new TextView(parent.getContext());
    textView.setFocusable(true);
    textView.setFocusableInTouchMode(true);
    textView.setBackground(
            parent.getContext().getResources().getDrawable(R.drawable.background_cone));
    return new ViewHolder(textView);
}
 
Example 14
Source File: InputExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 5 votes vote down vote up
private void addEditableStyling(TextView editText) {
    editText.setTypeface(getTypeface(CONTENT, Typeface.NORMAL));
    editText.setFocusableInTouchMode(true);
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, NORMALTEXTSIZE);
    editText.setTextColor(Color.parseColor(this.DEFAULT_TEXT_COLOR));
    editText.setPadding(0,30,0,30);
}
 
Example 15
Source File: MainFragment.java    From leanback-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
	TextView view = new TextView(parent.getContext());
	view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT));
	view.setFocusable(true);
	view.setFocusableInTouchMode(true);
	view.setBackgroundColor(getResources().getColor(R.color.default_background));
	view.setTextColor(Color.WHITE);
	view.setGravity(Gravity.CENTER);
	return new ViewHolder(view);
}
 
Example 16
Source File: FormAdapter.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
private void setAttachPicker(TextView tv, final int position, final LinearLayout layoutRow) {
    tv.setFocusableInTouchMode(false);
    layoutRow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            clickedPosition = position;
            getAttachPickerObservable(attachs).forEach(actionAttach);
        }
    });
}
 
Example 17
Source File: TextItemPresenter.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(ITEM_WIDTH, ITEM_HEIGHT));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    view.setTextSize(32);
    return new ViewHolder(view);
}
 
Example 18
Source File: MainFragment.java    From alltv with MIT License 5 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {

    TextView view = new TextView(parent.getContext());

    view.setLayoutParams(new ViewGroup.LayoutParams(getResources().getInteger(R.integer.GRID_ITEM_WIDTH), getResources().getInteger(R.integer.GRID_ITEM_HEIGHT)));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);

    return new ViewHolder(view);
}
 
Example 19
Source File: SubLayout.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
SubLayout(Context context) {
    super(context);
    setWillNotDraw(false);
    final Resources resources = context.getResources();
    int size = resources.getDimensionPixelOffset(R.dimen.floatingActionModeItemSize);
    int textColor = resources.getColor(R.color.floatingActionModeSubTitleTextColor);
    float textSize = resources.getDimension(R.dimen.floatingActionModeSubTitleTextSize);
    @SuppressLint("CustomViewStyleable") final TypedArray custom =
            context.obtainStyledAttributes(R.styleable.FloatingActionMode);
    size = custom.getDimensionPixelOffset(
            R.styleable.FloatingActionMode_floatingActionModeItemSize, size);
    final int textAppearance = custom.getResourceId(
            R.styleable.FloatingActionMode_floatingActionModeSubTitleTextAppearance, 0);
    textColor = custom.getColor(
            R.styleable.FloatingActionMode_floatingActionModeSubTitleTextColor, textColor);
    textSize = custom.getDimension(
            R.styleable.FloatingActionMode_floatingActionModeSubTitleTextSize, textSize);
    custom.recycle();
    setOrientation(VERTICAL);
    mTitle = new TextView(context);
    if (textAppearance != 0)
        mTitle.setTextAppearance(context, textAppearance);
    else {
        final TypedArray a = context.obtainStyledAttributes(
                new int[]{android.R.attr.textAppearanceListItemSmall});
        mTitle.setTextAppearance(context, a.getResourceId(0, 0));
        a.recycle();
    }
    mTitle.setBackgroundDrawable(null);
    mTitle.setEllipsize(TextUtils.TruncateAt.END);
    mTitle.setFocusable(false);
    mTitle.setFocusableInTouchMode(false);
    mTitle.setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
    mTitle.setGravity(Gravity.CENTER);
    mTitle.setSingleLine();
    mTitle.setTextColor(textColor);
    mTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    mTitle.setMinimumHeight(size);
    mTitle.setPadding(size, 0, size, 0);
    if (Build.VERSION.SDK_INT >= 16)
        mTitle.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
    mTitle.setLayoutParams(new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    mList = new SubListView(context);
    mListMaxHeight = mList.getMaxHeight();
    mParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0);
    mParams.weight = 1;
    mCornerCrop.setFillType(Path.FillType.EVEN_ODD);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    mCropPath.setFillType(Path.FillType.EVEN_ODD);
    mList.setOnItemClickListener(this);
}
 
Example 20
Source File: SnackbarManager.java    From pandroid with Apache License 2.0 4 votes vote down vote up
private ToastNotifier makeCustomNotification(Activity activity, ToastType toastType, String label, String btnLabel, int drawableRes, int style, int duration, boolean undefinedLoad, final ToastListener listener) {
    if (duration < 0)
        duration = Snackbar.LENGTH_INDEFINITE;
    final Snackbar notif = Snackbar.make(activity.findViewById(android.R.id.content), label, duration);
    if (style == 0) {
        style = R.style.Toast;
    }
    TypedArray attributes = activity.obtainStyledAttributes(style, R.styleable.ToastAppearance);
    int textColor = attributes.getColor(R.styleable.ToastAppearance_toastTextColor, ContextCompat.getColor(activity, R.color.white));
    int buttonTextColor = attributes.getColor(R.styleable.ToastAppearance_toastButtonTextColor, ContextCompat.getColor(activity, R.color.pandroid_green_dark));
    int backgroundColor = attributes.getColor(R.styleable.ToastAppearance_toastBackground, ContextCompat.getColor(activity, R.color.pandroid_green));
    notif.getView().setBackgroundColor(backgroundColor);
    ((TextView) notif.getView().findViewById(android.support.design.R.id.snackbar_text)).setTextColor(textColor);
    TextView actionView = ((TextView) notif.getView().findViewById(android.support.design.R.id.snackbar_action));
    actionView.setTextColor(buttonTextColor);
    attributes.recycle();

    notif.setCallback(new Snackbar.Callback() {
        @Override
        public void onDismissed(Snackbar snackbar, int event) {
            super.onDismissed(snackbar, event);
            if (listener != null)
                listener.onDismiss();
        }
    });

    Drawable drawable = null;
    if (drawableRes > 0) {
        drawable = ContextCompat.getDrawable(activity, drawableRes);
    }
    actionView.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, drawable, null);
    if (toastType == ToastType.ACTION && btnLabel != null) {
        notif.setAction(btnLabel, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null)
                    listener.onActionClicked();
            }
        });
    } else if (drawableRes > 0) {
        actionView.setVisibility(View.VISIBLE);
        actionView.setClickable(false);
        actionView.setFocusableInTouchMode(false);
        actionView.setFocusable(false);
        actionView.setEnabled(false);
    }

    if (toastType == ToastType.LOADER) {
        ProgressWheel progressWheel = new ProgressWheel(activity);
        progressWheel.setId(R.id.snakebar_loader);
        if (undefinedLoad)
            progressWheel.spin();

        progressWheel.setBarWidth((int) DeviceUtils.dpToPx(activity, 4));
        progressWheel.setCircleRadius((int) DeviceUtils.dpToPx(activity, 30));
        progressWheel.setBarColor(buttonTextColor);
        progressWheel.setLinearProgress(true);
        ((Snackbar.SnackbarLayout) notif.getView()).addView(progressWheel, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }
    notif.show();
    lastShowNotif = notif;
    return new ToastNotifier() {
        @Override
        public void setProgress(int progress) {
            ProgressWheel loader = (ProgressWheel) notif.getView().findViewById(R.id.snakebar_loader);
            if (loader != null) {
                loader.setProgress(progress / 100f);
            }
        }

        @Override
        public void dismiss() {
            notif.dismiss();
        }

    };
}