Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 15 additions & 47 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion LICENSE.md → LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
154 changes: 87 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,121 +1,141 @@
# 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!

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
Expand Down
32 changes: 16 additions & 16 deletions TypefaceHelper/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions TypefaceHelper/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Add har specific ProGuard rules for consumer here.
3 changes: 0 additions & 3 deletions TypefaceHelper/gradle.properties

This file was deleted.

18 changes: 1 addition & 17 deletions TypefaceHelper/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 0 additions & 5 deletions TypefaceHelper/src/main/AndroidManifest.xml

This file was deleted.

24 changes: 24 additions & 0 deletions TypefaceHelper/src/main/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Loading