mobile/android/base/widget/Divider.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/widget/Divider.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,39 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +package org.mozilla.gecko.widget;
     1.9 +
    1.10 +import android.content.Context;
    1.11 +import android.util.AttributeSet;
    1.12 +import android.view.View;
    1.13 +import android.widget.LinearLayout.LayoutParams;
    1.14 +
    1.15 +public class Divider extends View {
    1.16 +    public static enum Orientation { HORIZONTAL, VERTICAL };
    1.17 +
    1.18 +    // Orientation of the divider.
    1.19 +    private Orientation mOrientation;
    1.20 +
    1.21 +    // Density of the device.
    1.22 +    private int mDensity;
    1.23 +
    1.24 +    public Divider(Context context, AttributeSet attrs) {
    1.25 +        super(context, attrs);
    1.26 +
    1.27 +        mDensity = (int) context.getResources().getDisplayMetrics().density;
    1.28 +
    1.29 +        setOrientation(Orientation.HORIZONTAL);
    1.30 +    }
    1.31 +
    1.32 +    public void setOrientation(Orientation orientation) {
    1.33 +        if (mOrientation != orientation) {
    1.34 +            mOrientation = orientation;
    1.35 +
    1.36 +            if (mOrientation == Orientation.HORIZONTAL)
    1.37 +                setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, mDensity));
    1.38 +            else
    1.39 +                setLayoutParams(new LayoutParams(mDensity, LayoutParams.FILL_PARENT));
    1.40 +        }
    1.41 +    }
    1.42 +}

mercurial