Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Use Java 8 #73

Merged
merged 1 commit into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}

dependencies {
Expand Down
30 changes: 13 additions & 17 deletions app/src/main/java/ch/fixme/status/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,17 @@ private AlertDialog createHsDialog() {
.findViewById(R.id.listview);
listView.setAdapter(adapter);
listView.setFastScrollEnabled(true);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Log.d(TAG, "hs dialog, on click");
String url = mHsUrls.get(position);
Editor edit = mPrefs.edit();
edit.putString(Prefs.KEY_API_URL, url);
getApiTask = new GetApiTask();
getApiTask.execute(url);
edit.commit();
setIntent(null);
dismissDialog(DIALOG_LIST);
Log.i(TAG, "Item clicked=" + url + " (" + position + ")");
}
listView.setOnItemClickListener((parent, view1, position, id) -> {
Log.d(TAG, "hs dialog, on click");
String url = mHsUrls.get(position);
Editor edit = mPrefs.edit();
edit.putString(Prefs.KEY_API_URL, url);
getApiTask = new GetApiTask();
getApiTask.execute(url);
edit.commit();
setIntent(null);
dismissDialog(DIALOG_LIST);
Log.i(TAG, "Item clicked=" + url + " (" + position + ")");
});
builder.setView(view);
builder.setTitle(R.string.choose_hs);
Expand Down Expand Up @@ -826,8 +822,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.hs_entry, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.text1);
holder.desc = (TextView) convertView.findViewById(R.id.text2);
holder.name = convertView.findViewById(R.id.text1);
holder.desc = convertView.findViewById(R.id.text2);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
Expand Down
17 changes: 7 additions & 10 deletions app/src/main/java/ch/fixme/status/Parse12.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,17 @@ protected HashMap<String, Object> parse() throws JSONException {
if (!mApi.isNull(API_SENSORS)) {
JSONArray sensors = mApi.getJSONArray(API_SENSORS);
JSONObject elem;
HashMap<String, ArrayList<HashMap<String, String>>> result = new HashMap<String, ArrayList<HashMap<String, String>>>(
sensors.length());
HashMap<String, ArrayList<HashMap<String, String>>> result = new HashMap<>(sensors.length());
for (int i = 0; i < sensors.length(); i++) {
elem = (JSONObject) sensors.get(i);
try {
for (int j = 0; j < elem.length(); j++) {
ArrayList<HashMap<String, String>> elem_value = new ArrayList<HashMap<String, String>>();
ArrayList<HashMap<String, String>> elem_value = new ArrayList<>();
String name = (String) elem.names().get(j);
JSONObject obj = elem.getJSONObject(name);
for (int k = 0; k < obj.length(); k++) {
String name2 = (String) obj.names().get(k);
HashMap<String, String> elem_value_map = new HashMap<String, String>();
HashMap<String, String> elem_value_map = new HashMap<>();
elem_value_map.put(API_SENSOR_NAME, name2);
elem_value_map.put(API_SENSOR_VALUE, obj.getString(name2));
elem_value.add(elem_value_map);
Expand All @@ -108,8 +107,8 @@ protected HashMap<String, Object> parse() throws JSONException {
} catch (Exception e) {
Log.e(Main.TAG, e.getLocalizedMessage());
e.printStackTrace();
ArrayList<HashMap<String, String>> elem_value = new ArrayList<HashMap<String, String>>();
HashMap<String, String> elem_value_map = new HashMap<String, String>();
ArrayList<HashMap<String, String>> elem_value = new ArrayList<>();
HashMap<String, String> elem_value_map = new HashMap<>();
elem_value_map.put(API_SENSOR_VALUE, elem.toString());
elem_value.add(elem_value_map);
result.put((String) elem.names().get(0), elem_value);
Expand All @@ -123,8 +122,7 @@ protected HashMap<String, Object> parse() throws JSONException {
if (!mApi.isNull(API_STREAM)) {
JSONObject stream = mApi.optJSONObject(API_STREAM);
if (stream != null) {
HashMap<String, String> streamMap = new HashMap<String, String>(
stream.length());
HashMap<String, String> streamMap = new HashMap<>(stream.length());
JSONArray names = stream.names();
for (int i = 0; i < stream.length(); i++) {
final String type = names.getString(i);
Expand All @@ -138,8 +136,7 @@ protected HashMap<String, Object> parse() throws JSONException {
if (!mApi.isNull(API_CAM)) {
JSONArray cam = mApi.optJSONArray(API_CAM);
if (cam != null) {
HashMap<String, String> camMap = new HashMap<String, String>(
cam.length());
HashMap<String, String> camMap = new HashMap<>(cam.length());
for (int i = 0; i < cam.length(); i++) {
camMap.put("http", cam.getString(i));
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/ch/fixme/status/Parse13.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ protected HashMap<String, Object> parse() throws JSONException {
continue;
}
elem = sensors.getJSONArray(sensor_name);
elem_value = new ArrayList<HashMap<String, String>>(elem.length());
elem_value = new ArrayList<>(elem.length());
for (int j = 0; j < elem.length(); j++) {
HashMap<String, String> elem_value_map = new HashMap<String, String>();
HashMap<String, String> elem_value_map = new HashMap<>();
try {
JSONObject obj = (JSONObject) elem.get(j);
if (!obj.isNull(API_SENSOR_VALUE)
Expand Down Expand Up @@ -185,7 +185,7 @@ protected HashMap<String, Object> parse() throws JSONException {
if (!mApi.isNull(API_STREAM)) {
JSONObject stream = mApi.optJSONObject(API_STREAM);
if (stream != null) {
HashMap<String, String> streamMap = new HashMap<String, String>(
HashMap<String, String> streamMap = new HashMap<>(
stream.length());
JSONArray names = stream.names();
for (int i = 0; i < stream.length(); i++) {
Expand All @@ -201,7 +201,7 @@ protected HashMap<String, Object> parse() throws JSONException {
if (!mApi.isNull(API_CAM)) {
JSONArray cam = mApi.optJSONArray(API_CAM);
if (cam != null) {
ArrayList<String> camList = new ArrayList<String>(cam.length());
ArrayList<String> camList = new ArrayList<>(cam.length());
for (int i = 0; i < cam.length(); i++) {
camList.add(cam.getString(i));
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ch/fixme/status/ParseGeneric.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.HashMap;

public class ParseGeneric {
protected HashMap<String, Object> mResult = new HashMap<String, Object>();
protected HashMap<String, Object> mResult = new HashMap<>();
protected JSONObject mApi;

protected static final String API_NAME = "space";
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/java/ch/fixme/status/Widget.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,8 @@ protected void onHandleIntent(Intent intent) {
+ widgetId, ParseGeneric.API_DEFAULT);
Log.i(TAG, "Update widgetid " + widgetId + " with url "
+ url);
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
new GetApiTask(ctxt, widgetId).execute(url);
}
});
new Handler(Looper.getMainLooper())
.post(() -> new GetApiTask(ctxt, widgetId).execute(url));
}
stopSelf();
}
Expand Down
31 changes: 14 additions & 17 deletions app/src/main/java/ch/fixme/status/Widget_config.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,19 @@ public void onCreate(Bundle savedInstanceState) {
Bundle extras = intent.getExtras();
mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
findViewById(R.id.choose_ok).setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
Editor edit = mPrefs.edit();
edit.putBoolean(
Prefs.KEY_WIDGET_TRANSPARENCY,
((CheckBox) findViewById(R.id.choose_transparency))
.isChecked());
edit.putBoolean(Prefs.KEY_WIDGET_TEXT,
((CheckBox) findViewById(R.id.choose_text))
.isChecked());
edit.commit();
setWidgetAlarm();
finish();
}
});
findViewById(R.id.choose_ok).setOnClickListener(v -> {
Editor edit = mPrefs.edit();
edit.putBoolean(
Prefs.KEY_WIDGET_TRANSPARENCY,
((CheckBox) findViewById(R.id.choose_transparency))
.isChecked());
edit.putBoolean(Prefs.KEY_WIDGET_TEXT,
((CheckBox) findViewById(R.id.choose_text))
.isChecked());
edit.commit();
setWidgetAlarm();
finish();
});
((CheckBox) findViewById(R.id.choose_transparency)).setChecked(mPrefs
.getBoolean(Prefs.KEY_WIDGET_TRANSPARENCY,
Prefs.DEFAULT_WIDGET_TRANSPARENCY));
Expand Down Expand Up @@ -149,7 +146,7 @@ protected void onPostExecute(String result) {
JSONArray arr = obj.names();
int len = obj.length();
String[] names = new String[len];
final ArrayList<String> url = new ArrayList<String>(len);
final ArrayList<String> url = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
names[i] = arr.getString(i);
}
Expand Down