Last active
April 4, 2020 05:59
-
-
Save faranak616/a3f16c7e35dddd69ff2372431216770c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity | |
{ | |
Button language; | |
TextView phone; | |
RatingBar ratingBar; | |
//String languageStr = "fa"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) | |
{ | |
final LoginShared languageStr = new LoginShared(); | |
if (languageStr.getLanguage() == null) | |
{ | |
languageStr.setLanguage("fa"); | |
} | |
super.onCreate(savedInstanceState); | |
Locale locale = new Locale(languageStr.getLanguage()); | |
Locale.setDefault(locale); | |
Configuration config = new Configuration(); | |
config.locale = locale; | |
getBaseContext().getResources().updateConfiguration(config, | |
getBaseContext().getResources().getDisplayMetrics()); | |
setContentView(R.layout.activity_main); | |
language = findViewById(R.id.choose_language); | |
phone = findViewById(R.id.telTv); | |
ratingBar = findViewById(R.id.rate); | |
ratingBar.setRating(3.5f); | |
phone.setText("021 33333333"); | |
language.setOnClickListener(new View.OnClickListener() | |
{ | |
@Override | |
public void onClick(View view) | |
{ | |
PopupMenu popupMenu = new PopupMenu(MainActivity.this, language); | |
//popupMenu.getMenuInflater().inflate(R.menu.menu_type_of_print, popupMenu.getMenu()); | |
if (languageStr.getLanguage().equals("en")) | |
popupMenu.getMenu().add(getResources().getString(R.string.persian)); | |
if (languageStr.getLanguage().equals("fa")) | |
popupMenu.getMenu().add(getResources().getString(R.string.english)); | |
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { | |
public boolean onMenuItemClick(MenuItem item) { | |
switch (item.getTitle().toString()) | |
{ | |
case "Persian": | |
case "فارسی": | |
languageStr.setLanguage("fa"); | |
restartActivity(); | |
break; | |
case "English": | |
case "انگلیسی": | |
languageStr.setLanguage("en"); | |
restartActivity(); | |
break; | |
} | |
return true; | |
} | |
}); | |
popupMenu.show(); | |
} | |
}); | |
} | |
private void restartActivity() { | |
Intent intent = new Intent(MainActivity.this , MainActivity.class); | |
startActivity(intent); | |
finish(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ImageView | |
android:id="@+id/merchant_image" | |
android:layout_width="60dp" | |
android:layout_height="60dp" | |
android:layout_marginStart="16dp" | |
android:layout_marginTop="13dp" | |
android:src="@mipmap/ic_launcher" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<TextView | |
android:id="@+id/nameTv" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_marginStart="8dp" | |
android:layout_marginEnd="12dp" | |
android:text="@string/name" | |
android:textColor="#66000000" | |
android:textSize="16sp" | |
android:typeface="sans" | |
app:layout_constraintStart_toEndOf="@+id/merchant_image" | |
app:layout_constraintTop_toTopOf="@+id/merchant_image" /> | |
<RatingBar | |
android:id="@+id/rate" | |
style="@style/RatingBar" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="start" | |
android:layout_marginEnd="8dp" | |
android:visibility="visible" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintTop_toTopOf="@+id/merchant_image" /> | |
<TextView | |
android:id="@+id/addressTv" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="4dp" | |
android:layout_marginEnd="12dp" | |
android:text="@string/address" | |
android:textColor="#acacac" | |
android:textSize="14sp" | |
android:typeface="sans" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="@+id/nameTv" | |
app:layout_constraintTop_toBottomOf="@+id/nameTv" /> | |
<View | |
android:id="@+id/view3" | |
android:layout_width="0dp" | |
android:layout_height="1dp" | |
android:layout_marginStart="8dp" | |
android:layout_marginTop="16dp" | |
android:layout_marginEnd="8dp" | |
android:background="@color/dash_color" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/addressTv" /> | |
<ImageView | |
android:id="@+id/imageView20" | |
android:layout_width="15dp" | |
android:layout_height="15dp" | |
android:layout_marginStart="16dp" | |
android:layout_marginTop="8dp" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@id/view3" | |
app:srcCompat="@drawable/ic_local_phone_24dp" /> | |
<TextView | |
android:id="@+id/telTv" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_marginStart="8dp" | |
android:textColor="#acacac" | |
android:visibility="visible" | |
app:layout_constraintBottom_toBottomOf="@id/imageView20" | |
app:layout_constraintStart_toEndOf="@id/imageView20" | |
app:layout_constraintTop_toTopOf="@id/imageView20" | |
tools:text="@string/phone" /> | |
<Button | |
android:id="@+id/choose_language" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="24dp" | |
android:text="@string/choose_language" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@id/imageView20" /> | |
</androidx.constraintlayout.widget.ConstraintLayout> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment