Skip to content

Commit 995cb30

Browse files
author
Yoav Sternberg
committed
Support for dialogs
1 parent 74527c0 commit 995cb30

4 files changed

Lines changed: 240 additions & 2 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
tools:layout_height="260dp"
7+
tools:layout_width="260dp"
8+
tools:paddingTop="60dp">
9+
10+
<TextView
11+
android:id="@+id/text"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:textColor="@android:color/black"
15+
android:layout_marginTop="10dp"
16+
android:layout_centerHorizontal="true"
17+
android:gravity="center"
18+
android:textSize="16sp"
19+
tools:text="New Quick Circle apps were installed." />
20+
21+
<ImageView
22+
android:id="@+id/image"
23+
android:layout_width="60dp"
24+
android:layout_height="60dp"
25+
android:layout_below="@+id/text"
26+
android:layout_centerHorizontal="true"
27+
android:layout_marginTop="20dp" />
28+
29+
<LinearLayout
30+
android:layout_width="match_parent"
31+
android:layout_height="60dp"
32+
android:layout_alignParentBottom="true"
33+
android:orientation="horizontal">
34+
35+
<Button
36+
android:id="@+id/positive"
37+
android:layout_width="0dp"
38+
android:layout_height="match_parent"
39+
android:layout_weight="1"
40+
android:background="@drawable/back_button_background"
41+
android:text="@android:string/ok"
42+
android:textColor="#4C89B8" />
43+
44+
<Button
45+
android:id="@+id/negative"
46+
android:layout_width="0dp"
47+
android:layout_height="match_parent"
48+
android:layout_weight="1"
49+
android:background="@drawable/back_button_background"
50+
android:text="@android:string/cancel"
51+
android:textColor="#4C89B8" />
52+
</LinearLayout>
53+
</RelativeLayout>

