Skip to content

Instantly share code, notes, and snippets.

View alidaoud's full-sized avatar
🎯
Focusing

Ali Daoud alidaoud

🎯
Focusing
View GitHub Profile
@alidaoud
alidaoud / ThumbnailUrlExtractor.java
Created July 24, 2020 16:44
class creates a thumbnail url of a youtube video using its youtube url
/**
* this class creates a thumbnail url of a youtube video using its url
*
* supports the below link formats:
* => the original format of the youtube url e.g. https://www.youtube.com/watch?v=<watchId>&feature=youtu.be
* => the shortcut format of the youtube url e.g. https://youtu.be/<watchId>
*/
public class ThumbnailUrlExtractor {
private static final String LINK_FORMAT_1 = "watch?v=";
private static void hideKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
View view = activity.getCurrentFocus();
if (view == null) {
view = new View(activity);
}
if (inputMethodManager != null){
@alidaoud
alidaoud / start a list view from specific item position.java
Created September 1, 2019 12:48
start displaying a list-view from a specific item position
//This line will select n row starting from top
listview.setSelectionFromTop(n, 0);
@alidaoud
alidaoud / getting boolean value from sqlite database.java
Created August 30, 2019 18:15
getting a boolean value from an SQLite database and store it into a local variable
boolean value = cursor.getInt(boolean_column_index) > 0;
//If you are using an ActionBarActivity then you can tell Android to use the Toolbar as the ActionBar like so:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
//And now to make sure that the back arrow is gonna show
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //or for fragments //((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true); //or for fragments //((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayShowHomeEnabled(true);
<!-- considering that we need 2 lines at most -->
android:maxLines="2"
android:ellipsize="end"
@alidaoud
alidaoud / adding dots for text view.xml
Created May 26, 2019 18:07
providing dots for the extra text in the textView after reaching the limit that have been specified
<!-- considering that we need 2 lines at most -->
android:maxLines="2"
android:ellipsize="end"
@alidaoud
alidaoud / Set view dim programmatically.java
Created May 26, 2019 16:31
Set view width & height programmatically
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point(); //we're using this because the display.getWidth() is deprecated
display.getSize(size);
int viewWidth = size.x / 2;
int viewHeight = size.y / 3;
View ourView = findViewById(R.id.our_view_id);
@alidaoud
alidaoud / non clickable list item.java
Created May 24, 2019 19:28
making an item in a list view non clickable in Android
view.setEnabled(false);
view.setOnClickListener(null);
public class MyApplication extends Application {
private static Context context;
public void onCreate() {
super.onCreate();
MyApplication.context = getApplicationContext();
}
public static Context getAppContext() {