Example usage for android.widget TextView setClickable

List of usage examples for android.widget TextView setClickable

Introduction

In this page you can find the example usage for android.widget TextView setClickable.

Prototype

public void setClickable(boolean clickable) 

Source Link

Document

Enables or disables click events for this view.

Usage

From source file:com.tune.news.fragment.EntriesListFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true);

    if (mEntriesCursorAdapter != null) {
        setListAdapter(mEntriesCursorAdapter);
    }/*from   www.j a va2 s . co m*/

    mListView = (ListView) rootView.findViewById(android.R.id.list);
    mListView.setFastScrollEnabled(true);
    //        mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext()));

    if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) {
        final TextView header = new TextView(mListView.getContext());
        header.setMinimumHeight(UiUtils.dpToPixel(70));
        int footerPadding = UiUtils.dpToPixel(10);
        header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding);
        header.setText(R.string.tip_sentence);
        header.setGravity(Gravity.CENTER_VERTICAL);
        header.setCompoundDrawablePadding(UiUtils.dpToPixel(5));
        header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_about, 0,
                R.drawable.ic_action_cancel, 0);
        header.setClickable(true);
        header.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListView.removeHeaderView(header);
                PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false);
            }
        });
        mListView.addHeaderView(header);
    }

    UiUtils.addEmptyFooterView(mListView, 90);

    mHideReadButton = (FloatingActionButton) rootView.findViewById(R.id.hide_read_button);
    mHideReadButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            UiUtils.displayHideReadButtonAction(mListView.getContext());
            return true;
        }
    });
    UiUtils.updateHideReadButton(mHideReadButton);

    mRefreshListBtn = (Button) rootView.findViewById(R.id.refreshListBtn);
    mRefreshListBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mNewEntriesNumber = 0;
            mListDisplayDate = new Date().getTime();

            refreshUI();
            if (mUri != null) {
                restartLoaders();
            }
        }
    });

    mSearchView = (SearchView) rootView.findViewById(R.id.searchView);
    if (savedInstanceState != null) {
        refreshUI(); // To hide/show the search bar
    }

    mSearchView.post(new Runnable() { // Do this AFTER the text has been restored from saveInstanceState
        @Override
        public void run() {
            mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String s) {
                    setData(EntryColumns.SEARCH_URI(s), true);
                    return false;
                }
            });
        }
    });

    disableSwipe();

    return rootView;
}

From source file:com.viktorrudometkin.burramys.fragment.EntriesListFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true);

    if (mEntriesCursorAdapter != null) {
        setListAdapter(mEntriesCursorAdapter);
    }/*ww w  . j a  v a2 s .c  o  m*/

    mListView = (ListView) rootView.findViewById(android.R.id.list);
    mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext()));

    if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) {
        final TextView header = new TextView(mListView.getContext());
        header.setMinimumHeight(UiUtils.dpToPixel(70));
        int footerPadding = UiUtils.dpToPixel(10);
        header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding);
        header.setText(R.string.tip_sentence);
        header.setGravity(Gravity.CENTER_VERTICAL);
        header.setCompoundDrawablePadding(UiUtils.dpToPixel(5));
        header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_about, 0,
                R.drawable.ic_action_cancel, 0);
        header.setClickable(true);
        header.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListView.removeHeaderView(header);
                PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false);
            }
        });
        mListView.addHeaderView(header);
    }

    UiUtils.addEmptyFooterView(mListView, 90);

    mRefreshListBtn = (Button) rootView.findViewById(R.id.refreshListBtn);
    mRefreshListBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mNewEntriesNumber = 0;
            mListDisplayDate = new Date().getTime();

            refreshUI();
            if (mCurrentUri != null) {
                restartLoaders();
            }
        }
    });

    disableSwipe();

    return rootView;
}

From source file:com.google.android.apps.santatracker.launch.TvStartupActivity.java

private void addDebugMenuListRaw(ArrayObjectAdapter objectAdapter) {

    mMarkers.setPadding(mMarkers.getPaddingLeft(), mMarkers.getPaddingTop() + 150, mMarkers.getPaddingRight(),
            mMarkers.getPaddingBottom());

    Presenter debugMenuPresenter = new Presenter() {
        @Override/*  ww w  . ja v a2 s .  c om*/
        public ViewHolder onCreateViewHolder(ViewGroup parent) {
            TextView tv = new TextView(parent.getContext());
            ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(200, 150);
            tv.setLayoutParams(params);
            tv.setGravity(Gravity.CENTER);
            tv.setBackgroundColor(getResources().getColor(R.color.SantaBlueDark));
            tv.setFocusableInTouchMode(false);
            tv.setFocusable(true);
            tv.setClickable(true);
            return new ViewHolder(tv);
        }

        @Override
        public void onBindViewHolder(ViewHolder viewHolder, Object item) {
            ((TextView) viewHolder.view).setText((String) item);
            viewHolder.view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final String text = ((TextView) v).getText().toString();
                    if (text.contains("Enable Tracker")) {
                        enableTrackerMode(true);
                    } else if (text.contains("Enable CountDown")) {
                        startCountdown(SantaPreferences.getCurrentTime());
                    } else {
                        mIsDebug = false;
                        initialiseViews();
                        resetLauncherStates();
                    }
                }
            });
        }

        @Override
        public void onUnbindViewHolder(ViewHolder viewHolder) {

        }
    };

    ObjectAdapter debugMenuAdapter = new ObjectAdapter(debugMenuPresenter) {

        private final String[] mMenuString = { "Enable Tracker", "Enable CountDown", "Hide DebugMenu" };

        @Override
        public int size() {
            return mMenuString.length;
        }

        @Override
        public Object get(int position) {
            return mMenuString[position];
        }
    };

    ListRow debugMenuListRow = new ListRow(debugMenuAdapter);
    objectAdapter.add(debugMenuListRow);
}

From source file:com.cairoconfessions.MainActivity.java

public void addLocation(View view) {
    TextView newView = new TextView(this);
    AutoCompleteTextView addLoc = ((AutoCompleteTextView) findViewById(R.id.addLocation));
    String newLoc = addLoc.getText().toString();
    ViewGroup locList = ((ViewGroup) findViewById(R.id.locations));
    boolean notFound = true;
    for (int i = 0; i < locList.getChildCount(); i++) {
        if (newLoc.equals(((TextView) locList.getChildAt(i)).getText().toString()))
            notFound = false;/*w  w w . j  av a2 s . c  o  m*/
        break;
    }
    if (Arrays.asList(COUNTRIES).contains(newLoc) && notFound) {
        newView.setText(newLoc);
        newView.setClickable(true);
        newView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                addItem(view);
            }
        });
        float scale = getResources().getDisplayMetrics().density;
        newView.setGravity(17);
        newView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);

        newView.setBackgroundResource(R.drawable.city2);

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                (int) (150 * scale));
        lp.setMargins((int) (0 * scale), (int) (0 * scale), (int) (0 * scale), (int) (2 * scale));
        newView.setLayoutParams(lp);
        locList.addView(newView, 0);
        addLoc.setText("");
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(addLoc.getWindowToken(), 0);
        addLoc.setCursorVisible(false);

    } else {
        Toast.makeText(this, "Invalid location", Toast.LENGTH_LONG).show();
    }
}

From source file:hu.fnf.devel.atlas.Atlas.java

