androidx: move to new libs

This commit is contained in:
PeratX 2019-10-10 10:09:36 +08:00
parent b7c4ff9850
commit d207a41635
13 changed files with 56 additions and 74 deletions

View File

@ -56,14 +56,15 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.percentlayout:percentlayout:1.0.0' implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha10' implementation 'com.google.android.material:material:1.1.0-beta01'
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta04' implementation 'androidx.recyclerview:recyclerview:1.1.0-beta05'
implementation "androidx.preference:preference:1.1.0"
//DNS //DNS
implementation 'org.pcap4j:pcap4j-core:1.7.6' implementation 'org.pcap4j:pcap4j-core:1.8.2'
implementation 'org.pcap4j:pcap4j-packetfactory-static:1.7.6' implementation 'org.pcap4j:pcap4j-packetfactory-static:1.8.2'
implementation 'org.minidns:minidns-client:0.3.4' implementation 'org.minidns:minidns-client:0.3.4'
implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okhttp3:okhttp:3.14.1' implementation 'com.squareup.okhttp3:okhttp:4.2.0'
//Analytics //Analytics
googleReleaseImplementation 'com.google.firebase:firebase-core:17.2.0' googleReleaseImplementation 'com.google.firebase:firebase-core:17.2.0'

View File

@ -10,8 +10,8 @@ import android.graphics.drawable.Icon;
import android.net.Uri; import android.net.Uri;
import android.net.VpnService; import android.net.VpnService;
import android.os.Build; import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import androidx.preference.PreferenceManager;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;

View File

