Skip to content

Instantly share code, notes, and snippets.

View MohammadSamandari's full-sized avatar
💭
Android Is SO MUCH FUN

Mohammad Samandari MohammadSamandari

💭
Android Is SO MUCH FUN
View GitHub Profile

AsyncTask

To keep the user experience (UX) running smoothly, the Android framework provides a helper class called AsyncTask, which processes work off of the UI thread. Using AsyncTask to move intensive processing onto a separate thread means that the UI thread can stay responsive.

  • AsyncTask is an abstract class, which means you must subclass it in order to use it

When you create an AsyncTask subclass, you can configure it using these parameters:

  1. Params: The data type of the parameters sent to the task upon executing the doInBackground() override method.
  2. Progress: The data type of the progress units published using the onProgressUpdated() override method.
@MohammadSamandari
MohammadSamandari / Android - Cards and Color.md
Created April 2, 2020 19:55
Android Cardview - Color - Recyclerview -

Cards and Color

Cardview

When presenting information that has mixed media (like images and text), the Material Design guidelines recommend using a CardView, which is a FrameLayout with some extra features (such as elevation and rounded corners) that give it a consistent look and feel across many different applications and platforms. CardView is a UI component found in the Android Support Libraries.

Glide

Using images is resource intensive for your app: the Android framework has to load the entire image into memory at full resolution, even if the app only displays a small thumbnail of the image.

In this section you learn how to use the Glide library to load large images efficiently, without draining your resources or even crashing your app due to 'Out of Memory' exceptions.

@MohammadSamandari
MohammadSamandari / Android-Drawable-Styles-Theme.md
Created April 2, 2020 14:41
Android Drawable and Styles and Theme Creating Dark Theme , Using Styles , Using Selectors and ImageView

Drawable - Styles - Theme

drawable resource

In Android, graphics are often handled by a resource called a Drawable. In the following step you learn how to create a certain type of Drawable called a ShapeDrawable, and apply it to your ImageButton elements as a background.

Create a ShapeDrawable

A ShapeDrawable is a primitive geometric shape defined in an XML file by a number of attributes including color, shape, padding and more. It defines a vector graphic, which can scale up and down without losing any definition.

  1. Choose New > Drawable resource file.

RecyclerView

to show data inside the recyclerview we need the following :

  1. Data to display: Use the mWordList.
  2. A RecyclerView for the scrolling list that contains the list items.
  3. Layout for one item of data. All list items look the same.
  4. A layout manager. RecyclerView.LayoutManager handles the hierarchy and layout of View elements. RecyclerView requires an explicit layout manager to manage the arrangement of list items contained within it. This layout could be vertical, horizontal, or a grid. You will use a vertical LinearLayoutManager.
  5. An adapter. RecyclerView.Adapter connects your data to the RecyclerView. It prepares the data in a RecyclerView.ViewHolder. You will create an adapter that inserts into and updates your generated words in your views.
  6. A ViewHolder. Inside your adapter, you will create a ViewHolder that contains the View information for displaying one item from the item's layout.

To implement these pieces, you will need to:

@MohammadSamandari
MohammadSamandari / Android-NavigationDrawer.md
Created March 31, 2020 17:47
Navigation Drawer - Gradient Color - Menu Resources

Navigation Drawer

A navigation drawer is a panel that usually displays navigation options on the left edge of the screen, as shown on the right side of the figure below. It is hidden most of the time, but is revealed when the user swipes a finger from the left edge of the screen or touches the navigation icon in the app bar

To make a navigation drawer in your app, you need to create the following layouts:

  • A navigation drawer as the Activity layout root ViewGroup.
  • A navigation View for the drawer itself.
  • An app bar layout that will include a navigation icon button.
  • A content layout for the Activity that displays the navigation drawer.
  • A layout for the navigation drawer header.
@MohammadSamandari
MohammadSamandari / Android Navigation (Toolbar - TabLayout - ViewPager - Fragment ).md
Last active March 31, 2020 14:29
User Navigation - Toolbar - Fragment - ViewPager - TabLayout

Navigation

App bar navigation

to declare that a activity is a child of another activity and show the back button in the appbar so that we the user clicks it it goes back to the parent activity we add the following code to the manifest:

android:parentActivityName=".MainActivity">

Toolbar

  • In order to use a Toolbar rather than an app bar and app title,
@MohammadSamandari
MohammadSamandari / Android-Menu-Dialog-Picker-Fragment.md
Created March 30, 2020 22:59
Android ( menu - dialog - Picker - Fragment )

Menus and pickers

Menu

  1. we created a folder in res names menu
  2. we created a menu resource file and designed the menu.
  3. Infiltrate the menu to the activity that we want the menu in
        @Override
        public boolean onCreateOptionsMenu (Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

@MohammadSamandari
MohammadSamandari / Android-Spinner.java
Last active March 30, 2020 21:14
Working With Spinners
// A Spinner provides a drop-down menu:
// Add a Spinner to the layout. Use an ArrayAdapter to assign an array of text values as the Spinner menu items.
// Implement the AdapterView.OnItemSelectedListener interface, which requires also adding the onItemSelected() and
// onNothingSelected() callback methods to activate the Spinner and its listener.
// Use the onItemSelected() callback method to retrieve the selected item in the Spinner menu using getItemAtPosition().
final ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.spinner_values, android.R.layout.simple_spinner_dropdown_item);
final Spinner spinner = findViewById(R.id.spinner);
if (spinner != null) {
@MohammadSamandari
MohammadSamandari / ContextCompat.md
Last active March 30, 2020 20:35
Support Libraries / ContextCompat / Change a color base on the resources proramatically

Support libraries

Android uses three directives to indicate how your app should behave for different API versions:

minSdkVersion: the minimum API version your app supports. compileSdkVersion: the API version your app should be compiled with. targetSdkVersion: the API version your app was designed for.

ContextCompat

get a value from the resources and changing a color base on the colors in the resources:

The ContextCompat class provides methods for compatibility with context and resource-related methods for both old and new API levels.

@MohammadSamandari
MohammadSamandari / Implicit Intent.md
Last active March 30, 2020 00:16
Implicit Intent / Sending Implicit Intent / Receiveing Implicit Intent

Implicit Intent

  • An implicit Intent allows you to activate an Activity if you know the action, but not the specific app or Activity that will handle that action.
  • An Activity that can receive an implicit Intent must define Intent filters in the AndroidManifest.xml file that match one or more Intent actions and categories.
  • The Android system matches the content of an implicit Intent and the Intent filters of any available Activity to determine which Activity to activate. If there is more than one available Activity, the system provides a chooser so the user can pick one.
  • The ShareCompat.IntentBuilder class makes it easy to build an implicit Intent for sharing data to social media or email.

Task 2: Implement the Open Website button

Go to main activity and see the openWebsite function. Note:This Intent constructor is different from the one you used to create an explicit Intent.