Java Code Examples for android.content.res.TypedArray#getFraction()

The following examples show how to use android.content.res.TypedArray#getFraction() . 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: KeyboardRow.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
public float getKeyWidth(final TypedArray keyAttr, final float keyXPos) {
    if (keyAttr == null) {
        return getDefaultKeyWidth();
    }
    final int widthType = ResourceUtils.getEnumValue(keyAttr,
            R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM);
    switch (widthType) {
    case KEYWIDTH_FILL_RIGHT:
        // If keyWidth is fillRight, the actual key width will be determined to fill
        // out the area up to the right edge of the keyboard.
        final int keyboardRightEdge = mParams.mOccupiedWidth - mParams.mRightPadding;
        return keyboardRightEdge - keyXPos;
    default: // KEYWIDTH_NOT_ENUM
        return keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
                mParams.mBaseWidth, mParams.mBaseWidth, getDefaultKeyWidth());
    }
}
 
Example 2
Source File: KeyboardRow.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
public float getKeyX(final TypedArray keyAttr) {
    if (keyAttr == null || !keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) {
        return mCurrentX;
    }
    final float keyXPos = keyAttr.getFraction(R.styleable.Keyboard_Key_keyXPos,
            mParams.mBaseWidth, mParams.mBaseWidth, 0);
    if (keyXPos >= 0) {
        return keyXPos + mParams.mLeftPadding;
    }
    // If keyXPos is negative, the actual x-coordinate will be
    // keyboardWidth + keyXPos.
    // keyXPos shouldn't be less than mCurrentX because drawable area for this
    // key starts at mCurrentX. Or, this key will overlaps the adjacent key on
    // its left hand side.
    final int keyboardRightEdge = mParams.mOccupiedWidth - mParams.mRightPadding;
    return Math.max(keyXPos + keyboardRightEdge, mCurrentX);
}
 
Example 3
Source File: FrameView.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private void init(AttributeSet attrs) {
    if (attrs != null) {
        TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.FrameView);

        frameColor = typedArray.getColor(R.styleable.FrameView_frame_color, Color.WHITE);
        frameSize = typedArray.getFraction(R.styleable.FrameView_frame_size, 1, 1, 1f);
        if (frameSize > 0.5) {
            frameSize = 1f;
        }
        frameThickness = typedArray.getDimensionPixelSize(R.styleable.FrameView_frame_thickness, 1);

        typedArray.recycle();
    }

    paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(frameThickness);
    paint.setColor(frameColor);

    offset = frameThickness / 2f;
}
 
Example 4
Source File: KeyboardRow.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
public float getKeyWidth(final TypedArray keyAttr, final float keyXPos) {
    if (keyAttr == null) {
        return getDefaultKeyWidth();
    }
    final int widthType = ResourceUtils.getEnumValue(keyAttr,
            R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM);
    switch (widthType) {
    case KEYWIDTH_FILL_RIGHT:
        // If keyWidth is fillRight, the actual key width will be determined to fill
        // out the area up to the right edge of the keyboard.
        final int keyboardRightEdge = mParams.mOccupiedWidth - mParams.mRightPadding;
        return keyboardRightEdge - keyXPos;
    default: // KEYWIDTH_NOT_ENUM
        return keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
                mParams.mBaseWidth, mParams.mBaseWidth, getDefaultKeyWidth());
    }
}
 
Example 5
Source File: KeyboardRow.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
public float getKeyX(final TypedArray keyAttr) {
    if (keyAttr == null || !keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) {
        return mCurrentX;
    }
    final float keyXPos = keyAttr.getFraction(R.styleable.Keyboard_Key_keyXPos,
            mParams.mBaseWidth, mParams.mBaseWidth, 0);
    if (keyXPos >= 0) {
        return keyXPos + mParams.mLeftPadding;
    }
    // If keyXPos is negative, the actual x-coordinate will be
    // keyboardWidth + keyXPos.
    // keyXPos shouldn't be less than mCurrentX because drawable area for this
    // key starts at mCurrentX. Or, this key will overlaps the adjacent key on
    // its left hand side.
    final int keyboardRightEdge = mParams.mOccupiedWidth - mParams.mRightPadding;
    return Math.max(keyXPos + keyboardRightEdge, mCurrentX);
}
 
Example 6
Source File: KeyboardRow.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
public float getKeyWidth(final TypedArray keyAttr, final float keyXPos) {
    if (keyAttr == null) {
        return getDefaultKeyWidth();
    }
    final int widthType = ResourceUtils.getEnumValue(keyAttr,
            R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM);
    switch (widthType) {
    case KEYWIDTH_FILL_RIGHT:
        // If keyWidth is fillRight, the actual key width will be determined to fill
        // out the area up to the right edge of the keyboard.
        final int keyboardRightEdge = mParams.mOccupiedWidth - mParams.mRightPadding;
        return keyboardRightEdge - keyXPos;
    default: // KEYWIDTH_NOT_ENUM
        return keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
                mParams.mBaseWidth, mParams.mBaseWidth, getDefaultKeyWidth());
    }
}
 
Example 7
Source File: ParallaxViewPager.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
public ParallaxViewPager(Context context, AttributeSet attrs)
{
    super(context, attrs);
    mParallaxTransformer = new ParallaxTransformer();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ParallaxViewPager, 0,
            0);
    mMode = Mode.values()[a.getInt(R.styleable.ParallaxViewPager_mode, 0)];
    setMode(mMode);

    if (a.hasValue(R.styleable.ParallaxViewPager_right_shadow))
    {
        mRightShadow = a.getDrawable(R.styleable.ParallaxViewPager_right_shadow);
    }
    if (a.hasValue(R.styleable.ParallaxViewPager_left_shadow))
    {
        mLeftShadow = a.getDrawable(R.styleable.ParallaxViewPager_left_shadow);
    }
    mShadowWidth = a.getDimensionPixelSize(R.styleable.ParallaxViewPager_shadow_width, (int) dp2px(20, getContext()));
    TypedValue tv = a.peekValue(R.styleable.ParallaxViewPager_outset);
    if (tv != null)
    {
        if (tv.type == TypedValue.TYPE_FRACTION)
        {
            mOutsetFraction = a.getFraction(R.styleable.ParallaxViewPager_outset, 1, 1, 0);
            setOutsetFraction(mOutsetFraction);
        } else if (tv.type == TypedValue.TYPE_DIMENSION)
        {
            mOutset = (int) TypedValue.complexToDimension(tv.data, getResources().getDisplayMetrics());
            setOutset(mOutset);
        }
    }
    final int resID = a.getResourceId(R.styleable.ParallaxViewPager_interpolator, 0);
    if (resID > 0)
    {
        setInterpolator(context, resID);
    }
    a.recycle();
}
 
Example 8
Source File: ResourceUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
public static float getDimensionOrFraction(final TypedArray a, final int index, final int base,
        final float defValue) {
    final TypedValue value = a.peekValue(index);
    if (value == null) {
        return defValue;
    }
    if (isFractionValue(value)) {
        return a.getFraction(index, base, base, defValue);
    } else if (isDimensionValue(value)) {
        return a.getDimension(index, defValue);
    }
    return defValue;
}
 
Example 9
Source File: KeyboardRow.java    From simple-keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Parse and update key attributes using default attributes. This constructor is used
 * to parse include tag.
 *
 * @param keyAttr an attributes array of include tag.
 * @param defaultRowAttr default Row attributes.
 * @param keyboardWidth the keyboard width that is required to calculate keyWidth attribute.
 */
public RowAttributes(final TypedArray keyAttr, final RowAttributes defaultRowAttr,
        final int keyboardWidth) {
    mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
            keyboardWidth, keyboardWidth, defaultRowAttr.mDefaultKeyWidth);
    mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0)
            | defaultRowAttr.mDefaultKeyLabelFlags;
    mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
            defaultRowAttr.mDefaultBackgroundType);
}
 
Example 10
Source File: KeyboardRow.java    From LokiBoard-Android-Keylogger with Apache License 2.0 5 votes vote down vote up
/**
 * Parse and create key attributes. This constructor is used to parse Row tag.
 *
 * @param keyAttr an attributes array of Row tag.
 * @param defaultKeyWidth a default key width.
 * @param keyboardWidth the keyboard width that is required to calculate keyWidth attribute.
 */
