This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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] : ''; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get file extension | |
* @param $filePath | |
* @return string | |
*/ | |
public function getExtension( $filePath ) | |
{ | |
if( strpos( $filePath, '.' ) === false ){ | |
return ''; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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>'; |