Skip to content

Commit

Permalink
Introduce round corders
Browse files Browse the repository at this point in the history
On API level 21+ this dialog now uses round corners as in the so called "Material 2" design.
This also removes support for Android API levels <14.
  • Loading branch information
dmfs committed Nov 12, 2018
1 parent a5f737b commit 509010c
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 36 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
compileSdkVersion 26

defaultConfig {
applicationId "org.dmfs.android.colorpicker"
minSdkVersion 15
targetSdkVersion 25
targetSdkVersion 26
}

buildTypes {
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ allprojects {
repositories {
jcenter()
google()
maven { url "https://jitpack.io" }
}
}
6 changes: 3 additions & 3 deletions colorpicker-activity/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
compileSdkVersion 26

defaultConfig {
minSdkVersion 15
targetSdkVersion 25
targetSdkVersion 26

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -22,5 +22,5 @@ android {

dependencies {
api project(':colorpicker')
implementation 'com.android.support:appcompat-v7:25.4.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
}
10 changes: 6 additions & 4 deletions colorpicker/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
compileSdkVersion 26

defaultConfig {
minSdkVersion 9
targetSdkVersion 25
minSdkVersion 14
targetSdkVersion 26
}

buildTypes {
Expand All @@ -17,7 +17,9 @@ android {
}

dependencies {
compile 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.github.dmfs.bolts:color-bolts:2b1b95d'
compile files('libs/android-retention-magic-1.2.2.jar')
compile files('libs/drawablepagertabstrip.jar')
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import org.dmfs.android.bolts.color.colors.AttributeColor;
import org.dmfs.android.colorpicker.PaletteFragment.OnColorSelectedListener;
import org.dmfs.android.colorpicker.palettes.Palette;
import org.dmfs.android.retentionmagic.SupportDialogFragment;
import org.dmfs.android.retentionmagic.annotations.Retain;
import org.dmfs.android.view.DrawablePagerTabStrip;
import org.dmfs.android.view.ViewPager;


Expand Down Expand Up @@ -136,14 +142,13 @@ public void setTitle(int title)
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.org_dmfs_colorpickerdialog_fragment, container);

mPager = (ViewPager) view.findViewById(R.id.pager);
mPager = view.findViewById(R.id.pager);
mPagerAdapter = new PalettesPagerAdapter(getResources(), getChildFragmentManager(), mPalettes);
mPagerAdapter.notifyDataSetChanged();
mPager.setAdapter(mPagerAdapter);
mPager.setCurrentItem(mPagerAdapter.getCount() / 2 + mSelected);

mTitleView = (TextView) view.findViewById(android.R.id.title);
mTitleView = view.findViewById(android.R.id.title);

if (mTitleId != 0)
{
Expand All @@ -154,16 +159,27 @@ else if (mTitle != null)
mTitleView.setText(mTitle);
}

DrawablePagerTabStrip titleStrip = view.findViewById(R.id.pager_title_strip);
titleStrip.setTabIndicatorColor(new AttributeColor(getContext(), R.attr.colorAccent).argb());
return view;
}


@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
Dialog result = super.onCreateDialog(savedInstanceState);
result.requestWindowFeature(Window.FEATURE_NO_TITLE);
result.setOnCancelListener(this);
if (Build.VERSION.SDK_INT >= 21)
{
// set a background with round corners
result.getWindow().setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.colorpicker_dialog_background));
// ensure we still have the right drop shadow in place
ViewCompat.setElevation(result.getWindow().getDecorView(), 24);
}
// else: on ancient devices we'll just continue using default square corners
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,7 @@ public void onGlobalLayout()
* away from a library without resource dependencies. Maybe there is an Android dimension resource with a reasonable value?
*/
DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics();
if (android.os.Build.VERSION.SDK_INT > 10)
{
columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * (mAdapter.getNumColumns() - 1);
}
else
{
// Android 2 seems to add spacing around the entire gridview
columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * mAdapter.getNumColumns();
}
columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * (mAdapter.getNumColumns() - 1);
}

// width of a single column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ public View getView(int position, View convertView, ViewGroup parent)
View view = convertView;
if (view == null)
{
/*
* TODO: build the layout programmatically
*/
view = mLayoutInflater.inflate(R.layout.org_dmfs_colorpickerdialog_palette_field, null);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Wrap this in an item which adds another margin to preserve the original size -->
<item
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="?android:colorBackground"/>
<corners android:radius="8dp"/>
<padding
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp"/>
</shape>
</item>
</layer-list>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
Expand All @@ -13,9 +14,8 @@
android:layout_margin="8dp"
android:maxLines="1"
android:singleLine="true"
android:text="@string/org_dmfs_colorpicker_pick_a_color"
android:textSize="20sp"
android:textStyle="bold"/>
style="@style/Base.TextAppearance.AppCompat.Title"
android:text="@string/org_dmfs_colorpicker_pick_a_color"/>

<org.dmfs.android.colorpicker.SquareViewPager
android:id="@+id/pager"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
android:numColumns="2"
android:requiresFadingEdge="vertical"
android:stretchMode="none"
android:verticalSpacing="8dip"></GridView>
android:verticalSpacing="8dip"/>

</LinearLayout>
7 changes: 4 additions & 3 deletions demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
compileSdkVersion 26

defaultConfig {
applicationId "org.dmfs.android.colorpicker.demo"
minSdkVersion 9
targetSdkVersion 25
minSdkVersion 14
targetSdkVersion 26
}

buildTypes {
Expand All @@ -19,4 +19,5 @@ android {

dependencies {
compile project(':colorpicker')
implementation 'com.android.support:appcompat-v7:26.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@
package org.dmfs.android.colorpicker.demo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import org.dmfs.android.colorpicker.ColorPickerDialogFragment;
import org.dmfs.android.colorpicker.ColorPickerDialogFragment.ColorDialogResultListener;
import org.dmfs.android.colorpicker.palettes.ColorShadeFactory;
import org.dmfs.android.colorpicker.palettes.Palette;
import org.dmfs.android.colorpicker.palettes.ArrayPalette;
import org.dmfs.android.colorpicker.palettes.ColorFactory;
import org.dmfs.android.colorpicker.palettes.ColorShadeFactory;
import org.dmfs.android.colorpicker.palettes.CombinedColorFactory;
import org.dmfs.android.colorpicker.palettes.FactoryPalette;
import org.dmfs.android.colorpicker.palettes.Palette;
import org.dmfs.android.colorpicker.palettes.RainbowColorFactory;
import org.dmfs.android.colorpicker.palettes.RandomPalette;
import org.dmfs.android.retentionmagic.FragmentActivity;
import org.dmfs.android.retentionmagic.annotations.Retain;

import java.util.ArrayList;


public class DemoActivity extends FragmentActivity implements ColorDialogResultListener
public class DemoActivity extends AppCompatActivity implements ColorDialogResultListener
{
private final static int[] COLORS = new int[] {
0xff000000, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffff00, 0xff00ffff, 0xffff00ff, 0xff404040,
Expand All @@ -62,6 +62,8 @@ public class DemoActivity extends FragmentActivity implements ColorDialogResultL
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);

setContentView(R.layout.activity_demo);
mTextView = (TextView) findViewById(R.id.textView2);
mColorBox = findViewById(R.id.colorbox);
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/res/values-v14/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<style name="AppBaseTheme" parent="Theme.AppCompat.DayNight">
<!-- API 14 theme customizations can go here. -->
</style>

Expand Down

0 comments on commit 509010c

Please sign in to comment.