forked from upstream-mirrors/OpenTracks
Move navcontrols icon decleration to xml.
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2010 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.
|
||||||
|
-->
|
||||||
|
<resources>
|
||||||
|
<array name="left_icons">
|
||||||
|
<item>@drawable/left_arrow_chart_stateful</item>
|
||||||
|
<item>@drawable/left_arrow_track_stateful</item>
|
||||||
|
<item>@drawable/left_arrow_stats_stateful</item>
|
||||||
|
</array>
|
||||||
|
|
||||||
|
<array name="right_icons">
|
||||||
|
<item>@drawable/right_arrow_stats_stateful</item>
|
||||||
|
<item>@drawable/right_arrow_chart_stateful</item>
|
||||||
|
<item>@drawable/right_arrow_track_stateful</item>
|
||||||
|
</array>
|
||||||
|
</resources>
|
||||||
@@ -202,17 +202,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
|
|
||||||
private NavControls navControls;
|
private NavControls navControls;
|
||||||
|
|
||||||
/** Icons shown on the left for each tab. */
|
|
||||||
private final int leftIcons[] =
|
|
||||||
{ R.drawable.left_arrow_chart_stateful,
|
|
||||||
R.drawable.left_arrow_track_stateful,
|
|
||||||
R.drawable.left_arrow_stats_stateful };
|
|
||||||
/** Icons shown on the right for each tab. */
|
|
||||||
private final int rightIcons[] =
|
|
||||||
{ R.drawable.right_arrow_stats_stateful,
|
|
||||||
R.drawable.right_arrow_chart_stateful,
|
|
||||||
R.drawable.right_arrow_track_stateful };
|
|
||||||
|
|
||||||
private final Runnable changeTab = new Runnable() {
|
private final Runnable changeTab = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
getTabHost().setCurrentTab(navControls.getCurrentIcons());
|
getTabHost().setCurrentTab(navControls.getCurrentIcons());
|
||||||
@@ -298,7 +287,10 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
|
new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
|
||||||
layout.setLayoutParams(params);
|
layout.setLayoutParams(params);
|
||||||
navControls =
|
navControls =
|
||||||
new NavControls(this, layout, leftIcons, rightIcons, changeTab);
|
new NavControls(this, layout,
|
||||||
|
getResources().obtainTypedArray(R.array.left_icons),
|
||||||
|
getResources().obtainTypedArray(R.array.right_icons),
|
||||||
|
changeTab);
|
||||||
navControls.show();
|
navControls.show();
|
||||||
tabHost.addView(layout);
|
tabHost.addView(layout);
|
||||||
layout.setOnTouchListener(this);
|
layout.setOnTouchListener(this);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
package com.google.android.apps.mytracks;
|
package com.google.android.apps.mytracks;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -62,8 +63,7 @@ public class NavControls {
|
|||||||
addView(icon);
|
addView(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(int iconId) {
|
public void setIcon(Drawable drawable) {
|
||||||
Drawable drawable = getContext().getResources().getDrawable(iconId);
|
|
||||||
icon.setImageDrawable(drawable);
|
icon.setImageDrawable(drawable);
|
||||||
icon.setVisibility(View.VISIBLE);
|
icon.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
@@ -102,21 +102,21 @@ public class NavControls {
|
|||||||
|
|
||||||
private final TouchLayout prevImage;
|
private final TouchLayout prevImage;
|
||||||
private final TouchLayout nextImage;
|
private final TouchLayout nextImage;
|
||||||
private final int[] leftIcons;
|
private final TypedArray leftIcons;
|
||||||
private final int[] rightIcons;
|
private final TypedArray rightIcons;
|
||||||
private final Runnable touchRunnable;
|
private final Runnable touchRunnable;
|
||||||
|
|
||||||
private boolean isVisible = false;
|
private boolean isVisible = false;
|
||||||
private int currentIcons;
|
private int currentIcons;
|
||||||
|
|
||||||
public NavControls(Context context, ViewGroup container,
|
public NavControls(Context context, ViewGroup container,
|
||||||
int[] leftIcons, int[] rightIcons,
|
TypedArray leftIcons, TypedArray rightIcons,
|
||||||
Runnable touchRunnable) {
|
Runnable touchRunnable) {
|
||||||
this.leftIcons = leftIcons;
|
this.leftIcons = leftIcons;
|
||||||
this.rightIcons = rightIcons;
|
this.rightIcons = rightIcons;
|
||||||
this.touchRunnable = touchRunnable;
|
this.touchRunnable = touchRunnable;
|
||||||
|
|
||||||
if (leftIcons.length != rightIcons.length || leftIcons.length < 1) {
|
if (leftIcons.length() != rightIcons.length() || leftIcons.length() < 1) {
|
||||||
throw new IllegalArgumentException("Invalid icons specified");
|
throw new IllegalArgumentException("Invalid icons specified");
|
||||||
}
|
}
|
||||||
if (touchRunnable == null) {
|
if (touchRunnable == null) {
|
||||||
@@ -145,8 +145,8 @@ public class NavControls {
|
|||||||
container.addView(prevImage);
|
container.addView(prevImage);
|
||||||
container.addView(nextImage);
|
container.addView(nextImage);
|
||||||
|
|
||||||
prevImage.setIcon(leftIcons[0]);
|
prevImage.setIcon(leftIcons.getDrawable(0));
|
||||||
nextImage.setIcon(rightIcons[0]);
|
nextImage.setIcon(rightIcons.getDrawable(0));
|
||||||
this.currentIcons = 0;
|
this.currentIcons = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,8 +206,8 @@ public class NavControls {
|
|||||||
|
|
||||||
private void shiftIcons(boolean isLeft) {
|
private void shiftIcons(boolean isLeft) {
|
||||||
// Increment or decrement by one, with wrap around
|
// Increment or decrement by one, with wrap around
|
||||||
currentIcons = (currentIcons + leftIcons.length + (isLeft ? -1 : 1)) % leftIcons.length;
|
currentIcons = (currentIcons + leftIcons.length() + (isLeft ? -1 : 1)) % leftIcons.length();
|
||||||
prevImage.setIcon(leftIcons[currentIcons]);
|
prevImage.setIcon(leftIcons.getDrawable(currentIcons));
|
||||||
nextImage.setIcon(rightIcons[currentIcons]);
|
nextImage.setIcon(rightIcons.getDrawable(currentIcons));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user