Java 8 migration

This commit is contained in:
TacoTheDank 2020-08-31 19:29:33 -04:00
parent 9b0a17ab0a
commit cbef592f8d
14 changed files with 97 additions and 188 deletions

View File

@ -78,12 +78,9 @@ public class GmsConnector<C extends ApiClient, R extends Result> {
final AbstractPendingResult<R> result = (AbstractPendingResult<R>) msg.obj; final AbstractPendingResult<R> result = (AbstractPendingResult<R>) msg.obj;
try { try {
C connection = (C) apiClient.getApiConnection(api); C connection = (C) apiClient.getApiConnection(api);
callback.onClientAvailable(connection, new GmsConnector.Callback.ResultProvider<R>() { callback.onClientAvailable(connection, realResult -> {
@Override result.deliverResult(realResult);
public void onResultAvailable(R realResult) { apiClient.decrementUsageCounter();
result.deliverResult(realResult);
apiClient.decrementUsageCounter();
}
}); });
} catch (RemoteException ignored) { } catch (RemoteException ignored) {

View File

@ -19,12 +19,10 @@ package org.microg.gms.common.api;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.util.Log;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.Api; import com.google.android.gms.common.api.Api;
import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient;
@ -65,16 +63,12 @@ public class GoogleApiClientImpl implements GoogleApiClient {
} }
} }
}; };
private final OnConnectionFailedListener baseConnectionFailedListener = new private final OnConnectionFailedListener baseConnectionFailedListener = result -> {
OnConnectionFailedListener() { Log.d(TAG, "OnConnectionFailedListener : onConnectionFailed()");
@Override for (OnConnectionFailedListener listener : connectionFailedListeners) {
public void onConnectionFailed(ConnectionResult result) { listener.onConnectionFailed(result);
Log.d(TAG, "OnConnectionFailedListener : onConnectionFailed()"); }
for (OnConnectionFailedListener listener : connectionFailedListeners) { };
listener.onConnectionFailed(result);
}
}
};
private int usageCounter = 0; private int usageCounter = 0;
private boolean shouldDisconnect = false; private boolean shouldDisconnect = false;

View File

@ -47,19 +47,13 @@ public abstract class AbstractDashboardActivity extends AppCompatActivity {
private void evaluateConditionAsync(final Condition condition) { private void evaluateConditionAsync(final Condition condition) {
if (condition.willBeEvaluating()) { if (condition.willBeEvaluating()) {
new Thread(new Runnable() { new Thread(() -> {
@Override if (condition.isActive(AbstractDashboardActivity.this)) {
public void run() { runOnUiThread(() -> {
if (condition.isActive(AbstractDashboardActivity.this)) { if (conditions.contains(condition) && condition.isEvaluated()) {
runOnUiThread(new Runnable() { addConditionToView(condition);
@Override }
public void run() { });
if (conditions.contains(condition) && condition.isEvaluated()) {
addConditionToView(condition);
}
}
});
}
} }
}).start(); }).start();
} }

View File

@ -108,16 +108,13 @@ public class Condition {
} }
final View detailGroup = view.findViewById(R.id.detail_group); final View detailGroup = view.findViewById(R.id.detail_group);
final ImageView expandIndicator = (ImageView) view.findViewById(R.id.expand_indicator); final ImageView expandIndicator = (ImageView) view.findViewById(R.id.expand_indicator);
View.OnClickListener expandListener = new View.OnClickListener() { View.OnClickListener expandListener = v -> {
@Override if (detailGroup.getVisibility() == View.VISIBLE) {
public void onClick(View v) { expandIndicator.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_expand_more, context.getTheme()));
if (detailGroup.getVisibility() == View.VISIBLE) { detailGroup.setVisibility(View.GONE);
expandIndicator.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_expand_more, context.getTheme())); } else {
detailGroup.setVisibility(View.GONE); expandIndicator.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_expand_less, context.getTheme()));
} else { detailGroup.setVisibility(View.VISIBLE);
expandIndicator.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_expand_less, context.getTheme()));
detailGroup.setVisibility(View.VISIBLE);
}
} }
}; };
view.findViewById(R.id.collapsed_group).setOnClickListener(expandListener); view.findViewById(R.id.collapsed_group).setOnClickListener(expandListener);

View File

