View isOnline.kt
private fun isOnline(context: Context): Boolean { | |
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
val n = cm.activeNetwork | |
if (n != null) { | |
val nc = cm.getNetworkCapabilities(n) | |
return nc!!.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || nc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) | |
} | |
return false | |
} |
View MyWebViewClient.java
@SuppressWarnings("deprecation") | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
Uri uri = Uri.parse(url); | |
if (uri.getHost() != null && uri.getHost().contains("example.com")) { | |
return false; | |
} | |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | |
view.getContext().startActivity(intent); |
View gist:36cfe44ce4ae92c56a39a59fdaa9cd27
private void openNewActivity(String title, String description){ | |
Intent testIntent = new Intent(this,TestActivity.class); | |
testIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK); | |
PendingIntent pen = PendingIntent.getActivity(this,15,testIntent,PendingIntent.FLAG_ONE_SHOT); | |
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); | |
builder.setContentTitle(title) | |
.setContentText(description) | |
.setSmallIcon(R.mipmap.ic_launcher) | |
.setOngoing(true) | |
.addAction(R.drawable.ic_play, "Test", pen) |
View ShowNotification
private void sendNotification(String messageBody, String webUrl) { | |
Intent intent = new Intent(this, MainActivity.class); | |
intent.putExtra("targetLink",webUrl); | |
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); | |
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); | |
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) | |
.setSmallIcon(R.mipmap.ic_launcher) | |
.setContentTitle(getString(R.string.app_name)) |
View getYoutubeId.php
/** | |
* getYoutubeId | |
* @par string $video_url | |
*/ | |
public function getYoutubeId( $url ) | |
{ | |
// http://stackoverflow.com/a/10315969/2252921 | |
preg_match('/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/', $url, $founded); | |
return !empty( $founded ) ? $founded[1] : ''; | |
} |
View getExtension.php
/** | |
* Get file extension | |
* @param $filePath | |
* @return string | |
*/ | |
public function getExtension( $filePath ) | |
{ | |
if( strpos( $filePath, '.' ) === false ){ | |
return ''; | |
} |
View secondsToTime.php
/** | |
* Seconds to time | |
* @param $sec | |
* @return string | |
*/ | |
static function secondsToTime( $sec ){ | |
if( !is_float( $sec ) ) $sec = floatval( $sec ); | |
$hours = floor($sec / 3600); | |
$minutes = floor(($sec - ($hours * 3600)) / 60); | |
$seconds = $sec - ($hours * 3600) - ($minutes * 60); |
View php _get_file_size_from_byte.php
/** | |
* @param $bytes | |
* @param string $unit | |
* @param int $decimals | |
* @return string | |
*/ | |
static function sizeFormat($bytes, $unit = "", $decimals = 2) | |
{ | |
$units = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4, 'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8); | |
$value = 0; |
View pagination_config.php
$config['base_url'] = base_url() . 'controller/method/'; | |
$config['total_rows'] = $this->Model->totalRowNoCount();// Total row count | |
$config['per_page'] = 2; | |
$config['prev_link'] = '«'; | |
$config['next_link'] = '»'; | |
$config['first_link'] = ''; | |
$config['last_link'] = ''; | |
$config['full_tag_open'] = '<ul class="pagination">'; | |
$config['full_tag_close'] = '</ul>'; | |
$config['prev_tag_open'] = '<li>'; |