Skip to content

Commit 3c3848e

Browse files
author
David Graeff
committed
Dark theme repaired. Use ThemeHelper for dialogs. LoadStoreIconData: Move all inner classes out and create new SelectDrawableDialog class. Use recyclerview for the later.
1 parent 92f100a commit 3c3848e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+690
-525
lines changed

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ android {
1616
defaultConfig {
1717
minSdkVersion 17
1818
targetSdkVersion 22
19-
versionCode 120
20-
versionName "8.0"
19+
versionCode 121
20+
versionName "8.1"
2121
applicationId appID
2222
testApplicationId "oly.netpowerctrl.tests"
2323
testInstrumentationRunner "android.test.InstrumentationTestRunner"

app/src/main/java/oly/netpowerctrl/data/graphic/ArrayAdapterWithIcons.java

+39-18
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,64 @@
22

33
import android.content.Context;
44
import android.graphics.drawable.Drawable;
5+
import android.support.v7.widget.RecyclerView;
6+
import android.view.LayoutInflater;
57
import android.view.View;
68
import android.view.ViewGroup;
7-
import android.widget.ArrayAdapter;
89
import android.widget.TextView;
910

11+
import java.util.ArrayList;
1012
import java.util.List;
1113

1214
/**
1315
* A simple array adapter that additionally provide an icon per entry.
1416
*/
15-
class ArrayAdapterWithIcons extends ArrayAdapter<ArrayAdapterWithIcons.Item> {
16-
public final List<Item> items;
17+
class ArrayAdapterWithIcons extends RecyclerView.Adapter<ArrayAdapterWithIcons.ViewHolder> {
18+
final static int resource = android.R.layout.select_dialog_item;
19+
final static int textViewResourceId = android.R.id.text1;
20+
public final List<Item> items = new ArrayList<>();
21+
private int dp5;
1722

1823
@SuppressWarnings("SameParameterValue")
19-
public ArrayAdapterWithIcons(Context context, int resource, int textViewResourceId, List<Item> objects) {
20-
super(context, resource, textViewResourceId, objects);
21-
items = objects;
24+
public ArrayAdapterWithIcons(Context context) {
25+
//Add margin between image and text (support various screen densities)
26+
dp5 = (int) (5 * context.getResources().getDisplayMetrics().density + 0.5f);
2227
}
2328

2429
@Override
25-
public View getView(int position, View convertView, ViewGroup parent) {
26-
//User super class to create the View
27-
View v = super.getView(position, convertView, parent);
28-
assert v != null;
29-
TextView tv = (TextView) v.findViewById(android.R.id.text1);
30+
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
31+
return new ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(resource, viewGroup, false));
32+
}
33+
34+
@Override
35+
public void onBindViewHolder(ViewHolder holder, int position) {
3036
//Put the image on the TextView
31-
tv.setCompoundDrawablesWithIntrinsicBounds(items.get(position).icon, null, null, null);
37+
Item item = items.get(position);
3238

33-
if (items.get(position).icon != null) {
34-
//Add margin between image and text (support various screen densities)
35-
int dp5 = (int) (5 * getContext().getResources().getDisplayMetrics().density + 0.5f);
36-
tv.setCompoundDrawablePadding(dp5);
39+
if (item.text != null)
40+
holder.tv.setText(item.text);
41+
42+
holder.tv.setCompoundDrawablesWithIntrinsicBounds(item.icon, null, null, null);
43+
44+
if (item.icon != null) {
45+
holder.tv.setCompoundDrawablePadding(dp5);
3746
} else {
38-
tv.setCompoundDrawablePadding(0);
47+
holder.tv.setCompoundDrawablePadding(0);
3948
}
49+
}
4050

41-
return v;
51+
@Override
52+
public int getItemCount() {
53+
return items.size();
54+
}
55+
56+
public static class ViewHolder extends RecyclerView.ViewHolder {
57+
TextView tv;
58+
59+
public ViewHolder(View itemView) {
60+
super(itemView);
61+
tv = (TextView) itemView.findViewById(textViewResourceId);
62+
}
4263
}
4364

4465
public static class Item {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package oly.netpowerctrl.data.graphic;
2+
3+
import android.graphics.Bitmap;
4+
5+
/**
6+
* Created by david on 15.05.15.
7+
*/
8+
public class DrawableCacheEntry {
9+
Bitmap bitmap;
10+
boolean isDefault;
11+
12+
public DrawableCacheEntry(Bitmap bitmap, boolean isDefault) {
13+
this.bitmap = bitmap;
14+
this.isDefault = isDefault;
15+
}
16+
}

app/src/main/java/oly/netpowerctrl/data/graphic/IconDeferredLoadingThread.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public interface IconLoaded {
6161
* ViewHolder and the bitmap index.
6262
*/
6363
public static class IconItem {
64-
private final LoadStoreIconData.IconState state;
64+
private final IconState state;
6565
private final WeakReference<IconLoaded> target;
6666
private final int position;
6767
private Drawable drawable;
6868

69-
public IconItem(LoadStoreIconData.IconState state, int position, IconLoaded target) {
69+
public IconItem(IconState state, int position, IconLoaded target) {
7070
this.state = state;
7171
this.position = position;
7272
this.target = new WeakReference<>(target);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package oly.netpowerctrl.data.graphic;
2+
3+
import android.content.Intent;
4+
import android.graphics.Bitmap;
5+
6+
/**
7+
* Created by david on 15.05.15.
8+
*/
9+
public interface IconSelected {
10+
void setIcon(Object context_object, Bitmap bitmap);
11+
12+
void startActivityForResult(Intent intent, int requestCode);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package oly.netpowerctrl.data.graphic;
2+
3+
/**
4+
* Created by david on 15.05.15.
5+
*/
6+
public enum IconState {
7+
StateOn,
8+
StateOff,
9+
StateUnknown,
10+
OnlyOneState,
11+
StateNotApplicable // State does not apply e.g. for a background
12+
}

0 commit comments

Comments
 (0)