Android LoginButton Facebook no action size height

90 views Asked by At

I have use button facebook, but when set size height, it is no success. Can you help me. It my code :

<com.facebook.login.widget.LoginButton
                android:id="@+id/btn_login_facebook"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="10dp"
             android:layout_marginTop="20sp"/>
1

There are 1 answers

0
Shoeb Siddique On

You can setPadding for your facebook Like box.

FacebookLikeBox.class

package com.example.facebook;

import com.example.facebook.FacebookLinkStatProcessor.Result;
import com.example.fblike.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.Button;



public class FacebookLikeBox extends Button {
    private static final String LOG_TAG = FacebookLikeBox.class.getSimpleName();
    private static final Looper BACKGROUND;

    static {
        HandlerThread thread = new HandlerThread(FacebookLikeBox.class.getSimpleName(), Process.THREAD_PRIORITY_LOWEST);
        thread.start();
        BACKGROUND = thread.getLooper();
    }

    private Handler mHandler;
    private FacebookLinkStatProcessor mProcessor;
    private String mUrl;
    private boolean mAttachedToWindow;

    private CalloutPath mPath;
    private ShapeDrawable mFill;
    private ShapeDrawable mStroke;
    private float mCornerRadius;
    private int mCalloutMarker;

    public void setProcessor(FacebookLinkStatProcessor processor) {
        mProcessor = processor;
    }

    public void setPageUrl(String url) {
        String old = mUrl;
        mUrl = url;

        if (old == null && url != null || old != null && !old.equals(url)) {
            onUrlChanged(old, url);
        }
    }

    @SuppressLint("NewApi")
    @Override
    public boolean isAttachedToWindow() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            return mAttachedToWindow;
        } else {
            return super.isAttachedToWindow();
        }
    }

    public FacebookLikeBox(Context context) {
        super(context);
        init(null);
    }

    public FacebookLikeBox(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }

    public FacebookLikeBox(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(attrs);
    }

    private void init(AttributeSet attrs) {
        mProcessor = new FacebookLinkStatProcessor();

        mHandler = new Handler(BACKGROUND, new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                processUrl((String) msg.obj);
                return true;
            }
        });

        if (attrs == null) {
            return;
        }

        Context c = getContext();
        if (c == null) {
            return;
        }

        TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.FacebookLikeBox);
        if (a == null) {
            return;
        }

        Resources r = getResources();
        if (r == null) {
            return;
        }

        try {
            mPath = new CalloutPath();
            mFill = new ShapeDrawable();
            mFill.getPaint().setStyle(Paint.Style.FILL);
            mFill.getPaint().setColor(a.getColor(R.styleable.FacebookLikeBox_boxFillColor, r.getColor(R.color.com_shamanland_facebook_like_box_background_color)));
            mStroke = new ShapeDrawable();
            mStroke.getPaint().setStyle(Paint.Style.STROKE);
            mStroke.getPaint().setColor(a.getColor(R.styleable.FacebookLikeBox_boxStrokeColor, r.getColor(R.color.com_shamanland_facebook_like_box_text_color)));
            mStroke.getPaint().setAntiAlias(true);
            mStroke.getPaint().setStrokeWidth(a.getDimension(R.styleable.FacebookLikeBox_boxStrokeWidth, r.getDimension(R.dimen.com_shamanland_facebook_like_box_stroke_width)));
            mCornerRadius = a.getDimension(R.styleable.FacebookLikeBox_boxCornersRadius, r.getDimension(R.dimen.com_shamanland_facebook_like_corners_radius));
            mCalloutMarker = a.getInt(R.styleable.FacebookLikeBox_calloutMarker, 0);

            initBackground();
        } finally {
            a.recycle();
        }
    }

    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    private void initBackground() {

        Drawable drawable = new LayerDrawable(new Drawable[]{mFill, mStroke});
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            setBackgroundDrawable(drawable);
        } else {
            setBackground(drawable);
        }


        setPadding(5, 5, 5, 5); // you can do your padding.
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        mAttachedToWindow = true;
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mAttachedToWindow = false;
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldW, int oldH) {
        mPath.build(mCalloutMarker, w, h, mStroke.getPaint().getStrokeWidth(), mCornerRadius);
        PathShape shape = new PathShape(mPath, w, h);
        mFill.setShape(shape);
        mStroke.setShape(shape);
    }

    protected void onUrlChanged(String oldValue, String newValue) {
        setText(R.string.com_shamanland_facebook_like_box_text_default);

        if (oldValue != null) {
            mHandler.removeMessages(0, oldValue);
        }

        if (newValue != null) {
            Message msg = Message.obtain();
            if (msg != null) {
                msg.obj = newValue;
                mHandler.sendMessage(msg);
            }
        }
    }

    /**
     * Background thread
     */
     protected void processUrl(final String url) {
        try {
            final Result result = mProcessor.processUrl(url);
            post(new Runnable() {
                @SuppressLint("NewApi")
                @Override
                public void run() {
                    if (isAttachedToWindow()) {
                        postProcessUrl(url, result);
                    }
                }
            });
        } catch (Throwable ex) {
            ex.printStackTrace();
            /*if (LOGGING) {
                Log.wtf(LOG_TAG, ex);
            }*/
        }
     }

     protected void postProcessUrl(String url, Result result) {
         if (url.equals(mUrl)) {
             onUrlProcessed(result);
         }
     }

     protected void onUrlProcessed(Result result) {
         setText(prettyNumber(result.shares));
     }

     protected String prettyNumber(long number) {
         if (number > 1000000000L) {
             return number / 1000000000L + "." + (number % 1000000000L) / 100000000L + "b";
         } else if (number > 1000000L) {
             return number / 1000000L + "." + (number % 1000000L) / 100000L + "m";
         } else if (number > 1000L) {
             return number / 1000L + "." + (number % 1000L) / 100L + "k";
         } else {
             return String.valueOf(number);
         }
     }
}