Skip to content

Commit dc9de22

Browse files
author
David Gräff
committed
clean up code (part 1); widget create activity improved; widget default values
1 parent 6f39d74 commit dc9de22

File tree

106 files changed

+5853
-1951
lines changed

Some content is hidden

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

106 files changed

+5853
-1951
lines changed

.idea/workspace.xml

Lines changed: 538 additions & 801 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ android {
2020
versionName "5.7.2"
2121
applicationId appID
2222
testApplicationId "oly.netpowerctrl.tests"
23+
testInstrumentationRunner "android.test.InstrumentationTestRunner"
24+
resConfig "de"
2325
}
2426

2527
lintOptions {
@@ -31,6 +33,15 @@ android {
3133
targetCompatibility JavaVersion.VERSION_1_7
3234
}
3335

36+
def getRevision = { ->
37+
def stdout = new ByteArrayOutputStream()
38+
exec {
39+
commandLine 'git', 'rev-parse', '--short', 'HEAD'
40+
standardOutput = stdout
41+
}
42+
return stdout.toString().trim()
43+
}
44+
3445
buildTypes {
3546
release {
3647
zipAlign true
@@ -41,6 +52,7 @@ android {
4152
debuggable false
4253
}
4354
debug {
55+
versionNameSuffix "-" + getRevision()
4456
applicationIdSuffix ".debug"
4557
resValue "string", "authority", appID + ".utils.AssetDocumentProvider.Debug"
4658
//buildConfigField "String", "AUTHORITY", appID + ".utils.AssetDocumentProvider.Debug"
@@ -50,6 +62,11 @@ android {
5062
}
5163
}
5264
sourceSets { main { java.srcDirs = ['src/main/java', 'src/tests/java'] } }
65+
66+
aaptOptions {
67+
//noCompress 'txt'
68+
ignoreAssetsPattern "!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"
69+
}
5370
}
5471

5572
dependencies {

app/src/lint-result.xml

Lines changed: 4591 additions & 0 deletions
Large diffs are not rendered by default.

app/src/main/java/oly/netpowerctrl/anel/AnelPluginHttp.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ public void startElement(String uri,
179179
if (current.hour_minute_start == -1)
180180
complete_post_data[0] += "99:99";
181181
else
182-
complete_post_data[0] += URLEncoder.encode(current.time(current.hour_minute_start), "utf-8");
182+
complete_post_data[0] += URLEncoder.encode(Timer.time(current.hour_minute_start), "utf-8");
183183
complete_post_data[0] += "&";
184184

185185
// off-time
186186
complete_post_data[0] += "T3" + timer + "=";
187187
if (current.hour_minute_stop == -1)
188188
complete_post_data[0] += "99:99";
189189
else
190-
complete_post_data[0] += URLEncoder.encode(current.time(current.hour_minute_stop), "utf-8");
190+
complete_post_data[0] += URLEncoder.encode(Timer.time(current.hour_minute_stop), "utf-8");
191191
complete_post_data[0] += "&";
192192

193193
if (i == 4) {
@@ -196,7 +196,7 @@ public void startElement(String uri,
196196
if (current.hour_minute_random_interval == -1)
197197
complete_post_data[0] += "99:99";
198198
else
199-
complete_post_data[0] += URLEncoder.encode(current.time(current.hour_minute_random_interval), "utf-8");
199+
complete_post_data[0] += URLEncoder.encode(Timer.time(current.hour_minute_random_interval), "utf-8");
200200
complete_post_data[0] += "&";
201201
}
202202
}

app/src/main/java/oly/netpowerctrl/data/LoadStoreIconData.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.annotation.SuppressLint;
44
import android.app.Activity;
55
import android.app.AlertDialog;
6+
import android.content.ActivityNotFoundException;
67
import android.content.Context;
78
import android.content.DialogInterface;
89
import android.content.Intent;
@@ -67,6 +68,10 @@ public static UUID uuidFromWidgetID(int widgetId) {
6768
return new UUID(0xABCD, (long) widgetId);
6869
}
6970

71+
public static UUID uuidFromDefaultWidget() {
72+
return new UUID(0xABCE, 0);
73+
}
74+
7075
public static int getResIdForState(IconState state) {
7176
switch (state) {
7277
case StateOff:
@@ -262,10 +267,14 @@ public void onClick(DialogInterface dialogInterface, int i) {
262267
PICK_IMAGE_BEFORE_KITKAT
263268
);
264269
} else {
265-
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
266-
intent.setType("image/*");
267-
intent.addCategory(Intent.CATEGORY_OPENABLE);
268-
callback.startActivityForResult(intent, PICK_IMAGE_KITKAT);
270+
try {
271+
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
272+
intent.setType("image/*");
273+
intent.addCategory(Intent.CATEGORY_OPENABLE);
274+
callback.startActivityForResult(intent, PICK_IMAGE_KITKAT);
275+
} catch (ActivityNotFoundException ignored) {
276+
Toast.makeText(context, "Cannot open file chooser", Toast.LENGTH_SHORT).show();
277+
}
269278
}
270279

271280
} else {
@@ -297,6 +306,7 @@ public static void activityCheckForPickedImage(final Context context,
297306
}
298307
}
299308

309+
300310
public static enum IconType {
301311
SceneIcon,
302312
WidgetIcon,

app/src/main/java/oly/netpowerctrl/data/LoadStoreJSonData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class LoadStoreJSonData {
2828

29-
private onStorageUpdate storageUpdate = new onStorageUpdate() {
29+
private final onStorageUpdate storageUpdate = new onStorageUpdate() {
3030
@Override
3131
public void save(CollectionWithType collection, Storable item) {
3232
File file = new File(App.instance.getDir(collection.type(), 0), item.getStorableName());

app/src/main/java/oly/netpowerctrl/data/SharedPrefs.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.os.Parcel;
99
import android.preference.PreferenceManager;
1010

11+
import java.io.File;
1112
import java.io.FileInputStream;
1213
import java.io.FileOutputStream;
1314
import java.io.IOException;
@@ -27,11 +28,12 @@ public class SharedPrefs implements SharedPreferences.OnSharedPreferenceChangeLi
2728
public final static String PREF_WIDGET_BASENAME = "oly.netpowerctrl.widget";
2829
public final static String hide_not_reachable = "hide_not_reachable";
2930
private final static int PREF_CURRENT_VERSION = 4;
31+
private final static String firstTabExtraFilename = "firstTabExtra";
3032
public final String PREF_use_dark_theme = "use_dark_theme";
3133
public final String PREF_show_persistent_notification = "show_persistent_notification";
3234
private final Context context;
33-
private WeakHashMap<IShowBackground, Boolean> observers_showBackground = new WeakHashMap<>();
34-
private WeakHashMap<IHideNotReachable, Boolean> observers_HideNotReachable = new WeakHashMap<>();
35+
private final WeakHashMap<IShowBackground, Boolean> observers_showBackground = new WeakHashMap<>();
36+
private final WeakHashMap<IHideNotReachable, Boolean> observers_HideNotReachable = new WeakHashMap<>();
3537

3638
private SharedPrefs() {
3739
this.context = App.instance;
@@ -69,9 +71,13 @@ public String getFirstTab() {
6971
}
7072

7173
public Bundle getFirstTabExtra() {
74+
File file = context.getFileStreamPath(firstTabExtraFilename);
75+
if (!file.exists())
76+
return null;
77+
7278
Parcel parcel = Parcel.obtain(); //creating empty parcel object
7379
try {
74-
FileInputStream fis = context.openFileInput("firstTabExtra");
80+
FileInputStream fis = context.openFileInput(firstTabExtraFilename);
7581
byte[] array = new byte[(int) fis.getChannel().size()];
7682
fis.read(array, 0, array.length);
7783
fis.close();
@@ -96,7 +102,7 @@ public void setFirstTab(String fragmentClassName, Bundle extra) {
96102
if (extra != null) {
97103
Parcel parcel = Parcel.obtain(); //creating empty parcel object
98104
try {
99-
FileOutputStream fos = context.openFileOutput("firstTabExtra", Context.MODE_PRIVATE);
105+
FileOutputStream fos = context.openFileOutput(firstTabExtraFilename, Context.MODE_PRIVATE);
100106
extra.writeToParcel(parcel, 0); //saving bundle as parcel
101107
fos.write(parcel.marshall()); //writing parcel to file
102108
fos.flush();
@@ -106,7 +112,8 @@ public void setFirstTab(String fragmentClassName, Bundle extra) {
106112
} finally {
107113
parcel.recycle();
108114
}
109-
115+
} else {
116+
context.deleteFile(firstTabExtraFilename);
110117
}
111118
}
112119

@@ -238,7 +245,7 @@ public boolean isPreferenceNameLogEnergySaveMode(String name) {
238245
return name.equals("use_log_energy_saving_mode");
239246
}
240247

241-
public String getVersionName(Context context) {
248+
String getVersionName(Context context) {
242249
try {
243250
Class cls = App.class;
244251
ComponentName comp = new ComponentName(context, cls);
@@ -330,6 +337,12 @@ public long getLastTimeOpenIssuesRequested() {
330337
return prefs.getLong("open_issues_last_access", -1);
331338
}
332339

340+
public boolean getSmallerClickExecuteArea() {
341+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
342+
boolean value = context.getResources().getBoolean(R.bool.smaller_click_execute_area);
343+
return prefs.getBoolean("smaller_click_execute_area", value);
344+
}
345+
333346
public void setOpenIssues(int value, long last_access) {
334347

335348
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@@ -367,6 +380,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
367380
}
368381
}
369382

383+
370384
public interface IShowBackground {
371385
void backgroundChanged(boolean showBackground);
372386
}

app/src/main/java/oly/netpowerctrl/data/Storable.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
public interface Storable {
1414
public StorableDataType getDataType();
1515

16-
;
17-
1816
public String getStorableName();
1917

2018
public void load(JsonReader reader) throws IOException, ClassNotFoundException;

app/src/main/java/oly/netpowerctrl/device_ports/DevicePortAdapterItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class DevicePortAdapterItem {
1616
// command_value instead overwriting DevicePort's value. The implementation
1717
// depends on the child class.
1818
int command_value;
19-
boolean marked_removed = false;
19+
private boolean marked_removed = false;
2020
private UUID group;
2121
private groupTypeEnum groupType = groupTypeEnum.NOGROUP_TYPE;
2222

@@ -85,7 +85,7 @@ public groupTypeEnum groupType() {
8585
return groupType;
8686
}
8787

88-
public void setGroupType(groupTypeEnum groupType) {
88+
void setGroupType(groupTypeEnum groupType) {
8989
this.groupType = groupType;
9090
}
9191

app/src/main/java/oly/netpowerctrl/device_ports/DevicePortsBaseAdapter.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@
3535
public class DevicePortsBaseAdapter extends BaseAdapter implements SortCriteriaInterface,
3636
SharedPrefs.IShowBackground {
3737

38-
protected final IconDeferredLoadingThread mIconCache;
38+
final IconDeferredLoadingThread mIconCache;
3939
final List<DevicePortAdapterItem> mItems;
4040
private final LayoutInflater mInflater;
4141
// Source of values for this adapter.
4242
private final DevicePortSource mSource;
43-
protected int mOutlet_res_id = 0;
44-
protected boolean mShowHidden = true;
45-
protected DevicePortViewHolder cViewHolder;
43+
int mOutlet_res_id = 0;
44+
boolean mShowHidden = true;
45+
DevicePortViewHolder cViewHolder;
4646
// Some observers
47-
protected ListItemMenu mListContextMenu;
47+
ListItemMenu mListContextMenu;
4848
// Animation ids
49-
protected WeakReference<AnimationController> mAnimationWeakReference = new WeakReference<>(null);
49+
WeakReference<AnimationController> mAnimationWeakReference = new WeakReference<>(null);
5050
private boolean drawShadows;
5151
private int mNextId = 0; // we need stable IDs
5252
// If you change the layout or an image we increment this layout change id
@@ -69,7 +69,7 @@ public class DevicePortsBaseAdapter extends BaseAdapter implements SortCriteriaI
6969
source.setTargetAdapter(this);
7070
}
7171
drawShadows = SharedPrefs.getInstance().isBackground();
72-
SharedPrefs.getInstance().getInstance().registerShowBackground(this);
72+
SharedPrefs.getInstance().registerShowBackground(this);
7373
}
7474

7575
@Override
@@ -264,6 +264,7 @@ public View getView(final int position, View convertView, ViewGroup parent) {
264264
port.Hidden ? Typeface.ITALIC : Typeface.NORMAL);
265265
cViewHolder.title.setText(port.getDescription());
266266
cViewHolder.title.setEnabled(item.isEnabled());
267+
267268
if (drawShadows)
268269
cViewHolder.title.setShadowLayer(4f, 0, 0, Color.WHITE);
269270

@@ -453,7 +454,7 @@ public void addItem(DevicePort devicePort, int command_value, boolean finalActio
453454
*/
454455
private boolean addItemToGroup(DevicePort devicePort, int command_value, int start_position) {
455456
boolean found = false;
456-
AnimationController a = mAnimationWeakReference.get();
457+
// AnimationController a = mAnimationWeakReference.get();
457458

458459
int destination_index = mItems.size();
459460
for (int i = start_position; i < mItems.size(); ++i) {

0 commit comments

Comments
 (0)