private void addChilds(View parent, LinearLayout pll) {
    Uri.Builder builder = new Builder();
    builder.scheme("content");
    builder.authority(AtlasData.DB_AUTHORITY);
    builder.appendPath(AtlasData.TABLE_CATEGORIES);
    builder.appendPath("childs");
    builder.appendPath(String.valueOf(parent.getId()));

    Cursor items = getContentResolver().query(builder.build(), AtlasData.CATEGORIES_COLUMNS, null, null, null);

    if (items != null && items.moveToFirst()) {
        LinearLayout ll = null;//ww w  .j  a  va 2  s  . c  om
        do {
            ll = new LinearLayout(getApplicationContext());
            LayoutParams llp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            ll.setLayoutParams(llp);
            TextView child = new TextView(getApplicationContext());
            child.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_Medium_Inverse);

            ll.setId(items.getInt(AtlasData.CATEGORIES_ID));
            child.setId(items.getInt(AtlasData.CATEGORIES_ID));
            child.setText(items.getString(AtlasData.CATEGORIES_NAME));
            for (int i = 0; i < AtlasData.MAX_CAT_DEPTH - items.getInt(AtlasData.CATEGORIES_DEPTH); i++) {
                TextView holder = new TextView(getApplicationContext());
                holder.setText("        ");
                ll.addView(holder);
            }

            child.setClickable(true);

            Log.d("Atlas", "build to ll: " + child.getText().toString());
            ll.addView(child);

            ll.setOnClickListener(onCatClick);
            child.setOnClickListener(onCatClick);

            View line = new View(getApplicationContext());

            line.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1));
            line.setBackgroundColor(Color.GRAY);

            pll.addView(line);
            pll.addView(ll);
            Log.d("Atlas", "build to pll: " + ll.getId());

            addChilds(child, pll);
        } while (items.moveToNext());
        items.close();
    } else {
        // no more kids
        return;
    }
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

private void handleIntent(final Intent intent) {
    if ((intent == null) || (intent.getAction() == null)) {
        Log.d(MainActivity.TAG, "action null");
    } else if (DefinitionsHelper.SHOW_TASK.equals(intent.getAction())
            || DefinitionsHelper.SHOW_TASK_REMINDER.equals(intent.getAction())
            || DefinitionsHelper.SHOW_TASK_FROM_WIDGET.equals(intent.getAction())) {
        final Optional<Task> task = TaskHelper.getTaskFromIntent(intent);
        if (task.isPresent()) {
            this.currentList = task.get().getList();
            if (this.mDrawerLayout != null) {
                this.mDrawerLayout.postDelayed(new Runnable() {
                    @Override/*from   ww w.jav a2  s  .c  o  m*/
                    public void run() {
                        setCurrentTask(task.get(), true);
                    }
                }, 10L);
            }
        } else {
            Log.d(MainActivity.TAG, "task null");
        }
        if (intent.getAction().equals(DefinitionsHelper.SHOW_TASK_FROM_WIDGET)) {
            this.closeOnBack = true;
        }
    } else if (intent.getAction().equals(Intent.ACTION_SEND)
            || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
        this.closeOnBack = true;
        this.newTaskContent = intent.getStringExtra(Intent.EXTRA_TEXT);
        this.newTaskSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        // If from google now, the content is the subject
        if ((intent.getCategories() != null)
                && intent.getCategories().contains("com.google.android.voicesearch.SELF_NOTE")
                && !this.newTaskContent.isEmpty()) {
            this.newTaskSubject = this.newTaskContent;
            this.newTaskContent = "";
        }
        if (!"text/plain".equals(intent.getType()) && (this.newTaskSubject == null)) {
            this.newTaskSubject = MirakelCommonPreferences.getImportFileTitle();
        }
        final Optional<ListMirakel> listFromSharing = MirakelModelPreferences.getImportDefaultList();
        if (listFromSharing.isPresent()) {
            addTaskFromSharing(listFromSharing.get(), intent);
        } else {
            final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.import_to);
            final List<CharSequence> items = new ArrayList<>();
            final List<Long> list_ids = new ArrayList<>();
            final int currentItem = 0;
            for (final ListMirakel list : ListMirakel.all()) {
                if (list.getId() > 0) {
                    items.add(list.getName());
                    list_ids.add(list.getId());
                }
            }
            builder.setSingleChoiceItems(items.toArray(new CharSequence[items.size()]), currentItem,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(final DialogInterface dialog, final int which) {
                            final Optional<ListMirakel> listMirakelOptional = ListMirakel
                                    .get(list_ids.get(which));
                            withOptional(listMirakelOptional, new OptionalUtils.Procedure<ListMirakel>() {
                                @Override
                                public void apply(final ListMirakel input) {
                                    addTaskFromSharing(input, intent);
                                    dialog.dismiss();
                                }
                            });
                        }
                    });
            builder.create().show();
        }
    } else if (intent.getAction().equals(DefinitionsHelper.SHOW_LIST)
            || intent.getAction().contains(DefinitionsHelper.SHOW_LIST_FROM_WIDGET)) {
        final Optional<ListMirakel> listMirakelOptional = ListHelper.getListMirakelFromIntent(intent);
        if (listMirakelOptional.isPresent()) {
            final ListMirakel list = listMirakelOptional.get();
            setCurrentList(list);
            final Optional<Task> taskOptional = list.getFirstTask();
            if (taskOptional.isPresent()) {
                this.currentTask = taskOptional.get();
            }
            if (getTaskFragment() != null) {
                getTaskFragment().update(this.currentTask);
            }
        } else {
            Log.d(TAG, "show_list does not pass list, so ignore this");
        }
    } else if (intent.getAction().equals(DefinitionsHelper.SHOW_LISTS)) {
        this.mDrawerLayout.openDrawer(DefinitionsHelper.GRAVITY_LEFT);
    } else if (intent.getAction().equals(Intent.ACTION_SEARCH)) {
        final String query = intent.getStringExtra(SearchManager.QUERY);
        search(query);
    } else if (intent.getAction().contains(DefinitionsHelper.ADD_TASK_FROM_WIDGET)) {
        final int listId = Integer
                .parseInt(intent.getAction().replace(DefinitionsHelper.ADD_TASK_FROM_WIDGET, ""));
        final Optional<ListMirakel> listMirakelOptional = ListMirakel.get(listId);
        if (listMirakelOptional.isPresent()) {
            setCurrentList(listMirakelOptional.get());
        } else {
            setCurrentList(ListMirakel.safeFirst());
        }
        this.mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                if ((getTasksFragment() != null) && getTasksFragment().isReady()) {
                    getTasksFragment().focusNew(true);
                } else if (!MirakelCommonPreferences.isTablet()) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (getTasksFragment() != null) {
                                getTasksFragment().focusNew(true);
                            } else {
                                Log.wtf(MainActivity.TAG, "Tasksfragment null");
                            }
                        }
                    });
                }
            }
        }, 10);
    } else if (intent.getAction().equals(DefinitionsHelper.SHOW_MESSAGE)) {
        final String message = intent.getStringExtra(Intent.EXTRA_TEXT);
        String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        if (message != null) {
            if (subject == null) {
                subject = getString(R.string.message_notification);
            }
            final TextView msg = (TextView) getLayoutInflater().inflate(R.layout.alertdialog_textview, null);
            msg.setText(Html.fromHtml(message));
            msg.setMovementMethod(LinkMovementMethod.getInstance());
            msg.setClickable(true);
            new AlertDialog.Builder(this).setTitle(subject).setView(msg).show();
        }
    } else {
        setCurrentItem(getTaskFragmentPosition());
    }
    if (((intent == null) || (intent.getAction() == null)
            || !intent.getAction().contains(DefinitionsHelper.ADD_TASK_FROM_WIDGET))
            && (getTasksFragment() != null)) {
        getTasksFragment().clearFocus();
    }
    setIntent(null);
    if (this.currentList == null) {
        setCurrentList(SpecialList.firstSpecialSafe());
    }
}

From source file:gc.david.dfm.ui.MainActivity.java

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

    Mint.initAndStartSession(MainActivity.this, "6f2149e6");
    // Enable logging
    Mint.enableLogging(true);/*ww  w  . j a  va 2  s.  co  m*/
    Mint.leaveBreadcrumb("MainActivity::onCreate");

    setContentView(R.layout.activity_main);
    inject(this);

    DEVICE_DENSITY = getResources().getDisplayMetrics().density;

    googleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API)
            .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();

    final SupportMapFragment fragment = ((SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map));
    googleMap = fragment.getMap();

    if (googleMap != null) {
        googleMap.setMyLocationEnabled(true);
        googleMap.getUiSettings().setZoomControlsEnabled(true);
        googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

        // InMobi Ads
        InMobi.initialize(this, "9b61f509a1454023b5295d8aea4482c2");
        banner = (IMBanner) findViewById(R.id.banner);
        if (banner != null) {
            // Si no hay red el banner no carga ni aunque est vaco
            banner.setRefreshInterval(30);
            banner.setIMBannerListener(new IMBannerListener() {
                @Override
                public void onShowBannerScreen(IMBanner arg0) {
                    Mint.leaveBreadcrumb("MainActivity::banner onShowBannerScreen");
                }

                @Override
                public void onLeaveApplication(IMBanner arg0) {
                    Mint.leaveBreadcrumb("MainActivity::banner onLeaveApplication");
                }

                @Override
                public void onDismissBannerScreen(IMBanner arg0) {
                    Mint.leaveBreadcrumb("MainActivity::banner onDismissBannerScreen");
                }

                @Override
                public void onBannerRequestSucceeded(IMBanner arg0) {
                    Mint.leaveBreadcrumb("MainActivity::banner onBannerRequestSucceeded");
                    bannerShown = true;
                    fixMapPadding();
                }

                @Override
                public void onBannerRequestFailed(IMBanner arg0, IMErrorCode arg1) {
                    Mint.leaveBreadcrumb("MainActivity::banner onBannerRequestFailed");
                }

                @Override
                public void onBannerInteraction(IMBanner arg0, Map<String, String> arg1) {
                    Mint.leaveBreadcrumb("MainActivity::banner onBannerInteraction");
                    Mint.logEvent("Ad tapped");
                }
            });
            banner.loadBanner();
        }

        if (!isOnline(getApplicationContext())) {
            showWifiAlertDialog();
        }

        googleMap.setOnMapLongClickListener(new OnMapLongClickListener() {
            @Override
            public void onMapLongClick(LatLng point) {
                Mint.leaveBreadcrumb("MainActivity::googleMap onMapLongClick");
                calculatingDistance = true;

                if (distanceMode == DistanceMode.DISTANCE_FROM_ANY_POINT) {
                    if (coordinates == null || coordinates.isEmpty()) {
                        toastIt(getString(R.string.toast_first_point_needed), getApplicationContext());
                    } else {
                        coordinates.add(point);
                        drawAndShowMultipleDistances(coordinates, "", false, true);
                    }
                }
                // Si no hemos encontrado la posicin actual, no podremos
                // calcular la distancia
                else if (currentLocation != null) {
                    if ((distanceMode == DistanceMode.DISTANCE_FROM_CURRENT_POINT) && (coordinates.isEmpty())) {
                        coordinates
                                .add(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()));
                    }
                    coordinates.add(point);
                    drawAndShowMultipleDistances(coordinates, "", false, true);
                }

                calculatingDistance = false;
            }
        });

        googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng point) {
                Mint.leaveBreadcrumb("MainActivity::googleMap onMapClick");
                if (distanceMode == DistanceMode.DISTANCE_FROM_ANY_POINT) {
                    if (!calculatingDistance) {
                        coordinates.clear();
                    }

                    calculatingDistance = true;

                    if (coordinates.isEmpty()) {
                        googleMap.clear();
                    }
                    coordinates.add(point);
                    googleMap.addMarker(new MarkerOptions().position(point));
                } else {
                    // Si no hemos encontrado la posicin actual, no podremos
                    // calcular la distancia
                    if (currentLocation != null) {
                        if (coordinates != null) {
                            if (!calculatingDistance) {
                                coordinates.clear();
                            }
                            calculatingDistance = true;

                            if (coordinates.isEmpty()) {
                                googleMap.clear();
                                coordinates.add(new LatLng(currentLocation.getLatitude(),
                                        currentLocation.getLongitude()));
                            }
                            coordinates.add(point);
                            googleMap.addMarker(new MarkerOptions().position(point));
                        } else {
                            final IllegalStateException illegalStateException = new IllegalStateException(
                                    "Empty coordinates list");
                            Mint.logException(illegalStateException);
                            throw illegalStateException;
                        }
                    }
                }
            }
        });

        // TODO Future release
        // Cambiar esto: debera modificar solamentela posicin que estemos tuneando y recalcular
        //         googleMap.setOnMarkerDragListener(new OnMarkerDragListener() {
        ////            private String selectedMarkerId;
        //
        //            @Override
        //            public void onMarkerDragStart(Marker marker) {
        ////               selectedMarkerId = null;
        ////               final String markerId = marker.getId();
        ////               if (coordinates.contains(markerId)) {
        ////                  for (int i = 0; i < coordinates.size(); i++) {
        ////                     final LatLng position = coordinates.get(i);
        ////                     if (markerId.latitude == position.latitude &&
        ////                           markerId.longitude == position.longitude) {
        ////                        selectedMarkerId = i;
        ////                        break;
        ////                     }
        ////                  }
        ////               }
        //            }
        //
        //            @Override
        //            public void onMarkerDragEnd(Marker marker) {
        ////               if (selectedMarkerId != -1) {
        ////                  coordinates.set(selectedMarkerId, marker.getPosition());
        ////               }
        ////               // NO movemos el zoom porque estamos simplemente afinando la
        ////               // posicin
        ////               drawAndShowMultipleDistances(coordinates, "", false, false);
        //            }
        //
        //            @Override
        //            public void onMarkerDrag(Marker marker) {
        //               // nothing
        //            }
        //         });

        googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
            @Override
            public void onInfoWindowClick(Marker marker) {
                Mint.leaveBreadcrumb("MainActivity::googleMap onInfoWindowClick");
                final Intent showInfoActivityIntent = new Intent(MainActivity.this, ShowInfoActivity.class);

                showInfoActivityIntent.putExtra(ShowInfoActivity.POSITIONS_LIST_EXTRA_KEY_NAME,
                        Lists.newArrayList(coordinates));
                showInfoActivityIntent.putExtra(ShowInfoActivity.DISTANCE_EXTRA_KEY_NAME,
                        distanceMeasuredAsText);
                startActivity(showInfoActivityIntent);
            }
        });

        googleMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter(this));

        // Iniciando la app
        if (currentLocation == null) {
            toastIt(getString(R.string.toast_loading_position), getApplicationContext());
        }

        handleIntents(getIntent());

        final List<String> distanceModes = Lists.newArrayList(
                getString(R.string.navigation_drawer_starting_point_current_position_item),
                getString(R.string.navigation_drawer_starting_point_any_position_item));
        final List<Integer> distanceIcons = Lists.newArrayList(R.drawable.ic_action_device_gps_fixed,
                R.drawable.ic_action_communication_location_on);
        drawerList = (ListView) findViewById(R.id.left_drawer);

        // TODO cambiar esto por un header como dios manda
        final LayoutInflater inflater = (LayoutInflater) getApplicationContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View convertView = inflater.inflate(R.layout.simple_textview_list_item, drawerList, false);
        final TextView tvListElement = (TextView) convertView.findViewById(R.id.simple_textview);
        tvListElement.setText(getString(R.string.navigation_drawer_starting_point_header));
        tvListElement.setClickable(false);
        tvListElement.setTextColor(getResources().getColor(R.color.white));
        drawerList.addHeaderView(convertView);
        drawerList.setAdapter(new NavigationDrawerItemAdapter(this, distanceModes, distanceIcons));

        drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                selectItem(position);
            }
        });

        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
                R.string.progressdialog_search_position_message,
                R.string.progressdialog_search_position_message) {
            @Override
            public void onDrawerOpened(View drawerView) {
                Mint.leaveBreadcrumb("MainActivity::actionBarDrawerToggle onDrawerOpened");
                super.onDrawerOpened(drawerView);
                supportInvalidateOptionsMenu();
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                Mint.leaveBreadcrumb("MainActivity::actionBarDrawerToggle onDrawerClosed");
                super.onDrawerClosed(drawerView);
                supportInvalidateOptionsMenu();
            }
        };

        drawerLayout.setDrawerListener(actionBarDrawerToggle);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        if (savedInstanceState == null) {
            Mint.leaveBreadcrumb("MainActivity savedInstanceState == null");
            // TODO change this because the header!!!!
            selectItem(FIRST_DRAWER_ITEM_INDEX);
        }
    }
}

From source file:net.bluehack.ui.Components.EmojiView.java

public EmojiView(boolean needStickers, boolean needGif, final Context context) {
    super(context);

    showGifs = needGif;/*w w w .  j a va 2  s .  co  m*/

    dotDrawable = context.getResources().getDrawable(R.drawable.bluecircle);

    if (Build.VERSION.SDK_INT >= 21) {
        outlineProvider = new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(view.getPaddingLeft(), view.getPaddingTop(),
                        view.getMeasuredWidth() - view.getPaddingRight(),
                        view.getMeasuredHeight() - view.getPaddingBottom(), AndroidUtilities.dp(6));
            }
        };
    }

    for (int i = 0; i < EmojiData.dataColored.length + 1; i++) {
        GridView gridView = new GridView(context);
        if (AndroidUtilities.isTablet()) {
            gridView.setColumnWidth(AndroidUtilities.dp(60));
        } else {
            gridView.setColumnWidth(AndroidUtilities.dp(45));
        }
        gridView.setNumColumns(-1);
        EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1);
        AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7);
        gridView.setAdapter(emojiGridAdapter);
        adapters.add(emojiGridAdapter);
        emojiGrids.add(gridView);
        FrameLayout frameLayout = new FrameLayout(context);
        frameLayout.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));

        views.add(frameLayout);
    }

    if (needStickers) {
        stickersWrap = new FrameLayout(context);

        StickersQuery.checkStickers(StickersQuery.TYPE_IMAGE);
        StickersQuery.checkFeaturedStickers();
        stickersGridView = new RecyclerListView(context) {
            @Override
            public boolean onInterceptTouchEvent(MotionEvent event) {
                boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event,
                        stickersGridView, EmojiView.this.getMeasuredHeight());
                return super.onInterceptTouchEvent(event) || result;
            }

            @Override
            public void setVisibility(int visibility) {
                if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE
                        || trendingGridView != null && trendingGridView.getVisibility() == VISIBLE) {
                    super.setVisibility(GONE);
                    return;
                }
                super.setVisibility(visibility);
            }
        };

        stickersGridView.setLayoutManager(stickersLayoutManager = new GridLayoutManager(context, 5));
        stickersLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (position == stickersGridAdapter.totalItems) {
                    return stickersGridAdapter.stickersPerRow;
                }
                return 1;
            }
        });
        stickersGridView.setPadding(0, AndroidUtilities.dp(4 + 48), 0, 0);
        stickersGridView.setClipToPadding(false);
        views.add(stickersWrap);
        stickersGridView.setAdapter(stickersGridAdapter = new StickersGridAdapter(context));
        stickersGridView.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return StickerPreviewViewer.getInstance().onTouch(event, stickersGridView,
                        EmojiView.this.getMeasuredHeight(), stickersOnItemClickListener);
            }
        });
        stickersOnItemClickListener = new RecyclerListView.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (!(view instanceof StickerEmojiCell)) {
                    return;
                }
                StickerPreviewViewer.getInstance().reset();
                StickerEmojiCell cell = (StickerEmojiCell) view;
                if (cell.isDisabled()) {
                    return;
                }
                cell.disable();
                listener.onStickerSelected(cell.getSticker());
            }
        };
        stickersGridView.setOnItemClickListener(stickersOnItemClickListener);
        stickersGridView.setGlowColor(0xfff5f6f7);
        stickersWrap.addView(stickersGridView);

        trendingGridView = new RecyclerListView(context);
        trendingGridView.setItemAnimator(null);
        trendingGridView.setLayoutAnimation(null);
        trendingGridView.setLayoutManager(trendingLayoutManager = new GridLayoutManager(context, 5) {
            @Override
            public boolean supportsPredictiveItemAnimations() {
                return false;
            }
        });
        trendingLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (trendingGridAdapter.cache.get(position) instanceof Integer
                        || position == trendingGridAdapter.totalItems) {
                    return trendingGridAdapter.stickersPerRow;
                }
                return 1;
            }
        });
        trendingGridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                checkStickersTabY(recyclerView, dy);
            }
        });
        trendingGridView.setClipToPadding(false);
        trendingGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0);
        trendingGridView.setAdapter(trendingGridAdapter = new TrendingGridAdapter(context));
        trendingGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                TLRPC.StickerSetCovered pack = trendingGridAdapter.positionsToSets.get(position);
                if (pack != null) {
                    listener.onShowStickerSet(pack);
                }
            }
        });
        trendingGridAdapter.notifyDataSetChanged();
        trendingGridView.setGlowColor(0xfff5f6f7);
        trendingGridView.setVisibility(GONE);
        stickersWrap.addView(trendingGridView);

        if (needGif) {
            gifsGridView = new RecyclerListView(context);
            gifsGridView.setClipToPadding(false);
            gifsGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0);
            gifsGridView.setLayoutManager(flowLayoutManager = new ExtendedGridLayoutManager(context, 100) {

                private Size size = new Size();

                @Override
                protected Size getSizeForItem(int i) {
                    TLRPC.Document document = recentGifs.get(i);
                    size.width = document.thumb != null && document.thumb.w != 0 ? document.thumb.w : 100;
                    size.height = document.thumb != null && document.thumb.h != 0 ? document.thumb.h : 100;
                    for (int b = 0; b < document.attributes.size(); b++) {
                        TLRPC.DocumentAttribute attribute = document.attributes.get(b);
                        if (attribute instanceof TLRPC.TL_documentAttributeImageSize
                                || attribute instanceof TLRPC.TL_documentAttributeVideo) {
                            size.width = attribute.w;
                            size.height = attribute.h;
                            break;
                        }
                    }
                    return size;
                }
            });
            flowLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                @Override
                public int getSpanSize(int position) {
                    return flowLayoutManager.getSpanSizeForItem(position);
                }
            });
            gifsGridView.addItemDecoration(new RecyclerView.ItemDecoration() {
                @Override
                public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent,
                        RecyclerView.State state) {
                    outRect.left = 0;
                    outRect.top = 0;
                    outRect.bottom = 0;
                    int position = parent.getChildAdapterPosition(view);
                    if (!flowLayoutManager.isFirstRow(position)) {
                        outRect.top = AndroidUtilities.dp(2);
                    }
                    outRect.right = flowLayoutManager.isLastInRow(position) ? 0 : AndroidUtilities.dp(2);
                }
            });
            gifsGridView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
            gifsGridView.setAdapter(gifsAdapter = new GifsAdapter(context));
            gifsGridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    checkStickersTabY(recyclerView, dy);
                }
            });
            gifsGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    if (position < 0 || position >= recentGifs.size() || listener == null) {
                        return;
                    }
                    listener.onGifSelected(recentGifs.get(position));
                }
            });
            gifsGridView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
                @Override
                public boolean onItemClick(View view, int position) {
                    if (position < 0 || position >= recentGifs.size()) {
                        return false;
                    }
                    final TLRPC.Document searchImage = recentGifs.get(position);
                    AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setMessage(LocaleController.getString("DeleteGif", R.string.DeleteGif));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK).toUpperCase(),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    StickersQuery.removeRecentGif(searchImage);
                                    recentGifs = StickersQuery.getRecentGifs();
                                    if (gifsAdapter != null) {
                                        gifsAdapter.notifyDataSetChanged();
                                    }
                                    if (recentGifs.isEmpty()) {
                                        updateStickerTabs();
                                    }
                                }
                            });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    builder.show().setCanceledOnTouchOutside(true);
                    return true;
                }
            });
            gifsGridView.setVisibility(GONE);
            stickersWrap.addView(gifsGridView);
        }

        stickersEmptyView = new TextView(context);
        stickersEmptyView.setText(LocaleController.getString("NoStickers", R.string.NoStickers));
        stickersEmptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        stickersEmptyView.setTextColor(0xff888888);
        stickersWrap.addView(stickersEmptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
                LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0));
        stickersGridView.setEmptyView(stickersEmptyView);

        stickersTab = new ScrollSlidingTabStrip(context) {

            boolean startedScroll;
            float lastX;
            float lastTranslateX;
            boolean first = true;

            @Override
            public boolean onInterceptTouchEvent(MotionEvent ev) {
                if (getParent() != null) {
                    getParent().requestDisallowInterceptTouchEvent(true);
                }
                return super.onInterceptTouchEvent(ev);
            }

            @Override
            public boolean onTouchEvent(MotionEvent ev) {
                if (first) {
                    first = false;
                    lastX = ev.getX();
                }
                float newTranslationX = stickersTab.getTranslationX();
                if (stickersTab.getScrollX() == 0 && newTranslationX == 0) {
                    if (!startedScroll && lastX - ev.getX() < 0) {
                        if (pager.beginFakeDrag()) {
                            startedScroll = true;
                            lastTranslateX = stickersTab.getTranslationX();
                        }
                    } else if (startedScroll && lastX - ev.getX() > 0) {
                        if (pager.isFakeDragging()) {
                            pager.endFakeDrag();
                            startedScroll = false;
                        }
                    }
                }
                if (startedScroll) {
                    int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX);
                    try {
                        pager.fakeDragBy(dx);
                        lastTranslateX = newTranslationX;
                    } catch (Exception e) {
                        try {
                            pager.endFakeDrag();
                        } catch (Exception e2) {
                            //don't promt
                        }
                        startedScroll = false;
                        FileLog.e("tmessages", e);
                    }
                }
                lastX = ev.getX();
                if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) {
                    first = true;
                    if (startedScroll) {
                        pager.endFakeDrag();
                        startedScroll = false;
                    }
                }
                return startedScroll || super.onTouchEvent(ev);
            }
        };
        stickersTab.setUnderlineHeight(AndroidUtilities.dp(1));
        stickersTab.setIndicatorColor(0xffe2e5e7);
        stickersTab.setUnderlineColor(0xffe2e5e7);
        stickersTab.setBackgroundColor(0xfff5f6f7);
        stickersTab.setVisibility(INVISIBLE);
        addView(stickersTab,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
        stickersTab.setTranslationX(AndroidUtilities.displaySize.x);
        updateStickerTabs();
        stickersTab.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() {
            @Override
            public void onPageSelected(int page) {
                if (gifsGridView != null) {
                    if (page == gifTabNum + 1) {
                        if (gifsGridView.getVisibility() != VISIBLE) {
                            listener.onGifTab(true);
                            showGifTab();
                        }
                    } else if (page == trendingTabNum + 1) {
                        if (trendingGridView.getVisibility() != VISIBLE) {
                            showTrendingTab();
                        }
                    } else {
                        if (gifsGridView.getVisibility() == VISIBLE) {
                            listener.onGifTab(false);
                            gifsGridView.setVisibility(GONE);
                            stickersGridView.setVisibility(VISIBLE);
                            stickersEmptyView
                                    .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE);
                            saveNewPage();
                        } else if (trendingGridView.getVisibility() == VISIBLE) {
                            trendingGridView.setVisibility(GONE);
                            stickersGridView.setVisibility(VISIBLE);
                            stickersEmptyView
                                    .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE);
                            saveNewPage();
                        }
                    }
                }
                if (page == 0) {
                    pager.setCurrentItem(0);
                    return;
                } else {
                    if (page == gifTabNum + 1 || page == trendingTabNum + 1) {
                        return;
                    } else if (page == recentTabBum + 1) {
                        stickersLayoutManager.scrollToPositionWithOffset(0, 0);
                        checkStickersTabY(null, 0);
                        stickersTab.onPageScrolled(recentTabBum + 1,
                                (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
                        return;
                    }
                }
                int index = page - 1 - stickersTabOffset;
                if (index >= stickerSets.size()) {
                    if (listener != null) {
                        listener.onStickersSettingsClick();
                    }
                    return;
                }
                if (index >= stickerSets.size()) {
                    index = stickerSets.size() - 1;
                }
                stickersLayoutManager.scrollToPositionWithOffset(
                        stickersGridAdapter.getPositionForPack(stickerSets.get(index)), 0);
                checkStickersTabY(null, 0);
                checkScroll();
            }
        });

        stickersGridView.setOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                checkScroll();
                checkStickersTabY(recyclerView, dy);
            }
        });
    }

    pager = new ViewPager(context) {
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (getParent() != null) {
                getParent().requestDisallowInterceptTouchEvent(true);
            }
            return super.onInterceptTouchEvent(ev);
        }
    };
    pager.setAdapter(new EmojiPagesAdapter());

    emojiTab = new LinearLayout(context) {
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (getParent() != null) {
                getParent().requestDisallowInterceptTouchEvent(true);
            }
            return super.onInterceptTouchEvent(ev);
        }
    };
    emojiTab.setOrientation(LinearLayout.HORIZONTAL);
    addView(emojiTab, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48));

    pagerSlidingTabStrip = new PagerSlidingTabStrip(context);
    pagerSlidingTabStrip.setViewPager(pager);
    pagerSlidingTabStrip.setShouldExpand(true);
    pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2));
    pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1));
    pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2);
    pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7);
    emojiTab.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f));
    pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            EmojiView.this.onPageScrolled(position, getMeasuredWidth() - getPaddingLeft() - getPaddingRight(),
                    positionOffsetPixels);
        }

        @Override
        public void onPageSelected(int position) {
            saveNewPage();
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    FrameLayout frameLayout = new FrameLayout(context);
    emojiTab.addView(frameLayout, LayoutHelper.createLinear(52, 48));

    backspaceButton = new ImageView(context) {
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                backspacePressed = true;
                backspaceOnce = false;
                postBackspaceRunnable(350);
            } else if (event.getAction() == MotionEvent.ACTION_CANCEL
                    || event.getAction() == MotionEvent.ACTION_UP) {
                backspacePressed = false;
                if (!backspaceOnce) {
                    if (listener != null && listener.onBackspace()) {
                        backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
                    }
                }
            }
            super.onTouchEvent(event);
            return true;
        }
    };
    backspaceButton.setImageResource(R.drawable.ic_smiles_backspace);
    backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace);
    backspaceButton.setScaleType(ImageView.ScaleType.CENTER);
    frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48));

    View view = new View(context);
    view.setBackgroundColor(0xffe2e5e7);
    frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM));

    TextView textView = new TextView(context);
    textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    textView.setTextSize(18);
    textView.setTextColor(0xff888888);
    textView.setGravity(Gravity.CENTER);
    textView.setClickable(false);
    textView.setFocusable(false);
    ((FrameLayout) views.get(0)).addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0));
    emojiGrids.get(0).setEmptyView(textView);

    addView(pager, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT,
            Gravity.LEFT | Gravity.TOP));

    emojiSize = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 40 : 32);
    pickerView = new EmojiColorPickerView(context);
    pickerViewPopup = new EmojiPopupWindow(pickerView,
            popupWidth = AndroidUtilities.dp((AndroidUtilities.isTablet() ? 40 : 32) * 6 + 10 + 4 * 5),
            popupHeight = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 64 : 56));
    pickerViewPopup.setOutsideTouchable(true);
    pickerViewPopup.setClippingEnabled(true);
    pickerViewPopup.setInputMethodMode(EmojiPopupWindow.INPUT_METHOD_NOT_NEEDED);
    pickerViewPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
    pickerViewPopup.getContentView().setFocusableInTouchMode(true);
    pickerViewPopup.getContentView().setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0
                    && event.getAction() == KeyEvent.ACTION_UP && pickerViewPopup != null
                    && pickerViewPopup.isShowing()) {
                pickerViewPopup.dismiss();
                return true;
            }
            return false;
        }
    });
    currentPage = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE).getInt("selected_page", 0);
    loadRecents();
}

From source file:kr.wdream.ui.Components.EmojiView.java

public EmojiView(boolean needStickers, boolean needGif, final Context context) {
    super(context);

    showGifs = needGif;//from  w w  w. j av  a  2 s  .c  o m

    dotDrawable = context.getResources().getDrawable(kr.wdream.storyshop.R.drawable.bluecircle);

    if (Build.VERSION.SDK_INT >= 21) {
        outlineProvider = new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(view.getPaddingLeft(), view.getPaddingTop(),
                        view.getMeasuredWidth() - view.getPaddingRight(),
                        view.getMeasuredHeight() - view.getPaddingBottom(), AndroidUtilities.dp(6));
            }
        };
    }

    for (int i = 0; i < EmojiData.dataColored.length + 1; i++) {
        GridView gridView = new GridView(context);
        if (AndroidUtilities.isTablet()) {
            gridView.setColumnWidth(AndroidUtilities.dp(60));
        } else {
            gridView.setColumnWidth(AndroidUtilities.dp(45));
        }
        gridView.setNumColumns(-1);
        EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1);
        AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7);
        gridView.setAdapter(emojiGridAdapter);
        adapters.add(emojiGridAdapter);
        emojiGrids.add(gridView);
        FrameLayout frameLayout = new FrameLayout(context);
        frameLayout.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));

        views.add(frameLayout);
    }

    if (needStickers) {
        stickersWrap = new FrameLayout(context);

        StickersQuery.checkStickers(StickersQuery.TYPE_IMAGE);
        StickersQuery.checkFeaturedStickers();
        stickersGridView = new RecyclerListView(context) {
            @Override
            public boolean onInterceptTouchEvent(MotionEvent event) {
                boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event,
                        stickersGridView, EmojiView.this.getMeasuredHeight());
                return super.onInterceptTouchEvent(event) || result;
            }

            @Override
            public void setVisibility(int visibility) {
                if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE
                        || trendingGridView != null && trendingGridView.getVisibility() == VISIBLE) {
                    super.setVisibility(GONE);
                    return;
                }
                super.setVisibility(visibility);
            }
        };

        stickersGridView.setLayoutManager(stickersLayoutManager = new GridLayoutManager(context, 5));
        stickersLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (position == stickersGridAdapter.totalItems) {
                    return stickersGridAdapter.stickersPerRow;
                }
                return 1;
            }
        });
        stickersGridView.setPadding(0, AndroidUtilities.dp(4 + 48), 0, 0);
        stickersGridView.setClipToPadding(false);
        views.add(stickersWrap);
        stickersGridView.setAdapter(stickersGridAdapter = new StickersGridAdapter(context));
        stickersGridView.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return StickerPreviewViewer.getInstance().onTouch(event, stickersGridView,
                        EmojiView.this.getMeasuredHeight(), stickersOnItemClickListener);
            }
        });
        stickersOnItemClickListener = new RecyclerListView.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (!(view instanceof StickerEmojiCell)) {
                    return;
                }
                StickerPreviewViewer.getInstance().reset();
                StickerEmojiCell cell = (StickerEmojiCell) view;
                if (cell.isDisabled()) {
                    return;
                }
                cell.disable();
                listener.onStickerSelected(cell.getSticker());
            }
        };
        stickersGridView.setOnItemClickListener(stickersOnItemClickListener);
        stickersGridView.setGlowColor(0xfff5f6f7);
        stickersWrap.addView(stickersGridView);

        trendingGridView = new RecyclerListView(context);
        trendingGridView.setItemAnimator(null);
        trendingGridView.setLayoutAnimation(null);
        trendingGridView.setLayoutManager(trendingLayoutManager = new GridLayoutManager(context, 5) {
            @Override
            public boolean supportsPredictiveItemAnimations() {
                return false;
            }
        });
        trendingLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (trendingGridAdapter.cache.get(position) instanceof Integer
                        || position == trendingGridAdapter.totalItems) {
                    return trendingGridAdapter.stickersPerRow;
                }
                return 1;
            }
        });
        trendingGridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                checkStickersTabY(recyclerView, dy);
            }
        });
        trendingGridView.setClipToPadding(false);
        trendingGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0);
        trendingGridView.setAdapter(trendingGridAdapter = new TrendingGridAdapter(context));
        trendingGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                TLRPC.StickerSetCovered pack = trendingGridAdapter.positionsToSets.get(position);
                if (pack != null) {
                    listener.onShowStickerSet(pack);
                }
            }
        });
        trendingGridAdapter.notifyDataSetChanged();
        trendingGridView.setGlowColor(0xfff5f6f7);
        trendingGridView.setVisibility(GONE);
        stickersWrap.addView(trendingGridView);

        if (needGif) {
            gifsGridView = new RecyclerListView(context);
            gifsGridView.setClipToPadding(false);
            gifsGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0);
            gifsGridView.setLayoutManager(flowLayoutManager = new ExtendedGridLayoutManager(context, 100) {

                private Size size = new Size();

                @Override
                protected Size getSizeForItem(int i) {
                    TLRPC.Document document = recentGifs.get(i);
                    size.width = document.thumb != null && document.thumb.w != 0 ? document.thumb.w : 100;
                    size.height = document.thumb != null && document.thumb.h != 0 ? document.thumb.h : 100;
                    for (int b = 0; b < document.attributes.size(); b++) {
                        TLRPC.DocumentAttribute attribute = document.attributes.get(b);
                        if (attribute instanceof TLRPC.TL_documentAttributeImageSize
                                || attribute instanceof TLRPC.TL_documentAttributeVideo) {
                            size.width = attribute.w;
                            size.height = attribute.h;
                            break;
                        }
                    }
                    return size;
                }
            });
            flowLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                @Override
                public int getSpanSize(int position) {
                    return flowLayoutManager.getSpanSizeForItem(position);
                }
            });
            gifsGridView.addItemDecoration(new RecyclerView.ItemDecoration() {
                @Override
                public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent,
                        RecyclerView.State state) {
                    outRect.left = 0;
                    outRect.top = 0;
                    outRect.bottom = 0;
                    int position = parent.getChildAdapterPosition(view);
                    if (!flowLayoutManager.isFirstRow(position)) {
                        outRect.top = AndroidUtilities.dp(2);
                    }
                    outRect.right = flowLayoutManager.isLastInRow(position) ? 0 : AndroidUtilities.dp(2);
                }
            });
            gifsGridView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
            gifsGridView.setAdapter(gifsAdapter = new GifsAdapter(context));
            gifsGridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    checkStickersTabY(recyclerView, dy);
                }
            });
            gifsGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    if (position < 0 || position >= recentGifs.size() || listener == null) {
                        return;
                    }
                    listener.onGifSelected(recentGifs.get(position));
                }
            });
            gifsGridView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
                @Override
                public boolean onItemClick(View view, int position) {
                    if (position < 0 || position >= recentGifs.size()) {
                        return false;
                    }
                    final TLRPC.Document searchImage = recentGifs.get(position);
                    AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
                    builder.setTitle(
                            LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName));
                    builder.setMessage(
                            LocaleController.getString("DeleteGif", kr.wdream.storyshop.R.string.DeleteGif));
                    builder.setPositiveButton(
                            LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK).toUpperCase(),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    StickersQuery.removeRecentGif(searchImage);
                                    recentGifs = StickersQuery.getRecentGifs();
                                    if (gifsAdapter != null) {
                                        gifsAdapter.notifyDataSetChanged();
                                    }
                                    if (recentGifs.isEmpty()) {
                                        updateStickerTabs();
                                    }
                                }
                            });
                    builder.setNegativeButton(
                            LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null);
                    builder.show().setCanceledOnTouchOutside(true);
                    return true;
                }
            });
            gifsGridView.setVisibility(GONE);
            stickersWrap.addView(gifsGridView);
        }

        stickersEmptyView = new TextView(context);
        stickersEmptyView
                .setText(LocaleController.getString("NoStickers", kr.wdream.storyshop.R.string.NoStickers));
        stickersEmptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        stickersEmptyView.setTextColor(0xff888888);
        stickersWrap.addView(stickersEmptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
                LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0));
        stickersGridView.setEmptyView(stickersEmptyView);

        stickersTab = new ScrollSlidingTabStrip(context) {

            boolean startedScroll;
            float lastX;
            float lastTranslateX;
            boolean first = true;

            @Override
            public boolean onInterceptTouchEvent(MotionEvent ev) {
                if (getParent() != null) {
                    getParent().requestDisallowInterceptTouchEvent(true);
                }
                return super.onInterceptTouchEvent(ev);
            }

            @Override
            public boolean onTouchEvent(MotionEvent ev) {
                if (first) {
                    first = false;
                    lastX = ev.getX();
                }
                float newTranslationX = stickersTab.getTranslationX();
                if (stickersTab.getScrollX() == 0 && newTranslationX == 0) {
                    if (!startedScroll && lastX - ev.getX() < 0) {
                        if (pager.beginFakeDrag()) {
                            startedScroll = true;
                            lastTranslateX = stickersTab.getTranslationX();
                        }
                    } else if (startedScroll && lastX - ev.getX() > 0) {
                        if (pager.isFakeDragging()) {
                            pager.endFakeDrag();
                            startedScroll = false;
                        }
                    }
                }
                if (startedScroll) {
                    int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX);
                    try {
                        pager.fakeDragBy(dx);
                        lastTranslateX = newTranslationX;
                    } catch (Exception e) {
                        try {
                            pager.endFakeDrag();
                        } catch (Exception e2) {
                            //don't promt
                        }
                        startedScroll = false;
                        FileLog.e("tmessages", e);
                    }
                }
                lastX = ev.getX();
                if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) {
                    first = true;
                    if (startedScroll) {
                        pager.endFakeDrag();
                        startedScroll = false;
                    }
                }
                return startedScroll || super.onTouchEvent(ev);
            }
        };
        stickersTab.setUnderlineHeight(AndroidUtilities.dp(1));
        stickersTab.setIndicatorColor(0xffe2e5e7);
        stickersTab.setUnderlineColor(0xffe2e5e7);
        stickersTab.setBackgroundColor(0xfff5f6f7);
        stickersTab.setVisibility(INVISIBLE);
        addView(stickersTab,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
        stickersTab.setTranslationX(AndroidUtilities.displaySize.x);
        updateStickerTabs();
        stickersTab.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() {
            @Override
            public void onPageSelected(int page) {
                if (gifsGridView != null) {
                    if (page == gifTabNum + 1) {
                        if (gifsGridView.getVisibility() != VISIBLE) {
                            listener.onGifTab(true);
                            showGifTab();
                        }
                    } else if (page == trendingTabNum + 1) {
                        if (trendingGridView.getVisibility() != VISIBLE) {
                            showTrendingTab();
                        }
                    } else {
                        if (gifsGridView.getVisibility() == VISIBLE) {
                            listener.onGifTab(false);
                            gifsGridView.setVisibility(GONE);
                            stickersGridView.setVisibility(VISIBLE);
                            stickersEmptyView
                                    .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE);
                            saveNewPage();
                        } else if (trendingGridView.getVisibility() == VISIBLE) {
                            trendingGridView.setVisibility(GONE);
                            stickersGridView.setVisibility(VISIBLE);
                            stickersEmptyView
                                    .setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE);
                            saveNewPage();
                        }
                    }
                }
                if (page == 0) {
                    pager.setCurrentItem(0);
                    return;
                } else {
                    if (page == gifTabNum + 1 || page == trendingTabNum + 1) {
                        return;
                    } else if (page == recentTabBum + 1) {
                        stickersLayoutManager.scrollToPositionWithOffset(0, 0);
                        checkStickersTabY(null, 0);
                        stickersTab.onPageScrolled(recentTabBum + 1,
                                (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
                        return;
                    }
                }
                int index = page - 1 - stickersTabOffset;
                if (index >= stickerSets.size()) {
                    if (listener != null) {
                        listener.onStickersSettingsClick();
                    }
                    return;
                }
                if (index >= stickerSets.size()) {
                    index = stickerSets.size() - 1;
                }
                stickersLayoutManager.scrollToPositionWithOffset(
                        stickersGridAdapter.getPositionForPack(stickerSets.get(index)), 0);
                checkStickersTabY(null, 0);
                checkScroll();
            }
        });

        stickersGridView.setOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                checkScroll();
                checkStickersTabY(recyclerView, dy);
            }
        });
    }

    pager = new ViewPager(context) {
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (getParent() != null) {
                getParent().requestDisallowInterceptTouchEvent(true);
            }
            return super.onInterceptTouchEvent(ev);
        }
    };
    pager.setAdapter(new EmojiPagesAdapter());

    emojiTab = new LinearLayout(context) {
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (getParent() != null) {
                getParent().requestDisallowInterceptTouchEvent(true);
            }
            return super.onInterceptTouchEvent(ev);
        }
    };
    emojiTab.setOrientation(LinearLayout.HORIZONTAL);
    addView(emojiTab, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48));

    pagerSlidingTabStrip = new PagerSlidingTabStrip(context);
    pagerSlidingTabStrip.setViewPager(pager);
    pagerSlidingTabStrip.setShouldExpand(true);
    pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(0));
    pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1));
    //?   ?
    pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2);
    pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7);
    emojiTab.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f));
    pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            EmojiView.this.onPageScrolled(position, getMeasuredWidth() - getPaddingLeft() - getPaddingRight(),
                    positionOffsetPixels);
        }

        @Override
        public void onPageSelected(int position) {
            saveNewPage();
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    FrameLayout frameLayout = new FrameLayout(context);
    emojiTab.addView(frameLayout, LayoutHelper.createLinear(52, 48));

    backspaceButton = new ImageView(context) {
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                backspacePressed = true;
                backspaceOnce = false;
                postBackspaceRunnable(350);
            } else if (event.getAction() == MotionEvent.ACTION_CANCEL
                    || event.getAction() == MotionEvent.ACTION_UP) {
                backspacePressed = false;
                if (!backspaceOnce) {
                    if (listener != null && listener.onBackspace()) {
                        backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
                    }
                }
            }
            super.onTouchEvent(event);
            return true;
        }
    };
    backspaceButton.setImageResource(kr.wdream.storyshop.R.drawable.ic_smiles_backspace);
    backspaceButton.setBackgroundResource(kr.wdream.storyshop.R.drawable.ic_emoji_backspace);
    backspaceButton.setScaleType(ImageView.ScaleType.CENTER);
    frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48));

    View view = new View(context);
    view.setBackgroundColor(0xffe2e5e7);
    frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM));

    TextView textView = new TextView(context);
    textView.setText(LocaleController.getString("NoRecent", kr.wdream.storyshop.R.string.NoRecent));
    textView.setTextSize(18);
    textView.setTextColor(0xff888888);
    textView.setGravity(Gravity.CENTER);
    textView.setClickable(false);
    textView.setFocusable(false);
    ((FrameLayout) views.get(0)).addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0));
    emojiGrids.get(0).setEmptyView(textView);

    addView(pager, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT,
            Gravity.LEFT | Gravity.TOP));

    emojiSize = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 40 : 32);
    pickerView = new EmojiColorPickerView(context);
    pickerViewPopup = new EmojiPopupWindow(pickerView,
            popupWidth = AndroidUtilities.dp((AndroidUtilities.isTablet() ? 40 : 32) * 6 + 10 + 4 * 5),
            popupHeight = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 64 : 56));
    pickerViewPopup.setOutsideTouchable(true);
    pickerViewPopup.setClippingEnabled(true);
    pickerViewPopup.setInputMethodMode(EmojiPopupWindow.INPUT_METHOD_NOT_NEEDED);
    pickerViewPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
    pickerViewPopup.getContentView().setFocusableInTouchMode(true);
    pickerViewPopup.getContentView().setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0
                    && event.getAction() == KeyEvent.ACTION_UP && pickerViewPopup != null
                    && pickerViewPopup.isShowing()) {
                pickerViewPopup.dismiss();
                return true;
            }
            return false;
        }
    });
    currentPage = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE).getInt("selected_page", 0);
    loadRecents();
}

From source file:edu.ptu.navpattern.tooltip.Tooltip.java

private View getContentView(final Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);
    LinearLayout vgContent = new LinearLayout(builder.mContext);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        vgContent.setBackground(drawable);
    } else {//w ww  .j av  a  2s .  c o m
        //noinspection deprecation
        vgContent.setBackgroundDrawable(drawable);
    }
    int padding = (int) builder.mPadding;
    vgContent.setPadding(padding, padding, padding, padding);
    vgContent.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textViewParams.topMargin = 1;
    vgContent.setLayoutParams(textViewParams);
    vgContent.setDividerDrawable(vgContent.getResources().getDrawable(R.drawable.divider_line));
    vgContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);

    if (builder.itemText != null && builder.itemText.length > 0) {
        for (int i = 0; i < builder.itemText.length; i++) {

            TextView textView = new TextView(builder.mContext);
            textView.setText(builder.itemText[i]);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 44);
            textView.setTextColor(0xffffffff);
            textView.setGravity(Gravity.CENTER_VERTICAL);
            if (builder.itemLogo != null && builder.itemLogo.length > i) {
                Drawable drawableLeft = builder.mContext.getResources().getDrawable(builder.itemLogo[i]);
                /// ??,??.
                //                    drawableLeft.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                //                    textView.setCompoundDrawables(drawableLeft, null, null, null);
                //                    textView.setCompoundDrawablePadding(4);
                //                    textView.setBackgroundDrawable(drawableLeft);
                LinearLayout linearLayout = new LinearLayout(builder.mContext);
                linearLayout.setMinimumHeight((int) dpToPx(44f));
                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.setGravity(Gravity.CENTER_VERTICAL);
                ImageView icon = new ImageView(builder.mContext);
                icon.setImageDrawable(drawableLeft);
                linearLayout.addView(icon);
                linearLayout.addView(textView);
                vgContent.addView(linearLayout);
                final int position = i;
                linearLayout.setClickable(false);
                linearLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v,
                                MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                                        MotionEvent.ACTION_UP, v.getLeft() + 5, v.getTop() + 5, 0));
                    }
                });
            } else {
                vgContent.addView(textView);
                final int position = i;
                textView.setClickable(false);
                textView.setMinimumHeight((int) dpToPx(44f));
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v, null);
                    }
                });
            }
        }

    }

    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) 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(vgContent);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(vgContent);
    }

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