Code Monkey home page Code Monkey logo

ssp's Introduction

issues Forks Stars Maven Central License

SSP - a scalable size unit for texts

An android lib that provides a new size unit - ssp (scalable sp). This size unit scales with the screen size based on the sp size unit (for texts). It can help Android developers with supporting multiple screens.

This is the sibling of the sdp size unit that should be used for non text views.

Attention

Use it carefully! for example, in most cases you still need to design a different layout for tablets.

Example

Here is a single layout built using ssp:

ssp example

And here is the same layout built using sp:

sp example

You can see that ssp scales with the screen size and the sp stays with the same size on all screen sizes.

Getting Started

To add ssp to your Android Studio project:

add implementation 'com.intuit.ssp:ssp-android:1.1.1โ€™ to your build.gradle dependencies block.

for example:

dependencies {
  implementation 'com.intuit.ssp:ssp-android:1.1.1'
}

See the ssp_example.xml to see how to use to the ssp size unit.

For easy mapping of designs to ssp units, one can create designs with 300 pixels screen width - in this case each pixel in the design corresponds to 1 ssp.

Note

The ssp size unit calculation includes some approximation due to some performance and usability constraints.

ssp's People

Contributors

elhanan-mishraky avatar rapito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ssp's Issues

text size big

Text size shows very big in large device or high resolution device. How to fix it

Different sizes while using SSP Programettically.

Hi,

First of all, thank you for this great library. I'm trying to use your library for setting GridLayout Textview size. However, we noticed that when we run this in different mobiles, sizes very too much.

Code I've written is given below. Please help me.

txtSwitch.setTextSize(getResources().getDimension(R.dimen._7ssp));

Setting ssp size in code.

Is there a way to programmatically set the text size to ssp values?
What i mean: if you use sp units, in code you can set the text size like this

button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);

but what about ssp?
Is there any way to get this base in code?

No issues so far

Hi,

I have no issues so far. This library is truly great and saves me a lot of time compared on creating multiple layouts for different screen sizes. I'm wondering why Google don't have this built on their api. They should have a look on this project. Keep up the good work man! I wish you the best.

Text sizes are bigger in fold-able devices

The text view and button text sizes are comparatively larger in Android foldable devices.

For example if the device is in fold-in position then text size, margin, padding etc all working fine. But when the device is in the fold-out position, the text size, margin, padding, etc. all increase in size according to the width and height of the screen.

Please find attached screenshots for the reference.
Screenshot_1668770025
Screenshot_1668770909

ssp not supporting few devices

Many Samsung devices(Samsung s4 and Samsung note 3 tested) and also some standard devices(Nexus 5, Pixel Series tested) isn't supported by this library. Please try to fix this.

device crashes in some resolutions

This is my complete stacktrace

Caused by android.content.res.Resources$NotFoundException: Resource "com.example.myapplication:dimen/_25ssp" (7f0700c2) is not a Drawable (color or path): TypedValue{t=0x5/d=0x10400022 a=7 r=0x7f0700c2}
       at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:838)
       at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:683)
       at android.content.res.Resources.getDrawableForDensity(Resources.java:921)
       at android.content.res.Resources.getDrawable(Resources.java:860)
       at android.content.Context.getDrawable(Context.java:689)
       at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java)
       at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:3)
       at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:2)
       at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:4)
       at androidx.appcompat.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:8)
       at androidx.appcompat.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:4)
       at com.example.myapplication.feature.main.SectionOneAdapter$LevelViewHolder.bindItems(SectionOneAdapter.java:9)
       at com.example.myapplication.feature.main.SectionOneAdapter.onBindViewHolder(SectionOneAdapter.java:9)
       at com.example.myapplication.feature.main.SectionOneAdapter.onBindViewHolder(SectionOneAdapter.java:9)
       at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java)
       at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:78)
       at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:78)
       at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:78)
       at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:1)
       at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2)
       at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java)
       at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:2)
       at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:22)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:38)
       at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:61)
       at android.view.View.measure(View.java:26415)
       at androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure(ConstraintLayout.java:18)
       at androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure.a(BasicMeasure.java:112)
       at androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure.measureChildren(BasicMeasure.java:49)
       at androidx.constraintlayout.solver.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:49)
       at androidx.constraintlayout.widget.ConstraintLayout.resolveSystem(ConstraintLayout.java:49)
       at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:49)
       at android.view.View.measure(View.java:26415)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7845)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:154)
       at android.view.View.measure(View.java:26415)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7845)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
       at android.view.View.measure(View.java:26415)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7845)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:26415)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7845)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
       at android.view.View.measure(View.java:26415)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7845)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at com.android.internal.policy.DecorView.onMeasure(DecorView.java:1013)
       at android.view.View.measure(View.java:26415)
       at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3609)
       at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2352)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2644)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2204)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9003)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:996)
       at android.view.Choreographer.doCallbacks(Choreographer.java:794)
       at android.view.Choreographer.doFrame(Choreographer.java:729)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:981)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:7860)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

UI not showing same in 5.5' screen

i am applying font size runtime it's working fine but in some places words are breaking showing in two lines.

i am applying like this

    `binding.tvExportHistory.setTextSize(getResources().getDimension(R.dimen.medium_font));`

These are my font sizes

 <dimen name="small_font">@dimen/_5ssp</dimen>
    <dimen name="medium_font">@dimen/_6ssp</dimen>
    <dimen name="large_font">@dimen/_7ssp</dimen>

1
2

why UI is breaking in the 5.5-inch screen? what should i do?

Any Suggestion would be helpful.

Huge text size in some devices

Hi , in some devices (eg. Sony C3 Dual , some tablets , etc.) text size is larger than standard phones , is this a problem in this library? any idea to solve this?

SSP doesn't work for text shadows

It's ok for text size and text padding but the ssp doesn't work for text shadows or radius.
For example:
android:shadowDx="@dimen/_3ssp"
android:shadowDy="@dimen/_3ssp"
android:shadowRadius="@dimen/_8ssp"
will generate 3 errors, maybe because the ssp uses the floating format.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.