Example usage for android.widget ImageView setOnLongClickListener

List of usage examples for android.widget ImageView setOnLongClickListener

Introduction

In this page you can find the example usage for android.widget ImageView setOnLongClickListener.

Prototype

public void setOnLongClickListener(@Nullable OnLongClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked and held.

Usage

From source file:nl.vincentketelaars.mexen.activities.RollDice.java

protected void setupDice(ImageView[] diesIn, ImageView[] vastImagesIn, int[] rollIn, boolean vastIn[]) {
    this.dies = diesIn;
    this.vastImages = vastImagesIn;
    this.roll = rollIn;
    this.vast = vastIn;

    // Get the dice
    for (int i = 0; i < diceImages.length; i++) {
        dice[i] = getResources().getDrawable(diceImages[i]);
    }//  w ww.  ja va2s . c  o m

    // Set drawable
    animationHandler = new Handler(new Handler.Callback() {
        public boolean handleMessage(Message msg) {
            for (int i = 0; i < dies.length; i++) {
                dies[i].setImageDrawable(dice[roll[i]]);
            }
            return true;
        }
    });

    // Listener that increments the number on the dice
    OnClickListener diceListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!changeDiceValueAllowed())
                return;
            for (int i = 0; i < dies.length; i++) {
                if (dies[i].getId() == v.getId() && !vast[i]) {
                    roll[i] = (roll[i] + 1) % diceImages.length;
                }
            }
            animationHandler.sendEmptyMessage(0);
            evaluateChances();
        }
    };

    // Listener that sets vast
    OnLongClickListener vastListener = new OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int numVast = 0;
            for (boolean v : vast) {
                if (v)
                    numVast++;
            }
            for (int i = 0; i < dies.length; i++) {
                if (dies[i].getId() == view.getId()) {
                    if (vastImages[i].getVisibility() == View.VISIBLE) {
                        setVast(i, false);
                        break;
                    }
                    if (isSpecialVastCase())
                        break;
                    if (vastImages[i].getVisibility() == View.INVISIBLE && numVast < dies.length - 1
                            && roll[i] < getHighestVastNumber()) { // Only vast till highest allowed number
                        setVast(i, true);
                    }
                }
            }
            evaluateChances();
            return true;
        }
    };

    for (ImageView d : dies) {
        d.setOnClickListener(diceListener); // Set the listener for each dice
        d.setOnLongClickListener(vastListener); // Set the long listener for each dice
    }
    evaluateChances();
}

From source file:com.fatelon.partyphotobooth.kiosk.KioskActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    mKioskModeHelper = new KioskModeHelper(this);
    mPreferencesHelper = new PreferencesHelper();
    mCurrentFrame = 1;//from w ww.  j a va2s  .c  om
    mTotalFrames = mPreferencesHelper.getPhotoStripTemplate(this).getNumPhotos();

    // Show on top of lock screen.
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

    setContentView(R.layout.activity_kiosk);

    // Configure button to exit Kiosk mode.
    ImageView exitButton = (ImageView) findViewById(R.id.kiosk_exit_button);
    mFlashScreen = findViewById(R.id.flash_screen);
    exitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            launchPhotoBoothUi();
        }
    });

    exitButton.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {

            if (mKioskModeHelper.isPasswordRequired()) {
                showDialogFragment(KioskPasswordDialogFragment.newInstance());
            } else {
                exitKioskMode();
            }
            return true;
        }
    });
}

From source file:im.vector.adapters.VectorMediasViewerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, final int position) {
    View view = mLayoutInflater.inflate(R.layout.adapter_vector_medias_viewer, null, false);

    // hide the pie chart
    final PieFractionView pieFractionView = (PieFractionView) view.findViewById(R.id.media_slider_piechart);
    pieFractionView.setVisibility(View.GONE);

    final WebView imageWebView = (WebView) view.findViewById(R.id.media_slider_image_webview);
    final View videoLayout = view.findViewById(R.id.media_slider_videolayout);
    final ImageView thumbView = (ImageView) view.findViewById(R.id.media_slider_video_thumbnail);

    imageWebView.getSettings().setDisplayZoomControls(false);

    imageWebView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override/*w  ww . j  a v a  2 s.  c o  m*/
        public boolean onLongClick(View v) {
            VectorMediasViewerAdapter.this.onLongClick();
            return true;
        }
    });

    thumbView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            VectorMediasViewerAdapter.this.onLongClick();
            return true;
        }
    });

    // black background
    view.setBackgroundColor(0xFF000000);
    imageWebView.setBackgroundColor(0xFF000000);
    videoLayout.setBackgroundColor(0xFF000000);

    final SlidableMediaInfo mediaInfo = mMediasMessagesList.get(position);
    String mediaUrl = mediaInfo.mMediaUrl;

    if (mediaInfo.mMessageType.equals(Message.MSGTYPE_IMAGE)) {
        imageWebView.setVisibility(View.VISIBLE);
        imageWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        imageWebView.getSettings().setJavaScriptEnabled(true);
        imageWebView.getSettings().setLoadWithOverviewMode(true);
        imageWebView.getSettings().setUseWideViewPort(true);
        imageWebView.getSettings().setBuiltInZoomControls(true);

        videoLayout.setVisibility(View.GONE);

        final int rotationAngle = mediaInfo.mRotationAngle;
        final String mimeType = mediaInfo.mMimeType;
        File mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mimeType);

        // is the high picture already downloaded ?
        if (null != mediaFile) {
            if (mHighResMediaIndex.indexOf(position) < 0) {
                mHighResMediaIndex.add(position);
            }
        } else {
            // try to retrieve the thumbnail
            mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mMaxImageWidth, mMaxImageHeight, null);
        }

        // the thumbnail is not yet downloaded
        if (null == mediaFile) {
            // display nothing
            container.addView(view, 0);
            return view;
        }

        String mediaUri = "file://" + mediaFile.getPath();

        String css = computeCss(mediaUri, mMaxImageWidth, mMaxImageHeight, rotationAngle);
        final String viewportContent = "width=640";
        loadImage(imageWebView, Uri.parse(mediaUri), viewportContent, css);
        container.addView(view, 0);
    } else {
        loadVideo(position, view, mediaInfo.mThumbnailUrl, mediaUrl, mediaInfo.mMimeType);
        container.addView(view, 0);
    }

    // check if the media is downloading
    String downloadId = mMediasCache.downloadMedia(mContext, mSession.getHomeserverConfig(), mediaUrl,
            mediaInfo.mMimeType);

    if (null != downloadId) {
        pieFractionView.setVisibility(View.VISIBLE);
        pieFractionView.setFraction(mMediasCache.getProgressValueForDownloadId(downloadId));
        pieFractionView.setTag(downloadId);

        mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() {
            @Override
            public void onDownloadError(String downloadId, JsonElement jsonElement) {
                pieFractionView.setVisibility(View.GONE);
                MatrixError error = JsonUtils.toMatrixError(jsonElement);

                if ((null != error) && error.isSupportedErrorCode()) {
                    Toast.makeText(VectorMediasViewerAdapter.this.mContext, error.getLocalizedMessage(),
                            Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onDownloadProgress(String aDownloadId, DownloadStats stats) {
                if (aDownloadId.equals(pieFractionView.getTag())) {
                    pieFractionView.setFraction(stats.mProgress);
                }
            }

            @Override
            public void onDownloadComplete(String aDownloadId) {
                if (aDownloadId.equals(pieFractionView.getTag())) {
                    pieFractionView.setVisibility(View.GONE);
                }
            }
        });
    }

    return view;
}

From source file:org.jitsi.android.gui.call.VideoCallActivity.java

/**
 * Initializes the microphone button view.
 *///w w w .j a va  2  s  .  c  om
private void initMicrophoneView() {
    final ImageView microphoneButton = (ImageView) findViewById(R.id.callMicrophoneButton);

    microphoneButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            CallManager.setMute(call, !isMuted());
        }
    });
    microphoneButton.setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View view) {
            DialogFragment newFragment = VolumeControlDialog.createInputVolCtrlDialog();
            newFragment.show(getSupportFragmentManager(), "vol_ctrl_dialog");
            return true;
        }
    });
}

