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
var something: String? = getSomething() | |
fun main(args: Array<String>) { | |
nowItsNotAVarAnymore(something) | |
} | |
fun nowItsNotAVarAnymore(param: String?) { | |
if (param) { | |
println("Param is not nullable and contains ${param.length} characters) | |
} else { |
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
import android.app.Activity | |
import android.support.annotation.IdRes | |
import android.view.View | |
fun <T : View> Activity.bind(@IdRes idRes: Int): Lazy<T> { | |
@Suppress("UNCHECKED_CAST") | |
return unsafeLazy { findViewById(idRes) as T } | |
} | |
fun <T : View> View.bind(@IdRes idRes: Int): Lazy<T> { |
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 takePicture() { | |
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { | |
Uri photoURI = null; | |
try { | |
File photoFile = createImageFileWith(); | |
path = photoFile.getAbsolutePath(); | |
photoURI = FileProvider.getUriForFile(MainActivity.this, | |
getString(R.string.file_provider_authority), | |
photoFile); |
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 takePicture() { | |
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { | |
Uri photoURI = null; | |
try { | |
File photoFile = createImageFileWith(); | |
path = photoFile.getAbsolutePath(); | |
photoURI = FileProvider.getUriForFile(MainActivity.this, | |
getString(R.string.file_provider_authority), | |
photoFile); |
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 takePicture() { | |
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { | |
File photoFile = null; | |
try { | |
photoFile = createImageFileWith(); | |
} catch (IOException ex) { | |
Log.e("TakePicture", ex.getMessage()); | |
} | |
if (photoFile != null) { |
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
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
Log.v("Chart onMeasure w", MeasureSpec.toString(widthMeasureSpec)); | |
Log.v("Chart onMeasure h", MeasureSpec.toString(heightMeasureSpec)); | |
int desiredWidth = getSuggestedMinimumWidth() + getPaddingLeft() + getPaddingRight(); | |
int desiredHeight = getSuggestedMinimumHeight() + getPaddingTop() + getPaddingBottom(); | |
setMeasuredDimension(measureDimension(desiredWidth, widthMeasureSpec), | |
measureDimension(desiredHeight, heightMeasureSpec)); |
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 int measureDimension(int desiredSize, int measureSpec) { | |
int result; | |
int specMode = MeasureSpec.getMode(measureSpec); | |
int specSize = MeasureSpec.getSize(measureSpec); | |
if (specMode == MeasureSpec.EXACTLY) { | |
result = specSize; | |
} else { | |
result = desiredSize; | |
if (specMode == MeasureSpec.AT_MOST) { |
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
Calendar calendar = Calendar.getInstance(); | |
calendar.add(Calendar.MONTH, -1); | |
long start = calendar.getTimeInMillis(); | |
long end = System.currentTimeMillis(); | |
Map<String, UsageStats> stats = usageStatsManager.queryAndAggregateUsageStats(start, end); |
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
Calendar calendar = Calendar.getInstance(); | |
calendar.add(Calendar.MONTH, -1); | |
long start = calendar.getTimeInMillis(); | |
long end = System.currentTimeMillis(); | |
List<UsageStats> stats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_WEEKLY, start, end); |
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 boolean checkForPermission(Context context) { | |
AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); | |
int mode = appOps.checkOpNoThrow(OPSTR_GET_USAGE_STATS, Process.myUid(), context.getPackageName()); | |
return mode == MODE_ALLOWED; | |
} |