Added images to comment bar and working on adding pictures

pull/14/head
Andrew Shaw 13 years ago
parent 03f2327dfe
commit ed10a08cbe

@ -12,13 +12,15 @@ import java.util.List;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.format.DateUtils;
import android.text.util.Linkify;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
@ -26,6 +28,7 @@ import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -38,6 +41,9 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.ActFmCameraModule;
import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback;
import com.todoroo.astrid.actfm.ActFmCameraModule.ClearImageCallback;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.core.PluginServices;
@ -76,6 +82,9 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
private View timerView;
private View commentButton;
private int commentItems = 10;
private ImageButton pictureButton;
private Bitmap picture = null;
private final List<UpdatesChangedListener> listeners = new LinkedList<UpdatesChangedListener>();
public interface UpdatesChangedListener {
@ -83,8 +92,8 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
public void commentAdded();
}
public EditNoteActivity(Context context, View parent, long t) {
super(context);
public EditNoteActivity(Activity activity, View parent, long t) {
super(activity);
DependencyInjectionService.getInstance().inject(this);
setOrientation(VERTICAL);
@ -92,7 +101,6 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
commentsBar = parent.findViewById(R.id.updatesFooter);
parentView = parent;
loadViewForTaskID(t);
}
@ -180,6 +188,23 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
}
});
final ClearImageCallback clearImage = new ClearImageCallback() {
@Override
public void clearImage() {
picture = null;
pictureButton.setImageResource(R.drawable.camera_button);
}
};
pictureButton = (ImageButton) commentsBar.findViewById(R.id.picture);
pictureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (picture != null)
ActFmCameraModule.showPictureLauncher((Activity)getContext(), clearImage);
else
ActFmCameraModule.showPictureLauncher((Activity)getContext(), null);
}
});
if(!TextUtils.isEmpty(task.getValue(Task.NOTES))) {
TextView notes = new TextView(getContext());
notes.setLinkTextColor(Color.rgb(100, 160, 255));
@ -268,9 +293,6 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
}
for (UpdatesChangedListener l : listeners) {
l.updatesChanged();
}
}
@ -313,23 +335,6 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
date.setText(dateString);
}
}
/*
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if(menu.size() > 0)
return true;
MenuItem item;
if(actFmPreferenceService.isLoggedIn()) {
item = menu.add(Menu.NONE, MENU_REFRESH_ID, Menu.NONE,
R.string.ENA_refresh_comments);
item.setIcon(R.drawable.ic_menu_refresh);
}
return true;
}*/
// --- events
public void refreshData(boolean manual, SyncResultCallback existingCallback) {
final SyncResultCallback callback;
@ -375,6 +380,8 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
private void addComment() {
addComment(commentField.getText().toString(), "task_comment"); //$NON-NLS-1$
}
private void addComment(String message, String actionCode) {
Update update = new Update();
update.setValue(Update.MESSAGE, message);
@ -382,12 +389,26 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
update.setValue(Update.USER_ID, 0L);
update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID));
update.setValue(Update.CREATION_DATE, DateUtilities.now());
if (picture != null) {
update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
}
Flags.checkAndClear(Flags.ACTFM_SUPPRESS_SYNC);
updateDao.createNew(update);
final long updateId = update.getId();
final Bitmap tempPicture = picture;
new Thread() {
@Override
public void run() {
actFmSyncService.pushUpdate(updateId, tempPicture);
}
}.start();
commentField.setText(""); //$NON-NLS-1$
setUpListAdapter();
picture = null;
pictureButton.setImageResource(R.drawable.camera_button);
StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_COMMENT);
for (UpdatesChangedListener l : listeners) {
@ -398,30 +419,6 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
public int numberOfComments() {
return items.size();
}
//TODO figure out what to do with menu
/*
private final OnClickListener dismissCommentsListener = new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
};
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// handle my own menus
switch (item.getItemId()) {
case MENU_REFRESH_ID: {
refreshData(true, null);
return true;
}
default: return false;
}
}*/
// --- adapter
private static class NoteOrUpdate {
private final String picture;
@ -495,4 +492,23 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
DateUtilities.getTimeString(getContext(), new Date()) + "\n" + getContext().getString(R.string.TEA_timer_comment_spent) + " " + elapsedTime, "task_stopped"); //$NON-NLS-1$
}
/*
* Callback from edittask when picture is added
*/
public boolean activityResult(int requestCode, int resultCode, Intent data) {
Log.d("Activity result", "Called on camera for request code: " + requestCode);
CameraResultCallback callback = new CameraResultCallback() {
@Override
public void handleCameraResult(Bitmap bitmap) {
picture = bitmap;
pictureButton.setImageBitmap(picture);
}
};
return (ActFmCameraModule.activityResult((Activity)getContext(), requestCode, resultCode, data, callback));
//Handled
}
}

@ -2,10 +2,10 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:state_enabled="true"
android:state_focused="false" android:drawable="@drawable/camera_button_red" />
android:state_focused="false" android:drawable="@drawable/camera_button_gray" />
<item android:state_pressed="true" android:state_enabled="true"
android:drawable="@drawable/camera_button_gray" />
android:drawable="@drawable/camera_button_red" />
<item android:state_pressed="false" android:state_enabled="true"
android:state_focused="true" android:drawable="@drawable/camera_button_gray" />
android:state_focused="true" android:drawable="@drawable/camera_button_red" />
</selector>

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/drawable/editbox_background.xml
**
** Copyright 2006, 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.
*/
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/footer_comment_edittext_focused" />
<item android:drawable="@drawable/footer_comment_edittext_normal" />
</selector>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:color="#f28118"
android:width="1dip" />
<gradient
android:startColor="#eeeeee"
android:endColor="#ffffff"
android:angle="270"
android:height="20dp" />
<size android:width="40dip"
android:height="40dip"/>
</shape>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#eeeeee"
android:endColor="#ffffff"
android:angle="270"
android:height="20dp" />
<stroke
android:color="#bbbbbf"
android:width="1dip" />
<size android:width="40dip"
android:height="40dip"/>
</shape>

