Browse Source

Working widgets with correct loading static and list rows UI.

pull/13/merge
Eric Kok 11 years ago
parent
commit
c70ee61646
  1. BIN
      core/res/drawable-hdpi/widget_preview.png
  2. 12
      core/res/layout-v11/activity_widgetconfig.xml
  3. 34
      core/res/layout-v11/list_item_widget_dark.xml
  4. 34
      core/res/layout-v11/list_item_widget_light.xml
  5. 48
      core/res/layout-v11/widget_torrents_dark.xml
  6. 49
      core/res/layout-v11/widget_torrents_light.xml
  7. 5
      core/res/values/dimens.xml
  8. 6
      core/res/values/strings.xml
  9. 2
      core/res/xml/appwidget_info.xml
  10. 66
      core/src/org/transdroid/core/gui/lists/SimpleListItemSpinnerAdapter.java
  11. 30
      core/src/org/transdroid/core/gui/lists/SortByListItem.java
  12. 20
      core/src/org/transdroid/core/widget/WidgetConfigActivity.java
  13. 78
      core/src/org/transdroid/core/widget/WidgetProvider.java
  14. 22
      core/src/org/transdroid/core/widget/WidgetService.java

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

12
core/res/layout-v11/activity_widgetconfig.xml

@ -62,13 +62,21 @@ @@ -62,13 +62,21 @@
android:id="@+id/filter_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_default" />
android:layout_marginTop="@dimen/margin_half" />
<TextView
android:id="@+id/sortbyheader_text"
style="@style/SectionHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/widget_sortby"
android:textIsSelectable="false" />
<Spinner
android:id="@+id/sort_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_default" />
android:layout_marginTop="@dimen/margin_half" />
<CheckBox
android:id="@+id/reverseorder_check_box"

34
core/res/layout-v11/list_item_widget_dark.xml

@ -18,26 +18,26 @@ @@ -18,26 +18,26 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_line_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="@dimen/widget_list_item_height"
android:background="@drawable/selectable_background_transdroid"
android:paddingRight="@dimen/margin_default" >
android:paddingRight="@dimen/widget_list_item_padding" >
<View
<TextView
android:id="@+id/status_view"
android:layout_height="match_parent"
android:layout_width="6dp" />
android:layout_width="6dp"
android:layout_height="@dimen/widget_list_item_height" />
<TextView
android:id="@+id/name_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_torrentlistleft"
android:layout_marginLeft="@dimen/widget_list_item_padding_left"
android:ellipsize="end"
android:fontFamily="sans-serif-condensed"
android:paddingTop="@dimen/margin_half"
android:maxLines="1"
android:paddingTop="@dimen/widget_list_item_padding"
android:textColor="@color/text_bright_dark"
android:textIsSelectable="false"
android:maxLines="1"
android:ellipsize="end"
android:textSize="@dimen/text_enlarged" />
<TextView
@ -46,9 +46,10 @@ @@ -46,9 +46,10 @@
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/name_text"
android:layout_marginLeft="@dimen/margin_half"
android:layout_marginTop="4.0dip"
android:paddingBottom="@dimen/margin_half"
android:layout_marginLeft="@dimen/widget_list_item_padding"
android:layout_marginTop="4dip"
android:maxLines="1"
android:paddingBottom="@dimen/widget_list_item_padding"
android:textIsSelectable="false"
android:textSize="@dimen/text_small" />
@ -58,9 +59,10 @@ @@ -58,9 +59,10 @@
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/ratio_text"
android:layout_alignParentLeft="true"
android:layout_marginLeft="@dimen/margin_torrentlistleft"
android:layout_toLeftOf="@id/priority_image"
android:layout_marginLeft="@dimen/widget_list_item_padding_left"
android:layout_toLeftOf="@id/ratio_text"
android:maxLines="1"
android:textIsSelectable="false"
android:textSize="@dimen/text_small" />
</RelativeLayout>
</RelativeLayout>

34
core/res/layout-v11/list_item_widget_light.xml

@ -18,26 +18,26 @@ @@ -18,26 +18,26 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_line_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="@dimen/widget_list_item_height"
android:background="@drawable/selectable_background_transdroid2"
android:paddingRight="@dimen/margin_default" >
android:paddingRight="@dimen/widget_list_item_padding" >
<View
<TextView
android:id="@+id/status_view"
android:layout_height="match_parent"
android:layout_width="6dp" />
android:layout_width="6dp"
android:layout_height="@dimen/widget_list_item_height" />
<TextView
android:id="@+id/name_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_torrentlistleft"
android:layout_marginLeft="@dimen/widget_list_item_padding_left"
android:ellipsize="end"
android:fontFamily="sans-serif-condensed"
android:paddingTop="@dimen/margin_half"
android:maxLines="1"
android:paddingTop="@dimen/widget_list_item_padding"
android:textColor="@color/text_bright_light"
android:textIsSelectable="false"
android:maxLines="1"
android:ellipsize="end"
android:textSize="@dimen/text_enlarged" />
<TextView
@ -46,9 +46,10 @@ @@ -46,9 +46,10 @@
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/name_text"
android:layout_marginLeft="@dimen/margin_half"
android:layout_marginTop="4.0dip"
android:paddingBottom="@dimen/margin_half"
android:layout_marginLeft="@dimen/widget_list_item_padding"
android:layout_marginTop="4dip"
android:maxLines="1"
android:paddingBottom="@dimen/widget_list_item_padding"
android:textIsSelectable="false"
android:textSize="@dimen/text_small" />
@ -58,9 +59,10 @@ @@ -58,9 +59,10 @@
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/ratio_text"
android:layout_alignParentLeft="true"
android:layout_marginLeft="@dimen/margin_torrentlistleft"
android:layout_toLeftOf="@id/priority_image"
android:layout_marginLeft="@dimen/widget_list_item_padding_left"
android:layout_toLeftOf="@id/ratio_text"
android:maxLines="1"
android:textIsSelectable="false"
android:textSize="@dimen/text_small" />
</RelativeLayout>
</RelativeLayout>

48
core/res/layout-v11/widget_torrents_dark.xml

@ -1,4 +1,20 @@ @@ -1,4 +1,20 @@
<?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/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -7,30 +23,44 @@ @@ -7,30 +23,44 @@
<ImageButton
android:id="@+id/icon_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_width="@dimen/widget_header_height"
android:layout_height="@dimen/widget_header_height"
android:background="@drawable/selectable_background_transdroid"
android:contentDescription="@string/widget_opentransdroid"
android:padding="4dp"
android:padding="@dimen/widget_header_padding"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/refresh_button"
android:layout_width="@dimen/widget_header_height"
android:layout_height="@dimen/widget_header_height"
android:layout_alignParentRight="true"
android:background="@drawable/selectable_background_transdroid"
android:contentDescription="@string/action_refresh"
android:padding="@dimen/widget_header_padding"
android:scaleType="fitXY"
android:src="@drawable/ic_action_refresh_dark" />
<LinearLayout
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_height="@dimen/widget_header_height"
android:layout_toLeftOf="@id/refresh_button"
android:layout_toRightOf="@id/icon_image"
android:background="@drawable/selectable_background_transdroid"
android:clickable="true"
android:orientation="vertical"
android:paddingTop="2dp"
android:paddingRight="@dimen/margin_half" >
android:paddingRight="@dimen/margin_half"
android:paddingTop="3dp" >
<TextView
android:id="@+id/filter_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fontFamily="sans-serif-condensed"
android:maxLines="1"
android:textColor="@color/text_actionbar_dark"
android:textIsSelectable="false"
android:textSize="@dimen/ui_navigation_filter" />
@ -40,20 +70,22 @@ @@ -40,20 +70,22 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-4dip"
android:ellipsize="marquee"
android:fontFamily="sans-serif-light"
android:maxLines="1"
android:textColor="@color/text_actionbar_dark"
android:textIsSelectable="false"
android:textSize="@dimen/ui_navigation_server" />
</LinearLayout>
<View
<TextView
android:id="@+id/topline_view"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@id/icon_image"
android:background="@color/green" />
<View
<TextView
android:id="@+id/bottomline_view"
android:layout_width="match_parent"
android:layout_height="2dp"

49
core/res/layout-v11/widget_torrents_light.xml

@ -1,4 +1,20 @@ @@ -1,4 +1,20 @@
<?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/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -7,30 +23,44 @@ @@ -7,30 +23,44 @@
<ImageButton
android:id="@+id/icon_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_width="@dimen/widget_header_height"
android:layout_height="@dimen/widget_header_height"
android:background="@drawable/selectable_background_transdroid2"
android:contentDescription="@string/widget_opentransdroid"
android:padding="4dp"
android:padding="@dimen/widget_header_padding"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/refresh_button"
android:layout_width="@dimen/widget_header_height"
android:layout_height="@dimen/widget_header_height"
android:layout_alignParentRight="true"
android:background="@drawable/selectable_background_transdroid2"
android:contentDescription="@string/action_refresh"
android:padding="@dimen/widget_header_padding"
android:scaleType="fitXY"
android:src="@drawable/ic_action_refresh_light" />
<LinearLayout
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_height="@dimen/widget_header_height"
android:layout_toLeftOf="@id/refresh_button"
android:layout_toRightOf="@id/icon_image"
android:background="@drawable/selectable_background_transdroid2"
android:clickable="true"
android:orientation="vertical"
android:paddingTop="2dp"
android:paddingRight="@dimen/margin_half" >
android:paddingRight="@dimen/margin_half"
android:paddingTop="3dp" >
<TextView
android:id="@+id/filter_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fontFamily="sans-serif-condensed"
android:maxLines="1"
android:textColor="@color/text_actionbar_light"
android:textIsSelectable="false"
android:textSize="@dimen/ui_navigation_filter" />
@ -40,20 +70,22 @@ @@ -40,20 +70,22 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-4dip"
android:ellipsize="marquee"
android:fontFamily="sans-serif-light"
android:maxLines="1"
android:textColor="@color/text_actionbar_light"
android:textIsSelectable="false"
android:textSize="@dimen/ui_navigation_server" />
</LinearLayout>
<View
<TextView
android:id="@+id/topline_view"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@id/icon_image"
android:background="@color/green" />
<View
<TextView
android:id="@+id/bottomline_view"
android:layout_width="match_parent"
android:layout_height="2dp"
@ -76,7 +108,6 @@ @@ -76,7 +108,6 @@
android:layout_below="@id/topline_view"
android:layout_gravity="center"
android:gravity="center"
android:maxWidth="400dip"
android:padding="@dimen/margin_default"
android:textIsSelectable="false"
android:visibility="gone" />

5
core/res/values/dimens.xml

@ -46,5 +46,10 @@ @@ -46,5 +46,10 @@
<dimen name="widget_preview_padding">20dp</dimen>
<dimen name="widget_preview_height">200dp</dimen>
<dimen name="widget_preview_width">-1dp</dimen>
<dimen name="widget_header_height">46dp</dimen>
<dimen name="widget_header_padding">6dp</dimen>
<dimen name="widget_list_item_height">54dp</dimen>
<dimen name="widget_list_item_padding">6dp</dimen>
<dimen name="widget_list_item_padding_left">12dp</dimen>
</resources>

6
core/res/values/strings.xml

@ -190,11 +190,13 @@ @@ -190,11 +190,13 @@
</plurals>
<string name="rss_service_newfor">New torrents for %1$s</string>
<string name="widget_loading">Loading&#8230;</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_sortby">SORT ORDER</string>
<string name="widget_reversesortorder">Reversed sort order</string>
<string name="widget_usedarktheme">Use dark theme (no preview)</string>
<string name="widget_done">DONE</string>
<string name="pref_servers">Servers</string>

2
core/res/xml/appwidget_info.xml

@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
android:minResizeHeight="110dip"
android:minResizeWidth="110dp"
android:minWidth="180dp"
android:previewImage="@drawable/ic_launcher"
android:previewImage="@drawable/widget_preview"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="3600000"
android:widgetCategory="home_screen|keyguard" />

66
core/src/org/transdroid/core/gui/lists/SimpleListItemSpinnerAdapter.java

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
/*
* 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 java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
/**
* A wrapper around {@link ArrayAdapter} that contains {@link SimpleListItem}s which simply show their name in the
* Spinner. The standard Android spinner resources are used for the layout.
* @author Eric Kok
*/
public class SimpleListItemSpinnerAdapter<T extends SimpleListItem> extends ArrayAdapter<T> {
/**
* Constructs the adapter, supplying the {@link SimpleListItem}s to show in the spinner. The given resource will be
* ignored as the standard Android Spinner layout is used instead.
* @param context The UI context to inflate the layout in
* @param resource This is ignored; android.R.layout.simple_spinner_item is always used instead
* @param objects The items to show in the spinner, which can simply display some name
*/
public SimpleListItemSpinnerAdapter(Context context, int resource, List<T> objects) {
super(context, android.R.layout.simple_spinner_item, objects);
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// This relies on the ArrayAdapter implementation and the used standard xml layouts that simply return a
// TextView; this can then be filled with the SimpleListItem's name instead of the standard toString()
// implementation
TextView text = (TextView) super.getView(position, convertView, parent);
text.setText(getItem(position).getName());
return text;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
// This relies on the ArrayAdapter implementation and the used standard xml layouts that simply return a
// TextView; this can then be filled with the SimpleListItem's name instead of the standard toString()
// implementation
TextView text = (TextView) super.getDropDownView(position, convertView, parent);
text.setText(getItem(position).getName());
return text;
}
}

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

@ -16,18 +16,42 @@ @@ -16,18 +16,42 @@
*/
package org.transdroid.core.gui.lists;
import org.transdroid.core.R;
import org.transdroid.daemon.TorrentsSortBy;
import android.content.Context;
/**
* Represents a way in which a torrents list can be sorted.
* @author Eric Kok
*/
public class SortByListItem implements SimpleListItem {
private TorrentsSortBy sortBy;
private final TorrentsSortBy sortBy;
private final String name;
public SortByListItem(TorrentsSortBy sortBy) {
public SortByListItem(Context context, TorrentsSortBy sortBy) {
this.sortBy = sortBy;
switch (sortBy) {
case DateAdded:
this.name = context.getString(R.string.action_sort_added);
break;
case DateDone:
this.name = context.getString(R.string.action_sort_done);
break;
case Ratio:
this.name = context.getString(R.string.action_sort_ratio);
break;
case Status:
this.name = context.getString(R.string.action_sort_status);
break;
case UploadSpeed:
this.name = context.getString(R.string.action_sort_upspeed);
break;
default:
this.name = context.getString(R.string.action_sort_alpha);
break;
}
}
/**
@ -40,7 +64,7 @@ public class SortByListItem implements SimpleListItem { @@ -40,7 +64,7 @@ public class SortByListItem implements SimpleListItem {
@Override
public String getName() {
return sortBy.name();
return name;
}
}

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

@ -30,10 +30,9 @@ import org.androidannotations.annotations.ViewById; @@ -30,10 +30,9 @@ 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.gui.lists.SimpleListItem;
import org.transdroid.core.gui.lists.SimpleListItemSpinnerAdapter;
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;
@ -111,18 +110,20 @@ public class WidgetConfigActivity extends SherlockActivity { @@ -111,18 +110,20 @@ public class WidgetConfigActivity extends SherlockActivity {
@AfterViews
protected void init() {
// Populate the selection spinners
List<SimpleListItem> sortOrders = new ArrayList<SimpleListItem>();
// Populate the selection spinners with custom array adapters
List<SortByListItem> sortOrders = new ArrayList<SortByListItem>();
for (TorrentsSortBy order : TorrentsSortBy.values()) {
sortOrders.add(new SortByListItem(order));
sortOrders.add(new SortByListItem(this, order));
}
serverSpinner.setAdapter(new FilterListItemAdapter(this, applicationSettings.getServerSettings()));
filterSpinner.setAdapter(new FilterListItemAdapter(this, StatusType.getAllStatusTypes(this)));
sortSpinner.setAdapter(new FilterListItemAdapter(this, sortOrders));
serverSpinner.setAdapter(new SimpleListItemSpinnerAdapter<ServerSetting>(this, 0, applicationSettings
.getServerSettings()));
filterSpinner.setAdapter(new SimpleListItemSpinnerAdapter<StatusTypeFilter>(this, 0, StatusType
.getAllStatusTypes(this)));
sortSpinner.setAdapter(new SimpleListItemSpinnerAdapter<SortByListItem>(this, 0, sortOrders));
// TODO: Update to AndroidAnnotations 3.0 and use @CheckedChanged
reverseorderCheckBox.setOnCheckedChangeListener(reverseorderCheckedChanged);
torrentsList.setAdapter(previewTorrentsAdapter);
torrentsList.setEmptyView(errorText);
// Set up action bar with a done button
// Inspired by NoNonsenseNotes's ListWidgetConfig.java (Apache License, Version 2.0)
@ -257,4 +258,5 @@ public class WidgetConfigActivity extends SherlockActivity { @@ -257,4 +258,5 @@ public class WidgetConfigActivity extends SherlockActivity {
}
};
}

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

@ -20,7 +20,7 @@ import org.androidannotations.annotations.Bean; @@ -20,7 +20,7 @@ import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EReceiver;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.*;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.gui.TorrentsActivity_;
import org.transdroid.core.gui.log.Log;
import android.annotation.TargetApi;
@ -40,46 +40,40 @@ public class WidgetProvider extends AppWidgetProvider { @@ -40,46 +40,40 @@ public class WidgetProvider extends AppWidgetProvider {
public static final String INTENT_STARTSERVER = "org.transdroid.START_SERVER";
public static final String EXTRA_TORRENT = "extra_torrent";
public static final String EXTRA_SERVER = "extra_server";
public static final String EXTRA_REFRESH = "extra_refresh";
@Bean
protected ApplicationSettings applicationSettings;
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.hasExtra(EXTRA_REFRESH)) {
// Manually requested a refresh for the app widget of which the ID was supplied
int appWidgetId = intent.getIntExtra(EXTRA_REFRESH, -1);
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId,
buildRemoteViews(context, appWidgetId, applicationSettings.getWidgetConfig(appWidgetId)));
AppWidgetManager.getInstance(context).notifyAppWidgetViewDataChanged(appWidgetId, R.id.torrents_list);
return;
}
super.onReceive(context, intent);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
appWidgetManager.updateAppWidget(appWidgetId,
buildRemoteViews(context, appWidgetId, applicationSettings.getWidgetConfig(appWidgetId)));
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.torrents_list);
}
}
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
super.onDeleted(context, appWidgetIds);
for (int appWidgetId : appWidgetIds) {
applicationSettings.removeWidgetConfig(appWidgetId);
}
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null || intent.getAction() == null || intent.getExtras() == null
|| !intent.hasExtra(EXTRA_SERVER))
return;
// Launch an Intent to start Transdroid on some specific server; and possibly a specific torrent too
Intent start = new Intent(INTENT_STARTSERVER);
start.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
start.putExtra(EXTRA_SERVER, intent.getIntExtra(EXTRA_SERVER, -1));
if (intent.getAction().equals(EXTRA_TORRENT)) {
start.putExtra(EXTRA_TORRENT, intent.getParcelableExtra(EXTRA_TORRENT));
}
context.startActivity(start);
super.onReceive(context, intent);
}
/**
* Loads and sets up the layout for some specific app widget given the user's widget settings. Note that the views
* for the list view rows are loaded separately in the {@link WidgetViewsFactory}.
@ -103,26 +97,44 @@ public class WidgetProvider extends AppWidgetProvider { @@ -103,26 +97,44 @@ public class WidgetProvider extends AppWidgetProvider {
// Load the dark or light widget layout xml
RemoteViews rv = new RemoteViews(context.getPackageName(),
config.shouldUseDarkTheme() ? R.layout.list_item_widget_dark : R.layout.list_item_widget_light);
config.shouldUseDarkTheme() ? R.layout.widget_torrents_dark : R.layout.widget_torrents_light);
// Set up the widget's list view loading service which refers to the WidgetViewsFactory
// Use a unique data URI next to the extra to make sure the intents are unique form each widget
Intent intent = new Intent(context, WidgetService.class);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME) + "//widget/" + appWidgetId + "/server/"
+ config.getServerId()));
intent.putExtra(EXTRA_SERVER, config.getServerId());
rv.setRemoteAdapter(appWidgetId, R.id.torrents_list, intent);
Intent data = new Intent(context, WidgetService_.class);
data.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
data.setData(Uri.parse(data.toUri(Intent.URI_INTENT_SCHEME)));
rv.setRemoteAdapter(appWidgetId, R.id.torrents_list, data);
Intent open = new Intent(context, TorrentsActivity_.class);
open.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
rv.setPendingIntentTemplate(R.id.torrents_list,
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
PendingIntent.getActivity(context, appWidgetId, open, PendingIntent.FLAG_UPDATE_CURRENT));
rv.setEmptyView(R.id.torrents_list, R.id.error_text);
rv.setTextViewText(R.id.error_text, context.getString(R.string.navigation_emptytorrents));
rv.setTextViewText(R.id.error_text, context.getString(R.string.widget_loading));
// Show the server and status type filter from the widget configuration
// Show the server and status type filter from the widget configuration in the 'action bar'
ServerSetting server = appSettings.getServerSetting(config.getServerId());
rv.setTextViewText(R.id.server_text, server.getName());
rv.setTextViewText(R.id.filter_text, config.getStatusType().getFilterItem(context).getName());
// Set up the START_SERVER intent for 'action bar' clicks to start Transdroid normally
Intent start = new Intent(context, TorrentsActivity_.class);
//start.setData(Uri.parse("intent://widget/" + appWidgetId + "/start/" + config.getServerId()));
start.setAction(INTENT_STARTSERVER);
start.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
start.putExtra(EXTRA_SERVER, config.getServerId());
rv.setOnClickPendingIntent(R.id.icon_image,
PendingIntent.getActivity(context, 0, intent.cloneFilter(), PendingIntent.FLAG_UPDATE_CURRENT));
PendingIntent.getActivity(context, appWidgetId, start, PendingIntent.FLAG_UPDATE_CURRENT));
rv.setOnClickPendingIntent(R.id.navigation_view,
PendingIntent.getActivity(context, appWidgetId, start, PendingIntent.FLAG_UPDATE_CURRENT));
// Set up the widgets refresh button pending intent (calling this WidgetProvider itself)
// Make sure that the intent is unique using a custom data path (rather than just the extras)
Intent refresh = new Intent(context, WidgetProvider_.class);
refresh.setData(Uri.parse("intent://widget/" + appWidgetId + "/refresh"));
refresh.putExtra(EXTRA_REFRESH, appWidgetId);
refresh.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
rv.setOnClickPendingIntent(R.id.refresh_button,
PendingIntent.getBroadcast(context, appWidgetId, refresh, PendingIntent.FLAG_UPDATE_CURRENT));
return rv;

22
core/src/org/transdroid/core/widget/WidgetService.java

@ -39,7 +39,6 @@ import android.annotation.TargetApi; @@ -39,7 +39,6 @@ import android.annotation.TargetApi;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
@ -131,29 +130,28 @@ class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory { @@ -131,29 +130,28 @@ class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory {
// Bind the torrent details texts and status colour
Torrent torrent = torrents.get(position);
LocalTorrent local = LocalTorrent.fromTorrent(torrent);
Resources r = context.getResources();
rv.setTextViewText(R.id.name_text, torrent.getName());
rv.setTextViewText(R.id.progress_text, local.getProgressSizeText(r, false));
rv.setTextViewText(R.id.ratio_text, local.getProgressEtaRatioText(r));
rv.setTextViewText(R.id.progress_text, local.getProgressSizeText(context.getResources(), false));
rv.setTextViewText(R.id.ratio_text, local.getProgressEtaRatioText(context.getResources()));
int statusColour;
switch (torrent.getStatusCode()) {
case Downloading:
statusColour = r.getColor(r.getColor(R.color.torrent_downloading));
statusColour = R.color.torrent_downloading;
break;
case Paused:
statusColour = r.getColor(r.getColor(R.color.torrent_paused));
statusColour = R.color.torrent_paused;
break;
case Seeding:
statusColour = r.getColor(r.getColor(R.color.torrent_seeding));
statusColour = R.color.torrent_seeding;
break;
case Error:
statusColour = r.getColor(r.getColor(R.color.torrent_error));
statusColour = R.color.torrent_error;
break;
default: // Checking, Waiting, Queued, Unknown
statusColour = r.getColor(r.getColor(R.color.torrent_other));
statusColour = R.color.torrent_other;
break;
}
rv.setInt(R.id.status_view, "setBackgroundColor", r.getColor(statusColour));
rv.setInt(R.id.status_view, "setBackgroundColor", context.getResources().getColor(statusColour));
Intent startIntent = new Intent();
startIntent.putExtra(WidgetProvider.EXTRA_SERVER, config.getServerId());
startIntent.putExtra(WidgetProvider.EXTRA_TORRENT, torrent);
@ -170,7 +168,9 @@ class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory { @@ -170,7 +168,9 @@ class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory {
@Override
public void onDestroy() {
torrents.clear();
if (torrents != null)
torrents.clear();
torrents = null;
}
@Override

Loading…
Cancel
Save