Skip to content

Commit

Permalink
Merge pull request #372 from bitmold/java8
Browse files Browse the repository at this point in the history
Update to Java 8 + Removed Legacy Code
  • Loading branch information
bitmold committed Jul 27, 2020
2 parents dc536fc + af1ab22 commit 4e425cb
Show file tree
Hide file tree
Showing 35 changed files with 379 additions and 719 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ android {
minSdkVersion 16
targetSdkVersion 29
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
aaptOptions {
cruncherEnabled = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
Expand Down Expand Up @@ -370,29 +369,26 @@ private AlertDialog showDownloadDialog() {
AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
downloadDialog.setTitle(title);
downloadDialog.setMessage(message);
downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String packageName;
if (targetApplications.contains(BS_PACKAGE)) {
// Prefer to suggest download of BS if it's anywhere in the list
packageName = BS_PACKAGE;
downloadDialog.setPositiveButton(buttonYes, (dialogInterface, i) -> {
String packageName;
if (targetApplications.contains(BS_PACKAGE)) {
// Prefer to suggest download of BS if it's anywhere in the list
packageName = BS_PACKAGE;
} else {
// Otherwise, first option:
packageName = targetApplications.get(0);
}
Uri uri = Uri.parse("market://details?id=" + packageName);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try {
if (fragment == null) {
activity.startActivity(intent);
} else {
// Otherwise, first option:
packageName = targetApplications.get(0);
}
Uri uri = Uri.parse("market://details?id=" + packageName);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try {
if (fragment == null) {
activity.startActivity(intent);
} else {
fragment.startActivity(intent);
}
} catch (ActivityNotFoundException anfe) {
// Hmm, market is not installed
Log.w(TAG, "Google Play is not installed; cannot install " + packageName);
fragment.startActivity(intent);
}
} catch (ActivityNotFoundException anfe) {
// Hmm, market is not installed
Log.w(TAG, "Google Play is not installed; cannot install " + packageName);
}
});
downloadDialog.setNegativeButton(buttonNo, null);
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/org/torproject/android/OnBootReceiver.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.torproject.android;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand All @@ -26,7 +25,6 @@ public void onReceive(Context context, Intent intent) {

private void startService (String action, Context context)
{

Intent intent = new Intent(context, OrbotService.class);
intent.setAction(action);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Expand All @@ -38,7 +36,7 @@ private void startService (String action, Context context)
}

}


}

52 changes: 1 addition & 51 deletions app/src/main/java/org/torproject/android/OrbotApp.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@

package org.torproject.android;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import androidx.core.app.NotificationCompat;

import org.torproject.android.service.OrbotConstants;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.settings.Languages;
import org.torproject.android.settings.LocaleHelper;

import java.util.Locale;


public class OrbotApp extends Application implements OrbotConstants {

private Locale locale;

@Override
public void onCreate() {
super.onCreate();
Expand All @@ -32,7 +21,6 @@ public void onCreate() {
if (!Prefs.getDefaultLocale().equals(Locale.getDefault().getLanguage())) {
Languages.setLanguage(this, Prefs.getDefaultLocale(), true);
}

}

@Override
Expand All @@ -49,42 +37,4 @@ public void onConfigurationChanged(Configuration newConfig) {
Languages.setLanguage(this, Prefs.getDefaultLocale(), true);
}


public static Languages getLanguages(Activity activity) {
return Languages.get(activity);
}


@SuppressLint("NewApi")
protected void showToolbarNotification (String shortMsg, String notifyMsg, int notifyId, int icon)
{

NotificationCompat.Builder notifyBuilder;

//Reusable code.
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(getPackageName());
PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notifyBuilder = new NotificationCompat.Builder(this)
.setContentTitle(getString(org.torproject.android.service.R.string.app_name));


notifyBuilder.setContentIntent(pendIntent);

notifyBuilder.setContentText(shortMsg);
notifyBuilder.setSmallIcon(icon);
notifyBuilder.setTicker(notifyMsg);

notifyBuilder.setOngoing(false);

notifyBuilder.setStyle(new NotificationCompat.BigTextStyle()
.bigText(notifyMsg).setBigContentTitle(getString(org.torproject.android.service.R.string.app_name)));

Notification notification = notifyBuilder.build();

notificationManager.notify(notifyId, notification);
}
}
98 changes: 20 additions & 78 deletions app/src/main/java/org/torproject/android/OrbotMainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

package org.torproject.android;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.AlertDialog;

import android.content.BroadcastReceiver;
Expand Down Expand Up @@ -35,7 +33,6 @@
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
Expand Down Expand Up @@ -294,22 +291,14 @@ private void doLayout() {
mTxtOrbotLog = findViewById(R.id.orbotLog);

lblStatus = findViewById(R.id.lblStatus);
lblStatus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDrawer.openDrawer(LOG_DRAWER_GRAVITY);
}
});
lblStatus.setOnClickListener(v -> mDrawer.openDrawer(LOG_DRAWER_GRAVITY));

lblPorts = findViewById(R.id.lblPorts);

imgStatus = findViewById(R.id.imgStatus);
imgStatus.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
toggleTor();
return true;
}
imgStatus.setOnLongClickListener(v -> {
toggleTor();
return true;
});

downloadText = findViewById(R.id.trafficDown);
Expand All @@ -320,12 +309,7 @@ public boolean onLongClick(View v) {
uploadText.setText(zero);

mBtnStart = findViewById(R.id.btnStart);
mBtnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleTor();
}
});
mBtnStart.setOnClickListener(v -> toggleTor());

