Skip to content

Instantly share code, notes, and snippets.

View dmitriy-chernysh's full-sized avatar
🚀
Building NeonFrame.app

Dmitri Chernysh dmitriy-chernysh

🚀
Building NeonFrame.app
View GitHub Profile
@dmitriy-chernysh
dmitriy-chernysh / PickPhoneNumberActivity.java
Created January 5, 2015 15:49
Pick contact`s phone number (for Android)
public class PickPhoneNumberActivity extends ActionBarActivity {
final int PICK_CONTACT_REQUEST = 1;
//some code
.....
private void pickContact() {
Intent pickContact = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
@dmitriy-chernysh
dmitriy-chernysh / gist:061539eb31ea41539dc8
Last active August 29, 2015 14:14
Android Widget UI Update
public class Widget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
final int countWidgets = appWidgetIds.length;
for (int i = 0; i < countWidgets; i++) {
int appwidgetId = appWidgetIds[i];
@dmitriy-chernysh
dmitriy-chernysh / Alert Dialog
Last active August 29, 2015 14:17
[Android] Alert dialog
public class SampleDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout..... , null);
return new AlertDialog.Builder(getActivity())
.setView(view)
.setTitle(R.string.....)
//set statusbar color for API 21+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getResources().getColor(R.color.primary_dark));
}
@dmitriy-chernysh
dmitriy-chernysh / MainActivity.java
Last active August 29, 2015 14:24
Android AppBar with CoordinatorLayout (hide AppBar when scrolling up)
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
@dmitriy-chernysh
dmitriy-chernysh / ViewPagerAdapter.java
Last active August 29, 2015 14:24
Android ViewPager adapter
package study.android.coordinatorlayout.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.ArrayList;
public class ViewPagerAdapter extends FragmentPagerAdapter {
@dmitriy-chernysh
dmitriy-chernysh / .gitignore
Last active August 29, 2015 14:24
.gitignore for Android Studio projects
.gradle
/local.properties
.DS_Store
/build
.idea
*.txt
*.apk
*.iml
*.properties
@dmitriy-chernysh
dmitriy-chernysh / getActionBarHeight.java
Last active August 29, 2015 14:24
Android getting ActionBar height
/**
* Method for getting height of Actionbar
* @param context Application context
* @return height
*/
public static int getActionBarHeight(Context context){
TypedValue tv = new TypedValue();
if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
{
@dmitriy-chernysh
dmitriy-chernysh / toolbar.xml
Created July 16, 2015 12:14
Android toolbar layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
@dmitriy-chernysh
dmitriy-chernysh / appbar_shadow.xml
Last active August 29, 2015 14:25
Android toolbar / appbar shadow
<?xml version="1.0" encoding="utf-8"?>
<View
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/appbar_elevation"
android:background="@drawable/appbar_shadow"/>