Eric Kok
12 years ago
9 changed files with 213 additions and 14 deletions
@ -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> |
@ -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> |
@ -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); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue