mirror of
https://github.com/BOINC/boinc.git
synced 2025-02-26 20:45:07 +00:00
android: redesing preference dialogs
This commit is contained in:
parent
686688dcef
commit
513e8dd994
@ -18,10 +18,32 @@
|
||||
along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dip"
|
||||
android:orientation="vertical">
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/white_smoke" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/black"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/shape_light_blue_background"
|
||||
android:text="@string/prefs_dialog_title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pref"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/black"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_margin="10dp"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/Input"
|
||||
android:layout_width="match_parent"
|
||||
@ -29,4 +51,37 @@
|
||||
android:inputType="numberDecimal">
|
||||
<requestFocus />
|
||||
</EditText>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="220dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5dp"
|
||||
android:clickable="true"
|
||||
android:layout_margin="5dp"
|
||||
android:background="@drawable/shape_button_blue"
|
||||
android:textColor="@color/white_smoke"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/confirm_cancel"
|
||||
android:layout_weight="0.5"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/confirm"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5dp"
|
||||
android:clickable="true"
|
||||
android:layout_margin="5dp"
|
||||
android:background="@drawable/shape_button_red"
|
||||
android:textColor="@color/white_smoke"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/prefs_submit_button"
|
||||
android:layout_weight="0.5" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@ -18,20 +18,77 @@
|
||||
along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dip"
|
||||
android:orientation="vertical">
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/white_smoke" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/black"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/shape_light_blue_background"
|
||||
android:text="@string/prefs_dialog_title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pref"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/black"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_margin="10dp"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="100">
|
||||
</SeekBar>
|
||||
android:max="10"
|
||||
android:layout_margin="10dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/seekbar_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal" >
|
||||
</TextView>
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="220dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5dp"
|
||||
android:clickable="true"
|
||||
android:layout_margin="5dp"
|
||||
android:background="@drawable/shape_button_blue"
|
||||
android:textColor="@color/white_smoke"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/confirm_cancel"
|
||||
android:layout_weight="0.5"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/confirm"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5dp"
|
||||
android:clickable="true"
|
||||
android:layout_margin="5dp"
|
||||
android:background="@drawable/shape_button_red"
|
||||
android:textColor="@color/white_smoke"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/prefs_submit_button"
|
||||
android:layout_weight="0.5" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
@ -139,8 +139,7 @@
|
||||
<!-- preferences tab strings -->
|
||||
<string name="prefs_loading">Reading preferences…</string>
|
||||
<string name="prefs_submit_button">Save</string>
|
||||
<string name="prefs_cancel_button">Cancel</string>
|
||||
<string name="prefs_dialog_title">Please enter desired value for: </string>
|
||||
<string name="prefs_dialog_title">Enter new value:</string>
|
||||
<string name="prefs_category_general">General</string>
|
||||
<string name="prefs_category_network">Network</string>
|
||||
<string name="prefs_category_power">Power</string>
|
||||
|
@ -19,7 +19,6 @@
|
||||
package edu.berkeley.boinc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import edu.berkeley.boinc.adapter.PrefsListAdapter;
|
||||
import edu.berkeley.boinc.adapter.PrefsListItemWrapper;
|
||||
import edu.berkeley.boinc.adapter.PrefsListItemWrapperBool;
|
||||
@ -27,10 +26,8 @@ import edu.berkeley.boinc.adapter.PrefsListItemWrapperDouble;
|
||||
import edu.berkeley.boinc.client.ClientNotification;
|
||||
import edu.berkeley.boinc.client.Monitor;
|
||||
import edu.berkeley.boinc.rpc.GlobalPreferences;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.AsyncTask;
|
||||
@ -38,8 +35,10 @@ import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
@ -61,9 +60,6 @@ public class PrefsActivity extends FragmentActivity {
|
||||
private GlobalPreferences clientPrefs = null; //preferences of the client, read on every onResume via RPC
|
||||
private AppPreferences appPrefs = null; //Android specific preferences, singleton of monitor
|
||||
|
||||
private Dialog dialog; //Dialog for input on non-Bool preferences
|
||||
private PrefsListItemWrapperDouble dialogItem; // saves content of preference Dialog is showing
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
doBindService();
|
||||
@ -199,22 +195,24 @@ public class PrefsActivity extends FragmentActivity {
|
||||
|
||||
// onClick of listview items with PrefsListItemWrapperDouble
|
||||
public void onItemClick (View view) {
|
||||
PrefsListItemWrapperDouble listItem = (PrefsListItemWrapperDouble) view.getTag();
|
||||
final PrefsListItemWrapperDouble listItem = (PrefsListItemWrapperDouble) view.getTag();
|
||||
Log.d(TAG,"onItemClick " + listItem.ID);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
final View dialogContent;
|
||||
|
||||
final Dialog dialog = new Dialog(this);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
if(listItem.isPct) {
|
||||
dialogContent = inflater.inflate(R.layout.prefs_layout_dialog_pct, null);
|
||||
TextView sliderProgress = (TextView) dialogContent.findViewById(R.id.seekbar_status);
|
||||
sliderProgress.setText(listItem.status.intValue() + " %");
|
||||
SeekBar slider = (SeekBar) dialogContent.findViewById(R.id.seekbar);
|
||||
slider.setProgress(listItem.status.intValue());
|
||||
// show dialog with slider
|
||||
dialog.setContentView(R.layout.prefs_layout_dialog_pct);
|
||||
// setup slider
|
||||
TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
|
||||
sliderProgress.setText(listItem.status.intValue() + " " + getString(R.string.prefs_unit_pct));
|
||||
Double seekBarDefault = listItem.status / 10;
|
||||
SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar);
|
||||
slider.setProgress(seekBarDefault.intValue());
|
||||
slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
|
||||
String progressString = progress + " %";
|
||||
TextView sliderProgress = (TextView) dialogContent.findViewById(R.id.seekbar_status);
|
||||
String progressString = (progress * 10) + " " + getString(R.string.prefs_unit_pct);
|
||||
TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
|
||||
sliderProgress.setText(progressString);
|
||||
}
|
||||
@Override
|
||||
@ -223,34 +221,41 @@ public class PrefsActivity extends FragmentActivity {
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {}
|
||||
});
|
||||
} else {
|
||||
dialogContent = inflater.inflate(R.layout.prefs_layout_dialog, null);
|
||||
// show dialog with edit text
|
||||
dialog.setContentView(R.layout.prefs_layout_dialog);
|
||||
}
|
||||
builder.setMessage(listItem.ID)
|
||||
.setView(dialogContent)
|
||||
.setNegativeButton(R.string.prefs_cancel_button, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialogI, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.prefs_submit_button, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialogI, int id) {
|
||||
double value;
|
||||
if(dialogItem.isPct) {
|
||||
SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar);
|
||||
value = slider.getProgress();
|
||||
} else {
|
||||
EditText edit = (EditText) dialog.findViewById(R.id.Input);
|
||||
String input = edit.getText().toString();
|
||||
Double valueTmp = parseInputValueToDouble(input);
|
||||
if(valueTmp == null) return;
|
||||
value = valueTmp;
|
||||
}
|
||||
writeDoublePreference(dialogItem.ID, value);
|
||||
}
|
||||
});
|
||||
dialog = builder.create();
|
||||
dialog.show();
|
||||
dialogItem = listItem; // set dialog content
|
||||
// show preference name
|
||||
((TextView)dialog.findViewById(R.id.pref)).setText(listItem.ID);
|
||||
|
||||
// setup buttons
|
||||
Button confirm = (Button) dialog.findViewById(R.id.confirm);
|
||||
confirm.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
double value;
|
||||
if(listItem.isPct) {
|
||||
SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar);
|
||||
value = slider.getProgress()*10;
|
||||
} else {
|
||||
EditText edit = (EditText) dialog.findViewById(R.id.Input);
|
||||
String input = edit.getText().toString();
|
||||
Double valueTmp = parseInputValueToDouble(input);
|
||||
if(valueTmp == null) return;
|
||||
value = valueTmp;
|
||||
}
|
||||
writeDoublePreference(listItem.ID, value);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
Button cancel = (Button) dialog.findViewById(R.id.cancel);
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -293,9 +298,7 @@ public class PrefsActivity extends FragmentActivity {
|
||||
toast.show();
|
||||
return;
|
||||
}
|
||||
|
||||
// preferences adapted, dismiss dialog and write preferences to client
|
||||
dialog.dismiss();
|
||||
// preferences adapted, write preferences to client
|
||||
new WriteClientPrefsAsync().execute(clientPrefs);
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,9 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
|
||||
public class ClientNotification {
|
||||
private static final String TAG = "ClientNotification";
|
||||
//private static final String TAG = "ClientNotification";
|
||||
|
||||
private static ClientNotification clientNotification = null;
|
||||
|
||||
@ -51,7 +50,6 @@ public class ClientNotification {
|
||||
public synchronized void update() {
|
||||
// check whether notification is allowed in preferences
|
||||
if (!Monitor.getAppPrefs().getShowNotification()) {
|
||||
//Log.d(TAG,"cancelling notification");
|
||||
nm.cancel(notificationId);
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user