Skip to content

Commit

Permalink
Add Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneBg committed Sep 3, 2014
1 parent 41399bf commit 8d4c01b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 0 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}
26 changes: 16 additions & 10 deletions app/src/main/java/uk/me/lewisdeane/ldialogs/CustomDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void init() {
mButtonContainers[1] = (LinearLayout) mRootView.findViewById(R.id.dialog_custom_stacked_buttons);

// Set alignment for title view.
((TextView)mViews[0]).setGravity(getGravityFromAlignment(mTitleAlignment) | Gravity.CENTER_VERTICAL);
((TextView) mViews[0]).setGravity(getGravityFromAlignment(mTitleAlignment) | Gravity.CENTER_VERTICAL);

// Load typeface from assets to be used.
mTypeface = Typeface.createFromAsset(getContext().getResources().getAssets(), "Roboto-Medium.ttf");
Expand Down Expand Up @@ -199,10 +199,10 @@ private int getIndexFromView(View _view) {

private void applyTheme() {
// Apply the correct colours based on theme and user preference.
((TextView)mViews[0]).setTextColor(Color.parseColor(this.mTitleColour.length() > 0 ? mTitleColour : (mTheme == Theme.LIGHT ? LightColours.TITLE.mColour : DarkColours.TITLE.mColour)));
((TextView)mViews[1]).setTextColor(Color.parseColor(this.mContentColour.length() > 0 ? mContentColour : (mTheme == Theme.LIGHT ? LightColours.CONTENT.mColour : DarkColours.CONTENT.mColour)));
((Button)mViews[2]).setTextColor(Color.parseColor(this.mPositiveColour.length() > 0 ? mPositiveColour : (mTheme == Theme.LIGHT ? LightColours.BUTTON.mColour : DarkColours.BUTTON.mColour)));
((Button)mViews[3]).setTextColor(Color.parseColor(this.mNegativeColour.length() > 0 ? mNegativeColour : (mTheme == Theme.LIGHT ? LightColours.BUTTON.mColour : DarkColours.BUTTON.mColour)));
((TextView) mViews[0]).setTextColor(Color.parseColor(this.mTitleColour.length() > 0 ? mTitleColour : (mTheme == Theme.LIGHT ? LightColours.TITLE.mColour : DarkColours.TITLE.mColour)));
((TextView) mViews[1]).setTextColor(Color.parseColor(this.mContentColour.length() > 0 ? mContentColour : (mTheme == Theme.LIGHT ? LightColours.CONTENT.mColour : DarkColours.CONTENT.mColour)));
((Button) mViews[2]).setTextColor(Color.parseColor(this.mPositiveColour.length() > 0 ? mPositiveColour : (mTheme == Theme.LIGHT ? LightColours.BUTTON.mColour : DarkColours.BUTTON.mColour)));
((Button) mViews[3]).setTextColor(Color.parseColor(this.mNegativeColour.length() > 0 ? mNegativeColour : (mTheme == Theme.LIGHT ? LightColours.BUTTON.mColour : DarkColours.BUTTON.mColour)));
}

public CustomDialog setClickListener(ClickListener mCallbacks) {
Expand Down Expand Up @@ -243,12 +243,18 @@ public Builder(Context _context, String _title, String _positiveText) {
this.mPositiveText = _positiveText;
}

public Builder(Context _context, int _titleResId, int _positiveTextResId) {
this.mContext = _context;
this.mTitle = mContext.getString(_titleResId);
this.mPositiveText = mContext.getString(_positiveTextResId);
}

// Optional parameters initialised by default.
private String mNegativeText = "", mPositiveColour = "", mNegativeColour = "", mTitleColour = "", mContentColour = "", mContent = "";
private boolean mDarkTheme = false;
private Alignment mTitleAlignment = Alignment.LEFT;

public Builder content(String _content){
public Builder content(String _content) {
this.mContent = _content;
return this;
}
Expand All @@ -263,17 +269,17 @@ public Builder positiveColor(String _positiveColour) {
return this;
}

public Builder negativeColor(String _negativeColour){
public Builder negativeColor(String _negativeColour) {
this.mNegativeColour = _negativeColour;
return this;
}

public Builder titleColor(String _colour){
public Builder titleColor(String _colour) {
this.mTitleColour = _colour;
return this;
}

public Builder contentColor(String _colour){
public Builder contentColor(String _colour) {
this.mContentColour = _colour;
return this;
}
Expand All @@ -283,7 +289,7 @@ public Builder darkTheme(boolean _isDark) {
return this;
}

public Builder titleAlignment(Alignment _alignment){
public Builder titleAlignment(Alignment _alignment) {
this.mTitleAlignment = _alignment;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.me.lewisdeane.ldialogs;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
Expand Down Expand Up @@ -155,6 +154,12 @@ public Builder(Context _context, String _title, String[] _items) {
this.mItems = _items;
}

public Builder(Context _context, int _titleResId, int _itemsResId) {
this.mContext = _context;
this.mTitle = mContext.getString(_titleResId);
this.mItems = mContext.getResources().getStringArray(_itemsResId);
}

// Optional parameters initialised with default values.
private Alignment mTitleAlignment = Alignment.LEFT, mItemAlignment = Alignment.LEFT;
private String mTitleColour = "", mItemColour = "";
Expand Down
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

Expand Down

0 comments on commit 8d4c01b

Please sign in to comment.