Skip to content

Commit

Permalink
Progress background SmartView. #474
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor Keszthelyi committed Nov 13, 2017
1 parent 1b106c6 commit 9c1082e
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 111 deletions.
2 changes: 1 addition & 1 deletion opentasks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies {
exclude module: 'carrot'
exclude group: 'com.android.support'
}
compile 'org.dmfs:essentials:1.9'
compile 'org.dmfs:jems:1.13'

testCompile 'junit:junit:4.12'
}
4 changes: 2 additions & 2 deletions opentasks/src/main/java/org/dmfs/tasks/ViewTaskFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public void loadUri(Uri uri)

if ((oldUri == null) != (uri == null))
{
/*
/*
* getActivity().invalidateOptionsMenu() doesn't work in Android 2.x so use the compat lib
*/
ActivityCompat.invalidateOptionsMenu(getActivity());
Expand Down Expand Up @@ -491,7 +491,7 @@ public void onModelLoaded(Model model)
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
/*
/*
* Don't show any options if we don't have a task to show.
*/
if (mTaskUri != null)
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/ByDueDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Build;
import android.os.Build.VERSION;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.groupings.cursorloaders.TimeRangeCursorFactory;
Expand All @@ -37,6 +37,7 @@
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptorAdapter;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;

import java.text.DateFormatSymbols;

Expand Down Expand Up @@ -123,23 +124,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
{
priorityView.setBackgroundResource(R.color.priority_green);
}
if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}

new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/ByList.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Build.VERSION;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.tasks.QuickAddDialogFragment;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
Expand All @@ -38,6 +38,7 @@
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptorAdapter;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;


/**
Expand Down Expand Up @@ -120,23 +121,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
priorityView.setBackgroundResource(R.color.priority_green);
}

if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
setOverlay(view, cursor.getPosition(), cursor.getCount());
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/ByPriority.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Build.VERSION;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.provider.tasks.AuthorityUtil;
import org.dmfs.tasks.QuickAddDialogFragment;
import org.dmfs.tasks.R;
Expand All @@ -41,6 +41,7 @@
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptorAdapter;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;


/**
Expand Down Expand Up @@ -112,23 +113,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
priorityView.setBackgroundResource(R.color.priority_green);
}

if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
setOverlay(view, cursor.getPosition(), cursor.getCount());
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/ByProgress.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Build.VERSION;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.groupings.cursorloaders.ProgressCursorFactory;
Expand All @@ -35,6 +35,7 @@
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptorAdapter;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;


/**
Expand Down Expand Up @@ -105,23 +106,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
priorityView.setBackgroundResource(R.color.priority_green);
}

if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
setOverlay(view, cursor.getPosition(), cursor.getCount());
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/BySearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.database.Cursor;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Build.VERSION;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
Expand All @@ -31,6 +30,7 @@
import android.widget.TextView;
import android.widget.Toast;

import org.dmfs.optional.NullSafe;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.contract.TaskContract.Tasks;
Expand All @@ -44,6 +44,7 @@
import org.dmfs.tasks.utils.SearchHistoryDatabaseHelper.SearchHistoryColumns;
import org.dmfs.tasks.utils.SearchHistoryHelper;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;


/**
Expand Down Expand Up @@ -116,23 +117,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
priorityView.setBackgroundResource(R.color.priority_green);
}

if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
setOverlay(view, cursor.getPosition(), cursor.getCount());
Expand Down
23 changes: 5 additions & 18 deletions opentasks/src/main/java/org/dmfs/tasks/groupings/ByStartDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import android.database.Cursor;
import android.graphics.Paint;
import android.os.Build;
import android.os.Build.VERSION;
import android.text.format.Time;
import android.view.View;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import org.dmfs.optional.NullSafe;
import org.dmfs.tasks.R;
import org.dmfs.tasks.contract.TaskContract.Instances;
import org.dmfs.tasks.groupings.cursorloaders.TimeRangeCursorFactory;
Expand All @@ -41,6 +41,7 @@
import org.dmfs.tasks.utils.ExpandableGroupDescriptor;
import org.dmfs.tasks.utils.ExpandableGroupDescriptorAdapter;
import org.dmfs.tasks.utils.ViewDescriptor;
import org.dmfs.tasks.widget.ProgressBackgroundView;


/**
Expand Down Expand Up @@ -138,23 +139,9 @@ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter ada
priorityView.setBackgroundResource(R.color.priority_green);
}

if (VERSION.SDK_INT >= 11)
{
// update percentage background
View background = getView(view, R.id.percentage_background_view);
background.setPivotX(0);
Integer percentComplete = TaskFieldAdapters.PERCENT_COMPLETE.get(cursor);
if (percentComplete < 100)
{
background.setScaleX(percentComplete == null ? 0 : percentComplete / 100f);
background.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
background.setScaleX(1);
background.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
.update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

setColorBar(view, cursor);
setDescription(view, cursor);
setOverlay(view, cursor.getPosition(), cursor.getCount());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2017 dmfs GmbH
*
* 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.
*/

package org.dmfs.tasks.widget;

import android.os.Build;
import android.view.View;

import org.dmfs.optional.Optional;
import org.dmfs.tasks.R;


/**
* {@link SmartView} adapting any {@link View} so that its background can be updated with a progress in percent,
* so that it shows the value as a proportionate horizontal overlay.
*
* @author Gabor Keszthelyi
*/
public final class ProgressBackgroundView implements SmartView<Optional<Integer>>
{
private final View mBackgroundView;


public ProgressBackgroundView(View backgroundView)
{
mBackgroundView = backgroundView;
}


@Override
public void update(Optional<Integer> percentComplete)
{
if (Build.VERSION.SDK_INT >= 11 && percentComplete.isPresent())
{
mBackgroundView.setPivotX(0);
if (percentComplete.value() < 100)
{
mBackgroundView.setScaleX(percentComplete.value() / 100f);
mBackgroundView.setBackgroundResource(R.drawable.task_progress_background_shade);
}
else
{
mBackgroundView.setScaleX(1);
mBackgroundView.setBackgroundResource(R.drawable.complete_task_background_overlay);
}
}
}
}
Loading

0 comments on commit 9c1082e

Please sign in to comment.