Browse Source

Added new widget config acitivity (the actual wisget is to follow).

pull/13/merge
Eric Kok 11 years ago
parent
commit
85c2263f85
  1. BIN
      core/res/drawable-hdpi/ic_action_done_dark.png
  2. BIN
      core/res/drawable-hdpi/ic_action_done_light.png
  3. BIN
      core/res/drawable-mdpi/ic_action_done_dark.png
  4. BIN
      core/res/drawable-mdpi/ic_action_done_light.png
  5. BIN
      core/res/drawable-xhdpi/ic_action_done_dark.png
  6. BIN
      core/res/drawable-xhdpi/ic_action_done_light.png
  7. 37
      core/res/layout/actionbar_donebutton.xml
  8. 91
      core/res/layout/activity_widgetconfig.xml
  9. 69
      core/res/layout/widget_torrents_dark.xml
  10. 69
      core/res/layout/widget_torrents_light.xml
  11. 11
      core/res/values-sw600dp/dimens.xml
  12. 21
      core/res/values-v14/dimens.xml
  13. 1
      core/res/values/attrs.xml
  14. 7
      core/res/values/dimens.xml
  15. 7
      core/res/values/strings.xml
  16. 2
      core/res/values/styles.xml
  17. 29
      core/res/xml/appwidget_info.xml
  18. 30
      core/src/org/transdroid/core/app/settings/ApplicationSettings.java
  19. 46
      core/src/org/transdroid/core/gui/lists/SortByListItem.java
  20. 4
      core/src/org/transdroid/core/gui/navigation/StatusType.java
  21. 265
      core/src/org/transdroid/core/widget/WidgetConfigActivity.java
  22. 34
      core/src/org/transdroid/core/widget/WidgetProvider.java
  23. 63
      core/src/org/transdroid/core/widget/WidgetSettings.java
  24. 18
      full/AndroidManifest.xml
  25. 1
      lite/AndroidManifest.xml

BIN
core/res/drawable-hdpi/ic_action_done_dark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
core/res/drawable-hdpi/ic_action_done_light.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
core/res/drawable-mdpi/ic_action_done_dark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
core/res/drawable-mdpi/ic_action_done_light.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
core/res/drawable-xhdpi/ic_action_done_dark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
core/res/drawable-xhdpi/ic_action_done_light.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

37
core/res/layout/actionbar_donebutton.xml

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2010-2013 Eric Kok et al.
Based on Roman Nurik 2012 Apache License, Version 2.0
Transdroid is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Transdroid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionbar_done"
style="?actionButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<TextView
style="?actionBarTabTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableLeft="?attr/ic_action_done"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:paddingRight="20dp"
android:text="@string/widget_done" />
</FrameLayout>

91
core/res/layout/activity_widgetconfig.xml

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2010-2013 Eric Kok et al.
Transdroid is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Transdroid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerPadding="@dimen/margin_default"
android:orientation="@integer/widget_config_orientation"
android:padding="@dimen/margin_default" >
<FrameLayout
android:layout_width="@dimen/widget_preview_width"
android:layout_height="@dimen/widget_preview_height"
android:layout_gravity="center_horizontal"
android:background="@null"
android:padding="@dimen/widget_preview_padding" >
<include layout="@layout/widget_torrents_light" />
</FrameLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/filterheader_text"
style="@style/SectionHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/widget_filter"
android:textIsSelectable="false" />
<Spinner
android:id="@+id/server_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/filter_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/sort_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/reverseorder_check_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/widget_reversesortorder" />
<TextView
android:id="@+id/lookfeelheader_text"
style="@style/SectionHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/widget_lookfeel"
android:textIsSelectable="false" />
<CheckBox
android:id="@+id/darktheme_check_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/widget_usedarktheme" />
</LinearLayout>
</ScrollView>
</LinearLayout>

69
core/res/layout/widget_torrents_dark.xml

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin_widget" >
<ImageButton
android:id="@+id/icon_image"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/selectable_background_transdroid2"
android:contentDescription="@string/widget_opentransdroid"
android:padding="8dp"
android:src="@drawable/ic_launcher"
android:scaleType="fitXY" />
<include
android:id="@+id/status_view"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignParentRight="true"
layout="@layout/actionbar_serverstatus"
android:background="@drawable/selectable_background_transdroid2" />
<include
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_toLeftOf="@id/navigation_view"
android:layout_toRightOf="@id/icon_image"
layout="@layout/actionbar_navigation"
android:background="@color/background_light" />
<View
android:id="@+id/topline_view"
android:layout_height="2dp"
android:layout_width="match_parent"
android:layout_below="@id/icon_image"
android:background="@color/green" />
<View
android:id="@+id/bottomline_view"
android:layout_height="2dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:background="@color/green" />
<com.actionbarsherlock.view.SherlockListView
android:id="@+id/torrents_list"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="@id/topline_view"
android:layout_above="@id/bottomline_view"
android:visibility="gone" />
<TextView
android:id="@+id/error_text"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="@id/topline_view"
android:layout_above="@id/bottomline_view"
android:layout_gravity="center"
android:gravity="center"
android:maxWidth="400dip"
android:padding="@dimen/margin_default"
android:textIsSelectable="false"
android:visibility="gone" />
</RelativeLayout>

69
core/res/layout/widget_torrents_light.xml

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin_widget" >
<ImageButton
android:id="@+id/icon_image"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@drawable/selectable_background_transdroid2"
android:contentDescription="@string/widget_opentransdroid"
android:padding="8dp"
android:src="@drawable/ic_launcher"
android:scaleType="fitXY" />
<include
android:id="@+id/status_view"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignParentRight="true"
layout="@layout/actionbar_serverstatus"
android:background="@drawable/selectable_background_transdroid2" />
<include
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_toLeftOf="@id/navigation_view"
android:layout_toRightOf="@id/icon_image"
layout="@layout/actionbar_navigation"
android:background="@color/background_light" />
<View
android:id="@+id/topline_view"
android:layout_height="2dp"
android:layout_width="match_parent"
android:layout_below="@id/icon_image"
android:background="@color/green" />
<View
android:id="@+id/bottomline_view"
android:layout_height="2dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:background="@color/green" />
<com.actionbarsherlock.view.SherlockListView
android:id="@+id/torrents_list"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="@id/topline_view"
android:layout_above="@id/bottomline_view"
android:visibility="gone" />
<TextView
android:id="@+id/error_text"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="@id/topline_view"
android:layout_above="@id/bottomline_view"
android:layout_gravity="center"
android:gravity="center"
android:maxWidth="400dip"
android:padding="@dimen/margin_default"
android:textIsSelectable="false"
android:visibility="gone" />
</RelativeLayout>

11
core/res/values-sw600dp/dimens.xml

@ -16,11 +16,6 @@
--> -->
<resources> <resources>
<!-- Margins -->
<dimen name="margin_default">16dp</dimen>
<dimen name="margin_half">8dp</dimen>
<dimen name="margin_torrentlistleft">16dp</dimen>
<!-- Text sizes --> <!-- Text sizes -->
<dimen name="text_small">14sp</dimen> <dimen name="text_small">14sp</dimen>
<dimen name="text_default">17sp</dimen> <dimen name="text_default">17sp</dimen>
@ -40,4 +35,10 @@
<dimen name="ui_serverstatus_smallnumber">14sp</dimen> <dimen name="ui_serverstatus_smallnumber">14sp</dimen>
<dimen name="ui_serverstatus_width">63dp</dimen> <dimen name="ui_serverstatus_width">63dp</dimen>
<!-- Widget configuration -->
<integer name="widget_config_orientation">0</integer>
<dimen name="widget_preview_padding">15dp</dimen>
<dimen name="widget_preview_height">-1dp</dimen>
<dimen name="widget_preview_width">300dp</dimen>
</resources> </resources>

21
core/res/values-v14/dimens.xml

@ -0,0 +1,21 @@
<!--
Copyright 2010-2013 Eric Kok et al.
Transdroid is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Transdroid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
-->
<resources>
<dimen name="margin_widget">0dp</dimen>
</resources>

1
core/res/values/attrs.xml

@ -42,6 +42,7 @@
<attr name="ic_action_stop" format="reference"/> <attr name="ic_action_stop" format="reference"/>
<attr name="ic_action_trackers" format="reference"/> <attr name="ic_action_trackers" format="reference"/>
<attr name="ic_action_website" format="reference"/> <attr name="ic_action_website" format="reference"/>
<attr name="ic_action_done" format="reference"/>
<attr name="loading_progress" format="reference"/> <attr name="loading_progress" format="reference"/>
<attr name="selectable_background_transdroid" format="reference"/> <attr name="selectable_background_transdroid" format="reference"/>
<attr name="text_bright" format="reference" /> <attr name="text_bright" format="reference" />

7
core/res/values/dimens.xml

@ -20,6 +20,7 @@
<dimen name="margin_default">16dp</dimen> <dimen name="margin_default">16dp</dimen>
<dimen name="margin_half">8dp</dimen> <dimen name="margin_half">8dp</dimen>
<dimen name="margin_torrentlistleft">16dp</dimen> <dimen name="margin_torrentlistleft">16dp</dimen>
<dimen name="margin_widget">8dp</dimen>
<!-- Text sizes --> <!-- Text sizes -->
<dimen name="text_small">12sp</dimen> <dimen name="text_small">12sp</dimen>
@ -40,4 +41,10 @@
<dimen name="ui_serverstatus_smallnumber">13sp</dimen> <dimen name="ui_serverstatus_smallnumber">13sp</dimen>
<dimen name="ui_serverstatus_width">53dp</dimen> <dimen name="ui_serverstatus_width">53dp</dimen>
<!-- Widget configuration -->
<integer name="widget_config_orientation">1</integer>
<dimen name="widget_preview_padding">10dp</dimen>
<dimen name="widget_preview_height">150dp</dimen>
<dimen name="widget_preview_width">-1dp</dimen>
</resources> </resources>

7
core/res/values/strings.xml

@ -190,6 +190,13 @@
</plurals> </plurals>
<string name="rss_service_newfor">New torrents for %1$s</string> <string name="rss_service_newfor">New torrents for %1$s</string>
<string name="widget_opentransdroid">Open Transdroid</string>
<string name="widget_filter">SERVER VIEW</string>
<string name="widget_lookfeel">LOOK &amp; FEEL</string>
<string name="widget_reversesortorder">Reverse sort order</string>
<string name="widget_usedarktheme">Use dark theme</string>
<string name="widget_done">DONE</string>
<string name="pref_servers">Servers</string> <string name="pref_servers">Servers</string>
<string name="pref_addserver">Add new server</string> <string name="pref_addserver">Add new server</string>
<string name="pref_searchsites">Search sites</string> <string name="pref_searchsites">Search sites</string>

2
core/res/values/styles.xml

@ -22,6 +22,7 @@
<item name="android:windowBackground">@color/background_light</item> <item name="android:windowBackground">@color/background_light</item>
<item name="ic_action_discard">@drawable/ic_action_discard_light</item> <item name="ic_action_discard">@drawable/ic_action_discard_light</item>
<item name="ic_action_done">@drawable/ic_action_done_light</item>
<item name="ic_action_filter">@drawable/ic_action_filter_light</item> <item name="ic_action_filter">@drawable/ic_action_filter_light</item>
<item name="ic_action_labels">@drawable/ic_action_labels_light</item> <item name="ic_action_labels">@drawable/ic_action_labels_light</item>
<item name="ic_action_new">@drawable/ic_action_new_light</item> <item name="ic_action_new">@drawable/ic_action_new_light</item>
@ -53,6 +54,7 @@
<item name="android:windowBackground">@color/background_dark</item> <item name="android:windowBackground">@color/background_dark</item>
<item name="ic_action_discard">@drawable/ic_action_discard_dark</item> <item name="ic_action_discard">@drawable/ic_action_discard_dark</item>
<item name="ic_action_done">@drawable/ic_action_done_dark</item>
<item name="ic_action_filter">@drawable/ic_action_filter_dark</item> <item name="ic_action_filter">@drawable/ic_action_filter_dark</item>
<item name="ic_action_labels">@drawable/ic_action_labels_dark</item> <item name="ic_action_labels">@drawable/ic_action_labels_dark</item>
<item name="ic_action_new">@drawable/ic_action_new_dark</item> <item name="ic_action_new">@drawable/ic_action_new_dark</item>

29
core/res/xml/appwidget_info.xml

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2010-2013 Eric Kok et al.
Transdroid is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Transdroid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
-->
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:configure="org.transdroid.core.widget.WidgetConfigActivity_"
android:initialKeyguardLayout="@layout/widget_torrents_light"
android:initialLayout="@layout/widget_torrents_light"
android:minHeight="110dip"
android:minResizeHeight="110dip"
android:minResizeWidth="110dp"
android:minWidth="180dp"
android:previewImage="@drawable/ic_launcher"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="86400000"
android:widgetCategory="home_screen|keyguard" />

30
core/src/org/transdroid/core/app/settings/ApplicationSettings.java

@ -29,7 +29,9 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.transdroid.core.app.search.SearchHelper; import org.transdroid.core.app.search.SearchHelper;
import org.transdroid.core.app.search.SearchSite; import org.transdroid.core.app.search.SearchSite;
import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.search.SearchSetting; import org.transdroid.core.gui.search.SearchSetting;
import org.transdroid.core.widget.WidgetSettings;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.OS; import org.transdroid.daemon.OS;
import org.transdroid.daemon.TorrentsSortBy; import org.transdroid.daemon.TorrentsSortBy;
@ -504,4 +506,32 @@ public class ApplicationSettings {
prefs.edit().putString(server.getUniqueIdentifier(), lastStats.toString()).commit(); prefs.edit().putString(server.getUniqueIdentifier(), lastStats.toString()).commit();
} }
/**
* Returns the user configuration for some specific app widget, if the widget is known at all.
* @param appWidgetId The unique ID of the app widget to retrieve settings for, as supplied by the AppWidgetManager
* @return A widget configuration object, or null if no settings were stored for the widget ID
*/
public WidgetSettings getWidgetConfig(int appWidgetId) {
if (!prefs.contains("widget_server_" + appWidgetId))
return null;
// @formatter:off
return new WidgetSettings(
prefs.getInt("widget_server_" + appWidgetId, -1),
StatusType.valueOf(prefs.getString("widget_status_" + appWidgetId, StatusType.ShowAll.name())),
TorrentsSortBy.valueOf(prefs.getString("widget_sortby_" + appWidgetId, TorrentsSortBy.Alphanumeric.name())),
prefs.getBoolean("widget_reverse_" + appWidgetId, false),
prefs.getBoolean("widget_darktheme_" + appWidgetId, false));
// @formatter:on
}
public void setWidgetConfig(int appWidgetId, WidgetSettings settings) {
Editor edit = prefs.edit();
edit.putInt("widget_server_" + appWidgetId, settings.getServerId());
edit.putString("widget_status_" + appWidgetId, settings.getStatusType().name());
edit.putString("widget_sortby_" + appWidgetId, settings.getSortBy().name());
edit.putBoolean("widget_reverse_" + appWidgetId, settings.shouldReserveSort());
edit.putBoolean("widget_darktheme_" + appWidgetId, settings.shouldUseDarkTheme());
edit.commit();
}
} }

46
core/src/org/transdroid/core/gui/lists/SortByListItem.java

@ -0,0 +1,46 @@
/*
* Copyright 2010-2013 Eric Kok et al.
*
* Transdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Transdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*/
package org.transdroid.core.gui.lists;
import org.transdroid.daemon.TorrentsSortBy;
/**
* Represents a way in which a torrents list can be sorted.
* @author Eric Kok
*/
public class SortByListItem implements SimpleListItem {
private TorrentsSortBy sortBy;
public SortByListItem(TorrentsSortBy sortBy) {
this.sortBy = sortBy;
}
/**
* Returns the contained represented sort order.
* @return The sort by order as its enumeration value
*/
public TorrentsSortBy getSortBy() {
return sortBy;
}
@Override
public String getName() {
return sortBy.name();
}
}

4
core/src/org/transdroid/core/gui/navigation/StatusType.java

@ -97,6 +97,10 @@ public enum StatusType {
this.name = name; this.name = name;
} }
public StatusType getStatusType() {
return statusType;
}
@Override @Override
public String getName() { public String getName() {
return name; return name;

265
core/src/org/transdroid/core/widget/WidgetConfigActivity.java

@ -0,0 +1,265 @@
/*
* Copyright 2010-2013 Eric Kok et al.
*
* Transdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Transdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*/
package org.transdroid.core.widget;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ItemSelect;
import org.androidannotations.annotations.SystemService;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.lists.SortByListItem;
import org.transdroid.core.gui.lists.TorrentsAdapter;
import org.transdroid.core.gui.navigation.FilterListItemAdapter;
import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.navigation.StatusType.StatusTypeFilter;
import org.transdroid.core.service.ConnectivityHelper;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Label;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentsComparator;
import org.transdroid.daemon.TorrentsSortBy;
import org.transdroid.daemon.task.DaemonTaskResult;
import org.transdroid.daemon.task.RetrieveTask;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Spinner;
import android.widget.TextView;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.SherlockListView;
@EActivity(resName = "activity_widgetconfig")
public class WidgetConfigActivity extends SherlockActivity {
// Views and adapters
@ViewById
protected Spinner serverSpinner, filterSpinner, sortSpinner;
@ViewById
protected CheckBox reverseorderCheckBox, darkthemeCheckBox;
@ViewById
protected TextView filterText, serverText, errorText;
@ViewById
protected SherlockListView torrentsList;
@Bean
protected TorrentsAdapter previewTorrentsAdapter;
private List<Torrent> previewTorrents = null;
// Settings and helpers
@SystemService
protected AppWidgetManager appWidgetManager;
@SystemService
protected LayoutInflater layoutInflater;
@Bean
protected ConnectivityHelper connectivityHelper;
@Bean
protected ApplicationSettings applicationSettings;
private int appWidgetId;
@Override
protected void onCreate(Bundle savedInstanceState) {
// Set the theme according to the user preference
if (SystemSettings_.getInstance_(this).useDarkTheme()) {
setTheme(R.style.TransdroidTheme_Dark);
getSupportActionBar().setIcon(R.drawable.ic_activity_torrents);
}
super.onCreate(savedInstanceState);
if (getIntent() != null && getIntent().getExtras() != null) {
// Get the appwidget ID we are configuring
appWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
// Set preliminary canceled result and continue with the initialisation
setResult(RESULT_CANCELED, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId));
}
// Invalid configuration; return canceled result
setResult(RESULT_CANCELED,
new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID));
finish();
}
@AfterViews
protected void init() {
// Populate the selection spinners
List<SimpleListItem> sortOrders = new ArrayList<SimpleListItem>();
for (TorrentsSortBy order : TorrentsSortBy.values()) {
sortOrders.add(new SortByListItem(order));
}
serverSpinner.setAdapter(new FilterListItemAdapter(this, applicationSettings.getServerSettings()));
filterSpinner.setAdapter(new FilterListItemAdapter(this, StatusType.getAllStatusTypes(this)));
sortSpinner.setAdapter(new FilterListItemAdapter(this, sortOrders));
// TODO: Update to AndroidAnnotations 3.0 and use @CheckedChanged
reverseorderCheckBox.setOnCheckedChangeListener(reverseorderCheckedChanged);
torrentsList.setAdapter(previewTorrentsAdapter);
// Set up action bar with a done button
// Inspired by NoNonsenseNotes's ListWidgetConfig.java (Apache License, Version 2.0)
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
View doneButtonFrame = layoutInflater.inflate(R.layout.actionbar_donebutton, null);
doneButtonFrame.findViewById(R.id.actionbar_done).setOnClickListener(doneClicked);
getSupportActionBar().setCustomView(doneButtonFrame);
}
@ItemSelect
protected void serverSpinnerItemSelected(boolean selected, ServerSetting server) {
serverText.setText(server.getName());
loadTorrents();
}
@ItemSelect
protected void filterSpinnerItemSelected(boolean selected, StatusTypeFilter statusTypeFilter) {
filterText.setText(statusTypeFilter.getName());
filterTorrents();
}
@ItemSelect
protected void sortSpinnerItemSelected(boolean selected, SortByListItem sortByListItem) {
filterTorrents();
}
protected OnCheckedChangeListener reverseorderCheckedChanged = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
filterTorrents();
}
};
@Background
protected void loadTorrents() {
if (serverSpinner.getSelectedItem() == null)
return;
// Create a connection object and retrieve the live torrents
IDaemonAdapter connection = ((ServerSetting) serverSpinner.getSelectedItem())
.createServerAdapter(connectivityHelper.getConnectedNetworkName());
DaemonTaskResult result = RetrieveTask.create(connection).execute();
if (result instanceof RetrieveTaskSuccessResult) {
// Success; show the active torrents in the widget preview
onTorrentsRetrieved(((RetrieveTaskSuccessResult) result).getTorrents(),
((RetrieveTaskSuccessResult) result).getLabels());
} else {
// Can't connect right now; provide a nice error message
showError(false);
}
}
@UiThread
protected void onTorrentsRetrieved(List<Torrent> torrents, List<Label> labels) {
previewTorrents = torrents;
filterTorrents();
}
protected void filterTorrents() {
// All spinners have to be initialised already
if (serverSpinner.getSelectedItem() == null)
return;
if (filterSpinner.getSelectedItem() == null)
return;
if (sortSpinner.getSelectedItem() == null)
return;
if (previewTorrents == null)
return;
// Get the already loaded torrents and filter and sort them
ArrayList<Torrent> filteredTorrents = new ArrayList<Torrent>(previewTorrents.size());
StatusTypeFilter statusTypeFilter = (StatusTypeFilter) filterSpinner.getSelectedItem();
for (Torrent torrent : previewTorrents) {
if (statusTypeFilter.matches(torrent))
filteredTorrents.add(torrent);
}
if (filteredTorrents.size() == 0) {
showError(true);
return;
}
TorrentsSortBy sortBy = ((SortByListItem) sortSpinner.getSelectedItem()).getSortBy();
Daemon serverType = filteredTorrents.get(0).getDaemon();
Collections
.sort(filteredTorrents, new TorrentsComparator(serverType, sortBy, reverseorderCheckBox.isChecked()));
// Finally update the widget preview with the live, filtered and sorted torrents list
previewTorrentsAdapter.update(filteredTorrents);
torrentsList.setVisibility(View.VISIBLE);
errorText.setVisibility(View.GONE);
}
@UiThread
protected void showError(boolean emptyResults) {
torrentsList.setVisibility(View.GONE);
errorText.setVisibility(View.VISIBLE);
errorText.setText(emptyResults ? R.string.navigation_emptytorrents : R.string.error_httperror);
}
private OnClickListener doneClicked = new OnClickListener() {
@Override
public void onClick(View v) {
// All spinner have to be initialised already
if (serverSpinner.getSelectedItem() == null)
return;
if (filterSpinner.getSelectedItem() == null)
return;
if (sortSpinner.getSelectedItem() == null)
return;
// Store these user preferences
int server = ((ServerSetting) serverSpinner.getSelectedItem()).getOrder();
StatusType statusType = ((StatusTypeFilter) filterSpinner.getSelectedItem()).getStatusType();
TorrentsSortBy sortBy = ((SortByListItem) sortSpinner.getSelectedItem()).getSortBy();
boolean reverseSort = reverseorderCheckBox.isChecked();
boolean useDarkTheme = darkthemeCheckBox.isChecked();
applicationSettings.setWidgetConfig(appWidgetId, new WidgetSettings(server, statusType, sortBy,
reverseSort, useDarkTheme));
// Return the widget configuration result
appWidgetManager.updateAppWidget(appWidgetId, null);
setResult(RESULT_OK, new Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId));
finish();
}
};
}

34
core/src/org/transdroid/core/widget/WidgetProvider.java

@ -0,0 +1,34 @@
/*
* Copyright 2010-2013 Eric Kok et al.
*
* Transdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Transdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*/
package org.transdroid.core.widget;
import org.androidannotations.annotations.EReceiver;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
@EReceiver
public class WidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// TODO
}
}

63
core/src/org/transdroid/core/widget/WidgetSettings.java

@ -0,0 +1,63 @@
/*
* Copyright 2010-2013 Eric Kok et al.
*
* Transdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Transdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*/
package org.transdroid.core.widget;
import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.daemon.TorrentsSortBy;
/**
* Represents a set of settings that define how the user configured a specific app widget.
* @author Eric Kok
*/
public class WidgetSettings {
private final int serverId;
private final StatusType statusType;
private final TorrentsSortBy sortBy;
private final boolean reserveSort;
private final boolean useDarkTheme;
public WidgetSettings(int serverId, StatusType statusType, TorrentsSortBy sortBy, boolean reverseSort,
boolean useDarkTheme) {
this.serverId = serverId;
this.statusType = statusType;
this.sortBy = sortBy;
this.reserveSort = reverseSort;
this.useDarkTheme = useDarkTheme;
}
public int getServerId() {
return serverId;
}
public StatusType getStatusType() {
return statusType;
}
public TorrentsSortBy getSortBy() {
return sortBy;
}
public boolean shouldReserveSort() {
return reserveSort;
}
public boolean shouldUseDarkTheme() {
return useDarkTheme;
}
}

