package com.example.appautocompletetextviewdemo1;

//LAMW: Lazarus Android Module Wizard  - version 0.7 - 04 July - 2016
//RAD Android: Project Wizard, Form Designer and Components Development Model!

//https://github.com/jmpessoa/lazandroidmodulewizard
//http://forum.lazarus.freepascal.org/index.php/topic,21919.270.html

//Android Java Interface for LAZARUS [december/2013 by jmpessoa]

//Developers:
//          Simon,Choi / Choi,Won-sik
//                       simonsayz@naver.com
//                       http://blog.naver.com/simonsayz
//
//          LoadMan    / Jang,Yang-Ho
//                       wkddidgh@naver.com
//                       http://blog.naver.com/wkddidgh
//
//          Jose Marques Pessoa   / jmpessoa@hotmail.com
//
//Version
//History
//			2013.02.24 ver0.01 Started
//			2013.02.28 ver0.02 added Delphi Style
//			2013.03.01 ver0.03 added sysInfo
//			2013.03.05 ver0.04 added Java Loading Png
//			2013.03.08 ver0.05 Restructuring (Interlation #.02)
//			2013.07.13 ver0.06 added TForm
//			2013.07.22 ver0.07 added Back Event for Close
//			2013.07.26 ver0.08 Class,Method Cache (Single Thread,Class)
//			2013.07.30 ver0.09 added TEditText Keyboard,Focus
//			2013.08.02 ver0.10 added TextView - Enabled
//			2013.08.05 ver0.11 added Form Object
//			2013.08.11 ver0.12 added Canvas
//                              added Direct Bitmap access
//			2013.08.14 ver0.13 Fixed Memory Leak
//			2013.08.18 ver0.14 added OpenGL ES1 2D (Stencil)
//			2013.08.21 ver0.15 Fixed jImageBtn Memory Leak
//                              Fixed Socket Buffer
//			2013.08.23 ver0.16 Fixed Memory Leak for Form,Control
//                              added Form Stack
//			2013.08.24 ver0.17 added Thread
//			2013.08.26 ver0.18 added OpenGL ES2 2D/3D
//                              added Button Font Color/Height
//			2013.08.31 ver0.19 added Unified OpenGL ES1,2 Canvas
//                              added OpenGL ES1,2 Simulator for Windows
//			2013.09.01 ver0.20 added GLThread on Canvas
//                              Fixed OpenGL Crash
//                              rename example Name
//			12.2013 LAMW Started by jmpessoa

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Dialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.hardware.Sensor;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.os.Vibrator;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.provider.ContactsContract;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.Toast;
import java.io.*;
import java.lang.Class;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.lang.reflect.*;

//-------------------------------------------------------------------------
//Constants
//-------------------------------------------------------------------------
class Const {
  public static final int TouchDown                   =  0;
  public static final int TouchMove                   =  1;
  public static final int TouchUp                     =  2;
  public static final int Click_Default               =  0;
}

//-------------------------------------------------------------------------
//Form
//-------------------------------------------------------------------------
class jForm {
// Java-Pascal Interface
private long             PasObj   = 0;     // Pascal Obj
private Controls        controls = null;   // Control Class for Event
private RelativeLayout  layout   = null;
private LayoutParams    layparam = null;
private RelativeLayout  parent   = null;
private OnClickListener onClickListener;   // event
private OnClickListener onViewClickListener;   // generic delegate event
private OnItemClickListener onListItemClickListener;
private Boolean         enabled  = true;   //
private Intent intent;
private int mCountTab = 0;

// Constructor
public  jForm(Controls ctrls, long pasobj) {
PasObj   = pasobj;
controls = ctrls;
layout   = new RelativeLayout(controls.activity);
layparam = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                            ViewGroup.LayoutParams.MATCH_PARENT);
layout.setLayoutParams(layparam);
// Init Event
onClickListener = new OnClickListener() {
  public  void onClick(View view) {
    if (enabled) {
      controls.pOnClick(PasObj,Const.Click_Default);
    }
  };
};

//geric list item click Event - experimental component model!
onListItemClickListener = new OnItemClickListener() {
@Override
public  void onItemClick(AdapterView<?> parent, View v, int position, long id) {
     controls.jAppOnListItemClick(parent, v, position, v.getId());
}
};

//Init Event
onViewClickListener = new OnClickListener() {
public  void onClick(View view) {
 if (enabled) {
   controls.jAppOnViewClick(view, view.getId());
 }
};
};

layout.setOnClickListener(onClickListener);

}

public  RelativeLayout GetLayout() {
  return layout;
}

public  RelativeLayout GetView() {
	  return layout;
}

public  void Show(int effect) {
   controls.appLayout.addView(layout);
   parent = controls.appLayout;
}

public  void Close(int effect ) {
    controls.pOnClose(PasObj);
}

public  void Close2() {
  controls.appLayout.removeView(layout);
  controls.pOnClose(PasObj);
}

public boolean IsConnected(){ // by renabor
   boolean r = false;
   ConnectivityManager cm =  (ConnectivityManager)controls.activity.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (cm == null) return r;
   NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
   if (activeNetwork == null) return r;
   return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

public boolean IsConnectedWifi(){ // by renabor
   boolean r = false;
   ConnectivityManager cm =  (ConnectivityManager)controls.activity.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (cm == null) return r;
   NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
   if (activeNetwork == null) return r;
   return activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
}

public boolean IsConnectedTo(int _connectionType) {
	   int r = -1;
	   if (!IsConnected()) return false;
	   ConnectivityManager cm =  (ConnectivityManager)controls.activity.getSystemService(Context.CONNECTIVITY_SERVICE);
	   NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
	   if (activeNetwork != null) {
		  switch (activeNetwork.getType()){
		  case ConnectivityManager.TYPE_MOBILE: r = 0; break;  //0
		  case ConnectivityManager.TYPE_WIFI: r = 1; break;  //1
 		  case ConnectivityManager.TYPE_BLUETOOTH: r = 2; break; //7
		  case ConnectivityManager.TYPE_ETHERNET: r = 3; break; //9
		  }
	   }
	   if (r == _connectionType)
		   return true;
	   else
		  return false;

}
//
public  void SetVisible ( boolean visible ) {
if (visible) { if (layout.getParent() == null)
               { controls.appLayout.addView(layout); } }
else         { if (layout.getParent() != null)
               { controls.appLayout.removeView(layout); } };
}

//
public  void SetEnabled ( boolean enabled ) {
for (int i = 0; i < layout.getChildCount(); i++) {
  View child = layout.getChildAt(i);
  child.setEnabled(enabled);
}

}

public void ShowMessage(String msg){
  Log.i("ShowMessage", msg);
  Toast.makeText(controls.activity, msg, Toast.LENGTH_SHORT).show();
}

public String GetDateTime() {
  SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss", Locale.getDefault() );
  return( formatter.format ( new Date () ) );
}

//Free object except Self, Pascal Code Free the class.
 public void Free() {
   if (parent != null) { controls.appLayout.removeView(layout); }
   onClickListener = null;
   layout.setOnClickListener(null);
   layparam = null;
   layout   = null;
 }

 //http://startandroid.ru/en/lessons/complete-list/250-lesson-29-invoking-activity-and-getting-a-result-startactivityforresult-method.html
public String GetStringExtra(Intent data, String extraName) {
		String valueStr;
		valueStr= "";
	    if (data != null) {
	    	valueStr = data.getStringExtra(extraName);
	    }
	    return valueStr;
}

public int GetIntExtra(Intent data, String extraName, int defaultValue) {
	int value;
	value = defaultValue;
    if (data != null) {
    	value = data.getIntExtra(extraName, defaultValue);
    }
    return value;
}

public double GetDoubleExtra(Intent data, String extraName, double defaultValue) {
	double value;
	value = defaultValue;
    if (data != null) {
    	value = data.getDoubleExtra(extraName, defaultValue);
    }
    return value;
}

public  OnClickListener GetOnViewClickListener () {
	return this.onViewClickListener;
}

public  OnItemClickListener  GetOnListItemClickListener  () {
	return this.onListItemClickListener;
}

public int getSystemVersion()
{
	return controls.systemVersion;
}

 public boolean SetWifiEnabled(boolean _status) {
    WifiManager wifiManager = (WifiManager)this.controls.activity.getSystemService(Context.WIFI_SERVICE);
    return wifiManager.setWifiEnabled(_status);
 }

 public boolean IsWifiEnabled() {
    WifiManager wifiManager = (WifiManager)this.controls.activity.getSystemService(Context.WIFI_SERVICE);
    return  wifiManager.isWifiEnabled();
 }

 public boolean IsMobileDataEnabled() {
   boolean mobileDataEnabled = false; // Assume disabled
   ConnectivityManager cm = (ConnectivityManager) controls.activity.getSystemService(Context.CONNECTIVITY_SERVICE);
   try {
      final Class<?> cmClass = Class.forName(cm.getClass().getName());
      Method method = cmClass.getDeclaredMethod("getMobileDataEnabled");
      method.setAccessible(true); // Make the method callable
      // get the setting for "mobile data"
      mobileDataEnabled = (Boolean)method.invoke(cm);
   } catch (Exception e) {
     // Some problem accessible private API
     // TODO do whatever error handling you want here
   }
   return mobileDataEnabled;
 }

public String GetEnvironmentDirectoryPath(int _directory) {

	File filePath= null;
	String absPath="";   //fail!

	//Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);break; //only Api 19!
	if (_directory != 8) {
	  switch(_directory) {
	    case 0:  filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); break;
	    case 1:  filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); break;
	    case 2:  filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC); break;
	    case 3:  filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); break;
	    case 4:  filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS); break;
	    case 5:  filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); break;
	    case 6:  filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS); break;
	    case 7:  filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES); break;

	    case 9: absPath  = this.controls.activity.getFilesDir().getAbsolutePath(); break;      //Result : /data/data/com/MyApp/files
	    case 10: absPath = this.controls.activity.getFilesDir().getPath();
	             absPath = absPath.substring(0, absPath.lastIndexOf("/")) + "/databases"; break;
	    case 11: absPath = this.controls.activity.getFilesDir().getPath();
                 absPath = absPath.substring(0, absPath.lastIndexOf("/")) + "/shared_prefs"; break;

	  }

	  //Make sure the directory exists.
      if (_directory < 8) {
    	 filePath.mkdirs();
    	 absPath= filePath.getPath();
      }

	}else {  //== 8
	    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) == true) {
	    	filePath = Environment.getExternalStorageDirectory();  //sdcard!
	    	// Make sure the directory exists.
	    	filePath.mkdirs();
	   	    absPath= filePath.getPath();
	    }
	}

	return absPath;
}

public String GetInternalAppStoragePath() { //GetAbsoluteDirectoryPath
   String PathDat = this.controls.activity.getFilesDir().getAbsolutePath();       //Result : /data/data/com/MyApp/files
   return PathDat;
}

private void copyFileUsingFileStreams(File source, File dest)
		throws IOException {
	InputStream input = null;
	OutputStream output = null;
	try {
		input = new FileInputStream(source);
		output = new FileOutputStream(dest);
		byte[] buf = new byte[1024];
		int bytesRead;
		while ((bytesRead = input.read(buf)) > 0) {
			output.write(buf, 0, bytesRead);
		}
	} finally {
		input.close();
		output.close();
	}
}

public boolean CopyFile(String _scrFullFileName, String _destFullFileName) {
	File src= new File(_scrFullFileName);
	File dest= new File(_destFullFileName);
	try {
		copyFileUsingFileStreams(src, dest);
		return true;
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return false;
	}
}

//ref. https://xjaphx.wordpress.com/2011/10/02/store-and-use-files-in-assets/
//result: path to new storage [Internal App Storage]
public String LoadFromAssets(String _filename){

	    String pathRes="";

		InputStream is = null;
		FileOutputStream fos = null;
		String PathDat = controls.activity.getFilesDir().getAbsolutePath();
		try {
			File outfile = new File(PathDat, _filename);

			fos = new FileOutputStream(outfile);  //save to data/data/your_package/files/your_file_name
			is = controls.activity.getAssets().open(_filename);
			int size = is.available();
			byte[] buffer = new byte[size];

			for (int c = is.read(buffer); c != -1; c = is.read(buffer)){
		      fos.write(buffer, 0, c);
			}
			is.close();
			fos.close();
			pathRes= PathDat +"/"+ _filename;

		}catch (IOException e) {
		     e.printStackTrace();
		}

		return pathRes;
}

public boolean IsSdCardMounted() {
   return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}

public void DeleteFile(String _filename) {
   this.controls.activity.deleteFile(_filename);
}

public void DeleteFile(String _fullPath, String _filename) {
   File file;
   if ( _fullPath.equalsIgnoreCase("") ) {
      file = new File(Environment.getExternalStorageDirectory()+"/"+ _filename); // root
   }
   else {
	  file = new File(_fullPath+"/"+ _filename);
   }
   file.delete();
}

public void DeleteFile(int _environmentDir, String _filename) {
	String baseDir = GetEnvironmentDirectoryPath(_environmentDir);
	if (!baseDir.equalsIgnoreCase("")) {
   	    File file = new File(baseDir, _filename);
	    file.delete();
	}
}

public String CreateDir(String _dirName) {
	this.controls.activity.getDir(_dirName, 0); //if not exist -->> CREATE!
    String absPath = this.controls.activity.getFilesDir().getPath();
    absPath = absPath.substring(0, absPath.lastIndexOf("/")) + "/"+_dirName;
	return absPath;
}

public String CreateDir(int _environmentDir, String _dirName) {
    String baseDir = GetEnvironmentDirectoryPath(_environmentDir);
    if (!baseDir.equalsIgnoreCase("")) {
       File file = new File(baseDir, _dirName);
       file.mkdirs();
  	  return file.getPath();
    }else return "";
}

public String CreateDir(String _fullPath, String _dirName) {
    File file = new File(_fullPath, _dirName);
    file.mkdirs();
    return file.getPath();
}

/*
Added in API level 11
Returns whether the primary "external" storage device is emulated. If true,
data stored on this device will be stored on a portion of the internal storage system.
*/
public boolean IsExternalStorageEmulated () {
  return  Environment.isExternalStorageEmulated();
}

/*
Added in API level 9
Returns whether the primary "external" storage device is removable.
*/
public boolean IsExternalStorageRemovable() {
	return  Environment.isExternalStorageRemovable();
}

//
public  String GetjFormVersionFeatures() {
    String listVersionInfo =
		   "6$5=SetWifiEnabled;" +  //[0.6-05]
		   "6$5=IsWifiEnabled;" +
		   "6$5=GetEnvironmentDirectoryPath;" +
		   "6$5=GetInternalAppStoragePath;" +
		   "6$5=CopyFile;" +
		   "6$5=LoadFromAssets;" +
		   "6$5=IsSdCardMounted;" +
		   "6$5=DeleteFile;" +
		   "6$5=CreateDir;" +
		   "6$5=IsExternalStorageEmulated;" +
		   "6$5=IsExternalStorageRemovable";
    return listVersionInfo;
}

/*
*Given that you can access R.java just fine normally in code.
*As long as you are retrieving data from your application's R.java - Use reflection!
*/
public int GetStringResourceId(String _resName) {
	  try {
	     Class<?> res = R.string.class;
	     Field field = res.getField(_resName);
	     int strId = field.getInt(null);
	     return strId;
	   }
	   catch (Exception e) {
	     Log.e("jForm", "Failure to Get String  Resource", e);
	     return 0;
	   }
}

public String GetStringResourceById(int _resID) {
   return (String)( this.controls.activity.getResources().getText(_resID));
}

public int GetDrawableResourceId(String _resName) {
	  try {
	     Class<?> res = R.drawable.class;
	     Field field = res.getField(_resName);  //"drawableName"
	     int drawableId = field.getInt(null);
	     return drawableId;
	  }
	  catch (Exception e) {
	     Log.e("jForm", "Failure to get drawable id.", e);
	     return 0;
	  }
}

public Drawable GetDrawableResourceById(int _resID) {
	return (Drawable)( this.controls.activity.getResources().getDrawable(_resID));
}

//by  thierrydijoux
public String GetQuantityStringByName(String _resName, int _quantity) {
	int id = this.controls.activity.getResources().getIdentifier(_resName, "plurals", this.controls.activity.getPackageName());
  String value = id == 0 ? "" : (String) this.controls.activity.getResources().getQuantityString(id, _quantity, _quantity);
	return value;
}

//by thierrydijoux
public String GetStringResourceByName(String _resName) {
	int id = this.controls.activity.getResources().getIdentifier(_resName, "string", this.controls.activity.getPackageName());
  String value = id == 0 ? "" : (String) this.controls.activity.getResources().getText(id);
	return value;
}

public ActionBar GetActionBar() {
    return this.controls.activity.getActionBar();
}

/*
 * To disableAction-bar Icon and Title, you must do two things:
 setDisplayShowHomeEnabled(false);  // hides action bar icon
 setDisplayShowTitleEnabled(false); // hides action bar title
 */

public void HideActionBar() {
 ActionBar actionBar = this.controls.activity.getActionBar();
 actionBar.hide();
}

public void ShowActionBar() {
	ActionBar actionBar = this.controls.activity.getActionBar();
	actionBar.show();
}

//Hide the title label
public void ShowTitleActionBar(boolean _value) {
	ActionBar actionBar = this.controls.activity.getActionBar();
    actionBar.setDisplayShowTitleEnabled(_value);
}

//Hide the logo = false
public void ShowLogoActionBar(boolean _value) {
   ActionBar actionBar = this.controls.activity.getActionBar();
   actionBar.setDisplayShowHomeEnabled(_value);
}

//set a title and subtitle to the Action bar as shown in the code snippet.
public void SetTitleActionBar(String _title) {
	ActionBar actionBar = this.controls.activity.getActionBar();
    actionBar.setTitle(_title);
}

//set a title and subtitle to the Action bar as shown in the code snippet.
public void SetSubTitleActionBar(String _subtitle) {
   ActionBar actionBar = this.controls.activity.getActionBar();
   actionBar.setSubtitle(_subtitle);
   //actionBar.setDisplayHomeAsUpEnabled(true);
}

//forward [<] activity! // If your minSdkVersion is 11 or higher!
/*.*/public void SetDisplayHomeAsUpEnabledActionBar(boolean _value) {
   ActionBar actionBar = this.controls.activity.getActionBar();
   actionBar.setDisplayHomeAsUpEnabled(_value);
}

public void SetIconActionBar(String _iconIdentifier) {
	ActionBar actionBar = this.controls.activity.getActionBar();
    actionBar.setIcon(GetDrawableResourceById(GetDrawableResourceId(_iconIdentifier)));
}

public void SetTabNavigationModeActionBar(){
	ActionBar actionBar = this.controls.activity.getActionBar();
	actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);	//API 11
	actionBar.setSelectedNavigationItem(0);
}

//This method remove all tabs from the action bar and deselect the current tab
public void RemoveAllTabsActionBar() {
	ActionBar actionBar = this.controls.activity.getActionBar();
	actionBar.removeAllTabs();
        this.controls.activity.invalidateOptionsMenu(); // by renabor
	actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); //API 11 renabor
}

//Calculate ActionBar height
//ref http://stackoverflow.com/questions/12301510/how-to-get-the-actionbar-height
public int GetActionBarHeight() {
int actionBarHeight = 0;
TypedValue tv = new TypedValue();
if (controls.activity.getActionBar().isShowing()) {
   if (controls.activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
      actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,controls.activity.getResources().getDisplayMetrics());
   }
}
return actionBarHeight;
}

public boolean ActionBarIsShowing() {
  return controls.activity.getActionBar().isShowing();
}

