阅读:11827回复:6

修改系统framework里面的Dialog

楼主#
更多 发布于:2021-10-12 09:38
 系统平台 RK3288 Android9.0

 用户使用系统wifi直连p2p时会弹出一个系统Dialog,用户希望修改这个Dialog保持和他们的Launcher风格一致,用户有提供了Dialog布局,图片,焦点样式,资源文件包括:layout,color,string, style,drawable,slector,shape等一系列文件,甚至还有一个自定义的字体文件,后缀为ttf的。怎样把这些资源文件加到fraemwork里面呢?经过我的一番检索和自己摸索,不断试错,最后成功都加进去了,做出了用户想要的效果,具体修改如下:
frameworks/base/core/res/res/values/colors.xml

+
+    <color name="unselect_grey">#59a0a0a0</color>
+    <color name="bgley">#181818</color>
frameworks/base/core/res/res/values/strings.xml

+    <string name="my_dialog_ok">예</string>
+       <string name="my_dialog_cancle">아니오</string>
+       <string name="my_dialog_title">기기에서 연결 시도합니다</string>
+       <string name="my_dialog_message">연결 하시겠습니까?</string>
+    <string name="my_dialog_message_auto_sleep">시동이 꺼진 상태이므로 5초 뒤 시스템을 종료 합니다</string>
frameworks/base/core/res/res/values/styles.xml

+    <!--自定义dialog背景全透明无边框theme -->
+    <!-- @hide -->
+       <style name="MyDialog" parent="android:style/Theme.Dialog">
+           <!--背景颜色及和透明程度-->
+           <item name="android:windowBackground">@android:color/transparent</item>
+           <!--是否去除标题 -->
+           <item name="android:windowNoTitle">true</item>
+           <!--是否去除边框-->
+           <item name="android:windowFrame">@null</item>
+           <!--是否浮现在activity之上-->
+           <item name="android:windowIsFloating">true</item>
+           <!--背景是否变暗-->
+           <item name="android:backgroundDimEnabled">true</item>
+       </style>
core/res/res/drawable/active_focus.png
core/res/res/drawable/black_round.xml
core/res/res/drawable/button_focused.xml
core/res/res/drawable/button_normal.xml
core/res/res/drawable/button_selector.xml
core/res/res/layout/mydialog_layout.xml
core/res/res/layout/mydialog_layout_auto_sleep.xml
data/fonts/hyundaih_l.ttf



这些都是一些资源文件添加,没什么好说的,需要注意的是所有资源的名字,和资源文件名都需要添加到系统的symbols.xml文件里面,据说这个是代表系统私有的,其他App是无法调用的。
 frameworks/base/core/res/res/values/symbols.xml
+  <java-symbol type="string" name="my_dialog_ok" />
+  <java-symbol type="string" name="my_dialog_cancle" />
+  <java-symbol type="string" name="my_dialog_title" />
+  <java-symbol type="string" name="my_dialog_message" />
+  <java-symbol type="string" name="my_dialog_message_auto_sleep" />
+  <java-symbol type="color" name="unselect_grey" />
+  <java-symbol type="color" name="bgley" />
+  <java-symbol type="style" name="MyDialog" />
+  <java-symbol type="drawable" name="active_focus" />
+  <java-symbol type="drawable" name="black_round" />
+  <java-symbol type="drawable" name="button_focused" />
+  <java-symbol type="drawable" name="button_normal" />
+  <java-symbol type="drawable" name="button_selector" />
+  <java-symbol type="layout" name="mydialog_layout" />
+  <java-symbol type="layout" name="mydialog_layout_auto_sleep" />
+  <java-symbol type="id" name="mydialog_btn_ok" />
+  <java-symbol type="id" name="mydialog_btn_cancel" />
+  <java-symbol type="id" name="mydialog_title" />
+  <java-symbol type="id" name="mydialog_message" />
+  <java-symbol type="id" name="mydialog_message_auto_sleep" />

这个就是安卓里面的样式来添加就好了,类型+名字
还有个字体文件是加到这个地方:data/fonts/hyundaih_l.ttf 在对应的地方添加一下这个文件,具体使用是在后面的java代码里面

diff --git a/data/fonts/Android.mk b/data/fonts/Android.mk
old mode 100644
new mode 100755
index 76eb4e67692..594e5a76d39
--- a/data/fonts/Android.mk
+++ b/data/fonts/Android.mk
@@ -74,7 +74,8 @@ $(eval include $(BUILD_PREBUILT))
 endef
 
 font_src_files := \
-    AndroidClock.ttf
+    AndroidClock.ttf \
+    hyundaih_l.ttf
 
 $(foreach f, $(font_src_files), $(call build-one-font-module, $(f)))
 
diff --git a/data/fonts/fonts.mk b/data/fonts/fonts.mk
old mode 100644
new mode 100755
index e884f2fe4bb..6bc7e005368
--- a/data/fonts/fonts.mk
+++ b/data/fonts/fonts.mk
@@ -17,4 +17,5 @@
 PRODUCT_PACKAGES := \
     DroidSansMono.ttf \
     AndroidClock.ttf \
+    hyundaih_l.ttf \
     fonts.xml
diff --git a/data/fonts/fonts.xml b/data/fonts/fonts.xml
old mode 100644
new mode 100755
index 72d9bce687a..157c6562c21
--- a/data/fonts/fonts.xml
+++ b/data/fonts/fonts.xml
@@ -36,6 +36,10 @@
         <font weight="700" style="italic">Roboto-BoldItalic.ttf</font>
     </family>
 
+    <family name="hyundaih_l">
+        <font weight="400" style="normal">hyundaih_l.ttf</font>
+    </family>


frameworks/opt/net/wifi/service/java/com/android/server/wifi/p2p/MyDialog.java
这个是自定义Dialog  在此感谢CSDN友情提供,具体代码如下:

package com.android.server.wifi.p2p;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.TextView;
import com.android.internal.R;
import android.graphics.Typeface;
import android.view.KeyEvent;


public class MyDialog extends Dialog {


    private Button yes;
    private Button no;
    private TextView titleView;
    private TextView messageView;
    private String title;
    private String message;
    private onYesOnclickListener yesOnclickListener;
    private onNoOnclickListener noOnclickListener;
        private View dialogView;
        private Context mContext;


    public MyDialog(Context context, int themeResId) {
        super(context, themeResId);
                this.mContext = context;
    }


    public void setYesOnclickListener(onYesOnclickListener yesOnclickListener) {
        this.yesOnclickListener = yesOnclickListener;
    }


    public void setNoOnclickListener(onNoOnclickListener noOnclickListener) {
        this.noOnclickListener = noOnclickListener;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                dialogView = LayoutInflater.from(mContext).inflate(R.layout.mydialog_layout, null);
        setContentView(dialogView);
        initView();
        initData();
        initEvent();
    }


    private void initView() {
        yes = (Button) dialogView.findViewById(R.id.mydialog_btn_ok);
        no = (Button) dialogView.findViewById(R.id.mydialog_btn_cancel);
        titleView = (TextView) dialogView.findViewById(R.id.mydialog_title);
                messageView = (TextView) dialogView.findViewById(R.id.mydialog_message);
                yes.setTypeface(Typeface.create("hyundaih_l",Typeface.NORMAL));
        no.setTypeface(Typeface.create("hyundaih_l",Typeface.NORMAL));
        titleView.setTypeface(Typeface.create("hyundaih_l",Typeface.NORMAL));
        messageView.setTypeface(Typeface.create("hyundaih_l",Typeface.NORMAL));
    }


    private void initData() {
        if (title != null) {
            titleView.setText(title);
        }


        if (message != null) {
            messageView.setText(message);
        }
    }


    private void initEvent() {
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (yesOnclickListener != null) {
                    yesOnclickListener.onYesOnclick();
                }
            }
        });
                yes.setOnKeyListener(new View.OnKeyListener() {


                        @Override
                        public boolean onKey(View v, int keyCode, KeyEvent event) {
                                if((keyCode==KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER) && event.getAction() == KeyEvent.ACTION_UP){
                                        if (yesOnclickListener != null) {
                            yesOnclickListener.onYesOnclick();
                        }
                                }
                                return false;
                        }
                });


        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (noOnclickListener != null) {
                    noOnclickListener.onNoOnclick();
                }
            }
        });
                no.setOnKeyListener(new View.OnKeyListener() {


                        @Override
                        public boolean onKey(View v, int keyCode, KeyEvent event) {
                                if((keyCode==KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER) && event.getAction() == KeyEvent.ACTION_UP){
                                        if (noOnclickListener != null) {
                            noOnclickListener.onNoOnclick();
                        }
                                }
                                return false;
                        }
                });
    }


    public void setTitle(String title) {
        this.title = title;
    }


    public void setMessage(String message) {
        this.message = message;
    }


    public interface onYesOnclickListener {
        public void onYesOnclick();
    }


    public interface onNoOnclickListener {
        public void onNoOnclick();
    }
}


后面就是具体调用Dialog的地方
frameworks/opt/net/wifi/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java

--- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
+++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
@@ -17,6 +17,8 @@
 package com.android.server.wifi.p2p;
 
 import android.app.AlertDialog;
+import android.app.Dialog;
+import android.widget.Button;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -2696,7 +2698,13 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
             dialog.show();
         }
 
+        //Add by jachary 2021-10-9
+               private boolean p2pConnectEnabled;
         private void notifyInvitationReceived() {
+                       if(p2pConnectEnabled){
+                               sendMessage(PEER_CONNECTION_USER_ACCEPT);
+                               return;
+                       }
             Resources r = Resources.getSystem();
             final WpsInfo wps = mSavedPeerConfig.wps;
             final View textEntryView = LayoutInflater.from(mContext)
@@ -2708,7 +2716,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
 
             final EditText pin = (EditText) textEntryView.findViewById(R.id.wifi_p2p_wps_pin);
 
-            AlertDialog dialog = new AlertDialog.Builder(mContext)
+            /*AlertDialog dialog = new AlertDialog.Builder(mContext)
                     .setTitle(r.getString(R.string.wifi_p2p_invitation_to_connect_title))
                     .setView(textEntryView)
                     .setPositiveButton(r.getString(R.string.accept), new OnClickListener() {
@@ -2769,7 +2777,31 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
                 });
                 // TODO: add timeout for this dialog.
                 // TODO: update UI in appliance mode to tell user what to do.
-            }
+            }*/
+            final MyDialog dialog = new MyDialog(mContext, com.android.internal.R.style.MyDialog);
+            dialog.setTitle(getDeviceName(mSavedPeerConfig.deviceAddress) + r.getString(R.string.my_dialog_title));
+            dialog.setYesOnclickListener(new MyDialog.onYesOnclickListener() {
+                @Override
+                public void onYesOnclick() {
+                                       p2pConnectEnabled = true;
+                    sendMessage(PEER_CONNECTION_USER_ACCEPT);
+                    dialog.dismiss();
+                }
+            });
+            dialog.setNoOnclickListener(new MyDialog.onNoOnclickListener() {
+                @Override
+                public void onNoOnclick() {
+                    sendMessage(PEER_CONNECTION_USER_REJECT);
+                    dialog.dismiss();
+                }
+            });
+            /*dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
+                @Override
+                public void onCancel(DialogInterface arg0) {
+                    sendMessage(PEER_CONNECTION_USER_REJECT);
+                }
+            });*/
+            dialog.setCanceledOnTouchOutside(false);
 
             dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
[url]http://190.lsal.cn/195/1329.gif?0728100424873[/url]
沙发#
发布于:2021-10-12 11:34
赵工也做车载?
板凳#
发布于:2021-10-12 13:23
是,这个rk3288-9.0是车载盒子,是后排看电视的
[url]http://190.lsal.cn/195/1329.gif?0728100424873[/url]
地板#
发布于:2021-10-12 14:30
zhaoyf13:是,这个rk3288-9.0是车载盒子,是后排看电视的回到原帖
车载后座今年行情好冷淡,我们都没几个定单
4楼#
发布于:2021-10-13 08:35
我们就这一个单,做了快2年需求还没改完,问题太多了
[url]http://190.lsal.cn/195/1329.gif?0728100424873[/url]
6楼#
发布于:2022-10-18 10:08
字体文件其实也可以放在这个目录:
frameworks\base\core\res\res\font\
hyundaih_l.tty
在这个文件里面添加配置
frameworks\base\core\res\res\values\symbols.xml
<java-symbol type="font" name="hyundaih_l" />

在xml布局文件里,就可以调用字体了。
android:fontFamily="@font/hyundaih_l"
[url]http://190.lsal.cn/195/1329.gif?0728100424873[/url]
游客

返回顶部