├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── compiler.xml
├── dictionaries
│ └── marco.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── marcoscg
│ │ └── headerdialogsample
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── marcoscg
│ │ │ └── headerdialogsample
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-hdpi
│ │ └── ic_action_action_info_outline.png
│ │ ├── drawable-mdpi
│ │ └── ic_action_action_info_outline.png
│ │ ├── drawable-xhdpi
│ │ └── ic_action_action_info_outline.png
│ │ ├── drawable-xxhdpi
│ │ └── ic_action_action_info_outline.png
│ │ ├── drawable-xxxhdpi
│ │ └── ic_action_action_info_outline.png
│ │ ├── drawable
│ │ └── ic_info_outline_black_48dp.png
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── custom.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── marcoscg
│ └── headerdialogsample
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── marcoscg
│ │ └── headerdialog
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ ├── medium.ttf
│ │ └── regular.ttf
│ ├── java
│ │ └── com
│ │ │ └── marcoscg
│ │ │ └── headerdialog
│ │ │ ├── HeaderDialog.java
│ │ │ └── widgets
│ │ │ ├── ContentTextView.java
│ │ │ ├── ContentTextViewJustified.java
│ │ │ └── TitleTextView.java
│ └── res
│ │ ├── drawable
│ │ └── top_shadow.xml
│ │ ├── layout
│ │ └── header_dialog_content.xml
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── marcoscg
│ └── headerdialog
│ └── ExampleUnitTest.java
├── screenshots
├── 1.jpg
└── 2.jpg
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/dictionaries/marco.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Marcos Calvo García
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HeaderDialog [](https://android-arsenal.com/api?level=9) [](https://android-arsenal.com/details/1/5076)
2 | An android library to display a material-designed dialog with header.
3 |
4 | ---
5 |
6 | ## Releases:
7 |
8 | #### Current release: 1.0.6.
9 |
10 | You can see all the library releases [here](https://github.com/marcoscgdev/HeaderDialog/releases).
11 |
12 | ---
13 |
14 | ## Screenshots
15 |
16 |
17 |
18 |
19 |
20 |
21 | ---
22 |
23 | ## Features
24 |
25 | - Roboto font
26 | - LinkMovementMethod support
27 | - Justify text option
28 | - Icon, text and both as header
29 | - Custom header background color
30 | - Custom header text color
31 | - Custom header icon color
32 | - Custom header text gravity
33 | - Custom message text gravity
34 | - Show or hide header shadow
35 | - Multiline header title text option
36 | - Arabic text support
37 | - Custom view support (NEW)
38 |
39 | ---
40 |
41 | ## Usage:
42 |
43 | ### Adding the depencency
44 |
45 | Add this to your root *build.gradle* file:
46 |
47 | ```
48 | allprojects {
49 | repositories {
50 | ...
51 | maven { url 'https://jitpack.io' }
52 | }
53 | }
54 | ```
55 |
56 | Now add the dependency to your app build.gradle file:
57 |
58 | ```
59 | implementation 'com.github.marcoscgdev:HeaderDialog:1.0.6'
60 | ```
61 |
62 | ### Creating the dialog
63 |
64 | Here is a complete snippet of it usage:
65 |
66 | ```java
67 | new HeaderDialog(this)
68 | .setColor(getResources().getColor(R.color.colorAccent)) // Sets the header background color
69 | .setElevation(false) // Sets the header elevation, true by default
70 | .setIcon(getResources().getDrawable(R.drawable.ic_info_outline_black_48dp)) // Sets the dialog icon image
71 | .setTitle(getResources().getString(R.string.library_name)) // Sets the dialog title
72 | .setMessage("Lorem ipsum dolor sit amet...") // Sets the dialog message
73 | .justifyContent(true) // Justifies the message text, false by default
74 | .setTitleColor(Color.parseColor("#212121")) // Sets the header title text color
75 | .setIconColor(Color.parseColor("#212121")) // Sets the header icon color
76 | .setTitleGravity(Gravity.CENTER_HORIZONTAL) // Sets the header title text gravity
77 | .setMessageGravity(Gravity.CENTER_HORIZONTAL) // Sets the message text gravity
78 | .setTitleMultiline(false) // Multiline header title text option, true by default
79 | .setView(R.layout.custom); // Set custom view to the dialog (only possible via layout resource)
80 | .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
81 | public void onClick(DialogInterface dialog, int which) {
82 | // Your action
83 | }
84 | })
85 | .setNegativeButton("Close", null)
86 | .show();
87 | ```
88 |
89 | #### Important note: Do not enable the justified text if you are using html content!
90 |
91 | ### Accessing inflated custom view
92 |
93 | ```java
94 | HeaderDialog headerDialog = new HeaderDialog(this);
95 | ...
96 | headerDialog.show();
97 | headerDialog.getInflatedView().findViewById(R.id.checkbox).setOnClickListener(new View.OnClickListener() {
98 | @Override
99 | public void onClick(View v) {
100 | Toast.makeText(MainActivity.this, "Checkbox clicked!", Toast.LENGTH_SHORT).show();
101 | }
102 | });
103 | ```
104 |
105 | ---
106 | >See the *sample project* to clarify any queries you may have.
107 |
108 | ---
109 |
110 | ## License
111 |
112 | ```
113 | The MIT License (MIT)
114 |
115 | Copyright (c) 2017 Marcos Calvo García
116 |
117 | Permission is hereby granted, free of charge, to any person obtaining a copy
118 | of this software and associated documentation files (the "Software"), to deal
119 | in the Software without restriction, including without limitation the rights
120 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
121 | copies of the Software, and to permit persons to whom the Software is
122 | furnished to do so, subject to the following conditions:
123 |
124 | The above copyright notice and this permission notice shall be included in all
125 | copies or substantial portions of the Software.
126 |
127 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
128 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
129 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
130 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
131 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
132 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
133 | SOFTWARE.
134 | ```
135 |
136 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.marcoscg.headerdialogsample"
7 | minSdkVersion 14
8 | targetSdkVersion 27
9 | versionCode 106
10 | versionName "1.0.6"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:27.1.1'
24 | implementation project(':library')
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 | }
29 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/marcoscg/headerdialogsample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.marcoscg.headerdialogsample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.marcoscg.headerdialogsample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/marcoscg/headerdialogsample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.marcoscg.headerdialogsample;
2 |
3 | import android.content.DialogInterface;
4 | import android.content.Intent;
5 | import android.graphics.Color;
6 | import android.net.Uri;
7 | import android.os.Build;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.os.Bundle;
10 | import android.text.Html;
11 | import android.view.Gravity;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 | import android.view.View;
15 | import android.widget.CheckBox;
16 | import android.widget.CompoundButton;
17 | import android.widget.Toast;
18 |
19 | import com.marcoscg.headerdialog.HeaderDialog;
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 |
28 | if (Build.VERSION.SDK_INT >= 21 && getSupportActionBar()!=null)
29 | getSupportActionBar().setElevation(0f);
30 | }
31 |
32 | public void showHeaderDialog(View v) {
33 | CheckBox hideIcon = (CheckBox) findViewById(R.id.hideIcon);
34 | CheckBox hideTitle = (CheckBox) findViewById(R.id.hideTitle);
35 | CheckBox justify = (CheckBox) findViewById(R.id.justify);
36 |
37 | HeaderDialog headerDialog = new HeaderDialog(this);
38 | headerDialog.setColor(getResources().getColor(R.color.colorAccent));
39 |
40 | if (!hideIcon.isChecked())
41 | headerDialog.setIcon(getResources().getDrawable(R.drawable.ic_info_outline_black_48dp));
42 |
43 | if (!hideTitle.isChecked())
44 | headerDialog.setTitle(getResources().getString(R.string.app_name));
45 |
46 | headerDialog.setMessage(getResources().getString(R.string.lorem));
47 |
48 | if (justify.isChecked())
49 | headerDialog.justifyContent(true);
50 |
51 | headerDialog.setTitleColor(Color.parseColor("#212121"));
52 | headerDialog.setTitleGravity(Gravity.CENTER_HORIZONTAL);
53 | headerDialog.setView(R.layout.custom);
54 | headerDialog.setPositiveButton(android.R.string.ok, null);
55 | headerDialog.show();
56 |
57 | ((CheckBox)headerDialog.getInflatedView().findViewById(R.id.checkbox))
58 | .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
59 | @Override
60 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
61 | Toast.makeText(MainActivity.this, "Checkbox checked: " + isChecked, Toast.LENGTH_SHORT).show();
62 | }
63 | });
64 | }
65 |
66 | @Override
67 | public boolean onCreateOptionsMenu(Menu menu) {
68 | getMenuInflater().inflate(R.menu.menu_main, menu);
69 | return true;
70 | }
71 |
72 | @Override
73 | public boolean onOptionsItemSelected(MenuItem item) {
74 | int id = item.getItemId();
75 | if (id == R.id.action_settings) {
76 | showAboutDialog();
77 | return true;
78 | }
79 | return super.onOptionsItemSelected(item);
80 | }
81 |
82 | public void showAboutDialog() {
83 | String msg = getResources().getString(R.string.about_text);
84 | new HeaderDialog(this)
85 | .setColor(getResources().getColor(R.color.colorAccent))
86 | .setIcon(getResources().getDrawable(R.mipmap.ic_launcher))
87 | .setTitle(getResources().getString(R.string.library_name))
88 | .setMessage(Html.fromHtml(msg))
89 | .setElevation(true)
90 | .justifyContent(false) // Default false
91 | .setTitleColor(getResources().getColor(R.color.colorPrimary))
92 | .setTitleGravity(Gravity.CENTER_HORIZONTAL)
93 | .setMessageGravity(Gravity.CENTER_HORIZONTAL)
94 | .setPositiveButton("Close", null)
95 | .setNeutralButton("View on GitHub", new DialogInterface.OnClickListener() {
96 | public void onClick(DialogInterface dialog, int which) {
97 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/marcoscgdev/HeaderDialog/")));
98 | }
99 | })
100 | .show();
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_action_info_outline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/drawable-hdpi/ic_action_action_info_outline.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_action_info_outline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/drawable-mdpi/ic_action_action_info_outline.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_action_info_outline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/drawable-xhdpi/ic_action_action_info_outline.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_action_info_outline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/drawable-xxhdpi/ic_action_action_info_outline.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_action_action_info_outline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/drawable-xxxhdpi/ic_action_action_info_outline.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_info_outline_black_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/drawable/ic_info_outline_black_48dp.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
24 |
25 |
33 |
34 |
42 |
43 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/custom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #388E3C
4 | #2E7D32
5 | #FF9800
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Header Dialog Sample
3 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
4 | HeaderDialog
5 | Marcos CG.
If you have any queries please don\'t hesitate to contact me.
Facebook Twitter Google+ GitHub Website ]]>
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/com/marcoscg/headerdialogsample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.marcoscg.headerdialogsample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.3'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jul 28 20:22:18 CEST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 27
11 | versionCode 106
12 | versionName "1.0.6"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'com.android.support:appcompat-v7:27.1.1'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
34 | }
35 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/marcoscg/headerdialog/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.marcoscg.headerdialog;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.marcoscg.headerdialog.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/library/src/main/assets/medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/library/src/main/assets/medium.ttf
--------------------------------------------------------------------------------
/library/src/main/assets/regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/library/src/main/assets/regular.ttf
--------------------------------------------------------------------------------
/library/src/main/java/com/marcoscg/headerdialog/HeaderDialog.java:
--------------------------------------------------------------------------------
1 | package com.marcoscg.headerdialog;
2 |
3 | /**
4 | * Created by @MarcosCGdev on 14/01/2017.
5 | */
6 |
7 | import android.content.Context;
8 | import android.graphics.PorterDuff;
9 | import android.graphics.Typeface;
10 | import android.graphics.drawable.Drawable;
11 | import android.support.annotation.LayoutRes;
12 | import android.support.annotation.StringRes;
13 | import android.support.v7.app.AlertDialog;
14 | import android.support.v7.widget.AppCompatImageView;
15 | import android.text.method.LinkMovementMethod;
16 | import android.util.DisplayMetrics;
17 | import android.view.Gravity;
18 | import android.view.LayoutInflater;
19 | import android.view.View;
20 | import android.widget.Button;
21 | import android.widget.LinearLayout;
22 |
23 | import com.marcoscg.headerdialog.widgets.ContentTextView;
24 | import com.marcoscg.headerdialog.widgets.ContentTextViewJustified;
25 | import com.marcoscg.headerdialog.widgets.TitleTextView;
26 |
27 | import java.util.Locale;
28 |
29 | public class HeaderDialog extends AlertDialog.Builder {
30 |
31 | private ContentTextViewJustified ctvj;
32 | private ContentTextView ctv;
33 | private TitleTextView tv;
34 | private AppCompatImageView iv;
35 | private LinearLayout ly;
36 | private LinearLayout customLayout;
37 | private View shadow;
38 | private Context ctx;
39 | private boolean setElevation = true;
40 | private View customInflatedLayout;
41 |
42 | public HeaderDialog(Context context) {
43 | super(context);
44 | ctx = context;
45 | init(context);
46 | }
47 |
48 | public HeaderDialog(final Context context, final int theme) {
49 | super(context, theme);
50 | ctx = context;
51 | init(context);
52 | }
53 |
54 | @Override
55 | public HeaderDialog setTitle(CharSequence title) {
56 | tv.setText(title);
57 | if (Locale.getDefault().getLanguage().equals("ar"))
58 | tv.setGravity(Gravity.RIGHT);
59 | tv.setVisibility(View.VISIBLE);
60 | if (ly.getVisibility() == View.GONE)
61 | ly.setVisibility(View.VISIBLE);
62 | if (shadow.getVisibility() == View.GONE && setElevation)
63 | shadow.setVisibility(View.VISIBLE);
64 | if (iv.getVisibility() == View.VISIBLE)
65 | tv.setPadding(0,dpToPx(8),0,0);
66 | return this;
67 | }
68 |
69 | @Override
70 | public HeaderDialog setTitle(@StringRes int titleRes) {
71 | String title = ctx.getResources().getString(titleRes);
72 | tv.setText(title);
73 | if (Locale.getDefault().getLanguage().equals("ar"))
74 | tv.setGravity(Gravity.RIGHT);
75 | tv.setVisibility(View.VISIBLE);
76 | if (ly.getVisibility() == View.GONE)
77 | ly.setVisibility(View.VISIBLE);
78 | if (shadow.getVisibility() == View.GONE && setElevation)
79 | shadow.setVisibility(View.VISIBLE);
80 | if (iv.getVisibility() == View.VISIBLE)
81 | tv.setPadding(0,dpToPx(8),0,0);
82 | return this;
83 | }
84 |
85 | @Override
86 | public HeaderDialog setMessage(CharSequence message) {
87 | ctv.setText(message);
88 | ctvj.setText(message);
89 | if (Locale.getDefault().getLanguage().equals("ar"))
90 | ctv.setGravity(Gravity.RIGHT);
91 | return this;
92 | }
93 |
94 | @Override
95 | public HeaderDialog setMessage(int messageRes) {
96 | String message = ctx.getResources().getString(messageRes);
97 | ctv.setText(message);
98 | ctvj.setText(message);
99 | if (Locale.getDefault().getLanguage().equals("ar"))
100 | ctv.setGravity(Gravity.RIGHT);
101 | return this;
102 | }
103 |
104 | public HeaderDialog setColor(int color) {
105 | ly.setBackgroundColor(color);
106 | return this;
107 | }
108 |
109 | public HeaderDialog setTitleColor(int color) {
110 | tv.setTextColor(color);
111 | return this;
112 | }
113 |
114 | public HeaderDialog setIconColor(int color) {
115 | if (iv.getDrawable() != null)
116 | iv.getDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
117 | return this;
118 | }
119 |
120 | public HeaderDialog setTitleGravity(int gravity) {
121 | tv.setGravity(gravity);
122 | return this;
123 | }
124 |
125 | public HeaderDialog setMessageGravity(int gravity) {
126 | ctv.setGravity(gravity);
127 | return this;
128 | }
129 |
130 | @Override
131 | public HeaderDialog setIcon(int icon) {
132 | iv.setImageResource(icon);
133 | iv.setVisibility(View.VISIBLE);
134 | if (ly.getVisibility() == View.GONE)
135 | ly.setVisibility(View.VISIBLE);
136 | if (shadow.getVisibility() == View.GONE && setElevation)
137 | shadow.setVisibility(View.VISIBLE);
138 | return this;
139 | }
140 |
141 | @Override
142 | public HeaderDialog setIcon(Drawable icon) {
143 | iv.setImageDrawable(icon);
144 | iv.setVisibility(View.VISIBLE);
145 | if (ly.getVisibility() == View.GONE)
146 | ly.setVisibility(View.VISIBLE);
147 | if (shadow.getVisibility() == View.GONE && setElevation)
148 | shadow.setVisibility(View.VISIBLE);
149 | return this;
150 | }
151 |
152 | @Override
153 | public AlertDialog show() {
154 | AlertDialog alertDialog = super.show();
155 |
156 | Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
157 | "medium.ttf");
158 |
159 | Button bPos = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
160 | Button bNeg = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
161 | Button bNeu = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
162 |
163 | if (bPos!=null)
164 | bPos.setTypeface(tf);
165 |
166 | if (bNeg!=null)
167 | bNeg.setTypeface(tf);
168 |
169 | if (bNeu!=null)
170 | bNeu.setTypeface(tf);
171 |
172 | return alertDialog;
173 | }
174 |
175 | public HeaderDialog justifyContent(boolean justify) {
176 | if (justify) {
177 | if (ctv.getVisibility() == View.VISIBLE)
178 | ctv.setVisibility(View.GONE);
179 | if (ctvj.getVisibility() == View.GONE)
180 | ctvj.setVisibility(View.VISIBLE);
181 | }
182 | else {
183 | if (ctv.getVisibility() == View.GONE)
184 | ctv.setVisibility(View.VISIBLE);
185 | if (ctvj.getVisibility() == View.VISIBLE)
186 | ctvj.setVisibility(View.GONE);
187 | }
188 | return this;
189 | }
190 |
191 | public HeaderDialog setElevation(boolean elevation) {
192 | setElevation = elevation;
193 | return this;
194 | }
195 |
196 | public HeaderDialog setTitleMultiline(boolean multiline) {
197 | if (!multiline)
198 | tv.setMaxLines(1);
199 | return this;
200 | }
201 |
202 | @Override
203 | public HeaderDialog setView(@LayoutRes int layoutRes) {
204 | customInflatedLayout = LayoutInflater.from(customLayout.getContext()).inflate(layoutRes, customLayout, false);
205 | customLayout.addView(customInflatedLayout);
206 | return this;
207 | }
208 |
209 | public View getInflatedView() {
210 | return customInflatedLayout;
211 | }
212 |
213 | private void init(Context context) {
214 | View view = LayoutInflater.from(context).inflate(R.layout.header_dialog_content, null);
215 | ctvj = (ContentTextViewJustified) view.findViewById(R.id.content_justified);
216 | ctv = (ContentTextView) view.findViewById(R.id.content);
217 | tv = (TitleTextView) view.findViewById(R.id.title);
218 | tv.setGravity(Gravity.CENTER_HORIZONTAL);
219 | ctv.setMovementMethod(LinkMovementMethod.getInstance());
220 | iv = (AppCompatImageView) view.findViewById(R.id.icon);
221 | ly = (LinearLayout) view.findViewById(R.id.layout);
222 | shadow = view.findViewById(R.id.top_shadow);
223 | customLayout = (LinearLayout) view.findViewById(R.id.contentView);
224 | setView(view);
225 | }
226 |
227 | private int dpToPx(int dp) {
228 | DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
229 | return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
230 | }
231 |
232 | }
233 |
--------------------------------------------------------------------------------
/library/src/main/java/com/marcoscg/headerdialog/widgets/ContentTextView.java:
--------------------------------------------------------------------------------
1 | package com.marcoscg.headerdialog.widgets;
2 |
3 | /**
4 | * Created by marcos on 15/01/2017.
5 | */
6 |
7 | import android.content.Context;
8 | import android.graphics.Typeface;
9 | import android.support.v7.widget.AppCompatTextView;
10 | import android.util.AttributeSet;
11 |
12 | public class ContentTextView extends AppCompatTextView {
13 |
14 | public ContentTextView(Context context) {
15 | super(context);
16 | init();
17 | }
18 |
19 | public ContentTextView(Context context, AttributeSet attrs) {
20 | super(context, attrs);
21 | init();
22 | }
23 |
24 | public ContentTextView(Context context, AttributeSet attrs, int defStyle) {
25 | super(context, attrs, defStyle);
26 | init();
27 | }
28 |
29 | private void init() {
30 | Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
31 | "regular.ttf");
32 | setTypeface(tf);
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/marcoscg/headerdialog/widgets/ContentTextViewJustified.java:
--------------------------------------------------------------------------------
1 | package com.marcoscg.headerdialog.widgets;
2 |
3 | /**
4 | * Created by marcos on 15/01/2017.
5 | */
6 |
7 | import android.annotation.TargetApi;
8 | import android.content.Context;
9 | import android.graphics.Canvas;
10 | import android.graphics.Typeface;
11 | import android.os.Build;
12 | import android.support.v7.widget.AppCompatTextView;
13 | import android.text.Layout;
14 | import android.text.StaticLayout;
15 | import android.text.TextPaint;
16 | import android.util.AttributeSet;
17 |
18 | public final class ContentTextViewJustified extends AppCompatTextView {
19 |
20 | public ContentTextViewJustified(Context context) {
21 | super(context);
22 | init();
23 | }
24 |
25 | public ContentTextViewJustified(Context context, AttributeSet attrs) {
26 | super(context, attrs);
27 | init();
28 | }
29 |
30 | public ContentTextViewJustified(Context context, AttributeSet attrs, int defStyleAttr) {
31 | super(context, attrs, defStyleAttr);
32 | init();
33 | }
34 |
35 | @Override
36 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
37 | super.onLayout(changed, left, top, right, bottom);
38 | }
39 |
40 | @Override
41 | protected void onDraw(Canvas canvas) {
42 | TextPaint paint = getPaint();
43 | paint.setColor(getCurrentTextColor());
44 | paint.drawableState = getDrawableState();
45 |
46 | String text = getText().toString();
47 |
48 | float lineY = 0;
49 | lineY += getTextSize() * 1f;
50 |
51 | final Layout layout = getLayout();
52 | final float desiredLineWidth = getMeasuredWidth();
53 |
54 | for (int i = 0, lineCount = layout.getLineCount(); i < lineCount; i++) {
55 | int lineStart = layout.getLineStart(i);
56 | int lineEnd = layout.getLineEnd(i);
57 | String line = text.substring(lineStart, lineEnd);
58 |
59 | if (needScale(line) && i < lineCount - 1) {
60 | drawScaledText(line, canvas, lineY, desiredLineWidth, paint);
61 | } else {
62 | canvas.drawText(line, 0, lineY, paint);
63 | }
64 |
65 | lineY += getLineHeight();
66 | }
67 | }
68 |
69 | private void drawScaledText(final String line, final Canvas canvas, final float y, final float desiredLineWidth, final TextPaint paint) {
70 | String[] words = line.split(" ");
71 |
72 | float lineWidthWithoutSpaces = StaticLayout.getDesiredWidth(line.replace(" ", ""), getPaint());
73 | float spacing = (desiredLineWidth - lineWidthWithoutSpaces) / (words.length - 1);
74 |
75 | float x = 0;
76 | for (String word : words) {
77 | float cw = StaticLayout.getDesiredWidth(word, paint);
78 | canvas.drawText(word, x, y, paint);
79 | x += cw + spacing;
80 | }
81 | }
82 |
83 | private boolean needScale(String line) {
84 | if (line.length() == 0) {
85 | return false;
86 | } else {
87 | return line.charAt(line.length() - 1) != '\n';
88 | }
89 | }
90 | private void init() {
91 | Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
92 | "regular.ttf");
93 | setTypeface(tf);
94 | }
95 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/marcoscg/headerdialog/widgets/TitleTextView.java:
--------------------------------------------------------------------------------
1 | package com.marcoscg.headerdialog.widgets;
2 |
3 | /**
4 | * Created by marcos on 15/01/2017.
5 | */
6 |
7 | import android.content.Context;
8 | import android.graphics.Typeface;
9 | import android.support.v7.widget.AppCompatTextView;
10 | import android.util.AttributeSet;
11 |
12 | public class TitleTextView extends AppCompatTextView {
13 |
14 | public TitleTextView(Context context) {
15 | super(context);
16 | init();
17 | }
18 |
19 | public TitleTextView(Context context, AttributeSet attrs) {
20 | super(context, attrs);
21 | init();
22 | }
23 |
24 | public TitleTextView(Context context, AttributeSet attrs, int defStyle) {
25 | super(context, attrs, defStyle);
26 | init();
27 | }
28 |
29 | private void init() {
30 | Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
31 | "medium.ttf");
32 | setTypeface(tf);
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/library/src/main/res/drawable/top_shadow.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/header_dialog_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
22 |
23 |
31 |
32 |
33 |
34 |
39 |
40 |
44 |
45 |
55 |
56 |
67 |
68 |
73 |
74 |
75 |
76 |
77 |
78 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Header Dialog
3 |
4 |
--------------------------------------------------------------------------------
/library/src/test/java/com/marcoscg/headerdialog/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.marcoscg.headerdialog;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/screenshots/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/screenshots/1.jpg
--------------------------------------------------------------------------------
/screenshots/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoscgdev/HeaderDialog/e27aaa575f22b1ac0f2e9254add32fc2a8518244/screenshots/2.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------