public boolean IsPackageInstalled(String _packagename) {
    PackageManager pm = controls.activity.getPackageManager();
    try {
        pm.getPackageInfo(_packagename, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}
   //android.view.View
public void ShowCustomMessage(View _layout,  int _gravity) {
    //controls.pOnShowCustomMessage(PasObj);
    Toast toast = new Toast(controls.activity);
    toast.setGravity(_gravity, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    RelativeLayout par = (RelativeLayout)_layout.getParent();
	if (par != null) {
	    par.removeView(_layout);
	}
    _layout.setVisibility(0);
    toast.setView(_layout);
    toast.show();
}

private class MyCountDownTimer extends CountDownTimer {
	  Toast toast;
	  public MyCountDownTimer(long startTime, long interval, Toast toas) {
	     super(startTime, interval);
	     toast = toas;
	  }
	  @Override
	  public void onFinish() {
	   //text.setText("Time's up!");
		  toast.cancel();
	  }
	  @Override
	  public void onTick(long millisUntilFinished) {
	   //text.setText("" + millisUntilFinished / 1000);
		  toast.show();
	  }
}

public void ShowCustomMessage(View _layout,  int _gravity,  int _lenghTimeSecond) {
    Toast toast = new Toast(controls.activity);
    toast.setGravity(_gravity, 0, 0);
    //toast.setDuration(Toast.LENGTH_LONG);
    RelativeLayout par = (RelativeLayout)_layout.getParent();
	if (par != null) {
	    par.removeView(_layout);
	}
    _layout.setVisibility(0);
    toast.setView(_layout);
    //it will show the toast for 20 seconds:
    //(20000 milliseconds/1st argument) with interval of 1 second/2nd argument //--> (20 000, 1000)
    MyCountDownTimer countDownTimer = new MyCountDownTimer(_lenghTimeSecond*1000, 1000, toast);
    countDownTimer.start();
}

public void SetScreenOrientation(int _orientation) {
	//Log.i("Screen","Orientation "+ _orientation);
    switch(_orientation) {
      case 1: controls.activity.setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break;
      case 2: controls.activity.setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break;
      default:controls.activity.setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_SENSOR); break;
    }
}

public int GetScreenOrientation() {
	    int orientation = controls.activity.getResources().getConfiguration().orientation;
	    int r = 0;
        switch(orientation) {
           case Configuration.ORIENTATION_PORTRAIT:
               r= 1;//setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
               break;
           case Configuration.ORIENTATION_LANDSCAPE:
               r = 2; //setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
               break;
       }
       return r;
}

public String GetScreenDensity() {
    String r= "";
    DisplayMetrics metrics = new DisplayMetrics();

    controls.activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int density = metrics.densityDpi;

    if (density==DisplayMetrics.DENSITY_XXHIGH) {
        r= "XXHIGH:" + String.valueOf(density);
    }
    else if (density==DisplayMetrics.DENSITY_XHIGH) {
        r= "XHIGH:" + String.valueOf(density);
    }
    else if (density==DisplayMetrics.DENSITY_HIGH) {
        r= "HIGH:" + String.valueOf(density);
    }
    else if (density==DisplayMetrics.DENSITY_MEDIUM) {
        r= "MEDIUM:" + String.valueOf(density);
    }
    else if (density==DisplayMetrics.DENSITY_LOW) {
        r= "LOW:" + String.valueOf(density);
    }
    return r;
}

public String GetScreenSize() {
	String r= "";

	if((controls.activity.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
        r = "XLARGE";
    }else if((controls.activity.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
        r = "LARGE";
    }else if ((controls.activity.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
        r = "NORMAL";
    }else if ((controls.activity.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
    	r = "SMALL";
    }
	return r;
}

public void LogDebug(String _tag, String  _msg) {
   Log.d(_tag, _msg);  //debug
}

public void Vibrate(int _milliseconds) {
	Vibrator vib = (Vibrator) controls.activity.getSystemService(Context.VIBRATOR_SERVICE);
    if (vib.hasVibrator()) {
    	vib.vibrate(_milliseconds);
    }
}

public void Vibrate(long[] _millisecondsPattern) {
	Vibrator vib = (Vibrator) controls.activity.getSystemService(Context.VIBRATOR_SERVICE);
    if (vib.hasVibrator()) {
    	vib.vibrate(_millisecondsPattern, -1);
    }
}
//http://stackoverflow.com/questions/2661536/how-to-programatically-take-a-screenshot-on-android
public void TakeScreenshot(String _savePath, String _saveFileNameJPG) {

	String myPath = _savePath + "/" +  _saveFileNameJPG;
	Bitmap bitmap;
	View v1 = controls.activity.getWindow().getDecorView().getRootView();
	v1.setDrawingCacheEnabled(true);
	bitmap = Bitmap.createBitmap(v1.getDrawingCache());
	v1.setDrawingCacheEnabled(false);

	OutputStream fout = null;
	File imageFile = new File(myPath);

	try {
	    fout = new FileOutputStream(imageFile);
	    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
	    fout.flush();
	    fout.close();

	} catch (FileNotFoundException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	} catch (IOException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
}

public String GetTitleActionBar() {
	ActionBar actionBar = this.controls.activity.getActionBar();
    return (String)actionBar.getTitle();
}

public String GetSubTitleActionBar() {
	   ActionBar actionBar = this.controls.activity.getActionBar();
	   return (String)actionBar.getSubtitle();
}

//https://xjaphx.wordpress.com/2011/10/02/store-and-use-files-in-assets/
public void CopyFromAssetsToInternalAppStorage(String _filename){
		InputStream is = null;
		FileOutputStream fos = null;
		String PathDat = controls.activity.getFilesDir().getAbsolutePath();
		try {
			File outfile = new File(PathDat+"/"+_filename);
			// if file doesnt exists, then create it
			if (!outfile.exists()) {
				outfile.createNewFile();
			}
			fos = new FileOutputStream(outfile);  //save to data/data/your_package/files/your_file_name
			is = controls.activity.getAssets().open(_filename);
			int size = is.available();
			byte[] buffer = new byte[size];
			for (int c = is.read(buffer); c != -1; c = is.read(buffer)){
		      fos.write(buffer, 0, c);
			}
			is.close();
			fos.close();
		}catch (IOException e) {
			// Log.i("ShareFromAssets","fail!!");
		     e.printStackTrace();
		}
}

public void CopyFromInternalAppStorageToEnvironmentDir(String _filename, String _environmentDir) {
    String srcPath = controls.activity.getFilesDir().getAbsolutePath()+"/"+ _filename;       //Result : /data/data/com/MyApp/files
    String destPath = _environmentDir + "/" + _filename;
    CopyFile(srcPath, destPath);
}

public void CopyFromAssetsToEnvironmentDir(String _filename, String _environmentDir) {
	CopyFromAssetsToInternalAppStorage(_filename);
	CopyFromInternalAppStorageToEnvironmentDir(_filename,_environmentDir);
}

public void ToggleSoftInput() {
	  InputMethodManager imm =(InputMethodManager) controls.activity.getSystemService(Context.INPUT_METHOD_SERVICE);
	  imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}

//thanks to Mladen
public String GetDeviceModel() {
  return android.os.Build.MODEL;
}

public String GetDeviceManufacturer() {
  return android.os.Build.MANUFACTURER;
}

public void SetKeepScreenOn(boolean _value) {
  if (_value)
	   controls.activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  else
	  controls.activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

public void SetTurnScreenOn(boolean _value) {
	if (_value)
	   controls.activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
	else
		controls.activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}

public void SetAllowLockWhileScreenOn(boolean _value) {
	if (_value)
	   controls.activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
	else
	   controls.activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
}

public void SetShowWhenLocked(boolean _value) {
	if (_value)
	    controls.activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
	else
		controls.activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}

public Uri ParseUri(String _uriAsString) {
  return Uri.parse(_uriAsString);
}

public String UriToString(Uri _uri) {
  return _uri.toString();
}

}

//**class entrypoint**//please, do not remove/change this line!

//Main Java/Pascal Interface Class
public class Controls {
//
public Activity        activity;  // Activity
public RelativeLayout  appLayout; // Base Layout
public int screenStyle=0;         // Screen Style [Dev:0 , Portrait: 1, Landscape : 2]
public int systemVersion;

//Jave -> Pascal Function ( Pascal Side = Event )
public native void pAppOnCreate(Context context, RelativeLayout layout);
public native int  pAppOnScreenStyle();
public native void pAppOnNewIntent();
public native void pAppOnDestroy();
public native void pAppOnPause();
public native void pAppOnRestart();
public native void pAppOnResume();
public native void pAppOnStart();
public native void pAppOnStop();
public native void pAppOnBackPressed();
public native int pAppOnRotate(int rotate);
public native void pAppOnConfigurationChanged();
public native void pAppOnActivityResult(int requestCode, int resultCode, Intent data);
public native void pAppOnCreateOptionsMenu(Menu menu);
public native void pAppOnClickOptionMenuItem(MenuItem menuItem, int itemID, String itemCaption, boolean checked);
public native boolean pAppOnPrepareOptionsMenu(Menu menu, int menuSize);
public native boolean pAppOnPrepareOptionsMenuItem(Menu menu, MenuItem menuItem, int itemIndex);
public native void pAppOnCreateContextMenu(ContextMenu menu);
public native void pAppOnClickContextMenuItem(MenuItem menuItem, int itemID, String itemCaption, boolean checked);
public native void pOnDraw(long pasobj, Canvas canvas);
public native void pOnTouch(long pasobj, int act, int cnt, float x1, float y1, float x2, float y2);
public native void pOnClickGeneric(long pasobj, int value);
public native boolean pAppOnSpecialKeyDown(char keyChar, int keyCode, String keyCodeString);
public native void pOnClick(long pasobj, int value);
public native void pOnChange(long pasobj, String txt, int count);
public native void pOnChanged(long pasobj, String txt, int count);
public native void pOnEnter(long pasobj);
public native void pOnClose(long pasobj);
public native void pAppOnViewClick(View view, int id);
public native void pAppOnListItemClick(AdapterView adapter, View view, int position, int id);
public native void pOnFlingGestureDetected(long pasobj, int direction);
public native void pOnPinchZoomGestureDetected(long pasobj, float scaleFactor, int state);

//Load Pascal Library
static {
	/*
    try {
    	System.loadLibrary("freetype"); // need by TFPNoGUIGraphicsBridge [ref. www.github.com/jmpessoa/tfpnoguigraphicsbridge]
    } catch (UnsatisfiedLinkError e) {
         Log.e("JNI_Load_LibFreetype", "exception", e);
    }
    */
    try {
    	System.loadLibrary("controls");
    } catch (UnsatisfiedLinkError e) {
         Log.e("JNI_Load_LibControls", "exception", e);
    }
}

// -------------------------------------------------------------------------
//  Activity Event
// -------------------------------------------------------------------------
public  int  jAppOnScreenStyle()          { return(pAppOnScreenStyle());   }
//
public  void jAppOnCreate(Context context,RelativeLayout layout )
                                          { pAppOnCreate(context,layout);  }

public  void jAppOnNewIntent()            { pAppOnNewIntent();             }
public  void jAppOnDestroy()              { pAppOnDestroy();               }
public  void jAppOnPause()                { pAppOnPause();                 }
public  void jAppOnRestart()              { pAppOnRestart();               }
public  void jAppOnResume()               { pAppOnResume();                }
public  void jAppOnStart()                { pAppOnStart();                 }     //change by jmpessoa : old OnActive
public  void jAppOnStop()                 { pAppOnStop();                  }
public  void jAppOnBackPressed()          { pAppOnBackPressed();           }
public  int  jAppOnRotate(int rotate)     {  return(pAppOnRotate(rotate)); }

//rotate=1 --> device on vertical/default position ; 2 --> device on horizontal position      //tips by jmpessoa
public  void jAppOnConfigurationChanged() { pAppOnConfigurationChanged();  }

public  void jAppOnActivityResult(int requestCode, int resultCode, Intent data)
                                          { pAppOnActivityResult(requestCode,resultCode,data); }

public  void jAppOnCreateOptionsMenu(Menu m) {pAppOnCreateOptionsMenu(m);}
public  void jAppOnClickOptionMenuItem(MenuItem item,int itemID, String itemCaption, boolean checked){pAppOnClickOptionMenuItem(item,itemID,itemCaption,checked);}

public boolean jAppOnPrepareOptionsMenu(Menu m, int size) {
	boolean r = pAppOnPrepareOptionsMenu(m, size);
	return r;
}

public boolean jAppOnPrepareOptionsItem(Menu m, MenuItem item, int index) {
	boolean r = pAppOnPrepareOptionsMenuItem(m, item, index);
	return r;
}

public  void jAppOnCreateContextMenu(ContextMenu m) {pAppOnCreateContextMenu(m);}
public  void jAppOnClickContextMenuItem(MenuItem item,int itemID, String itemCaption, boolean checked) {pAppOnClickContextMenuItem(item,itemID,itemCaption,checked);}
public void jAppOnViewClick(View view, int id){ pAppOnViewClick(view,id);}
public void jAppOnListItemClick(AdapterView adapter, View view, int position, int id){ pAppOnListItemClick(adapter, view,position,id);}
//public  void jAppOnHomePressed()          { pAppOnHomePressed();           }
public boolean jAppOnKeyDown(char keyChar , int keyCode, String keyCodeString) {return pAppOnSpecialKeyDown(keyChar, keyCode, keyCodeString);};

//// -------------------------------------------------------------------------
//  System, Class
// -------------------------------------------------------------------------
public  void systemGC() {
   System.gc();
}

public  void systemSetOrientation(int orientation) {
   this.activity.setRequestedOrientation(orientation);
}

//by jmpessoa
public  int  systemGetOrientation() {
   return (this.activity.getResources().getConfiguration().orientation);
}

public  void classSetNull (Class object) {
   object = null;
}
public  void classChkNull (Class object) {
   if (object == null) { Log.i("JAVA","checkNull-Null"); };
   if (object != null) { Log.i("JAVA","checkNull-Not Null"); };
}

public Context GetContext() {
   return this.activity;
}

//by  thierrydijoux
public String getQuantityStringByName(String _resName, int _quantity) {
	int id = this.activity.getResources().getIdentifier(_resName, "plurals", this.activity.getPackageName());
    String value = id == 0 ? "" : (String) this.activity.getResources().getQuantityString(id, _quantity, _quantity);
	return value;
}

//by thierrydijoux
public String getStringResourceByName(String _resName) {
	int id = this.activity.getResources().getIdentifier(_resName, "string", this.activity.getPackageName());
    String value = id == 0 ? "" : (String) this.activity.getResources().getText(id);
	return value;
}
// -------------------------------------------------------------------------
//  App Related
// -------------------------------------------------------------------------
//
public  void appFinish () {
	   activity.finish();
	   System.exit(0); //<< ------- fix by jmpessoa
}

public  void appKillProcess() {
   this.activity.finish();
}
// -------------------------------------------------------------------------
//  Asset Related
// -------------------------------------------------------------------------
// src : codedata.txt
// tgt : /data/data/com.kredix.control/data/codedata.txt
public  boolean assetSaveToFile(String src, String tgt) {
  InputStream is = null;
  FileOutputStream fos = null;
  String path = '/' + tgt.substring(1,tgt.lastIndexOf("/"));
  File outDir = new File(path);
  outDir.mkdirs();
  try {
    is = this.activity.getAssets().open(src);
    int size = is.available();
    byte[] buffer = new byte[size];
    File outfile = new File(tgt);
    fos = new FileOutputStream(outfile);
    for (int c = is.read(buffer); c != -1; c = is.read(buffer)){
      fos.write(buffer, 0, c);
    }
    is.close();
    fos.close();
    return(true); }
  catch (IOException e) {
    e.printStackTrace();
    return(false);       }
}

// -------------------------------------------------------------------------
//  View Related - Generic! --> AndroidWidget.pas
// -------------------------------------------------------------------------

public  void view_SetVisible(View view, int state) {
  view.setVisibility(state);
}

public  void view_SetBackGroundColor(View view, int color) {
  view.setBackgroundColor(color);
}

public  void view_Invalidate(View view) {
  view.invalidate();
}

// -------------------------------------------------------------------------
//  Form Related
// -------------------------------------------------------------------------
//
public  java.lang.Object jForm_Create(long pasobj ) {
  return (java.lang.Object)( new jForm(this,pasobj));
}

// -------------------------------------------------------------------------
//  System Info
// -------------------------------------------------------------------------
// Result : Width(16bit) : Height (16bit)
public  int  getScreenWH(android.content.Context context) {
  DisplayMetrics metrics = new DisplayMetrics();

  int h = context.getResources().getDisplayMetrics().heightPixels;
  int w = context.getResources().getDisplayMetrics().widthPixels;
// proposed by renabor
/*
 float density  = context.getResources().getDisplayMetrics().density;
 int dpHeight = Math.round ( h / density );
 int dpWidth  = Math.round ( w / density );
 return ( dpWidth << 16 | dpHeight ); // dp screen size
*/
  return ( (w << 16)| h );
}

// LORDMAN - 2013-07-28
public  int getStrLength(String Txt) {  //fix by jmpessoa
  int len = 0;
  if(Txt != null) {
     len = Txt.length();
  }
  return ( len );
}

/*LORDMAN - 2013-07-30
public  String getStrDateTime() {
  SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss", Locale.KOREA );
  return( formatter.format ( new Date () ) );
}
*/
//----------------------------------------------
//Controls Version Info
//-------------------------------------------
//GetControlsVersionFeatures ...  //Controls.java version-revision info! [0.6-04]
public  String getStrDateTime() {  //hacked by jmpessoa!! sorry, was for a good cause! please, use the  jForm_GetDateTime!!
  String listVersionInfo =
		  "7$0=GetControlsVersionInfo;" +  //added ... etc..
  		  "7$0=getLocale;"; //added ... etc..
  return listVersionInfo;
}

//Fatih: Path = '' = Asset Root Folder
//Path Example: gunlukler/2015/02/28/001
public String[] getAssetContentList(String Path) throws IOException {
	ArrayList<String> Folders = new ArrayList<String>();

	Resources r = this.activity.getResources();
	AssetManager am = r.getAssets();
	String fileList[] = am.list(Path);
	if (fileList != null)
	{
		for (int i = 0; i < fileList.length; i++)
		{
			Folders.add(fileList[i]);
		}
	}
	String sFolders[] = Folders.toArray(new String[Folders.size()]);
	return sFolders;
}

//Fatih: gets system storage driver list
public String[] getDriverList() {
	ArrayList<String> Drivers = new ArrayList<String>();

	String sDriver;
	sDriver = System.getenv("EXTERNAL_STORAGE");
	if(sDriver != null)
	{
		File fDriver = new File(sDriver);

		if (fDriver.exists() && fDriver.canWrite()) {
			Drivers.add(fDriver.getAbsolutePath());
		}
	}

	sDriver = System.getenv("SECONDARY_STORAGE");
	if(sDriver != null)
	{
		File fDriver = new File(sDriver);

		if (fDriver.exists() && fDriver.canWrite()) {
			Drivers.add(fDriver.getAbsolutePath());
		}
	}

	String sDrivers[] = Drivers.toArray(new String[Drivers.size()]);
	return sDrivers;
}

//Fatih: get folders list
//Path Example: /storage/emulated/legacy/
public String[] getFolderList(String Path) {
	ArrayList<String> Folders = new ArrayList<String>();

	File f = new File(Path);
	File[] files = f.listFiles();
	for (File fFile : files) {
	    if (fFile.isDirectory()) {
			Folders.add(fFile.getName());
	    }
	}
	String sFolders[] = Folders.toArray(new String[Folders.size()]);
	return sFolders;
}

//Fatih: get files list
//Path Example: /storage/emulated/legacy/
public String[] getFileList(String Path) {
	ArrayList<String> Folders = new ArrayList<String>();

	File f = new File(Path);
	File[] files = f.listFiles();
	for (File fFile : files) {
	    if (fFile.isFile()) {
			Folders.add(fFile.getName());
	    }
	}
	String sFolders[] = Folders.toArray(new String[Folders.size()]);
	return sFolders;
}
//by jmpessoa:  Class controls version info
public String GetControlsVersionInfo() {
  return "7$0";  //version$revision  [0.6$5]
}
public long getTick() {
  return ( System.currentTimeMillis() );
}
// -------------------------------------------------------------------------
//  Android path
// -------------------------------------------------------------------------
// Result : /data/app/com.kredix-1.apk
public  String getPathApp (android.content.Context context,String pkgName) {
  String PathApp = "";
  try {
   PathApp = context.getPackageManager().getApplicationInfo( pkgName, 0 ).sourceDir;
  }
  catch ( NameNotFoundException e ) {}
  return ( PathApp );
}

// Result : /data/data/com/kredix/files
public  String getPathDat (android.content.Context context) {
  //String version = Build.VERSION.RELEASE;
  String PathDat = context.getFilesDir().getAbsolutePath();
  return ( PathDat );
}

// Result : /storage/emulated/0
public  String getPathExt() {
  File FileExt = Environment.getExternalStorageDirectory();
  return ( FileExt.getPath() );
}

// Result : /storage/emulated/0/DCIM
public  String getPathDCIM() {
  File FileDCIM =  Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
  return ( FileDCIM.getPath() );
}

//by jmpessoa
public  String getPathDataBase(android.content.Context context) {
   String destPath = context.getFilesDir().getAbsolutePath();
   destPath = destPath.substring(0, destPath.lastIndexOf("/")) + "/databases";
   return destPath;
}

// -------------------------------------------------------------------------
//  Android Locale
// -------------------------------------------------------------------------
// thierrydijoux - get locale info
public String getLocale(int localeType) {
        Context context = this.activity;
  	String value = "";
   	switch (localeType) {
   		case 0: value = context.getResources().getConfiguration().locale.getCountry();
				break;
		case 1: value = context.getResources().getConfiguration().locale.getDisplayCountry();
				break;
   		case 2: value = context.getResources().getConfiguration().locale.getDisplayLanguage();
				break;
   		case 3: value = context.getResources().getConfiguration().locale.getDisplayName();
				break;
   		case 4: value = context.getResources().getConfiguration().locale.getDisplayVariant();
				break;
   		case 5: value = context.getResources().getConfiguration().locale.getISO3Country();
				break;
   		case 6: value = context.getResources().getConfiguration().locale.getISO3Language();
				break;
   		case 7: value = context.getResources().getConfiguration().locale.getVariant();
				break;
   	}

   	return value;
}
// -------------------------------------------------------------------------
//  Android Device
// -------------------------------------------------------------------------
// Result: Phone Number - LORDMAN
public  String getDevPhoneNumber() {
  TelephonyManager telephony = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
  return ( telephony.getLine1Number() );
}

// Result: Device ID - LORDMAN
// Remarks : Nexus7 (no moblie device) -> Crash : fixed code - Simon
public  String getDevDeviceID() {
  TelephonyManager telephony = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
  return ( telephony.getDeviceId()    );
}
// -------------------------------------------------------------------------
//  Bitmap
// -------------------------------------------------------------------------
// Get Image Width,Height without Decoding
public  int Image_getWH (String filename ) {
  BitmapFactory.Options options = new BitmapFactory.Options();
  options.inJustDecodeBounds = true;
  BitmapFactory.decodeFile(filename, options);
  return ( (options.outWidth << 16) | (options.outHeight) );
}

//
public  Bitmap Image_resample(String infile,int size) {
  int iw,ih,im; // input image w,h, max
  int scale;    //
  int ow,oh;    // output image w,h

  // get input image w,h
  BitmapFactory.Options options = new BitmapFactory.Options();
  options.inJustDecodeBounds = true;
  BitmapFactory.decodeFile(infile, options);
  iw = options.outWidth;
  ih = options.outHeight;
  //
  im = Math.max(iw,ih);
  scale = 1;
  if                      (size <= (im/32))  { scale = 32; }
  if (((im/32) < size) && (size <= (im/16))) { scale = 16; }
  if (((im/16) < size) && (size <= (im/ 8))) { scale =  8; }
  if (((im/ 8) < size) && (size <= (im/ 4))) { scale =  4; }
  if (((im/ 4) < size) && (size <= (im/ 2))) { scale =  2; }
  //
  options.inJustDecodeBounds = false;
  options.inSampleSize       = scale;
  Bitmap src = BitmapFactory.decodeFile(infile, options);
  //
  if  (im == iw) { ow = size;
                   oh = Math.round((float)ow*((float)ih/(float)iw)); }
            else { oh = size;
                   ow = Math.round((float)oh*((float)iw/(float)ih)); }
  //
  return( Bitmap.createScaledBitmap(src, ow,oh, true) );
}

public  void Image_save(Bitmap bmp, String filename) {
  try { FileOutputStream out = new FileOutputStream(filename);
        bmp.compress(Bitmap.CompressFormat.PNG, 100, out); }
  catch (Exception e)
      { e.printStackTrace(); }
}

// -------------------------------------------------------------------------
//  Toast
// -------------------------------------------------------------------------
//
public  void jToast( String str ) {
   Toast.makeText(activity, str, Toast.LENGTH_SHORT).show();
}

//by jmpessoa
//you need a real android device (not emulator!)
//http://www.androidaspect.com/2013/09/how-to-send-email-from-android.html
public void jSend_Email(
                     String to,
                     String cc,
                     String bcc,
                     String subject,
                     String message)
{
    try {
	Intent email = new Intent(Intent.ACTION_SEND);
    email.putExtra(Intent.EXTRA_EMAIL, to);
    email.putExtra(Intent.EXTRA_CC, cc);
    email.putExtra(Intent.EXTRA_BCC, bcc);
    email.putExtra(Intent.EXTRA_SUBJECT, subject);
    email.putExtra(Intent.EXTRA_TEXT, message);
    // Use email client only
    email.setType("message/rfc822");
    this.activity.startActivity(Intent.createChooser(email, "Choose an email client"));
    //rst = 1; //ok
  }catch (Exception e) {
		//Log.i("Java","Send Email Error");
    e.printStackTrace();
  }
}

//http://codetheory.in/android-sms/
//http://www.developerfeed.com/java/tutorial/sending-sms-using-android
//http://www.techrepublic.com/blog/software-engineer/how-to-send-a-text-message-from-within-your-android-app/
public int jSend_SMS(String phoneNumber, String msg) {
	SmsManager sms = SmsManager.getDefault();
	try {
	      //SmsManager.getDefault().sendTextMessage(phoneNumber, null, msg, null, null);
	      List<String> messages = sms.divideMessage(msg);
	      for (String message : messages) {
	          sms.sendTextMessage(phoneNumber, null, message, null, null);
	      }
	      //Log.i("Send_SMS",phoneNumber+": "+ msg);
	      return 1; //ok
	  }catch (Exception e) {
		  //Log.i("Send_SMS Fail",e.toString());
	      return 0; //fail
	  }
}

public int jSend_SMS(String phoneNumber, String msg, String packageDeliveredAction) {
	String SMS_DELIVERED = packageDeliveredAction;
	PendingIntent deliveredPendingIntent = PendingIntent.getBroadcast(this.GetContext(), 0, new Intent(SMS_DELIVERED), 0);
	SmsManager sms = SmsManager.getDefault();
	try {
	      //SmsManager.getDefault().sendTextMessage(phoneNumber, null, msg, null, deliveredPendingIntent);
	      //Log.i("Send_SMS",phoneNumber+": "+ msg);
	      List<String> messages = sms.divideMessage(msg);
	      for (String message : messages) {
	          sms.sendTextMessage(phoneNumber, null, message, null, deliveredPendingIntent);
	      }
	      return 1; //ok
	}catch (Exception e) {
	      return 0; //fail
	}
}

public String jRead_SMS(Intent intent, String addressBodyDelimiter)  {
  //---get the SMS message passed in---
  SmsMessage[] msgs = null;
  String str = "";
  if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
    Bundle bundle = intent.getExtras();
    if (bundle != null)
    {
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
            str += msgs[i].getOriginatingAddress();
            str += addressBodyDelimiter;
            str += msgs[i].getMessageBody().toString();
            str += " ";
        }
    }
  }
  return str;
}

//by jmpessoa
//http://eagle.phys.utk.edu/guidry/android/readContacts.html
@SuppressLint("DefaultLocale")
public String jContact_getMobileNumberByDisplayName(String contactName){

	   String matchNumber = "";
	   String username;

	   username = contactName;

	   username = username.toLowerCase();

	   Cursor phones = this.activity.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);

	   while (phones.moveToNext())
	   {
	     String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
	     String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
	     String phoneType = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));

	     name = name.toLowerCase();

	     if(name.equals(username)) {
	    	 if ( phoneType.equals("2")) { //mobile
	    	    matchNumber = phoneNumber;
	    	    break;
	    	 }
	     }
	   }
	   phones.close();
	   return matchNumber;
}

//by jmpessoa
//http://eagle.phys.utk.edu/guidry/android/readContacts.html
public String jContact_getDisplayNameList(char delimiter){
	   String nameList = "";
	   Cursor phones = this.activity.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
	   while (phones.moveToNext())
	   {
	     String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
	     String phoneType = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
	     if ( phoneType.equals("2")) { //mobile
	    	 nameList = nameList + delimiter  + name;
	     }
	   }
	   phones.close();
	   return nameList;
}
// -------------------------------------------------------------------------
//  Bitmap
// -------------------------------------------------------------------------
public  int[] getBmpArray(String file) {
  Bitmap bmp = BitmapFactory.decodeFile(file);
  int   length = bmp.getWidth()*bmp.getHeight();
  int[] pixels = new int[length+2];
  bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
  pixels[length+0] = bmp.getWidth ();
  pixels[length+1] = bmp.getHeight();
  return ( pixels );
}
// -------------------------------------------------------------------------
//  Camera
// -------------------------------------------------------------------------
  public void takePhoto(String filename) {  //HINT: filename = App.Path.DCIM + '/test.jpg
	  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
	  Uri mImageCaptureUri = Uri.fromFile(new File("", filename));
	  intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
	  intent.putExtra("return-data", true);
	  activity.startActivityForResult(intent, 12345);
  }
  /*
   * NOTE: The DCIM folder on the microSD card in your Android device is where Android stores the photos and videos
   * you take with the device's built-in camera. When you open the Android Gallery app,
   * you are browsing the files saved in the DCIM folder....
   */
  //by jmpessoa
public String jCamera_takePhoto(String path, String filename) {
 	  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
	  Uri mImageCaptureUri = Uri.fromFile(new File(path, '/'+filename)); // get Android.Uri from file
	  intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
	  intent.putExtra("return-data", true);
	  this.activity.startActivityForResult(intent, 12345); //12345 = requestCode
	  return (path+'/'+filename);
}

public String jCamera_takePhoto(String path, String filename, int requestCode) {
	  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
	  Uri mImageCaptureUri = Uri.fromFile(new File(path, '/'+filename)); // get Android.Uri from file
	  intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
	  intent.putExtra("return-data", true);
	  this.activity.startActivityForResult(intent, requestCode); //12345 = requestCode
	  return (path+'/'+filename);
}

//-------------------------------------------------------------------------------------------------------
//SMART LAMW DESIGNER
//-------------------------------------------------------------------------------------------------------

public  java.lang.Object jTextView_Create(long pasobj) {
  return (java.lang.Object)( new jTextView(this.activity,this,pasobj));
}

public java.lang.Object jAutoTextView_jCreate(long _Self) {
   return (java.lang.Object)(new jAutoTextView(this,_Self));
}
public native void pOnClickAutoDropDownItem(long pasobj, int itemIndex, String itemCaption);

}

{'repo_name': 'jmpessoa/lazandroidmodulewizard', 'stars': '137', 'repo_language': 'Pascal', 'file_name': 'fcl_bridges_pack.pas', 'mime_type': 'text/plain', 'hash': 3290629444876786524, 'source_dataset': 'data'}


package de.metas.data.export.api.impl;

/*
 * #%L
 * de.metas.swat.base
 * %%
 * Copyright (C) 2015 metas GmbH
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-2.0.html>.
 * #L%
 */

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.List;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.model.InterfaceWrapperHelper;
import org.compiere.model.I_AD_PInstance;
import org.compiere.util.Env;
import org.slf4j.Logger;

import de.metas.adempiere.form.IClientUIInstance;
import de.metas.data.export.api.IExporter;
import de.metas.data.export.api.IExporterMonitor;
import de.metas.logging.LogManager;
import de.metas.process.AdProcessId;
import de.metas.process.IADPInstanceDAO;
import de.metas.process.PInstanceId;
import de.metas.process.ProcessInfoParameter;
import de.metas.util.Services;
import lombok.NonNull;

/**
 * Helper monitor which logs the given parameters by using adProcessId when export started. When export finished, it logs the status.
 *
 * NOTE: this monitor is used when we don't have an actual ADempiere process but we would like to have the audit informations.
 *
 * @author tsa
 *
 */
public class ProcessLoggerExporterMonitor implements IExporterMonitor
{
	private static final Logger logger = LogManager.getLogger(ProcessLoggerExporterMonitor.class);

	private final AdProcessId adProcessId;
	private final Object params;
	private final Class<?> paramsInterfaceClass;

	private I_AD_PInstance pinstance;

	private IClientUIInstance clientUIInstance;

	/**
	 *
	 * @param ctx
	 * @param adProcessId which process shall be used when creating the {@link I_AD_PInstance} record
	 * @param params object which contains the export parameters
	 * @param paramsInterfaceClass interface class to be used when we are introspecting the export parameters
	 */
	public <T> ProcessLoggerExporterMonitor(
			@NonNull final AdProcessId adProcessId,
			@NonNull final T params,
			@NonNull final Class<T> paramsInterfaceClass)
	{
		this.adProcessId = adProcessId;
		this.params = params;
		this.paramsInterfaceClass = paramsInterfaceClass;
	}

	@Override
	public void exportStarted(IExporter exporter)
	{
		pinstance = createPInstance();
	}

	@Override
	public void exportFinished(IExporter exporter)
	{
		final Throwable error = exporter.getError();
		if (error != null)
		{
			// Log the error to console. This is useful if the exporter is running asynchronous and the threads executor service is not logging the exception
			logger.error(error.getLocalizedMessage(), error);

			if (clientUIInstance != null)
			{
				clientUIInstance.error(Env.WINDOW_MAIN, "Error", error.getLocalizedMessage());
			}
		}

		if (pinstance != null)
		{
			pinstance.setResult(exporter.getExportedRowCount());
			pinstance.setIsProcessing(false);
			if (error != null)
			{
				pinstance.setErrorMsg(error.getLocalizedMessage());
			}
			InterfaceWrapperHelper.save(pinstance);
		}
	}

	private I_AD_PInstance createPInstance()
	{
		final I_AD_PInstance pinstance = Services.get(IADPInstanceDAO.class).createAD_PInstance(adProcessId);
		pinstance.setIsProcessing(true);
		InterfaceWrapperHelper.save(pinstance);

		final BeanInfo beanInfo;
		try
		{
			beanInfo = Introspector.getBeanInfo(paramsInterfaceClass);
		}
		catch (IntrospectionException e)
		{
			throw new AdempiereException(e.getLocalizedMessage(), e);
		}

		final List<ProcessInfoParameter> piParams = new ArrayList<>();
		for (final PropertyDescriptor pd : beanInfo.getPropertyDescriptors())
		{
			final Object value;
			try
			{
				value = pd.getReadMethod().invoke(params);
			}
			catch (Exception e)
			{
				logger.info(e.getLocalizedMessage(), e);
				continue;
			}

			if (value == null)
			{
				continue;
			}

			piParams.add(ProcessInfoParameter.ofValueObject(pd.getName(), value));
		}

		Services.get(IADPInstanceDAO.class).saveParameterToDB(PInstanceId.ofRepoId(pinstance.getAD_PInstance_ID()), piParams);

		return pinstance;
	}

	public void setClientUIInstance(IClientUIInstance clientUIInstance)
	{
		this.clientUIInstance = clientUIInstance;
	}
}

{'repo_name': 'metasfresh/metasfresh', 'stars': '653', 'repo_language': 'TSQL', 'file_name': 'I_C_NonBusinessDay.java', 'mime_type': 'text/plain', 'hash': -3644880828460821705, 'source_dataset': 'data'}


set(WRAPPER_AUTO_INCLUDE_HEADERS OFF)
itk_wrap_include("itkMergeLabelMapFilter.h")

itk_wrap_simple_class("itk::MergeLabelMapFilterEnums")

itk_wrap_class("itk::MergeLabelMapFilter" POINTER)
  foreach(d ${ITK_WRAP_IMAGE_DIMS})
    itk_wrap_template("${ITKM_LM${d}}" "${ITKT_LM${d}}")
  endforeach()
itk_end_wrap_class()

{'repo_name': 'InsightSoftwareConsortium/ITK', 'stars': '698', 'repo_language': 'C++', 'file_name': 'config.yml', 'mime_type': 'text/plain', 'hash': -5164579741721044967, 'source_dataset': 'data'}


<?php
/**
 * Table Definition for resource
 *
 * PHP version 7
 *
 * Copyright (C) Villanova University 2010.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category VuFind
 * @package  Db_Table
 * @author   Demian Katz <demian.katz@villanova.edu>
 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
 * @link     https://vufind.org Main Site
 */
namespace VuFind\Db\Table;

use Laminas\Db\Adapter\Adapter;
use Laminas\Db\Sql\Expression;
use Laminas\Db\Sql\Select;
use VuFind\Date\Converter as DateConverter;
use VuFind\Db\Row\RowGateway;
use VuFind\Record\Loader;

/**
 * Table Definition for resource
 *
 * @category VuFind
 * @package  Db_Table
 * @author   Demian Katz <demian.katz@villanova.edu>
 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
 * @link     https://vufind.org Main Site
 */
class Resource extends Gateway
{
    /**
     * Date converter
     *
     * @var DateConverter
     */
    protected $dateConverter;

    /**
     * Record loader
     *
     * @var Loader
     */
    protected $recordLoader;

    /**
     * Constructor
     *
     * @param Adapter       $adapter   Database adapter
     * @param PluginManager $tm        Table manager
     * @param array         $cfg       Laminas configuration
     * @param RowGateway    $rowObj    Row prototype object (null for default)
     * @param DateConverter $converter Date converter
     * @param Loader        $loader    Record loader
     * @param string        $table     Name of database table to interface with
     */
    public function __construct(Adapter $adapter, PluginManager $tm, $cfg,
        ?RowGateway $rowObj, DateConverter $converter, Loader $loader,
        $table = 'resource'
    ) {
        $this->dateConverter = $converter;
        $this->recordLoader = $loader;
        parent::__construct($adapter, $tm, $cfg, $rowObj, $table);
    }

    /**
     * Look up a row for the specified resource.
     *
     * @param string                            $id     Record ID to look up
     * @param string                            $source Source of record to look up
     * @param bool                              $create If true, create the row if it
     * does not yet exist.
     * @param \VuFind\RecordDriver\AbstractBase $driver A record driver for the
     * resource being created (optional -- improves efficiency if provided, but will
     * be auto-loaded as needed if left null).
     *
     * @return \VuFind\Db\Row\Resource|null Matching row if found or created, null
     * otherwise.
     */
    public function findResource($id, $source = DEFAULT_SEARCH_BACKEND,
        $create = true, $driver = null
    ) {
        if (empty($id)) {
            throw new \Exception('Resource ID cannot be empty');
        }
        $select = $this->select(['record_id' => $id, 'source' => $source]);
        $result = $select->current();

        // Create row if it does not already exist and creation is enabled:
        if (empty($result) && $create) {
            $result = $this->createRow();
            $result->record_id = $id;
            $result->source = $source;

            // Load record if it was not provided:
            if (null === $driver) {
                $driver = $this->recordLoader->load($id, $source);
            }

            // Load metadata into the database for sorting/failback purposes:
            $result->assignMetadata($driver, $this->dateConverter);

            // Save the new row.
            $result->save();
        }
        return $result;
    }

    /**
     * Look up a rowset for a set of specified resources.
     *
     * @param array  $ids    Array of IDs
     * @param string $source Source of records to look up
     *
     * @return \Laminas\Db\ResultSet\AbstractResultSet
     */
    public function findResources($ids, $source = DEFAULT_SEARCH_BACKEND)
    {
        $callback = function ($select) use ($ids, $source) {
            $select->where->in('record_id', $ids);
            $select->where->equalTo('source', $source);
        };
        return $this->select($callback);
    }

    /**
     * Get a set of records from the requested favorite list.
     *
     * @param string $user   ID of user owning favorite list
     * @param string $list   ID of list to retrieve (null for all favorites)
     * @param array  $tags   Tags to use for limiting results
     * @param string $sort   Resource table field to use for sorting (null for
     * no particular sort).
     * @param int    $offset Offset for results
     * @param int    $limit  Limit for results (null for none)
     *
     * @return \Laminas\Db\ResultSet\AbstractResultSet
     */
    public function getFavorites($user, $list = null, $tags = [],
        $sort = null, $offset = 0, $limit = null
    ) {
        // Set up base query:
        $obj = & $this;
        return $this->select(
            function ($s) use ($user, $list, $tags, $sort, $offset, $limit, $obj) {
                $s->columns(
                    [
                        new Expression(
                            'DISTINCT(?)', ['resource.id'],
                            [Expression::TYPE_IDENTIFIER]
                        ), Select::SQL_STAR
                    ]
                );
                $s->join(
                    ['ur' => 'user_resource'], 'resource.id = ur.resource_id',
                    []
                );
                $s->where->equalTo('ur.user_id', $user);

                // Adjust for list if necessary:
                if (null !== $list) {
                    $s->where->equalTo('ur.list_id', $list);
                }

                if ($offset > 0) {
                    $s->offset($offset);
                }
                if (null !== $limit) {
                    $s->limit($limit);
                }

                // Adjust for tags if necessary:
                if (!empty($tags)) {
                    $linkingTable = $obj->getDbTable('ResourceTags');
                    foreach ($tags as $tag) {
                        $matches = $linkingTable
                            ->getResourcesForTag($tag, $user, $list)->toArray();
                        $getId = function ($i) {
                            return $i['resource_id'];
                        };
                        $s->where->in('resource.id', array_map($getId, $matches));
                    }
                }

                // Apply sorting, if necessary:
                if (!empty($sort)) {
                    Resource::applySort($s, $sort);
                }
            }
        );
    }

    /**
     * Get a set of records that do not have metadata stored in the resource
     * table.
     *
     * @return \Laminas\Db\ResultSet\AbstractResultSet
     */
    public function findMissingMetadata()
    {
        $callback = function ($select) {
            $select->where->equalTo('title', '')
                ->OR->isNull('author')
                ->OR->isNull('year');
        };
        return $this->select($callback);
    }

    /**
     * Update the database to reflect a changed record identifier.
     *
     * @param string $oldId  Original record ID
     * @param string $newId  Revised record ID
     * @param string $source Record source
     *
     * @return void
     */
    public function updateRecordId($oldId, $newId, $source = DEFAULT_SEARCH_BACKEND)
    {
        if ($oldId !== $newId
            && $resource = $this->findResource($oldId, $source)
        ) {
            // Do this as a transaction to prevent odd behavior:
            $connection = $this->getAdapter()->getDriver()->getConnection();
            $connection->beginTransaction();
            // Does the new ID already exist?
            if ($newResource = $this->findResource($newId, $source)) {
                // Special case: merge new ID and old ID:
                $tableObjects = [];
                foreach (['comments', 'userresource', 'resourcetags'] as $table) {
                    $tableObjects[$table] = $this->getDbTable($table);
                    $tableObjects[$table]->update(
                        ['resource_id' => $newResource->id],
                        ['resource_id' => $resource->id]
                    );
                }
                $resource->delete();
            } else {
                // Default case: just update the record ID:
                $resource->record_id = $newId();
                $resource->save();
            }
            // Done -- commit the transaction:
            $connection->commit();

            // Deduplicate rows where necessary (this can be safely done outside
            // of the transaction):
            if (isset($tableObjects['resourcetags'])) {
                $tableObjects['resourcetags']->deduplicate();
            }
            if (isset($tableObjects['userresource'])) {
                $tableObjects['userresource']->deduplicate();
            }
        }
    }

    /**
     * Apply a sort parameter to a query on the resource table.
     *
     * @param \Laminas\Db\Sql\Select $query Query to modify
     * @param string                 $sort  Field to use for sorting (may include
     * 'desc' qualifier)
     * @param string                 $alias Alias to the resource table (defaults to
     * 'resource')
     *
     * @return void
     */
    public static function applySort($query, $sort, $alias = 'resource')
    {
        // Apply sorting, if necessary:
        $legalSorts = [
            'title', 'title desc', 'author', 'author desc', 'year', 'year desc'
        ];
        if (!empty($sort) && in_array(strtolower($sort), $legalSorts)) {
            // Strip off 'desc' to obtain the raw field name -- we'll need it
            // to sort null values to the bottom:
            $parts = explode(' ', $sort);
            $rawField = trim($parts[0]);

            // Start building the list of sort fields:
            $order = [];

            // The title field can't be null, so don't bother with the extra
            // isnull() sort in that case.
            if (strtolower($rawField) != 'title') {
                $order[] = new Expression(
                    'isnull(?)', [$alias . '.' . $rawField],
                    [Expression::TYPE_IDENTIFIER]
                );
            }

            // Apply the user-specified sort:
            $order[] = $alias . '.' . $sort;

            // Inject the sort preferences into the query object:
            $query->order($order);
        }
    }
}

{'repo_name': 'vufind-org/vufind', 'stars': '187', 'repo_language': 'PHP', 'file_name': 'index.php', 'mime_type': 'text/x-php', 'hash': 783473860670687095, 'source_dataset': 'data'}


import java.util.*;
class Solution{
	public static void main(String[]args){
		Scanner cin=new Scanner(System.in);
		int T=cin.nextInt();
		for(;T>0;T--){
			int a=cin.nextInt(),b=cin.nextInt(),n=cin.nextInt();
			for(int i=0;i<n;i++){
				System.out.print(a+b*((2<<i)-1));
				System.out.print(i<n-1?" ":"\n");
			}
		}
	}
}

{'repo_name': 'cielavenir/procon', 'stars': '106', 'repo_language': 'C++', 'file_name': 'tyama_yukicoder725.rb', 'mime_type': 'text/x-ruby', 'hash': 7559567494456522189, 'source_dataset': 'data'}


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>en</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>io.loganwright.$(PRODUCT_NAME:rfc1034identifier)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>BNDL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>1</string>
</dict>
</plist>

{'repo_name': 'loganwright/Polymer', 'stars': '151', 'repo_language': 'Objective-C', 'file_name': 'Contents.json', 'mime_type': 'text/plain', 'hash': 5401134914392944725, 'source_dataset': 'data'}


/*
 *  R : A Computer Language for Statistical Data Analysis
 *  Copyright (C) 2092--2012     The R Core Team
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, a copy is available at
 *  https://www.R-project.org/Licenses/
 *
 */

#include <Rinternals.h>
#include "tools.h"

extern int extR_HTTPDCreate(const char *ip, int port);
extern void extR_HTTPDStop(void);

SEXP startHTTPD(SEXP sIP, SEXP sPort)
{
    const char *ip = 0;
    if (sIP != R_NilValue && (TYPEOF(sIP) != STRSXP || LENGTH(sIP) != 1))
	error(_("invalid bind address specification"));
    if (sIP != R_NilValue) ip = CHAR(STRING_ELT(sIP, 0));
    return ScalarInteger(extR_HTTPDCreate(ip, asInteger(sPort)));
}

SEXP stopHTTPD(void)
{
    extR_HTTPDStop();
    return R_NilValue;
}

{'repo_name': 'microsoft/microsoft-r-open', 'stars': '167', 'repo_language': 'R', 'file_name': 'NLSstClosest.R', 'mime_type': 'text/plain', 'hash': -2424622248142155324, 'source_dataset': 'data'}


/* pinyon-script-400normal - latin */
@font-face {
  font-family: 'Pinyon Script';
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src:
    local('Pinyon Script Regular '),
    local('Pinyon Script-Regular'),
    url('./files/pinyon-script-latin-400.woff2') format('woff2'), /* Super Modern Browsers */
    url('./files/pinyon-script-latin-400.woff') format('woff'); /* Modern Browsers */
}

{'repo_name': 'KyleAMathews/typefaces', 'stars': '2352', 'repo_language': 'CSS', 'file_name': 'download-file.js', 'mime_type': 'text/plain', 'hash': -3953262043823233623, 'source_dataset': 'data'}


#include<stdio.h>
#include"vgui_ControlConfigPanel.h"
#include<VGUI_HeaderPanel.h>
#include<VGUI_TablePanel.h>
#include<VGUI_Label.h>
#include<VGUI_ScrollPanel.h>
#include<VGUI_Scheme.h>
#include<VGUI_DataInputStream.h>
#include<VGUI.h>
#include<VGUI_TextEntry.h>

using namespace vgui;

namespace
{
class FooTablePanel : public TablePanel
{
private:
	Label*              _label;
	TextEntry*          _textEntry;
	ControlConfigPanel* _controlConfigPanel;
public:
	FooTablePanel(ControlConfigPanel* controlConfigPanel,int x,int y,int wide,int tall,int columnCount) : TablePanel(x,y,wide,tall,columnCount)
	{
		_controlConfigPanel=controlConfigPanel;
		_label=new Label("You are a dumb monkey",0,0,100,20);
		_label->setBgColor(Scheme::sc_primary3);
		_label->setFgColor(Scheme::sc_primary1);
		_label->setFont(Scheme::sf_primary3);

		_textEntry=new TextEntry("",0,0,100,20);
		//_textEntry->setFont(Scheme::sf_primary3);
	}
public:
	virtual int getRowCount()
	{
		return _controlConfigPanel->GetCVarCount();
	}
	virtual int getCellTall(int row)
	{
		return 12;
	}
	virtual Panel* getCellRenderer(int column,int row,bool columnSelected,bool rowSelected,bool cellSelected)
	{
		char cvar[128],desc[128],bind[128],bindAlt[128];
		_controlConfigPanel->GetCVar(row,cvar,128,desc,128);

		if(cellSelected)
		{
			_label->setBgColor(Scheme::sc_primary1);
			_label->setFgColor(Scheme::sc_primary3);
		}
		else
		if(rowSelected)
		{
			_label->setBgColor(Scheme::sc_primary2);
			_label->setFgColor(Scheme::sc_primary1);
		}
		else
		{
			_label->setBgColor(Scheme::sc_primary3);
			_label->setFgColor(Scheme::sc_primary1);
		}

		switch(column)
		{
			case 0:
			{
				_label->setText(desc);
				_label->setContentAlignment(Label::a_west);
				break;
			}
			case 1:
			{
				_controlConfigPanel->GetCVarBind(cvar,bind,128,bindAlt,128);
				_label->setText(bind);
				_label->setContentAlignment(Label::a_center);
				break;
			}
			case 2:
			{
				_controlConfigPanel->GetCVarBind(cvar,bind,128,bindAlt,128);
				_label->setText(bindAlt);
				_label->setContentAlignment(Label::a_center);
				break;
			}
			default:
			{
				_label->setText("");
				break;
			}
		}

		return _label;
	}
	virtual Panel* startCellEditing(int column,int row)
	{
		_textEntry->setText("Goat",strlen("Goat"));
		_textEntry->requestFocus();
		return _textEntry;
	}
};
}

ControlConfigPanel::ControlConfigPanel(int x,int y,int wide,int tall) : Panel(x,y,wide,tall)
{
	setPaintBorderEnabled(false);
	setPaintBackgroundEnabled(false);
	setPaintEnabled(false);

	_actionLabel=new Label("Action");
	_actionLabel->setBgColor(Scheme::sc_primary3);
	_actionLabel->setFgColor(Scheme::sc_primary3);

	_keyButtonLabel=new Label("Key / Button");
	_keyButtonLabel->setBgColor(Scheme::sc_primary3);
	_keyButtonLabel->setFgColor(Scheme::sc_primary3);

	_alternateLabel=new Label("Alternate");
	_alternateLabel->setBgColor(Scheme::sc_primary3);
	_alternateLabel->setFgColor(Scheme::sc_primary3);

	_headerPanel=new HeaderPanel(0,0,wide,20);
	_headerPanel->setParent(this);

	_headerPanel->addSectionPanel(_actionLabel);
	_headerPanel->addSectionPanel(_keyButtonLabel);
	_headerPanel->addSectionPanel(_alternateLabel);

	_headerPanel->setSliderPos( 0, wide/2 );
	_headerPanel->setSliderPos( 1, (wide/2) + (wide/4) );
	_headerPanel->setSliderPos( 2, wide );

	_scrollPanel=new ScrollPanel(0,20,wide,tall-20);
	_scrollPanel->setParent(this);
	_scrollPanel->setPaintBorderEnabled(false);
	_scrollPanel->setPaintBackgroundEnabled(false);
	_scrollPanel->setPaintEnabled(false);
	_scrollPanel->getClient()->setPaintBorderEnabled(false);
	_scrollPanel->getClient()->setPaintBackgroundEnabled(false);
	_scrollPanel->getClient()->setPaintEnabled(false);
	_scrollPanel->setScrollBarVisible(false,true);

	_tablePanel=new FooTablePanel(this,0,0,_scrollPanel->getClient()->getWide(),800, 3);
	_tablePanel->setParent(_scrollPanel->getClient());
	_tablePanel->setHeaderPanel(_headerPanel);
	_tablePanel->setBgColor(Color(200,0,0,255));
	_tablePanel->setFgColor(Color(Scheme::sc_primary2));
	_tablePanel->setGridVisible(true,true);
	_tablePanel->setGridSize(1,1);
}

void ControlConfigPanel::AddCVar(const char* cvar,const char* desc)
{
	_cvarDar.addElement(vgui_strdup(cvar));
	_descDar.addElement(vgui_strdup(desc));
}

int ControlConfigPanel::GetCVarCount()
{
	return _cvarDar.getCount();
}

void ControlConfigPanel::GetCVar(int index,char* cvar,int cvarLen,char* desc,int descLen)
{
	vgui_strcpy(cvar,cvarLen,_cvarDar[index]);
	vgui_strcpy(desc,descLen,_descDar[index]);
}

void ControlConfigPanel::AddCVarFromInputStream(InputStream* is)
{
	if(is==null)
	{
		return;
	}

	DataInputStream dis(is);

	bool success;

	while(1)
	{
		char buf[256],cvar[128],desc[128];
		dis.readLine(buf,256,success);
		if(!success)
		{
			break;
		}
		if(sscanf(buf,"\"%[^\"]\" \"%[^\"]\"",cvar,desc)==2)
		{
			AddCVar(cvar,desc);
		}
	}
}

void ControlConfigPanel::GetCVarBind(const char* cvar,char* bind,int bindLen,char* bindAlt,int bindAltLen)
{
	sprintf(bind,"%s : Bind",cvar);
	sprintf(bindAlt,"%s : BindAlt",cvar);
}

void ControlConfigPanel::SetCVarBind(const char* cvar,const char* bind,const char* bindAlt)
{
}

{'repo_name': 'unknownworlds/NS', 'stars': '220', 'repo_language': 'C++', 'file_name': 'steam installer.iss', 'mime_type': 'text/plain', 'hash': -2233700028167577591, 'source_dataset': 'data'}


;;;
;;; xa_lba48.asm
;;;
;;; LBA48 support by Paul Bartholomew (oz_paulb)
;;; Copyright (c) 2003 - Released under GNU Public License
;;;
;;; Modified and adapted for nkpatcher by rmenhal
;;; Copyright 2004 rmenhal
;;;
;;; Licensed under GNU General Public License version 2. See the file COPYING
;;; for details.
;;;
%include "diskcdromdef.inc"
%include "lba48.inc"
DEF_PARTMETHOD_ONLY_STANDARD_PARTITIONS			equ	0
DEF_PARTMETHOD_PART6_REST_OF_DRIVE			equ	1
DEF_PARTMETHOD_PART6_UNDER_137GB_PART7_REST_OF_DRIVE	equ	2
DEF_PARTMETHOD_PART6_UNDER_137GB_NO_PART7			equ	3
XBOX_SWAPPART1_LBA_START	equ 0x400
XBOX_SWAPPART_LBA_SIZE	equ 0x177000
XBOX_SWAPPART2_LBA_START	equ (XBOX_SWAPPART1_LBA_START + XBOX_SWAPPART_LBA_SIZE)
XBOX_SWAPPART3_LBA_START	equ (XBOX_SWAPPART2_LBA_START + XBOX_SWAPPART_LBA_SIZE)
XBOX_SYSPART_LBA_START	equ (XBOX_SWAPPART3_LBA_START + XBOX_SWAPPART_LBA_SIZE)
XBOX_SYSPART_LBA_SIZE	equ 0xfa000
XBOX_MUSICPART_LBA_START	equ (XBOX_SYSPART_LBA_START + XBOX_SYSPART_LBA_SIZE)
XBOX_MUSICPART_LBA_SIZE	equ 0x9896b0
XBOX_STANDARD_MAX_LBA	equ (XBOX_MUSICPART_LBA_START + XBOX_MUSICPART_LBA_SIZE)
xa_lba48_partition_table:
.hdr:
	db	'****PARTINFO****'
	times 32 db 0	; reserved
	PT_ENTRY	'XBOX MUSIC      ', \
			PE_PARTFLAGS_IN_USE, \
			XBOX_MUSICPART_LBA_START, \
			XBOX_MUSICPART_LBA_SIZE, \
			0
	PT_ENTRY	'XBOX SYSTEM     ', \
			PE_PARTFLAGS_IN_USE, \
			XBOX_SYSPART_LBA_START, \
			XBOX_SYSPART_LBA_SIZE, \
			0
	PT_ENTRY	'XBOX GAME SWAP 1', \
			PE_PARTFLAGS_IN_USE, \
			XBOX_SWAPPART1_LBA_START, \
			XBOX_SWAPPART_LBA_SIZE, \
			0
	PT_ENTRY	'XBOX GAME SWAP 2', \
			PE_PARTFLAGS_IN_USE, \
			XBOX_SWAPPART2_LBA_START, \
			XBOX_SWAPPART_LBA_SIZE, \
			0
	PT_ENTRY	'XBOX GAME SWAP 3', \
			PE_PARTFLAGS_IN_USE, \
			XBOX_SWAPPART3_LBA_START, \
			XBOX_SWAPPART_LBA_SIZE, \
			0
xa_lba48_partition_table_first_available:
	PT_ENTRY	'                ',0,0,0,0
	PT_ENTRY	'                ',0,0,0,0
	PT_ENTRY	'                ',0,0,0,0
	PT_ENTRY	'                ',0,0,0,0
	PT_ENTRY	'                ',0,0,0,0
	PT_ENTRY	'                ',0,0,0,0
	PT_ENTRY	'                ',0,0,0,0
	PT_ENTRY	'                ',0,0,0,0
	PT_ENTRY	'                ',0,0,0,0
%if ($-xa_lba48_partition_table) != PARTITION_TABLE_SIZE
	%error Partition table is bad.
%endif
	times (512-PARTITION_TABLE_SIZE) db 0
xa_lba48_def_partition_method:
	db	PARTITION_METHOD
xa_lba48_ignore_HD_part_table:
%ifdef IGNORE_HD_PARTITION_TABLE
	db	1
%else
	db	0
%endif
align 4
xa_lba48_identify_data:
	times 512 db 0
xa_lba48_fill_parameters:
.io_status		equ 0 - 8
.ata_pass		equ .io_status - ATA_PASS_THROUGH_size
.part_buf		equ .ata_pass - 512
.local_var_size		equ -.part_buf
	;; [esp+4] = Address to FEATURE_PARAMETERS for filling LBA48 parameters
	push	ebp
	mov	ebp,esp
	sub	esp,.local_var_size
	push	ebx
	push	esi
	push	edi
	lea	esi,[ebp + .io_status]	; IO status block
	push	eax
	mov	ebx,esp
	push	byte 40h
	push	.part0_ansistr
	push	byte 0
	mov	edx,esp		; Object attributes
	push	byte 20h	; FILE_SYNCHRONOUS_IO_NONALERT
	push	byte 3		; FILE_SHARE_READ | FILE_SHARE_WRITE
	push	esi
	push	edx
	push	80100000h	; GENERIC_READ | SYNCHRONIZE
	push	ebx
	call	dword [NtOpenFile]
	add	esp,byte 12
	pop	ebx
	test	eax,eax
	jl	near .exit
	xor	eax,eax
	lea	edi,[ebp + .ata_pass]
	mov	[edi + ATA_PASS_THROUGH.IdeReg],eax
	mov	[edi + ATA_PASS_THROUGH.IdeReg+4],eax
	mov	byte [edi + ATA_PASS_THROUGH.IdeReg + IDEREGS.bCommandReg],0ECh ; ATA Identify Device command
	mov	dword [edi + ATA_PASS_THROUGH.DataBufferSize],512
	mov	dword [edi + ATA_PASS_THROUGH.DataBuffer],xa_lba48_identify_data
	push	byte ATA_PASS_THROUGH_size
	push	edi
	push	byte ATA_PASS_THROUGH_size
	push	edi
	push	IOCTL_IDE_PASS_THROUGH
	push	esi
	push	eax
	push	eax
	push	eax
	push	ebx
	call	dword [NtDeviceIoControlFile]
	test	eax,eax
	jl	.exit_close
	call	.get_drive_total_sectors
	mov	edx,[ebp+8]
	mov	[edx + FEATURE_PARAMETERS.lba48_total_sectors],eax
	mov	dword [edx + FEATURE_PARAMETERS.lba48_partition_table],xa_lba48_partition_table
	cmp	byte [xa_lba48_ignore_HD_part_table],0
	jne	.usual_parts
	lea	edi,[ebp + .part_buf]
	xor	eax,eax
	push	eax
	push	eax
	push	esp
	push	512
	push	edi
	push	esi
	push	eax
	push	eax
	push	eax
	push	ebx
	call	dword [NtReadFile]
	pop	ecx
	pop	edx
	test	eax,eax
	jl	.usual_parts
	mov	esi,edi
	mov	edi,xa_lba48_partition_table.hdr
	push	byte (PARTITION_MAGIC_LEN/4)
	pop	ecx
	repe	cmpsd
	jne	.usual_parts
	mov	ecx,PARTITION_TABLE_SIZE-PARTITION_MAGIC_LEN
	rep	movsb
	jmp	short .exit_close
.usual_parts:
	mov	ecx,[ebp+8]
	mov	ecx,[ecx + FEATURE_PARAMETERS.lba48_total_sectors]
	call	.setup_usual_partition_table
.exit_close:
	push	ebx
	call	dword [NtClose]
.exit:
	pop	edi
	pop	esi
	pop	ebx
	leave
	ret
.part0_strz		db '\Device\Harddisk0\Partition0',0
.part0_ansistr		dw $-.part0_strz-1, $-.part0_strz
			dd .part0_strz
.ID_OFS__CMD_SET_SUPPORTED	equ	(83*2)
.BITMASK__CMD_SET_HAS_LBA48	equ	(1<<10)
.ID_OFS__TOTAL_USER_SECTORS_LBA28	equ	(60*2)
.ID_OFS__TOTAL_USER_SECTORS_LBA48_LOW	equ	(100*2)
.ID_OFS__TOTAL_USER_SECTORS_LBA48_HIGH	equ	(102*2)
.get_drive_total_sectors:
	mov	edx,xa_lba48_identify_data
	mov	eax,[edx + .ID_OFS__CMD_SET_SUPPORTED]
	test	eax,.BITMASK__CMD_SET_HAS_LBA48
	jnz	short .drive_supports_lba48
.no_lba48_support:
	mov	eax,[edx + .ID_OFS__TOTAL_USER_SECTORS_LBA28]
	jmp	short .have_total_sectors
.drive_supports_lba48:
	cmp	dword [edx + .ID_OFS__TOTAL_USER_SECTORS_LBA48_HIGH],byte 0
	ja	short .drive_is_huge__limit_to_32bits
	mov	eax,[edx + .ID_OFS__TOTAL_USER_SECTORS_LBA48_LOW]
	jmp	short .have_total_sectors
.drive_is_huge__limit_to_32bits:
	or	eax,byte -1
.have_total_sectors:
	ret
.setup_usual_partition_table:
	push	ebx
	push	esi
	push	edi
	mov	eax,ecx
	mov	edx,ecx
	cmp	eax,XBOX_STANDARD_MAX_LBA
	ja	.try_extra_partitions
.j_skip_extra_partitions:
	jmp	.skip_extra_partitions
.try_extra_partitions:
	cmp	byte [xa_lba48_def_partition_method],DEF_PARTMETHOD_ONLY_STANDARD_PARTITIONS
	jz	short .j_skip_extra_partitions
	sub	eax,XBOX_STANDARD_MAX_LBA
	;; eax now free space at end of drive
	mov	ebx,eax
	xor	ecx,ecx
	;; ebx holds part6 size (default to all free space)
	;; ecx holds part7 size (default to zero)
	;; if drive isn't > 137gb, just create part6
	cmp	edx,0x0fffffff
	jbe	.create_partitions
.drive_larger_than_137gb:
	cmp	byte [xa_lba48_def_partition_method],DEF_PARTMETHOD_PART6_REST_OF_DRIVE
	jz	.create_partitions
	mov	ebx,0x0fffffff - XBOX_STANDARD_MAX_LBA
	;; ebx holds part6 size (rest of space before 137gb)
	cmp	byte [xa_lba48_def_partition_method],DEF_PARTMETHOD_PART6_UNDER_137GB_NO_PART7
	jz	.create_partitions
	mov	ecx,edx				;edx holds total drive sectors
	sub	ecx,XBOX_STANDARD_MAX_LBA	;ecx now free space at end of
						;drive
	sub	ecx,ebx				;subtract space used for part6
	;; ecx holds part7 size
.create_partitions:
.drive_less_or_equal_to_137gb:
	;; ebx = part6 size
	;; ecx = part7 size
	;; edx = total drive sectors
	mov	eax,xa_lba48_partition_table_first_available
	mov	esi,.drive_f_str
	lea	edi,[eax + _PE_OFS__part_name]
	times 4 movsd
	mov	dword [eax + _PE_OFS__part_lba_start],XBOX_STANDARD_MAX_LBA
	mov	dword [eax + _PE_OFS__part_lba_size],ebx
	mov	dword [eax + _PE_OFS__part_flags],PE_PARTFLAGS_IN_USE
	test	ecx,ecx
	jz	.partitions_created
	add	eax,byte _PE_SIZ__part_entry
	mov	esi,.drive_g_str
	lea	edi,[eax + _PE_OFS__part_name]
	times 4 movsd
	mov	dword [eax + _PE_OFS__part_lba_start],XBOX_STANDARD_MAX_LBA
	add	dword [eax + _PE_OFS__part_lba_start],ebx
	mov	dword [eax + _PE_OFS__part_lba_size],ecx
	mov	dword [eax + _PE_OFS__part_flags],PE_PARTFLAGS_IN_USE
.partitions_created:
.skip_extra_partitions:
.partitions_done:
	pop	edi
	pop	esi
	pop	ebx
	ret
align 4
.drive_f_str	db 'DRIVE F:        '
.drive_g_str	db 'DRIVE P:        '

{'repo_name': 'Rocky5/Xbox-Softmodding-Tool', 'stars': '245', 'repo_language': 'C', 'file_name': 'lang.xml', 'mime_type': 'text/xml', 'hash': 4926792859338070406, 'source_dataset': 'data'}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:app="http://schemas.android.com/apk/res/com.example.wechat01"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:orientation="vertical">
	<com.example.wechat01.widght.swipe.SwipeLayout
	    android:id="@+id/swipe"
		app:drag_edge="right"
		android:layout_width="match_parent"
		android:layout_height="wrap_content">

	    <LinearLayout
		    android:id="@+id/layout_back"
			android:background="@color/red"
			android:gravity="center"
			android:layout_width="80dp"
			android:layout_height="65.0dip">
		 <TextView
				android:id="@+id/txt_del"
				style="@style/MMFontTitleInList"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:text="删除"
				android:textColor="@color/white"
				android:textSize="18sp"
				android:singleLine="true" />
		</LinearLayout>
	<LinearLayout
		android:id="@+id/contactitem_layout"
		style="@style/MMListItem"
		android:layout_height="65.0dip"
		android:background="@color/white"
		android:paddingLeft="12dip">
			<RelativeLayout
			android:id="@+id/avatar_container"
			android:layout_width="59dp"
			android:layout_marginTop="4dp"
			android:layout_height="match_parent"
			android:layout_alignParentLeft="true">
			<ImageView
				android:id="@+id/contactitem_avatar_iv"
				android:layout_width="50.0dip"
				android:layout_height="50.0dip"
				android:src="@drawable/head" />
			<TextView
				android:id="@+id/unread_msg_number"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:layout_alignParentRight="true"
				android:background="@drawable/aii"
				android:gravity="center"
			    android:text="2"
				android:textColor="@android:color/white"
				android:textSize="12sp" />
		</RelativeLayout>
		<RelativeLayout
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:layout_weight="1.0"
			android:orientation="vertical"
			android:paddingLeft="5dip">
			<TextView
			    android:text="老婆"
				android:id="@+id/txt_name"
				style="@style/MMFontTitleInList"
				android:textColor="@color/black"
				android:singleLine="true" />

			<TextView
			    android:text="吃饭了吗？"
				android:id="@+id/txt_content"
				style="@style/MMFontTitleInList"
				android:layout_below="@+id/txt_name"
				android:layout_toRightOf="@+id/txt_state"
				android:layout_width="wrap_content"
				android:layout_height="wrap_content"
				android:layout_marginTop="5dp"
				android:textSize="14sp"
				android:textColor="@color/black1"
				android:singleLine="true" />
		</RelativeLayout>
		<TextView
			android:id="@+id/txt_time"
			    android:text="下午 2.10"
			style="@style/MMFontTitleInList"
			android:layout_width="wrap_content"
			android:layout_height="match_parent"
			android:layout_marginTop="10dp"
			android:layout_marginRight="10dp"
			android:gravity="top"
			android:textSize="12sp"
			android:singleLine="true" />
	</LinearLayout>

	</com.example.wechat01.widght.swipe.SwipeLayout>
	<View
		android:layout_width="match_parent"
		android:layout_height="1dp"
		android:background="@color/black2" />
</LinearLayout>

{'repo_name': 'motianhuo/VCameraDemo', 'stars': '1421', 'repo_language': 'Java', 'file_name': 'org.eclipse.core.resources.prefs', 'mime_type': 'text/plain', 'hash': 3714016708906639099, 'source_dataset': 'data'}


var proto = require('./native'),
  ldap = require('ldapjs');

function LDAP(options) {
  this.options = options;

  this._ldapClient = ldap.createClient(options.server);
}

LDAP.prototype = proto.prototype;

/*
 *  Remote HTTP Basic Auth
 */
LDAP.prototype.test = function(username, password, opts, next) {
  var self = this,
    dao = this.dao,
    filter = {},
    options = this.options;

  if ('admin' === username || opts.asOwner) {
    this.__proto__._test.apply(this, arguments);

  } else if (!username || !password) {
    next(self.MSG_NOT_AUTHORIZED, null);

  } else {

    var client = this._ldapClient,
      base = options.base,
      search = app._.clone(options.search),
      bind = true;

    if (search.filter) {
      search.filter = search.filter.replace(/{{username}}/, username);
    }

    client.search(base, search, function(err, res) {
      if (err) {
        next(err);
      } else {

        var foundMatch = false,
          notFoundMsg = 'Not Found';

        res.on('end', function() {
          if (!foundMatch) {
            next(notFoundMsg, null);
          }
        });

        res.on('searchEntry', function(entry) {
          foundMatch = true;

          client.compare(entry.dn, 'userPassword', password, function(err, pass ) {

            if (err) {
              next(err);

            } else if (!pass) {
              next('Not Authorized')

            } else {

              // auth continue
              dao.find(
                'account',
                {
                  username : username
                },
                function(err, acctResult) {
                  if (!err && (null != acctResult)) {

                    var filter = {
                      'owner_id' : acctResult.id,
                      'type' : 'token'
                    }

                    dao.find('account_auth', filter, function(isErr, authResult) {
                      var resultModel = null;
                      if (!isErr && null != authResult) {

                        self.acctBind(acctResult, authResult, options, function(err, accountInfo) {
                          next(false, accountInfo);
                        });

                      } else {
                        next(self.MSG_NOT_AUTHORIZED, resultModel);
                      }
                    });

                  // if user auths off and option set, auto create
                  // local account
                  } else if (!acctResult && options.auto_sync && options.auto_sync.mail_field) {
                    var emailAddress;

                    // if no email address found, create a local dummy
                    if ('none' === options.auto_sync.mail_field) {
                      emailAddress = 'noreply@' + username + '.' + CFG.domain;
                    } else {
                      for (var i = 0; i < entry.attributes.length; i++) {
                        if (options.auto_sync.mail_field === entry.attributes[i].type) {
                          emailAddress = entry.attributes[i].vals.pop();
                          break;
                        }
                      }
                    }

                    if (emailAddress) {

                      dao.createUser(username, emailAddress, null, function(err, authResult) {
                        authResult.username = username;
                        authResult.name = username
                        authResult.account_level = GLOBAL.DEFS.ACCOUNT_LEVEL.USER;

                        self.acctBind(authResult, authResult, options, function(err, accountInfo) {
                          next(false, accountInfo);
                        });

                      });

                    } else {
                      next(self.MSG_NOT_AUTHORIZED, null);
                    }
                  } else {
                    app.logmessage('No Email field found to sync for ' + username + ', skipping auth', 'error');
                    next(self.MSG_NOT_AUTHORIZED, null);
                  }
                }
              );
            }
          });
        });
      }
    });
  }
}

module.exports = LDAP;

{'repo_name': 'bipio-server/bipio', 'stars': '875', 'repo_language': 'JavaScript', 'file_name': 'index.js', 'mime_type': 'text/plain', 'hash': 1392144483450170183, 'source_dataset': 'data'}


// Copyright 2009 the Sputnik authors.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/**
 * The MV of DecimalDigit ::: 3 or of HexDigit ::: 3 is 3
 *
 * @path ch09/9.3/9.3.1/S9.3.1_A19.js
 * @description Compare Number('0x3') and Number('0X3') with 3
 */

// CHECK#1
if (Number("3") !== 3)  {
  $ERROR('#1: Number("3") === 3. Actual: ' + (Number("3")));
}

// CHECK#2
if (+("0x3") !== 3)  {
  $ERROR('#2: +("0x3") === 3. Actual: ' + (+("0x3")));
}

// CHECK#3
if (Number("0X3") !== 3)  {
  $ERROR('#3: Number("0X3") === 3. Actual: ' + (Number("0X3")));
}

{'repo_name': 'wizzard0/js2lua', 'stars': '181', 'repo_language': 'JavaScript', 'file_name': 'shortcuts.js', 'mime_type': 'text/plain', 'hash': -424840682282020740, 'source_dataset': 'data'}