Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TagsResFactory.java « routes « ugc « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5891ba5f7d065815bca8c70ba6f54195bc6ed49b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.mapswithme.maps.ugc.routes;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.support.annotation.NonNull;

import com.mapswithme.maps.R;
import com.mapswithme.util.ThemeUtils;

public class TagsResFactory
{
  @NonNull
  public static StateListDrawable makeSelector(@NonNull Context context, int color)
  {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_enabled },
                      makeSelectedDrawable(color));
    drawable.addState(new int[] { -android.R.attr.state_selected, android.R.attr.state_enabled },
                      makeDefaultDrawable(context, color));
    int unselectedDisabledColor = getDisabledTagColor(context);
    drawable.addState(new int[] { -android.R.attr.state_selected, -android.R.attr.state_enabled },
                      makeDefaultDrawable(context, unselectedDisabledColor));
    return drawable;
  }

  private static int getDisabledTagColor(@NonNull Context context)
  {
    Resources res = context.getResources();
    return ThemeUtils.isNightTheme() ? res.getColor(R.color.white_12)
                                     : res.getColor(R.color.black_12);
  }

  @NonNull
  private static Drawable makeDefaultDrawable(@NonNull Context context, int color)
  {
    Resources res = context.getResources();
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setStroke(res.getDimensionPixelSize(R.dimen.divider_height), color);

    ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
    shapeDrawable.getPaint().setColor(Color.WHITE);
    return new LayerDrawable(new Drawable[] { shapeDrawable, gradientDrawable });
  }

  @NonNull
  public static ColorStateList makeColor(@NonNull Context context, int color)
  {
    return new ColorStateList(
        new int[][] {
            new int[] { android.R.attr.state_selected, android.R.attr.state_enabled },
            new int[] { -android.R.attr.state_selected, android.R.attr.state_enabled },
            new int[] { -android.R.attr.state_selected, -android.R.attr.state_enabled } },
        new int[] {
            context.getResources().getColor(android.R.color.white),
            color,
            getDisabledTagColor(context)
        }
    );
  }

  @NonNull
  private static ColorDrawable makeSelectedDrawable(int color)
  {
    return new ColorDrawable(color);
  }
}