mirror of https://github.com/tasks/tasks
Remove unused code
parent
f2d770f03f
commit
ef4b044faa
@ -1,12 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.andlib.sql;
|
||||
|
||||
public class EqCriterion extends UnaryCriterion {
|
||||
EqCriterion(Field field, Object value) {
|
||||
super(field, Operator.eq, value);
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.andlib.sql;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupBy {
|
||||
private List<Field> fields = new ArrayList<Field>();
|
||||
|
||||
public static GroupBy groupBy(Field field) {
|
||||
GroupBy groupBy = new GroupBy();
|
||||
groupBy.fields.add(field);
|
||||
return groupBy;
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.data;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.todoroo.andlib.data.ContentResolverDao;
|
||||
import com.todoroo.andlib.sql.Criterion;
|
||||
|
||||
/**
|
||||
* Data access object for accessing Astrid's {@link StoreObject} table. A
|
||||
* StoreObject is an arbitrary piece of data stored inside of Astrid.
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*/
|
||||
public class StoreObjectApiDao extends ContentResolverDao<StoreObject> {
|
||||
|
||||
public StoreObjectApiDao(Context context) {
|
||||
super(StoreObject.class, context, StoreObject.CONTENT_URI);
|
||||
}
|
||||
|
||||
// --- SQL clause generators
|
||||
|
||||
/**
|
||||
* Generates SQL clauses
|
||||
*/
|
||||
public static class StoreObjectCriteria {
|
||||
|
||||
/**
|
||||
* Returns all store objects with given type
|
||||
*/
|
||||
public static Criterion byType(String type) {
|
||||
return StoreObject.TYPE.eq(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns store object with type and key
|
||||
*/
|
||||
public static Criterion byTypeAndItem(String type, String item) {
|
||||
return Criterion.and(byType(type), StoreObject.ITEM.eq(item));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.actfm;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.service.Autowired;
|
||||
import com.todoroo.andlib.service.ContextManager;
|
||||
import com.todoroo.andlib.service.DependencyInjectionService;
|
||||
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
|
||||
import com.todoroo.astrid.api.AstridApiConstants;
|
||||
import com.todoroo.astrid.api.SyncAction;
|
||||
import com.todoroo.astrid.service.AstridDependencyInjector;
|
||||
|
||||
/**
|
||||
* Exposes sync action
|
||||
*/
|
||||
public class ActFmSyncActionExposer extends BroadcastReceiver {
|
||||
|
||||
@Autowired
|
||||
ActFmPreferenceService actFmPreferenceService;
|
||||
|
||||
static {
|
||||
AstridDependencyInjector.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
ContextManager.setContext(context);
|
||||
DependencyInjectionService.getInstance().inject(this);
|
||||
|
||||
// if we aren't logged in, don't expose sync action
|
||||
if (!actFmPreferenceService.isLoggedIn()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SyncAction syncAction = new SyncAction(context.getString(R.string.actfm_APr_header),
|
||||
null);
|
||||
|
||||
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS);
|
||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, ActFmPreferenceService.IDENTIFIER);
|
||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, syncAction);
|
||||
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
package com.todoroo.astrid.actfm.sync.messages;
|
||||
|
||||
import com.todoroo.astrid.dao.RemoteModelDao;
|
||||
import com.todoroo.astrid.data.RemoteModel;
|
||||
|
||||
import org.apache.http.entity.mime.MultipartEntity;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class RequestDoubleCheck<TYPE extends RemoteModel> extends ClientToServerMessage<TYPE> {
|
||||
|
||||
public RequestDoubleCheck(long id, Class<TYPE> modelClass, RemoteModelDao<TYPE> modelDao) {
|
||||
super(id, modelClass, modelDao);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean serializeExtrasToJSON(JSONObject serializeTo, MultipartEntity entity) throws JSONException {
|
||||
// No extras
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTypeString() {
|
||||
return "RequestDoubleCheck"; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.gtasks;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.andlib.service.Autowired;
|
||||
import com.todoroo.andlib.service.ContextManager;
|
||||
import com.todoroo.andlib.service.DependencyInjectionService;
|
||||
import com.todoroo.astrid.api.AstridApiConstants;
|
||||
import com.todoroo.astrid.api.SyncAction;
|
||||
import com.todoroo.astrid.service.AstridDependencyInjector;
|
||||
|
||||
/**
|
||||
* Exposes sync action
|
||||
*/
|
||||
public class GtasksSyncActionExposer extends BroadcastReceiver {
|
||||
|
||||
@Autowired
|
||||
private GtasksPreferenceService gtasksPreferenceService;
|
||||
|
||||
static {
|
||||
AstridDependencyInjector.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
ContextManager.setContext(context);
|
||||
DependencyInjectionService.getInstance().inject(this);
|
||||
|
||||
// if we aren't logged in, don't expose sync action
|
||||
if (!gtasksPreferenceService.isLoggedIn()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Intent syncIntent = new Intent(null, null,
|
||||
context, GtasksBackgroundService.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getService(context, 0, syncIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
SyncAction syncAction = new SyncAction(context.getString(R.string.gtasks_GPr_header),
|
||||
pendingIntent);
|
||||
|
||||
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS);
|
||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_ADDON, GtasksPreferenceService.IDENTIFIER);
|
||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_RESPONSE, syncAction);
|
||||
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.gtasks.api;
|
||||
|
||||
import com.google.api.services.tasks.model.Task;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Encapsulates a request to the api to update a task on the remote server
|
||||
*
|
||||
* @author Sam Bosley
|
||||
*/
|
||||
public class UpdateRequest extends PushRequest {
|
||||
|
||||
public UpdateRequest(GtasksInvoker service, String listId, Task toUpdate) {
|
||||
super(service, listId, toUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task executePush() throws IOException {
|
||||
return service.updateGtask(listId, toPush);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void recover() {
|
||||
//Figure out a good way to recover!
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.reminders;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class ReminderPlugin extends BroadcastReceiver {
|
||||
|
||||
static final String IDENTIFIER = "reminders"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
/*Plugin plugin = new Plugin(IDENTIFIER, "Reminders", "Todoroo",
|
||||
"Provides notification reminders for tasks");
|
||||
|
||||
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_PLUGINS);
|
||||
broadcastIntent.putExtra(AstridApiConstants.EXTRAS_PLUGIN, plugin);
|
||||
context.sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);*/
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.timsu.astrid.data.location;
|
||||
|
||||
public class GeoPoint {
|
||||
|
||||
private int latitude, longitude;
|
||||
|
||||
public GeoPoint(int latitude, int longitude) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public int getLatitudeE6() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public int getLongitudeE6() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,387 +0,0 @@
|
||||
/***
|
||||
Copyright (c) 2008-2009 CommonsWare, LLC
|
||||
Portions (c) 2009 Google, Inc.
|
||||
|
||||
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 com.commonsware.cwac.merge;
|
||||
|
||||
import android.database.DataSetObserver;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.SectionIndexer;
|
||||
|
||||
import com.commonsware.cwac.sacklist.SackOfViewsAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Adapter that merges multiple child adapters and views
|
||||
* into a single contiguous whole.
|
||||
* <p/>
|
||||
* Adapters used as pieces within MergeAdapter must
|
||||
* have view type IDs monotonically increasing from 0. Ideally,
|
||||
* adapters also have distinct ranges for their row ids, as
|
||||
* returned by getItemId().
|
||||
*/
|
||||
public class MergeAdapter extends BaseAdapter implements SectionIndexer {
|
||||
protected ArrayList<ListAdapter> pieces = new ArrayList<ListAdapter>();
|
||||
|
||||
/**
|
||||
* Stock constructor, simply chaining to the superclass.
|
||||
*/
|
||||
public MergeAdapter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new adapter to the roster of things to appear
|
||||
* in the aggregate list.
|
||||
*
|
||||
* @param adapter Source for row views for this section
|
||||
*/
|
||||
public void addAdapter(ListAdapter adapter) {
|
||||
pieces.add(adapter);
|
||||
adapter.registerDataSetObserver(new CascadeDataSetObserver());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new View to the roster of things to appear
|
||||
* in the aggregate list.
|
||||
*
|
||||
* @param view Single view to add
|
||||
*/
|
||||
public void addView(View view) {
|
||||
addView(view, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new View to the roster of things to appear
|
||||
* in the aggregate list.
|
||||
*
|
||||
* @param view Single view to add
|
||||
* @param enabled false if views are disabled, true if enabled
|
||||
*/
|
||||
public void addView(View view, boolean enabled) {
|
||||
ArrayList<View> list = new ArrayList<View>(1);
|
||||
|
||||
list.add(view);
|
||||
|
||||
addViews(list, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a list of views to the roster of things to appear
|
||||
* in the aggregate list.
|
||||
*
|
||||
* @param views List of views to add
|
||||
*/
|
||||
public void addViews(List<View> views) {
|
||||
addViews(views, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a list of views to the roster of things to appear
|
||||
* in the aggregate list.
|
||||
*
|
||||
* @param views List of views to add
|
||||
* @param enabled false if views are disabled, true if enabled
|
||||
*/
|
||||
public void addViews(List<View> views, boolean enabled) {
|
||||
if (enabled) {
|
||||
addAdapter(new EnabledSackAdapter(views));
|
||||
} else {
|
||||
addAdapter(new SackOfViewsAdapter(views));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data item associated with the specified
|
||||
* position in the data set.
|
||||
*
|
||||
* @param position Position of the item whose data we want
|
||||
*/
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
for (ListAdapter piece : pieces) {
|
||||
int size = piece.getCount();
|
||||
|
||||
if (position < size) {
|
||||
return piece.getItem(position);
|
||||
}
|
||||
|
||||
position -= size;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the adapter associated with the specified
|
||||
* position in the data set.
|
||||
*
|
||||
* @param position Position of the item whose adapter we want
|
||||
*/
|
||||
public ListAdapter getAdapter(int position) {
|
||||
for (ListAdapter piece : pieces) {
|
||||
int size = piece.getCount();
|
||||
|
||||
if (position < size) {
|
||||
return piece;
|
||||
}
|
||||
|
||||
position -= size;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many items are in the data set represented by this
|
||||
* Adapter.
|
||||
*/
|
||||
@Override
|
||||
public int getCount() {
|
||||
int total = 0;
|
||||
|
||||
for (ListAdapter piece : pieces) {
|
||||
total += piece.getCount();
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of types of Views that will be
|
||||
* created by getView().
|
||||
*/
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
int total = 0;
|
||||
|
||||
for (ListAdapter piece : pieces) {
|
||||
total += piece.getViewTypeCount();
|
||||
}
|
||||
|
||||
return Math.max(total, 1); // needed for setListAdapter() before content add'
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of View that will be created by getView()
|
||||
* for the specified item.
|
||||
*
|
||||
* @param position Position of the item whose data we want
|
||||
*/
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
int typeOffset = 0;
|
||||
int result = -1;
|
||||
|
||||
for (ListAdapter piece : pieces) {
|
||||
int size = piece.getCount();
|
||||
|
||||
if (position < size) {
|
||||
result = typeOffset + piece.getItemViewType(position);
|
||||
break;
|
||||
}
|
||||
|
||||
position -= size;
|
||||
typeOffset += piece.getViewTypeCount();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are all items in this ListAdapter enabled? If yes it
|
||||
* means all items are selectable and clickable.
|
||||
*/
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item at the specified position is
|
||||
* not a separator.
|
||||
*
|
||||
* @param position Position of the item whose data we want
|
||||
*/
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
for (ListAdapter piece : pieces) {
|
||||
int size = piece.getCount();
|
||||
|
||||
if (position < size) {
|
||||
return piece.isEnabled(position);
|
||||
}
|
||||
|
||||
position -= size;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a View that displays the data at the specified
|
||||
* position in the data set.
|
||||
*
|
||||
* @param position Position of the item whose data we want
|
||||
* @param convertView View to recycle, if not null
|
||||
* @param parent ViewGroup containing the returned View
|
||||
*/
|
||||
@Override
|
||||
public View getView(int position, View convertView,
|
||||
ViewGroup parent) {
|
||||
for (ListAdapter piece : pieces) {
|
||||
int size = piece.getCount();
|
||||
|
||||
if (position < size) {
|
||||
|
||||
return piece.getView(position, convertView, parent);
|
||||
}
|
||||
|
||||
position -= size;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the row id associated with the specified position
|
||||
* in the list.
|
||||
*
|
||||
* @param position Position of the item whose data we want
|
||||
*/
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
for (ListAdapter piece : pieces) {
|
||||
int size = piece.getCount();
|
||||
|
||||
if (position < size) {
|
||||
return piece.getItemId(position);
|
||||
}
|
||||
|
||||
position -= size;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPositionForSection(int section) {
|
||||
int position = 0;
|
||||
|
||||
for (ListAdapter piece : pieces) {
|
||||
if (piece instanceof SectionIndexer) {
|
||||
Object[] sections = ((SectionIndexer) piece).getSections();
|
||||
int numSections = 0;
|
||||
|
||||
if (sections != null) {
|
||||
numSections = sections.length;
|
||||
}
|
||||
|
||||
if (section < numSections) {
|
||||
return position + ((SectionIndexer) piece).getPositionForSection(section);
|
||||
} else if (sections != null) {
|
||||
section -= numSections;
|
||||
}
|
||||
}
|
||||
|
||||
position += piece.getCount();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSectionForPosition(int position) {
|
||||
int section = 0;
|
||||
|
||||
for (ListAdapter piece : pieces) {
|
||||
int size = piece.getCount();
|
||||
|
||||
if (position < size) {
|
||||
if (piece instanceof SectionIndexer) {
|
||||
return section + ((SectionIndexer) piece).getSectionForPosition(position);
|
||||
}
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
if (piece instanceof SectionIndexer) {
|
||||
Object[] sections = ((SectionIndexer) piece).getSections();
|
||||
|
||||
if (sections != null) {
|
||||
section += sections.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
position -= size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getSections() {
|
||||
ArrayList<Object> sections = new ArrayList<Object>();
|
||||
|
||||
for (ListAdapter piece : pieces) {
|
||||
if (piece instanceof SectionIndexer) {
|
||||
Object[] curSections = ((SectionIndexer) piece).getSections();
|
||||
|
||||
if (curSections != null) {
|
||||
for (Object section : curSections) {
|
||||
sections.add(section);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sections.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return sections.toArray(new Object[0]);
|
||||
}
|
||||
|
||||
private static class EnabledSackAdapter extends SackOfViewsAdapter {
|
||||
public EnabledSackAdapter(List<View> views) {
|
||||
super(views);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areAllItemsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class CascadeDataSetObserver extends DataSetObserver {
|
||||
@Override
|
||||
public void onChanged() {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInvalidated() {
|
||||
notifyDataSetInvalidated();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,106 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.commonsware.cwac.merge;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.SpinnerAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Adapter that merges multiple child adapters into a single
|
||||
* contiguous whole to be consumed by a Spinner.
|
||||
* <p/>
|
||||
* Adapters used as pieces within MergeSpinnerAdapter must
|
||||
* have view type IDs monotonically increasing from 0.
|
||||
* Ideally, adapters also have distinct ranges for their row
|
||||
* ids, as returned by getItemId().
|
||||
* <p/>
|
||||
* All Adapters used as pieces within MergeSpinnerAdapter
|
||||
* must be properly-configured implementations of
|
||||
* SpinnerAdapter (e.g., ArrayAdapter, CursorAdapter).
|
||||
*/
|
||||
public class MergeSpinnerAdapter extends MergeAdapter {
|
||||
/**
|
||||
* Stock constructor, simply chaining to the superclass.
|
||||
*/
|
||||
public MergeSpinnerAdapter() {
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the drop-down View for a given position, by
|
||||
* iterating over the pieces. Assumes that all pieces are
|
||||
* implementations of SpinnerAdapter.
|
||||
*
|
||||
* @see android.widget.BaseAdapter#getDropDownView(int,
|
||||
* android.view.View, android.view.ViewGroup)
|
||||
*/
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView,
|
||||
ViewGroup parent) {
|
||||
for (ListAdapter piece : pieces) {
|
||||
int size = piece.getCount();
|
||||
|
||||
if (position < size) {
|
||||
return ((SpinnerAdapter) piece).getDropDownView(position,
|
||||
convertView,
|
||||
parent);
|
||||
}
|
||||
|
||||
position -= size;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new View to the roster of things to appear in
|
||||
* the aggregate list.
|
||||
*
|
||||
* @param view Single view to add
|
||||
*/
|
||||
@Override
|
||||
public void addView(View view) {
|
||||
throw new RuntimeException("Not supported with MergeSpinnerAdapter");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new View to the roster of things to appear in
|
||||
* the aggregate list.
|
||||
*
|
||||
* @param view Single view to add
|
||||
* @param enabled false if views are disabled, true if enabled
|
||||
*/
|
||||
@Override
|
||||
public void addView(View view, boolean enabled) {
|
||||
throw new RuntimeException("Not supported with MergeSpinnerAdapter");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a list of views to the roster of things to appear
|
||||
* in the aggregate list.
|
||||
*
|
||||
* @param views List of views to add
|
||||
*/
|
||||
@Override
|
||||
public void addViews(List<View> views) {
|
||||
throw new RuntimeException("Not supported with MergeSpinnerAdapter");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a list of views to the roster of things to appear
|
||||
* in the aggregate list.
|
||||
*
|
||||
* @param views List of views to add
|
||||
* @param enabled false if views are disabled, true if enabled
|
||||
*/
|
||||
@Override
|
||||
public void addViews(List<View> views, boolean enabled) {
|
||||
throw new RuntimeException("Not supported with MergeSpinnerAdapter");
|
||||
}
|
||||
}
|
||||
@ -1,356 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class ExpandableListFragment extends Fragment
|
||||
implements
|
||||
ExpandableListView.OnChildClickListener, ExpandableListView.OnGroupCollapseListener,
|
||||
ExpandableListView.OnGroupExpandListener {
|
||||
|
||||
static final int INTERNAL_EMPTY_ID = 0x00ff0001;
|
||||
|
||||
final private Handler mHandler = new Handler();
|
||||
|
||||
final private Runnable mRequestFocus = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mList.focusableViewAvailable(mList);
|
||||
}
|
||||
};
|
||||
|
||||
final private AdapterView.OnItemClickListener mOnClickListener
|
||||
= new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
||||
onListItemClick();
|
||||
}
|
||||
};
|
||||
|
||||
ExpandableListAdapter mAdapter;
|
||||
ExpandableListView mList;
|
||||
View mEmptyView;
|
||||
TextView mStandardEmptyView;
|
||||
boolean mSetEmptyText;
|
||||
boolean mListShown;
|
||||
boolean mFinishedStart = false;
|
||||
|
||||
/**
|
||||
* Provide default implementation to return a simple list view. Subclasses
|
||||
* can override to replace with their own layout. If doing so, the
|
||||
* returned view hierarchy <em>must</em> have a ListView whose id
|
||||
* is {@link android.R.id#list android.R.id.list} and can optionally
|
||||
* have a sibling view id {@link android.R.id#empty android.R.id.empty}
|
||||
* that is to be shown when the list is empty.
|
||||
* <p/>
|
||||
* <p>If you are overriding this method with your own custom content,
|
||||
* consider including the standard layout {@link android.R.layout#list_content}
|
||||
* in your layout file, so that you continue to retain all of the standard
|
||||
* behavior of ListFragment. In particular, this is currently the only
|
||||
* way to have the built-in indeterminant progress state be shown.
|
||||
*/
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
FrameLayout root = new FrameLayout(getActivity());
|
||||
|
||||
TextView tv = new TextView(getActivity());
|
||||
tv.setId(INTERNAL_EMPTY_ID);
|
||||
tv.setGravity(Gravity.CENTER);
|
||||
root.addView(tv, new FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
|
||||
|
||||
ExpandableListView lv = new ExpandableListView(getActivity());
|
||||
lv.setId(android.R.id.list);
|
||||
lv.setDrawSelectorOnTop(false);
|
||||
root.addView(lv, new FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
|
||||
|
||||
ListView.LayoutParams lp = new ListView.LayoutParams(
|
||||
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
|
||||
root.setLayoutParams(lp);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach to list view once Fragment is ready to run.
|
||||
*/
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
ensureList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach from list view.
|
||||
*/
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
mHandler.removeCallbacks(mRequestFocus);
|
||||
mList = null;
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called when an item in the list is selected.
|
||||
* Subclasses should override. Subclasses can call
|
||||
* getListView().getItemAtPosition(position) if they need to access the
|
||||
* data associated with the selected item.
|
||||
*/
|
||||
public void onListItemClick() {
|
||||
// override me
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the cursor for the list view.
|
||||
*/
|
||||
public void setListAdapter(ExpandableListAdapter adapter) {
|
||||
boolean hadAdapter = mAdapter != null;
|
||||
mAdapter = adapter;
|
||||
if (mList != null) {
|
||||
mList.setAdapter(adapter);
|
||||
if (!mListShown && !hadAdapter) {
|
||||
// The list was hidden, and previously didn't have an
|
||||
// adapter. It is now time to show it.
|
||||
setListShown(true, getView().getWindowToken() != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the currently selected list item to the specified
|
||||
* position with the adapter's data
|
||||
*
|
||||
* @param position
|
||||
*/
|
||||
public void setSelection(int position) {
|
||||
ensureList();
|
||||
mList.setSelection(position);
|
||||
}
|
||||
|
||||
public long getSelectedPosition() {
|
||||
ensureList();
|
||||
return mList.getSelectedPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selection to the specified child. If the child is in a collapsed
|
||||
* group, the group will only be expanded and child subsequently selected if
|
||||
* shouldExpandGroup is set to true, otherwise the method will return false.
|
||||
*
|
||||
* @param groupPosition The position of the group that contains the child.
|
||||
* @param childPosition The position of the child within the group.
|
||||
* @param shouldExpandGroup Whether the child's group should be expanded if
|
||||
* it is collapsed.
|
||||
* @return Whether the selection was successfully set on the child.
|
||||
*/
|
||||
public boolean setSelectedChild(int groupPosition, int childPosition, boolean shouldExpandGroup) {
|
||||
ensureList();
|
||||
return mList.setSelectedChild(groupPosition, childPosition, shouldExpandGroup);
|
||||
}
|
||||
|
||||
public void setItemChecked(int position, boolean value) {
|
||||
ensureList();
|
||||
mList.setItemChecked(position, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selection to the specified group.
|
||||
*
|
||||
* @param groupPosition The position of the group that should be selected.
|
||||
*/
|
||||
public void setSelectedGroup(int groupPosition) {
|
||||
mList.setSelectedGroup(groupPosition);
|
||||
}
|
||||
|
||||
public long getSelectedId() {
|
||||
ensureList();
|
||||
return mList.getSelectedId();
|
||||
}
|
||||
|
||||
public ExpandableListView getExpandableListView() {
|
||||
ensureList();
|
||||
return mList;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default content for a ListFragment has a TextView that can
|
||||
* be shown when the list is empty. If you would like to have it
|
||||
* shown, call this method to supply the text it should use.
|
||||
*/
|
||||
public void setEmptyText(CharSequence text) {
|
||||
ensureList();
|
||||
if (mStandardEmptyView == null) {
|
||||
throw new IllegalStateException("Can't be used with a custom content view");
|
||||
}
|
||||
mStandardEmptyView.setText(text);
|
||||
if (!mSetEmptyText) {
|
||||
mList.setEmptyView(mStandardEmptyView);
|
||||
mSetEmptyText = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Control whether the list is being displayed. You can make it not
|
||||
* displayed if you are waiting for the initial data to show in it. During
|
||||
* this time an indeterminant progress indicator will be shown instead.
|
||||
* <p/>
|
||||
* <p>Applications do not normally need to use this themselves. The default
|
||||
* behavior of ListFragment is to start with the list not being shown, only
|
||||
* showing it once an adapter is given with {@link #setListAdapter(ListAdapter)}.
|
||||
* If the list at that point had not been shown, when it does get shown
|
||||
* it will be do without the user ever seeing the hidden state.
|
||||
*
|
||||
* @param shown If true, the list view is shown; if false, the progress
|
||||
* indicator. The initial value is true.
|
||||
*/
|
||||
public void setListShown(boolean shown) {
|
||||
setListShown(shown, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link #setListShown(boolean)}, but no animation is used when
|
||||
* transitioning from the previous state.
|
||||
*/
|
||||
public void setListShownNoAnimation(boolean shown) {
|
||||
setListShown(shown, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Control whether the list is being displayed. You can make it not
|
||||
* displayed if you are waiting for the initial data to show in it. During
|
||||
* this time an indeterminant progress indicator will be shown instead.
|
||||
*
|
||||
* @param shown If true, the list view is shown; if false, the progress
|
||||
* indicator. The initial value is true.
|
||||
* @param animate If true, an animation will be used to transition to the
|
||||
* new state.
|
||||
*/
|
||||
private void setListShown(boolean shown, boolean animate) {
|
||||
ensureList();
|
||||
if (mListShown == shown) {
|
||||
return;
|
||||
}
|
||||
mListShown = shown;
|
||||
if (shown) {
|
||||
if (animate) {
|
||||
mList.startAnimation(AnimationUtils.loadAnimation(
|
||||
getActivity(), android.R.anim.fade_in));
|
||||
}
|
||||
mList.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
if (animate) {
|
||||
mList.startAnimation(AnimationUtils.loadAnimation(
|
||||
getActivity(), android.R.anim.fade_out));
|
||||
}
|
||||
mList.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ListAdapter associated with this activity's ListView.
|
||||
*/
|
||||
public ExpandableListAdapter getExpandableListAdapter() {
|
||||
return mAdapter;
|
||||
}
|
||||
|
||||
private void ensureList() {
|
||||
if (mList != null) {
|
||||
return;
|
||||
}
|
||||
View root = getView();
|
||||
if (root == null) {
|
||||
throw new IllegalStateException("Content view not yet created");
|
||||
}
|
||||
if (root instanceof ExpandableListView) {
|
||||
mList = (ExpandableListView) root;
|
||||
} else {
|
||||
mStandardEmptyView = (TextView) root.findViewById(INTERNAL_EMPTY_ID);
|
||||
if (mStandardEmptyView == null) {
|
||||
mEmptyView = root.findViewById(android.R.id.empty);
|
||||
}
|
||||
View rawListView = root.findViewById(android.R.id.list);
|
||||
if (!(rawListView instanceof ExpandableListView)) {
|
||||
if (rawListView == null) {
|
||||
throw new RuntimeException(
|
||||
"Your content must have a ExpandableListView whose id attribute is " +
|
||||
"'android.R.id.list'");
|
||||
}
|
||||
throw new RuntimeException(
|
||||
"Content has view with id attribute 'android.R.id.list' "
|
||||
+ "that is not a ExpandableListView class");
|
||||
}
|
||||
mList = (ExpandableListView) rawListView;
|
||||
if (mEmptyView != null) {
|
||||
mList.setEmptyView(mEmptyView);
|
||||
}
|
||||
}
|
||||
mListShown = true;
|
||||
mList.setOnItemClickListener(mOnClickListener);
|
||||
if (mAdapter != null) {
|
||||
setListAdapter(mAdapter);
|
||||
} else {
|
||||
// We are starting without an adapter, so assume we won't
|
||||
// have our data right away and start with the progress indicator.
|
||||
setListShown(false, false);
|
||||
}
|
||||
mHandler.post(mRequestFocus);
|
||||
}
|
||||
|
||||
public void onContentChanged() {
|
||||
View emptyView = getView().findViewById(android.R.id.empty);
|
||||
mList = (ExpandableListView) getView().findViewById(android.R.id.list);
|
||||
if (mList == null) {
|
||||
throw new RuntimeException(
|
||||
"Your content must have a ExpandableListView whose id attribute is " +
|
||||
"'android.R.id.list'");
|
||||
}
|
||||
if (emptyView != null) {
|
||||
mList.setEmptyView(emptyView);
|
||||
}
|
||||
mList.setOnChildClickListener(this);
|
||||
mList.setOnGroupExpandListener(this);
|
||||
mList.setOnGroupCollapseListener(this);
|
||||
|
||||
if (mFinishedStart) {
|
||||
setListAdapter(mAdapter);
|
||||
}
|
||||
mFinishedStart = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupExpand(int groupPosition) {
|
||||
// override me
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupCollapse(int groupPosition) {
|
||||
// override me
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v,
|
||||
int groupPosition, int childPosition, long id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.ui;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
import com.todoroo.astrid.ui.CalendarView.OnSelectedDateListener;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class CalendarDialog extends Dialog implements OnClickListener, OnSelectedDateListener {
|
||||
|
||||
private final Button cancelButton;
|
||||
private Date calendarDate;
|
||||
|
||||
public CalendarDialog(Context context, Date calendarDate) {
|
||||
super(context);
|
||||
this.calendarDate = calendarDate;
|
||||
/** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
/** Design the dialog in main.xml file */
|
||||
setContentView(R.layout.calendar);
|
||||
|
||||
LayoutParams params = getWindow().getAttributes();
|
||||
params.height = LayoutParams.FILL_PARENT;
|
||||
params.width = LayoutParams.FILL_PARENT;
|
||||
getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
|
||||
|
||||
cancelButton = (Button) findViewById(R.id.CancelButton);
|
||||
|
||||
CalendarView calendarView = (CalendarView) findViewById(R.id.CalendarView);
|
||||
calendarView.setCalendarDate(calendarDate);
|
||||
calendarView.setOnSelectedDateListener(this);
|
||||
|
||||
cancelButton.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == cancelButton) {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectedDate(Date date) {
|
||||
calendarDate = date;
|
||||
dismiss();
|
||||
}
|
||||
|
||||
public Date getCalendarDate() {
|
||||
return calendarDate;
|
||||
}
|
||||
|
||||
public void setCalendarDate(Date calendarDate) {
|
||||
this.calendarDate = calendarDate;
|
||||
}
|
||||
}
|
||||
@ -1,195 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* 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 com.todoroo.astrid.ui;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.Bundle;
|
||||
import android.text.format.DateFormat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.TimePicker;
|
||||
import android.widget.TimePicker.OnTimeChangedListener;
|
||||
|
||||
import com.timsu.astrid.R;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* A dialog that prompts the user for the time of day using a {@link TimePicker}.
|
||||
* This is similar to the Android {@link TimePickerDialog} class
|
||||
* except allows users to specify "no specific time".
|
||||
*/
|
||||
|
||||
public class DeadlineTimePickerDialog extends AlertDialog implements OnClickListener,
|
||||
OnTimeChangedListener {
|
||||
|
||||
/**
|
||||
* The callback interface used to indicate the user is done filling in
|
||||
* the time (they clicked on the 'Set' button).
|
||||
*/
|
||||
public interface OnDeadlineTimeSetListener {
|
||||
|
||||
/**
|
||||
* @param view The view associated with this listener.
|
||||
* @param hasTime whether time is set
|
||||
* @param hourOfDay The hour that was set.
|
||||
* @param minute The minute that was set.
|
||||
*/
|
||||
void onTimeSet(TimePicker view, boolean hasTime, int hourOfDay, int minute);
|
||||
}
|
||||
|
||||
private static final String HOUR = "hour";
|
||||
private static final String MINUTE = "minute";
|
||||
private static final String IS_24_HOUR = "is24hour";
|
||||
|
||||
private final TimePicker mTimePicker;
|
||||
private final CheckBox mHasTime;
|
||||
private final OnDeadlineTimeSetListener mCallback;
|
||||
private final Calendar mCalendar;
|
||||
private final java.text.DateFormat mDateFormat;
|
||||
|
||||
int mInitialHourOfDay;
|
||||
int mInitialMinute;
|
||||
boolean mIs24HourView;
|
||||
|
||||
/**
|
||||
* @param context Parent.
|
||||
* @param callBack How parent is notified.
|
||||
* @param hourOfDay The initial hour.
|
||||
* @param minute The initial minute.
|
||||
* @param is24HourView Whether this is a 24 hour view, or AM/PM.
|
||||
*/
|
||||
public DeadlineTimePickerDialog(Context context,
|
||||
OnDeadlineTimeSetListener callBack,
|
||||
int hourOfDay, int minute, boolean is24HourView, boolean hasTime) {
|
||||
this(context, android.R.style.Theme_Dialog,
|
||||
callBack, hourOfDay, minute, is24HourView, hasTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context Parent.
|
||||
* @param theme the theme to apply to this dialog
|
||||
* @param callBack How parent is notified.
|
||||
* @param hourOfDay The initial hour.
|
||||
* @param minute The initial minute.
|
||||
* @param is24HourView Whether this is a 24 hour view, or AM/PM.
|
||||
*/
|
||||
public DeadlineTimePickerDialog(Context context,
|
||||
int theme,
|
||||
OnDeadlineTimeSetListener callBack,
|
||||
int hourOfDay, int minute, boolean is24HourView, boolean hasTime) {
|
||||
super(context, theme);
|
||||
mCallback = callBack;
|
||||
mInitialHourOfDay = hourOfDay;
|
||||
mInitialMinute = minute;
|
||||
mIs24HourView = is24HourView;
|
||||
|
||||
mDateFormat = DateFormat.getTimeFormat(context);
|
||||
mCalendar = Calendar.getInstance();
|
||||
|
||||
setButton(context.getText(android.R.string.ok), this);
|
||||
setButton2(context.getText(android.R.string.cancel), (OnClickListener) null);
|
||||
setIcon(R.drawable.ic_dialog_time);
|
||||
|
||||
LayoutInflater inflater =
|
||||
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View view = inflater.inflate(R.layout.time_picker_dialog, null);
|
||||
setView(view);
|
||||
mTimePicker = (TimePicker) view.findViewById(R.id.timePicker);
|
||||
mHasTime = (CheckBox) view.findViewById(R.id.hasTime);
|
||||
OnCheckedChangeListener listener = new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
boolean isChecked) {
|
||||
mTimePicker.setEnabled(isChecked);
|
||||
if (isChecked) {
|
||||
updateTitle();
|
||||
} else {
|
||||
setTitle(R.string.TEA_urgency_none);
|
||||
}
|
||||
}
|
||||
};
|
||||
mHasTime.setOnCheckedChangeListener(listener);
|
||||
mHasTime.setChecked(hasTime);
|
||||
listener.onCheckedChanged(null, hasTime);
|
||||
|
||||
// initialize state
|
||||
mTimePicker.setCurrentHour(mInitialHourOfDay);
|
||||
mTimePicker.setCurrentMinute(mInitialMinute);
|
||||
mTimePicker.setIs24HourView(mIs24HourView);
|
||||
mTimePicker.setOnTimeChangedListener(this);
|
||||
updateTitle();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (mCallback != null) {
|
||||
mTimePicker.clearFocus();
|
||||
mCallback.onTimeSet(mTimePicker,
|
||||
mHasTime.isChecked(),
|
||||
mTimePicker.getCurrentHour(),
|
||||
mTimePicker.getCurrentMinute());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
public void updateTime(int hourOfDay, int minutOfHour) {
|
||||
mTimePicker.setCurrentHour(hourOfDay);
|
||||
mTimePicker.setCurrentMinute(minutOfHour);
|
||||
}
|
||||
|
||||
private void updateTitle() {
|
||||
int hour = mTimePicker.getCurrentHour();
|
||||
int minute = mTimePicker.getCurrentMinute();
|
||||
mCalendar.set(Calendar.HOUR_OF_DAY, hour);
|
||||
mCalendar.set(Calendar.MINUTE, minute);
|
||||
setTitle(mDateFormat.format(mCalendar.getTime()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle onSaveInstanceState() {
|
||||
Bundle state = super.onSaveInstanceState();
|
||||
state.putInt(HOUR, mTimePicker.getCurrentHour());
|
||||
state.putInt(MINUTE, mTimePicker.getCurrentMinute());
|
||||
state.putBoolean(IS_24_HOUR, mTimePicker.is24HourView());
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
int hour = savedInstanceState.getInt(HOUR);
|
||||
int minute = savedInstanceState.getInt(MINUTE);
|
||||
mTimePicker.setCurrentHour(hour);
|
||||
mTimePicker.setCurrentMinute(minute);
|
||||
mTimePicker.setIs24HourView(savedInstanceState.getBoolean(IS_24_HOUR));
|
||||
mTimePicker.setOnTimeChangedListener(this);
|
||||
updateTitle();
|
||||
}
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class NestedListView extends ListView {
|
||||
private static final int MAXIMUM_LIST_ITEMS_VIEWABLE = 2;
|
||||
|
||||
|
||||
public NestedListView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
int newHeight = 0;
|
||||
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
if (heightMode != MeasureSpec.EXACTLY) {
|
||||
ListAdapter listAdapter = getAdapter();
|
||||
if (listAdapter != null && !listAdapter.isEmpty()) {
|
||||
int listPosition = 0;
|
||||
for (listPosition = 0; listPosition < listAdapter.getCount()
|
||||
&& listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE; listPosition++) {
|
||||
View listItem = listAdapter.getView(listPosition, null,
|
||||
this);
|
||||
listItem.measure(widthMeasureSpec, heightMeasureSpec);
|
||||
newHeight += listItem.getMeasuredHeight();
|
||||
}
|
||||
newHeight += getDividerHeight() * listPosition;
|
||||
}
|
||||
if (heightMode == MeasureSpec.AT_MOST && newHeight > heightSize) {
|
||||
if (newHeight > heightSize) {
|
||||
newHeight = heightSize;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
newHeight = getMeasuredHeight();
|
||||
}
|
||||
setMeasuredDimension(getMeasuredWidth(), newHeight);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class TextViewWithMeasureListener extends TextView {
|
||||
|
||||
public interface OnTextMeasureListener {
|
||||
public void onTextSizeChanged();
|
||||
}
|
||||
|
||||
private OnTextMeasureListener listener;
|
||||
|
||||
|
||||
public TextViewWithMeasureListener(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
if (listener != null) {
|
||||
listener.onTextSizeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public OnTextMeasureListener getOnTextSizeChangedListener() {
|
||||
return listener;
|
||||
}
|
||||
|
||||
public void setOnTextSizeChangedListener(OnTextMeasureListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
||||
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 com.todoroo.astrid.utility;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* <p>Escapes and unescapes <code>String</code>s for
|
||||
* Java, Java Script, HTML, XML, and SQL.</p>
|
||||
*
|
||||
* @author Apache Jakarta Turbine
|
||||
* @author Purple Technology
|
||||
* @author <a href="mailto:alex@purpletech.com">Alexander Day Chaffee</a>
|
||||
* @author Antony Riley
|
||||
* @author Helge Tesgaard
|
||||
* @author <a href="sean@boohai.com">Sean Brown</a>
|
||||
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
|
||||
* @author Phil Steitz
|
||||
* @author Pete Gieser
|
||||
* @version $Id: StringEscapeUtils.java 2696 2007-06-20 13:24:53Z damencho $
|
||||
* @since 2.0
|
||||
*/
|
||||
|
||||
public class StringEscapeUtils {
|
||||
|
||||
/**
|
||||
* <p><code>StringEscapeUtils</code> instances should NOT be constructed in
|
||||
* standard programming.</p>
|
||||
* <p/>
|
||||
* <p>Instead, the class should be used as:
|
||||
* <pre>StringEscapeUtils.escapeJava("foo");</pre></p>
|
||||
* <p/>
|
||||
* <p>This constructor is public to permit tools that require a JavaBean
|
||||
* instance to operate.</p>
|
||||
*/
|
||||
public StringEscapeUtils() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>Unescapes a string containing entity escapes to a string
|
||||
* containing the actual Unicode characters corresponding to the
|
||||
* escapes. Supports HTML 4.0 entities.</p>
|
||||
* <p/>
|
||||
* <p>For example, the string "&lt;Fran&ccedil;ais&gt;"
|
||||
* will become "<Français>"</p>
|
||||
* <p/>
|
||||
* <p>If an entity is unrecognized, it is left alone, and inserted
|
||||
* verbatim into the result string. e.g. "&gt;&zzzz;x" will
|
||||
* become ">&zzzz;x".</p>
|
||||
*
|
||||
* @param str the <code>String</code> to unescape, may be null
|
||||
* @return a new unescaped <code>String</code>, <code>null</code> if null string input
|
||||
* @see #escapeHtml(Writer, String)
|
||||
*/
|
||||
public static String unescapeHtml(String str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
StringWriter writer = new StringWriter((int) (str.length() * 1.5));
|
||||
unescapeHtml(writer, str);
|
||||
return writer.toString();
|
||||
} catch (IOException e) {
|
||||
//assert false;
|
||||
//should be impossible
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Unescapes a string containing entity escapes to a string
|
||||
* containing the actual Unicode characters corresponding to the
|
||||
* escapes. Supports HTML 4.0 entities.</p>
|
||||
* <p/>
|
||||
* <p>For example, the string "&lt;Fran&ccedil;ais&gt;"
|
||||
* will become "<Français>"</p>
|
||||
* <p/>
|
||||
* <p>If an entity is unrecognized, it is left alone, and inserted
|
||||
* verbatim into the result string. e.g. "&gt;&zzzz;x" will
|
||||
* become ">&zzzz;x".</p>
|
||||
*
|
||||
* @param writer the writer receiving the unescaped string, not null
|
||||
* @param string the <code>String</code> to unescape, may be null
|
||||
* @throws IllegalArgumentException if the writer is null
|
||||
* @throws IOException if an IOException occurs
|
||||
* @see #escapeHtml(String)
|
||||
*/
|
||||
public static void unescapeHtml(Writer writer, String string) throws IOException {
|
||||
if (writer == null) {
|
||||
throw new IllegalArgumentException("The Writer must not be null.");
|
||||
}
|
||||
if (string == null) {
|
||||
return;
|
||||
}
|
||||
Entities.HTML40.unescape(writer, string);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue