Browse Source

Added server status (counts and speeds) in the action bar.

pull/11/head
Eric Kok 11 years ago
parent
commit
f99bed2da2
  1. 2
      core/project.properties
  2. 84
      core/res/layout/actionbar_serverstatus.xml
  3. 27
      core/res/values-land/dimens.xml
  4. 6
      core/res/values-sw600dp/dimens.xml
  5. 6
      core/res/values/dimens.xml
  6. 4
      core/res/values/strings.xml
  7. 65
      core/src/org/transdroid/core/gui/ServerStatusView.java
  8. 14
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  9. 19
      lite/AndroidManifest.xml

2
core/project.properties

@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-16
target=android-17
android.library.reference.1=../external/JakeWharton-ActionBarSherlock/library
android.library.reference.2=../external/ColorPickerPreference
android.library=true

84
core/res/layout/actionbar_serverstatus.xml

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginRight="@dimen/margin_default"
android:layout_marginTop="@dimen/ui_serverstatus_margin"
android:background="?attr/selectable_background_transdroid"
android:clickable="true"
android:focusable="true" >
<TextView
android:id="@+id/upcount_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:paddingTop="@dimen/ui_serverstatus_signmargin"
android:text="↑"
android:textColor="?attr/text_bright"
android:textSize="@dimen/ui_serverstatus_sign"
android:visibility="invisible"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/upcount_text"
android:layout_width="@dimen/ui_serverstatus_width"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/upcount_sign"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="?attr/text_bright"
android:textSize="@dimen/ui_serverstatus_bignumber" />
<TextView
android:id="@+id/downcount_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/upcount_text"
android:fontFamily="sans-serif-light"
android:paddingTop="@dimen/ui_serverstatus_signmargin"
android:text="↓"
android:textColor="?attr/text_bright"
android:textSize="@dimen/ui_serverstatus_sign"
android:visibility="invisible"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/downcount_text"
android:layout_width="@dimen/ui_serverstatus_width"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/downcount_sign"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="?attr/text_bright"
android:textSize="@dimen/ui_serverstatus_bignumber" />
<TextView
android:id="@+id/upspeed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/upcount_text"
android:layout_alignParentRight="true"
android:layout_below="@id/upcount_text"
android:layout_marginTop="-4dip"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="?attr/text_bright"
android:textSize="@dimen/ui_serverstatus_smallnumber" />
<TextView
android:id="@+id/downspeed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/downcount_text"
android:layout_alignRight="@id/downcount_sign"
android:layout_below="@id/downcount_text"
android:layout_marginTop="-4dip"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textColor="?attr/text_bright"
android:textSize="@dimen/ui_serverstatus_smallnumber" />
</RelativeLayout>

27
core/res/values-land/dimens.xml

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
<resources>
<!-- Margins -->
<dimen name="margin_default">16dp</dimen>
<dimen name="margin_half">8dp</dimen>
<dimen name="margin_torrentlistleft">16dp</dimen>
<!-- Text sizes -->
<dimen name="text_small">12sp</dimen>
<dimen name="text_default">15sp</dimen>
<dimen name="text_enlarged">15sp</dimen>
<dimen name="text_enlargednumbers">22sp</dimen>
<dimen name="text_hugenumbers">33sp</dimen>
<dimen name="text_label">12sp</dimen>
<!-- UI elements -->
<dimen name="ui_navigation_filter">15sp</dimen>
<dimen name="ui_navigation_server">12sp</dimen>
<dimen name="ui_details_seperator">110dp</dimen>
<dimen name="ui_serverstatus_margin">1dp</dimen>
<dimen name="ui_serverstatus_signmargin">2dp</dimen>
<dimen name="ui_serverstatus_bignumber">19sp</dimen>
<dimen name="ui_serverstatus_sign">12sp</dimen>
<dimen name="ui_serverstatus_smallnumber">12sp</dimen>
<dimen name="ui_serverstatus_width">53dp</dimen>
</resources>

6
core/res/values-sw500dp/dimens.xml → core/res/values-sw600dp/dimens.xml

@ -17,5 +17,11 @@ @@ -17,5 +17,11 @@
<dimen name="ui_navigation_filter">18sp</dimen>
<dimen name="ui_navigation_server">15sp</dimen>
<dimen name="ui_details_seperator">125dp</dimen>
<dimen name="ui_serverstatus_margin">2dp</dimen>
<dimen name="ui_serverstatus_signmargin">5dp</dimen>
<dimen name="ui_serverstatus_bignumber">25sp</dimen>
<dimen name="ui_serverstatus_sign">17sp</dimen>
<dimen name="ui_serverstatus_smallnumber">14sp</dimen>
<dimen name="ui_serverstatus_width">63dp</dimen>
</resources>

6
core/res/values/dimens.xml

@ -17,5 +17,11 @@ @@ -17,5 +17,11 @@
<dimen name="ui_navigation_filter">17sp</dimen>
<dimen name="ui_navigation_server">14sp</dimen>
<dimen name="ui_details_seperator">110dp</dimen>
<dimen name="ui_serverstatus_margin">2dp</dimen>
<dimen name="ui_serverstatus_signmargin">3dp</dimen>
<dimen name="ui_serverstatus_bignumber">21sp</dimen>
<dimen name="ui_serverstatus_sign">15sp</dimen>
<dimen name="ui_serverstatus_smallnumber">13sp</dimen>
<dimen name="ui_serverstatus_width">53dp</dimen>
</resources>

4
core/res/values/strings.xml