mBtnVPN = findViewById(R.id.btnVPN);

Expand All @@ -337,24 +321,13 @@ public void onClick(View v) {
sendIntentToService(ACTION_START_VPN);
}

mBtnVPN.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
enableVPN(isChecked);
}
});
mBtnVPN.setOnCheckedChangeListener((buttonView, isChecked) -> enableVPN(isChecked));


mBtnBridges = findViewById(R.id.btnBridges);
mBtnBridges.setChecked(Prefs.bridgesEnabled());
mBtnBridges.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
promptSetupBridges(); //if ARM processor, show all bridge options
}


mBtnBridges.setOnClickListener(v -> {
promptSetupBridges(); //if ARM processor, show all bridge options
});

spnCountries = findViewById(R.id.spinnerCountry);
Expand Down Expand Up @@ -700,16 +673,13 @@ private synchronized void handleIntents() {
final Boolean authCookie = intent.getBooleanExtra("hs_auth_cookie", false);
final Uri mKeyUri = intent.getData();

DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
enableHiddenServicePort(
hiddenServiceName, hiddenServicePort,
hiddenServiceRemotePort, backupToPackage,
mKeyUri, authCookie
);
}
DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
if (which == DialogInterface.BUTTON_POSITIVE) {
enableHiddenServicePort(
hiddenServiceName, hiddenServicePort,
hiddenServiceRemotePort, backupToPackage,
mKeyUri, authCookie
);
}
};

Expand Down Expand Up @@ -817,13 +787,10 @@ protected void onActivityResult(int request, int response, Intent data) {
finish();

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 100ms
startActivity(new Intent(OrbotMainActivity.this, OrbotMainActivity.class));
handler.postDelayed(() -> {
//Do something after 100ms
startActivity(new Intent(OrbotMainActivity.this, OrbotMainActivity.class));

}
}, 1000);


Expand Down Expand Up @@ -1073,20 +1040,6 @@ private void requestTorStatus() {
sendIntentToService(TorServiceConstants.ACTION_STATUS);
}

private boolean isTorServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

if (manager != null) {
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (OrbotService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
}

return false;
}


// this is what takes messages or values from the callback threads or other non-mainUI threads
//and passes them back into the main UI thread for display to the user
Expand Down Expand Up @@ -1228,12 +1181,7 @@ private void addAppShortcuts() {
iv.setLayoutParams(params);
iv.setImageDrawable(pMgr.getApplicationIcon(pkgId));

iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openBrowser(URL_TOR_CHECK, false, pkgId);
}
});
iv.setOnClickListener(v -> openBrowser(URL_TOR_CHECK, false, pkgId));

llBoxShortcuts.addView(iv);
appsAdded++;
Expand Down Expand Up @@ -1264,13 +1212,7 @@ public void onClick(View v) {
iv.setLayoutParams(params);
iv.setImageDrawable(getResources().getDrawable(R.drawable.ic_settings_white_24dp));
llBoxShortcuts.addView(iv);
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(OrbotMainActivity.this, AppManagerActivity.class), REQUEST_VPN_APPS_SELECT);

}
});
iv.setOnClickListener(v -> startActivityForResult(new Intent(OrbotMainActivity.this, AppManagerActivity.class), REQUEST_VPN_APPS_SELECT));
}

}
Expand Down
18 changes: 0 additions & 18 deletions app/src/main/java/org/torproject/android/settings/Languages.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
Expand All @@ -19,7 +18,6 @@
import java.util.TreeMap;

public class Languages {
public static final String TAG = "Languages";

public static Locale defaultLocale;
public static final Locale TIBETAN = new Locale("bo");
Expand Down Expand Up @@ -175,22 +173,6 @@ private static void setLocale(final ContextWrapper contextWrapper, Locale locale
}
}

/**
* Force reload the {@link Activity to make language changes take effect.}
*
* @param activity the {@code Activity} to force reload
*/
public static void forceChangeLanguage(Activity activity) {
Intent intent = activity.getIntent();
if (intent == null) // when launched as LAUNCHER
return;
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
activity.finish();
activity.overridePendingTransition(0, 0);
activity.startActivity(intent);
activity.overridePendingTransition(0, 0);
}

/**
* Return an array of the names of all the supported languages, sorted to
* match what is returned by {@link Languages#getSupportedLocales()}.
Expand Down

0 comments on commit 4e425cb

Please sign in to comment.