Skip to content

Commit

Permalink
sample to get width of editText as soon as mainThread become idle
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Fadel committed Mar 17, 2018
1 parent e1f2882 commit ec08d3e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.github.Mohamed-Fadel:MainThreadScheduler:v1.0-alpha'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
package com.mohamedfadel91.mainthreadscheduler;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import android.widget.Toast;

import com.mohamedfadel91.mainthreadschedulerlib.MainThreadScheduler;

public class MainActivity extends AppCompatActivity {

EditText edtEmail;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

edtEmail = findViewById(R.id.edt_email);

MainThreadScheduler.scheduleWhenIdle(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,
" " + edtEmail.getWidth(),
Toast.LENGTH_SHORT).show();
}
});

}
}
19 changes: 9 additions & 10 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:padding="@dimen/frame_padding"
android:layout_height="match_parent"
tools:context="com.mohamedfadel91.mainthreadscheduler.MainActivity">

<TextView
android:layout_width="wrap_content"
<EditText
android:id="@+id/edt_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:inputType="textEmailAddress"
android:hint="@string/email_hint"/>

</android.support.constraint.ConstraintLayout>
</LinearLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="frame_padding">16dp</dimen>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">MainThreadScheduler</string>
<string name="email_hint">Email Address</string>
</resources>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

Expand Down

0 comments on commit ec08d3e

Please sign in to comment.