@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/Content">
android:orientation="vertical" >
<LinearLayout
style="@style/Header"
@ -14,23 +13,25 @@
android:orientation="horizontal" >
<!-- List Label -->
<TextView android:id="@+id/listLabel"
<TextView
android:id="@+id/listLabel"
style="@style/TextAppearance.TLA_Header"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="100"
android:gravity="center"
android:singleLine="true"
android:ellipsize="start"
style="@style/TextAppearance.TLA_Header"/>
android:gravity="center"
android:singleLine="true" />
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="5dip"
style="@android:style/Widget.ProgressBar.Horizontal"
android:visibility="gone"
android:layout_weight="1" />
android:layout_weight="1"
android:visibility="gone" />
<ListView
android:id="@android:id/list"
@ -38,53 +39,62 @@
android:layout_height="fill_parent"
android:layout_weight="100" />
<!-- Footer -->
<LinearLayout
android:id="@+id/updatesFooter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="47dip"
android:layout_weight="1"
android:background="@drawable/footer_background"
android:padding="3dip"
android:orientation="horizontal">
android:minHeight="47dip"
android:orientation="horizontal"
android:padding="3dip" >
<!-- Voice Add Button -->
<ImageButton android:id="@+id/picture"
<ImageButton
android:id="@+id/picture"
android:layout_width="39dip"
android:layout_height="39dip"
android:layout_gravity="top"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:background="#00000000"
android:paddingBottom="2dip"
android:paddingLeft="7dip"
android:paddingRight="7dip"
android:paddingBottom="2dip"
android:layout_weight="1"
android:src="@drawable/camera_button"
android:scaleType="fitCenter"/>
android:scaleType="centerInside"
android:src="@drawable/camera_button" />
<!-- Quick Add Task -->
<EditText android:id="@+id/commentField"
<EditText
android:id="@+id/commentField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dip"
android:layout_marginRight="1dip"
android:layout_marginLeft="1dip"
android:paddingLeft="10dip"
android:layout_weight="100"
android:background="@drawable/footer_edittext"
android:hint="@string/TVA_add_comment"
android:textSize="16sp"
android:autoText="true"
android:capitalize="sentences"/>
android:background="@drawable/footer_comment_edittext"
android:capitalize="sentences"
android:hint="@string/TVA_add_comment"
android:textSize="16sp" />
<!-- Extended Add Button -->
<ImageButton android:id="@+id/commentButton"
<ImageButton
android:id="@+id/commentButton"
android:layout_width="wrap_content"
android:layout_height="39dip"
android:layout_gravity="top"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:background="@drawable/footer_button"
android:src="@drawable/ic_footer_add"
android:scaleType="center"/>
android:scaleType="center"
android:src="@drawable/ic_footer_add" />
</LinearLayout>
</LinearLayout>

@ -125,10 +125,12 @@
android:id="@+id/commentField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dip"
android:layout_marginRight="1dip"
android:layout_marginLeft="1dip"
android:paddingLeft="10dip"
android:layout_weight="100"
android:autoText="true"
android:background="@drawable/footer_edittext"
android:background="@drawable/footer_comment_edittext"
android:capitalize="sentences"
android:hint="@string/TVA_add_comment"
android:textSize="16sp" />
@ -137,14 +139,14 @@
<LinearLayout
android:id="@+id/timer_container"
android:layout_width="40dip"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_marginLeft="5dip"
android:layout_marginLeft="3dip"
android:orientation="vertical"
android:layout_weight="1">
<Button
android:id="@+id/timer_button"
android:layout_width="25dip"
android:layout_width="30dip"
android:layout_height="25dip"
android:layout_marginTop="7dip"
android:scaleType="fitCenter"
@ -155,8 +157,8 @@
<ImageButton
android:id="@+id/commentButton"
android:layout_width="wrap_content"
android:layout_height="39dip"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_gravity="top"
android:layout_marginRight="3dip"
android:layout_weight="1"

@ -370,7 +370,7 @@ public final class TaskEditActivity extends Fragment implements
long idParam = getActivity().getIntent().getLongExtra(TOKEN_ID,
-1L);
if (remoteId > 0 && idParam > -1L) {
if (editNotes == null) {
// if (editNotes == null) {
editNotes = new EditNoteActivity(getActivity(), getView(),
idParam);
editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
@ -378,10 +378,13 @@ public final class TaskEditActivity extends Fragment implements
if (timerAction != null) {
timerAction.addListener(editNotes);
}
}
else {
editNotes.loadViewForTaskID(idParam);
Log.d("Did not add timerAction", "did not add timer action");
}
// }
// else {
// editNotes.loadViewForTaskID(idParam);
// }
if (mAdapter == null) {
mAdapter = new TaskEditViewPager(getActivity());
mAdapter.parent = this;
@ -1084,6 +1087,9 @@ public final class TaskEditActivity extends Fragment implements
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (editNotes.activityResult(requestCode, resultCode, data)) {
return;
}
if (requestCode == REQUEST_VOICE_RECOG
&& resultCode == Activity.RESULT_OK) {
// handle the result of voice recognition, put it into the

Loading…
Cancel
Save