Skip to content

Commit

Permalink
Finalize work on checkbox in multichoice
Browse files Browse the repository at this point in the history
Many thanks to @acappelli for his contribution and
@andyxialm for his wonderful checkbox library.

Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Dec 8, 2016
1 parent 9e48133 commit b7b4bd9
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 48 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ task checkstyle(type: Checkstyle){
'**/KeyboardAwareRelativeLayout.java', '**/FrameLayoutFixed.java',
'**/AbsListViewScrollDetector.java', '**/NoCacheMiniDnsResolver.java',
'**/XMPPTCPConnection.java',
'main/java/com/**', 'main/java/io/**'
'main/java/com/**', 'main/java/io/**', 'main/java/cn/**'
def configProps = ['baseDir': projectDir.absolutePath]
configProperties configProps
classpath = files()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package org.kontalk.ui.view;
/**
* * Copyright 2016 andy
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cn.refactor.library;

import android.annotation.TargetApi;
import android.content.Context;
Expand All @@ -19,7 +35,16 @@
import com.nineoldandroids.animation.ValueAnimator;

import org.kontalk.R;
import org.kontalk.util.SystemUtils;


/**
* Author : andy
* Date : 16/1/21 11:28
* Email : [email protected]
* Github : github.com/andyxialm
* Description : A custom CheckBox with animation for Android
*/


public class SmoothCheckBox extends View implements Checkable {
private static final String KEY_INSTANCE_STATE = "InstanceState";
Expand Down Expand Up @@ -74,7 +99,7 @@ private void init(AttributeSet attrs) {
mFloorColor = ta.getColor(R.styleable.SmoothCheckBox_color_unchecked_stroke, COLOR_FLOOR_UNCHECKED);
mCheckedColor = ta.getColor(R.styleable.SmoothCheckBox_color_checked, COLOR_CHECKED);
mUnCheckedColor = ta.getColor(R.styleable.SmoothCheckBox_color_unchecked, COLOR_UNCHECKED);
mStrokeWidth = ta.getDimensionPixelSize(R.styleable.SmoothCheckBox_stroke_width, SystemUtils.dp2px(getContext(), 0));
mStrokeWidth = ta.getDimensionPixelSize(R.styleable.SmoothCheckBox_stroke_width, 0);

ta.recycle();

Expand All @@ -98,20 +123,6 @@ private void init(AttributeSet attrs) {
mTickPoints[0] = new Point();
mTickPoints[1] = new Point();
mTickPoints[2] = new Point();

/*setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
toggle();
mTickDrawing = false;
mDrewDistance = 0;
if (isChecked()) {
startCheckedAnimation();
} else {
startUnCheckedAnimation();
}
}
});*/
}

@Override
Expand Down Expand Up @@ -188,7 +199,7 @@ private void reset() {
}

private int measureSize(int measureSpec) {
int defSize = SystemUtils.dp2px(getContext(), DEF_DRAW_SIZE);
int defSize = dp2px(getContext(), DEF_DRAW_SIZE);
int specSize = MeasureSpec.getSize(measureSpec);
int specMode = MeasureSpec.getMode(measureSpec);

Expand All @@ -205,6 +216,11 @@ private int measureSize(int measureSpec) {
return result;
}

private static int dp2px(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/kontalk/data/Contact.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void setLastSeen(long lastSeen) {
private static Drawable generateRandomAvatar(Context context, Contact contact) {
String letter = (contact.mName != null && contact.mName.length() > 0) ?
contact.mName : contact.mJID;
int size = context.getResources().getDimensionPixelSize(R.dimen.avatar_container);
int size = context.getResources().getDimensionPixelSize(R.dimen.avatar_size);

return TextDrawable.builder()
.beginConfig()
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/org/kontalk/ui/view/ContactsListItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import android.widget.ImageView;
import android.widget.TextView;

import cn.refactor.library.SmoothCheckBox;


public class ContactsListItem extends AvatarListItem implements Checkable {

Expand Down Expand Up @@ -155,7 +157,7 @@ public boolean isChecked() {
public void setChecked(boolean checked) {
if (checked != mChecked) {
mChecked = checked;
mCheckbox.setChecked(checked, true);
mCheckbox.setChecked(checked, !SystemUtils.isLegacySystem());
refreshDrawableState();
}
}
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/java/org/kontalk/util/SystemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public static String getVersionFullName(Context context) {
BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE);
}

/**
* Returns true if on Gingerbread or earlier.
* We need this to disable some fancy animations or graphics which would be
* too difficult to make them work on these Android versions. Besides, even
* Google doesn't want to support them anymore.
*/
public static boolean isLegacySystem() {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB;
}

@SuppressWarnings("deprecation")
public static Point getDisplaySize(Context context) {
Point displaySize = null;
Expand Down Expand Up @@ -415,9 +425,4 @@ public static int getThemedResource(Context context, @AttrRes int attrResId) {
return value.resourceId;
}

public static int dp2px(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}

}
38 changes: 20 additions & 18 deletions app/src/main/res/layout/contacts_list_item.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!-- Kontalk Android client
<?xml version="1.0" encoding="utf-8"?>
<!-- Kontalk Android client
Copyright (C) 2016 Kontalk Devteam <[email protected]>
This program is free software: you can redistribute it and/or modify
Expand All @@ -15,14 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<org.kontalk.ui.view.ContactsListItem xmlns:android="http://schemas.android.com/apk/res/android"
<org.kontalk.ui.view.ContactsListItem
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:minHeight="@dimen/avatar_list_item_height"
android:paddingEnd="?attr/listPreferredItemPaddingRight"
android:paddingRight="?attr/listPreferredItemPaddingRight">
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:paddingEnd="?attr/listPreferredItemPaddingRight">

<FrameLayout
android:id="@+id/header_container"
Expand All @@ -36,25 +37,26 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/header_container"
android:minHeight="@dimen/avatar_list_item_height"
android:layout_toRightOf="@+id/header_container"
android:minHeight="@dimen/avatar_list_item_height">
android:layout_toEndOf="@+id/header_container">

<RelativeLayout
android:id="@+id/container_avatar"
android:id="@+id/avatar_container"
style="@style/AvatarListItemStyle">

<org.kontalk.ui.view.CircleContactBadge
android:id="@+id/avatar"
android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size" />

<org.kontalk.ui.view.SmoothCheckBox
<cn.refactor.library.SmoothCheckBox
android:id="@+id/checkbox"
android:layout_width="@dimen/checkbox_size"
android:layout_height="@dimen/checkbox_size"
android:layout_width="@dimen/avatar_checkbox_size"
android:layout_height="@dimen/avatar_checkbox_size"
android:layout_alignBottom="@+id/avatar"
android:layout_alignRight="@+id/avatar"
android:layout_alignEnd="@+id/avatar"
app:color_checked="@color/app_primary_dark"
app:color_unchecked="@android:color/transparent"
app:color_unchecked_stroke="@android:color/transparent" />
Expand All @@ -68,23 +70,23 @@
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toEndOf="@id/container_avatar"
android:layout_toRightOf="@id/container_avatar"
android:layout_toEndOf="@id/avatar_container"
android:layout_toRightOf="@id/avatar_container"
android:ellipsize="marquee"
android:maxLines="1" />
android:maxLines="1"/>

<TextView
android:id="@android:id/text2"
style="@style/AvatarListItemSubtitleStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:paddingBottom="16dp"
android:layout_below="@android:id/text1"
android:layout_toEndOf="@id/container_avatar"
android:layout_toRightOf="@id/container_avatar"
android:ellipsize="end"
android:layout_toEndOf="@id/avatar_container"
android:layout_toRightOf="@id/avatar_container"
android:maxLines="2"
android:paddingBottom="16dp" />
android:ellipsize="end"/>
</RelativeLayout>

</org.kontalk.ui.view.ContactsListItem>
3 changes: 1 addition & 2 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
<dimen name="emoji_edittext_size">22sp</dimen>
<dimen name="emoji_listitem_size">18sp</dimen>

<dimen name="avatar_container">40dp</dimen>
<dimen name="avatar_size">40dp</dimen>
<dimen name="checkbox_size">16dp</dimen>
<dimen name="avatar_checkbox_size">16dp</dimen>

<dimen name="msg_status_size">16dp</dimen>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
</style>

<style name="AvatarListItemStyle">
<item name="android:layout_width">@dimen/avatar_container</item>
<item name="android:layout_height">@dimen/avatar_container</item>
<item name="android:layout_width">@dimen/avatar_size</item>
<item name="android:layout_height">@dimen/avatar_size</item>
<item name="android:layout_marginLeft">16dp</item>
<item name="android:layout_marginRight">16dp</item>
<item name="android:layout_marginTop">16dp</item>
Expand Down

0 comments on commit b7b4bd9

Please sign in to comment.