Skip to content

Instantly share code, notes, and snippets.

View shohiebsense's full-sized avatar
Thunder Breath; 99th Style

Shohieb shohiebsense

Thunder Breath; 99th Style
View GitHub Profile
@shohiebsense
shohiebsense / Showing Whatsapp Contact, unsaved.
Last active February 20, 2019 08:52
Showing Whatsapp Unsaved Contact
public void showWaContact(){
try{
String contactWaNumber = "6281363009995";
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.Conversation"));
sendIntent.putExtra("jid", contactWaNumber+"@s.whatsapp.net");
startActivity(sendIntent);
}catch (Exception e){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.whatsapp")));
}
@shohiebsense
shohiebsense / SetUpAutoCompleteTextViewAsDropdown.java
Created March 19, 2019 06:26
Self Explanatory as in the filename.
void setDropDownView(AutoCompleteTextView autoCompleteTextView){
int paddingBottom = autoCompleteTextView.getPaddingBottom();
int paddingStart = ViewCompat.getPaddingStart(autoCompleteTextView);
int paddingEnd = ViewCompat.getPaddingEnd(autoCompleteTextView);
int paddingTop = autoCompleteTextView.getPaddingTop();
ViewCompat.setBackground(autoCompleteTextView, null);
ViewCompat.setPaddingRelative(autoCompleteTextView, paddingStart,
paddingTop, paddingEnd, paddingBottom);
}
@shohiebsense
shohiebsense / activity.java
Created April 11, 2019 10:31
AutoCompleteTextView to dropdown feel-alike
void setDropDownView(AutoCompleteTextView autoCompleteTextView){
int paddingBottom = autoCompleteTextView.getPaddingBottom();
int paddingStart = ViewCompat.getPaddingStart(autoCompleteTextView);
int paddingEnd = ViewCompat.getPaddingEnd(autoCompleteTextView);
int paddingTop = autoCompleteTextView.getPaddingTop();
ViewCompat.setBackground(autoCompleteTextView, null);
ViewCompat.setPaddingRelative(autoCompleteTextView, paddingStart,
paddingTop, paddingEnd, paddingBottom);
}
@shohiebsense
shohiebsense / Image JPEG Processing on Android
Last active April 29, 2019 03:26
Image Processing, Gallery And Camera
<!-- Manifest.xml -->
<manifest>
<uses-permission android:name="android.permission.INTERNET" />
<!-- Camera -->
<uses-feature android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@shohiebsense
shohiebsense / WhereDateIsNow.java
Last active April 29, 2019 10:24
Sqlite from java class where date is today, given format yyyy-MM-dd HH:mm:ss
//the idea is to cut the slash / strip
//or do DATE (SUBSTR("TIMESTAMP_COLUMN_NAME+"1,11)) = DATE('now')
public static String getCurrentTimeStamp() {
java.util.Date date = new java.util.Date();
Timestamp timestamp = new Timestamp(date.getTime());
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(date);
return formattedDate;
}
@shohiebsense
shohiebsense / Log
Created May 9, 2019 02:48
No need to write TAG for logging purposes again.
public static void e(Object object, String message){
Class<?> classObj = object.getClass();
android.util.Log.d(classObj.getSimpleName(), " - "+message);
}
@shohiebsense
shohiebsense / BaseMaterialDialog.java
Created May 14, 2019 04:04
Default Material Dialog helper/util from afollestad/materialdialog
package com.infield.epms.view;
import android.content.Context;
import android.support.annotation.NonNull;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.infield.epms.R;
public class BaseMaterialDialog {
@shohiebsense
shohiebsense / EditTextActivity.java
Last active May 20, 2019 10:06
Delayed EditText so you could do anything you want in between.
EditText edit_text;
OnEditTextSearchListener listener;
String tempText;
//in case if it is using honeywell keypad...
int lengthBefore = 0;
@Override
@shohiebsense
shohiebsense / item_dropdown_general.xml
Created October 11, 2019 08:59
Best Dimension for Dropdown and it's field in AutoTextView
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="@dimen/padding_tiny"
android:paddingRight="@dimen/padding_tiny"
android:paddingTop="@dimen/padding_small"
android:paddingBottom="@dimen/padding_small"
android:ellipsize="end"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
public class IntegerInputFilter implements InputFilter {
private Pattern pattern = Pattern.compile("^(?!0{1,})\\d+(?:\\.\\d+)?$");
//or ..{1,}..
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
//Log.e("word "+source+ " "+dest);
Matcher matcher = pattern.matcher(dest.toString()+source.toString());
//you can handle with length == 1 return null;
if(!matcher.matches()){