How can I add a TextView to a specific page in Harism CurlView library?

1

I am creating an app. For this, I am using Harsim CurlView library from Github. There is the only image on every page but I want to add a TextView in each specific page. The full code is written in Java for the image. Nither code is written in XML for the image. I am a beginner. Please help me to add a TextView.

the Link to the Harish CurlView library:- https://github.com/harism/android-pagecurl

The XML code For CurlView library:- https://github.com/harism/android-pagecurl/blob/master/res/layout/main.xml

The curl_activity java file:-

private CurlView mCurlView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    int index = 0;
    if (getLastNonConfigurationInstance() != null) {
        index = (Integer) getLastNonConfigurationInstance();
    }
    mCurlView = (CurlView) findViewById(R.id.curl);
    mCurlView.setBitmapProvider(new BitmapProvider());
    mCurlView.setSizeChangedObserver(new SizeChangedObserver());
    mCurlView.setCurrentIndex(index);
    mCurlView.setBackgroundColor(0xFF202830);

    // This is something somewhat experimental. Before uncommenting next
    // line, please see method comments in CurlView.
    mCurlView.setEnableTouchPressure(true);

    // CAGS: This is to allow 2 pages landscape mode, set to false for legacy mode
    mCurlView.set2PagesLandscape(true);
}

@Override
public void onPause() {
    super.onPause();
    mCurlView.onPause();
}

@Override
public void onResume() {
    super.onResume();
    mCurlView.onResume();
}

@Override
public Object onRetainNonConfigurationInstance() {
    return mCurlView.getCurrentIndex();
}

/**
 * Bitmap provider.
 */
private class BitmapProvider implements CurlView.BitmapProvider {

    private int[] mBitmapIds = { R.drawable.obama, R.drawable.road_rage, R.drawable.taipei_101, R.drawable.world, R.drawable.color1, R.drawable.logo, R.drawable.man2 };
    private String[] mvalues = {"Harsh", "Ishwar", "Sanju", "Amit"};

    @Override
    public Bitmap getBitmap(int width, int height, int index) {
        Bitmap b = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);
        b.eraseColor(0xFFFFFFFF);
        Canvas c = new Canvas(b);
        Drawable d = getResources().getDrawable(mBitmapIds[index]);


        int margin = 7;
        int border = 3;
        Rect r = new Rect(margin, margin, width - margin, height - margin);

        int imageWidth = r.width() - (border * 2);
        int imageHeight = imageWidth * d.getIntrinsicHeight()
                / d.getIntrinsicWidth();
        if (imageHeight > r.height() - (border * 2)) {
            imageHeight = r.height() - (border * 2);
            imageWidth = imageHeight * d.getIntrinsicWidth()
                    / d.getIntrinsicHeight();
        }

        r.left += ((r.width() - imageWidth) ) - border;
        r.right = r.left + imageWidth + border + border;
        r.top += ((r.height() - imageHeight)) - border;
        r.bottom = r.top + imageHeight + border + border;

        Paint p = new Paint();
        p.setColor(0xFFC0C0C0);
        c.drawRect(r, p);
        r.left += border;
        r.right -= border;
        r.top += border;
        r.bottom -= border;

        d.setBounds(r);
        d.draw(c);
        return b;
    }

    @Override
    public int getBitmapCount() {
        return mBitmapIds.length;
    }
}

/**
 * CurlView size changed observer.
 */
private class SizeChangedObserver implements CurlView.SizeChangedObserver {
    @Override
    public void onSizeChanged(int w, int h) {
        if (h > w) {
            mCurlView.setViewMode(CurlView.SHOW_ONE_PAGE);
            mCurlView.setMargins(.01f, .01f, .01f, .01f);
        }
    }
}
java
android
xml
asked on Stack Overflow Jun 19, 2019 by Harsh0021

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0