Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
talhahasanzia / MyListView.java
Created June 19, 2017 07:06
Listview with extra spaces (padding)
public class MyListView extends ListView
{
private android.view.ViewGroup.LayoutParams params;
private int oldCount = 0;
public MyListView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@talhahasanzia
talhahasanzia / FirstRecylerAdapter.java
Created June 18, 2017 18:40
Recyler adapter with view holder pattern
public class FirstRecylerAdapter extends RecyclerView.Adapter<FirstRecylerAdapter.MyViewHolder> {
private List<Integer> imageList;
public class MyViewHolder extends RecyclerView.ViewHolder {
public ImageView image;
public MyViewHolder(View view) {
super(view);
image = (ImageView) view.findViewById(R.id.image);
@talhahasanzia
talhahasanzia / drop_shadow.xml
Created June 16, 2017 08:00
Drop shadow effect for all android versions
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<gradient
android:angle="360"
android:centerColor="#dcdcdc"
android:endColor="#e7e7e7"
android:gradientRadius="360"
@talhahasanzia
talhahasanzia / build.gradle
Last active June 5, 2017 08:12
APIs inclusion.
// tests
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.10.19"
@talhahasanzia
talhahasanzia / Compass.java
Last active May 9, 2017 07:15
Java direction to specific place compass.
@Override
public void onSensorChanged( SensorEvent event )
{
if ( currentLocation != null )
{
// get accelerometer data
if ( event.sensor.getType() == Sensor.TYPE_ACCELEROMETER )
@talhahasanzia
talhahasanzia / assets.java
Created February 22, 2017 07:55
Assets folder URI
Uri.parse("file:///android_asset/myfile.mp3")
@talhahasanzia
talhahasanzia / object_creation.js
Last active February 8, 2017 08:49
Node JS tutorials.
function User() {
this.id=0;
this.name="";
this.description="";
this.newDescription=function (newDescriptionData) {
this.description=newDescriptionData;
};
@talhahasanzia
talhahasanzia / MainActivity.java
Created February 2, 2017 09:46
Intent Service Example
public class MainActivity extends AppCompatActivity
{
private ResponseReceiver receiver;
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
@talhahasanzia
talhahasanzia / CustomFontTextView.java
Created January 26, 2017 06:33
Custom font in a predefined textview
public class CustomFontTextView extends TextView
{
public CustomFontTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public CustomFontTextView(Context context, AttributeSet attrs) {
super(context, attrs);
@talhahasanzia
talhahasanzia / PermissionsExample.java
Last active July 17, 2018 11:20
Location and Wifi Permissions Example
public static class PermissionsExample
{
public static void getLocationPermission( AppCompatActivity thisActivity )
{
if ( ActivityCompat.checkSelfPermission( thisActivity, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission( thisActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION ) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission( thisActivity, android.Manifest.permission.INTERNET ) != PackageManager.PERMISSION_GRANTED )
{