|
|
@ -1,8 +1,9 @@ |
|
|
|
package org.transdroid.core.gui.navigation; |
|
|
|
package org.transdroid.core.gui.navigation; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.security.InvalidParameterException; |
|
|
|
|
|
|
|
|
|
|
|
import org.transdroid.core.R; |
|
|
|
import org.transdroid.core.R; |
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.TargetApi; |
|
|
|
|
|
|
|
import android.app.AlertDialog; |
|
|
|
import android.app.AlertDialog; |
|
|
|
import android.app.Dialog; |
|
|
|
import android.app.Dialog; |
|
|
|
import android.content.DialogInterface; |
|
|
|
import android.content.DialogInterface; |
|
|
@ -20,7 +21,7 @@ import android.widget.TextView; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class SetTransferRatesDialog extends DialogFragment { |
|
|
|
public class SetTransferRatesDialog extends DialogFragment { |
|
|
|
|
|
|
|
|
|
|
|
private OnRatesPickedListener onRatesPicked; |
|
|
|
private OnRatesPickedListener onRatesPickedListener = null; |
|
|
|
private TextView maxSpeedDown, maxSpeedUp; |
|
|
|
private TextView maxSpeedDown, maxSpeedUp; |
|
|
|
|
|
|
|
|
|
|
|
public SetTransferRatesDialog() { |
|
|
|
public SetTransferRatesDialog() { |
|
|
@ -29,16 +30,19 @@ public class SetTransferRatesDialog extends DialogFragment { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the callback for results in this dialog (with newly selected values or a reset). |
|
|
|
* Sets the callback for results in this dialog (with newly selected values or a reset). |
|
|
|
* @param onRatesPicked The event listener to this dialog |
|
|
|
* @param onRatesPickedListener The event listener to this dialog |
|
|
|
* @return This dialog, for method chaining |
|
|
|
* @return This dialog, for method chaining |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public SetTransferRatesDialog setOnRatesPicked(OnRatesPickedListener onRatesPicked) { |
|
|
|
public SetTransferRatesDialog setOnRatesPickedListener(OnRatesPickedListener onRatesPickedListener) { |
|
|
|
this.onRatesPicked = onRatesPicked; |
|
|
|
this.onRatesPickedListener = onRatesPickedListener; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) { |
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) { |
|
|
|
|
|
|
|
if (onRatesPickedListener == null) |
|
|
|
|
|
|
|
throw new InvalidParameterException( |
|
|
|
|
|
|
|
"Please first set the callback listener using setOnRatesPickedListener before opening the dialog."); |
|
|
|
final View transferRatesContent = getActivity().getLayoutInflater().inflate(R.layout.dialog_transferrates, |
|
|
|
final View transferRatesContent = getActivity().getLayoutInflater().inflate(R.layout.dialog_transferrates, |
|
|
|
null, false); |
|
|
|
null, false); |
|
|
|
maxSpeedDown = (TextView) transferRatesContent.findViewById(R.id.maxspeeddown_text); |
|
|
|
maxSpeedDown = (TextView) transferRatesContent.findViewById(R.id.maxspeeddown_text); |
|
|
@ -59,14 +63,14 @@ public class SetTransferRatesDialog extends DialogFragment { |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
} |
|
|
|
} |
|
|
|
if (maxDown <= 0 || maxUp <= 0) { |
|
|
|
if (maxDown <= 0 || maxUp <= 0) { |
|
|
|
onRatesPicked.onInvalidNumber(); |
|
|
|
onRatesPickedListener.onInvalidNumber(); |
|
|
|
} |
|
|
|
} |
|
|
|
onRatesPicked.onRatesPicked(maxDown, maxUp); |
|
|
|
onRatesPickedListener.onRatesPicked(maxDown, maxUp); |
|
|
|
} |
|
|
|
} |
|
|
|
}).setNeutralButton(R.string.status_maxspeed_reset, new OnClickListener() { |
|
|
|
}).setNeutralButton(R.string.status_maxspeed_reset, new OnClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
onRatesPicked.resetRates(); |
|
|
|
onRatesPickedListener.resetRates(); |
|
|
|
} |
|
|
|
} |
|
|
|
}).setNegativeButton(android.R.string.cancel, null).create(); |
|
|
|
}).setNegativeButton(android.R.string.cancel, null).create(); |
|
|
|
} |
|
|
|
} |
|
|
@ -96,7 +100,9 @@ public class SetTransferRatesDialog extends DialogFragment { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public interface OnRatesPickedListener { |
|
|
|
public interface OnRatesPickedListener { |
|
|
|
public void onRatesPicked(int maxDownloadSpeed, int maxUploadSpeed); |
|
|
|
public void onRatesPicked(int maxDownloadSpeed, int maxUploadSpeed); |
|
|
|
|
|
|
|
|
|
|
|
public void resetRates(); |
|
|
|
public void resetRates(); |
|
|
|
|
|
|
|
|
|
|
|
public void onInvalidNumber(); |
|
|
|
public void onInvalidNumber(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|