This code able to convert the whole view in scrollview to images. It been tested and successfully working.
First image is from the mobile, after click the "save and print receipt" it will save the whole view and stored in image gallery. Second image is the result
Change Snippet Background Color
@BindView(R.id.native_resit)
protected ScrollView native_resit;
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
....
....
close_btn.setOnClickListener(new resitClickListener());
print_resit.setOnClickListener(new resitClickListener());
runRecieptData();
}
private class resitClickListener implements View.OnClickListener{
@Override
public void onClick(View view) {
if (view.getId() == R.id.close_btn){
getFragmentManager().popBackStack();
}
else if (view.getId() == R.id.print_resit){
print();
}
}
}
private void print(){
ProgressDialog dialog = new ProgressDialog(getActivity());
dialog.setMessage("Saving...");
dialog.show();
Bitmap bitmap = getBitmapFromView(native_resit,native_resit.getChildAt(0).getHeight(),native_resit.getChildAt(0).getWidth());
try {
File defaultFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Your_Folder");
if (!defaultFile.exists())
defaultFile.mkdirs();
String filename = "Order ID "+orderHistoryResponse.getOrderId()+".jpg";
File file = new File(defaultFile,filename);
if (file.exists()) {
file.delete();
file = new File(defaultFile,filename);
}
FileOutputStream output = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
output.flush();
output.close();
dialog.dismiss();
Toast.makeText(getActivity(), Message.RECEIPT_SAVE, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
dialog.dismiss();
Toast.makeText(getActivity(), Message.RECEIPT_SAVE_FAILED, Toast.LENGTH_SHORT).show();
}
}
//create bitmap from the view
private Bitmap getBitmapFromView(View view,int height,int width) {
Bitmap bitmap = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Drawable bgDrawable =view.getBackground();
if (bgDrawable!=null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
return bitmap;
}
After several attempt on how to wait all the fragment in view pager is loaded, i came out a solution where i create interface class to communicate between activity and the fragment..
Create Interface Class
Implement it on Activity class
Call it from each fragment at the off each process
Change Snippet Background Color
Create Interface as bridge between fragment and activity
public interface OnFragmentFinishLoad {
public void onFinish(String tag,boolean state);
}
Now Create Activity Class contain Viewpager.. (Code not complete)
public class PizzaActivity extends BaseActivity implements OnFragmentFinishLoad {
@BindView(R.id.cover_rl)
protected RelativeLayout cover_rl;
int countLoad = 0;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_carte_tab_layout);
cover_rl.setVisibility(View.VISIBLE);
setupViewPager(viewPager);
mTabLayout.setupWithViewPager(viewPager);
setupTabLayout(mTabLayout);
……
}
@Override public void onFinish(String tag, boolean state) {
if (state)
countLoad++;
//cat.size() is the number of fragment in view pager.
//each time fragment trigger this function, there will return true and countLoad will increase
//if number of true == cat.size() the loading will disappear
if (countLoad == cat.size() - 1) {
cover_rl.setVisibility(View.GONE);
}
}
}
Then, Create Fragment class,
public class PizzaFragment extends BaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.default_fragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
...
...
//run task
new AsyncDataTaskPizza().execute();
}
private class AsyncDataTaskPizza extends AsyncTask < Void, Void, Void > {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
//HTTP Call or else
}
@Override
protected void onPostExecute(List < PizzaDetail > result) {
// call this function after finish load everything
((OnFragmentFinishLoad) getActivity()).onFinish(null, true);
}
}
}
Create other Fragment class, do like the same or something else but last process must end with ((OnFragmentFinishLoad) getActivity()).onFinish(null, true); This is how i manage and i found that more easier to listen when all fragment in ViewPager is finish loading. :D
Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighbouring numbers is equal (note that 0 and n - 1 are neighbouring, too).
Given n and firstNumber, find the number which is written in the radially opposite position tofirstNumber.
Example
For n = 10 and firstNumber = 2, the output should be
circleOfNumbers(n, firstNumber) = 7.
Change Snippet Background Color
int circleOfNumbers(int n, int firstNumber) {
return (firstNumber+(n/2)) % n;
}
import java.util.*;
/**
Author : Hafiq
Date :
**/
public class HexaDec{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String line = System.getProperty("line.separator");
scan.useDelimiter(line);
int cases = scan.nextInt();
for(int x=0;x<cases;x++){
String[] split = scan.next().split(" ");
int one = Integer.parseInt(split[0],16);
int two = Integer.parseInt(split[1],16);
System.out.println(Integer.toHexString(one+two).toUpperCase());
}
}
}
import java.util.*;
/**
Author : Hafiq
Date :
**/
public class Aveg{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String line = System.getProperty("line.separator");
scan.useDelimiter(line);
int cases = scan.nextInt();
for(int x=0;x<cases;x++){
int count = scan.nextInt();
String[] split = scan.next().split(" ");
int [] num = new int[count];
for(int z=0;z<count;z++){
num[z] = Integer.parseInt(split[z]);
}
Arrays.sort(num);
int median = 0;double mean = 0;
int mid = count/2;
if(count%2 == 0)
median = (num[mid-1]+num[mid]) / 2;
else
median = num[mid];
for(int y=0;y<count;y++){
mean += num[y];
}
System.out.println("Average:"+mean/count+" Median:"+median);
}
}
}
import java.util.*;
/**
Author : Hafiq
Date :
**/
public class Winner{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String line = System.getProperty("line.separator");
scan.useDelimiter(line);
int cases = scan.nextInt();
int max = 0;
String current = "";
Event ev = new Event();
List event = new ArrayList<>();
for(int x=0;x(){
@Override
public int compare(Event e1,Event e2){
if (e1.gold > e2.gold) {
return -1;
} else if (e1.gold < e2.gold) {
return 1;
} else {
return 0;
}
}
});
for(Event e:event){
System.out.println(e.toString());
}
}
}
class Event{
public String name;
public int gold;
public int silver;
public int bronze;
public Event(){}
public Event(String a,int b,int c, int d){
name = a;
gold = b;
silver = c;
bronze = d;
}
public String toString(){
return name+" "+gold+" "+silver+" "+bronze;
}
}
Above images is where is tried to custom the tablayout to become the shape like that :D The designer design the UI like that and i have to came out a solution to custom it..
Note: I create it by my own. If you have better solution, you can suggest me :D TQ..
Below is the base init to custom tab layout
Tablayout tabs = (TabLayout)findViewById(R.id.tabs);
//cast the selected tablayout to viewgroupViewGroup vg = (ViewGroup) tabs.getChildAt(0);
//count how many tabs in tablayoutint tabsCount = vg.getChildCount();
//iterative each tabfor (int j =0; j < tabsCount; j++) {
//Get all element in each tabs and cast to viewgroupViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
//count the element in each tabsint tabChildsCount = vgTab.getChildCount();
for (int i =0; i < tabChildsCount; i++) {
// cast to ViewView tabViewChild = vgTab.getChildAt(i);
}
}
How to use
To change the font of the tabs. Just use View instanceOf TextView
// using built-in tablayout function to change indicator and text color but limited
tabs.setTabTextColors(ContextCompat.getColor(this, R.color.md_grey_500), ContextCompat.getColor(this, R.color.white));
tabs.setSelectedTabIndicatorColor(getResources().getColor(android.R.color.transparent));
Custom Tabs
// init your fontTypeface tf =Typeface.createFromAsset(getAssets(), "fonts/knockout-htf49-liteweight.ttf");
ViewGroup vg = (ViewGroup) tabs.getChildAt(0);
int tabsCount = vg.getChildCount();
for (int j =0; j < tabsCount; j++) {
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
int tabChildsCount = vgTab.getChildCount();
for (int i =0; i < tabChildsCount; i++) {
View tabViewChild = vgTab.getChildAt(i);
// Get TextView Elementif (tabViewChild instanceofTextView) {
// change font
((TextView) tabViewChild).setTypeface(tf);
// change color
((TextView) tabViewChild).setTextColor(getResources().getColor(R.color.white));
// change size
((TextView) tabViewChild).setTextSize(18);
// change padding
tabViewChild.setPadding(0, 0, 0, 0);
//..... etc...
}
}
}
To change background of the tabs
ViewGroup vg = (ViewGroup) tabs.getChildAt(0);
int tabsCount = vg.getChildCount();
for (int j =0; j < tabsCount; j++) {
View view = vg.getChildAt(j);
//change drawable for each tabs
view.setBackgroundResource(R.drawable.backgroundtabs);
//if you want to diff drawable for each tabs for example tabs is 4//if j == 0 view.setBackgroundResource(R.drawable.backgroundtabs1); //if j == 1 view.setBackgroundResource(R.drawable.backgroundtabs2);//if j == 2 view.setBackgroundResource(R.drawable.backgroundtabs3);//if j == 3 view.setBackgroundResource(R.drawable.backgroundtabs4);ViewGroup vgTab = (ViewGroup) view;
int tabChildsCount = vgTab.getChildCount();
for (int i =0; i < tabChildsCount; i++) {
View tabViewChild = vgTab.getChildAt(i);
}
}
Add listener if you want to track the tab changes
tabs.setOnTabSelectedListener(newTabLayout.OnTabSelectedListener() {
@OverridepublicvoidonTabSelected(TabLayout.Tabtab) {
// code what happen when tab is selected
}
@OverridepublicvoidonTabUnselected(TabLayout.Tabtab) {
// code what happen when tab is unselected
}
@OverridepublicvoidonTabReselected(TabLayout.Tabtab) {
// code what happen when the tab is reselected
}
});
To change background of the tablayout
<android.support.design.widget.TabLayout
android:layout_height="wrap_content"android:layout_width="match_parent"android:id="@+id/tabs"android:background="@drawable/stripetab" <-- create stripe background like example image
app:tabTextAppearance="@style/CustomTabStyle"/>
NOTES
if you want to use scrollable mode ...etc, You need to set the tabs size (i dont know why). If not, it will looks ugly
My case: i hardcode the width to 120dp (you can change it or just calculate by your own for your perfect size)
int width =120; // width - width of tabs int tabsize =120* tabcount; // tabcount - number of tabsViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
if (sizeScreen() < tabsize)
vgTab.getLayoutParams().width = dpToPx(120);
publicint dpToPx(int dp) {
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
returnMath.round(dp * (displayMetrics.xdpi /DisplayMetrics.DENSITY_DEFAULT));
}
publicint sizeScreen(){
return (int)((Resources.getSystem().getDisplayMetrics().widthPixels)/Resources.getSystem().getDisplayMetrics().density);
}
This is example of what im doing
privatevoid setupTabLayout(finalTabLayout tabs) {
tabs.setTabTextColors(ContextCompat.getColor(this, R.color.md_grey_500), ContextCompat.getColor(this, R.color.white));
tabs.setSelectedTabIndicatorColor(getResources().getColor(android.R.color.transparent));
if (sizeScreen()<tabsize){
tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
tabs.setTabGravity(TabLayout.GRAVITY_FILL);
}
else{
tabs.setTabMode(TabLayout.MODE_FIXED);
tabs.setTabGravity(TabLayout.GRAVITY_FILL);
}
// CHANGE TAB TEXT FONTTypeface tf =Typeface.createFromAsset(getAssets(), "fonts/knockout-htf49-liteweight.ttf");
ViewGroup vg = (ViewGroup) tabs.getChildAt(0);
int tabsCount = vg.getChildCount();
for (int j =0; j < tabsCount; j++) {
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
if (j==0){
View view = vg.getChildAt(j);
view.setBackgroundResource(R.drawable.backgroundtabs);
}
if (sizeScreen()<tabsize) {
vgTab.getLayoutParams().width = dpToPx(120);
}
int tabChildsCount = vgTab.getChildCount();
for (int i =0; i < tabChildsCount; i++) {
View tabViewChild = vgTab.getChildAt(i);
if (tabViewChild instanceofTextView) {
((TextView) tabViewChild).setTypeface(tf);
((TextView) tabViewChild).setTextSize(18);
((TextView) tabViewChild).setAllCaps(true);
((TextView) tabViewChild).setSingleLine(true);
//set the text to marquee if text longer than tabs size
((TextView) tabViewChild).setEllipsize(TextUtils.TruncateAt.MARQUEE);
((TextView) tabViewChild).setMarqueeRepeatLimit(100);
if (j==0){
tabViewChild.setPadding(0, 0, 0, 0);
}
else {
tabViewChild.setPadding(0, padding, 0, 0);
}
}
}
}
// add listener when tab is change
tabs.setOnTabSelectedListener(newTabLayout.OnTabSelectedListener() {
ViewGroup vg = (ViewGroup) tabs.getChildAt(0);
@OverridepublicvoidonTabSelected(TabLayout.Tabtab) {
ViewGroup vgTab = (ViewGroup) vg.getChildAt(tab.getPosition());
if (tab.getPosition()==0)
vg.getChildAt(tab.getPosition()).setBackgroundResource(R.drawable.backgroundtabs);
elseif (tab.getPosition()==tabcount-1)
vg.getChildAt(tab.getPosition()).setBackgroundResource(R.drawable.backgroundtabs_last);
else
vg.getChildAt(tab.getPosition()).setBackgroundResource(R.drawable.backgroundtabs_middle);
int tabChildsCount = vgTab.getChildCount();
for (int i =0; i < tabChildsCount; i++) {
View tabViewChild = vgTab.getChildAt(i);
if (tabViewChild instanceofTextView) {
tabViewChild.setPadding(0, 0, 0, 0);
}
}
viewPager.setCurrentItem(tab.getPosition());
}
@OverridepublicvoidonTabUnselected(TabLayout.Tabtab) {
ViewGroup vgTab = (ViewGroup) vg.getChildAt(tab.getPosition());
vg.getChildAt(tab.getPosition()).setBackgroundResource(0);
int tabChildsCount = vgTab.getChildCount();
for (int i =0; i < tabChildsCount; i++) {
View tabViewChild = vgTab.getChildAt(i);
if (tabViewChild instanceofTextView) {
tabViewChild.setPadding(0, padding, 0, 0);
}
}
}
@OverridepublicvoidonTabReselected(TabLayout.Tabtab) {
}
});
}
private static boolean findDuplicate(String str){
Map map = new HashMap<>();
char[] getChar = str.toCharArray();
for(Character isDuplicate:getChar){
if(map.containsKey(isDuplicate)){
// plus 1 if found same character
map.put(isDuplicate, map.get(isDuplicate)+1);
} else {
// add 1 to new Character
map.put(isDuplicate, 1);
}
}
Set keys = map.keySet();
for(Character isDuplicate:keys){
if(map.get(isDuplicate) > 1){
//found more than 1
return true;
}
}
return false;
}
This Autokey is polyalphabet Substitution cipher. In this cipher, the key is a stream of subkeys which is each subkey is used to encrypt the corresponding character in the plaintext.
For example
Plaintext --> F O L L O W D I R E C T I O N
Key --> P F O L L O W D I R E C T I O
As shown, the key is add the first of subkeys.
Lets Encrypt
F O L L O W D I R E C T I O N
P F O L L O W D I R E C T I O
-----------------------------
(+) U T Z W Z K Z L Z V G V B W B
-----------------------------
* can use vigenere table to calculate
Lets Decrypt
Put the key first
P
-----------------------------
U T Z W Z K Z L Z V G V B W B
-----------------------------
Do subtraction cipher - key. ex: U - P = F . Add F plaintext letter to the end of the keystream.
F
P F
-----------------------------
U T Z W Z K Z L Z V G V B W B
-----------------------------
Do subtraction cipher - key. ex: T - F = O . Again add O plaintext letter to the end of the keystream.
F O
P FO
-----------------------------
U T Z W Z K Z L Z V G V B W B
-----------------------------
F O L
P F O L
-----------------------------
U T Z W Z K Z L Z V G V B W B
-----------------------------
F O L L
P F O L L
-----------------------------
U T Z W Z K Z L Z V G V B W B
-----------------------------
continue subtraction until
F O L L O W D I R E C T I O N
P F O L L O W D I R E C T I O
-----------------------------
U T Z W Z K Z L Z V G V B W B
-----------------------------
DONE!
Change Snippet Background Color
/*
Autokey encryption and decryption
*/
import java.util.*;
import java.lang.*;
import java.math.*;
public class Autokey{
private static String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static void main(String[] args){
String text = "FOLLOWDIRECTION";
String key = "P"; //15 - P
if(key.matches("[-+]?\\d*\\.?\\d+"))
key = ""+alpha.charAt(Integer.parseInt(key));
String enc = AutoEncryption(text,key);
System.out.println("Plaintext : "+text);
System.out.println("Encrypted : "+enc);
System.out.println("Decrypted : "+AutoDecryption(enc,key));
}
public static String AutoEncryption(String text,String key){
int len = text.length();
String subkey = key + text;
subkey = subkey.substring(0,subkey.length()-key.length());
String sb = "";
for(int x=0;x<len;x++){
int get1 = alpha.indexOf(text.charAt(x));
int get2 = alpha.indexOf(subkey.charAt(x));
int total = (get1 + get2)%26;
sb += alpha.charAt(total);
}
return sb;
}
public static String AutoDecryption(String text,String key){
int len = text.length();
String current = key;
String sb ="";
for(int x=0;x<len;x++){
int get1 = alpha.indexOf(text.charAt(x));
int get2 = alpha.indexOf(current.charAt(x));
int total = (get1 - get2)%26;
total = (total<0)? total + 26 : total;
sb += alpha.charAt(total);
current += alpha.charAt(total);
}
return sb;
}
}
We are given an array of n points , and the problem is to find out the closest pair of points in the array. This problem arises in a number of applications. For example, in air-traffic control, you may want to monitor planes that come too close together, since this may indicate a possible collision. Recall the following formula for distance between two points p and q.
The Brute force solution is O(n^2), compute the distance between each pair and return the smallest. For faster solution to find smallest distance in O(nLogn) time using Divide and Conquer strategy.
In this case, Brute force produce must faster if the list of Coordinate we want to compare is less than 50.
But,
Divide and Conquer strategy can process large amount > 50 of list more faster than brute force.
This is the time execution for both method
1000 list
Brute force (462 ms)
Divide and conquer (56 ms)
500 list
Brute force (147 ms)
Divide and conquer (14 ms)
100 list
Brute force (10 ms)
Divide and conquer (8 ms)
50 list
Brute force (3 ms)
Divide and conquer (5 ms)
10 list
Brute force (1 ms)
Divide and conquer (3 ms)
Change Snippet Background Color
import java.io.*;
import java.util.*;
public class ClosestCoorFinder {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String line = System.getProperty("line.separator");
scan.useDelimiter(line);
List<Coordinate> points = new ArrayList<>();
Random random = new Random();
for (int x=0;x<1000;x++){
points.add(new Coordinate(random.nextInt(),random.nextInt()));
}
long startTime = System.currentTimeMillis();
CoordinateDetail bruteForceClosestPair = bruteForce(points);
long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Brute force (" + elapsedTime + " ms): " + bruteForceClosestPair);
startTime = System.currentTimeMillis();
CoordinateDetail dqClosestPair = divideAndConquer(points);
elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Divide and conquer (" + elapsedTime + " ms): " + dqClosestPair);
}
private static class Coordinate {
private double x;
private double y;
public Coordinate(int id, double x, double y) {
this.id = id;
this.x = x;
this.y = y;
}
public int getId() {
return id;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public String toString() {
return "(" + x + ", " + y +")";
}
}
private static class CoordinateDetail {
private Coordinate point1 = null;
private Coordinate point2 = null;
private double distance = 0.0;
public CoordinateDetail(Coordinate point1, Coordinate point2, double distance) {
this.point1 = point1;
this.point2 = point2;
this.distance = distance;
}
public Coordinate getPoint1() {
return point1;
}
public Coordinate getPoint2() {
return point2;
}
public double getDistance() {
return distance;
}
public void set(Coordinate point1, Coordinate point2, double distance) {
this.point1 = point1;
this.point2 = point2;
this.distance = distance;
}
public String toString() {
return getPoint1() +" "+getPoint2()+" : distance = "+getDistance();
}
}
private static double calDistance(Coordinate p1, Coordinate p2) {
double xdist = p2.getX() - p1.getX();
double ydist = p2.getY() - p1.getY();
return Math.hypot(xdist, ydist);
}
// much faster than DnV for list of Coordinate is less than 100
private static CoordinateDetail bruteForce(List<Coordinate> points) {
int coorSize = points.size();
if (coorSize < 2)
return null;
CoordinateDetail coorPoint = new CoordinateDetail(points.get(0), points.get(1),calDistance(points.get(0), points.get(1)));
if (coorSize > 2) {
for (int i = 0; i < coorSize - 1; i++) {
Coordinate point1 = points.get(i);
for (int j = i + 1; j < coorSize; j++) {
Coordinate point2 = points.get(j);
double distance = calDistance(point1, point2);
if (distance < coorPoint.getDistance())
coorPoint.set(point1, point2, distance);
}
}
}
return coorPoint;
}
private static void sortByX(List<Coordinate> points) {
Collections.sort(points, new Comparator < Coordinate > () {
public int compare(Coordinate point1, Coordinate point2) {
if (point1.getX() < point2.getX())
return -1;
if (point1.getX() > point2.getX())
return 1;
return 0;
}
});
}
private static void sortByY(List<Coordinate> points) {
Collections.sort(points, new Comparator <Coordinate> () {
public int compare(Coordinate point1, Coordinate point2) {
if (point1.getY() < point2.getY())
return -1;
if (point1.getY() > point2.getY())
return 1;
return 0;
}
});
}
// much faster than bruteforce for list of Coordinate is more than 100
public static CoordinateDetail divideAndConquer(List<Coordinate> points) {
List<Coordinate> listofSortedX = new ArrayList<> (points);
sortByX(listofSortedX);
List<Coordinate> listofSortedY = new ArrayList<> (points);
sortByY(listofSortedY);
return divideAndConquer(listofSortedX, listofSortedY);
}
private static CoordinateDetail divideAndConquer(List<Coordinate> listofSortedX, List<Coordinate> listofSortedY) {
int coorSize = listofSortedX.size();
if (coorSize <= 3)
return bruteForce(listofSortedX);
int index = coorSize >>> 1;
List<Coordinate>leftOfCenter = listofSortedX.subList(0, index);
List<Coordinate>rightOfCenter = listofSortedX.subList(index, coorSize);
List<Coordinate>tempList= new ArrayList<>(leftOfCenter);
sortByY(tempList);
CoordinateDetail closestPair = divideAndConquer(leftOfCenter, tempList);
tempList.clear();
tempList.addAll(rightOfCenter);
sortByY(tempList);
CoordinateDetail closestPairRight = divideAndConquer(rightOfCenter, tempList);
if (closestPairRight.getDistance() < closestPair.getDistance())
closestPair = closestPairRight;
tempList.clear();
double shortestDistance = closestPair.getDistance();
double centerX = rightOfCenter.get(0).getX();
for (Coordinate point: listofSortedY)
if (Math.abs(centerX - point.getX()) < shortestDistance)
tempList.add(point);
for (int i=0; i<tempList.size()-1;i++) {
Coordinate point1 = tempList.get(i);
for (int j=i+1;j<tempList.size();j++) {
Coordinate point2 = tempList.get(j);
if ((point2.getY() - point1.getY()) >= shortestDistance)
break;
double distance = calDistance(point1, point2);
if (distance < closestPair.getDistance()) {
closestPair.set(point1, point2, distance);
shortestDistance = distance;
}
}
}
return closestPair;
}
}