0
0
Fork 0
mirror of https://github.com/YTVanced/VancedMicroG synced 2024-11-24 04:05:13 +00:00

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;
try {
C connection = (C) apiClient.getApiConnection(api);
callback.onClientAvailable(connection, new GmsConnector.Callback.ResultProvider<R>() {
@Override
public void onResultAvailable(R realResult) {
result.deliverResult(realResult);
apiClient.decrementUsageCounter();
}
callback.onClientAvailable(connection, realResult -> {
result.deliverResult(realResult);
apiClient.decrementUsageCounter();
});
} catch (RemoteException ignored) {

View file

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

View file

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

View file

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

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

View file

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

View file

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

View file

@ -307,12 +307,7 @@ public class CastMediaRouteProvider extends MediaRouteProvider {
private void publishRoutesInMainThread() {
Handler mainHandler = new Handler(this.getContext().getMainLooper());
mainHandler.post(new Runnable() {
@Override
public void run() {
publishRoutes();
}
});
mainHandler.post(this::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,
final Callback<T> callback) {
new Thread(new Runnable() {
@Override
public void run() {
try {
callback.onResponse(request(url, request, tClass));
} catch (Exception e) {
callback.onException(e);
}
new Thread(() -> {
try {
callback.onResponse(request(url, request, tClass));
} catch (Exception e) {
callback.onException(e);
}
}).start();
}

View file

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

View file

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

View file

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

View file

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

View file

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