Repository: ihsanbal/Wiv
Branch: master
Commit: 52c119c81393
Files: 31
Total size: 40.0 KB
Directory structure:
gitextract_4_q_5bw6/
├── .gitignore
├── LICENSE
├── README.md
├── app/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── ihsanbal/
│ │ └── com/
│ │ └── wiv/
│ │ └── MainActivity.java
│ └── res/
│ ├── layout/
│ │ └── activity_main.xml
│ ├── menu/
│ │ └── menu_main.xml
│ └── values/
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── circle.yml
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── library/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── com/
│ │ └── ihsanbal/
│ │ └── wiv/
│ │ ├── AspectRatioLayout.java
│ │ ├── MediaView.java
│ │ └── OverlayImageView.java
│ └── res/
│ └── values/
│ ├── attrs.xml
│ └── strings.xml
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.iml
.gradle
/local.properties
.DS_Store
/captures
.externalNativeBuild
!gradle-wrapper.jar
# Generated files
bin/
gen/
out/
# Gradle files
build/
# Local configuration file (sdk path, etc)
/.idea/
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2017 ihsan BAL
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
Wiv
--------
[](https://circleci.com/gh/ihsanbal/Wiv/tree/master)

Library of [Tweet-ui](https://docs.fabric.io/android/twitter/tweet-ui.html) TweetMediaView component.
Usage
--------
```java
MediaView mediaView;
ArrayList medias;
//medias.add("http://datalook.io/app/uploads/NY.jpg");
mediaView.setOnMediaClickListener(new MediaView.OnMediaClickListener() {
@Override
public void onMediaClick(View view, int index) {
Snackbar.make(view, "onClickIndex :" + index, Snackbar.LENGTH_LONG).show();
}
});
mediaView.setMedias(medias);
```
```xml
```
Download
--------
Gradle:
```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.ihsanbal:Wiv:1.0.0'
}
```
Maven:
```xml
jitpack.io
https://jitpack.io
com.github.ihsanbal
Wiv
1.0.0
```
Screenshots
--------
================================================
FILE: app/.gitignore
================================================
/build
================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
//noinspection GradleDependency
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "ihsanbal.com.wiv"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
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.3.1'
compile 'com.android.support:design:25.3.1'
// compile project(':library')
compile 'com.github.ihsanbal:Wiv:1.0.0'
testCompile 'junit:junit:4.12'
}
================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/ihsan/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 *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: app/src/main/AndroidManifest.xml
================================================
================================================
FILE: app/src/main/java/ihsanbal/com/wiv/MainActivity.java
================================================
package ihsanbal.com.wiv;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import com.ihsanbal.wiv.MediaView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private ArrayList medias = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
MediaView mediaView = (MediaView) findViewById(R.id.media_view);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
medias.add("http://datalook.io/app/uploads/NY.jpg");
medias.add("https://wallpaperbrowse.com/media/images/High-Definition-Ultra-HD-Wallpaper.jpg");
medias.add("https://static.pexels.com/photos/17679/pexels-photo.jpg");
mediaView.setOnMediaClickListener(new MediaView.OnMediaClickListener() {
@Override
public void onMediaClick(View view, int index) {
Snackbar.make(view, "onClickIndex :" + index, Snackbar.LENGTH_LONG).show();
}
});
mediaView.setMedias(medias);
}
}
================================================
FILE: app/src/main/res/layout/activity_main.xml
================================================
================================================
FILE: app/src/main/res/menu/menu_main.xml
================================================
================================================
FILE: app/src/main/res/values/colors.xml
================================================
#3F51B5
#303F9F
#FF4081
================================================
FILE: app/src/main/res/values/dimens.xml
================================================
16dp
================================================
FILE: app/src/main/res/values/strings.xml
================================================
Wiv
Settings
================================================
FILE: app/src/main/res/values/styles.xml
================================================
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'https://jitpack.io' }
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: circle.yml
================================================
machine:
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
java:
version: oraclejdk8
dependencies:
pre:
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,build-tools-25.0.1,android-25,extra-google-m2repository,extra-google-google_play_services,extra-android-support,extra-android-m2repository
override:
- ./gradlew dependencies --daemon
test:
override:
- ./gradlew test
deployment:
testing:
branch: [development, master]
commands:
- ./gradlew assembleRelease
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Wed May 31 11:42:20 EEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: library/.gitignore
================================================
/build
================================================
FILE: library/build.gradle
================================================
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
//noinspection GradleDependency
buildToolsVersion "25.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.squareup.picasso:picasso:2.5.2'
}
================================================
FILE: library/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/ihsan/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 *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: library/src/main/AndroidManifest.xml
================================================
================================================
FILE: library/src/main/java/com/ihsanbal/wiv/AspectRatioLayout.java
================================================
package com.ihsanbal.wiv;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
/**
* @author ihsan on 31/05/2017.
*/
public class AspectRatioLayout extends FrameLayout {
private static final float DEFAULT_ASPECT_RATIO = 1.0f;
private static final int DEFAULT_ADJUST_DIMENSION = 0;
static final int ADJUST_DIMENSION_HEIGHT = 0;
protected double aspectRatio;
private int dimensionToAdjust;
public AspectRatioLayout(Context context) {
this(context, null);
}
public AspectRatioLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public AspectRatioLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initAttributes(attrs, defStyle);
}
private void initAttributes(AttributeSet attrs, int styleResId) {
final TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs,
R.styleable.AspectRatioLayout, styleResId, 0);
try {
aspectRatio = a.getFloat(
R.styleable.AspectRatioLayout_aspect_ratio,
DEFAULT_ASPECT_RATIO);
dimensionToAdjust = a.getInt(
R.styleable.AspectRatioLayout_dimension_to_adjust,
DEFAULT_ADJUST_DIMENSION);
} finally {
a.recycle();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width, height;
final int horizontalPadding = getPaddingLeft() + getPaddingRight();
final int verticalPadding = getPaddingBottom() + getPaddingTop();
if (dimensionToAdjust == ADJUST_DIMENSION_HEIGHT) {
if (View.MeasureSpec.getMode(widthMeasureSpec) == View.MeasureSpec.EXACTLY) {
width = View.MeasureSpec.getSize(widthMeasureSpec) - horizontalPadding;
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
width = getMeasuredWidth() - horizontalPadding;
}
height = (int) (width / aspectRatio);
} else {
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY) {
height = MeasureSpec.getSize(heightMeasureSpec) - verticalPadding;
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
height = getMeasuredHeight() - verticalPadding;
}
width = (int) (height * aspectRatio);
}
super.onMeasure(
View.MeasureSpec.makeMeasureSpec(width + horizontalPadding, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(height + verticalPadding, View.MeasureSpec.EXACTLY));
}
}
================================================
FILE: library/src/main/java/com/ihsanbal/wiv/MediaView.java
================================================
package com.ihsanbal.wiv;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.List;
public class MediaView extends ViewGroup implements View.OnClickListener {
static final int MAX_IMAGE_VIEW_COUNT = 4;
private static final CharSequence CONTENT_DESC = "content_description";
private static final int DEFAULT_DIVIDER_SIZE = 2;
private static final int DEFAULT_CORNER_RADII = 5;
private final OverlayImageView[] imageViews = new OverlayImageView[MAX_IMAGE_VIEW_COUNT];
private Picasso imageLoader;
private List mediaEntities = Collections.emptyList();
private final Path path = new Path();
private final RectF rect = new RectF();
private int mediaDividerSize;
private int imageCount;
final float[] radii = new float[8];
int mediaBgColor;
int photoErrorResId;
boolean internalRoundedCornersEnabled;
private OnMediaClickListener onMediaClickListener;
private int roundedCornersRadii;
public MediaView(Context context) {
this(context, null);
}
public MediaView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public MediaView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (!isInEditMode())
initAttributes(attrs, defStyle, Picasso.with(context));
}
private void initAttributes(AttributeSet attrs, int defStyle, Picasso loader) {
this.imageLoader = loader;
final TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.MediaView, defStyle, 0);
try {
roundedCornersRadii = a.getDimensionPixelSize(R.styleable.MediaView_corner_radii, DEFAULT_CORNER_RADII);
mediaDividerSize = a.getDimensionPixelSize(R.styleable.MediaView_divider_size, DEFAULT_DIVIDER_SIZE);
photoErrorResId = a.getResourceId(R.styleable.MediaView_place_holder, R.drawable.ic_place_holder);
mediaBgColor = a.getColor(R.styleable.MediaView_background_color, Color.WHITE);
} finally {
a.recycle();
}
}
public void setRoundedCornersRadii(int radii) {
this.radii[0] = radii;
this.radii[1] = radii;
this.radii[2] = radii;
this.radii[3] = radii;
this.radii[4] = radii;
this.radii[5] = radii;
this.radii[6] = radii;
this.radii[7] = radii;
requestLayout();
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
if (imageCount > 0) {
layoutImages();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final Size size;
if (imageCount > 0) {
size = measureImages(widthMeasureSpec, heightMeasureSpec);
} else {
size = Size.EMPTY;
}
setMeasuredDimension(size.width, size.height);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
path.reset();
rect.set(0, 0, w, h);
path.addRoundRect(rect, radii, Path.Direction.CW);
path.close();
}
@Override
protected void dispatchDraw(Canvas canvas) {
if (internalRoundedCornersEnabled &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
final int saveState = canvas.save();
canvas.clipPath(path);
super.dispatchDraw(canvas);
canvas.restoreToCount(saveState);
} else {
super.dispatchDraw(canvas);
}
}
public void setOnMediaClickListener(OnMediaClickListener onMediaClickListener) {
this.onMediaClickListener = onMediaClickListener;
}
public interface OnMediaClickListener {
void onMediaClick(View view, int index);
}
@Override
public void onClick(View view) {
Integer mediaEntityIndex = (Integer) view.getTag();
if (onMediaClickListener != null && mediaEntities != null && !mediaEntities.isEmpty()) {
onMediaClickListener.onMediaClick(view, mediaEntityIndex);
}
}
public void setMedias(List mediaEntities) {
this.mediaEntities = mediaEntities;
setRoundedCornersRadii(roundedCornersRadii);
clearImageViews();
initializeImageViews(mediaEntities);
internalRoundedCornersEnabled = true;
requestLayout();
}
Size measureImages(int widthMeasureSpec, int heightMeasureSpec) {
final int width = MeasureSpec.getSize(widthMeasureSpec);
final int height = MeasureSpec.getSize(heightMeasureSpec);
final int halfWidth = (width - mediaDividerSize) / 2;
final int halfHeight = (height - mediaDividerSize) / 2;
switch (imageCount) {
case 1:
measureImageView(0, width, height);
break;
case 2:
measureImageView(0, halfWidth, height);
measureImageView(1, halfWidth, height);
break;
case 3:
measureImageView(0, halfWidth, height);
measureImageView(1, halfWidth, halfHeight);
measureImageView(2, halfWidth, halfHeight);
break;
case 4:
measureImageView(0, halfWidth, halfHeight);
measureImageView(1, halfWidth, halfHeight);
measureImageView(2, halfWidth, halfHeight);
measureImageView(3, halfWidth, halfHeight);
break;
default:
break;
}
return Size.fromSize(width, height);
}
void measureImageView(int i, int width, int height) {
imageViews[i].measure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
void layoutImages() {
int width = getMeasuredWidth();
int height = getMeasuredHeight();
int halfWidth = (width - mediaDividerSize) / 2;
int halfHeight = (height - mediaDividerSize) / 2;
int middle = halfWidth + mediaDividerSize;
switch (imageCount) {
case 1:
layoutImage(0, 0, 0, width, height);
break;
case 2:
layoutImage(0, 0, 0, halfWidth, height);
layoutImage(1, halfWidth + mediaDividerSize, 0, width, height);
break;
case 3:
layoutImage(0, 0, 0, halfWidth, height);
layoutImage(1, middle, 0, width, halfHeight);
layoutImage(2, middle, halfHeight + mediaDividerSize, width, height);
break;
case 4:
layoutImage(0, 0, 0, halfWidth, halfHeight);
layoutImage(2, 0, halfHeight + mediaDividerSize, halfWidth, height);
layoutImage(1, middle, 0, width, halfHeight);
layoutImage(3, middle, halfHeight + mediaDividerSize, width, height);
break;
default:
break;
}
}
void layoutImage(int i, int left, int top, int right, int bottom) {
final ImageView view = imageViews[i];
if (view.getLeft() == left && view.getTop() == top && view.getRight() == right
&& view.getBottom() == bottom) {
return;
}
view.layout(left, top, right, bottom);
}
void clearImageViews() {
for (int index = 0; index < imageCount; index++) {
final ImageView imageView = imageViews[index];
if (imageView != null) {
imageView.setVisibility(GONE);
}
}
imageCount = 0;
}
void initializeImageViews(List mediaEntities) {
imageCount = Math.min(MAX_IMAGE_VIEW_COUNT, mediaEntities.size());
for (int index = 0; index < imageCount; index++) {
final OverlayImageView imageView = getOrCreateImageView(index);
final String mediaEntity = mediaEntities.get(index);
setAltText(imageView, "media");
setMediaImage(imageView, mediaEntity);
setOverlayImage(imageView);
}
}
OverlayImageView getOrCreateImageView(int index) {
OverlayImageView imageView = imageViews[index];
if (imageView == null) {
imageView = new OverlayImageView(getContext());
imageView.setLayoutParams(generateDefaultLayoutParams());
imageView.setOnClickListener(this);
imageViews[index] = imageView;
addView(imageView, index);
} else {
measureImageView(index, 0, 0);
layoutImage(index, 0, 0, 0, 0);
}
imageView.setVisibility(VISIBLE);
imageView.setBackgroundColor(mediaBgColor);
imageView.setTag(index);
return imageView;
}
@SuppressLint("PrivateResource")
void setAltText(ImageView imageView, String description) {
if (!TextUtils.isEmpty(description)) {
imageView.setContentDescription(description);
} else {
imageView.setContentDescription(CONTENT_DESC);
}
}
@SuppressLint("PrivateResource")
void setOverlayImage(OverlayImageView imageView) {
imageView.setOverlayDrawable(null);
}
void setMediaImage(ImageView imageView, String imagePath) {
if (imageLoader == null) return;
imageLoader.load(imagePath)
.fit()
.centerCrop()
.error(photoErrorResId)
.into(imageView, new PicassoCallback(imageView));
}
private static class PicassoCallback implements com.squareup.picasso.Callback {
final WeakReference imageViewWeakReference;
PicassoCallback(ImageView imageView) {
imageViewWeakReference = new WeakReference<>(imageView);
}
@Override
public void onSuccess() {
final ImageView imageView = imageViewWeakReference.get();
if (imageView != null) {
imageView.setBackgroundResource(android.R.color.transparent);
}
}
@Override
public void onError() { /* intentionally blank */ }
}
private static class Size {
static final Size EMPTY = new Size();
final int width;
final int height;
private Size() {
this(0, 0);
}
private Size(int width, int height) {
this.width = width;
this.height = height;
}
static Size fromSize(int w, int h) {
final int boundedWidth = Math.max(w, 0);
final int boundedHeight = Math.max(h, 0);
return boundedWidth != 0 || boundedHeight != 0 ?
new Size(boundedWidth, boundedHeight) : EMPTY;
}
}
}
================================================
FILE: library/src/main/java/com/ihsanbal/wiv/OverlayImageView.java
================================================
package com.ihsanbal.wiv;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
* An ImageView subclass that take a {@link android.graphics.drawable.Drawable} and draws it on top
* the ImageView content.
*/
public class OverlayImageView extends ImageView {
Overlay overlay = new Overlay(null);
public OverlayImageView(Context context) {
super(context);
}
public OverlayImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
overlay.draw(canvas);
}
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
overlay.setDrawableState(getDrawableState());
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
overlay.setDrawableBounds(getMeasuredWidth(), getMeasuredHeight());
}
@Override
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
super.onSizeChanged(width, height, oldWidth, oldHeight);
overlay.setDrawableBounds(width, height);
}
@Override
public void invalidateDrawable(Drawable drawable) {
if (drawable == overlay.drawable) {
invalidate();
} else {
super.invalidateDrawable(drawable);
}
}
/*
* Sets the drawable to be drawn on top the ImageView content.
*
* @param drawable The drawable
*/
public void setOverlayDrawable(Drawable drawable) {
if (drawable != overlay.drawable) {
overlay.cleanupDrawable(this);
if (drawable != null) {
drawable.setCallback(this);
}
overlay = new Overlay(drawable);
overlay.setDrawableState(getDrawableState());
requestLayout();
}
}
/**
* Takes a {@link android.graphics.drawable.Drawable} and draws it on top the ImageView content.
* The overlay drawable will respect the view's current state so a selector can be passed in.
*/
static protected class Overlay {
final Drawable drawable;
Overlay(Drawable drawable) {
this.drawable = drawable;
}
protected void cleanupDrawable(ImageView imageView) {
if (drawable != null) {
drawable.setCallback(null);
imageView.unscheduleDrawable(drawable);
}
}
protected void setDrawableBounds(int width, int height) {
if (drawable != null) {
drawable.setBounds(0, 0, width, height);
}
}
protected void setDrawableState(int[] state) {
if (drawable != null && drawable.isStateful()) {
drawable.setState(state);
}
}
protected void draw(Canvas canvas) {
if (drawable != null) {
drawable.draw(canvas);
}
}
}
}
================================================
FILE: library/src/main/res/values/attrs.xml
================================================
================================================
FILE: library/src/main/res/values/strings.xml
================================================
Library
================================================
FILE: settings.gradle
================================================
include ':app', ':library'