Skip to content

Instantly share code, notes, and snippets.

View mahdimortazavi's full-sized avatar
☺️
happy

mahdi mortazavi mahdimortazavi

☺️
happy
View GitHub Profile
@mahdimortazavi
mahdimortazavi / ProgressDialog webView
Created December 20, 2016 16:20
ProgressDialog webView
final ProgressDialog pd = ProgressDialog.show(this, "", "Loading...", true);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.google.com");
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
@mahdimortazavi
mahdimortazavi / webView setProgress
Created December 20, 2016 15:51
webView setProgress
WebView webView =(WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.google.com");
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
setTitle("Loading...");
setProgress(progress * 100);
if(progress == 100)
@mahdimortazavi
mahdimortazavi / gist:e54bc60b4ba58e69a2d8cc827260bb63
Created November 28, 2016 11:51
share image and text from app to telegram or other application
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "temporary_file.jpg");
try {
f.createNewFile();
@mahdimortazavi
mahdimortazavi / AppBarStateChangeListener
Created November 19, 2016 12:04
change back arrow color dynamically
public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {
public enum State {
EXPANDED,
COLLAPSED,
IDLE
}
private State mCurrentState = State.IDLE;
@mahdimortazavi
mahdimortazavi / btn shape
Created August 22, 2016 20:32
Button corner (btn shape)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<solid android:color="#49aa02"/>
<corners android:radius="10dp"/>
</shape>
@mahdimortazavi
mahdimortazavi / send email just email app
Created August 6, 2016 07:15
send Email by Email app
private void sendEmail(){
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:" + "recipient@example.com"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "My email's subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "My email's body");
try {
startActivity(Intent.createChooser(emailIntent, "Send email using..."));
} catch (android.content.ActivityNotFoundException ex) {
@mahdimortazavi
mahdimortazavi / URL
Last active August 2, 2016 19:28
open URL in android
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com")));
// for telegram channel
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("tg://resolve?domain=appmeraji")));
@mahdimortazavi
mahdimortazavi / animation to activity
Created July 26, 2016 08:11
animation between activity
Intent i = new Intent(Second.this, MainAct.class);
Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(), R.anim.slide_in_right, R.anim.slide_out_right).toBundle();
startActivity(i,bndlanimation);
----------------------------------
slide_out_right.xml
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
@mahdimortazavi
mahdimortazavi / onCreateOptionsMenu & onOptionsItemSelected
Created July 16, 2016 09:13
Sample onOptionsItemSelected and onCreateOptionsMenu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.bookmark_menu:
Toast.makeText(this, "You have selected Bookmark Menu", Toast.LENGTH_SHORT).show();
@mahdimortazavi
mahdimortazavi / Splash.java
Created June 28, 2016 13:17
Splash Screen Full Screen
public class Splash extends Activity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 1000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);