public RowAttributes(final TypedArray keyAttr, final float defaultKeyWidth,
        final int keyboardWidth) {
    mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
            keyboardWidth, keyboardWidth, defaultKeyWidth);
    mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0);
    mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
            Key.BACKGROUND_TYPE_NORMAL);
}
 
Example 11
Source File: ResourceUtils.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
public static float getFraction(final TypedArray a, final int index, final float defValue) {
    final TypedValue value = a.peekValue(index);
    if (value == null || !isFractionValue(value)) {
        return defValue;
    }
    return a.getFraction(index, 1, 1, defValue);
}
 
Example 12
Source File: KeyboardRow.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Parse and create key attributes. This constructor is used to parse Row tag.
 *
 * @param keyAttr an attributes array of Row tag.
 * @param defaultKeyWidth a default key width.
 * @param keyboardWidth the keyboard width that is required to calculate keyWidth attribute.
 */
public RowAttributes(final TypedArray keyAttr, final float defaultKeyWidth,
        final int keyboardWidth) {
    mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
            keyboardWidth, keyboardWidth, defaultKeyWidth);
    mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0);
    mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
            Key.BACKGROUND_TYPE_NORMAL);
}
 
Example 13
Source File: KeyboardRow.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parse and update key attributes using default attributes. This constructor is used
 * to parse include tag.
 *
 * @param keyAttr an attributes array of include tag.
 * @param defaultRowAttr default Row attributes.
 * @param keyboardWidth the keyboard width that is required to calculate keyWidth attribute.
 */
public RowAttributes(final TypedArray keyAttr, final RowAttributes defaultRowAttr,
        final int keyboardWidth) {
    mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
            keyboardWidth, keyboardWidth, defaultRowAttr.mDefaultKeyWidth);
    mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0)
            | defaultRowAttr.mDefaultKeyLabelFlags;
    mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
            defaultRowAttr.mDefaultBackgroundType);
}
 
Example 14
Source File: KeyboardRow.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parse and create key attributes. This constructor is used to parse Row tag.
 *
 * @param keyAttr an attributes array of Row tag.
 * @param defaultKeyWidth a default key width.
 * @param keyboardWidth the keyboard width that is required to calculate keyWidth attribute.
 */
public RowAttributes(final TypedArray keyAttr, final float defaultKeyWidth,
        final int keyboardWidth) {
    mDefaultKeyWidth = keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
            keyboardWidth, keyboardWidth, defaultKeyWidth);
    mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0);
    mDefaultBackgroundType = keyAttr.getInt(R.styleable.Keyboard_Key_backgroundType,
            Key.BACKGROUND_TYPE_NORMAL);
}
 
Example 15
Source File: JoystickView.java    From virtual-joystick-android with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor that is called when inflating a JoystickView from XML. This is called
 * when a JoystickView is being constructed from an XML file, supplying attributes
 * that were specified in the XML file.
 * @param context The Context the JoystickView is running in, through which it can
 *        access the current theme, resources, etc.
 * @param attrs The attributes of the XML tag that is inflating the JoystickView.
 */
