Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dyslexia Font Selector #10

Merged
merged 8 commits into from
Dec 3, 2020
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
15 changes: 3 additions & 12 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion app/src/main/java/com/ambinusian/adab/all/ActivityLive.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.Build;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
Expand Down Expand Up @@ -97,8 +98,9 @@ protected void onCreate(Bundle savedInstanceState) {
//scroll always to bottom
textContent.setMovementMethod(new ScrollingMovementMethod());

//set all Text Size
// set text attributes
setTextSize();
setTextTypeface();

apiManager.getClassDetails(userPreferences.getUserToken(), sessionId, new NetworkHelper.getClassDetails() {
@Override
Expand Down Expand Up @@ -325,4 +327,16 @@ private void setTextSize(){
courseTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, courseTitle.getTextSize() * textSize);
toolbarTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, toolbarTitle.getTextSize() * textSize);
}

private void setTextTypeface(){
//get font type
Typeface textTypeface = userPreferences.getTextTypeface();
//set font type for each text view
className.setTypeface(textTypeface, className.getTypeface().getStyle());
classSession.setTypeface(textTypeface, classSession.getTypeface().getStyle());
textContent.setTypeface(textTypeface, textContent.getTypeface().getStyle());
textLiveNow.setTypeface(textTypeface, textLiveNow.getTypeface().getStyle());
courseTitle.setTypeface(textTypeface, courseTitle.getTypeface().getStyle());
toolbarTitle.setTypeface(textTypeface, toolbarTitle.getTypeface().getStyle());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class HeadlineView extends RelativeLayout {

public HeadlineView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context,attrs);
init(context, attrs);
}

public void init(Context context, AttributeSet attrs){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ambinusian.adab.expandablenavigationdrawer;

import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.TypedValue;
Expand All @@ -23,6 +24,7 @@ public class ExpandableListAdapter extends BaseExpandableListAdapter {
HashMap<MenuModel,List<MenuModel>> childList;
UserPreferences userPreferences;
float defaultMenuTextSize = -1;
Typeface defaultMenuTextTypeface = null;

public ExpandableListAdapter(Context context, List<MenuModel> groupList, HashMap<MenuModel, List<MenuModel>> childList) {
this.context = context;
Expand Down Expand Up @@ -111,6 +113,9 @@ public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
mMenuName.setText(menuName);
getDefaultMenuTextSize(mMenuName);
mMenuName.setTextSize(TypedValue.COMPLEX_UNIT_PX,defaultMenuTextSize*userPreferences.getTextSize());
getDefaultMenuTextTypeface(mMenuName);
mMenuName.setTypeface(userPreferences.getTextTypeface());


if(i != 1){
indicatorIcon.setVisibility(View.GONE);
Expand Down Expand Up @@ -157,4 +162,10 @@ public void getDefaultMenuTextSize(TextView menu){
defaultMenuTextSize = menu.getTextSize();
}
}

public void getDefaultMenuTextTypeface(TextView menu){
if(defaultMenuTextTypeface == null){
defaultMenuTextTypeface = menu.getTypeface();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.preference.PreferenceManager;
import android.util.Log;

import androidx.core.content.res.ResourcesCompat;

import com.ambinusian.adab.R;

import java.lang.reflect.Type;

public class UserPreferences {

Expand All @@ -14,6 +22,8 @@ public class UserPreferences {
private static final String KEY_USER_DEPARTMENT = "user_departement"; //TODO: Bang, ini "department"
private static final String KEY_PREF_NIGHT = "pref_night";
private static final String KEY_TEXT_SIZE = "text_size";
private static final String KEY_TEXT_FAMILY = "text_family";
private static final String KEY_TEXT_STYLE = "text_style";

private static Context context = null;

Expand Down Expand Up @@ -114,4 +124,48 @@ public float getTextSize(){
return getSharedPreference().getFloat(KEY_TEXT_SIZE,1f);
}

public void setTextTypeface(int typefaceFamily){
SharedPreferences.Editor editor = getSharedPreference().edit();
editor.putInt(KEY_TEXT_FAMILY, typefaceFamily);
editor.apply();
}

public Typeface getTextTypeface(){
int typefaceFamily = getSharedPreference().getInt(KEY_TEXT_FAMILY,0);

Typeface typeface;

// pilih font family
switch (typefaceFamily) {
case 1:
typeface = ResourcesCompat.getFont(context, R.font.opendyslexic);
break;
default:
typeface = ResourcesCompat.getFont(context, R.font.interstate);
break;
}

return typeface;
}

public Typeface getTextTypeface(int typefaceFamily){

Typeface typeface;

// pilih font family
switch (typefaceFamily) {
case 1:
typeface = ResourcesCompat.getFont(context, R.font.opendyslexic);
break;
default:
typeface = ResourcesCompat.getFont(context, R.font.interstate);
break;
}

return typeface;
}

public int getTextTypefaceFamilyID() {
return getSharedPreference().getInt(KEY_TEXT_FAMILY, 0);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ambinusian.adab.recyclerview.classlist;

import android.content.Context;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -46,7 +47,9 @@ public void onBindViewHolder(@NonNull ClasslListHolder holder, int position) {
holder.meeting.setText(item.getMeeting());
holder.time.setText(item.getTime());

//set text attributes
setTextSize(holder);
setTextTypeface(holder);

//set classIcon
int classIcon = item.getClassIcon();
Expand Down Expand Up @@ -253,4 +256,13 @@ private void setTextSize(ClasslListHolder holder){
holder.meeting.setTextSize(TypedValue.COMPLEX_UNIT_PX,holder.meeting.getTextSize()*textSize);
holder.time.setTextSize(TypedValue.COMPLEX_UNIT_PX,holder.time.getTextSize()*textSize);
}

private void setTextTypeface(ClasslListHolder holder){
//get font type
Typeface textTypeface = userPreferences.getTextTypeface();
//set font type for each text view
holder.classTopic.setTypeface(textTypeface, holder.classTopic.getTypeface().getStyle());
holder.meeting.setTypeface(textTypeface, holder.meeting.getTypeface().getStyle());
holder.time.setTypeface(textTypeface, holder.time.getTypeface().getStyle());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
Expand All @@ -14,6 +15,7 @@
import com.ambinusian.adab.R;
import com.ambinusian.adab.all.ActivityLive;
import com.ambinusian.adab.preferences.UserPreferences;
import com.ambinusian.adab.recyclerview.classlist.ClasslListHolder;

import java.util.ArrayList;

Expand Down Expand Up @@ -54,8 +56,9 @@ public void onBindViewHolder(@NonNull CourseHolder holder, int position) {
holder.classCode.setText(item.getClassCode());
holder.classType.setText(item.getClassType());

//set text size for all text
//set text attributes
setTextSize(holder);
setTextTypeface(holder);

int classIcon = item.getClassIcon();
//set classIcon
Expand Down Expand Up @@ -280,4 +283,17 @@ private void setTextSize(CourseHolder holder){
holder.classCode.setTextSize(TypedValue.COMPLEX_UNIT_PX, holder.classCode.getTextSize() * textSize);
holder.classType.setTextSize(TypedValue.COMPLEX_UNIT_PX, holder.classType.getTextSize() * textSize);
}

private void setTextTypeface(CourseHolder holder){
//get font type
Typeface textTypeface = userPreferences.getTextTypeface();
//set font type for each text view
holder.classTime.setTypeface(textTypeface, holder.classTime.getTypeface().getStyle());
holder.classTitle.setTypeface(textTypeface, holder.classTitle.getTypeface().getStyle());
holder.courses.setTypeface(textTypeface, holder.courses.getTypeface().getStyle());
holder.classMeeting.setTypeface(textTypeface, holder.classMeeting.getTypeface().getStyle());
holder.courseCode.setTypeface(textTypeface, holder.courseCode.getTypeface().getStyle());
holder.classCode.setTypeface(textTypeface, holder.classCode.getTypeface().getStyle());
holder.classType.setTypeface(textTypeface, holder.classType.getTypeface().getStyle());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ambinusian.adab.recyclerview.schedule;

import android.content.Context;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -42,8 +43,9 @@ public void onBindViewHolder(@NonNull ScheduleHolder holder, int position) {
holder.scheduleClassCode.setText(item.getClassRoom());
holder.scheduleClassTime.setText(item.getClassTime());

//set text size to all text view
//set text attributes
setTextSize(holder);
setTextTypeface(holder);
}

@Override
Expand All @@ -62,4 +64,16 @@ private void setTextSize(ScheduleHolder holder){
holder.scheduleClassCode.setTextSize(TypedValue.COMPLEX_UNIT_PX, holder.scheduleClassCode.getTextSize() * textSize);
holder.scheduleClassTime.setTextSize(TypedValue.COMPLEX_UNIT_PX, holder.scheduleClassTime.getTextSize() * textSize);
}

private void setTextTypeface(ScheduleHolder holder){
//get font type
Typeface textTypeface = userPreferences.getTextTypeface();
//set font type for each text view
holder.scheduleClassType.setTypeface(textTypeface, holder.scheduleClassType.getTypeface().getStyle());
holder.scheduleClassTitle.setTypeface(textTypeface, holder.scheduleClassTitle.getTypeface().getStyle());
holder.scheduleCourse.setTypeface(textTypeface, holder.scheduleCourse.getTypeface().getStyle());
holder.scheduleCourseCode.setTypeface(textTypeface, holder.scheduleCourseCode.getTypeface().getStyle());
holder.scheduleClassCode.setTypeface(textTypeface, holder.scheduleClassCode.getTypeface().getStyle());
holder.scheduleClassTime.setTypeface(textTypeface, holder.scheduleClassTime.getTypeface().getStyle());
}
}
Loading