Set dialog title divider for preference dialogs

This commit is contained in:
Jimmy Shih
2013-11-25 15:52:12 -08:00
parent 8506b340e8
commit 2ae1d7fe29
13 changed files with 162 additions and 28 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/track_detail_chart_tab" >
<ListPreference
<com.google.android.apps.mytracks.settings.MyTracksListPreference
android:defaultValue="@string/chart_x_axis_distance"
android:key="@string/chart_x_axis_key"
android:title="@string/settings_chart_x_axis" />
+1 -1
View File
@@ -16,7 +16,7 @@ limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/settings_google" >
<ListPreference
<com.google.android.apps.mytracks.settings.MyTracksListPreference
android:defaultValue=""
android:key="@string/google_account_key"
android:title="@string/settings_google_account_title" />
+7 -10
View File
@@ -16,33 +16,30 @@ limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/track_detail_map_tab" >
<ListPreference
<com.google.android.apps.mytracks.settings.MyTracksListPreference
android:defaultValue="@string/settings_map_track_color_mode_single_value"
android:key="@string/track_color_mode_key"
android:title="@string/settings_map_track_color_mode" />
<PreferenceCategory android:title="@string/settings_map_track_color_mode_fixed" >
<EditTextPreference
<com.google.android.apps.mytracks.settings.MyTracksEditTextPreference
android:imeOptions="actionDone"
android:inputType="number"
android:key="@string/settings_map_slow_display_key"
android:persistent="false"
android:title="@string/settings_map_slow" >
</EditTextPreference>
<EditTextPreference
android:title="@string/settings_map_slow" />
<com.google.android.apps.mytracks.settings.MyTracksEditTextPreference
android:imeOptions="actionDone"
android:inputType="number"
android:key="@string/settings_map_medium_display_key"
android:persistent="false"
android:title="@string/settings_map_medium" >
</EditTextPreference>
android:title="@string/settings_map_medium" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/settings_map_track_color_mode_dynamic" >
<EditTextPreference
<com.google.android.apps.mytracks.settings.MyTracksEditTextPreference
android:imeOptions="actionDone"
android:inputType="number"
android:key="@string/settings_map_percentage_display_key"
android:persistent="false"
android:title="@string/settings_map_percentage" >
</EditTextPreference>
android:title="@string/settings_map_percentage" />
</PreferenceCategory>
</PreferenceScreen>
+1 -1
View File
@@ -24,7 +24,7 @@ limitations under the License.
android:defaultValue="0"
android:key="@string/split_frequency_key"
android:title="@string/menu_split_frequency" />
<ListPreference
<com.google.android.apps.mytracks.settings.MyTracksListPreference
android:defaultValue="@string/settings_recording_track_name_location_value"
android:key="@string/track_name_key"
android:title="@string/settings_recording_track_name_title" />
+2 -2
View File
@@ -17,7 +17,7 @@ limitations under the License.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="@string/settings_sensor_root_key"
android:title="@string/settings_sensor" >
<ListPreference
<com.google.android.apps.mytracks.settings.MyTracksListPreference
android:defaultValue="@string/sensor_type_value_none"
android:key="@string/sensor_type_key"
android:title="@string/settings_sensor_type" />
@@ -29,7 +29,7 @@ limitations under the License.
android:persistent="false"
android:summary="@string/settings_sensor_bluetooth_pairing_summary"
android:title="@string/settings_sensor_bluetooth_pairing" />
<ListPreference
<com.google.android.apps.mytracks.settings.MyTracksListPreference
android:defaultValue=""
android:key="@string/bluetooth_sensor_key"
android:title="@string/settings_sensor_bluetooth_sensor" />
+2 -2
View File
@@ -16,11 +16,11 @@ limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/track_detail_stats_tab" >
<ListPreference
<com.google.android.apps.mytracks.settings.MyTracksListPreference
android:defaultValue="@string/stats_units_metric"
android:key="@string/stats_units_key"
android:title="@string/settings_stats_units_title" />
<ListPreference
<com.google.android.apps.mytracks.settings.MyTracksListPreference
android:defaultValue="@string/stats_rate_speed"
android:key="@string/stats_rate_key"
android:title="@string/settings_stats_rate_title" />
@@ -37,7 +37,7 @@ public abstract class AbstractMyTracksDialogFragment extends DialogFragment {
@Override
public void onShow(DialogInterface dialogInterface) {
DialogUtils.setTitleDivier(getActivity(), dialog);
DialogUtils.setDialogTitleDivider(getActivity(), dialog);
}
});
return dialog;
@@ -173,7 +173,7 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment {
}
updateWeightContainer(weightContainer, position);
weight.setText(weightValue);
DialogUtils.setTitleDivier(activity, alertDialog);
DialogUtils.setDialogTitleDivider(activity, alertDialog);
}
});
@@ -16,11 +16,13 @@
package com.google.android.apps.mytracks.settings;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.TrackIconUtils;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
@@ -107,6 +109,12 @@ public class ActivityTypePreference extends DialogPreference {
return view;
}
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
DialogUtils.setDialogTitleDivider(getContext(), getDialog());
}
@Override
protected void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
@@ -17,7 +17,6 @@
package com.google.android.apps.mytracks.settings;
import android.content.Context;
import android.preference.ListPreference;
import android.util.AttributeSet;
/**
@@ -29,7 +28,7 @@ import android.util.AttributeSet;
*
* @author Rodrigo Damazio
*/
public class IntegerListPreference extends ListPreference {
public class IntegerListPreference extends MyTracksListPreference {
public IntegerListPreference(Context context) {
super(context);
@@ -0,0 +1,46 @@
/*
* Copyright 2013 Google Inc.
*
* 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.
*/
package com.google.android.apps.mytracks.settings;
import com.google.android.apps.mytracks.util.DialogUtils;
import android.content.Context;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.util.AttributeSet;
/**
* My Tracks edit text preference.
*
* @author Jimmy Shih
*/
public class MyTracksEditTextPreference extends EditTextPreference {
public MyTracksEditTextPreference(Context context) {
super(context);
}
public MyTracksEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
DialogUtils.setDialogTitleDivider(getContext(), getDialog());
}
}
@@ -0,0 +1,46 @@
/*
* Copyright 2013 Google Inc.
*
* 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.
*/
package com.google.android.apps.mytracks.settings;
import com.google.android.apps.mytracks.util.DialogUtils;
import android.content.Context;
import android.os.Bundle;
import android.preference.ListPreference;
import android.util.AttributeSet;
/**
* My Tracks list preference.
*
* @author Jimmy Shih
*/
public class MyTracksListPreference extends ListPreference {
public MyTracksListPreference(Context context) {
super(context);
}
public MyTracksListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
DialogUtils.setDialogTitleDivider(getContext(), getDialog());
}
}
@@ -46,15 +46,22 @@ public class DialogUtils {
* @param okListener the listener when OK is clicked
*/
public static Dialog createConfirmationDialog(
Context context, int titleId, String message, DialogInterface.OnClickListener okListener) {
AlertDialog.Builder builder = new AlertDialog.Builder(context)
final Context context, int titleId, String message, DialogInterface.OnClickListener okListener) {
final AlertDialog alertDialog = new AlertDialog.Builder(context)
.setCancelable(true)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(message)
.setNegativeButton(R.string.generic_no, null)
.setPositiveButton(R.string.generic_yes, okListener)
.setTitle(titleId);
return builder.create();
.setTitle(titleId).create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
setDialogTitleDivider(context, alertDialog);
}
});
return alertDialog;
}
/**
@@ -91,9 +98,9 @@ public class DialogUtils {
* @param onCancelListener the cancel listener
* @param formatArgs the format arguments for the message id
*/
private static ProgressDialog createProgressDialog(boolean spinner, Context context,
private static ProgressDialog createProgressDialog(boolean spinner, final Context context,
int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
ProgressDialog progressDialog = new ProgressDialog(context);
final ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setIcon(android.R.drawable.ic_dialog_info);
@@ -103,18 +110,49 @@ public class DialogUtils {
progressDialog.setProgressStyle(spinner ? ProgressDialog.STYLE_SPINNER
: ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.generic_progress_title);
progressDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
setDialogTitleDivider(context, progressDialog);
}
});
return progressDialog;
}
public static void setTitleDivier(Context context, Dialog dialog) {
/**
* Sets the dialog title divider.
*
* @param context the context
* @param dialog the dialog
*/
public static void setDialogTitleDivider(Context context, Dialog dialog) {
if (ApiAdapterFactory.getApiAdapter().hasDialogTitleDivider()) {
try {
ViewGroup decorView = (ViewGroup) dialog.getWindow().getDecorView();
if (decorView == null) {
return;
}
FrameLayout windowContentView = (FrameLayout) decorView.getChildAt(0);
if (windowContentView == null) {
return;
}
FrameLayout contentView = (FrameLayout) windowContentView.getChildAt(0);
if (contentView == null) {
return;
}
LinearLayout parentPanel = (LinearLayout) contentView.getChildAt(0);
if (parentPanel == null) {
return;
}
LinearLayout topPanel = (LinearLayout) parentPanel.getChildAt(0);
if (topPanel == null) {
return;
}
View titleDivider = topPanel.getChildAt(2);
if (titleDivider == null) {
return;
}
titleDivider.setBackgroundColor(context.getResources().getColor(R.color.holo_orange_dark));
} catch (Exception e) {
// Can safely ignore