mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
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.fragments.ChooseActivityTypeDialogFragment;
|
||||
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.TrackNameUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapFactory.Options;
|
||||
import android.os.Bundle;
|
||||
@@ -131,13 +133,14 @@ public class TrackEditActivity extends AbstractMyTracksActivity
|
||||
new StringBuilder[] {new StringBuilder(iconValue)}) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, android.view.ViewGroup parent) {
|
||||
ImageView imageView;
|
||||
if (convertView != null) {
|
||||
imageView = (ImageView) convertView;
|
||||
} else {
|
||||
imageView = new ImageView(getContext());
|
||||
ImageView imageView =
|
||||
convertView != null ? (ImageView) convertView : new ImageView(getContext());
|
||||
Bitmap source = BitmapFactory.decodeResource(
|
||||
getResources(), TrackIconUtils.getIconDrawable(getItem(position).toString()));
|
||||
if (ApiAdapterFactory.getApiAdapter().isSpinnerBackgroundLight()) {
|
||||
source = TrackIconUtils.invertBitmap(source);
|
||||
}
|
||||
imageView.setImageResource(TrackIconUtils.getIconDrawable(getItem(position).toString()));
|
||||
imageView.setImageBitmap(source);
|
||||
imageView.setMinimumHeight(height);
|
||||
imageView.setMinimumWidth(width);
|
||||
imageView.setPadding(padding, padding, padding, padding);
|
||||
|
||||
@@ -124,4 +124,9 @@ public class Api11Adapter extends Api10Adapter {
|
||||
public void invalidMenu(Activity activity) {
|
||||
activity.invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpinnerBackgroundLight() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,11 @@ public class Api8Adapter implements ApiAdapter {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpinnerBackgroundLight() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSearchKey(MenuItem menuItem) {
|
||||
// Return false and allow the framework to handle the search key.
|
||||
|
||||
@@ -163,6 +163,13 @@ public interface ApiAdapter {
|
||||
*/
|
||||
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.
|
||||
* <p>
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.google.android.apps.mytracks.util;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -157,6 +159,34 @@ public class TrackIconUtils {
|
||||
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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user