Browse Source

Making the contextual action bars work and allow setting of file priorities.

pull/11/head
Eric Kok 11 years ago
parent
commit
331950f89f
  1. BIN
      core/res/drawable-hdpi/ic_priority_high.png
  2. BIN
      core/res/drawable-hdpi/ic_priority_low.png
  3. BIN
      core/res/drawable-hdpi/ic_priority_normal.png
  4. BIN
      core/res/drawable-hdpi/ic_priority_off.png
  5. 29
      core/res/drawable/selectable_background_transdroid2.xml
  6. 6
      core/res/layout/list_item_torrent.xml
  7. 31
      core/res/layout/list_item_torrentfile.xml
  8. 6
      core/res/menu/fragment_details_file.xml
  9. 9
      core/res/values/strings.xml
  10. 5
      core/src/org/transdroid/core/app/settings/SettingsPersistence.java
  11. 20
      core/src/org/transdroid/core/gui/DetailsActivity.java
  12. 74
      core/src/org/transdroid/core/gui/DetailsFragment.java
  13. 3
      core/src/org/transdroid/core/gui/TorrentTasksExecutor.java
  14. 24
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  15. 20
      core/src/org/transdroid/core/gui/TorrentsFragment.java
  16. 77
      core/src/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java
  17. 26
      core/src/org/transdroid/core/gui/lists/TorrentFileView.java
  18. 10
      core/src/org/transdroid/core/gui/navigation/NavigationHelper.java
  19. 14
      core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 848 B

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

29
core/res/drawable/selectable_background_transdroid2.xml

@ -1,26 +1,11 @@ @@ -1,26 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- File created by the Android Action Bar Style Generator
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="@android:integer/config_mediumAnimTime">
Copyright (C) 2011 The Android Open Source Project
Copyright (C) 2012 readyState Software Ltd
<item android:drawable="@drawable/pressed_background_transdroid2" android:state_selected="true"/>
<item android:drawable="@drawable/pressed_background_transdroid2" android:state_checked="true" />
<item android:drawable="@drawable/pressed_background_transdroid2" android:state_activated="true"/>
<item android:drawable="@drawable/list_focused_transdroid2" android:state_focused="true" />
<item android:drawable="@drawable/pressed_background_transdroid2" android:state_pressed="true"/>
<item android:drawable="@android:color/transparent"/>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime" >
<item android:state_pressed="false" android:state_focused="true" android:drawable="@drawable/list_focused_transdroid2" />
<item android:state_pressed="false" android:state_checked="true" android:drawable="@drawable/list_focused_transdroid2" />
<item android:state_pressed="true" android:drawable="@drawable/pressed_background_transdroid2" />
<item android:drawable="@android:color/transparent" />
</selector>

6
core/res/layout/list_item_torrent.xml

@ -4,7 +4,8 @@ @@ -4,7 +4,8 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingRight="@dimen/margin_default" >
android:paddingRight="@dimen/margin_default"
android:background="?attr/selectable_background_transdroid" >
<TextView
android:id="@+id/name_text"
@ -35,8 +36,7 @@ @@ -35,8 +36,7 @@
android:layout_alignBottom="@id/ratio_text"
android:layout_marginLeft="@dimen/margin_half"
android:layout_toLeftOf="@id/ratio_text"
android:contentDescription="@string/status_priority_normal"
android:src="@drawable/ic_priority_normal" />
android:contentDescription="@string/status_priority_normal" />
<TextView
android:id="@+id/progress_text"

31
core/res/layout/list_item_torrentfile.xml

@ -1,25 +1,19 @@ @@ -1,25 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<fr.marvinlabs.widget.CheckableRelativeLayout
<org.transdroid.core.gui.lists.TorrentFilePriorityLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="@dimen/margin_half"
android:paddingBottom="@dimen/margin_half"
android:paddingRight="@dimen/margin_default">
android:paddingLeft="@dimen/margin_default"
android:paddingRight="@dimen/margin_default"
android:background="?attr/selectable_background_transdroid">
<fr.marvinlabs.widget.InertCheckBox
android:id="@+id/file_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
<TextView
android:id="@+id/name_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/file_checkbox"
android:textColor="?attr/text_bright"
android:textSize="@dimen/text_enlarged"
android:textIsSelectable="false"
@ -42,21 +36,8 @@ @@ -42,21 +36,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/progress_text"
android:layout_alignBottom="@+id/progress_text"
android:layout_toRightOf="@+id/priority_image"
android:textIsSelectable="false"
android:textSize="@dimen/text_small"
android:focusable="false" />
<ImageView
android:id="@+id/priority_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/name_text"
android:layout_below="@+id/name_text"
android:layout_marginTop="4dip"
android:layout_marginRight="@dimen/margin_half"
android:contentDescription="@string/status_priority_normal"
android:focusable="false" />
</fr.marvinlabs.widget.CheckableRelativeLayout>
</org.transdroid.core.gui.lists.TorrentFilePriorityLayout>

