Keme Appdev Reviwer
Keme Appdev Reviwer
Keme Appdev Reviwer
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
android:textStyle="bold"
android:text="@string/article_title"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@Override
public void onActivityResult(int requestCode, int resultCode, Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TEXT_REQUEST){
if (resultCode == RESULT_OK){
String reply =
data.getStringExtra(SecondActivity.EXTRA_REPLY);
mReplyHeadTextView.setVisibility(View.VISIBLE);
mReplyTextView.setText(reply);
mReplyTextView.setVisibility(View.VISIBLE);
}
}
}
Log.d(LOG_TAG,"-------");
Log.d(LOG_TAG,"onCreate");
mReply = findViewById(R.id.editText_second);
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
TextView textView = findViewById(R.id.text_message_reply);
textView.setText(message);
}
public void returnReply(View view) {
String reply = mReply.getText().toString();
Intent replyIntent = new Intent();
replyIntent.putExtra(EXTRA_REPLY, reply);
setResult(RESULT_OK, replyIntent);
Log.d(LOG_TAG, "End SecondActivity");
finish();
}
@Override
public void onStart(){
super.onStart();
Log.d(LOG_TAG,"onStart");
}
@Override
public void onPause(){
super.onPause();
Log.d(LOG_TAG,"onPause");
}
@Override
public void onRestart(){
super.onRestart();
Log.d(LOG_TAG,"onRestart");
}
@Override
public void onResume(){
super.onResume();
Log.d(LOG_TAG,"onResume");
}
@Override
public void onStop(){
super.onStop();
Log.d(LOG_TAG,"onStop");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d(LOG_TAG, "onDestroy");
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
mWebsiteEditText = findViewById(R.id.website_edittext);
mLocationEditText = findViewById(R.id.location_edittext);
mShareTextEditText = findViewById(R.id.share_edittext);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main),
(v, insets) -> {
Insets systemBars =
insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom);
return insets;
});
}
if (intent.resolveActivity(getPackageManager()) !=null){
startActivity(intent);
} else {
Log.d("ImplicitIntents", "Can't handle this!");
}
}
if (intent.resolveActivity(getPackageManager())!=null) {
startActivity(intent);
}else {
Log.d("ImplicitIntents", "Can't handle the intent!");
}
}
public void shareText(View view) {
String txt = mShareTextEditText.getText().toString();
String mimeType = "text/plain";
ShareCompat.IntentBuilder
.from(this)
.setType(mimeType)
.setChooserTitle(R.string.edittext_share)
.setText(txt)
.startChooser();
}
}
<EditText
android:id="@+id/address_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/enter_address_hint"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:inputType="textMultiLine"
app:layout_constraintBaseline_toBaselineOf="@+id/address_label"
app:layout_constraintStart_toEndOf="@id/address_label"
/>
<TextView
android:id="@+id/phone_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:text="@string/phone_label_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/address_text"
/>
<EditText
android:id="@+id/phone_text"
android:layout_width="134dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:ems="10"
android:hint="@string/enter_phone_hint"
android:inputType="phone"
app:layout_constraintBaseline_toBaselineOf="@+id/phone_label"
app:layout_constraintStart_toEndOf="@id/phone_label"
/>
<TextView
android:id="@+id/note_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="24dp"
android:text="@string/note_label_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/phone_label"
/>
<EditText
android:id="@+id/note_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:gravity="start|top"
android:hint="@string/enter_note_hint"
android:inputType="textCapSentences|textMultiLine"
app:layout_constraintBaseline_toBaselineOf="@+id/note_label"
app:layout_constraintStart_toEndOf="@id/note_label"
tools:layout_editor_absoluteX="64dp" />
<TextView
android:id="@+id/delivery_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="24dp"
android:text="@string/choose_delivery_method"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/note_text" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/delivery_label">
<RadioButton
android:id="@+id/sameday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/same_day_messenger_service"
android:onClick="onRadioButtonClicked" />
<RadioButton
android:id="@+id/nextday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next_day_ground_delivery"
android:onClick="onRadioButtonClicked" />
<RadioButton
android:id="@+id/pickup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pick_up"
android:onClick="onRadioButtonClicked" />
</RadioGroup>
<Spinner
android:id="@+id/label_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="24dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/phone_text"
app:layout_constraintTop_toBottomOf="@+id/address_text" />
Clickable image
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here
if (item.getItemId() == R.id.action_order) {
displayToast(getString(R.string.action_order_message));
return true;
} else if (item.getItemId() == R.id.action_status) {
displayToast(getString(R.string.action_status_message));
return true;
} else if (item.getItemId() == R.id.action_favorites) {
displayToast(getString(R.string.action_favorites_message));
return true;
} else if (item.getItemId() == R.id.action_contact) {
displayToast(getString(R.string.action_contacts_message));
return true;
} else {
// Handle other cases if needed
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this,
R.id.nav_host_fragment_content_main);
return NavigationUI.navigateUp(navController, appBarConfiguration)
|| super.onSupportNavigateUp();
}
public void displayToast(String message){
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).
show();
}
For alert
public void onClickShowAlert(View view) {
AlertDialog.Builder myAlertBuilder = new
AlertDialog.Builder(MainActivity.this);
myAlertBuilder.setTitle("Alert");
myAlertBuilder.setMessage(R.string.click_ok_to_continue_or_cancel_to_stop);
myAlertBuilder.setPositiveButton(R.string.ok_button, new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),
R.string.toast_ok_message, Toast.LENGTH_SHORT).show();
}
});
myAlertBuilder.setNegativeButton(R.string.cancel_button, new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),
R.string.toast_cancel_message, Toast.LENGTH_SHORT).show();
}
});
myAlertBuilder.show(); // Show the alert dialog
}
date picker
public class DatePickerFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
@Nullable
@Override
public DatePickerDialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int
day) {
// Get a reference to the MainActivity and call the method to process
the date
MainActivity activity = (MainActivity) getActivity();
if (activity != null) {
activity.processDatePickerResult(year, month, day);
}
}
}