Skip to content

Instantly share code, notes, and snippets.

View florinmuscalu's full-sized avatar
😅
I may be slow to respond.

Zekon Technologies florinmuscalu

😅
I may be slow to respond.
View GitHub Profile
android {
...
def versionFile = file('version.properties')
Properties prop = new Properties()
if (versionFile.canRead()) {
prop.load(new FileInputStream(versionFile))
}
else {
prop['VERSION_CODE']='0'
}
public LatLng getLocation() {
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(),"Request permission first!", Toast.LENGTH_LONG).show();
return null;
}
LocationManager locationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(bestProvider);
double lat, lon;
private boolean permissions_ok = false;
private static int LOCATION_PERMISSION_CODE = 100;
public void requestPermission(View view) {
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
permissions_ok = false;
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_PERMISSION_CODE);
}
else {
permissions_ok = true;
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
String s = "";
int counter = 1;
public void addLine(View view) {
TextView tv = findViewById(R.id.test_text);
s = s + "Line " + counter + "<br>";
counter++;
tv.setText(Html.fromHtml(s, Html.FROM_HTML_MODE_LEGACY));
int scrollAmount = tv.getLayout().getLineTop(tv.getLineCount()) - tv.getHeight();
TextView tv = findViewById(R.id.test_text);
tv.setMovementMethod(new ScrollingMovementMethod());
<TextView
android:id="@+id/test_text"
style="?attr/TextViewStyle"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="200dp"
android:background="#504C4C"
@florinmuscalu
florinmuscalu / .html
Created December 5, 2020 15:21
Using Easy Flashcards
[easyfc title="General knowledge" file="flashcards/general_k.txt"/]
@florinmuscalu
florinmuscalu / .json
Created December 5, 2020 15:17
JSON question file
{
"q1":{"q":"2 to the 10th?", "a":"1024"},
"q2":{"q":"Value of PI?", "a":"3.14"}
}
start="aa"
end="cc"
end=$(grep "$end" text.txt | tail -1)
sed -n "/$start/,/$end/p" test.txt