From source file:im.neon.adapters.VectorMediasViewerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, final int position) {
    View view = mLayoutInflater.inflate(R.layout.adapter_vector_medias_viewer, null, false);

    // hide the pie chart
    final PieFractionView pieFractionView = (PieFractionView) view.findViewById(R.id.media_slider_piechart);
    pieFractionView.setVisibility(View.GONE);

    final WebView imageWebView = (WebView) view.findViewById(R.id.media_slider_image_webview);
    final View videoLayout = view.findViewById(R.id.media_slider_videolayout);
    final ImageView thumbView = (ImageView) view.findViewById(R.id.media_slider_video_thumbnail);

    imageWebView.getSettings().setDisplayZoomControls(false);

    imageWebView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override//w ww  .ja  va  2  s  . com
        public boolean onLongClick(View v) {
            VectorMediasViewerAdapter.this.onLongClick();
            return true;
        }
    });

    thumbView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            VectorMediasViewerAdapter.this.onLongClick();
            return true;
        }
    });

    // black background
    view.setBackgroundColor(0xFF000000);
    imageWebView.setBackgroundColor(0xFF000000);
    videoLayout.setBackgroundColor(0xFF000000);

    final SlidableMediaInfo mediaInfo = mMediasMessagesList.get(position);
    String mediaUrl = mediaInfo.mMediaUrl;

    if (mediaInfo.mMessageType.equals(Message.MSGTYPE_IMAGE)) {
        imageWebView.setVisibility(View.VISIBLE);
        imageWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        imageWebView.getSettings().setJavaScriptEnabled(true);
        imageWebView.getSettings().setLoadWithOverviewMode(true);
        imageWebView.getSettings().setUseWideViewPort(true);
        imageWebView.getSettings().setBuiltInZoomControls(true);

        videoLayout.setVisibility(View.GONE);

        final int rotationAngle = mediaInfo.mRotationAngle;

        if (TextUtils.isEmpty(mediaInfo.mMimeType)) {
            mediaInfo.mMimeType = "image/jpeg";
        }

        final String mimeType = mediaInfo.mMimeType;
        File mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mimeType);

        // is the high picture already downloaded ?
        if (null != mediaFile) {
            if (mHighResMediaIndex.indexOf(position) < 0) {
                mHighResMediaIndex.add(position);
            }
        } else {
            // try to retrieve the thumbnail
            mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mMaxImageWidth, mMaxImageHeight, null);
        }

        // the thumbnail is not yet downloaded
        if (null == mediaFile) {
            // display nothing
            container.addView(view, 0);
            return view;
        }

        String mediaUri = "file://" + mediaFile.getPath();

        String css = computeCss(mediaUri, mMaxImageWidth, mMaxImageHeight, rotationAngle);
        final String viewportContent = "width=640";
        loadImage(imageWebView, Uri.parse(mediaUri), viewportContent, css);
        container.addView(view, 0);
    } else {
        loadVideo(position, view, mediaInfo.mThumbnailUrl, mediaUrl, mediaInfo.mMimeType);
        container.addView(view, 0);
    }

    // check if the media is downloading
    String downloadId = mMediasCache.downloadMedia(mContext, mSession.getHomeserverConfig(), mediaUrl,
            mediaInfo.mMimeType, mediaInfo.mEncryptedFileInfo);

    if (null != downloadId) {
        pieFractionView.setVisibility(View.VISIBLE);
        pieFractionView.setFraction(mMediasCache.getProgressValueForDownloadId(downloadId));
        pieFractionView.setTag(downloadId);

        mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() {
            @Override
            public void onDownloadError(String downloadId, JsonElement jsonElement) {
                pieFractionView.setVisibility(View.GONE);
                MatrixError error = JsonUtils.toMatrixError(jsonElement);

                if ((null != error) && error.isSupportedErrorCode()) {
                    Toast.makeText(VectorMediasViewerAdapter.this.mContext, error.getLocalizedMessage(),
                            Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onDownloadProgress(String aDownloadId, DownloadStats stats) {
                if (aDownloadId.equals(pieFractionView.getTag())) {
                    pieFractionView.setFraction(stats.mProgress);
                }
            }

            @Override
            public void onDownloadComplete(String aDownloadId) {
                if (aDownloadId.equals(pieFractionView.getTag())) {
                    pieFractionView.setVisibility(View.GONE);
                }
            }
        });
    }

    return view;
}

From source file:com.filemanager.free.adapters.DrawerAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (values.get(position).isSection()) {
        ImageView view = new ImageView(context);
        if (m.theme1 == 0)
            view.setImageResource(R.color.divider);
        else/*from w  ww  .j a  v  a  2  s . co m*/
            view.setImageResource(R.color.divider_dark);
        view.setClickable(false);
        view.setFocusable(false);
        if (m.theme1 == 0)
            view.setBackgroundColor(Color.WHITE);
        else
            view.setBackgroundResource(R.color.background_material_dark);
        view.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, m.dpToPx(17)));
        view.setPadding(0, m.dpToPx(8), 0, m.dpToPx(8));
        return view;
    } else {
        View view = inflater.inflate(R.layout.drawerrow, parent, false);
        final TextView txtTitle = (TextView) view.findViewById(R.id.firstline);
        final ImageView imageView = (ImageView) view.findViewById(R.id.icon);
        if (m.theme1 == 0) {
            view.setBackgroundResource(R.drawable.safr_ripple_white);
        } else {
            view.setBackgroundResource(R.drawable.safr_ripple_black);
        }
        view.setOnClickListener(new View.OnClickListener() {

            public void onClick(View p1) {
                m.selectItem(position);
            }
            // TODO: Implement this method

        });
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (!getItem(position).isSection())
                    // not to remove the first bookmark (storage) and permanent bookmarks
                    if (position > m.storage_count && position < values.size() - 7) {
                        EntryItem item = (EntryItem) getItem(position);
                        String path = (item).getPath();
                        if (DataUtils.containsBooks(new String[] { item.getTitle(), path }) != -1) {
                            m.renameBookmark((item).getTitle(), path);
                        } else if (path.startsWith("smb:/")) {
                            m.showSMBDialog(item.getTitle(), path, true);
                        }
                    } else if (position < m.storage_count) {
                        String path = ((EntryItem) getItem(position)).getPath();
                        if (!path.equals("/"))
                            new Futils().showProps(RootHelper.generateBaseFile(new File(path), true), m,
                                    m.theme1);
                    }

                // return true to denote no further processing
                return true;
            }
        });

        txtTitle.setText(((EntryItem) (values.get(position))).getTitle());
        imageView.setImageDrawable(getDrawable(position));
        imageView.clearColorFilter();
        if (myChecked.get(position)) {
            if (m.theme1 == 0)
                view.setBackgroundColor(Color.parseColor("#ffeeeeee"));
            else
                view.setBackgroundColor(Color.parseColor("#ff424242"));
            imageView.setColorFilter(fabskin);
            txtTitle.setTextColor(Color.parseColor(m.fabskin));
        } else {
            if (m.theme1 == 0) {
                imageView.setColorFilter(Color.parseColor("#666666"));
                txtTitle.setTextColor(ContextCompat.getColor(getContext(), android.R.color.black));
            } else {
                imageView.setColorFilter(Color.WHITE);
                txtTitle.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white));
            }
        }

        return view;
    }
}

