π§
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
import android.app.Service; | |
import android.content.Intent; | |
import android.graphics.PixelFormat; | |
import android.opengl.Visibility; | |
import android.os.IBinder; | |
import android.view.Gravity; | |
import android.view.LayoutInflater; | |
import android.view.MotionEvent; | |
import android.view.View; | |
import android.view.WindowManager; |
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
import android.content.Intent; | |
import android.net.Uri; | |
import android.os.Build; | |
import android.os.Bundle; | |
import android.provider.Settings; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { |
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
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content"> | |
<!--Root container--> | |
<RelativeLayout | |
android:id="@+id/root_container" |
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
case MotionEvent.ACTION_UP: | |
int Xdiff = (int) (event.getRawX() - initialTouchX); | |
int Ydiff = (int) (event.getRawY() - initialTouchY); | |
//The check for Xdiff <10 && YDiff< 10 because sometime elements moves a little while clicking. | |
//So that is click event. | |
if (Xdiff < 10 && Ydiff < 10) { | |
if (isViewCollapsed()) { | |
//When user clicks on the image view of the collapsed layout, | |
//visibility of the collapsed layout will be changed to "View.GONE" |
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
public class SingletonClass { | |
private static SingletonClass sSoleInstance; | |
private SingletonClass(){} //private constructor. | |
public static SingletonClass getInstance(){ | |
if (sSoleInstance == null){ //if there is no instance available... create new one | |
sSoleInstance = new SingletonClass(); | |
} |
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
public class SingletonTester { | |
public static void main(String[] args) { | |
//Instance 1 | |
SingletonClass instance1 = SingletonClass.getInstance(); | |
//Instance 2 | |
SingletonClass instance2 = SingletonClass.getInstance(); | |
//now lets check the hash key. | |
System.out.println("Instance 1 hash:" + instance1.hashCode()); |
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
public class SingletonTester { | |
public static void main(String[] args) { | |
//Create the 1st instance | |
SingletonClass instance1 = SingletonClass.getInstance(); | |
//Create 2nd instance using Java Reflection API. | |
SingletonClass instance2 = null; | |
try { | |
Class<SingletonClass> clazz = SingletonClass.class; | |
Constructor<SingletonClass> cons = clazz.getDeclaredConstructor(); |
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
public class SingletonClass { | |
private static SingletonClass sSoleInstance; | |
//private constructor. | |
private SingletonClass(){ | |
//Prevent form the reflection api. | |
if (sSoleInstance != null){ | |
throw new RuntimeException("Use getInstance() method to get the single instance of this class."); |
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
public class SingletonTester { | |
public static void main(String[] args) { | |
//Thread 1 | |
Thread t1 = new Thread(new Runnable() { | |
@Override | |
public void run() { | |
SingletonClass instance1 = SingletonClass.getInstance(); | |
System.out.println("Instance 1 hash:" + instance1.hashCode()); | |
} | |
}); |
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
public class SingletonClass { | |
private static SingletonClass sSoleInstance; | |
//private constructor. | |
private SingletonClass(){ | |
//Prevent form the reflection api. | |
if (sSoleInstance != null){ | |
throw new RuntimeException("Use getInstance() method to get the single instance of this class."); |