6
core/res/menu/fragment_details_file.xml

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_off"
android:id="@+id/action_priority_off"
android:showAsAction="ifRoom"
android:title="@string/action_priority_off" />
<item
@ -16,10 +16,6 @@ @@ -16,10 +16,6 @@
android:id="@+id/action_priority_high"
android:showAsAction="ifRoom"
android:title="@string/action_priority_high" />
<item
android:id="@+id/action_remoteplay"
android:showAsAction="ifRoom"
android:title="@string/action_remoteplay" />
<item
android:id="@+id/action_download"
android:showAsAction="ifRoom"

9
core/res/values/strings.xml

@ -51,6 +51,14 @@ @@ -51,6 +51,14 @@
<string name="navigation_status_onlyup">Uploading</string>
<string name="navigation_status_onlyactive">Active</string>
<string name="navigation_status_onlyinactive">Inactive</string>
<plurals name="navigation_torrentsselected">
<item quantity="one">%1$d torrent selected</item>
<item quantity="other">%1$d torrents selected</item>
</plurals>
<plurals name="navigation_filesselected">
<item quantity="one">%1$d files selected</item>
<item quantity="other">%1$d files selected</item>
</plurals>
<string name="status_status">STATUS: %1$s</string>
<string name="status_waiting">Waiting to check&#8230;</string>
@ -100,6 +108,7 @@ @@ -100,6 +108,7 @@
<string name="result_trackersupdated">Trackers updated</string>
<string name="result_labelset">Label set to \'%1$s\'</string>
<string name="result_locationset">Torrent moved to \'%1$s\'</string>
<string name="result_priotitiesset">File priorities updated</string>
<string name="search_torrentsearch">Torrent search</string>
<string name="search_hint">Search for torrents</string>

5
core/src/org/transdroid/core/app/settings/SettingsPersistence.java

@ -18,6 +18,11 @@ import android.content.SharedPreferences; @@ -18,6 +18,11 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Environment;
/**
* Singleton class that can persist user settings (servers, RSS feeds, etc.) to and from a plain text JSON file.
*
* @author Eric Kok
*/
@EBean(scope = Scope.Singleton)
public class SettingsPersistence {

20
core/src/org/transdroid/core/gui/DetailsActivity.java

@ -14,14 +14,13 @@ import org.androidannotations.annotations.OptionsItem; @@ -14,14 +14,13 @@ import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.annotations.UiThread;
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.*;
import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Priority;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile;
@ -38,6 +37,7 @@ import org.transdroid.daemon.task.ResumeTask; @@ -38,6 +37,7 @@ import org.transdroid.daemon.task.ResumeTask;
import org.transdroid.daemon.task.RetrieveTask;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
import org.transdroid.daemon.task.SetDownloadLocationTask;
import org.transdroid.daemon.task.SetFilePriorityTask;
import org.transdroid.daemon.task.SetLabelTask;
import org.transdroid.daemon.task.SetTrackersTask;
import org.transdroid.daemon.task.StartTask;
@ -247,12 +247,24 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -247,12 +247,24 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
}
}
@Background
@Override
public void updatePriority(Torrent torrent, List<TorrentFile> files, Priority priority) {
DaemonTaskResult result = SetFilePriorityTask.create(currentConnection, torrent, priority,
new ArrayList<TorrentFile>(files)).execute();
if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_priotitiesset));
} else {
onCommunicationError((DaemonTaskFailureResult) result);
}
}
@UiThread
protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) {
// Refresh the screen as well
refreshTorrent();
refreshTorrentDetails(torrent);
Crouton.showText(this, successMessage, navigationHelper.CROUTON_INFO_STYLE);
Crouton.showText(this, successMessage, NavigationHelper.CROUTON_INFO_STYLE);
}
@UiThread
@ -272,7 +284,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -272,7 +284,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
Log.i(this, result.getException().toString());
fragmentDetails.updateIsLoading(false);
Crouton.showText(this, getString(LocalTorrent.getResourceForDaemonException(result.getException())),
navigationHelper.CROUTON_ERROR_STYLE);
NavigationHelper.CROUTON_ERROR_STYLE);
}
@UiThread

