diff --git a/.gitignore b/.gitignore index b8dbed5..6bb6171 100644 --- a/.gitignore +++ b/.gitignore @@ -1,49 +1,17 @@ -*~ -# built application files -*.apk -*.ap_ - -# files for the dex VM -*.dex - -# Java class files -*.class - -# generated files -bin/ -gen/ -build/ -html/ -# Local configuration file (sdk path, etc) -local.properties - -.gradle - -# Eclipse project files -.classpath -.project - -# Android Studio -.idea/ -.gradle -/*/local.properties -/*/out -/*/*/build -/*/*/production *.iml -*.iws -*.ipr -*~ -*.swp - -# Mac temporary +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml .DS_Store - -node_modules/ - -deploygate.properties - -# Crashlytics -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx +/.idea +upload.gradle \ No newline at end of file diff --git a/LICENSE.md b/LICENSE similarity index 99% rename from LICENSE.md rename to LICENSE index 5c304d1..0b6099d 100644 --- a/LICENSE.md +++ b/LICENSE @@ -186,7 +186,7 @@ Apache License same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright (C) 2014 Drivemode, Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index c60115b..88ad0c1 100644 --- a/README.md +++ b/README.md @@ -1,85 +1,89 @@ # TypefaceHelper -[![Gitter](http://img.shields.io/badge/Gitter-Join%20Chat-brightgreen.svg?style=flat)](https://gitter.im/Drivemode/TypefaceHelper?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-TypefaceHelper-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1246) -[![License](http://img.shields.io/badge/License-Apache%202-brightgreen.svg?style=flat)](https://github.com/Drivemode/TypefaceHelper/blob/master/LICENSE) -[![Circle CI](https://circleci.com/gh/Drivemode/TypefaceHelper/tree/master.svg?style=shield)](https://circleci.com/gh/Drivemode/TypefaceHelper/tree/master) +[![Build](https://github.com/applibgroup/TypefaceHelper/actions/workflows/main.yml/badge.svg)](https://github.com/applibgroup/TypefaceHelper/actions/workflows/main.yml) +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=applibgroup_TypefaceHelper&metric=alert_status)](https://sonarcloud.io/dashboard?id=applibgroup_TypefaceHelper) -Helper object for injecting typeface into various text views of android. +Helper object for injecting typeface into various text components of HarmonyOS. ## Overview -We can use various custom typefaces asset for any text views(like TextView, Button, RadioButton, EditText, etc.), +We can use various custom typefaces asset for any text components (like Text, Button, RadioButton, etc.), but there's no way to set the typeface as a styled theme to apply the typeface for overall screens in the app. This library helps to do it in easy way :) -And there's also a serious bug that creating typeface from asset resource will cause memory leak ([See this link](https://code.google.com/p/android/issues/detail?id=9904) for more details), +And there's also a serious bug that creating typeface from asset resource will cause memory leak, this library will take care about this problem as well. -## How to use +## Source +This library has been inspired by https://github.com/Drivemode/TypefaceHelper -First, put your typeface into `asset` directory. +## How to use -In your application class, take care about the helper object lifecycle. +In your MyApplication class, take care about the helper object lifecycle. ```java -public class MyApp extends Application { - @Override - public void onCreate() { - super.onCreate(); - - TypefaceHelper.initialize(this); - } - - @Override - public void onTerminate() { - TypefaceHelper.destroy(); - super.onTerminate(); - } +public abstract class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + TypefaceHelper.initialize(this); + } + + @Override + public void onEnd() { + super.onEnd(); + TypefaceHelper.destroy(); + } } ``` -And in your activity, if you would like to set your typeface to a text view, +And in your MainAbilitySlice, if you would like to set your typeface to a text , ```java -public class MyActivity extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - TextView hello = (TextView) findViewById(R.id.hello_world); - TypefaceHelper.getInstance().setTypeface(hello, "font/font_file.ttf"); - } + +public class MainAbilitySlice extends AbilitySlice { + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + Text hello = (Text) findComponentById(ResourceTable.Id_hello_world); + TypefaceHelper.getInstance().setTypeface(hello, "font_file.ttf"); + } } + ``` -You can also set your typeface for all text views that belong to a specific view group just like this. +You can also set your typeface for all text that belong to a specific ComoponentConatainer just like this. ```java -public class MyActivity extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - LinearLayout container = (LinearLayout) findViewById(R.id.text_container); - TypefaceHelper.getInstance().setTypeface(container, "font/font_file.ttf"); - } +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + DirectionalLayout container = (DirectionalLayout) findComponentById(ResourceTable.Id_container); + TypefaceHelper.getInstance().setTypeface(container, "font_file.ttf"); + } } ``` -If you want to apply the typeface for all text views under the activity layout, +If you want to apply the typeface for all text under the AbilitySlice, ```java -public class MyActivity extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(TypefaceHelper.getInstance().setTypeface(this, R.layout.activity_main, "font/font_file.ttf")); - } +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + TypefaceHelper.getInstance().setTypeface(this, "font_file.ttf"); + } } + ``` Nice and easy! @@ -87,35 +91,51 @@ Nice and easy! You can apply the typeface to your whole window like this. ```java -public class MyActivity extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.layout_activity_main); - TypefaceHelper.getInstance().setTypeface(this, "font/font_file.ttf"); - } + +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + TypefaceHelper.getInstance().setTypeface(this, "font_file.ttf"); + } } + ``` And... you can also pass the font name as a string resource id: ```java -public class MyActivity extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.layout_activity_main); - TypefaceHelper.getInstance().setTypeface(this, R.string.font_primary); - } + + public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + TypefaceHelper.getInstance().setTypeface(this, Resourcetable.String_font_primary); + } } ``` -## Download -Gradle: + + +## Integration + +1. For using TypefaceHelper module in sample app, include the source code and add the below dependencies in entry/build.gradle to generate hap/support.har. +```java + implementation project(path: ':TypefaceHelper') +``` +2. For using TypefaceHelper module in separate application using har file, add the har file in the entry/libs folder and add the dependencies in entry/build.gradle file. + ```java + implementation fileTree(dir: 'libs', include: ['*.har']) ``` -compile 'com.drivemode:TypefaceHelper:1.2.0@aar' +3. For using TypefaceHelper module from a remote repository in separate application, add the below dependencies in entry/build.gradle file. +```java +implementation 'dev.applibgroup:TypefaceHelper:1.0.0' ``` ## License diff --git a/TypefaceHelper/build.gradle b/TypefaceHelper/build.gradle index dd345b0..b9c691e 100644 --- a/TypefaceHelper/build.gradle +++ b/TypefaceHelper/build.gradle @@ -1,22 +1,22 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 28 - +apply plugin: 'com.huawei.ohos.library' +//For instructions on signature configuration, see https://developer.harmonyos.com/en/docs/documentation/doc-guides/ide_debug_device-0000001053822404#EN-US_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 defaultConfig { - minSdkVersion 15 - targetSdkVersion 28 + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } } + } dependencies { - implementation 'com.android.support:support-v4:28.0.0-rc01' - implementation 'com.android.support:support-annotations:28.0.0-rc01' + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.13' } - -apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' - -afterEvaluate { - androidJavadocs.failOnError = false - androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath -} \ No newline at end of file diff --git a/TypefaceHelper/consumer-rules.pro b/TypefaceHelper/consumer-rules.pro new file mode 100644 index 0000000..9dccc61 --- /dev/null +++ b/TypefaceHelper/consumer-rules.pro @@ -0,0 +1 @@ +# Add har specific ProGuard rules for consumer here. \ No newline at end of file diff --git a/TypefaceHelper/gradle.properties b/TypefaceHelper/gradle.properties deleted file mode 100644 index 6d4a6a9..0000000 --- a/TypefaceHelper/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_NAME=TypefaceHelper -POM_ARTIFACT_ID=TypefaceHelper -POM_PACKAGING=aar diff --git a/TypefaceHelper/proguard-rules.pro b/TypefaceHelper/proguard-rules.pro index 200fdff..f7666e4 100644 --- a/TypefaceHelper/proguard-rules.pro +++ b/TypefaceHelper/proguard-rules.pro @@ -1,17 +1 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /usr/local/Cellar/android-sdk/22.6.2/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/TypefaceHelper/src/main/AndroidManifest.xml b/TypefaceHelper/src/main/AndroidManifest.xml deleted file mode 100644 index 38447d4..0000000 --- a/TypefaceHelper/src/main/AndroidManifest.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/TypefaceHelper/src/main/config.json b/TypefaceHelper/src/main/config.json new file mode 100644 index 0000000..528cefc --- /dev/null +++ b/TypefaceHelper/src/main/config.json @@ -0,0 +1,24 @@ +{ + "app": { + "bundleName": "com.example.typefacemaster", + "vendor": "drivemode", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": { + }, + "module": { + "package": "com.drivemode.harmony.typeface", + "deviceType": [ + "phone", + "tablet" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "TypefaceHelper", + "moduleType": "har" + } + } +} \ No newline at end of file diff --git a/TypefaceHelper/src/main/java/com/drivemode/android/typeface/DialogUtils.java b/TypefaceHelper/src/main/java/com/drivemode/android/typeface/DialogUtils.java deleted file mode 100644 index 66e1918..0000000 --- a/TypefaceHelper/src/main/java/com/drivemode/android/typeface/DialogUtils.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.drivemode.android.typeface; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.ProgressDialog; -import android.content.DialogInterface; -import android.widget.Button; -import android.widget.TextView; - -/** - * @author KeishinYokomaku - */ -final class DialogUtils { - public static void setTypeface(TypefaceHelper helper, D dialog, String typefaceName, int style) { - if (dialog instanceof ProgressDialog) { - setTypeface(helper, (ProgressDialog) dialog, typefaceName, style); - } else if (dialog instanceof AlertDialog) { - setTypeface(helper, (AlertDialog) dialog, typefaceName, style); - } - } - - private static void setTypeface(TypefaceHelper helper, AlertDialog alertDialog, String typefaceName, int style) { - Button positive = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); - Button negative = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE); - Button neutral = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL); - TextView message = (TextView) alertDialog.findViewById(android.R.id.message); - if (positive != null) { - helper.setTypeface(positive, typefaceName, style); - } - if (negative != null) { - helper.setTypeface(negative, typefaceName, style); - } - if (neutral != null) { - helper.setTypeface(neutral, typefaceName, style); - } - if (message != null) { - helper.setTypeface(message, typefaceName, style); - } - } - - private static void setTypeface(TypefaceHelper helper, ProgressDialog progressDialog, String typefaceName, int style) { - TextView message = (TextView) progressDialog.findViewById(android.R.id.message); - if (message != null) { - helper.setTypeface(message, typefaceName, style); - } - } -} diff --git a/TypefaceHelper/src/main/java/com/drivemode/android/typeface/TypefaceCache.java b/TypefaceHelper/src/main/java/com/drivemode/android/typeface/TypefaceCache.java deleted file mode 100644 index a3eb406..0000000 --- a/TypefaceHelper/src/main/java/com/drivemode/android/typeface/TypefaceCache.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.drivemode.android.typeface; - -import android.app.Application; -import android.content.Context; -import android.graphics.Typeface; - -import java.util.Hashtable; - -/** - * This is a typeface instance cache. - * The cache is to avoid memory leak problem when a typeface is loaded. - * See the link for more details about the memory leak issue. - * (https://code.google.com/p/android/issues/detail?id=9904) - * - * @author hnakagawa - */ -/* package */ final class TypefaceCache { - private static TypefaceCache sInstance; - - private final Hashtable mCache = new Hashtable(); - - private final Application mApplication; - - private TypefaceCache(Application application) { - mApplication = application; - } - - /** - * If the cache has an instance for the typeface name, this will return the instance immediately. - * Otherwise this method will create typeface instance and put it into the cache and return the instance. - * @param name the typeface name. - * @return {@link android.graphics.Typeface} instance. - */ - public synchronized Typeface get(String name) { - Typeface typeface = mCache.get(name); - if(typeface == null) { - try { - typeface = Typeface.createFromAsset(mApplication.getAssets(), name); - } catch (Exception exp) { - return null; - } - mCache.put(name, typeface); - } - return typeface; - } - - /** - * Retrieve this cache. - * @param context the context. - * @return the cache instance. - */ - public static synchronized TypefaceCache getInstance(Context context) { - if (sInstance == null) - sInstance = new TypefaceCache((Application)context.getApplicationContext()); - return sInstance; - } -} diff --git a/TypefaceHelper/src/main/java/com/drivemode/android/typeface/TypefaceHelper.java b/TypefaceHelper/src/main/java/com/drivemode/android/typeface/TypefaceHelper.java deleted file mode 100644 index 4eaa193..0000000 --- a/TypefaceHelper/src/main/java/com/drivemode/android/typeface/TypefaceHelper.java +++ /dev/null @@ -1,541 +0,0 @@ -package com.drivemode.android.typeface; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.app.Application; -import android.app.Dialog; -import android.content.Context; -import android.graphics.Paint; -import android.graphics.Typeface; -import android.os.Build; -import android.support.annotation.LayoutRes; -import android.support.annotation.StringRes; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; -import android.widget.Toast; - -/** - * Helper class for setting typeface to the text views. - * @author KeithYokoma - */ -@SuppressWarnings("unused") // public APIs -public final class TypefaceHelper { - public static final String TAG = TypefaceHelper.class.getSimpleName(); - private static TypefaceHelper sHelper; - private final Application mApplication; - private final TypefaceCache mCache; - - private TypefaceHelper(Application application) { - mApplication = application; - mCache = TypefaceCache.getInstance(application); - } - - /** - * Initialize the instance. - * @param application the application context. - */ - public static synchronized void initialize(Application application) { - if (sHelper != null) { - Log.v(TAG, "already initialized"); - } - sHelper = new TypefaceHelper(application); - } - - /** - * Terminate the instance. - */ - public static synchronized void destroy() { - if (sHelper == null) { - Log.v(TAG, "not initialized yet"); - return; - } - sHelper = null; - } - - /** - * Retrieve the helper instance. - * @return the helper instance. - */ - public static synchronized TypefaceHelper getInstance() { - if (sHelper == null) { - throw new IllegalArgumentException("Instance is not initialized yet. Call initialize() first."); - } - return sHelper; - } - - /** - * Fetches font instance from TypefaceCache - * @param typefaceName typeface name. - * @return requested typeface - */ - public Typeface getTypeface(String typefaceName){ - return mCache.get(typefaceName); - } - - /** - * Set the typeface to the target view. - * @param view to set typeface. - * @param typefaceName typeface name. - * @param text view parameter. - */ - public void setTypeface(V view, String typefaceName) { - Typeface typeface = mCache.get(typefaceName); - view.setTypeface(typeface); - } - - /** - * Set the typeface to the target view. - * @param view to set typeface. - * @param strResId string resource containing typeface name. - * @param text view parameter. - */ - public void setTypeface(V view, @StringRes int strResId) { - setTypeface(view, mApplication.getString(strResId)); - } - - /** - * Set the typeface to the target view. - * @param view to set typeface. - * @param typefaceName typeface name. - * @param style the typeface style. - * @param text view parameter. - */ - public void setTypeface(V view, String typefaceName, int style) { - Typeface typeface = mCache.get(typefaceName); - view.setTypeface(typeface, style); - } - - /** - * Set the typeface to the target view. - * @param view to set typeface. - * @param strResId string resource containing typeface name. - * @param style the typeface style. - * @param text view parameter. - */ - public void setTypeface(V view, @StringRes int strResId, int style) { - setTypeface(view, mApplication.getString(strResId), style); - } - - /** - * Set the typeface to the all text views belong to the view group. - * Note that this method recursively trace the child view groups and set typeface for the text views. - * @param viewGroup the view group that contains text views. - * @param typefaceName typeface name. - * @param view group parameter. - */ - public void setTypeface(V viewGroup, String typefaceName) { - int count = viewGroup.getChildCount(); - for (int i = 0; i < count; i++) { - View child = viewGroup.getChildAt(i); - if (child instanceof ViewGroup) { - setTypeface((ViewGroup) child, typefaceName); - continue; - } - if (!(child instanceof TextView)) { - continue; - } - setTypeface((TextView) child, typefaceName); - } - } - - /** - * Set the typeface to the all text views belong to the view group. - * Note that this method recursively trace the child view groups and set typeface for the text views. - * @param viewGroup the view group that contains text views. - * @param strResId string resource containing typeface name. - * @param view group parameter. - */ - public void setTypeface(V viewGroup, @StringRes int strResId) { - setTypeface(viewGroup, mApplication.getString(strResId)); - } - - /** - * Set the typeface to the all text views belong to the view group. - * Note that this method recursively trace the child view groups and set typeface for the text views. - * @param viewGroup the view group that contains text views. - * @param typefaceName typeface name. - * @param style the typeface style. - * @param view group parameter. - */ - public void setTypeface(V viewGroup, String typefaceName, int style) { - int count = viewGroup.getChildCount(); - for (int i = 0; i < count; i++) { - View child = viewGroup.getChildAt(i); - if (child instanceof ViewGroup) { - setTypeface((ViewGroup) child, typefaceName, style); - continue; - } - if (!(child instanceof TextView)) { - continue; - } - setTypeface((TextView) child, typefaceName, style); - } - } - - /** - * Set the typeface to the all text views belong to the view group. - * Note that this method recursively trace the child view groups and set typeface for the text views. - * @param viewGroup the view group that contains text views. - * @param strResId string resource containing typeface name. - * @param style the typeface style. - * @param view group parameter. - */ - public void setTypeface(V viewGroup, @StringRes int strResId, int style) { - setTypeface(viewGroup, mApplication.getString(strResId), style); - } - - /** - * Set the typeface to the target paint. - * @param paint the set typeface. - * @param typefaceName typeface name. - */ - public void setTypeface(Paint paint, String typefaceName) { - Typeface typeface = mCache.get(typefaceName); - paint.setTypeface(typeface); - } - - /** - * Set the typeface to the target paint. - * @param paint the set typeface. - * @param strResId string resource containing typeface name. - */ - public void setTypeface(Paint paint, @StringRes int strResId) { - setTypeface(paint, mApplication.getString(strResId)); - } - - /** - * Set the typeface to the all text views belong to the view group. - * @param context the context. - * @param layoutRes the layout resource id. - * @param typefaceName typeface name. - * @return the view. - */ - public View setTypeface(Context context, @LayoutRes int layoutRes, String typefaceName) { - return setTypeface(context, layoutRes, null, typefaceName); - } - - /** - * Set the typeface to the all text views belong to the view group. - * @param context the context. - * @param layoutRes the layout resource id. - * @param strResId string resource containing typeface name. - * @return the view. - */ - public View setTypeface(Context context, @LayoutRes int layoutRes, @StringRes int strResId) { - return setTypeface(context, layoutRes, mApplication.getString(strResId)); - } - - /** - * Set the typeface to the all text views belong to the view group. - * @param context the context. - * @param layoutRes the layout resource id. - * @param parent the parent view group to attach the layout. - * @param typefaceName typeface name. - * @return the view. - */ - public View setTypeface(Context context, @LayoutRes int layoutRes, ViewGroup parent, String typefaceName) { - ViewGroup view = (ViewGroup) LayoutInflater.from(context).inflate(layoutRes, parent); - setTypeface(view, typefaceName); - return view; - } - - /** - * Set the typeface to the all text views belong to the view group. - * @param context the context. - * @param layoutRes the layout resource id. - * @param parent the parent view group to attach the layout. - * @param strResId string resource containing typeface name. - * @return the view. - */ - public View setTypeface(Context context, @LayoutRes int layoutRes, ViewGroup parent, @StringRes int strResId) { - return setTypeface(context, layoutRes, parent, mApplication.getString(strResId)); - } - - /** - * Set the typeface to the all text views belong to the view group. - * @param context the context. - * @param layoutRes the layout resource id. - * @param typefaceName typeface name. - * @param style the typeface style. - * @return the view. - */ - public View setTypeface(Context context, @LayoutRes int layoutRes, String typefaceName, int style) { - return setTypeface(context, layoutRes, null, typefaceName, 0); - } - - /** - * Set the typeface to the all text views belong to the view group. - * @param context the context. - * @param layoutRes the layout resource id. - * @param strResId string resource containing typeface name. - * @param style the typeface style. - * @return the view. - */ - public View setTypeface(Context context, @LayoutRes int layoutRes, @StringRes int strResId, int style) { - return setTypeface(context, layoutRes, mApplication.getString(strResId), 0); - } - - /** - * Set the typeface to the all text views belong to the view group. - * @param context the context. - * @param layoutRes the layout resource id. - * @param parent the parent view group to attach the layout. - * @param typefaceName typeface name. - * @param style the typeface style. - * @return the view. - */ - public View setTypeface(Context context, @LayoutRes int layoutRes, ViewGroup parent, String typefaceName, int style) { - ViewGroup view = (ViewGroup) LayoutInflater.from(context).inflate(layoutRes, parent); - setTypeface(view, typefaceName, style); - return view; - } - - /** - * Set the typeface to the all text views belong to the view group. - * @param context the context. - * @param layoutRes the layout resource id. - * @param parent the parent view group to attach the layout. - * @param strResId string resource containing typeface name. - * @param style the typeface style. - * @return the view. - */ - public View setTypeface(Context context, @LayoutRes int layoutRes, ViewGroup parent, @StringRes int strResId, int style) { - return setTypeface(context, layoutRes, parent, mApplication.getString(strResId), style); - } - - /** - * Set the typeface to the all text views belong to the activity. - * Note that we use decor view of the activity so that the typeface will also be applied to action bar. - * @param activity the activity. - * @param typefaceName typeface name. - */ - public void setTypeface(Activity activity, String typefaceName) { - setTypeface(activity, typefaceName, 0); - } - - /** - * Set the typeface to the all text views belong to the activity. - * Note that we use decor view of the activity so that the typeface will also be applied to action bar. - * @param activity the activity. - * @param strResId string resource containing typeface name. - */ - public void setTypeface(Activity activity, @StringRes int strResId) { - setTypeface(activity, mApplication.getString(strResId)); - } - - /** - * Set the typeface to the all text views belong to the activity. - * Note that we use decor view of the activity so that the typeface will also be applied to action bar. - * @param activity the activity. - * @param typefaceName typeface name. - * @param style the typeface style. - */ - public void setTypeface(Activity activity, String typefaceName, int style) { - setTypeface((ViewGroup) activity.getWindow().getDecorView(), typefaceName, style); - } - - /** - * Set the typeface to the all text views belong to the activity. - * Note that we use decor view of the activity so that the typeface will also be applied to action bar. - * @param activity the activity. - * @param strResId string resource containing typeface name. - * @param style the typeface style. - */ - public void setTypeface(Activity activity, @StringRes int strResId, int style) { - setTypeface(activity, mApplication.getString(strResId), style); - } - - /** - * Set the typeface to the all text views belong to the fragment. - * Make sure to call this method after fragment view creation. - * If you use fragments in the support package, - * call {@link com.drivemode.android.typeface.TypefaceHelper#supportSetTypeface(android.support.v4.app.Fragment, String)} instead. - * @param fragment the fragment. - * @param typefaceName typeface name. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void setTypeface(F fragment, String typefaceName) { - setTypeface(fragment, typefaceName, 0); - } - - /** - * Set the typeface to the all text views belong to the fragment. - * Make sure to call this method after fragment view creation. - * If you use fragments in the support package, - * call {@link com.drivemode.android.typeface.TypefaceHelper#supportSetTypeface(android.support.v4.app.Fragment, String)} instead. - * @param fragment the fragment. - * @param strResId string resource containing typeface name. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void setTypeface(F fragment, @StringRes int strResId) { - setTypeface(fragment, mApplication.getString(strResId)); - } - - /** - * Set the typeface to the all text views belong to the fragment. - * Make sure to call this method after fragment view creation. - * If you use fragments in the support package, - * call {@link com.drivemode.android.typeface.TypefaceHelper#supportSetTypeface(android.support.v4.app.Fragment, String, int)} instead. - * @param fragment the fragment. - * @param typefaceName typeface name. - * @param style the typeface style. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void setTypeface(F fragment, String typefaceName, int style) { - View root = fragment.getView(); - if (root instanceof TextView) { - setTypeface((TextView) root, typefaceName, style); - } else if (root instanceof ViewGroup) { - setTypeface((ViewGroup) root, typefaceName, style); - } - } - - /** - * Set the typeface to the all text views belong to the fragment. - * Make sure to call this method after fragment view creation. - * If you use fragments in the support package, - * call {@link com.drivemode.android.typeface.TypefaceHelper#supportSetTypeface(android.support.v4.app.Fragment, String, int)} instead. - * @param fragment the fragment. - * @param strResId string resource containing typeface name. - * @param style the typeface style. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public void setTypeface(F fragment, @StringRes int strResId, int style) { - setTypeface(fragment, mApplication.getString(strResId), style); - } - - /** - * Set the typeface to the all text views belong to the fragment. - * Make sure to call this method after fragment view creation. - * And this is a support package fragments only. - * @param fragment the fragment. - * @param typefaceName typeface name. - */ - public void supportSetTypeface(F fragment, String typefaceName) { - supportSetTypeface(fragment, typefaceName, 0); - } - - /** - * Set the typeface to the all text views belong to the fragment. - * Make sure to call this method after fragment view creation. - * And this is a support package fragments only. - * @param fragment the fragment. - * @param strResId string resource containing typeface name. - */ - public void supportSetTypeface(F fragment, @StringRes int strResId) { - supportSetTypeface(fragment, mApplication.getString(strResId)); - } - - /** - * Set the typeface to the all text views belong to the fragment. - * Make sure to call this method after fragment view creation. - * And this is a support package fragments only. - * @param fragment the fragment. - * @param typefaceName typeface name. - * @param style the typeface style. - */ - public void supportSetTypeface(F fragment, String typefaceName, int style) { - View root = fragment.getView(); - if (root instanceof TextView) { - setTypeface((TextView) root, typefaceName, style); - } else if (root instanceof ViewGroup) { - setTypeface((ViewGroup) root, typefaceName, style); - } - } - - /** - * Set the typeface to the all text views belong to the fragment. - * Make sure to call this method after fragment view creation. - * And this is a support package fragments only. - * @param fragment the fragment. - * @param strResId string resource containing typeface name. - * @param style the typeface style. - */ - public void supportSetTypeface(F fragment, @StringRes int strResId, int style) { - supportSetTypeface(fragment, mApplication.getString(strResId), style); - } - - /** - * Set the typeface for the dialog view. - * @param dialog the dialog. - * @param typefaceName typeface name. - */ - public void setTypeface(D dialog, String typefaceName) { - setTypeface(dialog, typefaceName, 0); - } - - /** - * Set the typeface for the dialog view. - * @param dialog the dialog. - * @param strResId string resource containing typeface name. - */ - public void setTypeface(D dialog, @StringRes int strResId) { - setTypeface(dialog, mApplication.getString(strResId)); - } - - /** - * Set the typeface for the dialog view. - * @param dialog the dialog. - * @param typefaceName typeface name. - * @param style the typeface style. - */ - public void setTypeface(D dialog, String typefaceName, int style) { - DialogUtils.setTypeface(this, dialog, typefaceName, style); - } - - /** - * Set the typeface for the dialog view. - * @param dialog the dialog. - * @param strResId string resource containing typeface name. - * @param style the typeface style. - */ - public void setTypeface(D dialog, @StringRes int strResId, int style) { - setTypeface(dialog, mApplication.getString(strResId), style); - } - - /** - * Set the typeface for the toast view. - * @param toast toast. - * @param typefaceName typeface name. - * @return toast that the typeface is injected. - */ - public Toast setTypeface(Toast toast, String typefaceName) { - return setTypeface(toast, typefaceName, 0); - } - - /** - * Set the typeface for the toast view. - * @param toast toast. - * @param strResId string resource containing typeface name. - * @return toast that the typeface is injected. - */ - public Toast setTypeface(Toast toast, @StringRes int strResId) { - return setTypeface(toast, mApplication.getString(strResId)); - } - - /** - * Set the typeface for the toast view. - * @param toast toast. - * @param typefaceName typeface name. - * @param style the typeface style. - * @return toast that the typeface is injected. - */ - public Toast setTypeface(Toast toast, String typefaceName, int style) { - setTypeface((ViewGroup) toast.getView(), typefaceName, style); - return toast; - } - - /** - * Set the typeface for the toast view. - * @param toast toast. - * @param strResId string resource containing typeface name. - * @param style the typeface style. - * @return toast that the typeface is injected. - */ - public Toast setTypeface(Toast toast, @StringRes int strResId, int style) { - return setTypeface(toast, mApplication.getString(strResId), style); - } -} diff --git a/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/DialogUtils.java b/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/DialogUtils.java new file mode 100644 index 0000000..6a5007b --- /dev/null +++ b/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/DialogUtils.java @@ -0,0 +1,32 @@ +package com.drivemode.harmony.typeface; + +import ohos.agp.components.Button; +import ohos.agp.window.dialog.BaseDialog; +import ohos.agp.window.dialog.CommonDialog; +import ohos.agp.window.dialog.IDialog; + +final class DialogUtils { + + private DialogUtils() { + throw new IllegalStateException("Utility class"); + } + public static void setTypeface(TypefaceHelper helper, D dialog, String typefaceName, int style) { + if (dialog instanceof CommonDialog) { + setTypeface(helper, (CommonDialog) dialog, typefaceName, style); + } + } + private static void setTypeface(TypefaceHelper helper, CommonDialog alertDialog, String typefaceName, int style) { + Button positive = (Button) alertDialog.obtainComponentViaId(IDialog.BUTTON1); + Button negative = (Button) alertDialog.obtainComponentViaId(IDialog.BUTTON2); + Button neutral = (Button) alertDialog.obtainComponentViaId(IDialog.BUTTON3); + if (positive != null) { + helper.setTypeface(positive, typefaceName, style); + } + if (negative != null) { + helper.setTypeface(negative, typefaceName, style); + } + if (neutral != null) { + helper.setTypeface(neutral, typefaceName, style); + } + } +} diff --git a/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/LogUtil.java b/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/LogUtil.java new file mode 100644 index 0000000..4a66836 --- /dev/null +++ b/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/LogUtil.java @@ -0,0 +1,48 @@ +package com.drivemode.harmony.typeface; + +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +public class LogUtil { + private static final String TAG_LOG = "typeface"; + + private static final int DOMAIN_ID = 0xD000F00; + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, DOMAIN_ID, LogUtil.TAG_LOG); + + private static final String LOG_FORMAT = "%{public}s: %{public}s"; + + private static boolean isLog = false; + + public static void setIsLog(boolean isLog) { + LogUtil.isLog = isLog; + } + + private LogUtil() { + /* Do nothing */ + } + + /** + * Print debug log + * + * @param tag log tag + * @param msg log message + */ + public static void d(String tag, String msg) { + if (isLog) { + HiLog.debug(LABEL_LOG, LOG_FORMAT, tag, msg); + } + } + + /** + * Print info log + * + * @param tag log tag + * @param msg log message + */ + public static void i(String tag, String msg) { + if (isLog) { + HiLog.info(LABEL_LOG, LOG_FORMAT, tag, msg); + } + } + +} diff --git a/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/TypefaceCache.java b/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/TypefaceCache.java new file mode 100644 index 0000000..80b7fef --- /dev/null +++ b/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/TypefaceCache.java @@ -0,0 +1,83 @@ +package com.drivemode.harmony.typeface; + +import ohos.agp.text.Font; +import ohos.app.Context; +import ohos.app.Environment; +import ohos.global.resource.RawFileEntry; +import ohos.global.resource.Resource; +import ohos.global.resource.ResourceManager; + +import java.io.*; +import java.util.HashMap; +import java.util.Hashtable; +class TypefaceCache { + private static TypefaceCache sInstance; + + private final HashMap mCache = new HashMap<>(); + + private final Context mApplication; + + private TypefaceCache(Context application) { + mApplication = application; + } + + /** + * If the cache has an instance for the typeface name, this will return the instance immediately. + * Otherwise this method will create typeface instance and put it into the cache and return the instance. + * @param name the typeface name. + * @return {} instance. + */ + public synchronized Font get(String name) { + Font typeface = mCache.get(name); + if(typeface == null) { + try { + typeface = createFontBuild(mApplication, name); + } catch (Exception exp) { + return null; + } + mCache.put(name, typeface); + } + return typeface; + } + + Font createFontBuild(Context context, String name) throws IOException { + ResourceManager resManager = context.getResourceManager(); + RawFileEntry rawFileEntry = resManager.getRawFileEntry("resources/rawfile/" + name); + Resource resource = null; + try { + resource = rawFileEntry.openRawFile(); + } catch (IOException e) { + LogUtil.i("Exception",e.getLocalizedMessage()); + } + StringBuilder fileName = new StringBuilder(name); + File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString()); + + try(OutputStream outputStream = new FileOutputStream(file)) { + int index; + byte[] bytes = new byte[1024]; + while ((index = resource.read(bytes)) != -1) { + outputStream.write(bytes, 0, index); + outputStream.flush(); + } + } catch (FileNotFoundException e) { + LogUtil.i("Exception",e.getLocalizedMessage()); + } finally { + if(resource != null){ + resource.close(); + } + } + Font.Builder builder = new Font.Builder(file); + return builder.build(); + } + + /** + * Retrieve this cache. + * @param context the context. + * @return the cache instance. + */ + public static synchronized TypefaceCache getInstance(Context context) { + if (sInstance == null) + sInstance = new TypefaceCache(context.getApplicationContext()); + return sInstance; + } +} diff --git a/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/TypefaceHelper.java b/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/TypefaceHelper.java new file mode 100644 index 0000000..8d68fd7 --- /dev/null +++ b/TypefaceHelper/src/main/java/com/drivemode/harmony/typeface/TypefaceHelper.java @@ -0,0 +1,528 @@ +package com.drivemode.harmony.typeface; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.AbilitySlice; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.agp.render.Paint; +import ohos.agp.text.Font; +import ohos.agp.window.dialog.BaseDialog; +import ohos.agp.window.dialog.ToastDialog; +import ohos.app.Context; + +import java.lang.reflect.Field; +import java.util.Objects; + +public final class TypefaceHelper { + public static final String TAG = TypefaceHelper.class.getSimpleName(); + private static TypefaceHelper sHelper; + private final Context mApplication; + private final TypefaceCache mCache; + + private TypefaceHelper(Context application) { + mApplication = application; + mCache = TypefaceCache.getInstance(application); + } + + public static synchronized void initialize(Context application) { + if (sHelper != null) { + LogUtil.d(TAG, "already initialized"); + } + sHelper = new TypefaceHelper(application); + } + + public static synchronized void destroy() { + if (sHelper == null) { + LogUtil.d(TAG, "not initialized yet"); + return; + } + sHelper = null; + } + + public static synchronized TypefaceHelper getInstance() { + if (sHelper == null) { + throw new IllegalArgumentException("Instance is not initialized yet. Call initialize() first."); + } + return sHelper; + } + + /** + * Fetches font instance from TypefaceCache + * @param typefaceName typeface name. + * @return requested typeface + */ + public Font getTypeface(String typefaceName){ + return mCache.get(typefaceName); + } + /** + * Set the typeface to the target view. + * @param view to set typeface. + * @param typefaceName typeface name. + * @param text view parameter. + */ + public void setTypeface(V view, String typefaceName) { + Font typeface = mCache.get(typefaceName); + view.setFont(typeface); + } + + /** + * Set the typeface to the target view. + * @param view to set typeface. + * @param strResId string resource containing typeface name. + * @param text view parameter. + */ + public void setTypeface(V view, int strResId) { + setTypeface(view, mApplication.getString(strResId)); + } + + /** + * Set the typeface to the target view. + * @param view to set typeface. + * @param typefaceName typeface name. + * @param style the typeface style. + * @param text view parameter. */ + + public void setTypeface(V view, String typefaceName, int style) { + LogUtil.d(TAG, "Style API not available : " + style); + Font typeface = mCache.get(typefaceName); + view.setFont(typeface); + } + + /** + * Set the typeface to the target view. + * @param view to set typeface. + * @param strResId string resource containing typeface name. + * @param style the typeface style. + * @param text view parameter.*/ + + public void setTypeface(V view, int strResId, int style) { + setTypeface(view, mApplication.getString(strResId), style); + } + + /** + * Set the typeface to the all text views belong to the view group. + * Note that this method recursively trace the child view groups and set typeface for the text views. + * @param viewGroup the view group that contains text views. + * @param typefaceName typeface name. + * @param view group parameter. + */ + public void setTypeface(V viewGroup, String typefaceName) { + int count = viewGroup.getChildCount(); + for (int i = 0; i < count; i++) { + Component child = viewGroup.getComponentAt(i); + if (child instanceof ComponentContainer) { + setTypeface((ComponentContainer) child, typefaceName); + continue; + } + if (!(child instanceof Text)) { + continue; + } + setTypeface((Text) child, typefaceName); + } + } + + /** + * Set the typeface to the all text views belong to the view group. + * Note that this method recursively trace the child view groups and set typeface for the text views. + * @param viewGroup the view group that contains text views. + * @param strResId string resource containing typeface name. + * @param view group parameter. + */ + public void setTypeface(V viewGroup, int strResId) { + setTypeface(viewGroup, mApplication.getString(strResId)); + } + + /** + * Set the typeface to the all text views belong to the view group. + * Note that this method recursively trace the child view groups and set typeface for the text views. + * @param viewGroup the view group that contains text views. + * @param typefaceName typeface name. + * @param style the typeface style. + * @param view group parameter. + */ + public void setTypeface(V viewGroup, String typefaceName, int style) { + int count = viewGroup.getChildCount(); + for (int i = 0; i < count; i++) { + Component child = viewGroup.getComponentAt(i); + if (child instanceof ComponentContainer) { + setTypeface((ComponentContainer) child, typefaceName, style); + continue; + } + if (!(child instanceof Text)) { + continue; + } + + setTypeface((Text) child, typefaceName, style); + } + } + + /** + * Set the typeface to the all text views belong to the view group. + * Note that this method recursively trace the child view groups and set typeface for the text views. + * @param viewGroup the view group that contains text views. + * @param strResId string resource containing typeface name. + * @param style the typeface style. + * @param view group parameter. + */ + public void setTypeface(V viewGroup, int strResId, int style) { + setTypeface(viewGroup, mApplication.getString(strResId), style); + } + + /** + * Set the typeface to the target paint. + * @param paint the set typeface. + * @param typefaceName typeface name. + */ + public void setTypeface(Paint paint, String typefaceName) { + Font typeface = mCache.get(typefaceName); + paint.setFont(typeface); + } + + /** + * Set the typeface to the target paint. + * @param paint the set typeface. + * @param strResId string resource containing typeface name. + */ + public void setTypeface(Paint paint, int strResId) { + setTypeface(paint, mApplication.getString(strResId)); + } + + /** + * Set the typeface to the all text views belong to the view group. + * @param context the context. + * @param layoutRes the layout resource id. + * @param typefaceName typeface name. + * @return the view. + */ + public Component setTypeface(Context context, int layoutRes, String typefaceName) { + return setTypeface(context, layoutRes, null, typefaceName); + } + + /** + * Set the typeface to the all text views belong to the view group. + * @param context the context. + * @param layoutRes the layout resource id. + * @param parent the parent view group to attach the layout. + * @param typefaceName typeface name. + * @return the view. + */ + public Component setTypeface(Context context, int layoutRes, ComponentContainer parent, String typefaceName) { + ComponentContainer view = (ComponentContainer) + LayoutScatter.getInstance(context).parse(layoutRes, parent, false); + setTypeface(view, typefaceName); + return view; + } + + /** + * Set the typeface to the all text views belong to the view group. + * @param context the context. + * @param layoutRes the layout resource id. + * @param parent the parent view group to attach the layout. + * @param strResId string resource containing typeface name. + * @return the view. + */ + public Component setTypeface(Context context, int layoutRes, ComponentContainer parent, int strResId) { + return setTypeface(context, layoutRes, parent, mApplication.getString(strResId)); + } + + /** + * Set the typeface to the all text views belong to the view group. + * @param context the context. + * @param layoutRes the layout resource id. + * @param typefaceName typeface name. + * @param style the typeface style. + * @return the view. + */ + public Component setTypeface(Context context, int layoutRes, String typefaceName, int style) { + LogUtil.d(TAG, "Style API un-available : " + style); + return setTypeface(context, layoutRes, null, typefaceName, 0); + } + + /** + * Set the typeface to the all text views belong to the view group. + * @param context the context. + * @param layoutRes the layout resource id. + * @param strResId string resource containing typeface name. + * @param style the typeface style. + * @return the view. + */ + public Component setTypeface(Context context, int layoutRes, int strResId, int style) { + LogUtil.d(TAG, "Style API unavailable : " + style); + return setTypeface(context, layoutRes, mApplication.getString(strResId), 0); + } + + /** + * Set the typeface to the all text views belong to the view group. + * @param context the context. + * @param layoutRes the layout resource id. + * @param parent the parent view group to attach the layout. + * @param typefaceName typeface name. + * @param style the typeface style. + * @return the view. + */ + public Component setTypeface(Context context, int layoutRes, ComponentContainer parent, String typefaceName, int style) { + ComponentContainer view = (ComponentContainer) + LayoutScatter.getInstance(context).parse(layoutRes, parent,false); + setTypeface(view, typefaceName, style); + return view; + } + + /** + * Set the typeface to the all text views belong to the view group. + * @param context the context. + * @param layoutRes the layout resource id. + * @param parent the parent view group to attach the layout. + * @param strResId string resource containing typeface name. + * @param style the typeface style. + * @return the view. + */ + public Component setTypeface(Context context, int layoutRes, ComponentContainer parent, int strResId, int style) { + return setTypeface(context, layoutRes, parent, mApplication.getString(strResId), style); + } + + /** + * Set the typeface to the all text views belong to the activity. + * Note that we use decor view of the activity so that the typeface will also be applied to action bar. + * @param activity the activity. + * @param typefaceName typeface name. + */ + public void setTypeface(AbilitySlice activity, String typefaceName) { + setTypeface(activity, typefaceName, 0); + } + + /** + * Set the typeface to the all text views belong to the activity. + * Note that we use decor view of the activity so that the typeface will also be applied to action bar. + * @param activity the activity. + * @param strResId string resource containing typeface name. + */ + public void setTypeface(AbilitySlice activity, int strResId) { + setTypeface(activity, mApplication.getString(strResId)); + } + + /** + * Set the typeface to the all text views belong to the activity. + * Note that we use decor view of the activity so that the typeface will also be applied to action bar. + * @param activity the activity. + * @param typefaceName typeface name. + * @param style the typeface style. + */ + public void setTypeface(AbilitySlice activity, String typefaceName, int style) { + setTypeface((ComponentContainer) Objects.requireNonNull(getCurrentComponentContainer(activity)), typefaceName, style); + } + + public static Component getCurrentComponentContainer(AbilitySlice abilitySlice){ + try{ + Field uiContent = AbilitySlice.class.getDeclaredField("uiContent"); + uiContent.setAccessible(true); + Object uiContentObj = uiContent.get(abilitySlice); + LogUtil.i("Gowtham uiContentObj : " , uiContentObj.toString()); + + Field curComponentContainer = uiContentObj.getClass().getSuperclass() + .getDeclaredField("curComponentContainer"); + curComponentContainer.setAccessible(true); + Object curComponentContainerObj = curComponentContainer.get(uiContentObj); + + LogUtil.i("Gowtham curComponentContainerObj : " , curComponentContainerObj.toString()); + + + return (Component) curComponentContainerObj; + + } catch (NoSuchFieldException | IllegalAccessException | NullPointerException e) { + LogUtil.i("Exception",e.getLocalizedMessage()); + } + + return null; + } + + /** + * Set the typeface to the all text views belong to the activity. + * Note that we use decor view of the activity so that the typeface will also be applied to action bar. + * @param activity the activity. + * @param strResId string resource containing typeface name. + * @param style the typeface style. + */ + public void setTypeface(AbilitySlice activity, int strResId, int style) { + setTypeface(activity, mApplication.getString(strResId), style); + } + + /** + * Set the typeface to the all text views belong to the fragment. + * Make sure to call this method after fragment view creation. + * If you use fragments in the support package, + * call {@link com.drivemode.harmony.typeface.TypefaceHelper#supportSetTypeface(ohos.aafwk.ability.fraction.Fraction, String)} instead. + * @param fragment the fragment. + * @param typefaceName typeface name. + */ + public void setTypeface(F fragment, String typefaceName) { + setTypeface(fragment, typefaceName, 0); + } + + /** + * Set the typeface to the all text views belong to the fragment. + * Make sure to call this method after fragment view creation. + * If you use fragments in the support package, + * call {@link com.drivemode.harmony.typeface.TypefaceHelper#supportSetTypeface(ohos.aafwk.ability.fraction.Fraction, String)} instead. + * @param fragment the fragment. + * @param strResId string resource containing typeface name. + */ + public void setTypeface(F fragment, int strResId) { + setTypeface(fragment, mApplication.getString(strResId)); + } + + /** + * Set the typeface to the all text views belong to the fragment. + * Make sure to call this method after fragment view creation. + * If you use fragments in the support package, + * call {@link com.drivemode.harmony.typeface.TypefaceHelper#supportSetTypeface(ohos.aafwk.ability.fraction.Fraction, String, int)} instead. + * @param fragment the fragment. + * @param typefaceName typeface name. + * @param style the typeface style. + */ + public void setTypeface(F fragment, String typefaceName, int style) { + Component root = fragment.getComponent(); + if (root instanceof Text) { + setTypeface((Text) root, typefaceName, style); + } else if (root instanceof ComponentContainer) { + setTypeface((ComponentContainer) root, typefaceName, style); + } + } + + /** + * Set the typeface to the all text belong to the fragment. + * Make sure to call this method after fragment view creation. + * If you use fragments in the support package, + * call {@link com.drivemode.harmony.typeface.TypefaceHelper#supportSetTypeface(ohos.aafwk.ability.fraction.Fraction, String, int)} instead. + * @param fragment the fragment. + * @param strResId string resource containing typeface name. + * @param style the typeface style. + */ + public void setTypeface(F fragment, int strResId, int style) { + setTypeface(fragment, mApplication.getString(strResId), style); + } + + /** + * Set the typeface to the all text views belong to the fragment. + * Make sure to call this method after fragment view creation. + * And this is a support package fragments only. + * @param fragment the fragment. + * @param typefaceName typeface name. + */ + public void supportSetTypeface(F fragment, String typefaceName) { + supportSetTypeface(fragment, typefaceName, 0); + } + + /** + * Set the typeface to the all text views belong to the fragment. + * Make sure to call this method after fragment view creation. + * And this is a support package fragments only. + * @param fragment the fragment. + * @param strResId string resource containing typeface name. + */ + public void supportSetTypeface(F fragment, int strResId) { + supportSetTypeface(fragment, mApplication.getString(strResId)); + } + + /** + * Set the typeface to the all text views belong to the fragment. + * Make sure to call this method after fragment view creation. + * And this is a support package fragments only. + * @param fragment the fragment. + * @param typefaceName typeface name. + * @param style the typeface style. + */ + public void supportSetTypeface(F fragment, String typefaceName, int style) { + Component root = fragment.getComponent(); + if (root instanceof Text) { + setTypeface((Text) root, typefaceName, style); + } else if (root instanceof ComponentContainer) { + setTypeface((ComponentContainer) root, typefaceName, style); + } + } + + /** + * Set the typeface to the all text views belong to the fragment. + * Make sure to call this method after fragment view creation. + * And this is a support package fragments only. + * @param fragment the fragment. + * @param strResId string resource containing typeface name. + * @param style the typeface style. + */ + public void supportSetTypeface(F fragment, int strResId, int style) { + supportSetTypeface(fragment, mApplication.getString(strResId), style); + } + + /** + * Set the typeface for the dialog view. + * @param dialog the dialog. + * @param typefaceName typeface name. + */ + public void setTypeface(D dialog, String typefaceName) { + setTypeface(dialog, typefaceName, 0); + } + + /** + * Set the typeface for the dialog view. + * @param dialog the dialog. + * @param typefaceName typeface name. + * @param style the typeface style. + */ + public void setTypeface(D dialog, String typefaceName, int style) { + DialogUtils.setTypeface(this, dialog, typefaceName, style); + } + + /** + * Set the typeface for the dialog view. + * @param dialog the dialog. + * @param strResId string resource containing typeface name. + * @param style the typeface style. + */ + public void setTypeface(D dialog, int strResId, int style) { + setTypeface(dialog, mApplication.getString(strResId), style); + } + + /** + * Set the typeface for the toast view. + * @param toast toast. + * @param typefaceName typeface name. + * @return toast that the typeface is injected. + */ + public ToastDialog setTypeface(ToastDialog toast, String typefaceName) { + return setTypeface(toast, typefaceName, 0); + } + + /** + * Set the typeface for the toast view. + * @param toast toast. + * @param strResId string resource containing typeface name. + * @return toast that the typeface is injected. + */ + public ToastDialog setTypeface(ToastDialog toast, int strResId) { + return setTypeface(toast, mApplication.getString(strResId)); + } + + /** + * Set the typeface for the toast view. + * @param toast toast. + * @param typefaceName typeface name. + * @param style the typeface style. + * @return toast that the typeface is injected. + */ + public ToastDialog setTypeface(ToastDialog toast, String typefaceName, int style) { + setTypeface((ComponentContainer) toast.getComponent(), typefaceName, style); + return toast; + } + + /** + * Set the typeface for the toast view. + * @param toast toast. + * @param strResId string resource containing typeface name. + * @param style the typeface style. + * @return toast that the typeface is injected. + */ + public ToastDialog setTypeface(ToastDialog toast, int strResId, int style) { + return setTypeface(toast, mApplication.getString(strResId), style); + } +} diff --git a/TypefaceHelper/src/main/res/.gitkeep b/TypefaceHelper/src/main/res/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/TypefaceHelper/src/main/resources/base/element/string.json b/TypefaceHelper/src/main/resources/base/element/string.json new file mode 100644 index 0000000..ace4210 --- /dev/null +++ b/TypefaceHelper/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "TypefaceHelper_library", + "value": "TypefaceHelper_library" + } + ] +} diff --git a/build.gradle b/build.gradle index 63abfc6..0bbb383 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,69 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' +apply plugin: 'org.sonarqube' +apply plugin: 'checkstyle' + +//For instructions on signature configuration, see https://developer.harmonyos.com/en/docs/documentation/doc-guides/ide_debug_device-0000001053822404#EN-US_TOPIC_0000001154985555__section1112183053510 +ohos { + + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} buildscript { repositories { - google() + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.4' + classpath 'com.huawei.ohos:hap:2.4.4.2' + classpath 'com.huawei.ohos:decctest:1.2.4.0' + classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3" } } allprojects { repositories { - google() + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } jcenter() } + + task checkstyle(type: Checkstyle) { + showViolations = true + configFile file("config/checkstyle.xml") + + source 'entry/src/main/java' + source 'TypefaceHelper/src/main/java' + include '**/*.java' + + // empty classpath + classpath = files() + } +} + +checkstyle { + toolVersion "8.43" +} + +sonarqube { + properties { + property "sonar.projectKey", "applibgroup_TypefaceHelper" + property "sonar.organization", "applibgroup" + property "sonar.host.url", "https://sonarcloud.io" + property "sonar.sources", "entry,TypefaceHelper" + property "sonar.java.binaries", "entry/build,TypefaceHelper/build" + property "sonar.java.checkstyle.reportPaths", "build/reports/checkstyle/checkstyle.xml" + } } diff --git a/build.gradle.bak b/build.gradle.bak new file mode 100644 index 0000000..5dcda7a --- /dev/null +++ b/build.gradle.bak @@ -0,0 +1,49 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +//For instructions on signature configuration, see https://developer.harmonyos.com/en/docs/documentation/doc-guides/ide_debug_device-0000001053822404#EN-US_TOPIC_0000001154985555__section1112183053510 +ohos { + signingConfigs { + debug { + storeFile file('C:\\Users\\admin\\.ohos\\config\\auto_debug_2640091000002771297.p12') + storePassword '0000001882F20250D4AEDE78D57C27DA9FB07F765461BCC74B4DC3419DEA54125838C7814FCF4E9B' + keyAlias = 'debugKey' + keyPassword '0000001801459838DA68DF30FFE0D3A383F652138EAD89225951F55AE147415FCFA851A11D05DD84' + signAlg = 'SHA256withECDSA' + profile file('C:\\Users\\admin\\.ohos\\config\\auto_debug_typefacemaster_2640091000002771297.p7b') + certpath file('C:\\Users\\admin\\.ohos\\config\\auto_debug_2640091000002771297.cer') + } + } + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.4.2' + classpath 'com.huawei.ohos:decctest:1.2.4.0' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/circle.yml b/circle.yml deleted file mode 100644 index d884f7b..0000000 --- a/circle.yml +++ /dev/null @@ -1,20 +0,0 @@ -machine: - environment: - ANDROID_HOME: /usr/local/android-sdk-linux - -dependencies: - pre: - - echo y | android update sdk --no-ui --all --filter "platform-tools,tools" - - echo y | android update sdk --no-ui --all --filter "android-23,build-tools-23.0.2" - - echo y | android update sdk --no-ui --all --filter "extra-android-m2repository" - - echo y | android update sdk --no-ui --all --filter "extra-android-support" - - echo y | android update sdk --no-ui --all --filter "extra-google-m2repository" - - cache_directories: - - ~/.android - override: - - ./gradlew dependencies - -test: - override: - - ./gradlew clean build -PdisablePreDex diff --git a/sample/.gitignore b/entry/.gitignore similarity index 100% rename from sample/.gitignore rename to entry/.gitignore diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000..bca6efd --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/en/docs/documentation/doc-guides/ide_debug_device-0000001053822404#EN-US_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + implementation project(':TypefaceHelper') + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html','xml'] +} diff --git a/entry/proguard-rules.pro b/entry/proguard-rules.pro new file mode 100644 index 0000000..f7666e4 --- /dev/null +++ b/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/entry/src/main/config.json b/entry/src/main/config.json new file mode 100644 index 0000000..9a95f64 --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,47 @@ +{ + "app": { + "bundleName": "com.example.typefacemaster", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.typefacemaster", + "name": ".MyApplication", + "mainAbility": "com.example.typefacemaster.MainAbility", + "deviceType": [ + "phone", + "tablet" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.example.typefacemaster.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/example/typefacemaster/MainAbility.java b/entry/src/main/java/com/example/typefacemaster/MainAbility.java new file mode 100644 index 0000000..6fc845e --- /dev/null +++ b/entry/src/main/java/com/example/typefacemaster/MainAbility.java @@ -0,0 +1,36 @@ +package com.example.typefacemaster; + + +import com.drivemode.harmony.typeface.TypefaceHelper; +import com.example.typefacemaster.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.*; +import ohos.agp.components.element.Element; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.utils.TextAlignment; +import ohos.agp.window.dialog.BaseDialog; +import ohos.agp.window.dialog.ToastDialog; +import ohos.app.Context; +import ohos.global.resource.NotExistException; +import ohos.global.resource.ResourceManager; +import ohos.global.resource.WrongTypeException; + +import java.io.IOException; + +public class MainAbility extends Ability { + + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getCanonicalName()); + + } + + +} + diff --git a/entry/src/main/java/com/example/typefacemaster/MyApplication.java b/entry/src/main/java/com/example/typefacemaster/MyApplication.java new file mode 100644 index 0000000..a249bfa --- /dev/null +++ b/entry/src/main/java/com/example/typefacemaster/MyApplication.java @@ -0,0 +1,18 @@ +package com.example.typefacemaster; + +import com.drivemode.harmony.typeface.TypefaceHelper; +import ohos.aafwk.ability.AbilityPackage; + +public abstract class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + TypefaceHelper.initialize(this); + } + + @Override + public void onEnd() { + super.onEnd(); + TypefaceHelper.destroy(); + } +} diff --git a/entry/src/main/java/com/example/typefacemaster/slice/MainAbilitySlice.java b/entry/src/main/java/com/example/typefacemaster/slice/MainAbilitySlice.java new file mode 100644 index 0000000..dc241d1 --- /dev/null +++ b/entry/src/main/java/com/example/typefacemaster/slice/MainAbilitySlice.java @@ -0,0 +1,128 @@ +package com.example.typefacemaster.slice; + +import com.drivemode.harmony.typeface.TypefaceHelper; +import com.example.typefacemaster.ResourceTable; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.*; +import ohos.agp.components.element.Element; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.utils.TextAlignment; +import ohos.agp.window.dialog.ToastDialog; + +public class MainAbilitySlice extends AbilitySlice { + + private static final String TYPEFACE_NAME = "Isserley-Regular.ttf"; + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + TypefaceHelper.initialize(this); + TypefaceHelper.getInstance().setTypeface(this, TYPEFACE_NAME); + + ListContainer lv = (ListContainer) findComponentById(ResourceTable.Id_list_container); + MainListProvider listProvider = new MainListProvider(getStringArray(ResourceTable.Strarray_sample_list)); + + lv.setItemProvider(listProvider); + lv.setItemClickedListener(new ListContainer.ItemClickedListener() { + @Override + public void onItemClicked(ListContainer listContainer, Component component, int i, long l) { + ToastDialog toastDialog = createToast("pos: " + i); + TypefaceHelper.getInstance().setTypeface( + toastDialog, + TYPEFACE_NAME).show(); + } + }); + + + } + + /** + * The type Main list provider. + */ + public class MainListProvider extends BaseItemProvider { + /** + * The List items. + */ + String[] listItems; + + /** + * Instantiates a new Main list provider. + * + * @param lst the lst + */ + MainListProvider(String[] lst) { + listItems = lst; + } + + @Override + public int getCount() { + return listItems.length; + } + + @Override + public Object getItem(int position) { + return listItems[position]; + } + + @Override + public long getItemId(int position) { + return 0; + } + + @Override + public Component getComponent(int position, Component component, ComponentContainer componentContainer) { + Component convertView = component; + if (convertView == null) { + convertView = LayoutScatter.getInstance(getContext()).parse + (ResourceTable.Layout_list_item, componentContainer, false); + } + ((Text) (convertView.findComponentById(ResourceTable.Id_list_component))).setText + ((String) getItem(position)); + TypefaceHelper.getInstance().setTypeface((Text) convertView, TYPEFACE_NAME); + convertView.setClickable(false); + return convertView; + } + } + + @Override + protected void onStop() { + super.onStop(); + TypefaceHelper.destroy(); + } + + public ToastDialog createToast(String str) { + Text text = new Text(this); + text.setWidth(ComponentContainer.LayoutConfig.MATCH_PARENT); + text.setHeight(ComponentContainer.LayoutConfig.MATCH_CONTENT); + text.setTextSize(48); + text.setText(str); + text.setMultipleLine(true); + text.setTextAlignment(TextAlignment.CENTER); + ShapeElement shapeElement = (ShapeElement) buildDrawableByColor(Color.WHITE.getValue()); + text.setBackground(shapeElement); + DirectionalLayout directionalLayout = new DirectionalLayout(this); + directionalLayout.setBackground(shapeElement); + DirectionalLayout.LayoutConfig layoutConfig = new DirectionalLayout.LayoutConfig + (DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT); + layoutConfig.setMarginBottom(100); + directionalLayout.setLayoutConfig(layoutConfig); + directionalLayout.setPadding(20, 30, 20, 30); + directionalLayout.addComponent(text); + ToastDialog toastDialog = new ToastDialog(this); + toastDialog.setComponent(directionalLayout); + toastDialog.setAlignment(LayoutAlignment.BOTTOM).setTransparent(true); + return toastDialog; + } + + public static Element buildDrawableByColor(int color) { + ShapeElement drawable = new ShapeElement(); + drawable.setShape(ShapeElement.RECTANGLE); + drawable.setRgbColor(RgbColor.fromArgbInt(color)); + return drawable; + } +} diff --git a/entry/src/main/resources/base/element/dimens.json b/entry/src/main/resources/base/element/dimens.json new file mode 100644 index 0000000..76bf4bb --- /dev/null +++ b/entry/src/main/resources/base/element/dimens.json @@ -0,0 +1,44 @@ +{ + "float": [ + { + "name": "default_circle_indicator_stroke_width", + "value": "1vp" + }, + { + "name": "default_circle_indicator_radius", + "value": "3vp" + }, + { + "name": "default_title_indicator_footer_line_height", + "value": "2vp" + }, + { + "name": "default_title_indicator_footer_indicator_height", + "value": "4vp" + }, + { + "name": "default_title_indicator_footer_indicator_underline_padding", + "value": "20vp" + }, + { + "name": "default_title_indicator_footer_padding", + "value": "7vp" + }, + { + "name": "default_title_indicator_text_size", + "value": "15vp" + }, + { + "name": "default_title_indicator_title_padding", + "value": "5vp" + }, + { + "name": "default_title_indicator_clip_padding", + "value": "4vp" + }, + { + "name": "default_title_indicator_top_padding", + "value": "7vp" + } + ] +} diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000..00ccc62 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "Hello", + "value": "Hello" + }, + { + "name": "hello_world", + "value": "Hello World" + }, + { + "name": "app_name", + "value": "App Name" + }, + { + "name": "welcome", + "value": "Welcome" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/stringarray.json b/entry/src/main/resources/base/element/stringarray.json new file mode 100644 index 0000000..8ed7863 --- /dev/null +++ b/entry/src/main/resources/base/element/stringarray.json @@ -0,0 +1,45 @@ +{ + "strarray": [ + { + "name": "sample_list", + "value": [ + { + "value": "Foo" + }, + { + "value": "Bar" + }, + { + "value": "Baz" + }, + { + "value": "Qux" + }, + { + "value": "Quux" + }, + { + "value": "Hoge" + }, + { + "value": "Fuga" + }, + { + "value": "Piyo" + }, + { + "value": "Hoge" + }, + { + "value": "Alice" + }, + { + "value": "Bob" + }, + { + "value": "Charlie" + } + ] + } + ] +} diff --git a/entry/src/main/resources/base/graphic/background_ability_main.xml b/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 0000000..c0c0a3d --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 0000000..d907889 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/list_item.xml b/entry/src/main/resources/base/layout/list_item.xml new file mode 100644 index 0000000..bbe1f6d --- /dev/null +++ b/entry/src/main/resources/base/layout/list_item.xml @@ -0,0 +1,9 @@ + + diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000..ce307a8 Binary files /dev/null and b/entry/src/main/resources/base/media/icon.png differ diff --git a/entry/src/main/resources/en/element/string.json b/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000..bcf9f99 --- /dev/null +++ b/entry/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/sample/src/main/assets/Isserley-Regular.ttf b/entry/src/main/resources/rawfile/Isserley-Regular.ttf similarity index 100% rename from sample/src/main/assets/Isserley-Regular.ttf rename to entry/src/main/resources/rawfile/Isserley-Regular.ttf diff --git a/entry/src/main/resources/zh/element/string.json b/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000..fdc4bd1 --- /dev/null +++ b/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/entry/src/ohosTest/java/com/example/typefacemaster/ExampleOhosTest.java b/entry/src/ohosTest/java/com/example/typefacemaster/ExampleOhosTest.java new file mode 100644 index 0000000..754b587 --- /dev/null +++ b/entry/src/ohosTest/java/com/example/typefacemaster/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.example.typefacemaster; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.example.typefacemaster", actualBundleName); + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 194a388..be49249 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,33 +1,13 @@ # Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Settings specified in this file will override any Gradle settings -# configured through the IDE. - +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html - # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true - -VERSION_NAME=1.2.2 -VERSION_CODE=5 -GROUP=com.drivemode - -POM_DESCRIPTION=Helper object for injecting typeface into various text views of android. -POM_URL=https://github.com/Drivemode/TypefaceHelper -POM_SCM_URL=https://github.com/Drivemode/TypefaceHelper -POM_SCM_CONNECTION=scm:git@github.com:Drivemode/TypefaceHelper.git -POM_SCM_DEV_CONNECTION=scm:git@github.com:Drivemode/TypefaceHelper.git -POM_LICENCE_NAME=The Apache Software License, Version 2.0 -POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt -POM_LICENCE_DIST=repo -POM_DEVELOPER_ID=drivemode -POM_DEVELOPER_NAME=Drivemode,Inc. +# If the Chinese output is garbled, please configure the following parameter. +# This function is enabled by default when the DevEco Studio builds the hap/app,if you need disable gradle parallel,you should set org.gradle.parallel false. +# more information see https://docs.gradle.org/current/userguide/performance.html +# org.gradle.parallel=false +# org.gradle.jvmargs=-Dfile.encoding=GBK \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 8c0fb64..490fda8 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b235932..f59159e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Thu Apr 02 16:06:55 JST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip diff --git a/gradlew b/gradlew index 91a7e26..536f027 100644 --- a/gradlew +++ b/gradlew @@ -1,4 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# 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 +# +# https://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. +# ############################################################################## ## @@ -6,159 +22,162 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ]; do + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' >/dev/null; then + PRG="$link" + else + PRG=$(dirname "$PRG")"/$link" + fi +done +SAVED="$(pwd)" +cd "$(dirname \"$PRG\")/" >/dev/null +APP_HOME="$(pwd -P)" +cd "$SAVED" >/dev/null APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=$(basename "$0") + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { - echo "$*" +warn() { + echo "$*" } -die ( ) { - echo - echo "$*" - echo - exit 1 +die() { + echo + echo "$*" + echo + exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; +nonstop=false +case "$(uname)" in +CYGWIN*) + cygwin=true + ;; +Darwin*) + darwin=true + ;; +MINGW*) + msys=true + ;; +NONSTOP*) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME +if [ -n "$JAVA_HOME" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ]; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi + fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ]; then + MAX_FD_LIMIT=$(ulimit -H -n) + if [ $? -eq 0 ]; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then + MAX_FD="$MAX_FD_LIMIT" fi + ulimit -n $MAX_FD + if [ $? -ne 0 ]; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ]; then + APP_HOME=$(cygpath --path --mixed "$APP_HOME") + CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") + JAVACMD=$(cygpath --unix "$JAVACMD") + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=$(find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null) + SEP="" + for dir in $ROOTDIRSRAW; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ]; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@"; do + CHECK=$(echo "$arg" | egrep -c "$OURCYGPATTERN" -) + CHECK2=$(echo "$arg" | egrep -c "^-") ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ]; then ### Added a condition + eval $(echo args$i)=$(cygpath --path --ignore --mixed "$arg") + else + eval $(echo args$i)="\"$arg\"" fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac + i=$(expr $i + 1) + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save() { + for i; do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 8a0b282..62bd9b9 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -8,14 +24,17 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +65,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +78,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/sample/build.gradle b/sample/build.gradle deleted file mode 100644 index 9dda719..0000000 --- a/sample/build.gradle +++ /dev/null @@ -1,20 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 28 - - defaultConfig { - applicationId "com.drivemode.android.typeface.sample" - minSdkVersion 15 - targetSdkVersion 28 - versionCode 1 - versionName "1.0" - } -} - -dependencies { - api fileTree(dir: 'libs', include: ['*.jar']) - api project(':TypefaceHelper') - api 'com.android.support:support-v4:28.0.0-rc01' - api 'com.android.support:appcompat-v7:28.0.0-rc01' -} diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro deleted file mode 100644 index 200fdff..0000000 --- a/sample/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /usr/local/Cellar/android-sdk/22.6.2/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/sample/src/androidTest/java/com/drivemode/android/typeface/sample/ApplicationTest.java b/sample/src/androidTest/java/com/drivemode/android/typeface/sample/ApplicationTest.java deleted file mode 100644 index 7ddfe02..0000000 --- a/sample/src/androidTest/java/com/drivemode/android/typeface/sample/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.drivemode.android.typeface.sample; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml deleted file mode 100644 index 7c60d7e..0000000 --- a/sample/src/main/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - diff --git a/sample/src/main/java/com/drivemode/android/typeface/sample/MainActivity.java b/sample/src/main/java/com/drivemode/android/typeface/sample/MainActivity.java deleted file mode 100644 index 96f34df..0000000 --- a/sample/src/main/java/com/drivemode/android/typeface/sample/MainActivity.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.drivemode.android.typeface.sample; - -import android.annotation.SuppressLint; -import android.os.Bundle; -import android.support.v4.app.FragmentTransaction; -import android.support.v7.app.ActionBar; -import android.support.v7.app.ActionBarActivity; -import android.view.Menu; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.TextView; -import android.widget.Toast; - -import com.drivemode.android.typeface.TypefaceHelper; - -/** - * @author KeithYokoma - */ -public class MainActivity extends ActionBarActivity implements ActionBar.TabListener { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - ActionBar actionBar = getSupportActionBar(); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); - actionBar.addTab(actionBar.newTab().setText("Hoge").setTabListener(this)); - actionBar.addTab(actionBar.newTab().setText("Fuga").setTabListener(this)); - - ListView lv = (ListView) findViewById(R.id.list_view); - lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, - android.R.id.text1, getResources().getStringArray(R.array.sample_list)) { - @Override - public View getView(int position, View convertView, ViewGroup parent) { - View view = super.getView(position, convertView, parent); - TypefaceHelper.getInstance().setTypeface((TextView) view, "Isserley-Regular.ttf"); - return view; - } - }); - lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @SuppressLint("ShowToast") - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - TypefaceHelper.getInstance().setTypeface( - Toast.makeText(MainActivity.this.getApplicationContext(), - "pos: " + position, - Toast.LENGTH_LONG), - "Isserley-Regular.ttf").show(); - } - }); - - // You can also pass the typeface name stored in a string resource - TypefaceHelper.getInstance().setTypeface(this, R.string.font_primary); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.main, menu); - return true; - } - - @Override - public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {} - - @Override - public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {} - - @Override - public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {} -} diff --git a/sample/src/main/java/com/drivemode/android/typeface/sample/SampleApp.java b/sample/src/main/java/com/drivemode/android/typeface/sample/SampleApp.java deleted file mode 100644 index 2813800..0000000 --- a/sample/src/main/java/com/drivemode/android/typeface/sample/SampleApp.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.drivemode.android.typeface.sample; - -import android.app.Application; - -import com.drivemode.android.typeface.TypefaceHelper; - -/** - * @author KeithYokoma - */ -public class SampleApp extends Application { - @Override - public void onCreate() { - super.onCreate(); - TypefaceHelper.initialize(this); - } - - @Override - public void onTerminate() { - TypefaceHelper.destroy(); - super.onTerminate(); - } -} diff --git a/sample/src/main/res/drawable-hdpi/ic_launcher.png b/sample/src/main/res/drawable-hdpi/ic_launcher.png deleted file mode 100644 index 96a442e..0000000 Binary files a/sample/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/drawable-mdpi/ic_launcher.png b/sample/src/main/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index 359047d..0000000 Binary files a/sample/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xhdpi/ic_launcher.png b/sample/src/main/res/drawable-xhdpi/ic_launcher.png deleted file mode 100644 index 71c6d76..0000000 Binary files a/sample/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xxhdpi/ic_launcher.png b/sample/src/main/res/drawable-xxhdpi/ic_launcher.png deleted file mode 100644 index 4df1894..0000000 Binary files a/sample/src/main/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml deleted file mode 100644 index 8bedbd0..0000000 --- a/sample/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/sample/src/main/res/menu/main.xml b/sample/src/main/res/menu/main.xml deleted file mode 100644 index 2868df6..0000000 --- a/sample/src/main/res/menu/main.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - diff --git a/sample/src/main/res/values-w820dp/dimens.xml b/sample/src/main/res/values-w820dp/dimens.xml deleted file mode 100644 index 63fc816..0000000 --- a/sample/src/main/res/values-w820dp/dimens.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - 64dp - diff --git a/sample/src/main/res/values/dimens.xml b/sample/src/main/res/values/dimens.xml deleted file mode 100644 index 47c8224..0000000 --- a/sample/src/main/res/values/dimens.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - 16dp - 16dp - diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml deleted file mode 100644 index 235a47f..0000000 --- a/sample/src/main/res/values/strings.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - Sample App - Hello world! - Settings - - - Foo - Bar - Baz - Qux - Quux - Hoge - Fuga - Piyo - Hoge - Alice - Bob - Charlie - Dave - Ellen - Frank - - - Isserley-Regular.ttf - diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml deleted file mode 100644 index 00a7ff8..0000000 --- a/sample/src/main/res/values/styles.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/settings.gradle b/settings.gradle index 2ecca1a..8a8b8ac 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':TypefaceHelper', ':sample' +include ':entry', ':TypefaceHelper'