@ -85,12 +85,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
mSwitch.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); mSwitch.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
} }
addOnSwitchChangeListener(new OnSwitchChangeListener() { addOnSwitchChangeListener((switchView, isChecked) -> setTextViewLabel(isChecked));
@Override
public void onSwitchChanged(SwitchCompat switchView, boolean isChecked) {
setTextViewLabel(isChecked);
}
});
setOnClickListener(this); setOnClickListener(this);

View File

@ -25,7 +25,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.util.Log; import android.util.Log;
@ -39,7 +38,6 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.mgoogle.android.gms.R; import com.mgoogle.android.gms.R;
import com.squareup.wire.Wire;
import org.microg.gms.common.PackageUtils; import org.microg.gms.common.PackageUtils;
import org.microg.gms.people.PeopleManager; import org.microg.gms.people.PeopleManager;
@ -119,18 +117,10 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity {
if (profileIcon != null) { if (profileIcon != null) {
((ImageView) findViewById(R.id.account_photo)).setImageBitmap(profileIcon); ((ImageView) findViewById(R.id.account_photo)).setImageBitmap(profileIcon);
} else { } else {
new Thread(new Runnable() { new Thread(() -> {
@Override final Bitmap profileIcon1 = PeopleManager.getOwnerAvatarBitmap(AskPermissionActivity.this, account.name, true);
public void run() { runOnUiThread(() -> ((ImageView) findViewById(R.id.account_photo)).setImageBitmap(profileIcon1));
final Bitmap profileIcon = PeopleManager.getOwnerAvatarBitmap(AskPermissionActivity.this, account.name, true);
runOnUiThread(new Runnable() {
@Override
public void run() {
((ImageView) findViewById(R.id.account_photo)).setImageBitmap(profileIcon);
}
});
}
}).start(); }).start();
} }
@ -140,18 +130,8 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity {
} else { } else {
((TextView) findViewById(R.id.title)).setText(getString(R.string.ask_service_permission_title, appLabel)); ((TextView) findViewById(R.id.title)).setText(getString(R.string.ask_service_permission_title, appLabel));
} }
findViewById(android.R.id.button1).setOnClickListener(new View.OnClickListener() { findViewById(android.R.id.button1).setOnClickListener(v -> onAllow());
@Override findViewById(android.R.id.button2).setOnClickListener(v -> onDeny());
public void onClick(View v) {
onAllow();
}
});
findViewById(android.R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onDeny();
}
});
((ListView) findViewById(R.id.permissions)).setAdapter(new PermissionAdapter()); ((ListView) findViewById(R.id.permissions)).setAdapter(new PermissionAdapter());
} }
@ -161,24 +141,21 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity {
findViewById(android.R.id.button2).setEnabled(false); findViewById(android.R.id.button2).setEnabled(false);
findViewById(R.id.progress_bar).setVisibility(VISIBLE); findViewById(R.id.progress_bar).setVisibility(VISIBLE);
findViewById(R.id.no_progress_bar).setVisibility(GONE); findViewById(R.id.no_progress_bar).setVisibility(GONE);
new Thread(new Runnable() { new Thread(() -> {
@Override try {
public void run() { AuthResponse response = authManager.requestAuth(fromAccountManager);
try { Bundle result = new Bundle();
AuthResponse response = authManager.requestAuth(fromAccountManager); result.putString(KEY_AUTHTOKEN, response.auth);
Bundle result = new Bundle(); result.putString(KEY_ACCOUNT_NAME, account.name);
result.putString(KEY_AUTHTOKEN, response.auth); result.putString(KEY_ACCOUNT_TYPE, account.type);
result.putString(KEY_ACCOUNT_NAME, account.name); result.putString(KEY_ANDROID_PACKAGE_NAME, packageName);
result.putString(KEY_ACCOUNT_TYPE, account.type); result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
result.putString(KEY_ANDROID_PACKAGE_NAME, packageName); setAccountAuthenticatorResult(result);
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true); } catch (IOException e) {
setAccountAuthenticatorResult(result); Log.w(TAG, e);
} catch (IOException e) {
Log.w(TAG, e);
}
finish();
} }
finish();
}).start(); }).start();
} }

View File