From source file:com.audiokernel.euphonyrmt.fragments.NowPlayingFragment.java

/**
 * Run during fragment initialization, this sets up the cover art popup menu and the coverArt
 * ImageView.//from w  w  w  . ja va 2 s . c  om
 *
 * @param view The view to setup the coverArt ImageView in.
 * @return The resulting ImageView.
 */
private ImageView getCoverArt(final View view) {
    final ImageView coverArt = (ImageView) view.findViewById(R.id.albumCover);
    final PopupMenu coverMenu = new PopupMenu(mActivity, coverArt);
    final Menu menu = coverMenu.getMenu();

    coverArt.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            scrollToNowPlaying();
        }
    });

    menu.add(Menu.NONE, POPUP_COVER_BLACKLIST, Menu.NONE, R.string.otherCover);
    menu.add(Menu.NONE, POPUP_COVER_SELECTIVE_CLEAN, Menu.NONE, R.string.resetCover);
    coverMenu.setOnMenuItemClickListener(this);
    coverArt.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(final View v) {
            final boolean isConsumed;

            if (mCurrentSong != null) {
                menu.setGroupVisible(Menu.NONE, new AlbumInfo(mCurrentSong).isValid());
                coverMenu.show();
                isConsumed = true;
            } else {
                isConsumed = false;
            }

            return isConsumed;
        }
    });

    return coverArt;
}

From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java

public void refreshActionBarColumns() {

    int currentPosition = pager.getCurrentItem();

    layoutBackgroundColumnsBar.removeAllViews();

    int padding = (int) getResources().getDimension(R.dimen.default_padding);
    //int sizeButton = (int) getResources().getDimension(R.dimen.actionbar_columns_height);

    for (int i = 1; i < fragmentAdapter.getFragmentList().size(); i++) {

        ImageView view = new ImageView(this);
        view.setPadding(padding, padding, padding, padding);
        view.setImageBitmap(ColumnsUtils.getButtonWithTitle(this, fragmentAdapter.getFragmentList().get(i),
                true, currentPosition == i ? Color.GREEN : Color.BLACK));
        view.setTag(i);/*from  w  ww .j  a  v  a 2  s.co m*/
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (layoutMainOptionsColumns.getVisibility() != View.VISIBLE) {
                    showActionBarIndicatorAndMovePager((Integer) view.getTag());
                }
            }
        });
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                int pos = (Integer) view.getTag();
                int[] loc = new int[2];
                view.getLocationOnScreen(loc);
                showOptionsColumns(loc[0], pos, true);
                return false;
            }
        });
        layoutBackgroundColumnsBar.addView(view);
    }
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

@SuppressLint("RtlHardcoded")
private void drawTaskbar() {
    IconCache.getInstance(this).clearCache();

    // Initialize layout params
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    U.setCachedRotation(windowManager.getDefaultDisplay().getRotation());

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            PixelFormat.TRANSLUCENT);/*  w  w w.j  a v a2s.  co  m*/

    // Determine where to show the taskbar on screen
    switch (U.getTaskbarPosition(this)) {
    case "bottom_left":
        layoutId = R.layout.taskbar_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        positionIsVertical = false;
        break;
    case "bottom_vertical_left":
        layoutId = R.layout.taskbar_vertical;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        positionIsVertical = true;
        break;
    case "bottom_right":
        layoutId = R.layout.taskbar_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        positionIsVertical = false;
        break;
    case "bottom_vertical_right":
        layoutId = R.layout.taskbar_vertical;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        positionIsVertical = true;
        break;
    case "top_left":
        layoutId = R.layout.taskbar_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        positionIsVertical = false;
        break;
    case "top_vertical_left":
        layoutId = R.layout.taskbar_top_vertical;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        positionIsVertical = true;
        break;
    case "top_right":
        layoutId = R.layout.taskbar_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        positionIsVertical = false;
        break;
    case "top_vertical_right":
        layoutId = R.layout.taskbar_top_vertical;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        positionIsVertical = true;
        break;
    }

    // Initialize views
    int theme = 0;

    SharedPreferences pref = U.getSharedPreferences(this);
    switch (pref.getString("theme", "light")) {
    case "light":
        theme = R.style.AppTheme;
        break;
    case "dark":
        theme = R.style.AppTheme_Dark;
        break;
    }

    boolean altButtonConfig = pref.getBoolean("alt_button_config", false);

    ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme);
    layout = (LinearLayout) LayoutInflater.from(wrapper).inflate(layoutId, null);
    taskbar = (LinearLayout) layout.findViewById(R.id.taskbar);
    scrollView = (FrameLayout) layout.findViewById(R.id.taskbar_scrollview);

    if (altButtonConfig) {
        space = (Space) layout.findViewById(R.id.space_alt);
        layout.findViewById(R.id.space).setVisibility(View.GONE);
    } else {
        space = (Space) layout.findViewById(R.id.space);
        layout.findViewById(R.id.space_alt).setVisibility(View.GONE);
    }

    space.setOnClickListener(v -> toggleTaskbar());

    startButton = (ImageView) layout.findViewById(R.id.start_button);
    int padding;

    if (pref.getBoolean("app_drawer_icon", false)) {
        startButton.setImageDrawable(ContextCompat.getDrawable(this, R.mipmap.ic_launcher));
        padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding_alt);
    } else {
        startButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.all_apps_button_icon));
        padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding);
    }

    startButton.setPadding(padding, padding, padding, padding);
    startButton.setOnClickListener(ocl);
    startButton.setOnLongClickListener(view -> {
        openContextMenu();
        return true;
    });

    startButton.setOnGenericMotionListener((view, motionEvent) -> {
        if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY)
            openContextMenu();

        return false;
    });

    refreshInterval = (int) (Float.parseFloat(pref.getString("refresh_frequency", "2")) * 1000);
    if (refreshInterval == 0)
        refreshInterval = 100;

    sortOrder = pref.getString("sort_order", "false");
    runningAppsOnly = pref.getString("recents_amount", "past_day").equals("running_apps_only");

    switch (pref.getString("recents_amount", "past_day")) {
    case "past_day":
        searchInterval = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY;
        break;
    case "app_start":
        long oneDayAgo = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY;
        long appStartTime = pref.getLong("time_of_service_start", System.currentTimeMillis());
        long deviceStartTime = System.currentTimeMillis() - SystemClock.elapsedRealtime();
        long startTime = deviceStartTime > appStartTime ? deviceStartTime : appStartTime;

        searchInterval = startTime > oneDayAgo ? startTime : oneDayAgo;
        break;
    }

    Intent intent = new Intent("com.farmerbb.taskbar.HIDE_START_MENU");
    LocalBroadcastManager.getInstance(TaskbarService.this).sendBroadcast(intent);

    if (altButtonConfig) {
        button = (Button) layout.findViewById(R.id.hide_taskbar_button_alt);
        layout.findViewById(R.id.hide_taskbar_button).setVisibility(View.GONE);
    } else {
        button = (Button) layout.findViewById(R.id.hide_taskbar_button);
        layout.findViewById(R.id.hide_taskbar_button_alt).setVisibility(View.GONE);
    }

    try {
        button.setTypeface(Typeface.createFromFile("/system/fonts/Roboto-Regular.ttf"));
    } catch (RuntimeException e) {
        /* Gracefully fail */ }

    updateButton(false);
    button.setOnClickListener(v -> toggleTaskbar());

    LinearLayout buttonLayout = (LinearLayout) layout.findViewById(
            altButtonConfig ? R.id.hide_taskbar_button_layout_alt : R.id.hide_taskbar_button_layout);
    if (buttonLayout != null)
        buttonLayout.setOnClickListener(v -> toggleTaskbar());

    LinearLayout buttonLayoutToHide = (LinearLayout) layout.findViewById(
            altButtonConfig ? R.id.hide_taskbar_button_layout : R.id.hide_taskbar_button_layout_alt);
    if (buttonLayoutToHide != null)
        buttonLayoutToHide.setVisibility(View.GONE);

    int backgroundTint = U.getBackgroundTint(this);
    int accentColor = U.getAccentColor(this);

    dashboardButton = (FrameLayout) layout.findViewById(R.id.dashboard_button);
    navbarButtons = (LinearLayout) layout.findViewById(R.id.navbar_buttons);

    dashboardEnabled = pref.getBoolean("dashboard", false);
    if (dashboardEnabled) {
        layout.findViewById(R.id.square1).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square2).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square3).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square4).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square5).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square6).setBackgroundColor(accentColor);

        dashboardButton.setOnClickListener(v -> LocalBroadcastManager.getInstance(TaskbarService.this)
                .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_DASHBOARD")));
    } else
        dashboardButton.setVisibility(View.GONE);

    if (pref.getBoolean("button_back", false)) {
        navbarButtonsEnabled = true;

        ImageView backButton = (ImageView) layout.findViewById(R.id.button_back);
        backButton.setVisibility(View.VISIBLE);
        backButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_BACK);
            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);
        });
    }

    if (pref.getBoolean("button_home", false)) {
        navbarButtonsEnabled = true;

        ImageView homeButton = (ImageView) layout.findViewById(R.id.button_home);
        homeButton.setVisibility(View.VISIBLE);
        homeButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_HOME);
            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);
        });

        homeButton.setOnLongClickListener(v -> {
            Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
            voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            try {
                startActivity(voiceSearchIntent);
            } catch (ActivityNotFoundException e) {
                /* Gracefully fail */ }

            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);

            return true;
        });

        homeButton.setOnGenericMotionListener((view13, motionEvent) -> {
            if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                    && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
                voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                try {
                    startActivity(voiceSearchIntent);
                } catch (ActivityNotFoundException e) {
                    /* Gracefully fail */ }

                if (pref.getBoolean("hide_taskbar", true)
                        && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                    hideTaskbar(true);
            }
            return true;
        });
    }

    if (pref.getBoolean("button_recents", false)) {
        navbarButtonsEnabled = true;

        ImageView recentsButton = (ImageView) layout.findViewById(R.id.button_recents);
        recentsButton.setVisibility(View.VISIBLE);
        recentsButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_RECENTS);
            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);
        });

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            recentsButton.setOnLongClickListener(v -> {
                U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN);
                if (pref.getBoolean("hide_taskbar", true)
                        && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                    hideTaskbar(true);

                return true;
            });

            recentsButton.setOnGenericMotionListener((view13, motionEvent) -> {
                if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                        && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                    U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN);
                    if (pref.getBoolean("hide_taskbar", true)
                            && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                        hideTaskbar(true);
                }
                return true;
            });
        }
    }

    if (!navbarButtonsEnabled)
        navbarButtons.setVisibility(View.GONE);

    layout.setBackgroundColor(backgroundTint);
    layout.findViewById(R.id.divider).setBackgroundColor(accentColor);
    button.setTextColor(accentColor);

    if (isFirstStart && FreeformHackHelper.getInstance().isInFreeformWorkspace())
        showTaskbar(false);
    else if (!pref.getBoolean("collapsed", false) && pref.getBoolean("taskbar_active", false))
        toggleTaskbar();

    LocalBroadcastManager.getInstance(this).unregisterReceiver(showReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(tempShowReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(tempHideReceiver);

    LocalBroadcastManager.getInstance(this).registerReceiver(showReceiver,
            new IntentFilter("com.farmerbb.taskbar.SHOW_TASKBAR"));
    LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver,
            new IntentFilter("com.farmerbb.taskbar.HIDE_TASKBAR"));
    LocalBroadcastManager.getInstance(this).registerReceiver(tempShowReceiver,
            new IntentFilter("com.farmerbb.taskbar.TEMP_SHOW_TASKBAR"));
    LocalBroadcastManager.getInstance(this).registerReceiver(tempHideReceiver,
            new IntentFilter("com.farmerbb.taskbar.TEMP_HIDE_TASKBAR"));

    startRefreshingRecents();

    windowManager.addView(layout, params);

    isFirstStart = false;
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * Setup://from ww w . java2 s . c o m
 * <p/>
 * <ul>
 * <li>title of activity;</li>
 * <li>button go back;</li>
 * <li>button location;</li>
 * <li>button go forward;</li>
 * </ul>
 */
private void setupHeader() {
    if (mBtnGoHome != null)
        mBtnGoHome.setOnClickListener(mBtnGoHomeOnClickListener);
    if (mBtnBookmarkManager != null)
        mBtnBookmarkManager.setOnClickListener(mBtnBookmarkManagerOnClickListener);

    if (mIsSaveDialog) {
        getActivity().setTitle(R.string.anhuu_f5be488d_title_save_as);
    } else {
        switch (mFilterMode) {
        case BaseFile.FILTER_FILES_ONLY:
            getActivity().setTitle(getResources().getQuantityText(R.plurals.anhuu_f5be488d_title_choose_files,
                    mIsMultiSelection ? 2 : 1));
            break;
        case BaseFile.FILTER_FILES_AND_DIRECTORIES:
            getActivity().setTitle(getResources().getQuantityText(
                    R.plurals.anhuu_f5be488d_title_choose_files_directories, mIsMultiSelection ? 2 : 1));
            break;
        case BaseFile.FILTER_DIRECTORIES_ONLY:
            getActivity().setTitle(getResources().getQuantityText(
                    R.plurals.anhuu_f5be488d_title_choose_directories, mIsMultiSelection ? 2 : 1));
            break;
        }
    } // title of activity

    mViewGoBack.setEnabled(false);
    mViewGoBack.setOnClickListener(mBtnGoBackOnClickListener);

    mViewGoForward.setEnabled(false);
    mViewGoForward.setOnClickListener(mBtnGoForwardOnClickListener);

    for (ImageView v : new ImageView[] { mViewGoBack, mViewGoForward })
        v.setOnLongClickListener(mBtnGoBackForwardOnLongClickListener);
}