Skip to content

Commit

Permalink
Merge branch 'material'
Browse files Browse the repository at this point in the history
  • Loading branch information
David Vavra committed Jan 8, 2015
2 parents 72dbc10 + 6032403 commit 712f1f0
Show file tree
Hide file tree
Showing 87 changed files with 1,389 additions and 1,973 deletions.
66 changes: 16 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,45 @@
# StyledDialogs for Android

This library makes styling and using dialogs _a piece of cake_.

![Screenshot of the dialogs](graphics/screenshot-small.png)

Features:

- Compatible with Holo style and **Android Design Guidelines**
- Change style for all dialogs only by changing a **few color resources**
- Compatible with **Material Design Guidelines**
- Same look for **Android 2.2+**
- **Same API** as native Android DialogFragments
- `SimpleDialogFragment` class, which makes displaying simple dialogs a **one line of code**
- `ListDialogFragment`, `DatePickerDialogFragment` and `TimePickerDialogFragment`
- Built on top of standard **DialogFragment**
- Supports stacked buttons, neutral button, callbacks even after rotation
- Contains even more specialized dialogs: List, Progress, Time&Date Picker, Custom, ...

## How to include it in your project:

With Gradle:
```groovy
compile 'eu.inmite.android.lib:android-styled-dialogs:1.2.0'
dependencies {
compile 'com.avast:android-styled-dialogs:2.0.0'
}
```

With Maven:
```xml
<dependency>
<groupId>eu.inmite.android.lib</groupId>
<artifactId>android-styled-dialogs</artifactId>
<version>1.2.0</version>
<type>aar</type>
</dependency>
```

Manually:

