Reduce use of internal resources

This commit is contained in:
khanhduytran0 2020-11-20 15:13:02 +07:00
parent 9f73f983cb
commit 25e5d0f412
2 changed files with 33 additions and 48 deletions

View File

@ -33,7 +33,6 @@ import android.support.v7.app.*;
import android.content.res.*;
public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListener {
private final int POPUP_TEXT_LAYOUT = getInternalId("layout", "text_edit_action_popup_text");
private TextView mEditTextView;
private TextView mDeleteTextView;
@ -41,50 +40,9 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
super(handleView);
}
private int getInternalId(String type, String name) {
/*
int id = Resources.getSystem().getIdentifier(name, type, "com.android.internal");
if (id == 0) {
mHandleView.getContext().getResources().getIdentifier(name, type, "android");
}
return id;
*/
try {
for (Class perType : Class.forName("com.android.internal.R").getDeclaredClasses()) {
if (perType.getSimpleName().equals(type)) {
try {
Field f = perType.getDeclaredField(name);
f.setAccessible(true);
return (int) f.get(null);
} catch (Throwable th) {
th.printStackTrace();
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
// If unable to find in com.android.internal.R, go find in android.R
for (Class perType : android.R.class.getDeclaredClasses()) {
if (perType.getSimpleName().equals(type)) {
try {
Field f = perType.getDeclaredField(name);
f.setAccessible(true);
return (int) f.get(null);
} catch (Throwable th) {
th.printStackTrace();
}
}
}
return -1;
}
@Override
protected void createPopupWindow() {
mPopupWindow = new PopupWindow(mHandleView.getContext(), null, getInternalId("attr", "textSelectHandleWindowStyle"));
mPopupWindow = new PopupWindow(mHandleView.getContext(), null, android.R.attr.textSelectHandleWindowStyle);
mPopupWindow.setClippingEnabled(true);
}
@ -93,7 +51,7 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
LinearLayout linearLayout = new LinearLayout(mHandleView.getContext());
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
mContentView = linearLayout;
mContentView.setBackgroundResource(getInternalId("drawable", "text_edit_paste_window"));
mContentView.setBackgroundResource(Resources.getSystem().getIdentifier("text_edit_paste_window", "drawable", "com.android.internal"));
LayoutInflater inflater = (LayoutInflater) mHandleView.getContext().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@ -101,16 +59,16 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
LayoutParams wrapContent = new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mEditTextView = (TextView) inflater.inflate(POPUP_TEXT_LAYOUT, null);
mEditTextView = (TextView) inflater.inflate(R.layout.control_action_popup_text, null);
mEditTextView.setLayoutParams(wrapContent);
mContentView.addView(mEditTextView);
mEditTextView.setText(R.string.global_edit);
mEditTextView.setOnClickListener(this);
mDeleteTextView = (TextView) inflater.inflate(POPUP_TEXT_LAYOUT, null);
mDeleteTextView = (TextView) inflater.inflate(R.layout.control_action_popup_text, null);
mDeleteTextView.setLayoutParams(wrapContent);
mContentView.addView(mDeleteTextView);
mDeleteTextView.setText(getInternalId("string", "delete"));
mDeleteTextView.setText(Resources.getSystem().getIdentifier("delete", "string", "com.android.internal"));
mDeleteTextView.setOnClickListener(this);
}
@ -232,7 +190,7 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
dialog.show();
} else if (view == mDeleteTextView) {
alert.setMessage(view.getResources().getString(getInternalId("string", "delete")) + " " + mHandleView.mView.getText() + "?");
alert.setMessage(Resources.getSystem().getIdentifier("delete", "string", "com.android.internal") + " " + mHandleView.mView.getText() + "?");
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
@Override

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="16dip"
android:paddingEnd="16dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceSmallInverse"
android:textColor="@android:color/black"
android:textAllCaps="true"
android:textStyle="bold"
/>