Skip to content

Instantly share code, notes, and snippets.

View thanhcs94's full-sized avatar
🏠
Working from home

ThanhCS94 thanhcs94

🏠
Working from home
View GitHub Profile
@thanhcs94
thanhcs94 / isInternetConnected
Last active August 29, 2015 14:21
Android_Tips
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class ConnectedDetector {
private Context _context;
public ConnectedDetector(Context context){
this._context = context;
String title=shareItem.getTitle();
String photo=shareItem.getPhotoUrl();
if(title.isEmpty()) title="Giọng hát việt";
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
// sendIntent.putExtra(Intent.EXTRA_TITLE, txtTitle.getText());
// String
// text=txtTime.getText()+", "+txtDate.getText()+". Tại: "+txtLocation.getText();
String htmlText = title+"\n"
+ shareItem.getPhotoUrl()+"\n"
@thanhcs94
thanhcs94 / get all music
Created May 20, 2015 02:34
get all music sd card
//method to retrieve song info from device
public void getSongList2(){
//query external audio
ContentResolver musicResolver = getActivity().getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
//iterate over results if valid
if(musicCursor!=null && musicCursor.moveToFirst()){
//get columns
@thanhcs94
thanhcs94 / isValidEmail.java
Last active August 29, 2015 14:22
isValidEmail Function
public static boolean isEmailValid(String email) {
boolean isValid = false;
String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
CharSequence inputStr = email;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
#include <iostream>
#include <string>
#include <conio.h>
#include <fstream>
using namespace std;
void scanner();
void factor();
void term();
@thanhcs94
thanhcs94 / ScrollViewTop.java
Created July 31, 2015 01:45
Android ScrollView setting focus on top
Instead of:
ScrollView main = (ScrollView) findViewById(R.id.main);
main.scrollTo(0,0);
I used:
final ScrollView main = (ScrollView) findViewById(R.id.main);
main.post(new Runnable() {
public void run() {
main.scrollTo(0,0);
}
@thanhcs94
thanhcs94 / rotate.xml
Created July 31, 2015 06:06
rotate view
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="1"
android:toDegrees="360" />
private Activity context;
private int layoutResourceId;
private NewsListRSSItems newsListData[] = null;
public NewsListArrayAdapter(Activity context, int layoutResourceId, NewsListRSSItems[] newListData) {
super(context, layoutResourceId, newListData);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.newsListData = newListData;
@thanhcs94
thanhcs94 / Imagesimfilter.cpp
Last active September 20, 2015 15:49
Filter Images Using imfilter
>> I = imread('E:\fasterthinking.png');
>> h = ones(5,5) / 25;
>> I2 = imfilter(I,h);
>> imshow(I), title('Original Image');
>> figure, imshow(I2), title('Filtered Image')
//Link:
//http://www.mathworks.com/help/images/filter-images-using-imfilter.html
@thanhcs94
thanhcs94 / openChooser.java
Created September 28, 2015 09:54
openChooser
Intent intent = new Intent();
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select PDF "), SELECT_PDF);