mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 15:40:14 -04:00
Color inversion in Done/Next
Code refactor for background drawing New priority tooltip
This commit is contained in:
@@ -8,8 +8,8 @@ android {
|
||||
applicationId "com.wismna.geoffroy.donext"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 25
|
||||
versionCode 21
|
||||
versionName "1.4.6"
|
||||
versionCode 22
|
||||
versionName "1.4.7"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@@ -126,6 +126,26 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
}
|
||||
});
|
||||
|
||||
// Handle priority changes
|
||||
final TextView tooltip = (TextView) findViewById(R.id.new_task_priority_tooltip);
|
||||
SeekBar seekBar = (SeekBar) findViewById(R.id.new_task_priority);
|
||||
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
tooltip.setText(getResources().getStringArray(R.array.task_priority)[progress]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
tooltip.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
tooltip.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
tooltip.setText(getResources().getStringArray(R.array.task_priority)[seekBar.getProgress()]);
|
||||
// Set other properties if they exist
|
||||
if (task != null) {
|
||||
|
||||
@@ -133,7 +153,7 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
titleText.setText(task.getName());
|
||||
EditText descText = (EditText) findViewById(R.id.new_task_description);
|
||||
descText.setText(task.getDescription());
|
||||
SeekBar seekBar = (SeekBar) findViewById(R.id.new_task_priority);
|
||||
|
||||
seekBar.setProgress(task.getPriority());
|
||||
|
||||
// Set Due Date
|
||||
|
@@ -113,8 +113,8 @@ public class TasksFragment extends Fragment implements
|
||||
// Set ItemTouch helper in RecyclerView to handle swipe move on elements
|
||||
final Resources resources = getResources();
|
||||
ItemTouchHelper.Callback callback = new TaskTouchHelper(this,
|
||||
ContextCompat.getColor(context, R.color.colorAccent),
|
||||
ContextCompat.getColor(context, R.color.colorPrimary));
|
||||
ContextCompat.getColor(context, R.color.colorPrimary),
|
||||
ContextCompat.getColor(context, R.color.colorAccent));
|
||||
ItemTouchHelper helper = new ItemTouchHelper(callback);
|
||||
helper.attachToRecyclerView(recyclerView);
|
||||
|
||||
|
@@ -23,14 +23,14 @@ public class TaskTouchHelper extends ItemTouchHelper.SimpleCallback {
|
||||
}
|
||||
|
||||
private final TaskTouchHelperAdapter mAdapter;
|
||||
private int colorDone;
|
||||
private int colorNext;
|
||||
private int colorRight;
|
||||
private int colorLeft;
|
||||
|
||||
public TaskTouchHelper(TaskTouchHelperAdapter adapter, int colorDone, int colorNext){
|
||||
public TaskTouchHelper(TaskTouchHelperAdapter adapter, int colorRight, int colorLeft){
|
||||
// No drag moves, no swipes (except for 1st element, see getSwipeDirs method)
|
||||
super(0, 0);
|
||||
this.colorDone = colorDone;
|
||||
this.colorNext = colorNext;
|
||||
this.colorRight = colorRight;
|
||||
this.colorLeft = colorLeft;
|
||||
this.mAdapter = adapter;
|
||||
}
|
||||
|
||||
@@ -59,72 +59,48 @@ public class TaskTouchHelper extends ItemTouchHelper.SimpleCallback {
|
||||
View itemView = viewHolder.itemView;
|
||||
|
||||
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
|
||||
Paint background = new Paint();
|
||||
|
||||
TextPaint textPaint = new TextPaint();
|
||||
textPaint.setAntiAlias(true);
|
||||
textPaint.setTextSize(25 * itemView.getResources().getDisplayMetrics().density);
|
||||
textPaint.setColor(Color.WHITE);
|
||||
|
||||
int heightOffset = itemView.getHeight() / 2 - (int)textPaint.getTextSize() / 2;
|
||||
int widthOffset = 30;
|
||||
if (dX > 0) {
|
||||
// Set your color for positive displacement
|
||||
//background.setARGB(255, 222, 222, 222);
|
||||
//p.setARGB(255, 204, 229, 255);
|
||||
background.setColor(colorNext);
|
||||
// Draw Rect with varying right side, equal to displacement dX
|
||||
Rect rect = new Rect(itemView.getLeft(), itemView.getTop(), (int) dX,
|
||||
itemView.getBottom());
|
||||
c.drawRect(rect, background);
|
||||
|
||||
// Draw text in the rectangle
|
||||
String text = itemView.getResources().getString(R.string.task_confirmation_next_button).toUpperCase();
|
||||
int width = (int) textPaint.measureText(text);
|
||||
float textXCoordinate = rect.left + widthOffset;
|
||||
c.translate(textXCoordinate, dY + heightOffset);
|
||||
StaticLayout staticLayout = new StaticLayout(text, textPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false);
|
||||
staticLayout.draw(c);
|
||||
//textView = recyclerView.getRootView().findViewById(R.id.task_background_next);
|
||||
|
||||
setBackground(c, itemView, rect, dX, dY,
|
||||
colorLeft, R.string.task_confirmation_next_button);
|
||||
} else {
|
||||
// Set your color for negative displacement
|
||||
background.setColor(colorDone);
|
||||
//p.setARGB(255, 204, 255, 229);
|
||||
// Draw Rect with varying left side, equal to the item's right side plus negative displacement dX
|
||||
Rect rect = new Rect(itemView.getRight() + (int)dX, itemView.getTop(),
|
||||
itemView.getRight(), itemView.getBottom());
|
||||
c.drawRect(rect, background);
|
||||
|
||||
// Draw text in the rectangle
|
||||
String text = itemView.getResources().getString(R.string.task_confirmation_done_button).toUpperCase();
|
||||
int width = (int) textPaint.measureText(text);
|
||||
float textXCoordinate = rect.right - width - widthOffset;
|
||||
c.translate(textXCoordinate, dY + heightOffset);
|
||||
StaticLayout staticLayout = new StaticLayout(text, textPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false);
|
||||
staticLayout.draw(c);
|
||||
//textView = recyclerView.getRootView().findViewById(R.id.task_background_done);
|
||||
setBackground(c, itemView, rect, dX, dY,
|
||||
colorRight, R.string.task_confirmation_done_button);
|
||||
}
|
||||
//textView.draw(c);
|
||||
}
|
||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
|
||||
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE)
|
||||
{
|
||||
viewHolder.itemView.setBackgroundColor(Color.LTGRAY);
|
||||
}
|
||||
private void setBackground(Canvas c, View itemView,
|
||||
Rect rect, float dX, float dY, int color, int textId) {
|
||||
|
||||
super.onSelectedChanged(viewHolder, actionState);
|
||||
TextPaint textPaint = new TextPaint();
|
||||
textPaint.setAntiAlias(true);
|
||||
textPaint.setTextSize(25 * itemView.getResources().getDisplayMetrics().density);
|
||||
textPaint.setColor(Color.WHITE);
|
||||
|
||||
int heightOffset = itemView.getHeight() / 2 - (int)textPaint.getTextSize() / 2;
|
||||
int widthOffset = 30;
|
||||
|
||||
Paint background = new Paint();
|
||||
// Set your color for negative displacement
|
||||
background.setColor(color);
|
||||
// Draw Rect with varying left side, equal to the item's right side plus negative displacement dX
|
||||
c.drawRect(rect, background);
|
||||
|
||||
// Draw text in the rectangle
|
||||
String text = itemView.getResources().getString(textId).toUpperCase();
|
||||
int width = (int) textPaint.measureText(text);
|
||||
float textXCoordinate;
|
||||
if (dX > 0) textXCoordinate = rect.left + widthOffset;
|
||||
else textXCoordinate = rect.right - width - widthOffset;
|
||||
c.translate(textXCoordinate, dY + heightOffset);
|
||||
StaticLayout staticLayout = new StaticLayout(text, textPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false);
|
||||
staticLayout.draw(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
super.clearView(recyclerView, viewHolder);
|
||||
|
||||
viewHolder.itemView.setAlpha(1.0f);
|
||||
viewHolder.itemView.setBackgroundColor(0);
|
||||
}*/
|
||||
}
|
||||
|
@@ -64,6 +64,19 @@
|
||||
android:layout_height="30dp"
|
||||
android:layout_toEndOf="@id/new_task_priority_label"
|
||||
android:layout_below="@id/new_task_description" />
|
||||
<TextView
|
||||
android:id="@+id/new_task_priority_tooltip"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:padding="10dp"
|
||||
android:layout_above="@id/new_task_priority"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:background="@android:color/darker_gray"
|
||||
android:textColor="@android:color/white"
|
||||
android:textAlignment="center"
|
||||
android:visibility="gone" />
|
||||
<CheckBox
|
||||
android:id="@+id/new_task_today"
|
||||
android:layout_width="wrap_content"
|
||||
|
@@ -4,4 +4,9 @@
|
||||
<item>Simple</item>
|
||||
<item>Détaillée</item>
|
||||
</string-array>
|
||||
<string-array name="task_priority">
|
||||
<item>Basse</item>
|
||||
<item>Moyenne</item>
|
||||
<item>Haute</item>
|
||||
</string-array>
|
||||
</resources>
|
@@ -17,4 +17,9 @@
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
<string-array name="task_priority">
|
||||
<item>Low</item>
|
||||
<item>Medium</item>
|
||||
<item>High</item>
|
||||
</string-array>
|
||||
</resources>
|
@@ -5,7 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.3.0'
|
||||
classpath 'com.android.tools.build:gradle:2.3.1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
Reference in New Issue
Block a user