public JoystickView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.JoystickView,
            0, 0
    );

    int buttonColor;
    int borderColor;
    int backgroundColor;
    int borderWidth;
    Drawable buttonDrawable;
    try {
        buttonColor = styledAttributes.getColor(R.styleable.JoystickView_JV_buttonColor, DEFAULT_COLOR_BUTTON);
        borderColor = styledAttributes.getColor(R.styleable.JoystickView_JV_borderColor, DEFAULT_COLOR_BORDER);
        mBorderAlpha = styledAttributes.getInt(R.styleable.JoystickView_JV_borderAlpha, DEFAULT_ALPHA_BORDER);
        backgroundColor = styledAttributes.getColor(R.styleable.JoystickView_JV_backgroundColor, DEFAULT_BACKGROUND_COLOR);
        borderWidth = styledAttributes.getDimensionPixelSize(R.styleable.JoystickView_JV_borderWidth, DEFAULT_WIDTH_BORDER);
        mFixedCenter = styledAttributes.getBoolean(R.styleable.JoystickView_JV_fixedCenter, DEFAULT_FIXED_CENTER);
        mAutoReCenterButton = styledAttributes.getBoolean(R.styleable.JoystickView_JV_autoReCenterButton, DEFAULT_AUTO_RECENTER_BUTTON);
        mButtonStickToBorder = styledAttributes.getBoolean(R.styleable.JoystickView_JV_buttonStickToBorder, DEFAULT_BUTTON_STICK_TO_BORDER);
        buttonDrawable = styledAttributes.getDrawable(R.styleable.JoystickView_JV_buttonImage);
        mEnabled = styledAttributes.getBoolean(R.styleable.JoystickView_JV_enabled, true);
        mButtonSizeRatio = styledAttributes.getFraction(R.styleable.JoystickView_JV_buttonSizeRatio, 1, 1, 0.25f);
        mBackgroundSizeRatio = styledAttributes.getFraction(R.styleable.JoystickView_JV_backgroundSizeRatio, 1, 1, 0.75f);
        mButtonDirection = styledAttributes.getInteger(R.styleable.JoystickView_JV_buttonDirection, BUTTON_DIRECTION_BOTH);
    } finally {
        styledAttributes.recycle();
    }

    // Initialize the drawing according to attributes

    mPaintCircleButton = new Paint();
    mPaintCircleButton.setAntiAlias(true);
    mPaintCircleButton.setColor(buttonColor);
    mPaintCircleButton.setStyle(Paint.Style.FILL);

    if (buttonDrawable != null) {
        if (buttonDrawable instanceof BitmapDrawable) {
            mButtonBitmap = ((BitmapDrawable) buttonDrawable).getBitmap();
            mPaintBitmapButton = new Paint();
        }
    }

    mPaintCircleBorder = new Paint();
    mPaintCircleBorder.setAntiAlias(true);
    mPaintCircleBorder.setColor(borderColor);
    mPaintCircleBorder.setStyle(Paint.Style.STROKE);
    mPaintCircleBorder.setStrokeWidth(borderWidth);

    if (borderColor != Color.TRANSPARENT) {
        mPaintCircleBorder.setAlpha(mBorderAlpha);
    }

    mPaintBackground = new Paint();
    mPaintBackground.setAntiAlias(true);
    mPaintBackground.setColor(backgroundColor);
    mPaintBackground.setStyle(Paint.Style.FILL);


    // Init Runnable for MultiLongPress

    mRunnableMultipleLongPress = new Runnable() {
        @Override
        public void run() {
            if (mOnMultipleLongPressListener != null)
                mOnMultipleLongPressListener.onMultipleLongPress();
        }
    };
}
 
