forked from upstream-mirrors/OpenTracks
Invert icon image shown in Spinner for API level < 11
This commit is contained in:
@@ -20,10 +20,12 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
|||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment;
|
import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller;
|
import com.google.android.apps.mytracks.fragments.ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller;
|
||||||
|
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||||
import com.google.android.apps.mytracks.util.TrackNameUtils;
|
import com.google.android.apps.mytracks.util.TrackNameUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.BitmapFactory.Options;
|
import android.graphics.BitmapFactory.Options;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -131,13 +133,14 @@ public class TrackEditActivity extends AbstractMyTracksActivity
|
|||||||
new StringBuilder[] {new StringBuilder(iconValue)}) {
|
new StringBuilder[] {new StringBuilder(iconValue)}) {
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, android.view.ViewGroup parent) {
|
public View getView(int position, View convertView, android.view.ViewGroup parent) {
|
||||||
ImageView imageView;
|
ImageView imageView =
|
||||||
if (convertView != null) {
|
convertView != null ? (ImageView) convertView : new ImageView(getContext());
|
||||||
imageView = (ImageView) convertView;
|
Bitmap source = BitmapFactory.decodeResource(
|
||||||
} else {
|
getResources(), TrackIconUtils.getIconDrawable(getItem(position).toString()));
|
||||||
imageView = new ImageView(getContext());
|
if (ApiAdapterFactory.getApiAdapter().isSpinnerBackgroundLight()) {
|
||||||
|
source = TrackIconUtils.invertBitmap(source);
|
||||||
}
|
}
|
||||||
imageView.setImageResource(TrackIconUtils.getIconDrawable(getItem(position).toString()));
|
imageView.setImageBitmap(source);
|
||||||
imageView.setMinimumHeight(height);
|
imageView.setMinimumHeight(height);
|
||||||
imageView.setMinimumWidth(width);
|
imageView.setMinimumWidth(width);
|
||||||
imageView.setPadding(padding, padding, padding, padding);
|
imageView.setPadding(padding, padding, padding, padding);
|
||||||
|
|||||||
@@ -124,4 +124,9 @@ public class Api11Adapter extends Api10Adapter {
|
|||||||
public void invalidMenu(Activity activity) {
|
public void invalidMenu(Activity activity) {
|
||||||
activity.invalidateOptionsMenu();
|
activity.invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpinnerBackgroundLight() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,6 +133,11 @@ public class Api8Adapter implements ApiAdapter {
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpinnerBackgroundLight() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handleSearchKey(MenuItem menuItem) {
|
public boolean handleSearchKey(MenuItem menuItem) {
|
||||||
// Return false and allow the framework to handle the search key.
|
// Return false and allow the framework to handle the search key.
|
||||||
|
|||||||
@@ -163,6 +163,13 @@ public interface ApiAdapter {
|
|||||||
*/
|
*/
|
||||||
public void invalidMenu(Activity activity);
|
public void invalidMenu(Activity activity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if the spinner background is light color.
|
||||||
|
* <p>
|
||||||
|
* Due to changes in API level 11.
|
||||||
|
*/
|
||||||
|
public boolean isSpinnerBackgroundLight();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the search key press. Returns true if handled.
|
* Handles the search key press. Returns true if handled.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ package com.google.android.apps.mytracks.util;
|
|||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -157,6 +159,34 @@ public class TrackIconUtils {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inverts the colors in a bitmap.
|
||||||
|
*
|
||||||
|
* @param source the source
|
||||||
|
*/
|
||||||
|
public static Bitmap invertBitmap(Bitmap source) {
|
||||||
|
Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), source.getConfig());
|
||||||
|
int height = source.getHeight();
|
||||||
|
int width = source.getWidth();
|
||||||
|
int pixelColor;
|
||||||
|
int alpha;
|
||||||
|
int red;
|
||||||
|
int green;
|
||||||
|
int blue;
|
||||||
|
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
pixelColor = source.getPixel(x, y);
|
||||||
|
alpha = Color.alpha(pixelColor);
|
||||||
|
red = 255 - Color.red(pixelColor);
|
||||||
|
green = 255 - Color.green(pixelColor);
|
||||||
|
blue = 255 - Color.blue(pixelColor);
|
||||||
|
output.setPixel(x, y, Color.argb(alpha, red, green, blue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the activity type is in the list.
|
* Returns true if the activity type is in the list.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user