diff --git a/.classpath b/.classpath
index bb0c759..5176974 100644
--- a/.classpath
+++ b/.classpath
@@ -1,9 +1,9 @@
-
-
-
+
+
+
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5a83dd9..25df2db 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -4,13 +4,13 @@
android:versionName="1.0" >
+ android:minSdkVersion="7"
+ android:targetSdkVersion="19" />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/bin/TestDialogActivity.apk b/bin/TestDialogActivity.apk
deleted file mode 100644
index 3c3e811..0000000
Binary files a/bin/TestDialogActivity.apk and /dev/null differ
diff --git a/bin/classes.dex b/bin/classes.dex
deleted file mode 100644
index fcd9d78..0000000
Binary files a/bin/classes.dex and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/BuildConfig.class b/bin/classes/com/qustom/dialog/BuildConfig.class
deleted file mode 100644
index 892ee35..0000000
Binary files a/bin/classes/com/qustom/dialog/BuildConfig.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/QustomDialogBuilder.class b/bin/classes/com/qustom/dialog/QustomDialogBuilder.class
deleted file mode 100644
index 0de933b..0000000
Binary files a/bin/classes/com/qustom/dialog/QustomDialogBuilder.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/R$attr.class b/bin/classes/com/qustom/dialog/R$attr.class
deleted file mode 100644
index f982427..0000000
Binary files a/bin/classes/com/qustom/dialog/R$attr.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/R$dimen.class b/bin/classes/com/qustom/dialog/R$dimen.class
deleted file mode 100644
index 14fbd69..0000000
Binary files a/bin/classes/com/qustom/dialog/R$dimen.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/R$drawable.class b/bin/classes/com/qustom/dialog/R$drawable.class
deleted file mode 100644
index 6280691..0000000
Binary files a/bin/classes/com/qustom/dialog/R$drawable.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/R$id.class b/bin/classes/com/qustom/dialog/R$id.class
deleted file mode 100644
index 881163f..0000000
Binary files a/bin/classes/com/qustom/dialog/R$id.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/R$layout.class b/bin/classes/com/qustom/dialog/R$layout.class
deleted file mode 100644
index 4b56948..0000000
Binary files a/bin/classes/com/qustom/dialog/R$layout.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/R$string.class b/bin/classes/com/qustom/dialog/R$string.class
deleted file mode 100644
index 8ab8703..0000000
Binary files a/bin/classes/com/qustom/dialog/R$string.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/R$style.class b/bin/classes/com/qustom/dialog/R$style.class
deleted file mode 100644
index 18f626c..0000000
Binary files a/bin/classes/com/qustom/dialog/R$style.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/R.class b/bin/classes/com/qustom/dialog/R.class
deleted file mode 100644
index 8690898..0000000
Binary files a/bin/classes/com/qustom/dialog/R.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/TestDialogActivity$1.class b/bin/classes/com/qustom/dialog/TestDialogActivity$1.class
deleted file mode 100644
index 4af623f..0000000
Binary files a/bin/classes/com/qustom/dialog/TestDialogActivity$1.class and /dev/null differ
diff --git a/bin/classes/com/qustom/dialog/TestDialogActivity.class b/bin/classes/com/qustom/dialog/TestDialogActivity.class
deleted file mode 100644
index 2fece7d..0000000
Binary files a/bin/classes/com/qustom/dialog/TestDialogActivity.class and /dev/null differ
diff --git a/bin/dexedLibs/android-support-v4-353b7052ee16442a9b3c90a1b3907007.jar b/bin/dexedLibs/android-support-v4-353b7052ee16442a9b3c90a1b3907007.jar
deleted file mode 100644
index 10eddc6..0000000
Binary files a/bin/dexedLibs/android-support-v4-353b7052ee16442a9b3c90a1b3907007.jar and /dev/null differ
diff --git a/bin/jarlist.cache b/bin/jarlist.cache
deleted file mode 100644
index 0565465..0000000
--- a/bin/jarlist.cache
+++ /dev/null
@@ -1,3 +0,0 @@
-# cache for current jar dependency. DO NOT EDIT.
-# format is
-# Encoding is UTF-8
diff --git a/bin/res/drawable-hdpi/ic_action_search.png b/bin/res/drawable-hdpi/ic_action_search.png
deleted file mode 100644
index ffec9be..0000000
Binary files a/bin/res/drawable-hdpi/ic_action_search.png and /dev/null differ
diff --git a/bin/res/drawable-hdpi/ic_launcher.png b/bin/res/drawable-hdpi/ic_launcher.png
deleted file mode 100644
index 2642d5d..0000000
Binary files a/bin/res/drawable-hdpi/ic_launcher.png and /dev/null differ
diff --git a/bin/res/drawable-ldpi/ic_launcher.png b/bin/res/drawable-ldpi/ic_launcher.png
deleted file mode 100644
index 28424c3..0000000
Binary files a/bin/res/drawable-ldpi/ic_launcher.png and /dev/null differ
diff --git a/bin/res/drawable-mdpi/ic_action_search.png b/bin/res/drawable-mdpi/ic_action_search.png
deleted file mode 100644
index ce9399c..0000000
Binary files a/bin/res/drawable-mdpi/ic_action_search.png and /dev/null differ
diff --git a/bin/res/drawable-mdpi/ic_launcher.png b/bin/res/drawable-mdpi/ic_launcher.png
deleted file mode 100644
index 312d96f..0000000
Binary files a/bin/res/drawable-mdpi/ic_launcher.png and /dev/null differ
diff --git a/bin/res/drawable-xhdpi/ic_action_search.png b/bin/res/drawable-xhdpi/ic_action_search.png
deleted file mode 100644
index b2d7b2d..0000000
Binary files a/bin/res/drawable-xhdpi/ic_action_search.png and /dev/null differ
diff --git a/bin/res/drawable-xhdpi/ic_launcher.png b/bin/res/drawable-xhdpi/ic_launcher.png
deleted file mode 100644
index 2a66d4d..0000000
Binary files a/bin/res/drawable-xhdpi/ic_launcher.png and /dev/null differ
diff --git a/bin/resources.ap_ b/bin/resources.ap_
deleted file mode 100644
index 0bb61d9..0000000
Binary files a/bin/resources.ap_ and /dev/null differ
diff --git a/build.gradle b/build.gradle
index efde5e4..6144bcc 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,21 +3,23 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:0.6+'
+ classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
dependencies {
+ compile 'com.android.support:support-v4:19.1.+'
+ compile 'com.android.support:appcompat-v7:19.1.+'
}
android {
- compileSdkVersion 17
- buildToolsVersion "17"
+ compileSdkVersion 19
+ buildToolsVersion "19.0.1"
defaultConfig {
- minSdkVersion 14
- targetSdkVersion 17
+ minSdkVersion 7
+ targetSdkVersion 19
}
sourceSets {
main {
diff --git a/gen/com/qustom/dialog/BuildConfig.java b/gen/com/qustom/dialog/BuildConfig.java
deleted file mode 100644
index 67cdf1a..0000000
--- a/gen/com/qustom/dialog/BuildConfig.java
+++ /dev/null
@@ -1,6 +0,0 @@
-/** Automatically generated file. DO NOT MODIFY */
-package com.qustom.dialog;
-
-public final class BuildConfig {
- public final static boolean DEBUG = true;
-}
\ No newline at end of file
diff --git a/gen/com/qustom/dialog/R.java b/gen/com/qustom/dialog/R.java
deleted file mode 100644
index 6b21a29..0000000
--- a/gen/com/qustom/dialog/R.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/* AUTO-GENERATED FILE. DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found. It
- * should not be modified by hand.
- */
-
-package com.qustom.dialog;
-
-public final class R {
- public static final class attr {
- }
- public static final class dimen {
- public static final int padding_large=0x7f040002;
- public static final int padding_medium=0x7f040001;
- public static final int padding_small=0x7f040000;
- }
- public static final class drawable {
- public static final int ic_action_search=0x7f020000;
- public static final int ic_launcher=0x7f020001;
- }
- public static final class id {
- public static final int alertTitle=0x7f070007;
- public static final int button1=0x7f070000;
- public static final int contentPanel=0x7f070009;
- public static final int customPanel=0x7f07000b;
- public static final int icon=0x7f070006;
- public static final int ip_edit_text=0x7f070002;
- public static final int ip_text=0x7f070001;
- public static final int message=0x7f07000a;
- public static final int parentPanel=0x7f070003;
- public static final int titleDivider=0x7f070008;
- public static final int title_template=0x7f070005;
- public static final int topPanel=0x7f070004;
- }
- public static final class layout {
- public static final int activity_main=0x7f030000;
- public static final int example_ip_address_layout=0x7f030001;
- public static final int qustom_dialog_layout=0x7f030002;
- }
- public static final class string {
- public static final int alert_image_content_description=0x7f050002;
- public static final int app_name=0x7f050000;
- public static final int main_button_text=0x7f050001;
- }
- public static final class style {
- public static final int SnapchatTheme=0x7f060000;
- }
-}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index fc70cb0..5a4393c 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Sun Dec 15 05:23:25 PST 2013
+#Thu Feb 13 00:16:26 EET 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
diff --git a/project.properties b/project.properties
index a3ee5ab..4ab1256 100644
--- a/project.properties
+++ b/project.properties
@@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
-target=android-17
+target=android-19
diff --git a/res/layout-v11/qustom_dialog_items_divider.xml b/res/layout-v11/qustom_dialog_items_divider.xml
new file mode 100644
index 0000000..420bb6c
--- /dev/null
+++ b/res/layout-v11/qustom_dialog_items_divider.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml
index 3b9cd8d..ef233e9 100644
--- a/res/layout/activity_main.xml
+++ b/res/layout/activity_main.xml
@@ -1,12 +1,42 @@
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="5dp">
+ android:layout_centerHorizontal="true"
+ android:onClick="button1clicked"
+ android:text="@string/_1st_button_text"/>
+
+
+
+
+
+
+
diff --git a/res/layout/example_ip_address_layout.xml b/res/layout/example_ip_address_layout.xml
index b229551..1b10316 100644
--- a/res/layout/example_ip_address_layout.xml
+++ b/res/layout/example_ip_address_layout.xml
@@ -13,13 +13,16 @@
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="16dip"
- android:text="IP Address" />
+ android:text="@string/ip_address_text" />
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/qustom_dialog_items_divider.xml b/res/layout/qustom_dialog_items_divider.xml
new file mode 100644
index 0000000..af68f74
--- /dev/null
+++ b/res/layout/qustom_dialog_items_divider.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/qustom_dialog_layout.xml b/res/layout/qustom_dialog_layout.xml
index 2346d09..1785b36 100644
--- a/res/layout/qustom_dialog_layout.xml
+++ b/res/layout/qustom_dialog_layout.xml
@@ -16,11 +16,8 @@
** limitations under the License.
*/
-I have copied and edited this code from here:
+ref:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/alert_dialog_holo.xml
-
-I should have probably just rewritten similar code, but i was feeling lazy. Maybe I will later.
-
-->
-
+ android:textAlignment="viewStart" />
+ android:background="#33b5e5" />
-
-
-
+ android:layout_height="wrap_content">
+
+
+ android:minHeight="64dp">
-
\ No newline at end of file
+
+
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b1a9cca..f3445b2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1,7 +1,12 @@
Custom Dialog Example
- See a hot new custom dialog!
+ Custom dialog with message, custom View and Items
+ Custom dialog with message and items
+ Custom dialog with disabled items
Alert Image
+ IP address
+ 0.0.0.0
+ Custom dialog with single choice items and adapter
\ No newline at end of file
diff --git a/src/com/qustom/dialog/QustomDialogBuilder.java b/src/com/qustom/dialog/QustomDialogBuilder.java
index 1598e2a..c6a1fbb 100644
--- a/src/com/qustom/dialog/QustomDialogBuilder.java
+++ b/src/com/qustom/dialog/QustomDialogBuilder.java
@@ -1,20 +1,47 @@
package com.qustom.dialog;
+/*
+ Copyright 2010 The Android Open Source Project
+ Copyright 2013 Daniel Smith
+
+ 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.
+*/
+
import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
import android.content.Context;
+import android.content.DialogInterface;
+import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
+import android.view.MotionEvent;
import android.view.View;
+import android.view.View.OnTouchListener;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
-import com.qustom.dialog.R;
-
-public class QustomDialogBuilder extends AlertDialog.Builder{
+public class QustomDialogBuilder extends AlertDialog.Builder {
/** The custom_body layout */
private View mDialogView;
+ private AlertDialog mDialog;
/** optional dialog title layout */
private TextView mTitle;
@@ -24,6 +51,10 @@ public class QustomDialogBuilder extends AlertDialog.Builder{
private TextView mMessage;
/** The colored holo divider. You can set its color with the setDividerColor method */
private View mDivider;
+ /** optional custom panel image */
+ private FrameLayout mCustom;
+ /**Keep Context as Member to support Apis below 11*/
+ private Context mContext;
public QustomDialogBuilder(Context context) {
super(context);
@@ -35,7 +66,27 @@ public QustomDialogBuilder(Context context) {
mMessage = (TextView) mDialogView.findViewById(R.id.message);
mIcon = (ImageView) mDialogView.findViewById(R.id.icon);
mDivider = mDialogView.findViewById(R.id.titleDivider);
+ mCustom = (FrameLayout) mDialogView.findViewById(R.id.customPanel);
+ mContext = context;
}
+
+ /**
+ * Use this method to reference the whole dialog view, i.e. when inflating a custom
+ * view with {@link #setCustomView(int, Context)} and you want to find an id from the
+ * inflated layout.
+ *
+ * example:
+ *
+ * CheckBox showAgain = (CheckBox) myQustomDialogBuilder.getDialogView().findViewById(R.id.inflated_checkbox);
+ * if (!showAgain.isChecked()) {
+ * // do something
+ * }
+ *
+ * @return the qustom dialog view
+ */
+ public View getDialogView() {
+ return mDialogView;
+ }
/**
* Use this method to color the divider between the title and content.
@@ -73,6 +124,7 @@ public QustomDialogBuilder setMessage(CharSequence text) {
@Override
public QustomDialogBuilder setIcon(int drawableResId) {
+ mIcon.setVisibility(View.VISIBLE);
mIcon.setImageResource(drawableResId);
return this;
}
@@ -93,14 +145,160 @@ public QustomDialogBuilder setIcon(Drawable icon) {
*/
public QustomDialogBuilder setCustomView(int resId, Context context) {
View customView = View.inflate(context, resId, null);
- ((FrameLayout)mDialogView.findViewById(R.id.customPanel)).addView(customView);
+ mCustom.setVisibility(View.VISIBLE);
+ mCustom.addView(customView);
return this;
}
+
+ /**
+ * Set a list of items to be displayed in the dialog as the content, you will be notified of the
+ * selected item via the supplied listener. This should be an array type i.e. R.array.foo
+ *
+ * @return This Builder object to allow for chaining of calls to set methods
+ */
+ @Override
+ public QustomDialogBuilder setItems(int itemsId, final DialogInterface.OnClickListener listener) {
+ return setItems(mContext.getResources().getTextArray(itemsId), listener);
+ }
+
+ /**
+ * Set a list of items to be displayed in the dialog as the content, you will be notified of the
+ * selected item via the supplied listener.
+ *
+ * @return This Builder object to allow for chaining of calls to set methods
+ */
+ @Override
+ public QustomDialogBuilder setItems(CharSequence[] items, final DialogInterface.OnClickListener listener) {
+ return (QustomDialogBuilder) setItems(items, null, listener);
+ }
+
+ public Builder setItems(int itemsId, int[] disabledOptions, final DialogInterface.OnClickListener listener) {
+ CharSequence[] items = mContext.getResources().getTextArray(itemsId);
+ return setItems(items, disabledOptions, listener);
+ }
+
+ public Builder setItems(CharSequence[] items, int[] disabledOptions, final DialogInterface.OnClickListener listener) {
+ LinearLayout itemList = (LinearLayout) mDialogView.findViewById(R.id.items_list);
+
+ for (int i = 0; i < items.length; i++) {
+ final int currentItem = i;
+ TextView listItem = inflateItem(items[i].toString());
+ View divider = inflateDivider();
+
+ if (disabledOptions != null) {
+ final boolean enabled = isEnabled(i, disabledOptions);
+ listItem.setEnabled(enabled);
+ if (!enabled) listItem.setTextColor(Color.GRAY);
+ }
+
+ itemList.addView(listItem);
+ if (i+1 != items.length) itemList.addView(divider);
+ if (listener != null) {
+ // fix
+ listItem.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ listener.onClick(mDialog, currentItem);
+ mDialog.dismiss();
+ }
+ });
+ }
+ }
+
+ return this;
+ }
+
+ @Override
+ public Builder setSingleChoiceItems (ListAdapter adapter, int checkedItem, final DialogInterface.OnClickListener listener) {
+ final ListView listView = (ListView) mDialogView.findViewById(R.id.listView);
+ listView.setAdapter(adapter);
+ listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
+ listView.setItemChecked(checkedItem, true);
+
+
+ if (listener != null) {
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ listener.onClick(QustomDialogBuilder.this.mDialog, position);
+ }
+ });
+ }
+
+ return this;
+ }
+
+ @Override
+ public Builder setSingleChoiceItems(CharSequence[] items, int checkedItem,
+ final DialogInterface.OnClickListener listener) {
+ ArrayAdapter adapter = new ArrayAdapter(mContext,
+ android.R.layout.simple_list_item_single_choice, android.R.id.text1, items);
+
+ return this.setSingleChoiceItems(adapter, checkedItem, listener);
+ }
+
+ @Override
+ public Builder setSingleChoiceItems(int itemsId, int checkedItem, final DialogInterface.OnClickListener listener) {
+ return this.setSingleChoiceItems(mContext.getResources().getTextArray(itemsId), checkedItem, listener);
+ }
+
+ public Builder setSingleChoiceItems(Cursor cursor, int checkedItem, String labelColumn,
+ final DialogInterface.OnClickListener listener) {
+ SimpleCursorAdapter adapter = new SimpleCursorAdapter(mContext,
+ android.R.layout.simple_list_item_single_choice, cursor,
+ new String[]{labelColumn}, new int[]{android.R.id.text1});
+
+ return this.setSingleChoiceItems(adapter, checkedItem, listener);
+ }
+
+ public boolean isEnabled(int position, int[] disabledOptions) {
+ if (disabledOptions != null) {
+ for (int i = 0; i < disabledOptions.length; i++) {
+ if (position == disabledOptions[i]) return false;
+ }
+ }
+ return true;
+ }
+
+ private TextView inflateItem(String itemText) {
+ TextView listItem = (TextView) View.inflate(mContext, R.layout.qustom_dialog_item_layout, null);
+ TextView icaoTextView = (TextView) listItem.findViewById(R.id.item_text);
+ icaoTextView.setText(itemText);
+
+ listItem.setOnTouchListener(new OnTouchListener() {
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event){
+ if(event.getAction() == MotionEvent.ACTION_DOWN) {
+
+ v.setBackgroundColor(mContext.getResources().getColor(android.R.color.darker_gray));
+ }
+
+ if(event.getAction() == MotionEvent.ACTION_UP ||
+ event.getAction() == MotionEvent.ACTION_MOVE ||
+ event.getAction() == MotionEvent.ACTION_CANCEL) {
+
+ v.setBackgroundColor(mContext.getResources().getColor(android.R.color.transparent));
+ }
+
+ return false;
+ }
+ });
+
+ return listItem;
+ }
+
+ private View inflateDivider() {
+ View listDivider = View.inflate(mContext, R.layout.qustom_dialog_items_divider, null);
+ return listDivider;
+ }
@Override
public AlertDialog show() {
if (mTitle.getText().equals("")) mDialogView.findViewById(R.id.topPanel).setVisibility(View.GONE);
- return super.show();
+ // hide also message TextView if empty
+ if (mMessage.getText().equals("")) mDialogView.findViewById(R.id.contentPanel).setVisibility(View.GONE);
+ mDialog = super.show();
+ return mDialog;
}
-
}
diff --git a/src/com/qustom/dialog/TestDialogActivity.java b/src/com/qustom/dialog/TestDialogActivity.java
index 6e1b8bd..abd5a9f 100644
--- a/src/com/qustom/dialog/TestDialogActivity.java
+++ b/src/com/qustom/dialog/TestDialogActivity.java
@@ -1,37 +1,185 @@
package com.qustom.dialog;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import com.qustom.dialog.R;
+import android.widget.ArrayAdapter;
+import android.widget.Toast;
public class TestDialogActivity extends Activity {
private static final String HALLOWEEN_ORANGE = "#FF7F27";
- private OnClickListener mShowDialogClickListener =new OnClickListener(){
- public void onClick(View v){
- QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(v.getContext()).
- setTitle("Set IP Address").
- setTitleColor(HALLOWEEN_ORANGE).
- setDividerColor(HALLOWEEN_ORANGE).
- setMessage("You are now entering the 10th dimension.").
- setCustomView(R.layout.example_ip_address_layout, v.getContext()).
- setIcon(getResources().getDrawable(R.drawable.ic_launcher));
+ public void button1clicked(View view) {
+ String[] sa = {
+ "Alpha",
+ "Bravo",
+ "Charlie",
+ "Delta",
+ "Echo",
+ "Foxtrot",
+ "Golf",
+ "Hotel",
+ "India",
+ "Juliett",
+ "Kilo",
+ "Lima",
+ "Mike",
+ "November",
+ "Oscar",
+ "Papa",
+ "Quebec",
+ "Romeo",
+ "Sierra",
+ "Tango",
+ "Uniform",
+ "Victor",
+ "Whiskey",
+ "X-ray",
+ "Yankee",
+ "Zulu"
+ };
+
+ QustomDialogBuilder qustomDialogBuilder = (QustomDialogBuilder) new QustomDialogBuilder(this)
+ .setTitle("Dialog with Message, custom View and Items")
+ .setTitleColor(HALLOWEEN_ORANGE)
+ .setDividerColor(HALLOWEEN_ORANGE)
+ .setMessage("You are now entering the 10th dimension.")
+ .setCustomView(R.layout.example_ip_address_layout, this)
+ .setIcon(getResources().getDrawable(R.drawable.ic_launcher))
+ .setItems(sa, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ Toast.makeText(TestDialogActivity.this, "item " + which + " clicked...", Toast.LENGTH_SHORT).show(); }
+ });
+
+ qustomDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- qustomDialogBuilder.show();
- }
- };
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Toast.makeText(TestDialogActivity.this, "'OK' clicked...", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ qustomDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Toast.makeText(TestDialogActivity.this, "'Cancel' clicked...", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ qustomDialogBuilder.show();
+ }
+
+ public void button2clicked(View view) {
+ String[] sa = { "Rome", "London", "New York" };
+ QustomDialogBuilder qustomDialogBuilder = (QustomDialogBuilder) new QustomDialogBuilder(this)
+ .setTitle("Dialog with Message and Items")
+ .setMessage("You are now exiting the 10th dimension.")
+ .setTitleColor(HALLOWEEN_ORANGE)
+ .setDividerColor(HALLOWEEN_ORANGE)
+ .setIcon(getResources().getDrawable(R.drawable.ic_launcher))
+ .setItems(sa, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ Toast.makeText(TestDialogActivity.this, "item " + which + " clicked...", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ qustomDialogBuilder.show();
+ }
+
+ public void button3clicked(View view) {
+ String[] sa = { "Enabled item 1", "Disabled item 1", "Enabled item 2", "Disabled item 2" };
+
+ int[] disabledItems = new int[] {1,3};
+
+ QustomDialogBuilder qustomDialogBuilder = (QustomDialogBuilder) new QustomDialogBuilder(this)
+ .setTitle("Dialog with disabled Items")
+ .setTitleColor(HALLOWEEN_ORANGE)
+ .setDividerColor(HALLOWEEN_ORANGE)
+ .setIcon(getResources().getDrawable(R.drawable.ic_launcher))
+ .setItems(sa, disabledItems, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ Toast.makeText(TestDialogActivity.this, "item " + which + " clicked...", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ qustomDialogBuilder.show();
+ }
+
+ public void button4clicked(View view) {
+ String[] sa = {
+ "Alpha",
+ "Bravo",
+ "Charlie",
+ "Delta",
+ "Echo",
+ "Foxtrot",
+ "Golf",
+ "Hotel",
+ "India",
+ "Juliett",
+ "Kilo",
+ "Lima",
+ "Mike",
+ "November",
+ "Oscar",
+ "Papa",
+ "Quebec",
+ "Romeo",
+ "Sierra",
+ "Tango",
+ "Uniform",
+ "Victor",
+ "Whiskey",
+ "X-ray",
+ "Yankee",
+ "Zulu"
+ };
+
+ ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_single_choice);
+ for(int a = 0; a < sa.length; a++) {
+ adapter.add(sa[a]);
+ }
+
+ QustomDialogBuilder qustomDialogBuilder = (QustomDialogBuilder) new QustomDialogBuilder(this)
+ .setTitle("Dialog with single choice items and adapter")
+ .setTitleColor(HALLOWEEN_ORANGE)
+ .setDividerColor(HALLOWEEN_ORANGE)
+ .setIcon(getResources().getDrawable(R.drawable.ic_launcher))
+ .setSingleChoiceItems(adapter, 1, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ Toast.makeText(TestDialogActivity.this, "item " + which + " clicked...", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ qustomDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Toast.makeText(TestDialogActivity.this, "'OK' clicked...", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ qustomDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Toast.makeText(TestDialogActivity.this, "'Cancel' clicked...", Toast.LENGTH_SHORT).show();
+ }
+ });
+
+ qustomDialogBuilder.show();
+
+ adapter.add("new item");
+ adapter.notifyDataSetChanged();
+ }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- Button bt = (Button)findViewById(R.id.button1);
- bt.setOnClickListener(mShowDialogClickListener);
}
-
-
}