Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added first steps towards configurable quick capture widget.
- Loading branch information
Showing
10 changed files
with
267 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<solid android:color="@android:color/background_dark"/> | ||
|
||
<padding | ||
android:left="5dp" | ||
android:top="1dp" | ||
android:right="5dp" | ||
android:bottom="1dp"/> | ||
|
||
<corners | ||
android:bottomRightRadius="10dp" | ||
android:bottomLeftRadius="10dp" | ||
android:topLeftRadius="10dp" | ||
android:topRightRadius="10dp"/> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/capture_widget_root" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_margin="15dp" | ||
android:orientation="vertical" > | ||
|
||
<ImageView | ||
android:id="@+id/capture_widget_icon" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="center" | ||
android:layout_weight="1" | ||
android:src="@drawable/widget_capture" /> | ||
|
||
<TextView | ||
android:id="@+id/capture_widget_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:background="@drawable/capture_widget_text_bg" | ||
android:text="Widget" | ||
android:textColor="@android:color/primary_text_dark" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" > | ||
|
||
<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" | ||
android:layout_height="wrap_content" | ||
android:tag="captureLocationFragment" /> | ||
</LinearLayout> | ||
|
||
<LinearLayout | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" > | ||
|
||
<Button | ||
android:id="@+id/widget_save" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/save" /> | ||
|
||
<Button | ||
android:id="@+id/widget_cancel" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/cancel" /> | ||
</LinearLayout> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:configure="com.matburt.mobileorg.Gui.Widget.CaptureWidgetConfig" | ||
android:initialLayout="@layout/capture_widget" | ||
android:minHeight="72dp" | ||
android:minWidth="72dp" | ||
android:previewImage="@drawable/icon" | ||
android:resizeMode="horizontal|vertical" | ||
android:updatePeriodMillis="86400000" > | ||
|
||
</appwidget-provider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/com/matburt/mobileorg/Gui/Widget/CaptureWidgetConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.matburt.mobileorg.Gui.Widget; | ||
|
||
import android.appwidget.AppWidgetManager; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.widget.Button; | ||
|
||
import com.actionbarsherlock.app.SherlockFragmentActivity; | ||
import com.matburt.mobileorg.R; | ||
import com.matburt.mobileorg.Gui.Capture.LocationFragment; | ||
import com.matburt.mobileorg.OrgData.OrgNode; | ||
|
||
public class CaptureWidgetConfig extends SherlockFragmentActivity { | ||
|
||
private int mAppWidgetId; | ||
private LocationFragment locationFragment; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
setContentView(R.layout.capture_widget_config); | ||
|
||
Intent intent = getIntent(); | ||
Bundle extras = intent.getExtras(); | ||
if (extras != null) { | ||
mAppWidgetId = extras.getInt( | ||
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); | ||
} | ||
|
||
((Button) findViewById(R.id.widget_save)).setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
saveConfig(); | ||
} | ||
}); | ||
|
||
((Button) findViewById(R.id.widget_cancel)).setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
cancelConfig(); | ||
} | ||
}); | ||
|
||
locationFragment = (LocationFragment) getSupportFragmentManager() | ||
.findFragmentByTag("captureLocationFragment"); | ||
} | ||
|
||
|
||
private void saveConfig() { | ||
save(); | ||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); | ||
CaptureWidgetProvider.updateWidget(mAppWidgetId, appWidgetManager, this); | ||
|
||
Intent resultValue = new Intent(); | ||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); | ||
setResult(RESULT_OK, resultValue); | ||
finish(); | ||
} | ||
|
||
private void save() { | ||
OrgNode node = locationFragment.getLocationSelection(); | ||
String locationOlpId = node.getOlpId(getContentResolver()); | ||
|
||
CaptureWidgetProvider.writeConfig(mAppWidgetId, locationOlpId, | ||
getApplicationContext()); | ||
} | ||
|
||
private void cancelConfig() { | ||
Intent resultValue = new Intent(); | ||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); | ||
setResult(RESULT_CANCELED, resultValue); | ||
finish(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/com/matburt/mobileorg/Gui/Widget/CaptureWidgetProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.matburt.mobileorg.Gui.Widget; | ||
|
||
import android.app.PendingIntent; | ||
import android.appwidget.AppWidgetManager; | ||
import android.appwidget.AppWidgetProvider; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.content.SharedPreferences.Editor; | ||
import android.widget.RemoteViews; | ||
|
||
import com.matburt.mobileorg.R; | ||
import com.matburt.mobileorg.Gui.Capture.EditActivity; | ||
|
||
public class CaptureWidgetProvider extends AppWidgetProvider { | ||
public static final String LOCATION = "location"; | ||
|
||
@Override | ||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, | ||
int[] appWidgetIds) { | ||
super.onUpdate(context, appWidgetManager, appWidgetIds); | ||
try { | ||
for (int i = 0; i < appWidgetIds.length; i++) { | ||
int appWidgetId = appWidgetIds[i]; | ||
updateWidget(appWidgetId, appWidgetManager, context); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static void updateWidget(int appWidgetId, | ||
AppWidgetManager appWidgetManager, Context context) { | ||
SharedPreferences prefs = context.getSharedPreferences("widget_" | ||
+ appWidgetId, Context.MODE_PRIVATE); | ||
if (null == prefs) | ||
return; | ||
|
||
RemoteViews views = new RemoteViews(context.getPackageName(), | ||
R.layout.capture_widget); | ||
|
||
String location = prefs.getString(LOCATION, "???"); | ||
views.setTextViewText(R.id.capture_widget_text, | ||
prefs.getString("name", location)); | ||
|
||
Intent intent = getWidgetIntent(appWidgetId, context); | ||
|
||
PendingIntent pendingIntent = PendingIntent.getActivity( | ||
context, appWidgetId, intent, PendingIntent.FLAG_CANCEL_CURRENT); | ||
views.setOnClickPendingIntent(R.id.capture_widget_root, | ||
pendingIntent); | ||
|
||
appWidgetManager.updateAppWidget(appWidgetId, views); | ||
} | ||
|
||
private static Intent getWidgetIntent(int appWidgetId, Context context) { | ||
Intent intent = new Intent(context, EditActivity.class); | ||
|
||
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(); | ||
edit.putString(LOCATION, locationOlp); | ||
edit.commit(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...t/mobileorg/Services/MobileOrgWidget.java → ...mobileorg/Gui/Widget/MobileOrgWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters