Skip to content

Instantly share code, notes, and snippets.

View KanshuYokoo's full-sized avatar

kkaannnssshh KanshuYokoo

View GitHub Profile
@KanshuYokoo
KanshuYokoo / realm save
Created August 10, 2018 06:45
realm for android java save gist
private <E extends RealmModel> E saveToRealm(E model) {
E result_model;
try {
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
result_model = realm.copyToRealmOrUpdate(model);
realm.commitTransaction();
realm.close();
} catch (RealmException ex) {
throw ex;
@KanshuYokoo
KanshuYokoo / border.xml
Created August 11, 2018 13:04
android border gist
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="5dp"
android:color="@android:color/holo_blue_light" />
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="10dp" />
@KanshuYokoo
KanshuYokoo / gist:71294c45d3a9488a2ddb7a1b4a7554c2
Created August 12, 2018 13:25
go back previous button on Android
Button mBack;
mBack = findViewById(R.id.myBackButton);
mBack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
MyActivity.this.finish();
}
@KanshuYokoo
KanshuYokoo / check login credentials
Created August 13, 2018 03:49
Android, checking if login credentials are filled
public class LoginActivity extends AppCompatActivity implements View.OnClickListener, TextWatcher {
userData user;
private Button mLoginButton;
private EditText mLoginID;
private EditText mLoginPW;
@Override
protected void onCreate(Bundle savedInstanceState) {
mLoginID = findViewById(R.id.loginEdit);
public class StartActivity extends AppCompatActivity implements ResultHandleInterface {
private ProgressBar mCycler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new APITask(this).execute(place);
@KanshuYokoo
KanshuYokoo / java Data format
Created August 15, 2018 06:03
java data format
Date currentTime = myCalendar.getTime();
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat timeFormatter = new SimpleDateFormat("HHmm");
timeToSend = timeFormatter.format(currentTime);
dateToSend = dateFormatter.format(currentTime);
@KanshuYokoo
KanshuYokoo / java zero padding
Created August 18, 2018 07:08
java, 0 padding number to string
// 1000 to 00001000
int myNumber = 1000;
String.format("%08d", myNumber);
String example = "AnyString";
int paddingLength = 12;
String.format("%0"+ (paddingLength - example.length() )+"d%s",0 ,example);
@KanshuYokoo
KanshuYokoo / ios change view
Created September 2, 2018 12:51
ios swift; how to change view by code. *UI operations must be performed on the main thread's queue.
DispatchQueue.main.async() {
[unowned self] in
self.performSegue(withIdentifier: "toSecond", sender: nil)
}
@KanshuYokoo
KanshuYokoo / ios swift button enable with textfields
Created September 13, 2018 07:55
ios swift button enable with multiple textfields
class ViewController: UIViewController,UITextFieldDelegate {
@IBOutlet weak var text1: UITextField!
@IBOutlet weak var text2: UITextField!
@IBOutlet weak var button1Outlet: UIButton!
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
var t1 = text1.text
if(textField.tag == 0){