Example 16
Source File: MainKeyboardView.java    From openboard with GNU General Public License v3.0 4 votes vote down vote up
public MainKeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    final DrawingPreviewPlacerView drawingPreviewPlacerView =
            new DrawingPreviewPlacerView(context, attrs);

    final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
            attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
    final int ignoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
    final int gestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0);
    mTimerHandler = new TimerHandler(
            this, ignoreAltCodeKeyTimeout, gestureRecognitionUpdateTime);

    final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension(
            R.styleable.MainKeyboardView_keyHysteresisDistance, 0.0f);
    final float keyHysteresisDistanceForSlidingModifier = mainKeyboardViewAttr.getDimension(
            R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0.0f);
    mKeyDetector = new KeyDetector(
            keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier);

    PointerTracker.init(mainKeyboardViewAttr, mTimerHandler, this /* DrawingProxy */);

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final boolean forceNonDistinctMultitouch = prefs.getBoolean(
            DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, false);
    final boolean hasDistinctMultitouch = context.getPackageManager()
            .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)
            && !forceNonDistinctMultitouch;
    mNonDistinctMultitouchHelper = hasDistinctMultitouch ? null
            : new NonDistinctMultitouchHelper();

    final int backgroundDimAlpha = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_backgroundDimAlpha, 0);
    mBackgroundDimAlphaPaint.setColor(Color.BLACK);
    mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha);
    mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
            R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f);
    mLanguageOnSpacebarTextColor = mainKeyboardViewAttr.getColor(
            R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
    mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat(
            R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius,
            LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED);
    mLanguageOnSpacebarTextShadowColor = mainKeyboardViewAttr.getColor(
            R.styleable.MainKeyboardView_languageOnSpacebarTextShadowColor, 0);
    mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_languageOnSpacebarFinalAlpha,
            Constants.Color.ALPHA_OPAQUE);
    final int languageOnSpacebarFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
    final int altCodeKeyWhileTypingFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator, 0);
    final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);

    mKeyPreviewDrawParams = new KeyPreviewDrawParams(mainKeyboardViewAttr);
    mKeyPreviewChoreographer = new KeyPreviewChoreographer(mKeyPreviewDrawParams);

    final int moreKeysKeyboardLayoutId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
    final int moreKeysKeyboardForActionLayoutId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_moreKeysKeyboardForActionLayout,
            moreKeysKeyboardLayoutId);
    mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
            R.styleable.MainKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false);

    mGestureFloatingPreviewTextLingerTimeout = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_gestureFloatingPreviewTextLingerTimeout, 0);

    mGestureFloatingTextDrawingPreview = new GestureFloatingTextDrawingPreview(
            mainKeyboardViewAttr);
    mGestureFloatingTextDrawingPreview.setDrawingView(drawingPreviewPlacerView);

    mGestureTrailsDrawingPreview = new GestureTrailsDrawingPreview(mainKeyboardViewAttr);
    mGestureTrailsDrawingPreview.setDrawingView(drawingPreviewPlacerView);

    mSlidingKeyInputDrawingPreview = new SlidingKeyInputDrawingPreview(mainKeyboardViewAttr);
    mSlidingKeyInputDrawingPreview.setDrawingView(drawingPreviewPlacerView);
    mainKeyboardViewAttr.recycle();

    mDrawingPreviewPlacerView = drawingPreviewPlacerView;

    final LayoutInflater inflater = LayoutInflater.from(getContext());
    mMoreKeysKeyboardContainer = inflater.inflate(moreKeysKeyboardLayoutId, null);
    mMoreKeysKeyboardForActionContainer = inflater.inflate(
            moreKeysKeyboardForActionLayoutId, null);
    mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(
            languageOnSpacebarFadeoutAnimatorResId, this);
    mAltCodeKeyWhileTypingFadeoutAnimator = loadObjectAnimator(
            altCodeKeyWhileTypingFadeoutAnimatorResId, this);
    mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator(
            altCodeKeyWhileTypingFadeinAnimatorResId, this);

    mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;

    mLanguageOnSpacebarHorizontalMargin = (int)getResources().getDimension(
            R.dimen.config_language_on_spacebar_horizontal_margin);
}
 
Example 17
Source File: MainKeyboardView.java    From LokiBoard-Android-Keylogger with Apache License 2.0 4 votes vote down vote up
public MainKeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    final DrawingPreviewPlacerView drawingPreviewPlacerView =
            new DrawingPreviewPlacerView(context, attrs);

    final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
            attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
    final int ignoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
    mTimerHandler = new TimerHandler(this, ignoreAltCodeKeyTimeout);

    final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension(
            R.styleable.MainKeyboardView_keyHysteresisDistance, 0.0f);
    final float keyHysteresisDistanceForSlidingModifier = mainKeyboardViewAttr.getDimension(
            R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0.0f);
    mKeyDetector = new KeyDetector(
            keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier);

    PointerTracker.init(mainKeyboardViewAttr, mTimerHandler, this /* DrawingProxy */);

    final boolean hasDistinctMultitouch = context.getPackageManager()
            .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
    mNonDistinctMultitouchHelper = hasDistinctMultitouch ? null
            : new NonDistinctMultitouchHelper();

    final int backgroundDimAlpha = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_backgroundDimAlpha, 0);
    mBackgroundDimAlphaPaint.setColor(Color.BLACK);
    mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha);
    mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
            R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f);
    mLanguageOnSpacebarTextColor = mainKeyboardViewAttr.getColor(
            R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
    mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_languageOnSpacebarFinalAlpha,
            Constants.Color.ALPHA_OPAQUE);
    final int languageOnSpacebarFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
    final int altCodeKeyWhileTypingFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator, 0);
    final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);

    mKeyPreviewDrawParams = new KeyPreviewDrawParams(mainKeyboardViewAttr);
    mKeyPreviewChoreographer = new KeyPreviewChoreographer(mKeyPreviewDrawParams);

    final int moreKeysKeyboardLayoutId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
    mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
            R.styleable.MainKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false);

    mainKeyboardViewAttr.recycle();

    mDrawingPreviewPlacerView = drawingPreviewPlacerView;

    final LayoutInflater inflater = LayoutInflater.from(getContext());
    mMoreKeysKeyboardContainer = inflater.inflate(moreKeysKeyboardLayoutId, null);
    mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(
            languageOnSpacebarFadeoutAnimatorResId, this);
    mAltCodeKeyWhileTypingFadeoutAnimator = loadObjectAnimator(
            altCodeKeyWhileTypingFadeoutAnimatorResId, this);
    mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator(
            altCodeKeyWhileTypingFadeinAnimatorResId, this);

    mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;

    mLanguageOnSpacebarHorizontalMargin = (int)getResources().getDimension(
            R.dimen.config_language_on_spacebar_horizontal_margin);
}
 
