Thursday 23 July 2015

Three way android slider like iphone slider (Unlock screen animation)

The below code works with the animation of sliding

check out



Activity.class

//Package name
import android.os.Bundle;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class FirstscreenActivity extends Activity implements OnSeekBarChangeListener,
OnClickListener {
SeekBar sb;
boolean flag = false;
RelativeLayout page_background;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.firstscreenactivity);
Initialization();
sb.setOnSeekBarChangeListener(this);
page_background.setOnClickListener(this);
}

private void Initialization() {
sb = (SeekBar) findViewById(R.id.myseek);
sb.setProgress(50);
page_background = (RelativeLayout) findViewById(R.id.full_page_layout);
//seekbartest.setText("Slide to Unlock");

}

@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
if (arg1 > 95) {
arg0.setThumb(getResources().getDrawable(R.drawable.splashslider));
}
}

@Override
public void onStartTrackingTouch(SeekBar arg0) {
Log.e("progress baronStartTrackingTouch",""+arg0.getProgress());
}

@SuppressLint("NewApi") @Override
public void onStopTrackingTouch(final SeekBar arg0) {
Log.e("onStopTrackingTouch", "onStopTrackingTouch");
Log.e("progress bar",""+arg0.getProgress());
if (arg0.getProgress() <= 20) {
ValueAnimator anim = ValueAnimator.ofInt(arg0.getProgress(), 0);
anim.setDuration(100);
anim.addUpdateListener(new AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
    int animProgress = (Integer) animation.getAnimatedValue();
    arg0.setProgress(animProgress);
    }
});
anim.start();

}
else if(arg0.getProgress() > 20 && arg0.getProgress()< 50) {
ValueAnimator anim = ValueAnimator.ofInt(arg0.getProgress(), 50);
anim.setDuration(200);
anim.addUpdateListener(new AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
    int animProgress = (Integer) animation.getAnimatedValue();
    arg0.setProgress(animProgress);
    }
});
anim.start();
//arg0.setProgress(50);
}
else if(arg0.getProgress() > 50 && arg0.getProgress()< 80){
ValueAnimator anim = ValueAnimator.ofInt(arg0.getProgress(), 50);
anim.setDuration(200);
anim.addUpdateListener(new AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
    int animProgress = (Integer) animation.getAnimatedValue();
    arg0.setProgress(animProgress);
    }
});
anim.start();
//arg0.setProgress(50);
}else if(arg0.getProgress() >= 80){
ValueAnimator anim = ValueAnimator.ofInt(arg0.getProgress(), 100);
anim.setDuration(100);
anim.addUpdateListener(new AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
    int animProgress = (Integer) animation.getAnimatedValue();
    arg0.setProgress(animProgress);
    }
});
anim.start();
//arg0.setProgress(100);
sb.setVisibility(View.VISIBLE);

}
else{
}
}

@Override
public void onClick(View v) {
//Log.e()
sb.setVisibility(View.VISIBLE);
}

}





The xml file of the above activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/full_page_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/splashbg" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:layout_marginBottom="14dp"
     android:layout_alignParentBottom="true"
        >

        <SeekBar
            android:id="@+id/myseek"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="40dp"
             android:paddingRight="40dp"
            android:background="@android:color/transparent"
            android:clickable="false"
            android:max="100"
            android:progressDrawable="@android:color/transparent"
            android:thumb="@drawable/splashslider" />
       
    </RelativeLayout>

</RelativeLayout>

Sunday 19 July 2015

Add Special characters like nice curverd quotations in your text



The code is very simple to use


String alteredquote= '\u201D'+ "HELLO WORLD" + '\u201C';


you can find the html entites in the following link

http://www.javascripter.net/faq/mathsymbols.html


and to add color to the quotations



TextView  title = (TextView) findViewById(R.id.textview);
Spannable wordtoSpan = new SpannableString(alteredquote);
wordtoSpan.setSpan(new ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
wordtoSpan.setSpan(new ForegroundColorSpan(Color.RED),(alteredquote.length() - 1),(alteredquote.length()) , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
wordtoSpan.setSpan(new RelativeSizeSpan(1.5f), 0, 1,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
wordtoSpan.setSpan(new RelativeSizeSpan(1.5f), (alteredquote.length() - 1), (alteredquote.length()),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);


title.setText(wordtoSpan);


Enjoy!!!!1





Wednesday 8 July 2015

share pdf from url in android

Now you can share pdf from url ,its quiet easy 


check out the code

1. the async task to be performmed
private class DownloadFile extends AsyncTask<String, Void, Void>{

        @Override
        protected Void doInBackground(String... strings) {
            String fileUrl = strings[0];  //YOUR_URL_PDF.pdf
            String fileName = strings[1];  //ANY_NAME.PDF
            String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
            File folder = new File(extStorageDirectory, "testthreepdf");
            folder.mkdir();

            File pdfFile = new File(folder, fileName);

            try{
                pdfFile.createNewFile();
            }catch (IOException e){
                e.printStackTrace();
            }
            FileDownloader.downloadFile(fileUrl, pdfFile);
            return null;
        }

@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
  File pdfFile = new File(Environment.getExternalStorageDirectory() + "/testthreepdf/" + "ANY_NAME.pdf");  // -> filename = ANY_NAME.pdf
        Uri path = Uri.fromFile(pdfFile);
        Intent pdfIntent = new Intent(Intent.ACTION_SEND);
        pdfIntent.setDataAndType(path, "application/pdf");
        pdfIntent.putExtra(Intent.EXTRA_SUBJECT"subject");
        pdfIntent.putExtra(Intent.EXTRA_TEXT,     "your text");
        pdfIntent.putExtra(Intent.EXTRA_STREAM, path );
        pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        try{
            startActivity(pdfIntent);
        }catch(ActivityNotFoundException e){
            Toast.makeText(MainActivity.this, "Pdf could not be shared", Toast.LENGTH_SHORT).show();
           
          
        }
}
    }



2.call the async task in your share button

 new DownloadFile().execute("YOUR_URL_PDF.pdf", "ANY_NAME.pdf"); 




Thats it !!!!Enjoy

Saturday 4 July 2015

use snack bar library


use snack bar library
 from

https://github.com/Kennyc1012/SnackBar/tree/master/library/src/main/java/com/kenny/snackbar


public  static void maketoast(Activity c) {
 

new SnackBarItem.Builder(c)
.setMessageResource("No internet connection")
 
.setSnackBarMessageColorResource(R.color.white)
.setSnackBarBackgroundColorResource(R.color.blue)
.setInterpolatorResource(android.R.interpolator.accelerate_decelerate)
.setMessageTypeface(UtilsTyeFace.getHelveticaNeueLTArabicRoman(c))
.setDuration(5000)
.setSnackBarListener(new snackbarlistner())
.show();
}


}






snack bar listner
public class snackbarlistner implements SnackBarListener{

@Override
public void onSnackBarStarted(Object object) {
// TODO Auto-generated method stub
SharedObjects.getInstance().setCustomtoast(true);
}

@Override
public void onSnackBarFinished(Object object, boolean actionPressed) {
// TODO Auto-generated method stub
SharedObjects.getInstance().setCustomtoast(false);
Log.e("calledend","calledend");
}

}