Skip to content

Commit ec08d3e

Browse files
committed
sample to get width of editText as soon as mainThread become idle
1 parent e1f2882 commit ec08d3e

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ android {
2121
dependencies {
2222
implementation fileTree(dir: 'libs', include: ['*.jar'])
2323
implementation 'com.android.support:appcompat-v7:26.1.0'
24-
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
24+
implementation 'com.github.Mohamed-Fadel:MainThreadScheduler:v1.0-alpha'
2525
testImplementation 'junit:junit:4.12'
2626
androidTestImplementation 'com.android.support.test:runner:1.0.1'
2727
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
package com.mohamedfadel91.mainthreadscheduler;
22

3-
import android.support.v7.app.AppCompatActivity;
43
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.widget.EditText;
6+
import android.widget.Toast;
7+
8+
import com.mohamedfadel91.mainthreadschedulerlib.MainThreadScheduler;
59

610
public class MainActivity extends AppCompatActivity {
711

12+
EditText edtEmail;
13+
814
@Override
915
protected void onCreate(Bundle savedInstanceState) {
1016
super.onCreate(savedInstanceState);
1117
setContentView(R.layout.activity_main);
18+
19+
edtEmail = findViewById(R.id.edt_email);
20+
21+
MainThreadScheduler.scheduleWhenIdle(new Runnable() {
22+
@Override
23+
public void run() {
24+
Toast.makeText(MainActivity.this,
25+
" " + edtEmail.getWidth(),
26+
Toast.LENGTH_SHORT).show();
27+
}
28+
});
29+
1230
}
1331
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
43
xmlns:tools="http://schemas.android.com/tools"
54
android:layout_width="match_parent"
5+
android:orientation="vertical"
6+
android:padding="@dimen/frame_padding"
67
android:layout_height="match_parent"
78
tools:context="com.mohamedfadel91.mainthreadscheduler.MainActivity">
89

9-
<TextView
10-
android:layout_width="wrap_content"
10+
<EditText
11+
android:id="@+id/edt_email"
12+
android:layout_width="match_parent"
1113
android:layout_height="wrap_content"
12-
android:text="Hello World!"
13-
app:layout_constraintBottom_toBottomOf="parent"
14-
app:layout_constraintLeft_toLeftOf="parent"
15-
app:layout_constraintRight_toRightOf="parent"
16-
app:layout_constraintTop_toTopOf="parent" />
14+
android:inputType="textEmailAddress"
15+
android:hint="@string/email_hint"/>
1716

18-
</android.support.constraint.ConstraintLayout>
17+
</LinearLayout>

app/src/main/res/values/dimens.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<dimen name="frame_padding">16dp</dimen>
4+
</resources>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">MainThreadScheduler</string>
3+
<string name="email_hint">Email Address</string>
34
</resources>

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ allprojects {
1919
repositories {
2020
google()
2121
jcenter()
22+
maven { url 'https://jitpack.io' }
2223
}
2324
}
2425

0 commit comments

Comments
 (0)