Skip to content

Commit 3fe7585

Browse files
committed
设置模块从android.preference迁移至androidx.preference
1 parent 1ae996e commit 3fe7585

36 files changed

+688
-587
lines changed

app/build.gradle

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ dependencies {
119119

120120
// Add the dependencies for the Crashlytics and Analytics libraries
121121
// When using the BoM, you don't specify versions in Firebase library dependencies
122-
// implementation 'com.google.firebase:firebase-crashlytics'
123-
// implementation 'com.google.firebase:firebase-analytics'
124122
implementation 'com.google.firebase:firebase-crashlytics:19.2.1'
125123
implementation 'com.google.firebase:firebase-analytics:22.1.2'
126124
// implementation 'com.google.firebase:firebase-analytics:21.5.1'
@@ -132,7 +130,7 @@ dependencies {
132130
implementation "androidx.browser:browser:1.3.0"
133131
implementation 'androidx.cardview:cardview:1.0.0'
134132
implementation "androidx.fragment:fragment:1.8.5"
135-
implementation "androidx.preference:preference:1.2.1"
133+
implementation "androidx.preference:preference-ktx:1.2.1"
136134
implementation 'androidx.recyclerview:recyclerview:1.2.0'
137135
implementation 'org.conscrypt:conscrypt-android:2.5.1'
138136
// https://mvnrepository.com/artifact/androidx.core/core-ktx
@@ -146,9 +144,6 @@ dependencies {
146144
implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
147145
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
148146
implementation 'com.alibaba:fastjson:1.2.83'
149-
// implementation 'com.takisoft.preferencex:preferencex:1.1.0'
150-
// implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.1.0'
151-
// implementation 'com.alibaba.fastjson2:fastjson2:2.0.47'
152147

153148
implementation 'com.android.support:multidex:1.0.3'
154149
// implementation 'com.github.bumptech.glide:glide:4.16.0'

app/src/main/java/com/hippo/app/AppCompatPreferenceActivity.java

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
import androidx.core.app.NavUtils;
4848
import androidx.core.app.TaskStackBuilder;
4949

50-
public abstract class AppCompatPreferenceActivity extends PreferenceActivity implements AppCompatCallback,
50+
import com.hippo.ehviewer.ui.EhActivity;
51+
52+
public abstract class AppCompatPreferenceActivity extends EhActivity implements AppCompatCallback,
5153
TaskStackBuilder.SupportParentable, ActionBarDrawerToggle.DelegateProvider {
5254

5355
private AppCompatDelegate mDelegate;
@@ -64,11 +66,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6466
// the changes to take effect. On API 23+, we should bypass
6567
// setTheme(), which will no-op if the theme ID is identical to the
6668
// current theme ID.
67-
if (Build.VERSION.SDK_INT >= 23) {
68-
onApplyThemeResource(getTheme(), mThemeId, false);
69-
} else {
70-
setTheme(mThemeId);
71-
}
69+
onApplyThemeResource(getTheme(), mThemeId, false);
7270
}
7371
super.onCreate(savedInstanceState);
7472
}
@@ -179,19 +177,19 @@ public <T extends View> T findViewById(@IdRes int id) {
179177
return getDelegate().findViewById(id);
180178
}
181179

182-
@Override
183-
public final boolean onMenuItemSelected(int featureId, android.view.MenuItem item) {
184-
if (super.onMenuItemSelected(featureId, item)) {
185-
return true;
186-
}
187-
188-
final ActionBar ab = getSupportActionBar();
189-
if (item.getItemId() == android.R.id.home && ab != null &&
190-
(ab.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
191-
return onSupportNavigateUp();
192-
}
193-
return false;
194-
}
180+
// @Override
181+
// public final boolean onMenuItemSelected(int featureId, android.view.MenuItem item) {
182+
// if (super.onMenuItemSelected(featureId, item)) {
183+
// return true;
184+
// }
185+
//
186+
// final ActionBar ab = getSupportActionBar();
187+
// if (item.getItemId() == android.R.id.home && ab != null &&
188+
// (ab.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
189+
// return onSupportNavigateUp();
190+
// }
191+
// return false;
192+
// }
195193

196194
@Override
197195
protected void onDestroy() {
@@ -232,27 +230,27 @@ public void invalidateOptionsMenu() {
232230
getDelegate().invalidateOptionsMenu();
233231
}
234232

235-
/**
236-
* Notifies the Activity that a support action mode has been started.
237-
* Activity subclasses overriding this method should call the superclass implementation.
238-
*
239-
* @param mode The new action mode.
240-
*/
241-
@Override
242-
@CallSuper
243-
public void onSupportActionModeStarted(@NonNull ActionMode mode) {
244-
}
245-
246-
/**
247-
* Notifies the activity that a support action mode has finished.
248-
* Activity subclasses overriding this method should call the superclass implementation.
249-
*
250-
* @param mode The action mode that just finished.
251-
*/
252-
@Override
253-
@CallSuper
254-
public void onSupportActionModeFinished(@NonNull ActionMode mode) {
255-
}
233+
// /**
234+
// * Notifies the Activity that a support action mode has been started.
235+
// * Activity subclasses overriding this method should call the superclass implementation.
236+
// *
237+
// * @param mode The new action mode.
238+
// */
239+
// @Override
240+
// @CallSuper
241+
// public void onSupportActionModeStarted(@NonNull ActionMode mode) {
242+
// }
243+
244+
// /**
245+
// * Notifies the activity that a support action mode has finished.
246+
// * Activity subclasses overriding this method should call the superclass implementation.
247+
// *
248+
// * @param mode The action mode that just finished.
249+
// */
250+
// @Override
251+
// @CallSuper
252+
// public void onSupportActionModeFinished(@NonNull ActionMode mode) {
253+
// }
256254

257255
/**
258256
* Called when a support action mode is being started for this window. Gives the

app/src/main/java/com/hippo/app/CheckBoxDialogBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public CheckBoxDialogBuilder(Context context, String message, String checkText,
3434
super(context);
3535
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_checkbox_builder, null);
3636
setView(view);
37-
TextView messageView = (TextView) view.findViewById(R.id.message);
38-
mCheckBox = (CheckBox) view.findViewById(R.id.checkbox);
37+
TextView messageView = view.findViewById(R.id.message);
38+
mCheckBox = view.findViewById(R.id.checkbox);
3939
messageView.setText(message);
4040
mCheckBox.setText(checkText);
4141
mCheckBox.setChecked(checked);

app/src/main/java/com/hippo/app/EditTextDialogBuilder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import android.widget.Button;
2626
import android.widget.EditText;
2727
import android.widget.TextView;
28+
29+
import androidx.annotation.NonNull;
2830
import androidx.appcompat.app.AlertDialog;
2931
import com.google.android.material.textfield.TextInputLayout;
3032
import com.hippo.ehviewer.R;
@@ -41,7 +43,7 @@ public EditTextDialogBuilder(Context context, String text, String hint) {
4143
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_edittext_builder, null);
4244
setView(view);
4345
mTextInputLayout = (TextInputLayout) view;
44-
mEditText = (EditText) view.findViewById(R.id.edit_text);
46+
mEditText = view.findViewById(R.id.edit_text);
4547
mEditText.setText(text);
4648
mEditText.setSelection(mEditText.getText().length());
4749
mEditText.setOnEditorActionListener(this);
@@ -60,6 +62,7 @@ public void setError(CharSequence error) {
6062
mTextInputLayout.setError(error);
6163
}
6264

65+
@NonNull
6366
@Override
6467
public AlertDialog create() {
6568
mDialog = super.create();
Lines changed: 112 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,112 @@
1-
/*
2-
* Copyright 2018 Hippo Seven
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
17-
package com.hippo.app;
18-
19-
import android.content.Context;
20-
import android.preference.PreferenceActivity;
21-
import android.text.TextUtils;
22-
import android.view.LayoutInflater;
23-
import android.view.View;
24-
import android.view.ViewGroup;
25-
import android.widget.ArrayAdapter;
26-
import android.widget.ImageView;
27-
import android.widget.ListAdapter;
28-
import android.widget.TextView;
29-
import androidx.annotation.NonNull;
30-
import com.hippo.ehviewer.R;
31-
import java.util.ArrayList;
32-
import java.util.List;
33-
34-
public abstract class PrettyPreferenceActivity extends AppCompatPreferenceActivity {
35-
36-
@Override
37-
public void setListAdapter(ListAdapter adapter) {
38-
if (adapter == null) {
39-
super.setListAdapter(null);
40-
return;
41-
}
42-
43-
int count = adapter.getCount();
44-
List<Header> headers = new ArrayList<>(count);
45-
for (int i = 0; i < count; ++i) {
46-
headers.add((Header) adapter.getItem(i));
47-
}
48-
49-
super.setListAdapter(new HeaderAdapter(this, headers, R.layout.item_preference_header, true));
50-
}
51-
52-
private static class HeaderAdapter extends ArrayAdapter<Header> {
53-
private static class HeaderViewHolder {
54-
ImageView icon;
55-
TextView title;
56-
TextView summary;
57-
}
58-
59-
private LayoutInflater mInflater;
60-
private int mLayoutResId;
61-
private boolean mRemoveIconIfEmpty;
62-
63-
private HeaderAdapter(Context context, List<Header> objects, int layoutResId,
64-
boolean removeIconBehavior) {
65-
super(context, 0, objects);
66-
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
67-
mLayoutResId = layoutResId;
68-
mRemoveIconIfEmpty = removeIconBehavior;
69-
}
70-
71-
@NonNull
72-
@Override
73-
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
74-
HeaderViewHolder holder;
75-
View view;
76-
77-
if (convertView == null) {
78-
view = mInflater.inflate(mLayoutResId, parent, false);
79-
holder = new HeaderViewHolder();
80-
holder.icon = view.findViewById(android.R.id.icon);
81-
holder.title = view.findViewById(android.R.id.title);
82-
holder.summary = view.findViewById(android.R.id.summary);
83-
view.setTag(holder);
84-
} else {
85-
view = convertView;
86-
holder = (HeaderViewHolder) view.getTag();
87-
}
88-
89-
// All view fields must be updated every time, because the view may be recycled
90-
Header header = getItem(position);
91-
if (mRemoveIconIfEmpty) {
92-
if (header.iconRes == 0) {
93-
holder.icon.setVisibility(View.GONE);
94-
} else {
95-
holder.icon.setVisibility(View.VISIBLE);
96-
holder.icon.setImageResource(header.iconRes);
97-
}
98-
} else {
99-
holder.icon.setImageResource(header.iconRes);
100-
}
101-
holder.title.setText(header.getTitle(getContext().getResources()));
102-
CharSequence summary = header.getSummary(getContext().getResources());
103-
if (!TextUtils.isEmpty(summary)) {
104-
holder.summary.setVisibility(View.VISIBLE);
105-
holder.summary.setText(summary);
106-
} else {
107-
holder.summary.setVisibility(View.GONE);
108-
}
109-
110-
return view;
111-
}
112-
}
113-
}
1+
///*
2+
// * Copyright 2018 Hippo Seven
3+
// *
4+
// * Licensed under the Apache License, Version 2.0 (the "License");
5+
// * you may not use this file except in compliance with the License.
6+
// * You may obtain a copy of the License at
7+
// *
8+
// * http://www.apache.org/licenses/LICENSE-2.0
9+
// *
10+
// * Unless required by applicable law or agreed to in writing, software
11+
// * distributed under the License is distributed on an "AS IS" BASIS,
12+
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// * See the License for the specific language governing permissions and
14+
// * limitations under the License.
15+
// */
16+
//
17+
//package com.hippo.app;
18+
//
19+
//import android.content.Context;
20+
//import android.text.TextUtils;
21+
//import android.view.LayoutInflater;
22+
//import android.view.View;
23+
//import android.view.ViewGroup;
24+
//import android.widget.ArrayAdapter;
25+
//import android.widget.ImageView;
26+
//import android.widget.ListAdapter;
27+
//import android.widget.TextView;
28+
//import androidx.annotation.NonNull;
29+
//import com.hippo.ehviewer.R;
30+
//import java.util.ArrayList;
31+
//import java.util.List;
32+
//
33+
//public abstract class PrettyPreferenceActivity extends AppCompatPreferenceActivity {
34+
//
35+
// @Override
36+
// public void setListAdapter(ListAdapter adapter) {
37+
// if (adapter == null) {
38+
// super.setListAdapter(null);
39+
// return;
40+
// }
41+
//
42+
// int count = adapter.getCount();
43+
// List<Header> headers = new ArrayList<>(count);
44+
// for (int i = 0; i < count; ++i) {
45+
// headers.add((Header) adapter.getItem(i));
46+
// }
47+
//
48+
// super.setListAdapter(new HeaderAdapter(this, headers, R.layout.item_preference_header, true));
49+
// }
50+
//
51+
// private static class HeaderAdapter extends ArrayAdapter<Header> {
52+
// private static class HeaderViewHolder {
53+
// ImageView icon;
54+
// TextView title;
55+
// TextView summary;
56+
// }
57+
//
58+
// private LayoutInflater mInflater;
59+
// private int mLayoutResId;
60+
// private boolean mRemoveIconIfEmpty;
61+
//
62+
// private HeaderAdapter(Context context, List<Header> objects, int layoutResId,
63+
// boolean removeIconBehavior) {
64+
// super(context, 0, objects);
65+
// mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
66+
// mLayoutResId = layoutResId;
67+
// mRemoveIconIfEmpty = removeIconBehavior;
68+
// }
69+
//
70+
// @NonNull
71+
// @Override
72+
// public View getView(int position, View convertView, @NonNull ViewGroup parent) {
73+
// HeaderViewHolder holder;
74+
// View view;
75+
//
76+
// if (convertView == null) {
77+
// view = mInflater.inflate(mLayoutResId, parent, false);
78+
// holder = new HeaderViewHolder();
79+
// holder.icon = view.findViewById(android.R.id.icon);
80+
// holder.title = view.findViewById(android.R.id.title);
81+
// holder.summary = view.findViewById(android.R.id.summary);
82+
// view.setTag(holder);
83+
// } else {
84+
// view = convertView;
85+
// holder = (HeaderViewHolder) view.getTag();
86+
// }
87+
//
88+
// // All view fields must be updated every time, because the view may be recycled
89+
// Header header = getItem(position);
90+
// if (mRemoveIconIfEmpty) {
91+
// if (header.iconRes == 0) {
92+
// holder.icon.setVisibility(View.GONE);
93+
// } else {
94+
// holder.icon.setVisibility(View.VISIBLE);
95+
// holder.icon.setImageResource(header.iconRes);
96+
// }
97+
// } else {
98+
// holder.icon.setImageResource(header.iconRes);
99+
// }
100+
// holder.title.setText(header.getTitle(getContext().getResources()));
101+
// CharSequence summary = header.getSummary(getContext().getResources());
102+
// if (!TextUtils.isEmpty(summary)) {
103+
// holder.summary.setVisibility(View.VISIBLE);
104+
// holder.summary.setText(summary);
105+
// } else {
106+
// holder.summary.setVisibility(View.GONE);
107+
// }
108+
//
109+
// return view;
110+
// }
111+
// }
112+
//}

0 commit comments

Comments
 (0)