- clone the project
- add it as library project in your IDE
- include latest support library
(from [jcenter](https://bintray.com/avast/android/styled-dialogs/))

## How to style all dialogs:

Add following into your application theme:
```xml
<item name="sdlDialogStyle">@style/DialogStyleLight.Custom</item>
```
or
```xml
<item name="sdlDialogStyle">@style/DialogStyleDark.Custom</item>
```
Define your dialog style, example for light theme:
It uses standard Material colors, for example like this:

```xml
<style name="DialogStyleLight.Custom">
<!-- anything can be left out: -->
<item name="titleTextColor">@color/dialog_title_text</item>
<item name="titleSeparatorColor">@color/dialog_title_separator</item>
<item name="messageTextColor">@color/dialog_message_text</item>
<item name="buttonTextColor">@color/dialog_button_text</item>
<item name="buttonSeparatorColor">@color/dialog_button_separator</item>
<item name="buttonBackgroundColorNormal">@color/dialog_button_normal</item>
<item name="buttonBackgroundColorPressed">@color/dialog_button_pressed</item>
<item name="buttonBackgroundColorFocused">@color/dialog_button_focused</item>
<item name="dialogBackground">@drawable/dialog_background</item>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/indigo</item>
<item name="colorPrimaryDark">@color/indigo_dark</item>
<item name="colorAccent">@color/pink</item>
</style>
```

## How to create simple dialogs:

Easy:

### Dialog with a simple message and Close button:
### Dialog with a simple message only:
```java
SimpleDialogFragment.createBuilder(this, getSupportFragmentManager()).setMessage(R.string.message).show();
```
### Dialog with a title, message and Close button:
```java
SimpleDialogFragment.createBuilder(this, getSupportFragmentManager()).setTitle(R.string.title).setMessage(R.string.message).show();
```

### Dialog with a title, message and two buttons:
```java
SimpleDialogFragment.createBuilder(this, getSupportFragmentManager()).setTitle(R.string.title).setMessage(R.string.message).setPositiveButtonText(R.string.positive_button).setNegativeButtonText(R.string.negative_button).show();
Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
repositories {
mavenCentral()
jcenter()
}

dependencies {
Expand All @@ -9,12 +9,14 @@ buildscript {
}

allprojects {
version = VERSION_NAME
group = GROUP

repositories {
mavenCentral()
jcenter()
}
}

ext {
VERSION_NAME = "2.0.1"
VERSION_CODE = 6
}

apply plugin: 'android-reporting'
6 changes: 3 additions & 3 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ android {
buildToolsVersion "20"

defaultConfig {
minSdkVersion 7
minSdkVersion 8
targetSdkVersion 21
versionName project.VERSION_NAME
versionCode Integer.parseInt(project.VERSION_CODE)
versionCode project.VERSION_CODE
}
}

dependencies {
compile project(':library')
compile project(":library")
}
13 changes: 4 additions & 9 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.inmite.demo.dialogs"
android:versionCode="1"
android:versionName="1.0">
package="com.avast.dialogs">

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/CustomDarkTheme">
android:theme="@style/AppTheme"
android:allowBackup="true">
<activity
android:name=".MyActivity"
android:label="@string/app_name">
android:name=".DemoActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
221 changes: 221 additions & 0 deletions demo/src/main/java/com/avast/dialogs/DemoActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/*
* 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.avast.dialogs;

import java.text.DateFormat;
import java.util.Date;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Toast;

import com.avast.android.dialogs.fragment.*;
import com.avast.android.dialogs.iface.IDateDialogListener;
import com.avast.android.dialogs.iface.IListDialogListener;
import com.avast.android.dialogs.iface.ISimpleDialogCancelListener;
import com.avast.android.dialogs.iface.ISimpleDialogListener;

public class DemoActivity extends ActionBarActivity implements
ISimpleDialogListener,
IDateDialogListener,
ISimpleDialogCancelListener,
IListDialogListener {

private static final int REQUEST_PROGRESS = 1;

DemoActivity c = this;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.message_dialog).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SimpleDialogFragment.createBuilder(c, getSupportFragmentManager())
.setMessage("Love. Can know all the math in the \'verse but take a boat in the air that you don\'t " +
"love? She\'ll shake you off just as sure as a turn in the worlds. Love keeps her in the air when " +
"she oughtta fall down...tell you she\'s hurtin\' \'fore she keens...makes her a home.").show();
}
});
findViewById(R.id.message_title_dialog).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SimpleDialogFragment.createBuilder(c, getSupportFragmentManager())
.setTitle("More Firefly quotes:").setMessage
("Wash: \"Psychic, though? That sounds like something out of science fiction.\"\n\nZoe: \"We live" +
" " +
"in a space ship, dear.\"\nWash: \"Here lies my beloved Zoe, " +
("my autumn flower ... somewhat less attractive now that she's all corpsified and gross" +
".\"\n\nRiver Tam: \"Also? I can kill you with my brain.\"\n\nKayle: \"Going on a year now, nothins twixed my neathers not run on batteries.\" \n" +
"Mal: \"I can't know that.\" \n" +
"Jayne: \"I can stand to hear a little more.\"\n\nWash: \"I've been under fire before. " +
"Well ... I've been in a fire. Actually, I was fired. I can handle myself.\""))
.setNegativeButtonText("Close")
.show();
}
});
findViewById(R.id.message_title_buttons_dialog)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SimpleDialogFragment.createBuilder(c, getSupportFragmentManager())
.setTitle("Do you like this quote?")
.setMessage("Jayne: \"Shiny. Let's be bad guys.\"")
.setPositiveButtonText("Love")
.setNegativeButtonText("Hate").setNeutralButtonText("WTF?").setRequestCode(42)
.show();
}
});
findViewById(R.id.long_buttons).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SimpleDialogFragment.createBuilder(c, getSupportFragmentManager()).setMessage("How will you decide?")
.setPositiveButtonText("Time for some thrillin' heroics!").setNegativeButtonText("Misbehave")
.setNeutralButtonText("Keep flying").show();
}
});
findViewById(R.id.progress_dialog).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ProgressDialogFragment.createBuilder(c, getSupportFragmentManager())
.setMessage("Mal: I\'m just waiting to see if I pass out. Long story.")
.setRequestCode(REQUEST_PROGRESS)
.show();
}
});
findViewById(R.id.list_dialog).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ListDialogFragment
.createBuilder(c, getSupportFragmentManager())
.setTitle("Your favorite character:")
.setItems(new String[]{"Jayne", "Malcolm", "Kaylee",
"Wash", "Zoe", "River"})
.show();

}
});
findViewById(R.id.custom_dialog).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
JayneHatDialogFragment.show(c);
}
});
findViewById(R.id.time_picker).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TimePickerDialogFragment
.createBuilder(DemoActivity.this, getSupportFragmentManager())
.setDate(new Date())
.set24hour(true)
.setPositiveButtonText(android.R.string.ok)
.setNegativeButtonText(android.R.string.cancel)
.setRequestCode(13)
.show();
}
});
findViewById(R.id.date_picker).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatePickerDialogFragment
.createBuilder(DemoActivity.this, getSupportFragmentManager())
.setDate(new Date())
.set24hour(true)
.setPositiveButtonText(android.R.string.ok)
.setNegativeButtonText(android.R.string.cancel)
.setRequestCode(12)
.show();
}
});
}

// IListDialogListener

@Override
public void onListItemSelected(String value, int number) {
Toast.makeText(c, "Selected: " + value, Toast.LENGTH_SHORT).show();
}

@Override
public void onCancelled() {
Toast.makeText(c, "Nothing selected", Toast.LENGTH_SHORT).show();
}

// ISimpleDialogCancelListener

@Override
public void onCancelled(int requestCode) {
if (requestCode == 42) {
Toast.makeText(c, "Dialog cancelled", Toast.LENGTH_SHORT).show();
} else if (requestCode == REQUEST_PROGRESS) {
Toast.makeText(c, "Progress dialog cancelled", Toast.LENGTH_SHORT).show();
}
}

// ISimpleDialogListener

@Override
public void onPositiveButtonClicked(int requestCode) {
if (requestCode == 42) {
Toast.makeText(c, "Positive button clicked", Toast.LENGTH_SHORT).show();
}
}

@Override
public void onNegativeButtonClicked(int requestCode) {
if (requestCode == 42) {
Toast.makeText(c, "Negative button clicked", Toast.LENGTH_SHORT).show();
}
}

@Override
public void onNeutralButtonClicked(int requestCode) {
if (requestCode == 42) {
Toast.makeText(c, "Neutral button clicked", Toast.LENGTH_SHORT).show();
}
}

// IDateDialogListener

@Override
public void onNegativeButtonClicked(int resultCode, Date date) {
String text = "";
if (resultCode == 12) {
text = "Date ";
} else if (resultCode == 13) {
text = "Time ";
}

DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT);
Toast.makeText(this, text + "Cancelled " + dateFormat.format(date), Toast.LENGTH_SHORT).show();
}

@Override
public void onPositiveButtonClicked(int resultCode, Date date) {
String text = "";
if (resultCode == 12) {
text = "Date ";
} else if (resultCode == 13) {
text = "Time ";
}

DateFormat dateFormat = DateFormat.getDateTimeInstance();
Toast.makeText(this, text + "Success! " + dateFormat.format(date), Toast.LENGTH_SHORT).show();
}
}
Loading

0 comments on commit 712f1f0

Please sign in to comment.