Skip to content

Commit

Permalink
Merge pull request #2 from eveliotc/fix-ripples
Browse files Browse the repository at this point in the history
Fix ripples hotspot and some refactoring
  • Loading branch information
Musenkishi committed Feb 3, 2015
2 parents d567bf6 + 2dda973 commit f0fc47f
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 196 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright (C) 2014 Evelio Tarazona Caceres
* Copyright (C) 2014 Freddie (Musenkishi) Lust-Hed
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 com.musenkishi.wally.views;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.musenkishi.wally.R;

import static android.os.Build.VERSION_CODES.LOLLIPOP;

/**
* {@link android.widget.LinearLayout} but with foreground/overlay drawable capability
*/
public class OverlayLinearLayout extends LinearLayout {
private Drawable mOverlayDrawable;

public OverlayLinearLayout(Context context) {
super(context);
initSelf(context, null, 0, 0);
}

public OverlayLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
initSelf(context, attrs, 0, 0);
}

public OverlayLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initSelf(context, attrs, defStyleAttr, 0);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public OverlayLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initSelf(context, attrs, defStyleAttr, defStyleRes);
}

private void initSelf(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
if (attrs != null) {
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.OverlayLinearLayout);
setOverlayDrawable(a.getDrawable(R.styleable.OverlayLinearLayout_overlay));
a.recycle();
}
}

@Override
public void draw(Canvas canvas) {
super.draw(canvas);

if (mOverlayDrawable != null) {
mOverlayDrawable.draw(canvas);
}
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);

if (mOverlayDrawable != null) {
mOverlayDrawable.setBounds(0, 0, w, h);
}
}

@Override
protected void drawableStateChanged() {
super.drawableStateChanged();

Drawable d = mOverlayDrawable;
if (d != null && d.isStateful()) {
d.setState(getDrawableState());
}
}

@Override
protected boolean verifyDrawable(Drawable who) {
return super.verifyDrawable(who) || (who == mOverlayDrawable);
}

@Override
public void jumpDrawablesToCurrentState() {
super.jumpDrawablesToCurrentState();
if (mOverlayDrawable != null) {
mOverlayDrawable.jumpToCurrentState();
}
}

@Override
@TargetApi(LOLLIPOP)
public void drawableHotspotChanged(float x, float y) {
super.drawableHotspotChanged(x, y);
if (mOverlayDrawable != null) {
mOverlayDrawable.setHotspot(x, y);
}
}

private void setOverlayDrawable(Drawable overlayDrawable) {
if (mOverlayDrawable != null) {
mOverlayDrawable.setCallback(null);
unscheduleDrawable(mOverlayDrawable);
}
mOverlayDrawable = overlayDrawable;
if (mOverlayDrawable != null) {
setWillNotDraw(false);
mOverlayDrawable.setCallback(this);
if (mOverlayDrawable.isStateful()) {
mOverlayDrawable.setState(getDrawableState());
}
} else {
setWillNotDraw(true);
}
}

}
77 changes: 0 additions & 77 deletions wally/src/main/res/layout-v21/view_cell_thumb_tile.xml

This file was deleted.

47 changes: 0 additions & 47 deletions wally/src/main/res/layout-v21/view_cell_thumb_tile_saved.xml

This file was deleted.

91 changes: 42 additions & 49 deletions wally/src/main/res/layout/view_cell_thumb_tile.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2014 Freddie (Musenkishi) Lust-Hed
~ Copyright (C) 2014 Evelio Tarazona Caceres
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -15,62 +16,54 @@
~ limitations under the License.
-->

<RelativeLayout
<com.musenkishi.wally.views.OverlayLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:auto="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:layout_height="@dimen/thumb_cell_height"
android:padding="2dp">
android:padding="2dp"
android:background="@color/Thumb.Background"
auto:overlay="@drawable/default_selector"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">

<FrameLayout
android:layout_height="match_parent"
<ImageView
android:id="@+id/thumb_image_view"
android:layout_width="match_parent"
android:foreground="@drawable/default_selector">

<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/Thumb.Background"
android:orientation="vertical">
android:layout_height="0dp"
android:layout_weight="2"
android:scaleType="centerCrop" />

<ImageView
android:id="@+id/thumb_image_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:scaleType="centerCrop" />

<RelativeLayout
android:id="@+id/thumb_bottom_view"
android:layout_width="match_parent"
android:layout_height="@dimen/default_height"
android:gravity="center_vertical"
android:animateLayoutChanges="true">
<RelativeLayout
android:id="@+id/thumb_bottom_view"
android:layout_width="match_parent"
android:layout_height="@dimen/default_height"
android:gravity="center_vertical"
android:animateLayoutChanges="true">

<TextView
android:id="@+id/thumb_text_resolution"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="@dimen/default_gap"
android:paddingRight="@dimen/default_gap"
android:fontFamily="sans-serif"
android:textColor="@color/Thumb.Text"
android:textSize="14sp"
/>
<TextView
android:id="@+id/thumb_text_resolution"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="@dimen/default_gap"
android:paddingRight="@dimen/default_gap"
android:fontFamily="sans-serif"
android:textColor="@color/Thumb.Text"
android:textSize="14sp"
/>

<ImageButton
android:id="@+id/thumb_button_heart"
android:layout_width="@dimen/default_press_size"
android:layout_height="@dimen/default_press_size"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:scaleType="centerInside"
android:src="@drawable/ic_action_heart_empty"
android:background="@drawable/default_selector" />
<ImageButton
android:id="@+id/thumb_button_heart"
android:layout_width="@dimen/default_press_size"
android:layout_height="@dimen/default_press_size"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:scaleType="centerInside"
android:src="@drawable/ic_action_heart_empty"
android:background="?heartBackground"
/>

</RelativeLayout>
</RelativeLayout>

</LinearLayout>
</FrameLayout>
</RelativeLayout>
</com.musenkishi.wally.views.OverlayLinearLayout>

0 comments on commit f0fc47f

Please sign in to comment.