@ -1,7 +1,5 @@
package org.itxtech.daedalus.activity; package org.itxtech.daedalus.activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
@ -9,6 +7,8 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import org.itxtech.daedalus.Daedalus; import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R; import org.itxtech.daedalus.R;
import org.itxtech.daedalus.fragment.ConfigFragment; import org.itxtech.daedalus.fragment.ConfigFragment;
@ -64,7 +64,7 @@ public class ConfigActivity extends AppCompatActivity {
toolbar.setOnMenuItemClickListener(fragment); toolbar.setOnMenuItemClickListener(fragment);
toolbar.inflateMenu(R.menu.custom_config); toolbar.inflateMenu(R.menu.custom_config);
FragmentManager manager = getFragmentManager(); FragmentManager manager = getSupportFragmentManager();
fragment.setIntent(getIntent()); fragment.setIntent(getIntent());
FragmentTransaction fragmentTransaction = manager.beginTransaction(); FragmentTransaction fragmentTransaction = manager.beginTransaction();
fragmentTransaction.replace(R.id.id_config, fragment); fragmentTransaction.replace(R.id.id_config, fragment);

View File

@ -1,7 +1,6 @@
package org.itxtech.daedalus.activity; package org.itxtech.daedalus.activity;
import android.app.Activity; import android.app.Activity;
import android.app.FragmentManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -100,8 +99,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (currentFragment == null || fragmentClass != currentFragment.getClass()) { if (currentFragment == null || fragmentClass != currentFragment.getClass()) {
try { try {
ToolbarFragment fragment = (ToolbarFragment) fragmentClass.newInstance(); ToolbarFragment fragment = (ToolbarFragment) fragmentClass.newInstance();
FragmentManager fm = getFragmentManager(); getSupportFragmentManager().beginTransaction().replace(R.id.id_content, fragment).commit();
fm.beginTransaction().replace(R.id.id_content, fragment).commit();
currentFragment = fragment; currentFragment = fragment;
} catch (Exception e) { } catch (Exception e) {
Logger.logException(e); Logger.logException(e);
@ -153,22 +151,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setTitle("觉得还不错?") .setTitle("觉得还不错?")
.setMessage("您的支持是我动力来源!\n请考虑为我买杯咖啡醒醒脑甚至其他…… ;)") .setMessage("您的支持是我动力来源!\n请考虑为我买杯咖啡醒醒脑甚至其他…… ;)")
.setPositiveButton("为我买杯咖啡", new DialogInterface.OnClickListener() { .setPositiveButton("为我买杯咖啡", (dialog, which) -> {
@Override Daedalus.donate();
public void onClick(DialogInterface dialog, int which) { new AlertDialog.Builder(MainActivity.this)
Daedalus.donate(); .setMessage("感谢您的支持!;)\n我会再接再厉")
new AlertDialog.Builder(MainActivity.this) .setPositiveButton("确认", null)
.setMessage("感谢您的支持!;)\n我会再接再厉") .show();
.setPositiveButton("确认", null)
.show();
}
})
.setNeutralButton("不再显示", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Daedalus.configurations.setActivateCounter(-1);
}
}) })
.setNeutralButton("不再显示", (dialog, which) -> Daedalus.configurations.setActivateCounter(-1))
.setNegativeButton("取消", null) .setNegativeButton("取消", null)
.show(); .show();
} }
@ -182,6 +172,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
updateMainButton(R.string.button_text_deactivate); updateMainButton(R.string.button_text_deactivate);
Daedalus.updateShortcut(getApplicationContext()); Daedalus.updateShortcut(getApplicationContext());
} }
super.onActivityResult(request, result, data);
} }
private void updateMainButton(int id) { private void updateMainButton(int id) {

View File

@ -1,8 +1,8 @@
package org.itxtech.daedalus.fragment; package org.itxtech.daedalus.fragment;
import android.content.Intent; import android.content.Intent;
import android.preference.PreferenceFragment;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.preference.PreferenceFragmentCompat;
/** /**
* Daedalus Project * Daedalus Project
@ -15,7 +15,7 @@ import androidx.appcompat.widget.Toolbar;
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
*/ */
abstract public class ConfigFragment extends PreferenceFragment implements Toolbar.OnMenuItemClickListener { abstract public class ConfigFragment extends PreferenceFragmentCompat implements Toolbar.OnMenuItemClickListener {
protected Intent intent = null; protected Intent intent = null;
public void setIntent(Intent intent) { public void setIntent(Intent intent) {

View File

@ -2,7 +2,7 @@ package org.itxtech.daedalus.fragment;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.os.Bundle; import android.os.Bundle;
import android.preference.EditTextPreference; import androidx.preference.EditTextPreference;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -29,8 +29,7 @@ public class DNSServerConfigFragment extends ConfigFragment {
private int index; private int index;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.perf_server); addPreferencesFromResource(R.xml.perf_server);
} }
@ -38,19 +37,19 @@ public class DNSServerConfigFragment extends ConfigFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState); View view = super.onCreateView(inflater, container, savedInstanceState);
EditTextPreference serverName = (EditTextPreference) findPreference("serverName"); EditTextPreference serverName = findPreference("serverName");
serverName.setOnPreferenceChangeListener((preference, newValue) -> { serverName.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue); preference.setSummary((String) newValue);
return true; return true;
}); });
EditTextPreference serverAddress = (EditTextPreference) findPreference("serverAddress"); EditTextPreference serverAddress = findPreference("serverAddress");
serverAddress.setOnPreferenceChangeListener((preference, newValue) -> { serverAddress.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue); preference.setSummary((String) newValue);
return true; return true;
}); });
EditTextPreference serverPort = (EditTextPreference) findPreference("serverPort"); EditTextPreference serverPort = findPreference("serverPort");
serverPort.setOnPreferenceChangeListener((preference, newValue) -> { serverPort.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue); preference.setSummary((String) newValue);
return true; return true;

View File

@ -2,7 +2,7 @@ package org.itxtech.daedalus.fragment;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.*; import androidx.preference.*;
import org.itxtech.daedalus.Daedalus; import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R; import org.itxtech.daedalus.R;
import org.itxtech.daedalus.activity.AppFilterActivity; import org.itxtech.daedalus.activity.AppFilterActivity;
@ -20,12 +20,10 @@ import org.itxtech.daedalus.util.server.DNSServerHelper;
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
*/ */
public class GlobalConfigFragment extends PreferenceFragment { public class GlobalConfigFragment extends PreferenceFragmentCompat {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreate(savedInstanceState);
Daedalus.getPrefs().edit() Daedalus.getPrefs().edit()
.putString("primary_server", DNSServerHelper.getPrimary()) .putString("primary_server", DNSServerHelper.getPrimary())
.putString("secondary_server", DNSServerHelper.getSecondary()) .putString("secondary_server", DNSServerHelper.getSecondary())
@ -33,7 +31,7 @@ public class GlobalConfigFragment extends PreferenceFragment {
addPreferencesFromResource(R.xml.perf_settings); addPreferencesFromResource(R.xml.perf_settings);
ListPreference primaryServer = (ListPreference) findPreference("primary_server"); ListPreference primaryServer = findPreference("primary_server");
primaryServer.setEntries(DNSServerHelper.getNames(Daedalus.getInstance())); primaryServer.setEntries(DNSServerHelper.getNames(Daedalus.getInstance()));
primaryServer.setEntryValues(DNSServerHelper.getIds()); primaryServer.setEntryValues(DNSServerHelper.getIds());
primaryServer.setSummary(DNSServerHelper.getDescription(primaryServer.getValue(), Daedalus.getInstance())); primaryServer.setSummary(DNSServerHelper.getDescription(primaryServer.getValue(), Daedalus.getInstance()));
@ -42,7 +40,7 @@ public class GlobalConfigFragment extends PreferenceFragment {
return true; return true;
}); });
ListPreference secondaryServer = (ListPreference) findPreference("secondary_server"); ListPreference secondaryServer = findPreference("secondary_server");
secondaryServer.setEntries(DNSServerHelper.getNames(Daedalus.getInstance())); secondaryServer.setEntries(DNSServerHelper.getNames(Daedalus.getInstance()));
secondaryServer.setEntryValues(DNSServerHelper.getIds()); secondaryServer.setEntryValues(DNSServerHelper.getIds());
secondaryServer.setSummary(DNSServerHelper.getDescription(secondaryServer.getValue(), Daedalus.getInstance())); secondaryServer.setSummary(DNSServerHelper.getDescription(secondaryServer.getValue(), Daedalus.getInstance()));
@ -51,21 +49,21 @@ public class GlobalConfigFragment extends PreferenceFragment {
return true; return true;
}); });
EditTextPreference testDNSServers = (EditTextPreference) findPreference("dns_test_servers"); EditTextPreference testDNSServers = findPreference("dns_test_servers");
testDNSServers.setSummary(testDNSServers.getText()); testDNSServers.setSummary(testDNSServers.getText());
testDNSServers.setOnPreferenceChangeListener((preference, newValue) -> { testDNSServers.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue); preference.setSummary((String) newValue);
return true; return true;
}); });
EditTextPreference logSize = (EditTextPreference) findPreference("settings_log_size"); EditTextPreference logSize = findPreference("settings_log_size");
logSize.setSummary(logSize.getText()); logSize.setSummary(logSize.getText());
logSize.setOnPreferenceChangeListener((preference, newValue) -> { logSize.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue); preference.setSummary((String) newValue);
return true; return true;
}); });
SwitchPreference darkTheme = (SwitchPreference) findPreference("settings_dark_theme"); SwitchPreference darkTheme = findPreference("settings_dark_theme");
darkTheme.setOnPreferenceChangeListener((preference, o) -> { darkTheme.setOnPreferenceChangeListener((preference, o) -> {
getActivity().startActivity(new Intent(Daedalus.getInstance(), MainActivity.class) getActivity().startActivity(new Intent(Daedalus.getInstance(), MainActivity.class)
.putExtra(MainActivity.LAUNCH_FRAGMENT, MainActivity.FRAGMENT_SETTINGS) .putExtra(MainActivity.LAUNCH_FRAGMENT, MainActivity.FRAGMENT_SETTINGS)
@ -73,13 +71,13 @@ public class GlobalConfigFragment extends PreferenceFragment {
return true; return true;
}); });
SwitchPreference advanced = (SwitchPreference) findPreference("settings_advanced_switch"); SwitchPreference advanced = findPreference("settings_advanced_switch");
advanced.setOnPreferenceChangeListener((preference, newValue) -> { advanced.setOnPreferenceChangeListener((preference, newValue) -> {
updateOptions((boolean) newValue, "settings_advanced"); updateOptions((boolean) newValue, "settings_advanced");
return true; return true;
}); });
SwitchPreference appFilter = (SwitchPreference) findPreference("settings_app_filter_switch"); SwitchPreference appFilter = findPreference("settings_app_filter_switch");
appFilter.setOnPreferenceChangeListener((p, w) -> { appFilter.setOnPreferenceChangeListener((p, w) -> {
updateOptions((boolean) w, "settings_app_filter"); updateOptions((boolean) w, "settings_app_filter");
return true; return true;
@ -115,7 +113,7 @@ public class GlobalConfigFragment extends PreferenceFragment {
} }
private void updateOptions(boolean checked, String pref) { private void updateOptions(boolean checked, String pref) {
PreferenceCategory category = (PreferenceCategory) findPreference(pref); PreferenceCategory category = findPreference(pref);
for (int i = 1; i < category.getPreferenceCount(); i++) { for (int i = 1; i < category.getPreferenceCount(); i++) {
Preference preference = category.getPreference(i); Preference preference = category.getPreference(i);
if (checked) { if (checked) {

View File

@ -7,8 +7,8 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.preference.EditTextPreference; import androidx.preference.EditTextPreference;
import android.preference.ListPreference; import androidx.preference.ListPreference;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -72,10 +72,8 @@ public class RuleConfigFragment extends ConfigFragment {
} }
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.perf_rule); addPreferencesFromResource(R.xml.perf_rule);
} }
@ -85,13 +83,13 @@ public class RuleConfigFragment extends ConfigFragment {
mHandler = new RuleConfigHandler().setView(view); mHandler = new RuleConfigHandler().setView(view);
final EditTextPreference ruleName = (EditTextPreference) findPreference("ruleName"); final EditTextPreference ruleName = findPreference("ruleName");
ruleName.setOnPreferenceChangeListener((preference, newValue) -> { ruleName.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue); preference.setSummary((String) newValue);
return true; return true;
}); });
final ListPreference ruleType = (ListPreference) findPreference("ruleType"); final ListPreference ruleType = findPreference("ruleType");
final String[] entries = {"Hosts", "DNSMasq"}; final String[] entries = {"Hosts", "DNSMasq"};
String[] values = {"0", "1"}; String[] values = {"0", "1"};
ruleType.setEntries(entries); ruleType.setEntries(entries);
@ -101,19 +99,19 @@ public class RuleConfigFragment extends ConfigFragment {
return true; return true;
}); });
final EditTextPreference ruleDownloadUrl = (EditTextPreference) findPreference("ruleDownloadUrl"); final EditTextPreference ruleDownloadUrl = findPreference("ruleDownloadUrl");
ruleDownloadUrl.setOnPreferenceChangeListener((preference, newValue) -> { ruleDownloadUrl.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue); preference.setSummary((String) newValue);
return true; return true;
}); });
final EditTextPreference ruleFilename = (EditTextPreference) findPreference("ruleFilename"); final EditTextPreference ruleFilename = findPreference("ruleFilename");
ruleFilename.setOnPreferenceChangeListener((preference, newValue) -> { ruleFilename.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue); preference.setSummary((String) newValue);
return true; return true;
}); });
ClickPreference ruleSync = (ClickPreference) findPreference("ruleSync"); ClickPreference ruleSync = findPreference("ruleSync");
ruleSync.setOnPreferenceClickListener(preference -> { ruleSync.setOnPreferenceClickListener(preference -> {
save(); save();
if (mThread == null) { if (mThread == null) {
@ -167,7 +165,7 @@ public class RuleConfigFragment extends ConfigFragment {
return false; return false;
}); });
ListPreference ruleImportBuildIn = (ListPreference) findPreference("ruleImportBuildIn"); ListPreference ruleImportBuildIn = findPreference("ruleImportBuildIn");
ruleImportBuildIn.setEntries(Rule.getBuildInRuleNames()); ruleImportBuildIn.setEntries(Rule.getBuildInRuleNames());
ruleImportBuildIn.setEntryValues(Rule.getBuildInRuleEntries()); ruleImportBuildIn.setEntryValues(Rule.getBuildInRuleEntries());
ruleImportBuildIn.setOnPreferenceChangeListener((preference, newValue) -> { ruleImportBuildIn.setOnPreferenceChangeListener((preference, newValue) -> {
@ -183,7 +181,7 @@ public class RuleConfigFragment extends ConfigFragment {
return true; return true;
}); });
ClickPreference ruleImportExternal = (ClickPreference) findPreference("ruleImportExternal"); ClickPreference ruleImportExternal = findPreference("ruleImportExternal");
ruleImportExternal.setOnPreferenceClickListener(preference -> { ruleImportExternal.setOnPreferenceClickListener(preference -> {
performFileSearch(); performFileSearch();
return false; return false;

View File

@ -1,7 +1,5 @@
package org.itxtech.daedalus.fragment; package org.itxtech.daedalus.fragment;
import android.app.FragmentManager;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -28,13 +26,7 @@ public class SettingsFragment extends ToolbarFragment {
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
FragmentManager fm; getChildFragmentManager().beginTransaction().replace(R.id.settings_content, new GlobalConfigFragment()).commit();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
fm = getChildFragmentManager();
} else {
fm = getFragmentManager();
}
fm.beginTransaction().replace(R.id.settings_content, new GlobalConfigFragment()).commit();
} }
@Override @Override

View File

@ -1,10 +1,10 @@
package org.itxtech.daedalus.fragment; package org.itxtech.daedalus.fragment;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.View; import android.view.View;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import com.google.android.material.navigation.NavigationView; import com.google.android.material.navigation.NavigationView;
import org.itxtech.daedalus.R; import org.itxtech.daedalus.R;

View File

@ -168,7 +168,10 @@ public class UdpProvider extends Provider {
} }
if (!(parsedPacket.getPayload() instanceof UdpPacket)) { if (!(parsedPacket.getPayload() instanceof UdpPacket)) {
Log.i(TAG, "handleDnsRequest: Discarding unknown packet type " + parsedPacket.getPayload()); try {
Log.i(TAG, "handleDnsRequest: Discarding unknown packet type " + parsedPacket.getPayload());
} catch (Exception ignored) {
}
return; return;
} }

View File

@ -1,7 +1,7 @@
package org.itxtech.daedalus.widget; package org.itxtech.daedalus.widget;
import android.content.Context; import android.content.Context;
import android.preference.ListPreference; import androidx.preference.ListPreference;
import android.util.AttributeSet; import android.util.AttributeSet;
/** /**

View File

@ -9,9 +9,9 @@ buildscript {
} }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.0' classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.google.gms:google-services:4.3.2' classpath 'com.google.gms:google-services:4.3.2'
classpath 'io.fabric.tools:gradle:1.28.1' classpath 'io.fabric.tools:gradle:1.31.0'
} }
} }