QCircle-Design-Template/res/values/colors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
<color name="back_button_color_dark_pressed">#78909C</color>
77
<color name="back_button_color_semi_transparent_normal">#30000000</color>
88
<color name="back_button_color_semi_transparent_pressed">#60000000</color>
9+
<color name="dialog_title_background_color_regular">#669B9F</color>
10+
<color name="dialog_title_background_color_error">#DC4439</color>
911
</resources>
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
package com.lge.qcircle.template;
2+
3+
import android.annotation.SuppressLint;
4+
import android.app.Activity;
5+
import android.graphics.Color;
6+
import android.graphics.drawable.Drawable;
7+
import android.view.View;
8+
import android.widget.Button;
9+
import android.widget.ImageView;
10+
import android.widget.RelativeLayout;
11+
import android.widget.TextView;
12+
13+
/**
14+
* Created by Yoav.
15+
*/
16+
public class QCircleDialog {
17+
Activity activity;
18+
QCircleTemplate activityTemplate;
19+
// Dialog properties
20+
String title;
21+
String text;
22+
String positiveButtonText;
23+
String negativeButtonText;
24+
Drawable image;
25+
View.OnClickListener positiveButtonListener;
26+
View.OnClickListener negativeButtonListener;
27+
DialogMode mode;
28+
View templateLayout;
29+
30+
private QCircleDialog(Builder builder) {
31+
this.title = builder.title;
32+
this.text = builder.text;
33+
this.positiveButtonText = builder.positiveButtonText;
34+
this.negativeButtonText = builder.negativeButtonText;
35+
this.image = builder.image;
36+
this.positiveButtonListener = builder.positiveButtonListener;
37+
this.negativeButtonListener = builder.negativeButtonListener;
38+
this.mode = builder.mode;
39+
}
40+
41+
public static class Builder {
42+
private String title = null;
43+
private String text;
44+
private String positiveButtonText;
45+
private String negativeButtonText;
46+
private Drawable image = null;
47+
private View.OnClickListener positiveButtonListener;
48+
private View.OnClickListener negativeButtonListener = null;
49+
private QCircleDialog.DialogMode mode = DialogMode.Ok;
50+
51+
public Builder setTitle(String title) {
52+
this.title = title;
53+
return this;
54+
}
55+
56+
public Builder setText(String text) {
57+
this.text = text;
58+
return this;
59+
}
60+
61+
public Builder setImage(Drawable image) {
62+
this.image = image;
63+
return this;
64+
}
65+
66+
public Builder setPositiveButtonListener(View.OnClickListener positiveButtonListener) {
67+
this.positiveButtonListener = positiveButtonListener;
68+
return this;
69+
}
70+
71+
public Builder setNegativeButtonListener(View.OnClickListener negativeButtonListener) {
72+
this.negativeButtonListener = negativeButtonListener;
73+
return this;
74+
}
75+
76+
public Builder setMode(QCircleDialog.DialogMode mode) {
77+
this.mode = mode;
78+
return this;
79+
}
80+
81+
public void setPositiveButtonText(String positiveButtonText) {
82+
this.positiveButtonText = positiveButtonText;
83+
}
84+
85+
public void setNegativeButtonText(String negativeButtonText) {
86+
this.negativeButtonText = negativeButtonText;
87+
}
88+
89+
public QCircleDialog create() {
90+
return new QCircleDialog(this);
91+
}
92+
}
93+
94+
/**
95+
* Show the dialog
96+
*
97+
* @param activity The activity
98+
* @param activityTemplate The template that the activity uses
99+
*/
100+
public void show(Activity activity, QCircleTemplate activityTemplate) {
101+
this.activity = activity;
102+
this.activityTemplate = activityTemplate;
103+
RelativeLayout layout = (RelativeLayout) activityTemplate.getLayoutById(TemplateTag.CONTENT).getParent();
104+
QCircleTemplate template = new QCircleTemplate(activity);
105+
template.setTitle(title == null ? "" : title, Color.WHITE, activity.getResources().getColor(
106+
mode == DialogMode.Error ? R.color.dialog_title_background_color_error : R.color.dialog_title_background_color_regular));
107+
template.setTitleTextSize(17);
108+
RelativeLayout dialogLayout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.qcircle_dialog_layout, layout, false);
109+
if (text != null) {
110+
((TextView) dialogLayout.findViewById(R.id.text)).setText(text);
111+
}
112+
if (image != null) {
113+
((ImageView) dialogLayout.findViewById(R.id.image)).setImageDrawable(image);
114+
}
115+
switch (mode) {
116+
case YesNo:
117+
Button negativeButton = (Button) dialogLayout.findViewById(R.id.negative);
118+
if (negativeButtonText != null) {
119+
negativeButton.setText(negativeButtonText);
120+
}
121+
negativeButton.setOnClickListener(new View.OnClickListener() {
122+
@Override
123+
public void onClick(View v) {
124+
if (negativeButtonListener != null) negativeButtonListener.onClick(v);
125+
hide();
126+
}
127+
});
128+
case Ok:
129+
Button positiveButton = (Button) dialogLayout.findViewById(R.id.positive);
130+
if (positiveButtonText != null) {
131+
positiveButton.setText(positiveButtonText);
132+
}
133+
positiveButton.setOnClickListener(new View.OnClickListener() {
134+
@Override
135+
public void onClick(View v) {
136+
if (positiveButtonListener != null) positiveButtonListener.onClick(v);
137+
hide();
138+
}
139+
});
140+
break;
141+
case Error:
142+
@SuppressLint("CutPasteId")
143+
Button errorButton = (Button) dialogLayout.findViewById(R.id.positive);
144+
if (negativeButtonText != null) {
145+
errorButton.setText(negativeButtonText);
146+
}
147+
errorButton.setOnClickListener(new View.OnClickListener() {
148+
@Override
149+
public void onClick(View v) {
150+
if (negativeButtonListener != null) negativeButtonListener.onClick(v);
151+
hide();
152+
}
153+
});
154+
break;
155+
156+
}
157+
if (mode != DialogMode.YesNo)
158+
dialogLayout.findViewById(R.id.negative).setVisibility(View.GONE);
159+
template.getLayoutById(TemplateTag.CONTENT).addView(dialogLayout);
160+
layout.addView(templateLayout = template.getView());
161+
162+
}
163+
164+
public void hide() {
165+
((RelativeLayout) activityTemplate.getLayoutById(TemplateTag.CONTENT).getParent()).removeView(templateLayout);
166+
templateLayout = null;
167+
}
168+
169+
public enum DialogMode {
170+
/**
171+
* A dialog with yes and no buttons.
172+
*/
173+
YesNo,
174+
/**
175+
* A dialog with ok button only.
176+
*/
177+
Ok,
178+
/**
179+
* An error dialog. Shows only back button, which finish the activity.
180+
*/
181+
Error
182+
}
183+
}

QCircle-Design-Template/src/com/lge/qcircle/template/QCircleTitle.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final class QCircleTitle {
2424
/**
2525
* creates a title bar with a text.
2626
* <p>
27-
* It makes a {@link TextView} with the given text.
27+
* It makes a {@link android.widget.TextView} with the given text.
2828
*
2929
* @param title title text for the title. <br>
3030
* If it is null, no title text will be shown but the title bar will occupy some
@@ -39,7 +39,7 @@ public QCircleTitle(Context context, String title) {
3939
/**
4040
* creates a title bar with a text.
4141
* <p>
42-
* It makes a {@link TextView} with the given text.
42+
* It makes a {@link android.widget.TextView} with the given text.
4343
*
4444
* @param title title text for the title. <br>
4545
* If it is null, no title text will be shown but the title bar will occupy some

0 commit comments

Comments
 (0)