================================================
FILE: .idea/vcs.xml
================================================
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
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.
================================================
FILE: README.md
================================================
[](https://android-arsenal.com/details/1/3318)
[](https://jitpack.io/#ashishbhandari/AndroidTabbedDialog)
# AndroidTabbedDialog

## Setup
Add jitpack to your project’s repositories.
```
repositories {
// ...
maven { url "https://jitpack.io" }
}
```
Then add Tabbed dialog to your Module’s dependencies
```
dependencies {
compile 'com.github.ashishbhandari:AndroidTabbedDialog:v1.1'
}
```
## How to create tab dialogs:
```java
TabDialogFragment.createBuilder(MainActivity.this, getSupportFragmentManager())
.setTitle("hello")
.setSubTitle("subtitle")
.setTabButtonText(new CharSequence[]{"Tab1", "Tab2"})
.setPositiveButtonText("Love")
.setNegativeButtonText("Hate")
.setNeutralButtonText("WTF?")
.setRequestCode(REQUEST_SIMPLE_DIALOG)
.show();
```
### How to react on button press in your Activity/Fragment:
Simply implement interface `ISimpleDialogListener` in your Activity/Fragment. Listener's callbacks have `requestCode` parameter - you can use it if you have more dialogs in one Activity/Fragment.
### How to render tab view inside your dialog:
Simply implement interface `IFragmentListener` in your Activity/Fragment. Listener's callbacks have:-
`onFragmentViewCreated(Fragment fragment)`
`onFragmentAttached(Fragment fragment)`
`onFragmentDetached(Fragment fragment)`
```java
@Override
public void onFragmentViewCreated(Fragment fragment) {
int selectedTabPosition = fragment.getArguments().getInt(PageFragment.ARG_DAY_INDEX, 0);
View rootContainer = fragment.getView().findViewById(R.id.root_container);
Log.i(TAG, "Position: " + selectedTabPosition);
switch (selectedTabPosition) {
case 0:
// add view in container for first tab
View tabProductDetailLayout = getLayoutInflater().inflate(R.layout.tab_one_layout, (ViewGroup) rootContainer);
TextView textView = (TextView) tabProductDetailLayout.findViewById(R.id.text_view);
textView.setText("hello: tab1");
break;
case 1:
// add view in container for second tab
View tabProductDetailLayout2 = getLayoutInflater().inflate(R.layout.tab_one_layout, (ViewGroup) rootContainer);
TextView textView1 = (TextView) tabProductDetailLayout2.findViewById(R.id.text_view);
textView1.setText("hello: tab2");
break;
}
}
```
## License
Copyright (c) 2016 Ashish Bhandari
Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
================================================
FILE: app/.gitignore
================================================
/build
================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.androidifygeeks.tabdialogs"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
// compile 'com.github.ashishbhandari:AndroidTabbedDialog:1.0'
compile project(':library')
}
================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\AndroidStudioSDK/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 *;
#}
================================================
FILE: app/src/androidTest/java/com/androidifygeeks/tabdialogs/ApplicationTest.java
================================================
package com.androidifygeeks.tabdialogs;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* Testing Fundamentals
*/
public class ApplicationTest extends ApplicationTestCase {
public ApplicationTest() {
super(Application.class);
}
}
================================================
FILE: app/src/main/AndroidManifest.xml
================================================
================================================
FILE: app/src/main/java/com/androidifygeeks/tabdialogs/MainActivity.java
================================================
package com.androidifygeeks.tabdialogs;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.androidifygeeks.library.fragment.PageFragment;
import com.androidifygeeks.library.fragment.TabDialogFragment;
import com.androidifygeeks.library.iface.IFragmentListener;
import com.androidifygeeks.library.iface.ISimpleDialogCancelListener;
import com.androidifygeeks.library.iface.ISimpleDialogListener;
import java.util.HashSet;
import java.util.Set;
public class MainActivity extends AppCompatActivity implements ISimpleDialogListener, ISimpleDialogCancelListener, IFragmentListener {
private static final int REQUEST_TABBED_DIALOG = 42;
private static final String TAG = MainActivity.class.getSimpleName();
private final Set mMyScheduleFragments = new HashSet<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.testbutton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TabDialogFragment.createBuilder(MainActivity.this, getSupportFragmentManager())
.setTitle("Title")
.setSubTitle("Subtitle")
.setTabButtonText(new CharSequence[]{"Tab1", "Tab2"})
.setPositiveButtonText("Ok")
.setNegativeButtonText("Cancel")
.setNeutralButtonText("Neutral")
.setRequestCode(REQUEST_TABBED_DIALOG)
.show();
}
});
}
@Override
public void onCancelled(int requestCode) {
switch (requestCode) {
case REQUEST_TABBED_DIALOG:
Toast.makeText(MainActivity.this, "Dialog cancelled", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
@Override
public void onNegativeButtonClicked(int requestCode) {
if (requestCode == REQUEST_TABBED_DIALOG) {
Toast.makeText(MainActivity.this, "Negative button clicked", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onNeutralButtonClicked(int requestCode) {
if (requestCode == REQUEST_TABBED_DIALOG) {
Toast.makeText(MainActivity.this, "Neutral button clicked", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onPositiveButtonClicked(int requestCode) {
if (requestCode == REQUEST_TABBED_DIALOG) {
Toast.makeText(MainActivity.this, "Positive button clicked", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFragmentViewCreated(Fragment fragment) {
int selectedTabPosition = fragment.getArguments().getInt(PageFragment.ARG_DAY_INDEX, 0);
View rootContainer = fragment.getView().findViewById(R.id.root_container);
Log.i(TAG, "Position: " + selectedTabPosition);
switch (selectedTabPosition) {
case 0:
selectedTabPositionZeroCase(rootContainer);
break;
case 1:
selectedTabPositionOneCase(rootContainer);
break;
default:
break;
}
}
private void selectedTabPositionZeroCase(View rootContainer) {
// add view in container for first tab
View tabProductDetailLayout = getLayoutInflater().inflate(R.layout.tab_one_layout, (ViewGroup) rootContainer);
TextView textView = (TextView) tabProductDetailLayout.findViewById(R.id.text_view);
textView.setText("hello: tab1");
}
private void selectedTabPositionOneCase(View rootContainer) {
// add view in container for second tab
View tabProductDetailLayout2 = getLayoutInflater().inflate(R.layout.tab_one_layout, (ViewGroup) rootContainer);
TextView textView1 = (TextView) tabProductDetailLayout2.findViewById(R.id.text_view);
textView1.setText("hello: tab2");
}
@Override
public void onFragmentAttached(Fragment fragment) {
mMyScheduleFragments.add(fragment);
}
@Override
public void onFragmentDetached(Fragment fragment) {
mMyScheduleFragments.remove(fragment);
}
}
================================================
FILE: app/src/main/res/layout/activity_main.xml
================================================
================================================
FILE: app/src/main/res/layout/tab_one_layout.xml
================================================
================================================
FILE: app/src/main/res/values/colors.xml
================================================
#3F51B5#303F9F#FF4081
================================================
FILE: app/src/main/res/values/dimens.xml
================================================
16dp16dp
================================================
FILE: app/src/main/res/values/strings.xml
================================================
Tabbed Dialogs
================================================
FILE: app/src/main/res/values/styles.xml
================================================
================================================
FILE: app/src/main/res/values-w820dp/dimens.xml
================================================
64dp
================================================
FILE: app/src/test/java/com/androidifygeeks/tabdialogs/ExampleUnitTest.java
================================================
package com.androidifygeeks.tabdialogs;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
================================================
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:1.5.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' // Add this line
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-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.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# 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'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.ashishbhandari'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
}
// build a jar with source files
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
// build a jar with javadoc
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
================================================
FILE: library/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\AndroidStudioSDK/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 *;
#}
================================================
FILE: library/src/androidTest/java/com/androidifygeeks/library/ApplicationTest.java
================================================
package com.androidifygeeks.library;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* Testing Fundamentals
*/
public class ApplicationTest extends ApplicationTestCase {
public ApplicationTest() {
super(Application.class);
}
}
================================================
FILE: library/src/main/AndroidManifest.xml
================================================
================================================
FILE: library/src/main/java/com/androidifygeeks/library/core/BaseDialogBuilder.java
================================================
package com.androidifygeeks.library.core;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
/**
* Internal base builder that holds common values for all dialog fragment builders.
*
* Created by b_ashish on 21-Mar-16.
*/
public abstract class BaseDialogBuilder> {
protected final Context mContext;
protected final FragmentManager mFragmentManager;
protected final Class extends BaseDialogFragment> mClass;
public final static String ARG_REQUEST_CODE = "request_code";
public final static String ARG_CANCELABLE_ON_TOUCH_OUTSIDE = "cancelable_oto";
public final static String DEFAULT_TAG = "simple_dialog";
private String mTag = DEFAULT_TAG;
public final static int DEFAULT_REQUEST_CODE = -42;
private int mRequestCode = DEFAULT_REQUEST_CODE;
public static String ARG_USE_DARK_THEME = "usedarktheme";
public static String ARG_USE_LIGHT_THEME = "uselighttheme";
private Fragment mTargetFragment;
private boolean mCancelable = true;
private boolean mCancelableOnTouchOutside = true;
private boolean mUseDarkTheme = false;
private boolean mUseLightTheme = false;
public BaseDialogBuilder(Context context, FragmentManager fragmentManager, Class extends BaseDialogFragment> clazz) {
mFragmentManager = fragmentManager;
mContext = context.getApplicationContext();
mClass = clazz;
}
protected abstract T self();
protected abstract Bundle prepareArguments();
public T setCancelable(boolean cancelable) {
mCancelable = cancelable;
return self();
}
public T setCancelableOnTouchOutside(boolean cancelable) {
mCancelableOnTouchOutside = cancelable;
if (cancelable) {
mCancelable = cancelable;
}
return self();
}
public T setTargetFragment(Fragment fragment, int requestCode) {
mTargetFragment = fragment;
mRequestCode = requestCode;
return self();
}
public T setRequestCode(int requestCode) {
mRequestCode = requestCode;
return self();
}
public T setTag(String tag) {
mTag = tag;
return self();
}
public T useDarkTheme() {
mUseDarkTheme = true;
return self();
}
public T useLightTheme() {
mUseLightTheme = true;
return self();
}
private BaseDialogFragment create() {
final Bundle args = prepareArguments();
final BaseDialogFragment fragment = (BaseDialogFragment) Fragment.instantiate(mContext, mClass.getName(), args);
args.putBoolean(ARG_CANCELABLE_ON_TOUCH_OUTSIDE, mCancelableOnTouchOutside);
args.putBoolean(ARG_USE_DARK_THEME, mUseDarkTheme);
args.putBoolean(ARG_USE_LIGHT_THEME, mUseLightTheme);
if (mTargetFragment != null) {
fragment.setTargetFragment(mTargetFragment, mRequestCode);
} else {
args.putInt(ARG_REQUEST_CODE, mRequestCode);
}
fragment.setCancelable(mCancelable);
return fragment;
}
public DialogFragment show() {
BaseDialogFragment fragment = create();
fragment.show(mFragmentManager, mTag);
return fragment;
}
/**
* Like show() but allows the commit to be executed after an activity's state is saved. This
* is dangerous because the commit can be lost if the activity needs to later be restored from
* its state, so this should only be used for cases where it is okay for the UI state to change
* unexpectedly on the user.
*/
public DialogFragment showAllowingStateLoss() {
BaseDialogFragment fragment = create();
fragment.showAllowingStateLoss(mFragmentManager, mTag);
return fragment;
}
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/core/BaseDialogFragment.java
================================================
package com.androidifygeeks.library.core;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;
import com.androidifygeeks.library.R;
import com.androidifygeeks.library.fragment.PageFragment;
import com.androidifygeeks.library.iface.ISimpleDialogCancelListener;
import com.androidifygeeks.library.util.MultiSwipeRefreshLayout;
import com.androidifygeeks.library.util.TypefaceHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Base dialog fragment for all your dialogs, styleable and same design on Android 2.2+.
*
*
* @author David Vávra (david@inmite.eu)
*
* modified by b_ashish on 21-Mar-16.
*/
public abstract class BaseDialogFragment extends DialogFragment implements DialogInterface.OnShowListener, MultiSwipeRefreshLayout.CanChildScrollUpCallback {
private static final String TAG = BaseDialogFragment.class.getSimpleName();
protected int mRequestCode;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = new Dialog(getActivity());
Bundle args = getArguments();
if (args != null) {
dialog.setCanceledOnTouchOutside(
args.getBoolean(BaseDialogBuilder.ARG_CANCELABLE_ON_TOUCH_OUTSIDE));
}
/*
* disable the actual title of a dialog cause custom dialog title is rendering through custom layout
*/
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setOnShowListener(this);
return dialog;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Builder builder = new Builder(getActivity(), inflater, container);
return build(builder).create();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Fragment targetFragment = getTargetFragment();
if (targetFragment != null) {
mRequestCode = getTargetRequestCode();
} else {
Bundle args = getArguments();
if (args != null) {
mRequestCode = args.getInt(BaseDialogBuilder.ARG_REQUEST_CODE, 0);
}
}
}
/**
* Key method for using { com.avast.android.dialogs.core.BaseDialogFragment}.
* Customized dialogs need to be set up via provided builder.
*
* @param initialBuilder Provided builder for setting up customized dialog
* @return Updated builder
*/
protected abstract Builder build(Builder initialBuilder);
@Override
public void onDestroyView() {
// bug in the compatibility library
if (getDialog() != null && getRetainInstance()) {
getDialog().setDismissMessage(null);
}
super.onDestroyView();
}
public void showAllowingStateLoss(FragmentManager manager, String tag) {
FragmentTransaction ft = manager.beginTransaction();
ft.add(this, tag);
ft.commitAllowingStateLoss();
}
@Override
public void onShow(DialogInterface dialog) {
if (getView() != null) {
// ScrollView vMessageScrollView = (ScrollView) getView().findViewById(R.id.sdl_message_scrollview);
// ListView vListView = (ListView) getView().findViewById(R.id.sdl_list);
// FrameLayout vCustomViewNoScrollView = (FrameLayout) getView().findViewById(R.id.sdl_custom);
// boolean customViewNoScrollViewScrollable = false;
// if (vCustomViewNoScrollView.getChildCount() > 0) {
// View firstChild = vCustomViewNoScrollView.getChildAt(0);
// if (firstChild instanceof ViewGroup) {
// customViewNoScrollViewScrollable = isScrollable((ViewGroup) firstChild);
// }
// }
// boolean listViewScrollable = isScrollable(vListView);
// boolean messageScrollable = isScrollable(vMessageScrollView);
// boolean scrollable = listViewScrollable || messageScrollable || customViewNoScrollViewScrollable;
// modifyButtonsBasedOnScrollableContent(scrollable);
}
}
@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
for (ISimpleDialogCancelListener listener : getCancelListeners()) {
listener.onCancelled(mRequestCode);
}
}
/**
* Get dialog cancel listeners.
* There might be more than one cancel listener.
*
* @return Dialog cancel listeners
* @since 2.1.0
*/
protected List getCancelListeners() {
return getDialogListeners(ISimpleDialogCancelListener.class);
}
/**
* Utility method for acquiring all listeners of some type for current instance of DialogFragment
*
* @param listenerInterface Interface of the desired listeners
* @return Unmodifiable list of listeners
* @since 2.1.0
*/
@SuppressWarnings("unchecked")
protected List getDialogListeners(Class listenerInterface) {
final Fragment targetFragment = getTargetFragment();
List listeners = new ArrayList(2);
if (targetFragment != null && listenerInterface.isAssignableFrom(targetFragment.getClass())) {
listeners.add((T) targetFragment);
}
if (getActivity() != null && listenerInterface.isAssignableFrom(getActivity().getClass())) {
listeners.add((T) getActivity());
}
return Collections.unmodifiableList(listeners);
}
private boolean isScrollable(ViewGroup listView) {
int totalHeight = 0;
for (int i = 0; i < listView.getChildCount(); i++) {
totalHeight += listView.getChildAt(i).getMeasuredHeight();
}
return listView.getMeasuredHeight() < totalHeight;
}
@Override
public boolean canSwipeRefreshChildScrollUp() {
return false;
}
/**
* Custom dialog builder
*/
protected static class Builder {
private final Context mContext;
private final ViewGroup mContainer;
private final LayoutInflater mInflater;
private CharSequence mTitle = null;
private CharSequence mSubTitle = null;
private CharSequence mPositiveButtonText;
private View.OnClickListener mPositiveButtonListener;
private CharSequence mNegativeButtonText;
private View.OnClickListener mNegativeButtonListener;
private CharSequence mNeutralButtonText;
private View.OnClickListener mNeutralButtonListener;
private CharSequence mMessage;
private View mCustomView;
private ListAdapter mListAdapter;
private TabViewPagerAdapter mTabAdapter;
private CharSequence[] mTabItems;
private int mListCheckedItemIdx;
private int mChoiceMode;
private int[] mListCheckedItemMultipleIds;
private AdapterView.OnItemClickListener mOnItemClickListener;
private int contentHeight;
private int mViewPagerScrollState = ViewPager.SCROLL_STATE_IDLE;
private int baseTabViewId = 12345;
public Builder(Context context, LayoutInflater inflater, ViewGroup container) {
this.mContext = context;
this.mContainer = container;
this.mInflater = inflater;
}
public LayoutInflater getLayoutInflater() {
return mInflater;
}
public Builder setContentPaneHeight(int height) {
this.contentHeight = height;
return this;
}
public Builder setTitle(int titleId) {
this.mTitle = mContext.getText(titleId);
return this;
}
public Builder setTitle(CharSequence title) {
this.mTitle = title;
return this;
}
public Builder setSubTitle(int subTitleId) {
this.mSubTitle = mContext.getText(subTitleId);
return this;
}
public Builder setSubTitle(CharSequence subTitle) {
this.mSubTitle = subTitle;
return this;
}
public Builder setPositiveButton(int textId, final View.OnClickListener listener) {
mPositiveButtonText = mContext.getText(textId);
mPositiveButtonListener = listener;
return this;
}
public Builder setPositiveButton(CharSequence text, final View.OnClickListener listener) {
mPositiveButtonText = text;
mPositiveButtonListener = listener;
return this;
}
public Builder setNegativeButton(int textId, final View.OnClickListener listener) {
mNegativeButtonText = mContext.getText(textId);
mNegativeButtonListener = listener;
return this;
}
public Builder setNegativeButton(CharSequence text, final View.OnClickListener listener) {
mNegativeButtonText = text;
mNegativeButtonListener = listener;
return this;
}
public Builder setNeutralButton(int textId, final View.OnClickListener listener) {
mNeutralButtonText = mContext.getText(textId);
mNeutralButtonListener = listener;
return this;
}
public Builder setNeutralButton(CharSequence text, final View.OnClickListener listener) {
mNeutralButtonText = text;
mNeutralButtonListener = listener;
return this;
}
public Builder setMessage(int messageId) {
mMessage = mContext.getText(messageId);
return this;
}
public Builder setMessage(CharSequence message) {
mMessage = message;
return this;
}
public Builder setItems(ListAdapter listAdapter, int[] checkedItemIds, int choiceMode, final AdapterView.OnItemClickListener listener) {
mListAdapter = listAdapter;
mListCheckedItemMultipleIds = checkedItemIds;
mOnItemClickListener = listener;
mChoiceMode = choiceMode;
mListCheckedItemIdx = -1;
return this;
}
public Builder setTabItems(TabViewPagerAdapter tabAdapter, CharSequence[] tabItems) {
mTabAdapter = tabAdapter;
mTabItems = tabItems;
return this;
}
/**
* Set list
*
* @param checkedItemIdx Item check by default, -1 if no item should be checked
*/
public Builder setItems(ListAdapter listAdapter, int checkedItemIdx,
final AdapterView.OnItemClickListener listener) {
mListAdapter = listAdapter;
mOnItemClickListener = listener;
mListCheckedItemIdx = checkedItemIdx;
mChoiceMode = AbsListView.CHOICE_MODE_NONE;
return this;
}
public Builder setView(View view) {
mCustomView = view;
return this;
}
public View create() {
final LinearLayout content = (LinearLayout) mInflater.inflate(R.layout.tdl_dialog, mContainer, false);
TextView vTitle = (TextView) content.findViewById(R.id.tdl_title_text);
TextView vSubTitle = (TextView) content.findViewById(R.id.tdl_subtitle_text);
MultiSwipeRefreshLayout vMultiSwipeRefreshLayout = (MultiSwipeRefreshLayout) content.findViewById(R.id.tdl_swipe_refresh_layout);
setContentHeight(vMultiSwipeRefreshLayout);
final ViewPager vViewPager = (ViewPager) content.findViewById(R.id.tdl_view_pager);
final TabLayout vTabLayout = (TabLayout) content.findViewById(R.id.tdl_sliding_tabs);
// TextView vMessage = (TextView) content.findViewById(R.id.tdl_message);
// FrameLayout vCustomView = (FrameLayout) content.findViewById(R.id.sdl_custom);
Button vPositiveButton = (Button) content.findViewById(R.id.tdl_button_positive);
Button vNegativeButton = (Button) content.findViewById(R.id.tdl_button_negative);
Button vNeutralButton = (Button) content.findViewById(R.id.tdl_button_neutral);
Typeface regularFont = TypefaceHelper.get(mContext, "Roboto-Regular");
Typeface mediumFont = TypefaceHelper.get(mContext, "Roboto-Medium");
set(vTitle, mTitle, mediumFont);
set(vSubTitle, mSubTitle, mediumFont);
// set(vMessage, mMessage, regularFont);
// setPaddingOfTitleAndMessage(vTitle, vMessage);
//---- for tab rendering----//
if (mTabAdapter != null) {
vViewPager.setAdapter(mTabAdapter);
vTabLayout.setTabsFromPagerAdapter(mTabAdapter);
vTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
vViewPager.setCurrentItem(tab.getPosition(), true);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
// Do nothing
}
});
vViewPager.setPageMargin(mContext.getResources().getDimensionPixelSize(R.dimen.my_tab_view_page_margin));
vViewPager.setPageMarginDrawable(R.drawable.page_margin);
vViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
mViewPagerScrollState = ViewPager.SCROLL_STATE_DRAGGING;
}
@Override
public void onPageSelected(int position) {
TabLayout.Tab tab = vTabLayout.getTabAt(position);
tab.select();
}
@Override
public void onPageScrollStateChanged(int state) {
mViewPagerScrollState = ViewPager.SCROLL_STATE_IDLE;
}
});
for (int i = 0, count = mTabItems.length; i < count; i++) {
vTabLayout.setContentDescription(mTabItems[i]);
}
// help you to select default tab
TabLayout.Tab tab = vTabLayout.getTabAt(0);
tab.select();
}
//------end here--------//
set(vPositiveButton, mPositiveButtonText, mediumFont, mPositiveButtonListener);
set(vNegativeButton, mNegativeButtonText, mediumFont, mNegativeButtonListener);
set(vNeutralButton, mNeutralButtonText, mediumFont, mNeutralButtonListener);
return content;
}
/*
* defining the height of a content layout
*/
private void setContentHeight(MultiSwipeRefreshLayout swipeRefreshLayout) {
if (swipeRefreshLayout != null) {
if (contentHeight <= 0) {
swipeRefreshLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) mContext.getResources().getDimension(R.dimen.dialog_main_pane_height)));
} else {
swipeRefreshLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, contentHeight));
}
}
}
/**
* Padding is different if there is only title, only message or both.
*/
private void setPaddingOfTitleAndMessage(TextView vTitle, TextView vMessage) {
// int grid6 = mContext.getResources().getDimensionPixelSize(R.dimen.grid_6);
// int grid4 = mContext.getResources().getDimensionPixelSize(R.dimen.grid_4);
// if (!TextUtils.isEmpty(mTitle) && !TextUtils.isEmpty(mMessage)) {
// vTitle.setPadding(grid6, grid6, grid6, grid4);
// vMessage.setPadding(grid6, 0, grid6, grid4);
// } else if (TextUtils.isEmpty(mTitle)) {
// vMessage.setPadding(grid6, grid4, grid6, grid4);
// } else if (TextUtils.isEmpty(mMessage)) {
// vTitle.setPadding(grid6, grid6, grid6, grid4);
// }
}
private boolean shouldStackButtons() {
return shouldStackButton(mPositiveButtonText) || shouldStackButton(mNegativeButtonText)
|| shouldStackButton(mNeutralButtonText);
}
private boolean shouldStackButton(CharSequence text) {
final int MAX_BUTTON_CHARS = 12; // based on observation, could be done better with measuring widths
return text != null && text.length() > MAX_BUTTON_CHARS;
}
private void set(Button button, CharSequence text, Typeface font, View.OnClickListener listener) {
set(button, text, font);
if (listener != null) {
button.setOnClickListener(listener);
}
}
private void set(TextView textView, CharSequence text) {
if (text != null) {
textView.setText(text);
} else {
textView.setVisibility(View.GONE);
}
}
private void set(TextView textView, CharSequence text, Typeface font) {
if (text != null) {
textView.setText(text);
textView.setTypeface(font);
} else {
textView.setVisibility(View.GONE);
}
}
}
public class TabViewPagerAdapter extends FragmentPagerAdapter {
private final CharSequence[] tabItems;
private Fragment mCurrentFragment;
public TabViewPagerAdapter(FragmentManager fm, CharSequence[] tabItems) {
super(fm);
this.tabItems = tabItems;
}
public Fragment getCurrentFragment() {
return mCurrentFragment;
}
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
if (getCurrentFragment() != object) {
mCurrentFragment = ((Fragment) object);
}
super.setPrimaryItem(container, position, object);
}
@Override
public Fragment getItem(int position) {
Log.d(TAG, "Creating fragment #" + position);
PageFragment frag = new PageFragment();
Bundle args = new Bundle();
args.putInt(PageFragment.ARG_DAY_INDEX, position);
String parentTag = getTag();
args.putString(PageFragment.PARENT_TAG, parentTag);
frag.setArguments(args);
return frag;
}
@Override
public int getCount() {
return tabItems.length;
}
@Override
public CharSequence getPageTitle(int position) {
return tabItems[position];
}
}
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/fragment/PageFragment.java
================================================
package com.androidifygeeks.library.fragment;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.androidifygeeks.library.R;
import com.androidifygeeks.library.iface.IFragmentListener;
/**
* Created by b_ashish on 17-Mar-16.
*
* this class can be invoke from activity or either from fragment
*/
public class PageFragment extends Fragment {
private String mContentDescription = null;
private View mRoot = null;
public static final String ARG_DAY_INDEX = "com.androidifygeeks.library.ARG_DAY_INDEX";
public static final String PARENT_TAG = "com.androidifygeeks.library.PARENT_TAG";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRoot = inflater.inflate(R.layout.tdl_fragment_container, container, false);
if (mContentDescription != null) {
mRoot.setContentDescription(mContentDescription);
}
return mRoot;
}
public void setContentDescription(String desc) {
mContentDescription = desc;
if (mRoot != null) {
mRoot.setContentDescription(mContentDescription);
}
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (getActivity() instanceof IFragmentListener) {
((IFragmentListener) getActivity()).onFragmentViewCreated(this);
} else {
Fragment parentFragment;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
parentFragment = getParentFragment();
} else {
// Collect the tag from the arguments
String tag = getArguments().getString(PARENT_TAG);
// Use the tag to get the parentFragment from the activity, which is (conveniently) available in onAttach()
parentFragment = getActivity().getSupportFragmentManager().findFragmentByTag(tag);
}
if (parentFragment instanceof IFragmentListener) {
((IFragmentListener) parentFragment).onFragmentViewCreated(this);
}
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (getActivity() instanceof IFragmentListener) {
((IFragmentListener) getActivity()).onFragmentAttached(this);
} else {
Fragment parentFragment;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
parentFragment = getParentFragment();
} else {
// Collect the tag from the arguments
String tag = getArguments().getString(PARENT_TAG);
// Use the tag to get the parentFragment from the activity, which is (conveniently) available in onAttach()
parentFragment = getActivity().getSupportFragmentManager().findFragmentByTag(tag);
}
if (parentFragment instanceof IFragmentListener) {
((IFragmentListener) parentFragment).onFragmentAttached(this);
}
}
}
@Override
public void onDetach() {
super.onDetach();
if (getActivity() instanceof IFragmentListener) {
((IFragmentListener) getActivity()).onFragmentDetached(this);
} else {
Fragment parentFragment;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
parentFragment = getParentFragment();
} else {
// Collect the tag from the arguments
String tag = getArguments().getString(PARENT_TAG);
// Use the tag to get the parentFragment from the activity, which is (conveniently) available in onAttach()
parentFragment = getActivity().getSupportFragmentManager().findFragmentByTag(tag);
}
if (parentFragment instanceof IFragmentListener) {
((IFragmentListener) parentFragment).onFragmentDetached(this);
}
}
}
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/fragment/TabDialogFragment.java
================================================
package com.androidifygeeks.library.fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.text.Html;
import android.text.SpannedString;
import android.text.TextUtils;
import android.view.View;
import com.androidifygeeks.library.core.BaseDialogBuilder;
import com.androidifygeeks.library.core.BaseDialogFragment;
import com.androidifygeeks.library.iface.INegativeButtonDialogListener;
import com.androidifygeeks.library.iface.INeutralButtonDialogListener;
import com.androidifygeeks.library.iface.IPositiveButtonDialogListener;
import java.util.List;
/**
* Created by b_ashish on 21-Mar-16.
*/
public class TabDialogFragment extends BaseDialogFragment {
protected final static String ARG_MESSAGE = "message";
protected final static String ARG_TITLE = "title";
protected final static String ARG_SUB_TITLE = "sub_title";
protected final static String ARG_POSITIVE_BUTTON = "positive_button";
protected final static String ARG_NEGATIVE_BUTTON = "negative_button";
protected final static String ARG_NEUTRAL_BUTTON = "neutral_button";
protected final static String ARG_TAB_BUTTON = "tab_button";
public static TabDialogBuilder createBuilder(Context context, FragmentManager fragmentManager) {
return new TabDialogBuilder(context, fragmentManager, TabDialogFragment.class);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
/**
* Key method for extending {com.avast.android.dialogs.fragment.TabDialogFragment}.
* Children can extend this to add more things to base builder.
*/
@Override
protected BaseDialogFragment.Builder build(BaseDialogFragment.Builder builder) {
final CharSequence title = getTitle();
if (!TextUtils.isEmpty(title)) {
builder.setTitle(title);
}
final CharSequence subTitle = getSubTitle();
if (!TextUtils.isEmpty(subTitle)) {
builder.setSubTitle(subTitle);
}
final CharSequence message = getMessage();
if (!TextUtils.isEmpty(message)) {
builder.setMessage(message);
}
final CharSequence positiveButtonText = getPositiveButtonText();
if (!TextUtils.isEmpty(positiveButtonText)) {
builder.setPositiveButton(positiveButtonText, new View.OnClickListener() {
@Override
public void onClick(View view) {
for (IPositiveButtonDialogListener listener : getPositiveButtonDialogListeners()) {
listener.onPositiveButtonClicked(mRequestCode);
}
dismiss();
}
});
}
final CharSequence negativeButtonText = getNegativeButtonText();
if (!TextUtils.isEmpty(negativeButtonText)) {
builder.setNegativeButton(negativeButtonText, new View.OnClickListener() {
@Override
public void onClick(View view) {
for (INegativeButtonDialogListener listener : getNegativeButtonDialogListeners()) {
listener.onNegativeButtonClicked(mRequestCode);
}
dismiss();
}
});
}
final CharSequence neutralButtonText = getNeutralButtonText();
if (!TextUtils.isEmpty(neutralButtonText)) {
builder.setNeutralButton(neutralButtonText, new View.OnClickListener() {
@Override
public void onClick(View view) {
for (INeutralButtonDialogListener listener : getNeutralButtonDialogListeners()) {
listener.onNeutralButtonClicked(mRequestCode);
}
dismiss();
}
});
}
final CharSequence[] tabButtonText = getTabButtonText();
if (tabButtonText != null && tabButtonText.length > 0) {
buildTab(builder);
}
return builder;
}
private void buildTab(final Builder builder) {
builder.setTabItems(
prepareAdapter(), getTabButtonText());
}
private TabViewPagerAdapter prepareAdapter() {
TabViewPagerAdapter tabViewPagerAdapter = new TabViewPagerAdapter(getChildFragmentManager(), getTabButtonText());
return tabViewPagerAdapter;
}
protected CharSequence getMessage() {
return getArguments().getCharSequence(ARG_MESSAGE);
}
protected CharSequence getTitle() {
return getArguments().getCharSequence(ARG_TITLE);
}
protected CharSequence getSubTitle() {
return getArguments().getCharSequence(ARG_SUB_TITLE);
}
protected CharSequence getPositiveButtonText() {
return getArguments().getCharSequence(ARG_POSITIVE_BUTTON);
}
protected CharSequence getNegativeButtonText() {
return getArguments().getCharSequence(ARG_NEGATIVE_BUTTON);
}
protected CharSequence getNeutralButtonText() {
return getArguments().getCharSequence(ARG_NEUTRAL_BUTTON);
}
protected CharSequence[] getTabButtonText() {
return getArguments().getCharSequenceArray(ARG_TAB_BUTTON);
}
/**
* Get positive button dialog listeners.
* There might be more than one listener.
*
* @return Dialog listeners
* @since 2.1.0
*/
protected List getPositiveButtonDialogListeners() {
return getDialogListeners(IPositiveButtonDialogListener.class);
}
/**
* Get negative button dialog listeners.
* There might be more than one listener.
*
* @return Dialog listeners
* @since 2.1.0
*/
protected List getNegativeButtonDialogListeners() {
return getDialogListeners(INegativeButtonDialogListener.class);
}
/**
* Get neutral button dialog listeners.
* There might be more than one listener.
*
* @return Dialog listeners
* @since 2.1.0
*/
protected List getNeutralButtonDialogListeners() {
return getDialogListeners(INeutralButtonDialogListener.class);
}
public static class TabDialogBuilder extends BaseDialogBuilder {
private CharSequence mTitle;
private CharSequence mSubTitle;
private CharSequence mMessage;
private CharSequence mPositiveButtonText;
private CharSequence mNegativeButtonText;
private CharSequence mNeutralButtonText;
private CharSequence[] mTabButtonText;
public TabDialogBuilder(Context context, FragmentManager fragmentManager, Class extends BaseDialogFragment> clazz) {
super(context, fragmentManager, clazz);
}
@Override
protected TabDialogBuilder self() {
return this;
}
public TabDialogBuilder setTitle(int titleResourceId) {
mTitle = mContext.getString(titleResourceId);
return this;
}
public TabDialogBuilder setTitle(CharSequence title) {
mTitle = title;
return this;
}
public TabDialogBuilder setSubTitle(int subTitleResourceId) {
mSubTitle = mContext.getString(subTitleResourceId);
return this;
}
public TabDialogBuilder setSubTitle(CharSequence subTitle) {
mSubTitle = subTitle;
return this;
}
public TabDialogBuilder setMessage(int messageResourceId) {
mMessage = mContext.getText(messageResourceId);
return this;
}
/**
* Allow to set resource string with HTML formatting and bind %s,%i.
* This is workaround for https://code.google.com/p/android/issues/detail?id=2923
*/
public TabDialogBuilder setMessage(int resourceId, Object... formatArgs) {
mMessage = Html.fromHtml(String.format(Html.toHtml(new SpannedString(mContext.getText(resourceId))), formatArgs));
return this;
}
public TabDialogBuilder setMessage(CharSequence message) {
mMessage = message;
return this;
}
public TabDialogBuilder setPositiveButtonText(int textResourceId) {
mPositiveButtonText = mContext.getString(textResourceId);
return this;
}
public TabDialogBuilder setPositiveButtonText(CharSequence text) {
mPositiveButtonText = text;
return this;
}
public TabDialogBuilder setNegativeButtonText(int textResourceId) {
mNegativeButtonText = mContext.getString(textResourceId);
return this;
}
public TabDialogBuilder setNegativeButtonText(CharSequence text) {
mNegativeButtonText = text;
return this;
}
public TabDialogBuilder setNeutralButtonText(int textResourceId) {
mNeutralButtonText = mContext.getString(textResourceId);
return this;
}
public TabDialogBuilder setNeutralButtonText(CharSequence text) {
mNeutralButtonText = text;
return this;
}
public TabDialogBuilder setTabButtonText(CharSequence[] value) {
mTabButtonText = value;
return this;
}
@Override
protected Bundle prepareArguments() {
Bundle args = new Bundle();
args.putCharSequence(TabDialogFragment.ARG_MESSAGE, mMessage);
args.putCharSequence(TabDialogFragment.ARG_TITLE, mTitle);
args.putCharSequence(TabDialogFragment.ARG_SUB_TITLE, mSubTitle);
args.putCharSequence(TabDialogFragment.ARG_POSITIVE_BUTTON, mPositiveButtonText);
args.putCharSequence(TabDialogFragment.ARG_NEGATIVE_BUTTON, mNegativeButtonText);
args.putCharSequence(TabDialogFragment.ARG_NEUTRAL_BUTTON, mNeutralButtonText);
args.putCharSequenceArray(TabDialogFragment.ARG_TAB_BUTTON, mTabButtonText);
return args;
}
}
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/iface/IFragmentListener.java
================================================
package com.androidifygeeks.library.iface;
import android.support.v4.app.Fragment;
/**
* Created by b_ashish on 23-Mar-16.
*/
public interface IFragmentListener {
void onFragmentViewCreated(Fragment fragment);
void onFragmentAttached(Fragment fragment);
void onFragmentDetached(Fragment fragment);
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/iface/INegativeButtonDialogListener.java
================================================
package com.androidifygeeks.library.iface;
/**
* Implement this interface in Activity or Fragment to react to negative dialog buttons.
*
* @author Tomáš Kypta
* @since 2.1.0
*/
public interface INegativeButtonDialogListener {
public void onNegativeButtonClicked(int requestCode);
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/iface/INeutralButtonDialogListener.java
================================================
package com.androidifygeeks.library.iface;
/**
* Implement this interface in Activity or Fragment to react to neutral dialog buttons.
*
* @author Tomáš Kypta
* @since 2.1.0
*/
public interface INeutralButtonDialogListener {
public void onNeutralButtonClicked(int requestCode);
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/iface/IPositiveButtonDialogListener.java
================================================
package com.androidifygeeks.library.iface;
/**
* Implement this interface in Activity or Fragment to react to positive dialog buttons.
*
* @author Tomáš Kypta
* @since 2.1.0
*/
public interface IPositiveButtonDialogListener {
public void onPositiveButtonClicked(int requestCode);
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/iface/ISimpleDialogCancelListener.java
================================================
/*
* Copyright 2013 Inmite s.r.o. (www.inmite.eu).
*
* 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.androidifygeeks.library.iface;
/**
* Implement this interface in Activity or Fragment to react when the dialog is cancelled.
* This listener is common for all types of dialogs.
*
* @author Tomáš Kypta
*/
public interface ISimpleDialogCancelListener {
public void onCancelled(int requestCode);
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/iface/ISimpleDialogListener.java
================================================
/*
* Copyright 2013 Inmite s.r.o. (www.inmite.eu).
*
* 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.androidifygeeks.library.iface;
/**
* Implement this interface in Activity or Fragment to react to positive, negative and neutral dialog buttons.
*
* @author David Vávra (david@inmite.eu)
*/
public interface ISimpleDialogListener extends IPositiveButtonDialogListener, INegativeButtonDialogListener, INeutralButtonDialogListener {
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/util/MultiSwipeRefreshLayout.java
================================================
/*
* Copyright 2014 Google Inc. All rights reserved.
*
* 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.androidifygeeks.library.util;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import com.androidifygeeks.library.R;
public class MultiSwipeRefreshLayout extends SwipeRefreshLayout {
private CanChildScrollUpCallback mCanChildScrollUpCallback;
private Drawable mForegroundDrawable;
public MultiSwipeRefreshLayout(Context context) {
this(context, null);
}
public MultiSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
final TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.MultiSwipeRefreshLayout, 0, 0);
mForegroundDrawable = a.getDrawable(R.styleable.MultiSwipeRefreshLayout_foreground);
if (mForegroundDrawable != null) {
mForegroundDrawable.setCallback(this);
setWillNotDraw(false);
}
a.recycle();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (mForegroundDrawable != null) {
mForegroundDrawable.setBounds(0, 0, w, h);
}
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
if (mForegroundDrawable != null) {
mForegroundDrawable.draw(canvas);
}
}
public void setCanChildScrollUpCallback(CanChildScrollUpCallback canChildScrollUpCallback) {
mCanChildScrollUpCallback = canChildScrollUpCallback;
}
public static interface CanChildScrollUpCallback {
public boolean canSwipeRefreshChildScrollUp();
}
@Override
public boolean canChildScrollUp() {
if (mCanChildScrollUpCallback != null) {
return mCanChildScrollUpCallback.canSwipeRefreshChildScrollUp();
}
return super.canChildScrollUp();
}
}
================================================
FILE: library/src/main/java/com/androidifygeeks/library/util/TypefaceHelper.java
================================================
package com.androidifygeeks.library.util;
import android.content.Context;
import android.graphics.Typeface;
import android.support.v4.util.SimpleArrayMap;
/*
Taken from:
https://github.com/afollestad/material-dialogs/blob/master/library/src/main/java/com/afollestad/materialdialogs/util/TypefaceHelper.java
Each call to Typeface.createFromAsset will load a new instance of the typeface into memory,
and this memory is not consistently get garbage collected
http://code.google.com/p/android/issues/detail?id=9904
(It states released but even on Lollipop you can see the typefaces accumulate even after
multiple GC passes)
You can detect this by running:
adb shell dumpsys meminfo com.your.packagenage
You will see output like:
Asset Allocations
zip:/data/app/com.your.packagenage-1.apk:/assets/Roboto-Medium.ttf: 125K
zip:/data/app/com.your.packagenage-1.apk:/assets/Roboto-Medium.ttf: 125K
zip:/data/app/com.your.packagenage-1.apk:/assets/Roboto-Medium.ttf: 125K
zip:/data/app/com.your.packagenage-1.apk:/assets/Roboto-Regular.ttf: 123K
zip:/data/app/com.your.packagenage-1.apk:/assets/Roboto-Medium.ttf: 125K
*/
public class TypefaceHelper {
private static final SimpleArrayMap cache = new SimpleArrayMap<>();
public static Typeface get(Context c, String name) {
synchronized (cache) {
if (!cache.containsKey(name)) {
Typeface t = Typeface.createFromAsset(
c.getAssets(), String.format("fonts/%s.ttf", name));
cache.put(name, t);
return t;
}
return cache.get(name);
}
}
}
================================================
FILE: library/src/main/res/drawable/page_margin.xml
================================================
================================================
FILE: library/src/main/res/layout/horizontal_separator.xml
================================================
================================================
FILE: library/src/main/res/layout/tdl_dialog.xml
================================================
================================================
FILE: library/src/main/res/layout/tdl_dialog_header.xml
================================================
================================================
FILE: library/src/main/res/layout/tdl_fragment_container.xml
================================================
================================================
FILE: library/src/main/res/values/attrs.xml
================================================
================================================
FILE: library/src/main/res/values/colors.xml
================================================
#1976D2#FFFFFF#ff004446#de004446@color/white#ff275B64@color/blue@android:color/white#b3004446#ff008094
================================================
FILE: library/src/main/res/values/dimens.xml
================================================
16dp8dp4dp4dp@dimen/padding_normal165dp48dp14sp
================================================
FILE: library/src/main/res/values/fonts.xml
================================================
1sans-serif
================================================
FILE: library/src/main/res/values/strings.xml
================================================
library
================================================
FILE: library/src/main/res/values/styles.xml
================================================
================================================
FILE: library/src/main/res/values-sw600dp/dimens.xml
================================================
12dp8dp
================================================
FILE: library/src/main/res/values-v21/fonts.xml
================================================
0sans-serif-medium
================================================
FILE: library/src/test/java/com/androidifygeeks/library/ExampleUnitTest.java
================================================
package com.androidifygeeks.library;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
================================================
FILE: settings.gradle
================================================
include ':app', ':library'