@ -73,8 +73,8 @@ @@ -73,8 +73,8 @@
<string name="status_unknowneta">UNKNOWN ETA</string>
<string name="status_ratio">RATIO %1$s</string>
<string name="status_peers">%1$s OF %2$s PEERS</string>
<string name="status_speed_up">↑ %1$s</string>
<string name="status_speed_down">↓ %1$s</string>
<string name="status_speed_up" translatable="false">↑ %1$s</string>
<string name="status_speed_down" translatable="false">↓ %1$s</string>
<string name="status_downloading">Downloading</string>
<string name="status_seeding">Seeding</string>
<string name="status_paused">Paused</string>

65
core/src/org/transdroid/core/gui/ServerStatusView.java

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
package org.transdroid.core.gui;
import java.util.List;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentStatus;
import org.transdroid.daemon.util.FileSizeConverter;
import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
@EViewGroup(resName="actionbar_serverstatus")
public class ServerStatusView extends RelativeLayout {
@ViewById
protected TextView downcountText, upcountText, downcountSign, upcountSign, downspeedText, upspeedText;
public ServerStatusView(Context context) {
super(context);
}
/**
* Updates the statistics as shown in the action bar through this server status view.
* @param torrents The most recently received list of torrents
*/
public void update(List<Torrent> torrents) {
if (torrents == null) {
downcountText.setText(null);
upcountText.setText(null);
downspeedText.setText(null);
upspeedText.setText(null);
downcountSign.setVisibility(View.INVISIBLE);
upcountSign.setVisibility(View.INVISIBLE);
}
int downcount = 0, upcount = 0, downspeed = 0, upspeed = 0;
for (Torrent torrent : torrents) {
// Downloading torrents count towards downloads and uploads, seeding torrents towards uploads
if (torrent.getStatusCode() == TorrentStatus.Downloading) {
downcount++;
upcount++;
} else if (torrent.getStatusCode() == TorrentStatus.Seeding) {
upcount++;
}
downspeed += torrent.getRateDownload();
upspeed += torrent.getRateUpload();
}
downcountText.setText(Integer.toString(downcount));
upcountText.setText(Integer.toString(upcount));
downspeedText.setText(FileSizeConverter.getSize(downspeed));
upspeedText.setText(FileSizeConverter.getSize(upspeed));
downcountSign.setVisibility(View.VISIBLE);
upcountSign.setVisibility(View.VISIBLE);
}
}

14
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -101,6 +101,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -101,6 +101,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
protected SherlockListView filtersList;
protected FilterListAdapter navigationListAdapter = null;
protected FilterListDropDownAdapter navigationSpinnerAdapter = null;
protected ServerStatusView serverStatusView;
@SystemService
protected SearchManager searchManager;
@ -135,10 +136,14 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -135,10 +136,14 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@AfterViews
protected void init() {
// Set up navigation, with an action bar spinner and possibly (if room) with a filter list
// Set up navigation, with an action bar spinner, server status indicator and possibly (if room) with a filter
// list
serverStatusView = ServerStatusView_.build(this);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(serverStatusView);
navigationSpinnerAdapter = FilterListDropDownAdapter_.getInstance_(this);
// Servers are always added to the action bar spinner
navigationSpinnerAdapter.updateServers(applicationSettings.getServerSettings());
@ -780,13 +785,16 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -780,13 +785,16 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@UiThread
protected void onTorrentsRetrieved(List<Torrent> torrents, List<org.transdroid.daemon.Label> labels) {
// Report the newly retrieved list of torrents to the torrents fragment
fragmentTorrents.updateIsLoading(false);
fragmentTorrents.updateTorrents(new ArrayList<Torrent>(torrents));
// Update the details fragment if the currently shown torrent is in the newly retrieved list
if (fragmentDetails != null) {
fragmentDetails.perhapsUpdateTorrent(torrents);
}
// Update local list of labels in the navigation
List<Label> navigationLabels = Label.convertToNavigationLabels(labels,
getResources().getString(R.string.labels_unlabeled));
@ -797,6 +805,10 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -797,6 +805,10 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Labels are shown in the action bar spinner
navigationSpinnerAdapter.updateLabels(navigationLabels);
}
// Update the server status (counts and speeds) in the action bar
serverStatusView.update(torrents);
}
@UiThread

19
lite/AndroidManifest.xml

@ -19,7 +19,10 @@ @@ -19,7 +19,10 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application
android:allowBackup="true"
@ -31,9 +34,8 @@ @@ -31,9 +34,8 @@
<activity
android:name="org.transdroid.core.gui.TorrentsActivity_"
android:label="@string/app_name"
android:icon="@drawable/ic_activity_torrents"
android:uiOptions="splitActionBarWhenNarrow"
android:theme="@style/TransdroidTheme" >
android:theme="@style/TransdroidTheme"
android:uiOptions="splitActionBarWhenNarrow" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -42,14 +44,9 @@ @@ -42,14 +44,9 @@
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value="org.transdroid.gui.search.Search" />
</activity>
<activity
android:name="org.transdroid.core.gui.DetailsActivity_"
android:icon="@drawable/ic_activity_torrents"
android:uiOptions="splitActionBarWhenNarrow"
android:theme="@style/TransdroidTheme" >
</activity>
@ -57,10 +54,12 @@ @@ -57,10 +54,12 @@
<!-- Settings screens -->
<activity android:name="org.transdroid.core.gui.settings.MainSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.ServerSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.WebsearchSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.RssfeedSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.NotificationSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.SystemSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.navigation.DialogHelper_" />
</application>
</manifest>
Loading…
Cancel
Save