@ -23,7 +23,6 @@ import android.os.Bundle;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
@ -39,18 +38,8 @@ public abstract class AssistantActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.login_assistant); setContentView(R.layout.login_assistant);
formatTitle(); formatTitle();
findViewById(R.id.next_button).setOnClickListener(new View.OnClickListener() { findViewById(R.id.next_button).setOnClickListener(v -> onNextButtonClicked());
@Override findViewById(R.id.back_button).setOnClickListener(v -> onBackButtonClicked());
public void onClick(View v) {
onNextButtonClicked();
}
});
findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackButtonClicked();
}
});
} }
@SuppressLint("WrongViewCast") @SuppressLint("WrongViewCast")

View File

@ -307,12 +307,7 @@ public class CastMediaRouteProvider extends MediaRouteProvider {
private void publishRoutesInMainThread() { private void publishRoutesInMainThread() {
Handler mainHandler = new Handler(this.getContext().getMainLooper()); Handler mainHandler = new Handler(this.getContext().getMainLooper());
mainHandler.post(new Runnable() { mainHandler.post(this::publishRoutes);
@Override
public void run() {
publishRoutes();
}
});
} }
private void publishRoutes() { private void publishRoutes() {

View File

@ -191,14 +191,11 @@ public class HttpFormClient {
public static <T> void requestAsync(final String url, final Request request, final Class<T> tClass, public static <T> void requestAsync(final String url, final Request request, final Class<T> tClass,
final Callback<T> callback) { final Callback<T> callback) {
new Thread(new Runnable() { new Thread(() -> {
@Override try {
public void run() { callback.onResponse(request(url, request, tClass));
try { } catch (Exception e) {
callback.onResponse(request(url, request, tClass)); callback.onException(e);
} catch (Exception e) {
callback.onException(e);
}
} }
}).start(); }).start();
} }

View File

@ -117,15 +117,12 @@ public class RemoteListenerProxy<T extends IInterface> implements ServiceConnect
@Override @Override
public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable { public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable {
if (method.getDeclaringClass().equals(tClass)) { if (method.getDeclaringClass().equals(tClass)) {
runOncePossible(new Runnable() { runOncePossible(() -> {
@Override try {
public void run() { Object asInterface = Class.forName(tClass.getName() + "$Stub").getMethod("asInterface", IBinder.class).invoke(null, remote);
try { method.invoke(asInterface, args);
Object asInterface = Class.forName(tClass.getName() + "$Stub").getMethod("asInterface", IBinder.class).invoke(null, remote); } catch (Exception e) {
method.invoke(asInterface, args); Log.w(TAG, e);
} catch (Exception e) {
Log.w(TAG, e);
}
} }
}); });
connect(); connect();

View File

@ -28,19 +28,16 @@ public class UnregisterReceiver extends BroadcastReceiver {
Log.d(TAG, "Package removed or data cleared: " + packageName); Log.d(TAG, "Package removed or data cleared: " + packageName);
final GcmDatabase.App app = database.getApp(packageName); final GcmDatabase.App app = database.getApp(packageName);
if (app != null) { if (app != null) {
new Thread(new Runnable() { new Thread(() -> {
@Override List<GcmDatabase.Registration> registrations = database.getRegistrationsByApp(packageName);
public void run() { boolean deletedAll = true;
List<GcmDatabase.Registration> registrations = database.getRegistrationsByApp(packageName); for (GcmDatabase.Registration registration : registrations) {
boolean deletedAll = true; deletedAll &= PushRegisterManager.unregister(context, registration.packageName, registration.signature, null, null).deleted != null;
for (GcmDatabase.Registration registration : registrations) {
deletedAll &= PushRegisterManager.unregister(context, registration.packageName, registration.signature, null, null).deleted != null;
}
if (deletedAll) {
database.removeApp(packageName);
}
database.close();
} }
if (deletedAll) {
database.removeApp(packageName);
}
database.close();
}).start(); }).start();
} else { } else {
database.close(); database.close();

View File

@ -16,11 +16,9 @@
package org.microg.gms.people; package org.microg.gms.people;
import android.Manifest;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel; import android.os.Parcel;
@ -118,23 +116,20 @@ public class PeopleServiceImpl extends IPeopleService.Stub {
public ICancelToken loadOwnerAvatar(final IPeopleCallbacks callbacks, final String account, String pageId, int size, int flags) { public ICancelToken loadOwnerAvatar(final IPeopleCallbacks callbacks, final String account, String pageId, int size, int flags) {
Log.d(TAG, "loadOwnerAvatar: " + account + ", " + pageId + ", " + size + ", " + flags); Log.d(TAG, "loadOwnerAvatar: " + account + ", " + pageId + ", " + size + ", " + flags);
PackageUtils.assertExtendedAccess(context); PackageUtils.assertExtendedAccess(context);
final Thread thread = new Thread(new Runnable() { final Thread thread = new Thread(() -> {
@Override Bundle extras = new Bundle();
public void run() { extras.putBoolean("rewindable", false);
Bundle extras = new Bundle(); extras.putInt("width", 0);
extras.putBoolean("rewindable", false); extras.putInt("height", 0);
extras.putInt("width", 0); File avaterFile = PeopleManager.getOwnerAvaterFile(context, account, true);
extras.putInt("height", 0); try {
File avaterFile = PeopleManager.getOwnerAvaterFile(context, account, true); ParcelFileDescriptor fileDescriptor = null;
try { if (avaterFile != null) {
ParcelFileDescriptor fileDescriptor = null; fileDescriptor = ParcelFileDescriptor.open(avaterFile, ParcelFileDescriptor.MODE_READ_ONLY);
if (avaterFile != null) {
fileDescriptor = ParcelFileDescriptor.open(avaterFile, ParcelFileDescriptor.MODE_READ_ONLY);
}
callbacks.onParcelFileDescriptor(0, extras, fileDescriptor, extras);
} catch (Exception e) {
Log.w(TAG, e);
} }
callbacks.onParcelFileDescriptor(0, extras, fileDescriptor, extras);
} catch (Exception e) {
Log.w(TAG, e);
} }
}); });
thread.start(); thread.start();

View File

@ -5,7 +5,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
@ -58,30 +57,19 @@ public class AskPushPermission extends FragmentActivity {
CharSequence label = pm.getApplicationLabel(info); CharSequence label = pm.getApplicationLabel(info);
((TextView) findViewById(R.id.permission_message)).setText(Html.fromHtml("Allow <b>" + label + "</b> to register for push notifications?")); ((TextView) findViewById(R.id.permission_message)).setText(Html.fromHtml("Allow <b>" + label + "</b> to register for push notifications?"));
findViewById(R.id.permission_allow_button).setOnClickListener(new View.OnClickListener() { findViewById(R.id.permission_allow_button).setOnClickListener(v -> {
@Override if (answered) return;
public void onClick(View v) { database.noteAppKnown(packageName, true);
if (answered) return; answered = true;
database.noteAppKnown(packageName, true); new Thread(() -> PushRegisterService.registerAndReply(AskPushPermission.this, database, intent, packageName, requestId)).start();
answered = true; finish();
new Thread(new Runnable() {
@Override
public void run() {
PushRegisterService.registerAndReply(AskPushPermission.this, database, intent, packageName, requestId);
}
}).start();
finish();
}
}); });
findViewById(R.id.permission_deny_button).setOnClickListener(new View.OnClickListener() { findViewById(R.id.permission_deny_button).setOnClickListener(v -> {
@Override if (answered) return;
public void onClick(View v) { database.noteAppKnown(packageName, false);
if (answered) return; answered = true;
database.noteAppKnown(packageName, false); PushRegisterService.replyNotAvailable(AskPushPermission.this, intent, packageName, requestId);
answered = true; finish();
PushRegisterService.replyNotAvailable(AskPushPermission.this, intent, packageName, requestId);
finish();
}
}); });
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
finish(); finish();

View File

@ -55,14 +55,11 @@ public class Conditions {
return !pm.isIgnoringBatteryOptimizations(context.getPackageName()); return !pm.isIgnoringBatteryOptimizations(context.getPackageName());
} }
}) })
.firstAction(R.string.cond_gcm_bat_action, new View.OnClickListener() { .firstAction(R.string.cond_gcm_bat_action, v -> {
@Override if (SDK_INT < 23) return;
public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
if (SDK_INT < 23) return; intent.setData(Uri.parse("package:" + v.getContext().getPackageName()));
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); v.getContext().startActivity(intent);
intent.setData(Uri.parse("package:" + v.getContext().getPackageName()));
v.getContext().startActivity(intent);
}
}).build(); }).build();
} }