mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
A few fixes.
- use fill_parent since we are still supporting api level 7. - on the TrackListActivity, hide the empty view content until the check unit dialog has been showned. - fix the ChartView height. ChartView is no longer displayed on the full canvas. The new design has a tab bar and a zoom control. - In TrackDetailActivity, only call methods of a tab fragment if it is the current tab.
This commit is contained in:
@@ -16,17 +16,17 @@ limitations under the License.
|
||||
-->
|
||||
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/tabhost"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent" >
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent" >
|
||||
<LinearLayout
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
<TabWidget
|
||||
android:id="@android:id/tabs"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="horizontal" />
|
||||
<FrameLayout
|
||||
android:id="@android:id/tabcontent"
|
||||
@@ -37,6 +37,6 @@ limitations under the License.
|
||||
android:id="@+id/realtabcontent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent" />
|
||||
android:layout_width="fill_parent" />
|
||||
</LinearLayout>
|
||||
</TabHost>
|
||||
@@ -28,7 +28,9 @@ limitations under the License.
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
<TextView
|
||||
android:id="@+id/track_list_empty_message"
|
||||
android:text="@string/track_list_empty_message"
|
||||
android:visibility="gone"
|
||||
style="@style/ListEmptyTextView" >
|
||||
</TextView>
|
||||
<ImageButton
|
||||
@@ -38,6 +40,7 @@ limitations under the License.
|
||||
android:layout_width="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:src="@drawable/menu_record_track"
|
||||
android:visibility="gone"
|
||||
style="@android:style/Widget.DeviceDefault.ImageButton" />
|
||||
</LinearLayout>
|
||||
</merge>
|
||||
@@ -76,7 +76,7 @@ public class ChartView extends View {
|
||||
/**
|
||||
* Unscaled top border of the chart.
|
||||
*/
|
||||
private static final int TOP_BORDER = 15;
|
||||
private static final int TOP_BORDER = 16;
|
||||
|
||||
/**
|
||||
* Device scaled top border of the chart.
|
||||
@@ -86,7 +86,7 @@ public class ChartView extends View {
|
||||
/**
|
||||
* Unscaled bottom border of the chart.
|
||||
*/
|
||||
private static final float BOTTOM_BORDER = 40;
|
||||
private static final float BOTTOM_BORDER = 8;
|
||||
|
||||
/**
|
||||
* Device scaled bottom border of the chart.
|
||||
@@ -509,10 +509,16 @@ public class ChartView extends View {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
updateEffectiveDimensionsIfChanged(
|
||||
View.MeasureSpec.getSize(widthMeasureSpec), View.MeasureSpec.getSize(heightMeasureSpec));
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas c) {
|
||||
synchronized (data) {
|
||||
updateEffectiveDimensionsIfChanged(c);
|
||||
|
||||
// Keep original state.
|
||||
c.save();
|
||||
@@ -742,13 +748,16 @@ public class ChartView extends View {
|
||||
|
||||
/**
|
||||
* Updates the effective dimensions where the graph will be drawn, only if the
|
||||
* dimensions of the given canvas have changed since the last call.
|
||||
* dimensions have changed since the last call.
|
||||
*
|
||||
* @param newWidth the new width
|
||||
* @param newHeight the new height
|
||||
*/
|
||||
private void updateEffectiveDimensionsIfChanged(Canvas c) {
|
||||
if (w != c.getWidth() || h != c.getHeight()) {
|
||||
private void updateEffectiveDimensionsIfChanged(int newWidth, int newHeight) {
|
||||
if (w != newWidth || h != newHeight) {
|
||||
// Dimensions have changed (for example due to orientation change).
|
||||
w = c.getWidth();
|
||||
h = c.getHeight();
|
||||
w = newWidth;
|
||||
h = newHeight;
|
||||
updateEffectiveDimensions();
|
||||
setUpPath();
|
||||
}
|
||||
|
||||
@@ -237,14 +237,20 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
||||
ChartFragment.CHART_FRAGMENT_TAG.equals(currentTabTag));
|
||||
menu.findItem(R.id.track_detail_my_location)
|
||||
.setVisible(MapFragment.MAP_FRAGMENT_TAG.equals(currentTabTag));
|
||||
|
||||
// Set map or satellite mode
|
||||
MapFragment mapFragment = (MapFragment) getSupportFragmentManager()
|
||||
.findFragmentByTag(MapFragment.MAP_FRAGMENT_TAG);
|
||||
boolean isSatelliteMode = mapFragment != null ? mapFragment.isSatelliteView() : false;
|
||||
menu.findItem(R.id.track_detail_satellite_mode)
|
||||
.setVisible(MapFragment.MAP_FRAGMENT_TAG.equals(currentTabTag))
|
||||
.setTitle(isSatelliteMode ? R.string.menu_map_mode : R.string.menu_satellite_mode);
|
||||
MenuItem satelliteMode = menu.findItem(R.id.track_detail_satellite_mode)
|
||||
.setVisible(MapFragment.MAP_FRAGMENT_TAG.equals(currentTabTag));
|
||||
|
||||
if (satelliteMode.isVisible()) {
|
||||
MapFragment mapFragment = (MapFragment) getSupportFragmentManager()
|
||||
.findFragmentByTag(MapFragment.MAP_FRAGMENT_TAG);
|
||||
/*
|
||||
* The current tag is mapFragment, thus safe to call its methods like
|
||||
* isSatelliteView.
|
||||
*/
|
||||
boolean isSatelliteMode = mapFragment != null ? mapFragment.isSatelliteView() : false;
|
||||
menu.findItem(R.id.track_detail_satellite_mode).setTitle(
|
||||
isSatelliteMode ? R.string.menu_map_mode : R.string.menu_satellite_mode);
|
||||
}
|
||||
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileForm
|
||||
import com.google.android.apps.mytracks.services.ITrackRecordingService;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.CheckUnitsUtils;
|
||||
import com.google.android.apps.mytracks.util.EulaUtils;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.ListItemUtil;
|
||||
@@ -262,8 +263,21 @@ public class TrackListActivity extends FragmentActivity {
|
||||
getSupportFragmentManager(), EulaDialogFragment.EULA_DIALOG_TAG);
|
||||
}
|
||||
}
|
||||
if (CheckUnitsUtils.getCheckUnitsValue(this)) {
|
||||
enableEmptyView();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the content of the empty view.
|
||||
*/
|
||||
public void enableEmptyView() {
|
||||
View emptyMessage = findViewById(R.id.track_list_empty_message);
|
||||
emptyMessage.setVisibility(View.VISIBLE);
|
||||
View recordButton = findViewById(R.id.track_list_record_button);
|
||||
recordButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@@ -133,8 +133,9 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
ViewGroup layout = (ViewGroup) getActivity().findViewById(R.id.chart_view_layout);
|
||||
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||
LayoutParams.MATCH_PARENT);
|
||||
@SuppressWarnings("deprecation")
|
||||
LayoutParams layoutParams = new LayoutParams(
|
||||
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
|
||||
layout.addView(chartView, layoutParams);
|
||||
}
|
||||
|
||||
|
||||
+14
-5
@@ -17,6 +17,7 @@
|
||||
package com.google.android.apps.mytracks.fragments;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.CheckUnitsUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
@@ -31,13 +32,13 @@ import android.support.v4.app.DialogFragment;
|
||||
|
||||
/**
|
||||
* A DialogFragment to check preferred units.
|
||||
*
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class CheckUnitsDialogFragment extends DialogFragment {
|
||||
|
||||
public static final String CHECK_UNITS_DIALOG_TAG = "checkUnitsDialog";
|
||||
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
|
||||
@@ -46,19 +47,18 @@ public class CheckUnitsDialogFragment extends DialogFragment {
|
||||
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
CheckUnitsUtils.setCheckUnitsValue(getActivity());
|
||||
handleButtonClicked();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
CheckUnitsUtils.setCheckUnitsValue(getActivity());
|
||||
|
||||
int position = ((AlertDialog) dialog).getListView().getSelectedItemPosition();
|
||||
SharedPreferences sharedPreferences = getActivity()
|
||||
.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(sharedPreferences.edit()
|
||||
.putBoolean(getString(R.string.metric_units_key), position == 0));
|
||||
handleButtonClicked();
|
||||
}
|
||||
})
|
||||
.setSingleChoiceItems(new CharSequence[] { getString(R.string.preferred_units_metric),
|
||||
@@ -66,4 +66,13 @@ public class CheckUnitsDialogFragment extends DialogFragment {
|
||||
.setTitle(R.string.preferred_units_title)
|
||||
.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a button click.
|
||||
*/
|
||||
private void handleButtonClicked() {
|
||||
CheckUnitsUtils.setCheckUnitsValue(getActivity());
|
||||
TrackListActivity trackListActivity = (TrackListActivity) getActivity();
|
||||
trackListActivity.enableEmptyView();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user