| 14792 |
manas |
1 |
/**
|
|
|
2 |
* Copyright 2010-present Facebook.
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
package com.facebook.internal;
|
|
|
18 |
|
|
|
19 |
import android.content.Context;
|
|
|
20 |
import android.graphics.Typeface;
|
|
|
21 |
import android.util.TypedValue;
|
|
|
22 |
import android.view.Gravity;
|
|
|
23 |
import android.widget.Button;
|
|
|
24 |
import com.facebook.android.R;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* com.facebook.internal is solely for the use of other packages within the Facebook SDK for Android. Use of
|
|
|
28 |
* any of the classes in this package is unsupported, and they may be modified or removed without warning at
|
|
|
29 |
* any time.
|
|
|
30 |
*/
|
|
|
31 |
public class LikeButton extends Button {
|
|
|
32 |
|
|
|
33 |
private boolean isLiked;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Create the LikeButton .
|
|
|
37 |
*
|
|
|
38 |
* @see android.view.View#View(android.content.Context)
|
|
|
39 |
*/
|
|
|
40 |
public LikeButton(Context context, boolean isLiked) {
|
|
|
41 |
super(context);
|
|
|
42 |
|
|
|
43 |
this.isLiked = isLiked;
|
|
|
44 |
|
|
|
45 |
initialize();
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public void setLikeState(boolean isLiked) {
|
|
|
49 |
if (isLiked != this.isLiked) {
|
|
|
50 |
this.isLiked = isLiked;
|
|
|
51 |
updateForLikeStatus();
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
private void initialize() {
|
|
|
56 |
// apparently there's no method of setting a default style in xml,
|
|
|
57 |
// so in case the users do not explicitly specify a style, we need
|
|
|
58 |
// to use sensible defaults.
|
|
|
59 |
this.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
60 |
this.setTextColor(getResources().getColor(R.color.com_facebook_likebutton_text_color));
|
|
|
61 |
this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
|
|
|
62 |
getResources().getDimension(R.dimen.com_facebook_likebutton_text_size));
|
|
|
63 |
this.setTypeface(Typeface.DEFAULT_BOLD);
|
|
|
64 |
|
|
|
65 |
this.setCompoundDrawablePadding(
|
|
|
66 |
getResources().getDimensionPixelSize(R.dimen.com_facebook_likebutton_compound_drawable_padding));
|
|
|
67 |
this.setPadding(
|
|
|
68 |
getResources().getDimensionPixelSize(R.dimen.com_facebook_likebutton_padding_left),
|
|
|
69 |
getResources().getDimensionPixelSize(R.dimen.com_facebook_likebutton_padding_top),
|
|
|
70 |
getResources().getDimensionPixelSize(R.dimen.com_facebook_likebutton_padding_right),
|
|
|
71 |
getResources().getDimensionPixelSize(R.dimen.com_facebook_likebutton_padding_bottom));
|
|
|
72 |
|
|
|
73 |
updateForLikeStatus();
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
private void updateForLikeStatus() {
|
|
|
77 |
if (isLiked) {
|
|
|
78 |
this.setBackgroundResource(R.drawable.com_facebook_button_like_selected);
|
|
|
79 |
this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_button_like_icon_selected, 0, 0, 0);
|
|
|
80 |
this.setText(getResources().getString(R.string.com_facebook_like_button_liked));
|
|
|
81 |
} else {
|
|
|
82 |
this.setBackgroundResource(R.drawable.com_facebook_button_like);
|
|
|
83 |
this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.com_facebook_button_like_icon, 0, 0, 0);
|
|
|
84 |
this.setText(getResources().getString(R.string.com_facebook_like_button_not_liked));
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
}
|