Last active
July 11, 2016 22:49
-
-
Save deda9/9b717afc7b33b2d5fde6457a5b0a74b3 to your computer and use it in GitHub Desktop.
It contain some fixed Code we all write in every application
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
Button Background Selector insdide drawble folder ---------------------------------------------- | |
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:drawable="@drawable/numpad_button_bg_selected" android:state_selected="true"></item> | |
<item android:drawable="@drawable/numpad_button_bg_pressed" android:state_pressed="true"></item> | |
<item android:drawable="@drawable/numpad_button_bg_normal"></item> | |
</selector> | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Text Color Selector inside color folder ---------------------------------------------- | |
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_pressed="true" | |
android:color="#000000" /> <!-- pressed --> | |
<item android:state_focused="true" | |
android:color="#000000" /> <!-- focused --> | |
<item android:color="#FFFFFF" /> <!-- default --> | |
</selector> | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
out Of Memory ------------------------------------------------- | |
<application | |
android:largeHeap="true" > | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Support Arabic ------------------------------------------------- | |
<application | |
android:supportsRtl="true" > | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Call Phone Intent ------------------------------------------------- | |
Intent mobile_2 = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "0530556600")); | |
startActivity(mobile_2); | |
<uses-permission android:name="android.permission.CALL_PHONE" /> | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
MarshMewllo ask for Permission ------------------------------------------------- | |
if(Build.VERSION.SDK_INT > 22) | |
{ | |
if(ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) | |
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); | |
} | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Start activitu with animation ------------------------------------------------- | |
startActivity(new Intent(mContext, VisionActivity.class)); | |
overridePendingTransition(R.anim.fade_in, R.anim.fade_out); | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
fade_in ------------------------------------------------- | |
<?xml version="1.0" encoding="utf-8"?> | |
<alpha xmlns:android="http://schemas.android.com/apk/res/android" | |
android:duration="500" | |
android:fromAlpha="0.0" | |
android:interpolator="@android:anim/accelerate_interpolator" | |
android:toAlpha="1.0" /> | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
fade_out ------------------------------------------------- | |
<?xml version="1.0" encoding="utf-8"?> | |
<alpha xmlns:android="http://schemas.android.com/apk/res/android" | |
android:duration="500" | |
android:fillAfter="true" | |
android:fromAlpha="1.0" | |
android:interpolator="@android:anim/accelerate_interpolator" | |
android:toAlpha="0.0" /> | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Share in app ------------------------------------------------- | |
Uri localUri = Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), BitmapFactory.decodeResource(getResources(), R.drawable.logo), null, null)); | |
Intent localIntent = new Intent("android.intent.action.SEND"); | |
localIntent.setType("image/*"); | |
Intent sharingIntent = new Intent(Intent.ACTION_SEND); | |
sharingIntent.setType("text/plain"); | |
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text"); | |
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject"); | |
startActivity(Intent.createChooser(sharingIntent, "Share using")); | |
return; | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Broder xml in drawable folder------------------------------------------------- | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape="rectangle"> | |
<corners | |
android:radius="2dp" | |
android:topRightRadius="0dp" | |
android:bottomRightRadius="0dp" | |
android:bottomLeftRadius="0dp" /> | |
<stroke | |
android:width="1dp" | |
android:color="@android:color/white" /> | |
</shape> | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Hide Keyboard when Activity start ------------------------------------------------- | |
android:windowSoftInputMode="stateHidden" | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
set Text Password Type ------------------------------------------------- | |
et_password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Import jar lib ------------------------------------------------- | |
compile files('libs/picasso-2.5.2.jar') | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Intenet Permission ------------------------------------------------- | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Check get itent ------------------------------------------------- | |
if (getIntent() != null && getIntent().getExtras() != null) | |
TYPE = getIntent().getStringExtra("TYPE"); | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Start Activity and remove from Stack ------------------------------------------------- | |
Intent intent = new Intent(from, to); | |
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); | |
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); | |
from.startActivity(intent); | |
from.finish(); | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
no Toolbar in Manifest ------------------------------------------------ | |
android:theme="@style/AppTheme.NoActionBar" | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Circular Image ------------------------------------------------ | |
compile 'de.hdodenhof:circleimageview:2.0.0' | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Indicator ------------------------------------------------ | |
compile 'com.wang.avi:library:1.0.5' | |
compile 'com.nineoldandroids:library:2.4.0' | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Shadow xml ------------------------------------------------ | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item> | |
<layer-list> | |
<item android:right="5dp" android:top="5dp"> | |
<shape> | |
<corners android:radius="3dp" /> | |
<solid android:color="#D6D6D6" /> | |
</shape> | |
</item> | |
<item android:bottom="2dp" android:left="2dp"> | |
<shape> | |
<gradient android:angle="270" | |
android:endColor="#E2E2E2" android:startColor="#BABABA" /> | |
<stroke android:width="1dp" android:color="#BABABA" /> | |
<corners android:radius="4dp" /> | |
<padding android:bottom="10dp" android:left="10dp" | |
android:right="10dp" android:top="10dp" /> | |
</shape> | |
</item> | |
</layer-list> | |
</item> | |
</selector> | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Make tabs text lowercase ------------------------------------------------ | |
If you use "android.support.design.widget.TabLayout" needed to set | |
< app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"> | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Tab layout tabs selected Background ------------------------------------------------ | |
accepted | |
You need to define a selector as a drawable, and also have a drawable for the selected/unselected states. | |
First, the selector, tab_background.xml in the drawable folder: | |
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:drawable="@drawable/tab_background_selected" android:state_selected="true" /> | |
<item android:drawable="@drawable/tab_background_unselected" android:state_selected="false" android:state_focused="false" android:state_pressed="false" /> | |
</selector> | |
Then, tab_background_selected.xml in the drawable folder: | |
<?xml version="1.0" encoding="utf-8"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" > | |
<solid android:color="#d13fdd1a" /> | |
</shape> | |
Then, tab_background_unselected.xml in the drawable folder: | |
<?xml version="1.0" encoding="utf-8"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" > | |
<solid android:color="#3F51B5" /> | |
</shape> | |
Finally, in your styles.xml, specify the selector to use: | |
<style name="Base.Widget.Design.TabLayout" parent="android:Widget"> | |
<item name="tabBackground">@drawable/tab_background</item> | |
</style> | |
Result with the example colors above: | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
REtrofit timeout ------------------------------------------------ | |
final OkHttpClient okHttpClient = new OkHttpClient.Builder() | |
.readTimeout(60, TimeUnit.SECONDS) | |
.connectTimeout(60, TimeUnit.SECONDS) | |
.build(); | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
onConfigurationChanged rotation ------------------------------------------------ | |
public void onConfigurationChanged(Configuration paramConfiguration) | |
{ | |
super.onConfigurationChanged(paramConfiguration); | |
} | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Open Google Map location by longitude ------------------------------------------------ | |
https://developer.android.com/guide/components/intents-common.html#Maps | |
private void openLocationMap(float late, float lng) { | |
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", late, lng); | |
String uri = String.format(Locale.ENGLISH, "geo:<" + late + ">,<" + lng + ">?q=<" + late + ">,<" + lng + ">(" + label + ")"); | |
Intent intent = new Intent(Intent.ACTION_VIEW); | |
if (intent.resolveActivity(getActivity().getPackageManager()) != null) { | |
intent.setData(Uri.parse(uri)); | |
} | |
else { | |
String url = "https://www.google.com.eg/maps/@"+ late +"," + lng +",13z"; | |
intent.setData(Uri.parse(url)); | |
MLogger.MLog(url); | |
} | |
getActivity().startActivity(intent); | |
} | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Detect arabic or ENGLISH language ------------------------------------------------ | |
public static boolean isProbablyArabic(String s) { | |
for (int i = 0; i < s.length(); ) { | |
int c = s.codePointAt(i); | |
if (c >= 0x0600 && c <= 0x06E0) | |
return true; | |
i += Character.charCount(c); | |
} | |
return false; | |
} | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
How To Open mail ------------------------------------------------ | |
Intent intent = new Intent(Intent.ACTION_SEND); | |
intent.setType("message/rfc822"); | |
intent.putExtra(Intent.EXTRA_SUBJECT, "Please add your Subject"); | |
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {mail}); | |
intent.putExtra(Intent.EXTRA_TEXT, "Please add your Message"); | |
Intent mailer = Intent.createChooser(intent, null); | |
startActivity(mailer); | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Open the Activity from outside the scope in Manifest ------------------------------------------------ | |
android:exported="true" | |
------------------------------------------------------------------------------------------------------------------------------------------ | |
Open the Activity from outside the scope in Manifest ------------------------------------------------ | |
Will be updated ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment