简体   繁体   English

使用Gradle依赖项时如何覆盖函数?

[英]How can I overridden a function when I use Gradle dependency?

I use the range-seek-bar ( https://github.com/anothem/android-range-seek-bar ) control in my project, I hope to format the lable of the selected min and max value of android-range-seek-bar. 我在我的项目中使用了range-seek-bar( https://github.com/anothem/android-range-seek-bar )控件,我希望格式化android-range-的所选最小值和最大值的标签搜寻栏。 I browse source code, I think I should to change the code in the function onDraw in RangeSeekBar.java. 我浏览了源代码,我想我应该在RangeSeekBar.java中的onDraw函数中更改代码。 How can I do that? 我怎样才能做到这一点?

BTW, I don't wish to create a new project based range-seek-bar and modify code. 顺便说一句,我不想​​创建一个新的基于range-seek-bar的项目并修改代码。

UI 用户界面

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:rsb="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/border_ui">


    <LinearLayout
        android:id="@+id/linearLayoutToolBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        style="@style/myToolbar"
        android:weightSum="4" >

        <Button
            android:id="@+id/btnCrop"
            style="@style/myTextMedium"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:text="@string/BtnCrop" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/LinerSeekBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearLayoutToolBar"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingBottom="14dp"
        android:paddingTop="1dp"
        android:layout_centerHorizontal="true"
        android:orientation="vertical">

           <org.florescu.android.rangeseekbar.RangeSeekBar
            android:id="@+id/myRangeSeekBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            rsb:absoluteMaxValue="10000"
            rsb:absoluteMinValue="0"
            rsb:activateOnDefaultValues="true"
            rsb:showLabels="true"
            rsb:valuesAboveThumbs="false"
            rsb:textAboveThumbsColor="@color/black" />

    </LinearLayout>


    <TextureView
        android:id="@+id/mTextureView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        android:layout_marginBottom="5dp"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"

        android:layout_above="@+id/LinerSeekBar"
        android:layout_centerHorizontal="true"
     />


</RelativeLayout>

Gradle 摇篮

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"       

    productFlavors {
        free {
            applicationId "info.dodata.screenrecorder"
        }

        pro {
            applicationId "info.dodata.screenrecorder.pro"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            buildConfigField "boolean", "IsDebugMode", "false"
        }

        debug {
            buildConfigField "boolean", "IsDebugMode", "true"
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:7.3.0'
    compile 'com.android.support:support-v13:23.1.0'
    compile 'com.googlecode.mp4parser:isoparser:1.1.17'
    compile 'org.florescu.android.rangeseekbar:rangeseekbar-library:0.3.0'
}

RangeSeekBar.java RangeSeekBar.java

/**
     * Draws the widget on the given canvas.
     */
    @Override
    protected synchronized void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);

        paint.setTextSize(mTextSize);
        paint.setStyle(Style.FILL);
        paint.setColor(mDefaultColor);
        paint.setAntiAlias(true);
        float minMaxLabelSize = 0;

        if (mShowLabels) {
            // draw min and max labels
            String minLabel = getContext().getString(R.string.demo_min_label);
            String maxLabel = getContext().getString(R.string.demo_max_label);
            minMaxLabelSize = Math.max(paint.measureText(minLabel), paint.measureText(maxLabel));
            float minMaxHeight = mTextOffset + mThumbHalfHeight + mTextSize / 3;
            canvas.drawText(minLabel, 0, minMaxHeight, paint);
            canvas.drawText(maxLabel, getWidth() - minMaxLabelSize, minMaxHeight, paint);
        }
        padding = mInternalPad + minMaxLabelSize + mThumbHalfWidth;

        // draw seek bar background line
        mRect.left = padding;
        mRect.right = getWidth() - padding;
        canvas.drawRect(mRect, paint);

        boolean selectedValuesAreDefault = (getSelectedMinValue().equals(getAbsoluteMinValue()) &&
                getSelectedMaxValue().equals(getAbsoluteMaxValue()));

        int colorToUseForButtonsAndHighlightedLine = !mAlwaysActive && !mActivateOnDefaultValues && selectedValuesAreDefault ?
                mDefaultColor : // default values
                mActiveColor;   // non default, filter is active

        // draw seek bar active range line
        mRect.left = normalizedToScreen(normalizedMinValue);
        mRect.right = normalizedToScreen(normalizedMaxValue);

        paint.setColor(colorToUseForButtonsAndHighlightedLine);
        canvas.drawRect(mRect, paint);

        // draw minimum thumb (& shadow if requested) if not a single thumb control
        if (!mSingleThumb) {
            if (mThumbShadow) {
                drawThumbShadow(normalizedToScreen(normalizedMinValue), canvas);
            }
            drawThumb(normalizedToScreen(normalizedMinValue), Thumb.MIN.equals(pressedThumb), canvas,
                    selectedValuesAreDefault);
        }

        // draw maximum thumb & shadow (if necessary)
        if (mThumbShadow) {
            drawThumbShadow(normalizedToScreen(normalizedMaxValue), canvas);
        }
        drawThumb(normalizedToScreen(normalizedMaxValue), Thumb.MAX.equals(pressedThumb), canvas,
                selectedValuesAreDefault);

        // draw the text if sliders have moved from default edges
        if (mShowTextAboveThumbs && (mActivateOnDefaultValues || !selectedValuesAreDefault)) {
            paint.setTextSize(mTextSize);
            paint.setColor(mTextAboveThumbsColor);
            // give text a bit more space here so it doesn't get cut off
            int offset = PixelUtil.dpToPx(getContext(), TEXT_LATERAL_PADDING_IN_DP);

            String minText = String.valueOf(getSelectedMinValue());
            String maxText = String.valueOf(getSelectedMaxValue());
            float minTextWidth = paint.measureText(minText) + offset;
            float maxTextWidth = paint.measureText(maxText) + offset;

            if (!mSingleThumb) {
                canvas.drawText(minText,
                        normalizedToScreen(normalizedMinValue) - minTextWidth * 0.5f,
                        mDistanceToTop + mTextSize,
                        paint);

            }

            canvas.drawText(maxText,
                    normalizedToScreen(normalizedMaxValue) - maxTextWidth * 0.5f,
                    mDistanceToTop + mTextSize,
                    paint);
        }

    }

您可以创建一个MyRangeSeekBar类,该类扩展RangeSeekBar并用您的代码覆盖onDraw

I found the solution. 我找到了解决方案。 Download the source code of "android-range-seek-bar", then open it with Android Studio. 下载“ android-range-seek-bar”的源代码,然后使用Android Studio打开它。 Now you can edit the code. 现在您可以编辑代码。 when you finish editing, release the project. 完成编辑后,释放项目。 And get the ".aar" file in the "rangeseekbar/build/outputs/aar" folder. 并在“ rangeseekbar / build / outputs / aar”文件夹中获取“ .aar”文件。 Open your module settings, click add module, choose "Import .JAR/.AAR Package". 打开模块设置,单击添加模块,选择“导入.JAR / .AAR包”。 Import the .aar file you just generated. 导入刚刚生成的.aar文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何强制gradle使用依赖的不同版本? - How can i force gradle to use to different versions of a dependency? Android Gradle:如何使用“调试”源作为“发布”构建的“提供”依赖项 - Android Gradle: How can I use the “debug” sources as a “provided” dependency for “release” builds 如何强制特定依赖项在 gradle 中使用特定版本的库 - How can I force a specific dependency to use specific version of a library in gradle 使用变量时如何查看 build.gradle 中的依赖项更新? - How can I see dependency updates in build.gradle when using variables? 如何将Firebase和Snap Creative Kit作为Gradle依赖项包括在内 - How can I include Firebase and Snap Creative Kit as Gradle dependency 如何在android studio中创建自己的gradle依赖关系? - How can I create own gradle dependency in android studio? 如何添加我的图书馆项目作为gradle依赖项? - how can I add my library project as a gradle dependency? 如何通过 gradle 制作 jar 包括依赖项 - how can I make a jar through gradle including dependency 我想在我的Android应用程序中使用Firebase UI Auth,但是当我添加依赖项时,gradle显示错误 - I wanted to use Firebase UI Auth in my android app but when I add the dependency, the gradle shows an error 当我添加facebook gradle依赖关系时,它显示了gradle中的错误 - When I add facebook gradle dependency it shows me error in gradle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM