Example usage for android.view Gravity START

List of usage examples for android.view Gravity START

Introduction

In this page you can find the example usage for android.view Gravity START.

Prototype

int START

To view the source code for android.view Gravity START.

Click Source Link

Document

Push object to x-axis position at the start of its container, not changing its size.

Usage

From source file:com.android.settings.users.EditUserPhotoController.java

private void showUpdatePhotoPopup() {
    final boolean canTakePhoto = canTakePhoto();
    final boolean canChoosePhoto = canChoosePhoto();

    if (!canTakePhoto && !canChoosePhoto) {
        return;//from  ww  w .ja v a  2s  .  co  m
    }

    final Context context = mImageView.getContext();
    final List<EditUserPhotoController.RestrictedMenuItem> items = new ArrayList<>();

    if (canTakePhoto) {
        final String title = context.getString(R.string.user_image_take_photo);
        final Runnable action = new Runnable() {
            @Override
            public void run() {
                takePhoto();
            }
        };
        items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
    }

    if (canChoosePhoto) {
        final String title = context.getString(R.string.user_image_choose_photo);
        final Runnable action = new Runnable() {
            @Override
            public void run() {
                choosePhoto();
            }
        };
        items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
    }

    final ListPopupWindow listPopupWindow = new ListPopupWindow(context);

    listPopupWindow.setAnchorView(mImageView);
    listPopupWindow.setModal(true);
    listPopupWindow.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
    listPopupWindow.setAdapter(new RestrictedPopupMenuAdapter(context, items));

    final int width = Math.max(mImageView.getWidth(),
            context.getResources().getDimensionPixelSize(R.dimen.update_user_photo_popup_min_width));
    listPopupWindow.setWidth(width);
    listPopupWindow.setDropDownGravity(Gravity.START);

    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopupWindow.dismiss();
            final RestrictedMenuItem item = (RestrictedMenuItem) parent.getAdapter().getItem(position);
            item.doAction();
        }
    });

    listPopupWindow.show();
}

From source file:info.johannblake.shutterstockdemo.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mContext = this;
    mAppTerminating = false;//from   w w  w .  ja  v  a 2s  .co  m

    // Create a cache to store downloaded images.
    CacheSupport.createCache(mContext);

    restoreAppState();

    NavigationDrawerFragment navigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.navigation_drawer);

    // Set up the drawer.
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationDrawerFragment.setUp(R.id.navigation_drawer, mDrawerLayout);

    if (!INCLUDE_NAV_DRAWER)
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));
    toolbar.inflateMenu(R.menu.options_menu);

    mMenuItemSearch = toolbar.getMenu().findItem(R.id.search);
    mSearchView = (SearchView) mMenuItemSearch.getActionView();

    mSearchView.setOnQueryTextListener(queryTextListener);

    // Note: Calling mSearchView.setQuery doesn't set the SearchView's input field
    // probably because the SearchView's layout is inflated each time the search
    // icon is tapped. To set the input field, it has to be done after the
    // button has been tapped. Presumably, the SearchView's layout is inflated at that
    // moment.
    mSearchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mSearchView.setQuery(mQuery, false);
        }
    });

    if (INCLUDE_NAV_DRAWER) {
        // Display the hamburger icon.
        toolbar.setNavigationIcon(R.drawable.ic_hamburger);
    }

    // Handle the user tapping on the hamburger icon.
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (INCLUDE_NAV_DRAWER)
                mDrawerLayout.openDrawer(Gravity.START);
        }
    });

    // Move the toolbar up/down as the user scrolls the recyclerview.
    final LinearLayout llHeader = (LinearLayout) findViewById(R.id.llHeader);

    llHeader.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final CustomRecyclerView rvImages = (CustomRecyclerView) findViewById(R.id.rvImages);
            rvImages.setOverScrollMode(ScrollView.OVER_SCROLL_NEVER);

            rvImages.setY(llHeader.getHeight());
            mJBHeaderScroll = new JBHeaderScroll(llHeader, 0);
            mJBHeaderScroll.registerScroller(rvImages, new JBHeaderScroll.IJBHeaderScroll() {
                @Override
                public void onResize(float top) {
                    ViewGroup.LayoutParams rlLayoutParams = new ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    rvImages.setLayoutParams(rlLayoutParams);
                    rvImages.setY(top);
                    llHeader.bringToFront();
                }

                @Override
                public int onHeaderBeforeAnimation(boolean scrollingUp, float scrollDelta) {
                    return JBHeaderScroll.ANIMATE_HEADER_USE_DEFAULT;
                }

                @Override
                public void onHeaderAfterAnimation(boolean animatedUp, float scrollDelta) {
                }
            });

            rvImages.setJBHeaderRef(mJBHeaderScroll);
            llHeader.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });
}

From source file:de.aw.monma.mainscreen.ActivityMainScreen.java

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    mDrawerLayout.closeDrawer(Gravity.START, false);
    Intent intent = null;/*ww w .j a  v a2 s .  c om*/
    switch (item.getItemId()) {
    case R.id.nav_Convert:
        new ConvertWPIncomeTask(this).execute();
        break;
    case R.id.nav_UnassignedSales:
        intent = new Intent();
        intent.setClass(this, ActivityCash.class);
        intent.putExtra(ACTION, (Parcelable) Action.ShowUnassignedSales);
        intent.putExtra(FROMDATE, new Date(0).getTime());
        intent.putExtra(TODATE, new Date().getTime());
        break;
    case R.id.nav_HBCILog:
        intent = new Intent();
        intent.setClass(this, ActivityHBCIActions.class);
        intent.putExtra(ACTION, (Parcelable) Action.ShowLogFile);
        intent.putExtra(LOGFILE, MonMaApplication.HBCILOGFilename);
        break;
    case R.id.nav_Uebersicht:
        intent = new Intent();
        intent.setClass(this, ActivityActions.class);
        intent.putExtra(ACTION, (Parcelable) Action.ShowUebersicht);
        break;
    case R.id.nav_Cats:
        intent = new Intent();
        intent.setClass(this, ActivityActions.class);
        intent.putExtra(ACTION, (Parcelable) Action.ShowCats);
        break;
    case R.id.nav_Payee:
        intent = new Intent();
        intent.setClass(this, ActivityActions.class);
        intent.putExtra(ACTION, (Parcelable) Action.ShowPayees);
        break;
    case R.id.nav_Wertpapiere:
        intent = new Intent();
        intent.setClass(this, ActivityWertpapiere.class);
        intent.putExtra(ACTION, (Parcelable) Action.ShowWPliste);
        break;
    case R.id.nav_Accounts:
        break;
    case R.id.nav_Settings:
        intent = new Intent();
        intent.setClass(this, MonMaPreferenceActivity.class);
        break;
    default:
        return super.onNavigationItemSelected(item);
    }
    if (intent != null) {
        startActivity(intent);
    }
    return true;
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.app.SimpleDialog.java

private void initMessageView() {
    mMessage = new TextView(getContext());
    mMessage.setTextAppearance(getContext(), mMessageTextAppearanceId);
    mMessage.setTextColor(mMessageTextColor);
    mMessage.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
}

From source file:com.daiv.android.twitter.settings.SettingsActivityOld.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit);

    AppSettings.invalidate();/* ww  w  .j a  v  a2  s .  c o m*/

    setUpTheme();

    setContentView(R.layout.settings_main);

    DrawerArrayAdapter.current = 0;

    linkItems = new String[] { getResources().getString(R.string.get_help_settings),
            getResources().getString(R.string.other_apps), getResources().getString(R.string.whats_new),
            getResources().getString(R.string.rate_it) };

    settingsItems = new String[] { getResources().getString(R.string.ui_settings),
            getResources().getString(R.string.timelines_settings),
            getResources().getString(R.string.sync_settings),
            getResources().getString(R.string.notification_settings),
            getResources().getString(R.string.browser_settings),
            getResources().getString(R.string.advanced_settings),
            getResources().getString(R.string.memory_manage) };

    sharedPrefs = getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    if (sharedPrefs.getBoolean("version_1.20_1", true)) {
        // necessary because i didnt start out by using sets
        boolean led = sharedPrefs.getBoolean("led", true);
        boolean sound = sharedPrefs.getBoolean("sound", true);
        boolean vibrate = sharedPrefs.getBoolean("vibrate", true);
        boolean wakeScreen = sharedPrefs.getBoolean("wake", true);
        boolean timelineNot = sharedPrefs.getBoolean("timeline_notifications", true);
        boolean mentionsNot = sharedPrefs.getBoolean("mentions_notifications", true);
        boolean dmsNot = sharedPrefs.getBoolean("direct_message_notifications", true);
        boolean favoritesNot = sharedPrefs.getBoolean("favorite_notifications", true);
        boolean retweetNot = sharedPrefs.getBoolean("retweet_notifications", true);
        boolean followersNot = sharedPrefs.getBoolean("follower_notifications", true);

        Set<String> alert = sharedPrefs.getStringSet("alert_types", new HashSet<String>());
        alert.clear();
        if (vibrate) {
            alert.add("1");
        }
        if (led) {
            alert.add("2");
        }
        if (wakeScreen) {
            alert.add("3");
        }
        if (sound) {
            alert.add("4");
        }
        sharedPrefs.edit().putStringSet("alert_types", alert).commit();

        Set<String> timeline = sharedPrefs.getStringSet("timeline_set", new HashSet<String>());
        timeline.clear();
        if (timelineNot) {
            timeline.add("1");
        }
        if (mentionsNot) {
            timeline.add("2");
        }
        if (dmsNot) {
            timeline.add("3");
        }
        sharedPrefs.edit().putStringSet("timeline_set", timeline).commit();

        Set<String> interactions = sharedPrefs.getStringSet("interactions_set", new HashSet<String>());
        interactions.clear();
        if (favoritesNot) {
            interactions.add("1");
        }
        if (retweetNot) {
            interactions.add("2");
        }
        if (followersNot) {
            interactions.add("3");
        }
        sharedPrefs.edit().putStringSet("interactions_set", interactions).commit();

        sharedPrefs.edit().putBoolean("version_1.20_1", false).commit();

        recreate();
    }

    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), this, otherList);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);

    otherList = (ListView) findViewById(R.id.other_list);
    settingsList = (ListView) findViewById(R.id.settings_list);
    mDrawer = (LinearLayout) findViewById(R.id.drawer);

    // Set the adapter for the list view
    otherList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(linkItems))));
    settingsList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(settingsItems))));
    // Set the list's click listener
    settingsList.setOnItemClickListener(
            new SettingsDrawerClickListener(this, mDrawerLayout, settingsList, mViewPager, mDrawer));
    otherList.setOnItemClickListener(
            new SettingsLinkDrawerClickListener(this, mDrawerLayout, otherList, mViewPager, mDrawer));

    findViewById(R.id.settingsLinks).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchToSettingsList(true);
            settingsLinksActive = true;
            findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
        }
    });

    findViewById(R.id.otherLinks).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchToSettingsList(false);
            settingsLinksActive = false;
            findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
        }
    });

    if (settingsLinksActive) {
        settingsList.setVisibility(View.VISIBLE);
        otherList.setVisibility(View.GONE);
        findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
    } else {
        settingsList.setVisibility(View.GONE);
        otherList.setVisibility(View.VISIBLE);
        findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
    }

    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon });
    int resource = a.getResourceId(0, 0);
    a.recycle();

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            resource, /* nav drawer icon to replace 'Up' caret */
            R.string.app_name, /* "open drawer" description */
            R.string.app_name /* "close drawer" description */
    );

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    userKnows = sharedPrefs.getBoolean("user_knows_navigation_drawer", false);

    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        public void onPageScrollStateChanged(int state) {
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        public void onPageSelected(int position) {
            DrawerArrayAdapter.current = position;
            otherList.invalidateViews();
            settingsList.invalidateViews();
        }
    });

    if (!userKnows) {
        mDrawerLayout.openDrawer(mDrawer);
    }

    HoloTextView createdBy = (HoloTextView) findViewById(R.id.created_by);
    HoloTextView versionNumber = (HoloTextView) findViewById(R.id.version_number);

    try {
        String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;

        String text = getResources().getString(R.string.created_by) + " daiv";
        String text2 = getResources().getString(R.string.version) + " " + versionName;
        createdBy.setText(text);
        versionNumber.setText(text2);
    } catch (Exception e) {
        String text = getResources().getString(R.string.created_by) + " daiv";
        String text2 = getResources().getString(R.string.version) + " 0.00";
        createdBy.setText(text);
        versionNumber.setText(text2);
    }

    LinearLayout description = (LinearLayout) findViewById(R.id.created_by_layout);
    description.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/developer?id=daiv+Apps")));
        }
    });

    mDrawerLayout.openDrawer(Gravity.START);
}

From source file:ti.modules.titanium.ui.widget.TiUIDrawerLayout.java

public void toggleLeft() {
    if (layout.isDrawerOpen(Gravity.START)) {
        closeLeft();
    } else {
        openLeft();
    }
}

From source file:com.cryart.sabbathschool.ui.activity.SSMainActivity.java