74
core/src/org/transdroid/core/gui/DetailsFragment.java

@ -13,7 +13,9 @@ import org.androidannotations.annotations.ViewById; @@ -13,7 +13,9 @@ import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R;
import org.transdroid.core.gui.lists.DetailsAdapter;
import org.transdroid.core.gui.lists.SimpleListItemAdapter;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.Priority;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile;
@ -23,8 +25,13 @@ import android.widget.ProgressBar; @@ -23,8 +25,13 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SherlockListView;
import com.actionbarsherlock.view.SherlockListView.MultiChoiceModeListenerCompat;
import de.keyboardsurfer.android.widget.crouton.Crouton;
/**
* Fragment that shows detailed statistics about some torrent. These come from some already fetched {@link Torrent}
@ -57,7 +64,10 @@ public class DetailsFragment extends SherlockFragment { @@ -57,7 +64,10 @@ public class DetailsFragment extends SherlockFragment {
@AfterViews
protected void init() {
// Set up details adapter (itself containing the actual lists to show), which allows multi-select and fast
// scrolling
detailsList.setAdapter(new DetailsAdapter(getActivity()));
detailsList.setMultiChoiceModeListener(onDetailsSelected);
detailsList.setFastScrollEnabled(true);
if (torrent != null)
updateTorrent(torrent);
@ -233,6 +243,70 @@ public class DetailsFragment extends SherlockFragment { @@ -233,6 +243,70 @@ public class DetailsFragment extends SherlockFragment {
// TODO: Show trackers edit dialog
}
private MultiChoiceModeListenerCompat onDetailsSelected = new MultiChoiceModeListenerCompat() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Show contextual action bar to start/stop/remove/etc. torrents in batch mode
mode.getMenuInflater().inflate(R.menu.fragment_details_file, menu);
return true;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Get checked torrents
List<TorrentFile> checked = new ArrayList<TorrentFile>();
for (int i = 0; i < detailsList.getCheckedItemPositions().size(); i++) {
if (detailsList.getCheckedItemPositions().valueAt(i)
&& detailsList.getAdapter().getItem(detailsList.getCheckedItemPositions().keyAt(i)) instanceof TorrentFile)
checked.add((TorrentFile) detailsList.getAdapter().getItem(
detailsList.getCheckedItemPositions().keyAt(i)));
}
int itemId = item.getItemId();
if (itemId == R.id.action_download) {
// TODO: Start FTP download command for the selected torrents
Crouton.showText(getActivity(), "TODO: Start FTP download command for the selected torrents",
NavigationHelper.CROUTON_INFO_STYLE);
//for (TorrentFile file : checked) {
//}
mode.finish();
return true;
} else {
Priority priority = Priority.Normal;
if (itemId == R.id.action_priority_low)
priority = Priority.Low;
getTasksExecutor().updatePriority(torrent, checked, priority);
mode.finish();
return true;
}
}
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
// Show the number of selected files in the CAB
// torrentsList.getCheckedItemPositions().size() ?
int checkedCount = 0;
for (int i = 0; i < detailsList.getCheckedItemPositions().size(); i++) {
if (detailsList.getCheckedItemPositions().valueAt(i)
&& detailsList.getAdapter().getItem(detailsList.getCheckedItemPositions().keyAt(i)) instanceof TorrentFile)
checkedCount++;
}
mode.setTitle(getResources().getQuantityString(R.plurals.navigation_filesselected, checkedCount, checkedCount));
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
}
};
/**
* Returns the object responsible for executing torrent tasks against a connected server
* @return The executor for tasks on some torrent

3
core/src/org/transdroid/core/gui/TorrentTasksExecutor.java

@ -2,7 +2,9 @@ package org.transdroid.core.gui; @@ -2,7 +2,9 @@ package org.transdroid.core.gui;
import java.util.List;
import org.transdroid.daemon.Priority;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentFile;
public interface TorrentTasksExecutor {
void resumeTorrent(Torrent torrent);
@ -15,4 +17,5 @@ public interface TorrentTasksExecutor { @@ -15,4 +17,5 @@ public interface TorrentTasksExecutor {
void updateLocation(Torrent torrent, String newLocation);
void refreshTorrentDetails(Torrent torrent);
void refreshTorrentFiles(Torrent torrent);
void updatePriority(Torrent torrent, List<TorrentFile> files, Priority priority);
}

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

@ -31,6 +31,7 @@ import org.transdroid.core.gui.search.UrlEntryDialog; @@ -31,6 +31,7 @@ import org.transdroid.core.gui.search.UrlEntryDialog;
import org.transdroid.core.gui.settings.*;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.Priority;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile;
@ -54,6 +55,7 @@ import org.transdroid.daemon.task.RetrieveTask; @@ -54,6 +55,7 @@ import org.transdroid.daemon.task.RetrieveTask;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
import org.transdroid.daemon.task.SetAlternativeModeTask;
import org.transdroid.daemon.task.SetDownloadLocationTask;
import org.transdroid.daemon.task.SetFilePriorityTask;
import org.transdroid.daemon.task.SetLabelTask;
import org.transdroid.daemon.task.SetTrackersTask;
import org.transdroid.daemon.task.StartTask;
@ -631,16 +633,16 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -631,16 +633,16 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
}
} catch (SecurityException e) {
// No longer access to this file
Crouton.showText(this, R.string.error_torrentfile, navigationHelper.CROUTON_ERROR_STYLE);
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
} catch (IOException e1) {
// Can't write temporary file
Crouton.showText(this, R.string.error_torrentfile, navigationHelper.CROUTON_ERROR_STYLE);
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
} finally {
try {
if (input != null)
input.close();
} catch (IOException e) {
Crouton.showText(this, R.string.error_torrentfile, navigationHelper.CROUTON_ERROR_STYLE);
Crouton.showText(this, R.string.error_torrentfile, NavigationHelper.CROUTON_ERROR_STYLE);
}
}
}
@ -739,18 +741,30 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -739,18 +741,30 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
}
}
@Background
@Override
public void updatePriority(Torrent torrent, List<TorrentFile> files, Priority priority) {
DaemonTaskResult result = SetFilePriorityTask.create(currentConnection, torrent, priority,
new ArrayList<TorrentFile>(files)).execute();
if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_priotitiesset));
} else {
onCommunicationError((DaemonTaskFailureResult) result, false);
}
}
@UiThread
protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) {
// Refresh the screen as well
refreshScreen();
Crouton.showText(this, successMessage, navigationHelper.CROUTON_INFO_STYLE);
Crouton.showText(this, successMessage, NavigationHelper.CROUTON_INFO_STYLE);
}
@UiThread
protected void onCommunicationError(DaemonTaskFailureResult result, boolean isCritical) {
Log.i(this, result.getException().toString());
String error = getString(LocalTorrent.getResourceForDaemonException(result.getException()));
Crouton.showText(this, error, navigationHelper.CROUTON_ERROR_STYLE);
Crouton.showText(this, error, NavigationHelper.CROUTON_ERROR_STYLE);
fragmentTorrents.updateIsLoading(false);
if (isCritical)
fragmentTorrents.updateError(error);

20
core/src/org/transdroid/core/gui/TorrentsFragment.java

@ -70,13 +70,18 @@ public class TorrentsFragment extends SherlockFragment { @@ -70,13 +70,18 @@ public class TorrentsFragment extends SherlockFragment {
@AfterViews
protected void init() {
// Load the requested sort order from the user settings
this.currentSortOrder = applicationSettings.getLastUsedSortOrder();
this.currentSortDescending = applicationSettings.getLastUsedSortDescending();
// Set up the list adapter, which allows multi-select and fast scrolling
torrentsList.setAdapter(TorrentsAdapter_.getInstance_(getActivity()));
torrentsList.setMultiChoiceModeListener(onTorrentsSelected);
torrentsList.setFastScrollEnabled(true);
if (torrents != null)
updateTorrents(torrents);
}
/**
@ -183,8 +188,9 @@ public class TorrentsFragment extends SherlockFragment { @@ -183,8 +188,9 @@ public class TorrentsFragment extends SherlockFragment {
// Get checked torrents
List<Torrent> checked = new ArrayList<Torrent>();
for (int i = 0; i < torrentsList.getCheckedItemPositions().size(); i++) {
if (torrentsList.getCheckedItemPositions().get(i))
checked.add((Torrent) torrentsList.getAdapter().getItem(i));
if (torrentsList.getCheckedItemPositions().valueAt(i))
checked.add((Torrent) torrentsList.getAdapter().getItem(
torrentsList.getCheckedItemPositions().keyAt(i)));
}
int itemId = item.getItemId();
@ -223,7 +229,15 @@ public class TorrentsFragment extends SherlockFragment { @@ -223,7 +229,15 @@ public class TorrentsFragment extends SherlockFragment {
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
// TODO: Update title or otherwise show number of selected torrents?
// Show the number of selected torrents in the CAB
// torrentsList.getCheckedItemPositions().size() ?
int checkedCount = 0;
for (int i = 0; i < torrentsList.getCheckedItemPositions().size(); i++) {
if (torrentsList.getCheckedItemPositions().valueAt(i))
checkedCount++;
}
mode.setTitle(getResources().getQuantityString(R.plurals.navigation_torrentsselected, checkedCount,
checkedCount));
}
@Override

77
core/src/org/transdroid/core/gui/lists/TorrentFilePriorityLayout.java

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
package org.transdroid.core.gui.lists;
import org.transdroid.daemon.Priority;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import fr.marvinlabs.widget.CheckableRelativeLayout;
public class TorrentFilePriorityLayout extends CheckableRelativeLayout {
private final float scale = getContext().getResources().getDisplayMetrics().density;
private final int WIDTH = (int) (5 * scale + 0.5f);
private Priority priority = null;
private final Paint offPaint = new Paint();
private final Paint lowPaint = new Paint();
private final Paint highPaint = new Paint();
private final Paint normalPaint = new Paint();
private final RectF fullRect = new RectF();
public TorrentFilePriorityLayout(Context context) {
super(context);
initPaints();
setWillNotDraw(false);
}
public TorrentFilePriorityLayout(Context context, AttributeSet attrs) {
super(context, attrs);
initPaints();
setWillNotDraw(false);
}
private void initPaints() {
offPaint.setColor(0xFF9E9E9E); // Grey
lowPaint.setColor(0x778ACC12); // Very Light green
normalPaint.setColor(0xBB8ACC12); // Light green
highPaint.setColor(0xFF8ACC12); // Green
}
public void setPriority(Priority priority) {
this.priority = priority;
this.invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int height = getHeight();
int width = WIDTH;
fullRect.set(0, 0, width, height);
if (priority == null) {
return;
}
switch (priority) {
case Low:
canvas.drawRect(fullRect, lowPaint);
break;
case Normal:
canvas.drawRect(fullRect, normalPaint);
break;
case High:
canvas.drawRect(fullRect, highPaint);
break;
default: // Off
canvas.drawRect(fullRect, offPaint);
break;
}
}
}

26
core/src/org/transdroid/core/gui/lists/TorrentFileView.java

@ -2,25 +2,20 @@ package org.transdroid.core.gui.lists; @@ -2,25 +2,20 @@ package org.transdroid.core.gui.lists;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R;
import org.transdroid.daemon.TorrentFile;
import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;
import fr.marvinlabs.widget.CheckableRelativeLayout;
/**
* View that represents some {@link TorrentFile} object and show the file's name, status and priority
* @author Eric Kok
*/
@EViewGroup(resName="list_item_torrentfile")
public class TorrentFileView extends CheckableRelativeLayout {
public class TorrentFileView extends TorrentFilePriorityLayout {
@ViewById
protected TextView nameText, progressText, sizesText;
@ViewById
protected ImageView priorityImage;
public TorrentFileView(Context context) {
super(context, null);
@ -30,24 +25,7 @@ public class TorrentFileView extends CheckableRelativeLayout { @@ -30,24 +25,7 @@ public class TorrentFileView extends CheckableRelativeLayout {
nameText.setText(torrentFile.getName());
sizesText.setText(torrentFile.getDownloadedAndTotalSizeText());
progressText.setText(torrentFile.getProgressText());
switch (torrentFile.getPriority()) {
case Off:
priorityImage.setImageResource(R.drawable.ic_priority_off);
priorityImage.setContentDescription(getResources().getString(R.string.status_priority_off));
break;
case Low:
priorityImage.setImageResource(R.drawable.ic_priority_low);
priorityImage.setContentDescription(getResources().getString(R.string.status_priority_low));
break;
case Normal:
priorityImage.setImageResource(R.drawable.ic_priority_normal);
priorityImage.setContentDescription(getResources().getString(R.string.status_priority_normal));
break;
case High:
priorityImage.setImageResource(R.drawable.ic_priority_high);
priorityImage.setContentDescription(getResources().getString(R.string.status_priority_high));
break;
}
setPriority(torrentFile.getPriority());
}
}

10
core/src/org/transdroid/core/gui/navigation/NavigationHelper.java

@ -26,14 +26,14 @@ public class NavigationHelper { @@ -26,14 +26,14 @@ public class NavigationHelper {
/**
* Use with {@link Crouton#showText(android.app.Activity, int, Style)} (and variants) to display error messages.
*/
public Style CROUTON_ERROR_STYLE = new Style.Builder().setBackgroundColor(R.color.crouton_error).setTextSize(13)
.setDuration(2500).build();
public static Style CROUTON_ERROR_STYLE = new Style.Builder().setBackgroundColor(R.color.crouton_error)
.setTextSize(13).setDuration(2500).build();
/**
* Use with {@link Crouton#showText(android.app.Activity, int, Style)} (and variants) to display info messages.
*/
public Style CROUTON_INFO_STYLE = new Style.Builder().setBackgroundColor(R.color.crouton_info).setTextSize(13)
.setDuration(1500).build();
public static Style CROUTON_INFO_STYLE = new Style.Builder().setBackgroundColor(R.color.crouton_info)
.setTextSize(13).setDuration(1500).build();
/**
* Whether any search-related UI components should be shown in the interface. At the moment returns false only if we

14
core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java

@ -41,8 +41,6 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity { @@ -41,8 +41,6 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
protected static final int DIALOG_EXPORTSETTINGS = 3;
protected static final String INSTALLHELP_URI = "http://www.transdroid.org/download/";
@Bean
protected NavigationHelper navigationHelper;
@Bean
protected ApplicationSettings applicationSettings;
@Bean
@ -160,13 +158,13 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity { @@ -160,13 +158,13 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
try {
settingsPersistence.importSettings(prefs, SettingsPersistence.DEFAULT_SETTINGS_FILE);
Crouton.showText(SystemSettingsActivity.this, R.string.pref_import_success,
navigationHelper.CROUTON_INFO_STYLE);
NavigationHelper.CROUTON_INFO_STYLE);
} catch (FileNotFoundException e) {
Crouton.showText(SystemSettingsActivity.this, R.string.error_file_not_found,
navigationHelper.CROUTON_ERROR_STYLE);
NavigationHelper.CROUTON_ERROR_STYLE);
} catch (JSONException e) {
Crouton.showText(SystemSettingsActivity.this, R.string.error_no_valid_settings_file,
navigationHelper.CROUTON_ERROR_STYLE);
NavigationHelper.CROUTON_ERROR_STYLE);
}
}
};
@ -178,13 +176,13 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity { @@ -178,13 +176,13 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
try {
settingsPersistence.exportSettings(prefs, SettingsPersistence.DEFAULT_SETTINGS_FILE);
Crouton.showText(SystemSettingsActivity.this, R.string.pref_export_success,
navigationHelper.CROUTON_INFO_STYLE);
NavigationHelper.CROUTON_INFO_STYLE);
} catch (JSONException e) {
Crouton.showText(SystemSettingsActivity.this, R.string.error_cant_write_settings_file,
navigationHelper.CROUTON_ERROR_STYLE);
NavigationHelper.CROUTON_ERROR_STYLE);
} catch (IOException e) {
Crouton.showText(SystemSettingsActivity.this, R.string.error_cant_write_settings_file,
navigationHelper.CROUTON_ERROR_STYLE);
NavigationHelper.CROUTON_ERROR_STYLE);
}
}
};

Loading…
Cancel
Save