Skip to content

Commit

Permalink
add card view module
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Sharat committed Mar 1, 2017
1 parent 83a0b96 commit 26a0e4b
Show file tree
Hide file tree
Showing 12 changed files with 428 additions and 4 deletions.
1 change: 1 addition & 0 deletions cardview-v7/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
78 changes: 78 additions & 0 deletions cardview-v7/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Apache License
* Version 2.0, January 2004
* http://www.apache.org/licenses/LICENSE-2.0
*
* TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
*
* Copyright (c) 2017 Flipkart Internet Pvt. Ltd.
*
* 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.
*/

apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

afterEvaluate {
javadoc.classpath += files(android.libraryVariants.collect { variant ->
variant.javaCompile.classpath.files
})
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives javadocJar
archives sourcesJar
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:cardview-v7:25.1.0'
compile project(path: ':proteus-core')
}
33 changes: 33 additions & 0 deletions cardview-v7/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/aditya.sharat/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-dontobfuscate
-printmapping out.map
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated

# Preserve all annotations.

-keepattributes *Annotation*

# Preserve all public classes, and their public and protected fields and
# methods.

-keep public class * {
public protected *;
}
20 changes: 20 additions & 0 deletions cardview-v7/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
~ Apache License
~ Version 2.0, January 2004
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
~
~ Copyright (c) 2017 Flipkart Internet Pvt. Ltd.
~
~ 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.
-->

<manifest package="com.flipkart.android.proteus.support.v7"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Apache License
* Version 2.0, January 2004
* http://www.apache.org/licenses/LICENSE-2.0
*
* TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
*
* Copyright (c) 2017 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.support.v7;

import com.flipkart.android.proteus.ProteusBuilder;
import com.flipkart.android.proteus.support.v7.widget.CardViewParser;

/**
* CardViewCollection
*
* @author adityasharat
*/

public class CardViewCollection implements ProteusBuilder.Collection {

private CardViewCollection() {
}

public static CardViewCollection create() {
return new CardViewCollection();
}

@Override
public void registerWith(ProteusBuilder builder) {
builder.register(new CardViewParser());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Apache License
* Version 2.0, January 2004
* http://www.apache.org/licenses/LICENSE-2.0
*
* TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
*
* Copyright (c) 2017 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.support.v7.widget;

import android.content.res.ColorStateList;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.view.ViewGroup;

import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.processor.BooleanAttributeProcessor;
import com.flipkart.android.proteus.processor.ColorResourceProcessor;
import com.flipkart.android.proteus.processor.DimensionAttributeProcessor;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;

/**
* CardViewParser
*
* @author adityasharat
*/

public class CardViewParser<T extends CardView> extends ViewTypeParser<T> {

@NonNull
@Override
public String getType() {
return "CardView";
}

@Nullable
@Override
public String getParentType() {
return "FrameLayout";
}

@NonNull
@Override
public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) {
return new ProteusCardView(context);
}

@Override
protected void addAttributeProcessors() {

addAttributeProcessor("cardBackgroundColor", new ColorResourceProcessor<T>() {
@Override
public void setColor(T view, int color) {
view.setCardBackgroundColor(color);
}

@Override
public void setColor(T view, ColorStateList colors) {
view.setCardBackgroundColor(colors);
}
});

addAttributeProcessor("cardCornerRadius", new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
view.setRadius(dimension);
}
});

addAttributeProcessor("cardElevation", new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
view.setCardElevation(dimension);
}
});

addAttributeProcessor("cardMaxElevation", new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
view.setMaxCardElevation(dimension);
}
});

addAttributeProcessor("cardPreventCornerOverlap", new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
view.setPreventCornerOverlap(value);
}
});

addAttributeProcessor("cardUseCompatPadding", new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
view.setUseCompatPadding(value);
}
});

addAttributeProcessor("contentPadding", new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
view.setContentPadding((int) dimension, (int) dimension, (int) dimension, (int) dimension);
}
});

addAttributeProcessor("contentPaddingBottom", new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
int t = view.getContentPaddingTop();
int r = view.getContentPaddingRight();
int l = view.getContentPaddingLeft();

view.setContentPadding(l, t, r, (int) dimension);
}
});

addAttributeProcessor("contentPaddingLeft", new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
int t = view.getContentPaddingTop();
int r = view.getContentPaddingRight();
int b = view.getContentPaddingBottom();

view.setContentPadding((int) dimension, t, r, b);
}
});

addAttributeProcessor("contentPaddingRight", new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
int t = view.getContentPaddingTop();
int b = view.getContentPaddingBottom();
int l = view.getContentPaddingLeft();

view.setContentPadding(l, t, (int) dimension, b);
}
});

addAttributeProcessor("contentPaddingTop", new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
int r = view.getContentPaddingRight();
int b = view.getContentPaddingBottom();
int l = view.getContentPaddingLeft();

view.setContentPadding(l, (int) dimension, r, b);
}
});

}
}
Loading

0 comments on commit 26a0e4b

Please sign in to comment.