@Override
public void onBackPressed() {
    if (_SSDrawerLayout.isDrawerOpen(Gravity.START)) {
        _SSDrawerLayout.closeDrawer(Gravity.START);
    } else {//from   w w w.j  ava  2 s  . c  o  m
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}

From source file:com.klinker.android.twitter.settings.SettingsActivityOld.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit);

    AppSettings.invalidate();/*from  w  ww .  j a  v  a2s.  co m*/

    setUpTheme();

    setContentView(R.layout.settings_main);

    DrawerArrayAdapter.current = 0;

    linkItems = new String[] { getResources().getString(R.string.get_help_settings),
            getResources().getString(R.string.other_apps), getResources().getString(R.string.whats_new),
            getResources().getString(R.string.rate_it) };

    settingsItems = new String[] { getResources().getString(R.string.ui_settings),
            getResources().getString(R.string.timelines_settings),
            getResources().getString(R.string.sync_settings),
            getResources().getString(R.string.notification_settings),
            getResources().getString(R.string.browser_settings),
            getResources().getString(R.string.advanced_settings),
            getResources().getString(R.string.memory_manage) };

    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    if (sharedPrefs.getBoolean("version_1.20_1", true)) {
        // necessary because i didnt start out by using sets
        boolean led = sharedPrefs.getBoolean("led", true);
        boolean sound = sharedPrefs.getBoolean("sound", true);
        boolean vibrate = sharedPrefs.getBoolean("vibrate", true);
        boolean wakeScreen = sharedPrefs.getBoolean("wake", true);
        boolean timelineNot = sharedPrefs.getBoolean("timeline_notifications", true);
        boolean mentionsNot = sharedPrefs.getBoolean("mentions_notifications", true);
        boolean dmsNot = sharedPrefs.getBoolean("direct_message_notifications", true);
        boolean favoritesNot = sharedPrefs.getBoolean("favorite_notifications", true);
        boolean retweetNot = sharedPrefs.getBoolean("retweet_notifications", true);
        boolean followersNot = sharedPrefs.getBoolean("follower_notifications", true);

        Set<String> alert = sharedPrefs.getStringSet("alert_types", new HashSet<String>());
        alert.clear();
        if (vibrate) {
            alert.add("1");
        }
        if (led) {
            alert.add("2");
        }
        if (wakeScreen) {
            alert.add("3");
        }
        if (sound) {
            alert.add("4");
        }
        sharedPrefs.edit().putStringSet("alert_types", alert).commit();

        Set<String> timeline = sharedPrefs.getStringSet("timeline_set", new HashSet<String>());
        timeline.clear();
        if (timelineNot) {
            timeline.add("1");
        }
        if (mentionsNot) {
            timeline.add("2");
        }
        if (dmsNot) {
            timeline.add("3");
        }
        sharedPrefs.edit().putStringSet("timeline_set", timeline).commit();

        Set<String> interactions = sharedPrefs.getStringSet("interactions_set", new HashSet<String>());
        interactions.clear();
        if (favoritesNot) {
            interactions.add("1");
        }
        if (retweetNot) {
            interactions.add("2");
        }
        if (followersNot) {
            interactions.add("3");
        }
        sharedPrefs.edit().putStringSet("interactions_set", interactions).commit();

        sharedPrefs.edit().putBoolean("version_1.20_1", false).commit();

        recreate();
    }

    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), this, otherList);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);

    otherList = (ListView) findViewById(R.id.other_list);
    settingsList = (ListView) findViewById(R.id.settings_list);
    mDrawer = (LinearLayout) findViewById(R.id.drawer);

    // Set the adapter for the list view
    otherList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(linkItems))));
    settingsList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(settingsItems))));
    // Set the list's click listener
    settingsList.setOnItemClickListener(
            new SettingsDrawerClickListener(this, mDrawerLayout, settingsList, mViewPager, mDrawer));
    otherList.setOnItemClickListener(
            new SettingsLinkDrawerClickListener(this, mDrawerLayout, otherList, mViewPager, mDrawer));

    findViewById(R.id.settingsLinks).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchToSettingsList(true);
            settingsLinksActive = true;
            findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
        }
    });

    findViewById(R.id.otherLinks).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchToSettingsList(false);
            settingsLinksActive = false;
            findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
        }
    });

    if (settingsLinksActive) {
        settingsList.setVisibility(View.VISIBLE);
        otherList.setVisibility(View.GONE);
        findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
    } else {
        settingsList.setVisibility(View.GONE);
        otherList.setVisibility(View.VISIBLE);
        findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
    }

    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon });
    int resource = a.getResourceId(0, 0);
    a.recycle();

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            resource, /* nav drawer icon to replace 'Up' caret */
            R.string.app_name, /* "open drawer" description */
            R.string.app_name /* "close drawer" description */
    );

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    userKnows = sharedPrefs.getBoolean("user_knows_navigation_drawer", false);

    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        public void onPageScrollStateChanged(int state) {
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        public void onPageSelected(int position) {
            DrawerArrayAdapter.current = position;
            otherList.invalidateViews();
            settingsList.invalidateViews();
        }
    });

    if (!userKnows) {
        mDrawerLayout.openDrawer(mDrawer);
    }

    HoloTextView createdBy = (HoloTextView) findViewById(R.id.created_by);
    HoloTextView versionNumber = (HoloTextView) findViewById(R.id.version_number);

    try {
        String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;

        String text = getResources().getString(R.string.created_by) + " Luke Klinker";
        String text2 = getResources().getString(R.string.version) + " " + versionName;
        createdBy.setText(text);
        versionNumber.setText(text2);
    } catch (Exception e) {
        String text = getResources().getString(R.string.created_by) + " Luke Klinker";
        String text2 = getResources().getString(R.string.version) + " 0.00";
        createdBy.setText(text);
        versionNumber.setText(text2);
    }

    LinearLayout description = (LinearLayout) findViewById(R.id.created_by_layout);
    description.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/developer?id=Klinker+Apps")));
        }
    });

    mDrawerLayout.openDrawer(Gravity.START);
}

From source file:com.tooltip.Tooltip.java

private View getContentView(Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);

    int padding = (int) builder.mPadding;

    TextView textView = new TextView(builder.mContext);
    TextViewCompat.setTextAppearance(textView, builder.mTextAppearance);
    textView.setText(builder.mText);//from   www  . j  av a 2 s . c  o m
    textView.setPadding(padding, padding, padding, padding);
    textView.setLineSpacing(builder.mLineSpacingExtra, builder.mLineSpacingMultiplier);
    textView.setTypeface(builder.mTypeface, builder.mTextStyle);

    if (builder.mTextSize >= 0) {
        textView.setTextSize(TypedValue.TYPE_NULL, builder.mTextSize);
    }
    if (builder.mTextColor != null) {
        textView.setTextColor(builder.mTextColor);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        textView.setBackground(drawable);
    } else {
        //noinspection deprecation
        textView.setBackgroundDrawable(drawable);
    }

    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textView.setLayoutParams(textViewParams);

    mArrowView = new ImageView(builder.mContext);
    mArrowView.setImageDrawable(builder.mArrowDrawable);

    LinearLayout.LayoutParams arrowLayoutParams;
    if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight,
                0);
    } else {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth,
                0);
    }
    arrowLayoutParams.gravity = Gravity.CENTER;
    mArrowView.setLayoutParams(arrowLayoutParams);

    mContentView = new LinearLayout(builder.mContext);
    mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    padding = (int) Util.dpToPx(5);

    switch (mGravity) {
    case Gravity.START:
        mContentView.setPadding(0, 0, padding, 0);
        break;
    case Gravity.TOP:
    case Gravity.BOTTOM:
        mContentView.setPadding(padding, 0, padding, 0);
        break;
    case Gravity.END:
        mContentView.setPadding(padding, 0, 0, 0);
        break;
    }

    if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
        mContentView.addView(textView);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(textView);
    }

    mContentView.setOnClickListener(mClickListener);
    mContentView.setOnLongClickListener(mLongClickListener);

    if (builder.isCancelable || builder.isDismissOnClick) {
        mContentView.setOnTouchListener(mTouchListener);
    }
    return mContentView;
}

From source file:eu.faircode.adblocker.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
    Util.logExtras(getIntent());/*  w ww . j  a v  a2s  .c  o  m*/

    if (Build.VERSION.SDK_INT < MIN_SDK) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.android);
        return;
    }

    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    swEnabled = (SwitchCompat) findViewById(R.id.swEnabled);
    running = true;

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = prefs.getBoolean("enabled", false);
    boolean initialized = prefs.getBoolean("initialized", false);

    // Upgrade
    Receiver.upgrade(initialized, this);

    if (!getIntent().hasExtra(EXTRA_APPROVE)) {
        if (enabled)
            ServiceSinkhole.start("UI", this);
        else
            ServiceSinkhole.stop("UI", this);
    }

    // Action bar
    final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false);
    ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon);
    ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue);

    ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered);

    // Icon
    ivIcon.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            menu_about();
            return true;
        }
    });

    // Title
    getSupportActionBar().setTitle(null);

    // Netguard is busy
    ivQueue.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.START, location[0] + ivQueue.getLeft(),
                    Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    // On/off switch
    swEnabled.setChecked(enabled);
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Log.i(TAG, "Switch=" + isChecked);
            prefs.edit().putBoolean("enabled", isChecked).apply();

            if (isChecked) {
                try {
                    final Intent prepare = VpnService.prepare(ActivityMain.this);
                    if (prepare == null) {
                        Log.i(TAG, "Prepare done");
                        onActivityResult(REQUEST_VPN, RESULT_OK, null);
                    } else {
                        // Show dialog
                        LayoutInflater inflater = LayoutInflater.from(ActivityMain.this);
                        View view = inflater.inflate(R.layout.vpn, null, false);
                        dialogVpn = new AlertDialog.Builder(ActivityMain.this).setView(view)
                                .setCancelable(false)
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (running) {
                                            Log.i(TAG, "Start intent=" + prepare);
                                            try {
                                                startActivityForResult(prepare, REQUEST_VPN);
                                            } catch (Throwable ex) {
                                                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                                                Util.sendCrashReport(ex, ActivityMain.this);
                                                onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
                                                prefs.edit().putBoolean("enabled", false).apply();
                                            }
                                        }
                                    }
                                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        dialogVpn = null;
                                    }
                                }).create();
                        dialogVpn.show();
                    }
                } catch (Throwable ex) {
                    // Prepare failed
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    Util.sendCrashReport(ex, ActivityMain.this);
                    prefs.edit().putBoolean("enabled", false).apply();
                }

            } else
                ServiceSinkhole.stop("switch off", ActivityMain.this);
        }
    });
    if (enabled)
        checkDoze();

    // Network is metered
    ivMetered.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.START, location[0] + ivMetered.getLeft(),
                    Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(actionView);

    // Disabled warning
    TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
    tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);

    // Application list
    //        RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
    //        rvApplication.setHasFixedSize(true);
    //        rvApplication.setLayoutManager(new LinearLayoutManager(this));
    //        adapter = new AdapterRule(this);
    //        rvApplication.setAdapter(adapter);

    // Swipe to refresh
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    //        swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
    //        swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
    //        swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data);
    //        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    //            @Override
    //            public void onRefresh() {
    //                Rule.clearCache(ActivityMain.this);
    //                ServiceSinkhole.reload("pull", ActivityMain.this);
    //                updateApplicationList(null);
    //            }
    //        });

    // Listen for preference changes
    prefs.registerOnSharedPreferenceChangeListener(this);

    // Listen for rule set changes
    IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr);

    // Listen for queue changes
    IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq);

    // Listen for added/removed applications
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    registerReceiver(packageChangedReceiver, intentFilter);

    // First use
    if (!initialized) {
        // Create view
        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.first, null, false);
        TextView tvFirst = (TextView) view.findViewById(R.id.tvFirst);
        tvFirst.setMovementMethod(LinkMovementMethod.getInstance());

        // Show dialog
        dialogFirst = new AlertDialog.Builder(this).setView(view).setCancelable(false)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            prefs.edit().putBoolean("initialized", true).apply();
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            finish();
                    }
                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        dialogFirst = null;
                    }
                }).create();
        dialogFirst.show();
    }

    // Fill application list
    updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH));

    // Update IAB SKUs
    try {
        iab = new IAB(new IAB.Delegate() {
            @Override
            public void onReady(IAB iab) {
                try {
                    iab.updatePurchases();

                    if (!IAB.isPurchased(ActivityPro.SKU_LOG, ActivityMain.this))
                        prefs.edit().putBoolean("log", false).apply();
                    if (!IAB.isPurchased(ActivityPro.SKU_THEME, ActivityMain.this)) {
                        if (!"teal".equals(prefs.getString("theme", "teal")))
                            prefs.edit().putString("theme", "teal").apply();
                    }
                    if (!IAB.isPurchased(ActivityPro.SKU_SPEED, ActivityMain.this))
                        prefs.edit().putBoolean("show_stats", false).apply();
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                } finally {
                    iab.unbind();
                }
            }
        }, this);
        iab.bind();
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    checkExtras(getIntent());
}