1 /*
2  * Copyright (C) 2021 The Android Open Source Project
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.android.emojirenderingtestapp;
18 
19 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
20 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
21 
22 import android.app.Activity;
23 import android.graphics.fonts.Font;
24 import android.graphics.fonts.SystemFonts;
25 import android.os.Bundle;
26 import android.widget.LinearLayout;
27 import android.widget.TextView;
28 
29 public class GetAvailableFontsTestActivity extends Activity {
30 
31     @Override
onCreate(Bundle savedInstanceState)32     protected void onCreate(Bundle savedInstanceState) {
33         super.onCreate(savedInstanceState);
34         String emojiFontPath = "<Not found>";
35         for (Font font : SystemFonts.getAvailableFonts()) {
36             // Calls font attribute getters to make sure that they don't open font files.
37             font.getAxes();
38             font.getFile();
39             font.getLocaleList();
40             font.getStyle();
41             font.getTtcIndex();
42             if ("NotoColorEmoji.ttf".equals(font.getFile().getName())) {
43                 emojiFontPath = font.getFile().getAbsolutePath();
44             }
45         }
46         LinearLayout container = new LinearLayout(this);
47         container.setOrientation(LinearLayout.VERTICAL);
48         TextView textView = new TextView(this);
49         textView.setText(emojiFontPath);
50         container.addView(textView, new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
51         setContentView(container);
52     }
53 }
54