summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/animation/ViewHelper.java
blob: 3ea2e84373283a92883ef68f31fa468beb70ca9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko.animation;

import android.view.View;
import android.view.ViewGroup;

public final class ViewHelper {
    private ViewHelper() {
    }

    public static float getTranslationX(View view) {
        if (view != null) {
            return view.getTranslationX();
        }

        return 0;
    }

    public static void setTranslationX(View view, float translationX) {
        if (view != null) {
            view.setTranslationX(translationX);
        }
    }

    public static float getTranslationY(View view) {
        if (view != null) {
            return view.getTranslationY();
        }

        return 0;
    }

    public static void setTranslationY(View view, float translationY) {
        if (view != null) {
            view.setTranslationY(translationY);
        }
    }

    public static float getAlpha(View view) {
        if (view != null) {
            return view.getAlpha();
        }

        return 1;
    }

    public static void setAlpha(View view, float alpha) {
        if (view != null) {
            view.setAlpha(alpha);
        }
    }

    public static int getWidth(View view) {
        if (view != null) {
            return view.getWidth();
        }

        return 0;
    }

    public static void setWidth(View view, int width) {
        if (view != null) {
            ViewGroup.LayoutParams lp = view.getLayoutParams();
            lp.width = width;
            view.setLayoutParams(lp);
        }
    }

    public static int getHeight(View view) {
        if (view != null) {
            return view.getHeight();
        }

        return 0;
    }

    public static void setHeight(View view, int height) {
        if (view != null) {
            ViewGroup.LayoutParams lp = view.getLayoutParams();
            lp.height = height;
            view.setLayoutParams(lp);
        }
    }

    public static int getScrollX(View view) {
        if (view != null) {
            return view.getScrollX();
        }

        return 0;
    }

    public static int getScrollY(View view) {
        if (view != null) {
            return view.getScrollY();
        }

        return 0;
    }

    public static void scrollTo(View view, int scrollX, int scrollY) {
        if (view != null) {
            view.scrollTo(scrollX, scrollY);
        }
    }
}