Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fully functional capture widget.

  • Loading branch information...
commit 664a7474db1445643374c63917bebf3ef05fb4e7 1 parent 39e4bba
@hdweiss hdweiss authored
View
23 res/layout/capture_widget_config.xml
@@ -10,6 +10,20 @@
android:layout_height="wrap_content"
android:paddingTop="3dip" >
+ <EditText
+ android:id="@+id/widget_title"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/title"
+ android:inputType="text|textMultiLine|textAutoCorrect|textCapSentences" />
+ </LinearLayout>
+
+ <LinearLayout
+ style="@style/EditBorders"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="3dip" >
+
<fragment
android:name="com.matburt.mobileorg.Gui.Capture.LocationFragment"
android:layout_width="fill_parent"
@@ -20,19 +34,20 @@
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
+ android:gravity="center"
android:orientation="horizontal" >
<Button
- android:id="@+id/widget_save"
+ android:id="@+id/widget_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/save" />
+ android:text="@string/cancel" />
<Button
- android:id="@+id/widget_cancel"
+ android:id="@+id/widget_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/cancel" />
+ android:text="@string/save" />
</LinearLayout>
</LinearLayout>
View
4 src/com/matburt/mobileorg/Gui/Capture/EditActivity.java
@@ -20,7 +20,7 @@
import com.matburt.mobileorg.util.OrgNodeNotFoundException;
import com.matburt.mobileorg.util.OrgUtils;
-public class EditActivity extends SherlockFragmentActivity implements
+public class EditActivity extends SherlockFragmentActivity implements EditHost,
PayloadFragment.OnPayloadModifiedListener,
DatesFragment.OnDatesModifiedListener {
public final static String NODE_ID = "node_id";
@@ -38,7 +38,7 @@
private String actionMode;
private ContentResolver resolver;
-
+
@Override
public void onCreate(Bundle savedInstanceState) {
OrgUtils.setTheme(this);
View
12 src/com/matburt/mobileorg/Gui/Capture/EditHost.java
@@ -0,0 +1,12 @@
+package com.matburt.mobileorg.Gui.Capture;
+
+import com.matburt.mobileorg.OrgData.OrgNode;
+
+public interface EditHost {
+ public boolean isNodeEditable();
+ public OrgNode getOrgNode();
+ public String getActionMode();
+
+ public boolean isNodeRefilable();
+ public OrgNode getParentOrgNode();
+}
View
10 src/com/matburt/mobileorg/Gui/Capture/HeadingFragment.java
@@ -46,9 +46,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- EditActivity activity = ((EditActivity)getActivity());
+ EditHost activity = ((EditHost)getActivity());
- this.resolver = activity.getContentResolver();
+ this.resolver = getActivity().getContentResolver();
this.node = activity.getOrgNode();
if(savedInstanceState != null)
@@ -128,15 +128,15 @@ public OrgNode getEditedOrgNode() {
}
- private String getTitle() {
+ public String getTitle() {
return titleView.getText().toString();
}
- private String getTodo() {
+ public String getTodo() {
return todoStateView.getSelectedItem().toString();
}
- private String getPriority() {
+ public String getPriority() {
return priorityView.getSelectedItem().toString();
}
}
View
21 src/com/matburt/mobileorg/Gui/Capture/LocationFragment.java
@@ -5,7 +5,6 @@
import android.content.ContentResolver;
import android.os.Bundle;
-import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
@@ -41,24 +40,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
-
- FragmentActivity activity = getActivity();
- this.resolver = activity.getContentResolver();
+
+ this.resolver = getActivity().getContentResolver();
+ EditHost activity = (EditHost) getActivity();
restoreFromBundle(savedInstanceState);
- boolean isModifiable = true;
- try {
- EditActivity editActivity = (EditActivity) activity;
+ EditHost editActivity = (EditHost) activity;
- if (this.node == null)
- this.node = editActivity.getParentOrgNode();
+ if (this.node == null)
+ this.node = editActivity.getParentOrgNode();
- isModifiable = editActivity.isNodeRefilable();
- } catch (ClassCastException e) {}
-
initLocationView();
- setModifiable(isModifiable);
+
+ setModifiable(editActivity.isNodeRefilable());
}
@Override
View
41 src/com/matburt/mobileorg/Gui/Widget/CaptureWidgetConfig.java
@@ -6,16 +6,20 @@
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
+import android.widget.EditText;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.matburt.mobileorg.R;
+import com.matburt.mobileorg.Gui.Capture.EditActivity;
+import com.matburt.mobileorg.Gui.Capture.EditHost;
import com.matburt.mobileorg.Gui.Capture.LocationFragment;
import com.matburt.mobileorg.OrgData.OrgNode;
-public class CaptureWidgetConfig extends SherlockFragmentActivity {
+public class CaptureWidgetConfig extends SherlockFragmentActivity implements EditHost {
private int mAppWidgetId;
private LocationFragment locationFragment;
+ private EditText titleView;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -44,7 +48,9 @@ public void onClick(View v) {
}
});
- locationFragment = (LocationFragment) getSupportFragmentManager()
+ titleView = (EditText) findViewById(R.id.widget_title);
+
+ locationFragment = (LocationFragment) getSupportFragmentManager()
.findFragmentByTag("captureLocationFragment");
}
@@ -63,9 +69,9 @@ private void saveConfig() {
private void save() {
OrgNode node = locationFragment.getLocationSelection();
String locationOlpId = node.getOlpId(getContentResolver());
+ String title = titleView.getText().toString();
- CaptureWidgetProvider.writeConfig(mAppWidgetId, locationOlpId,
- getApplicationContext());
+ CaptureWidgetProvider.writeConfig(mAppWidgetId, this, locationOlpId, title);
}
private void cancelConfig() {
@@ -74,4 +80,31 @@ private void cancelConfig() {
setResult(RESULT_CANCELED, resultValue);
finish();
}
+
+
+ @Override
+ public boolean isNodeEditable() {
+ return true;
+ }
+
+
+ @Override
+ public OrgNode getOrgNode() {
+ return null;
+ }
+
+ @Override
+ public String getActionMode() {
+ return EditActivity.ACTIONMODE_ADDCHILD;
+ }
+
+ @Override
+ public boolean isNodeRefilable() {
+ return true;
+ }
+
+ @Override
+ public OrgNode getParentOrgNode() {
+ return null;
+ }
}
View
33 src/com/matburt/mobileorg/Gui/Widget/CaptureWidgetProvider.java
@@ -11,9 +11,12 @@
import com.matburt.mobileorg.R;
import com.matburt.mobileorg.Gui.Capture.EditActivity;
+import com.matburt.mobileorg.OrgData.OrgNode;
+import com.matburt.mobileorg.OrgData.OrgProviderUtils;
public class CaptureWidgetProvider extends AppWidgetProvider {
public static final String LOCATION = "location";
+ public static final String TITLE = "title";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
@@ -31,17 +34,16 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager,
public static void updateWidget(int appWidgetId,
AppWidgetManager appWidgetManager, Context context) {
- SharedPreferences prefs = context.getSharedPreferences("widget_"
- + appWidgetId, Context.MODE_PRIVATE);
+ SharedPreferences prefs = getPreferences(appWidgetId, context);
if (null == prefs)
return;
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.capture_widget);
- String location = prefs.getString(LOCATION, "???");
+ String title = prefs.getString(TITLE, "???");
views.setTextViewText(R.id.capture_widget_text,
- prefs.getString("name", location));
+ prefs.getString("name", title));
Intent intent = getWidgetIntent(appWidgetId, context);
@@ -55,16 +57,29 @@ public static void updateWidget(int appWidgetId,
private static Intent getWidgetIntent(int appWidgetId, Context context) {
Intent intent = new Intent(context, EditActivity.class);
+ intent.putExtra(EditActivity.ACTIONMODE, EditActivity.ACTIONMODE_ADDCHILD);
+
+ SharedPreferences prefs = getPreferences(appWidgetId, context);
+ String olpLocation = prefs.getString(LOCATION, "");
+ try {
+ OrgNode parentNode = OrgProviderUtils.getOrgNodeFromOlpPath(
+ olpLocation, context.getContentResolver());
+ intent.putExtra(EditActivity.NODE_ID, parentNode.id);
+ } catch (Exception e) {}
return intent;
}
- public static void writeConfig(int appWidgetId, String locationOlp, Context context) {
- SharedPreferences prefs = context.getSharedPreferences("widget_"
- + appWidgetId, Context.MODE_PRIVATE);
-
- Editor edit = prefs.edit();
+ public static void writeConfig(int appWidgetId, Context context, String locationOlp, String title) {
+ Editor edit = getPreferences(appWidgetId, context).edit();
edit.putString(LOCATION, locationOlp);
+ edit.putString(TITLE, title);
edit.commit();
}
+
+ public static SharedPreferences getPreferences(int appWidgetId, Context context) {
+ SharedPreferences prefs = context.getSharedPreferences("widget_"
+ + appWidgetId, Context.MODE_PRIVATE);
+ return prefs;
+ }
}

0 comments on commit 664a747

Please sign in to comment.
Something went wrong with that request. Please try again.