18
full/AndroidManifest.xml

@ -52,6 +52,7 @@
<!-- Main activities --> <!-- Main activities -->
<activity <activity
android:name="org.transdroid.core.gui.TorrentsActivity_" android:name="org.transdroid.core.gui.TorrentsActivity_"
android:allowTaskReparenting="true"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/TransdroidTheme" android:theme="@style/TransdroidTheme"
android:uiOptions="splitActionBarWhenNarrow" > android:uiOptions="splitActionBarWhenNarrow" >
@ -240,6 +241,23 @@
android:value="android.intent.action.BOOT_COMPLETED" /> android:value="android.intent.action.BOOT_COMPLETED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<!-- Home screen widget -->
<activity android:name="org.transdroid.core.widget.WidgetConfigActivity_" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<receiver android:name="org.transdroid.core.widget.WidgetProvider_" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/appwidget_info" />
</receiver>
</application> </application>
</manifest> </manifest>

1
lite/AndroidManifest.xml

@ -52,6 +52,7 @@
<!-- Main activities --> <!-- Main activities -->
<activity <activity
android:name="org.transdroid.core.gui.TorrentsActivity_" android:name="org.transdroid.core.gui.TorrentsActivity_"
android:allowTaskReparenting="true"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/TransdroidTheme" android:theme="@style/TransdroidTheme"
android:uiOptions="splitActionBarWhenNarrow" > android:uiOptions="splitActionBarWhenNarrow" >

Loading…
Cancel
Save