Example 18
Source File: KeyboardBuilder.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
private void parseKeyboardAttributes(final XmlPullParser parser) {
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyboardAttr = mContext.obtainStyledAttributes(
            attr, R.styleable.Keyboard, R.attr.keyboardStyle, R.style.Keyboard);
    final TypedArray keyAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key);
    try {
        final KeyboardParams params = mParams;
        final int height = params.mId.mHeight;
        final int width = params.mId.mWidth;
        params.mOccupiedHeight = height;
        params.mOccupiedWidth = width;
        params.mTopPadding = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_keyboardTopPadding, height, height, 0);
        params.mBottomPadding = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_keyboardBottomPadding, height, height, 0);
        params.mLeftPadding = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_keyboardLeftPadding, width, width, 0);
        params.mRightPadding = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_keyboardRightPadding, width, width, 0);

        final int baseWidth =
                params.mOccupiedWidth - params.mLeftPadding - params.mRightPadding;
        params.mBaseWidth = baseWidth;
        params.mDefaultKeyWidth = (int)keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
                baseWidth, baseWidth, baseWidth / DEFAULT_KEYBOARD_COLUMNS);
        params.mHorizontalGap = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_horizontalGap, baseWidth, baseWidth, 0);
        // TODO: Fix keyboard geometry calculation clearer. Historically vertical gap between
        // rows are determined based on the entire keyboard height including top and bottom
        // paddings.
        params.mVerticalGap = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_verticalGap, height, height, 0);
        final int baseHeight = params.mOccupiedHeight - params.mTopPadding
                - params.mBottomPadding + params.mVerticalGap;
        params.mBaseHeight = baseHeight;
        params.mDefaultRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
                R.styleable.Keyboard_rowHeight, baseHeight, baseHeight / DEFAULT_KEYBOARD_ROWS);

        params.mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);

        params.mMoreKeysTemplate = keyboardAttr.getResourceId(
                R.styleable.Keyboard_moreKeysTemplate, 0);
        params.mMaxMoreKeysKeyboardColumn = keyAttr.getInt(
                R.styleable.Keyboard_Key_maxMoreKeysColumn, 5);

        params.mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0);
        params.mIconsSet.loadIcons(keyboardAttr);
        params.mTextsSet.setLocale(params.mId.getLocale(), mContext);

        final int resourceId = keyboardAttr.getResourceId(
                R.styleable.Keyboard_touchPositionCorrectionData, 0);
        if (resourceId != 0) {
            final String[] data = mResources.getStringArray(resourceId);
            params.mTouchPositionCorrection.load(data);
        }
    } finally {
        keyAttr.recycle();
        keyboardAttr.recycle();
    }
}
 
Example 19
Source File: RulerView.java    From android-ruler-picker with Apache License 2.0 4 votes vote down vote up
private void parseAttr(@Nullable AttributeSet attributeSet) {
    if (attributeSet != null) {
        TypedArray a = getContext().getTheme().obtainStyledAttributes(attributeSet,
                R.styleable.RulerView,
                0,
                0);

        try { //Parse params
            if (a.hasValue(R.styleable.RulerView_ruler_text_color)) {
                mTextColor = a.getColor(R.styleable.RulerView_ruler_text_color, Color.WHITE);
            }

            if (a.hasValue(R.styleable.RulerView_ruler_text_size)) {
                mTextSize = a.getDimensionPixelSize(R.styleable.RulerView_ruler_text_size, 14);
            }

            if (a.hasValue(R.styleable.RulerView_indicator_color)) {
                mIndicatorColor = a.getColor(R.styleable.RulerView_indicator_color, Color.WHITE);
            }

            if (a.hasValue(R.styleable.RulerView_indicator_width)) {
                mIndicatorWidthPx = a.getDimensionPixelSize(R.styleable.RulerView_indicator_width,
                        4);
            }

            if (a.hasValue(R.styleable.RulerView_indicator_interval)) {
                mIndicatorInterval = a.getDimensionPixelSize(R.styleable.RulerView_indicator_interval,
                        4);
            }

            if (a.hasValue(R.styleable.RulerView_long_height_height_ratio)) {
                mLongIndicatorHeightRatio = a.getFraction(R.styleable.RulerView_long_height_height_ratio,
                        1, 1, 0.6f);
            }
            if (a.hasValue(R.styleable.RulerView_short_height_height_ratio)) {
                mShortIndicatorHeightRatio = a.getFraction(R.styleable.RulerView_short_height_height_ratio,
                        1, 1, 0.4f);
            }
            setIndicatorHeight(mLongIndicatorHeightRatio, mShortIndicatorHeightRatio);

            if (a.hasValue(R.styleable.RulerView_min_value)) {
                mMinValue = a.getInteger(R.styleable.RulerView_min_value, 0);
            }
            if (a.hasValue(R.styleable.RulerView_max_value)) {
                mMaxValue = a.getInteger(R.styleable.RulerView_max_value, 100);
            }
            setValueRange(mMinValue, mMaxValue);
        } finally {
            a.recycle();
        }
    }
    refreshPaint();
}
 
Example 20
Source File: MainKeyboardView.java    From simple-keyboard with Apache License 2.0 4 votes vote down vote up
public MainKeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    final DrawingPreviewPlacerView drawingPreviewPlacerView =
            new DrawingPreviewPlacerView(context, attrs);

    final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
            attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
    final int ignoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
    mTimerHandler = new TimerHandler(this, ignoreAltCodeKeyTimeout);

    final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension(
            R.styleable.MainKeyboardView_keyHysteresisDistance, 0.0f);
    final float keyHysteresisDistanceForSlidingModifier = mainKeyboardViewAttr.getDimension(
            R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0.0f);
    mKeyDetector = new KeyDetector(
            keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier);

    PointerTracker.init(mainKeyboardViewAttr, mTimerHandler, this /* DrawingProxy */);

    final boolean hasDistinctMultitouch = context.getPackageManager()
            .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
    mNonDistinctMultitouchHelper = hasDistinctMultitouch ? null
            : new NonDistinctMultitouchHelper();

    final int backgroundDimAlpha = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_backgroundDimAlpha, 0);
    mBackgroundDimAlphaPaint.setColor(Color.BLACK);
    mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha);
    mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
            R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f);
    mLanguageOnSpacebarTextColor = mainKeyboardViewAttr.getColor(
            R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
    mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt(
            R.styleable.MainKeyboardView_languageOnSpacebarFinalAlpha,
            Constants.Color.ALPHA_OPAQUE);
    final int languageOnSpacebarFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
    final int altCodeKeyWhileTypingFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator, 0);
    final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);

    mKeyPreviewDrawParams = new KeyPreviewDrawParams(mainKeyboardViewAttr);
    mKeyPreviewChoreographer = new KeyPreviewChoreographer(mKeyPreviewDrawParams);

    final int moreKeysKeyboardLayoutId = mainKeyboardViewAttr.getResourceId(
            R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
    mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
            R.styleable.MainKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false);

    mainKeyboardViewAttr.recycle();

    mDrawingPreviewPlacerView = drawingPreviewPlacerView;

    final LayoutInflater inflater = LayoutInflater.from(getContext());
    mMoreKeysKeyboardContainer = inflater.inflate(moreKeysKeyboardLayoutId, null);
    mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(
            languageOnSpacebarFadeoutAnimatorResId, this);
    mAltCodeKeyWhileTypingFadeoutAnimator = loadObjectAnimator(
            altCodeKeyWhileTypingFadeoutAnimatorResId, this);
    mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator(
            altCodeKeyWhileTypingFadeinAnimatorResId, this);

    mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;

    mLanguageOnSpacebarHorizontalMargin = (int)getResources().getDimension(
            R.dimen.config_language_on_spacebar_horizontal_margin);
}