Last active
April 5, 2022 07:36
-
-
Save IwonGunawan/fdd448ccbcf30315000ca94d052b607a to your computer and use it in GitHub Desktop.
Android
This file contains 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
Locale.getDefault().getLanguage() ---> en | |
Locale.getDefault().getISO3Language() ---> eng | |
Locale.getDefault().getCountry() ---> US | |
Locale.getDefault().getISO3Country() ---> USA | |
Locale.getDefault().getDisplayCountry() ---> United States | |
Locale.getDefault().getDisplayName() ---> English (United States) | |
Locale.getDefault().toString() ---> en_US | |
Locale.getDefault().getDisplayLanguage()---> English | |
Locale.getDefault().toLanguageTag() ---> en-US |
This file contains 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
import android.text.format.DateFormat; | |
import java.util.Calendar; | |
// Parsing date | |
String dateFormated = ""; | |
@SuppressLint("SimpleDateFormat") SimpleDateFormat formatterFrom = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); | |
@SuppressLint("SimpleDateFormat") SimpleDateFormat formatterTo = new SimpleDateFormat("HH:mm 'WIB'"); | |
//formatterFrom.setTimeZone(TimeZone.getTimeZone("Asia/Jakarta")); | |
try { | |
Date date = formatterFrom.parse(strDate); | |
dateFormated = formatterTo.format(date); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
// Convert 2020-11-01 to Date | |
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(sDate1); | |
// Get date time from Date | |
String dayOfTheWeek = (String) DateFormat.format("EEEE", date); // Thursday | |
String day = (String) DateFormat.format("dd", date); // 20 | |
String monthString = (String) DateFormat.format("MMM", date); // Jun | |
String monthNumber = (String) DateFormat.format("MM", date); // 06 | |
String year = (String) DateFormat.format("yyyy", date); // 2013 | |
// Add hours | |
Calendar cal = Calendar.getInstance(); | |
cal.setTime(date); | |
cal.add(Calendar.HOUR_OF_DAY,2); // this will add two hours | |
date = cal.getTime(); | |
// GET MIN & MAX DATE | |
import java.util.Calendar; | |
Calendar c1 = Calendar.getInstance(); | |
c1.add(Calendar.MONTH, -1); | |
Date dateMin = c1.getTime(); // Tue Oct 20 16:08:44 WIB 2020 | |
Calendar c2 = Calendar.getInstance(); | |
c2.add(Calendar.MONTH, +1); | |
Date dateMax = c2.getTime(); // Sun Dec 20 16:08:44 WIB 2020 |
This file contains 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
// open keypad contact | |
Intent intent = new Intent(Intent.ACTION_DIAL); | |
intent.setData(Uri.parse("tel:9999999999")); | |
startActivity(intent) | |
// open twitter | |
Intent intent = new Intent(Intent.ACTION_VIEW); | |
intent.setData(Uri.parse("https://twitter.com/intent/tweet?text=%40HaloBCA+&url")); | |
mActivity.startActivity(intent); | |
// open email | |
Intent intent = new Intent(Intent.ACTION_SENDTO); | |
intent.setData(Uri.parse("mailto:halobca@bca.co.id")); | |
mActivity.startActivity(intent); | |
// open whatsApp | |
Intent intent = new Intent(Intent.ACTION_VIEW); | |
intent.setData(Uri.parse("https://api.whatsapp.com/send?phone=6281115xxx&text=%23HaloBCA&app_absent=0")); | |
mActivity.startActivity(intent); |
This file contains 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
// SPINNER with VALUE & LABEL | |
String selectedVal = getResources().getStringArray(R.array.member_value)[spinnerType.getSelectedItemPosition()]; | |
// SAVE OBJECT to STRING : import com.google.gson.Gson; | |
MyObject myObject = new MyObject; | |
Gson gson = new Gson(); | |
String json = gson.toJson(myObject); | |
// RETRIVE STRING to OBJECT | |
Gson gson = new Gson(); | |
MyObject obj = gson.fromJson(json, MyObject.class); | |
log.d(obj.getName()); | |
// inflate layout without activity or fragment | |
FrameLayout frame = loginActivity.findViewById(R.id.fragment_forgot); | |
frame.removeAllViews(); | |
LayoutInflater.from(mContext).inflate(R.layout.otp, frame, true); |
This file contains 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
// Fragment -> Fragment | |
Fragment2 fragment2 = new Fragment2(); | |
FragmentManager fragmentManager = getFragmentManager(); | |
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); | |
fragmentTransaction.replace(R.id.container, fragment2); | |
fragmentTransaction.addToBackStack(null); | |
fragmentTransaction.commit(); | |
// Fragment -> activity | |
Intent intent = new Intent(getActivity(), MainActivityList.class); | |
startActivity(intent); | |
// activity -> fragment | |
FragmentManager fragmentManager = getSupportFragmentManager(); | |
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); | |
fragmentTransaction | |
.add(R.id.fragment_container, new ForgotPinFragment()) | |
.addToBackStack(null) | |
.commit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment