Example usage for android.widget ImageView setOnClickListener

List of usage examples for android.widget ImageView setOnClickListener

Introduction

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

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

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

Usage

From source file:cn.yunluosoft.tonglou.activity.ChatActivity.java

private void setUpView() {
    back.setOnClickListener(new OnClickListener() {

        @Override//from   w ww  .  j av a2  s . co  m
        public void onClick(View v) {
            finish();
        }
    });

    //      icon.setVisibility(View.VISIBLE);
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        messageInfo = (MessageInfo) getIntent().getSerializableExtra("info");
        m = getIntent().getIntExtra("dic", 0);

        if (messageInfo != null) {
            if (m == 1) {
                MessageInfo info = new MessageInfo(messageInfo.receiverUserId, messageInfo.senderUserId,
                        messageInfo.receiverImUserName, messageInfo.senderImUserName,
                        messageInfo.receiverHeadUrl, messageInfo.senderHeadUrl, messageInfo.receiverNickName,
                        messageInfo.senderNickName);
                messageInfo = info;
            }
            toChatUsername = messageInfo.receiverImUserName;
            // toChatUsername = getIntent().getStringExtra("userId");
            ((TextView) findViewById(R.id.title_title)).setText(messageInfo.receiverNickName);
            //            bitmapUtils.display(icon, messageInfo.receiverHeadUrl);
            //
            //            icon.setOnClickListener(new OnClickListener() {
            //
            //               @Override
            //               public void onClick(View v) {
            //                  Intent intent = new Intent(ChatActivity.this,
            //                        ConstactActivity.class);
            //                  intent.putExtra("id", messageInfo.receiverUserId);
            //                  intent.putExtra("name", messageInfo.receiverNickName);
            //                  intent.putExtra("flag", 155);
            //                  startActivityForResult(intent, 8226);
            //               }
            //            });

        }
        // toChatUsername = getIntent().getStringExtra("userId");
        // Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper
        // .getInstance()).getRobotList();
        // if (robotMap != null && robotMap.containsKey(toChatUsername)) {
        // isRobot = true;
        // String nick = robotMap.get(toChatUsername).getNick();
        // if (!TextUtils.isEmpty(nick)) {
        // ((TextView) findViewById(R.id.title_title)).setText(nick);
        // } else {
        // ((TextView) findViewById(R.id.title_title))
        // .setText(toChatUsername);
        // }
        // }
        // else {
        // UserUtils.setUserNick(toChatUsername,
        // (TextView) findViewById(R.id.title_title));
        // }
    } else {
        // ?
        messageInfo = (MessageInfo) getIntent().getSerializableExtra("info");
        if (messageInfo == null) {
            return;
        }

        MessageInfo info = new MessageInfo(ShareDataTool.getUserId(this), messageInfo.receiverUserId,
                ShareDataTool.getImUsername(this), messageInfo.receiverImUserName, ShareDataTool.getIcon(this),
                messageInfo.receiverHeadUrl, ShareDataTool.getNickname(this), messageInfo.receiverNickName);

        info.groupDynamicID = messageInfo.receiverUserId;
        messageInfo = info;
        toChatUsername = messageInfo.receiverImUserName;
        LogManager.LogShow("222222", "----------", LogManager.ERROR);
        group = EMGroupManager.getInstance().getGroup(toChatUsername);
        ((TextView) findViewById(R.id.title_title)).setText(messageInfo.receiverNickName);
        ImageView groupchat = (ImageView) findViewById(R.id.title_groupchat);
        groupchat.setVisibility(View.VISIBLE);
        groupchat.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ChatActivity.this, GroupInfoActivity.class);
                intent.putExtra("id", messageInfo.receiverHeadUrl);
                intent.putExtra("groupId", messageInfo.receiverUserId);
                startActivity(intent);

            }
        });
    }

    // for chatroom type, we only init conversation and create view adapter
    // on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // show forward message if the message is not null
        String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
        if (forward_msg_id != null) {
            // ?????
            forwardMessage(forward_msg_id);
        }
    }
}

From source file:com.android.dialer.DialtactsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.e(TAG, " --- onCreate(Bundle savedInstanceState) ---  start ");
    Trace.beginSection(TAG + " onCreate");
    View retView = null;/*from  w  w w  .j av  a2 s  .  com*/
    super.onCreateView(inflater, container, savedInstanceState);

    //??
    iControlDeleteBtn = (IControlDeleteBtn) getActivity();

    //mFirstLaunch = true;

    final Resources resources = getResources();
    int temp = resources.getDimensionPixelSize(R.dimen.floating_action_button_width);
    //?actionbar
    mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);

    Trace.beginSection(TAG + " setContentView");
    //setContentView(R.layout.dialtacts_activity);
    retView = inflater.inflate(R.layout.dialtacts_activity, container, false);
    Trace.endSection();

    Trace.beginSection(TAG + " setup Views");
    final ActionBar actionBar = getActivity().getActionBar();
    //actionbar?
    //actionBar.setCustomView(R.layout.dialtacts_actionbar);
    //actionBar.setDisplayShowCustomEnabled(true);
    TextView actionbarNameTxt = (TextView) actionBar.getCustomView().findViewById(R.id.actionbar_name);
    actionbarNameTxt.setOnClickListener(this);
    ImageView actionbarMenu = (ImageView) actionBar.getCustomView().findViewById(R.id.actionbar_menu);
    actionbarMenu.setOnClickListener(this);
    TextView editerToCalldetail = (TextView) actionBar.getCustomView()
            .findViewById(R.id.actionbar_call_dialtacts_action_editer);
    editerToCalldetail.setOnClickListener(this);
    TextView cancelTxt = (TextView) actionBar.getCustomView()
            .findViewById(R.id.actionbar_call_dialtacts_action_cancel);
    cancelTxt.setOnClickListener(this);
    actionbarNameTxt.setText(getString(R.string.all_calls));
    mSearchView = (EditText) actionBar.getCustomView().findViewById(R.id.edittext);
    mSearchView.setVisibility(View.GONE);
    mDialtactsActionBarController = new DialtactsActionBarController(actionbarMenu, editerToCalldetail,
            cancelTxt, actionbarNameTxt, this);
    //        actionBar.setBackgroundDrawable(null);

    SearchEditTextLayout searchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView()
            .findViewById(R.id.search_view_container);
    //        searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);

    //        mActionBarController = new DialtactsActionBarController(this, searchEditTextLayout);

    //        mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
    mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
    //        mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
    //        mSearchView.setOnClickListener(mSearchViewOnClickListener);
    //        searchEditTextLayout.findViewById(R.id.search_box_start_search)
    //                .setOnClickListener(mSearchViewOnClickListener);
    //        searchEditTextLayout.setOnClickListener(mSearchViewOnClickListener);
    //        searchEditTextLayout.setCallback(new SearchEditTextLayout.Callback() {
    //            @Override
    //            public void onBackButtonClicked() {
    //                onBackPressed();
    //            }
    //
    //            @Override
    //            public void onSearchViewClicked() {
    //                // Hide FAB, as the keyboard is shown.
    ////                mFloatingActionButtonController.scaleOut();
    //            }
    //        });
    mIsLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

    //        ImageButton optionsMenuButton =
    //                (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
    //        optionsMenuButton.setOnClickListener(this);
    //        mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
    //        optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());

    // Add the favorites fragment but only if savedInstanceState is null. Otherwise the
    // fragment manager is responsible for recreating it.
    //???
    if (savedInstanceState == null) {
        getChildFragmentManager().beginTransaction()
                .add(R.id.dialtacts_container, new DialpadFragment(getActivity()), TAG_DIALPAD_FRAGMENT)
                //                   .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
                .commit();
    } else {
        mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
        mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
        mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
        mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
        mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
        //            mActionBarController.restoreInstanceState(savedInstanceState);
    }

    final boolean isLayoutRtl = DialerUtils.isRtl();
    //??????
    if (mIsLandscape) {
        //??
        mSlideIn = AnimationUtils.loadAnimation(getActivity(),
                isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
        mSlideOut = AnimationUtils.loadAnimation(getActivity(),
                isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
    } else {
        mSlideIn = AnimationUtils.loadAnimation(getActivity(), R.anim.dialpad_slide_in_bottom);
        mSlideOut = AnimationUtils.loadAnimation(getActivity(), R.anim.dialpad_slide_out_bottom);
    }

    //        mSlideIn.setInterpolator(AnimUtils.EASE_IN);
    mSlideOut.setInterpolator(AnimUtils.EASE_OUT);

    mSlideIn.setAnimationListener(mSlideInListener);
    mSlideOut.setAnimationListener(mSlideOutListener);

    Trace.endSection();

    Trace.beginSection(TAG + " initialize smart dialing");
    mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(getActivity());
    SmartDialPrefix.initializeNanpSettings(getActivity());
    Trace.endSection();
    Trace.endSection();
    initFlushHandler();

    Log.e(TAG, " onCreate()  dialerFragment  " + mIsDialpadShown);
    return retView;
}

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

/**
 * Load the video items/*from  w w w. j  a v a 2s  .co m*/
 * @param view the page view
 * @param thumbnailUrl the thumbnail URL
 * @param videoUrl the video Url
 * @param videoMimeType the video mime type
 */
private void loadVideo(final int position, final View view, final String thumbnailUrl, final String videoUrl,
        final String videoMimeType) {
    final VideoView videoView = (VideoView) view.findViewById(R.id.media_slider_videoview);
    final ImageView thumbView = (ImageView) view.findViewById(R.id.media_slider_video_thumbnail);
    final ImageView playView = (ImageView) view.findViewById(R.id.media_slider_video_playView);

    displayVideoThumbnail(view, !videoView.isPlaying());

    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            mPlayingVideoView = null;
            displayVideoThumbnail(view, true);
        }
    });

    // the video is renderer in DSA so trap the on click on the video view parent
    ((View) videoView.getParent()).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            stopPlayingVideo();
            displayVideoThumbnail(view, true);
        }
    });

    // manage video error cases
    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            mPlayingVideoView = null;
            displayVideoThumbnail(view, true);
            return false;
        }
    });

    // init the thumbnail views
    mMediasCache.loadBitmap(mSession.getHomeserverConfig(), thumbView, thumbnailUrl, 0, 0, null, null);

    playView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // init the video view only if there is a valid file
            // check if the media has been downloaded
            File srcFile = mMediasCache.mediaCacheFile(videoUrl, videoMimeType);

            if (null != srcFile) {
                playVideo(view, videoView, videoUrl, videoMimeType);
            } else {
                mAutoPlayItemAt = position;
                downloadVideo(view, position);
            }
        }
    });
}

From source file:com.com.easemob.chatuidemo.adapter.MessageAdapter.java

/**
 * /* w w  w. j ava 2s.c  om*/
 *
 * @param localThumb
 *            
 * @param iv
 * @param thumbnailUrl
 *            
 * @param message
 */
private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
                EMLog.d(TAG, "video view is on click");
                Intent intent = new Intent(activity, ShowVideoActivity.class);
                intent.putExtra("localpath", videoBody.getLocalUrl());
                intent.putExtra("secret", videoBody.getSecret());
                intent.putExtra("remotepath", videoBody.getRemoteUrl());
                if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    message.isAcked = true;
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);

            }
        });

    } else {
        new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv, activity, message, this);
    }

}

From source file:com.samknows.measurement.activity.SamKnowsAggregateStatViewerActivity.java

private void buttonSetup() {

    // button setup

    Button execute_button;/*from  w  ww.j a v  a 2 s  .co  m*/
    execute_button = (Button) subview.findViewById(R.id.btnRunTest);
    execute_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(SamKnowsAggregateStatViewerActivity.this,
                    SamKnowsTestViewerActivity.class);

            startActivityForResult(intent, 1);
            overridePendingTransition(R.anim.transition_in, R.anim.transition_out);

        }
    });

    Button run_now_choice_button;
    run_now_choice_button = (Button) findViewById(R.id.btnRunTestChoice);

    run_now_choice_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            RunChoice();
        }
    });

    Button timeperiod_button;
    timeperiod_button = (Button) findViewById(R.id.btn_timeperiod);

    timeperiod_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            SingleChoice();
        }
    });

    LinearLayout timeperiod_button2;
    timeperiod_button2 = (LinearLayout) findViewById(R.id.timeperiod_header);

    timeperiod_button2.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            SingleChoice();
        }
    });

    // page turn navigation button
    ImageView page_right = (ImageView) findViewById(R.id.page_turn_right_agg);

    page_right.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            viewPager = (ViewPager) findViewById(R.id.viewPager);
            viewPager.setCurrentItem(1, true);
        }
    });

    // grid navigation buttons

    Button download_grid_right_button;
    download_grid_right_button = (Button) subview.findViewById(R.id.btn_download_grid_right);
    download_grid_right_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (download_page_index < total_download_archive_records - ITEMS_PER_PAGE) {
                download_page_index = download_page_index + ITEMS_PER_PAGE;
            }

            clearGrid(R.id.agggregate_test1_grid);
            loadDownloadGrid(TestResult.DOWNLOAD_TEST_ID, R.id.agggregate_test1_grid, download_page_index,
                    ITEMS_PER_PAGE);

        }
    });

    Button download_grid_left_button;
    download_grid_left_button = (Button) subview.findViewById(R.id.btn_download_grid_left);
    download_grid_left_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (download_page_index > 0) {
                download_page_index = download_page_index - ITEMS_PER_PAGE;
            }
            clearGrid(R.id.agggregate_test1_grid);
            loadDownloadGrid(TestResult.DOWNLOAD_TEST_ID, R.id.agggregate_test1_grid, download_page_index,
                    ITEMS_PER_PAGE);

        }
    });

    Button upload_grid_right_button;
    upload_grid_right_button = (Button) subview.findViewById(R.id.btn_upload_grid_right);
    upload_grid_right_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (upload_page_index < total_upload_archive_records - ITEMS_PER_PAGE) {
                upload_page_index = upload_page_index + ITEMS_PER_PAGE;
            }

            clearGrid(R.id.agggregate_test2_grid);
            loadDownloadGrid(TestResult.UPLOAD_TEST_ID, R.id.agggregate_test2_grid, upload_page_index,
                    ITEMS_PER_PAGE);

        }
    });

    Button upload_grid_left_button;
    upload_grid_left_button = (Button) subview.findViewById(R.id.btn_upload_grid_left);
    upload_grid_left_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (upload_page_index > 0) {
                upload_page_index = upload_page_index - ITEMS_PER_PAGE;
            }
            clearGrid(R.id.agggregate_test2_grid);
            loadDownloadGrid(TestResult.UPLOAD_TEST_ID, R.id.agggregate_test2_grid, upload_page_index,
                    ITEMS_PER_PAGE);

        }
    });

    Button latency_grid_right_button;
    latency_grid_right_button = (Button) subview.findViewById(R.id.btn_latency_grid_right);
    latency_grid_right_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (latency_page_index < total_latency_archive_records - ITEMS_PER_PAGE) {
                latency_page_index = latency_page_index + ITEMS_PER_PAGE;
            }

            clearGrid(R.id.agggregate_test3_grid);
            loadDownloadGrid(TestResult.LATENCY_TEST_ID, R.id.agggregate_test3_grid, latency_page_index,
                    ITEMS_PER_PAGE);

        }
    });

    Button latency_grid_left_button;
    latency_grid_left_button = (Button) subview.findViewById(R.id.btn_latency_grid_left);
    latency_grid_left_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (latency_page_index > 0) {
                latency_page_index = latency_page_index - ITEMS_PER_PAGE;
            }
            clearGrid(R.id.agggregate_test3_grid);
            loadDownloadGrid(TestResult.LATENCY_TEST_ID, R.id.agggregate_test3_grid, latency_page_index,
                    ITEMS_PER_PAGE);

        }
    });

    Button packetloss_grid_right_button;
    packetloss_grid_right_button = (Button) subview.findViewById(R.id.btn_packetloss_grid_right);
    packetloss_grid_right_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (packetloss_page_index < total_packetloss_archive_records - ITEMS_PER_PAGE) {
                packetloss_page_index = packetloss_page_index + ITEMS_PER_PAGE;
            }

            clearGrid(R.id.agggregate_test4_grid);
            loadDownloadGrid(TestResult.PACKETLOSS_TEST_ID, R.id.agggregate_test4_grid, packetloss_page_index,
                    ITEMS_PER_PAGE);

        }
    });

    Button packetloss_grid_left_button;
    packetloss_grid_left_button = (Button) subview.findViewById(R.id.btn_packetloss_grid_left);
    packetloss_grid_left_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (packetloss_page_index > 0) {
                packetloss_page_index = packetloss_page_index - ITEMS_PER_PAGE;
            }
            clearGrid(R.id.agggregate_test4_grid);
            loadDownloadGrid(TestResult.PACKETLOSS_TEST_ID, R.id.agggregate_test4_grid, packetloss_page_index,
                    ITEMS_PER_PAGE);

        }
    });

    Button jitter_grid_right_button;
    jitter_grid_right_button = (Button) subview.findViewById(R.id.btn_jitter_grid_right);
    jitter_grid_right_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (jitter_page_index < total_jitter_archive_records - ITEMS_PER_PAGE) {
                jitter_page_index = jitter_page_index + ITEMS_PER_PAGE;
            }

            clearGrid(R.id.agggregate_test5_grid);
            loadDownloadGrid(TestResult.JITTER_TEST_ID, R.id.agggregate_test5_grid, jitter_page_index,
                    ITEMS_PER_PAGE);

        }
    });

    Button jitter_grid_left_button;
    jitter_grid_left_button = (Button) subview.findViewById(R.id.btn_jitter_grid_left);
    jitter_grid_left_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (jitter_page_index > 0) {
                jitter_page_index = jitter_page_index - ITEMS_PER_PAGE;
            }
            clearGrid(R.id.agggregate_test5_grid);
            loadDownloadGrid(TestResult.JITTER_TEST_ID, R.id.agggregate_test5_grid, jitter_page_index,
                    ITEMS_PER_PAGE);

        }
    });

    // toggle buttons

    TableLayout button;
    button = (TableLayout) findViewById(R.id.download_header);
    ImageView button_iv = (ImageView) findViewById(R.id.btn_download_toggle);

    button.setOnClickListener(this);
    button_iv.setOnClickListener(this);

    TableLayout button2;
    button2 = (TableLayout) subview.findViewById(R.id.upload_header);
    ImageView button2_iv = (ImageView) findViewById(R.id.btn_upload_toggle);

    button2.setOnClickListener(this);
    button2_iv.setOnClickListener(this);

    TableLayout button3;
    button3 = (TableLayout) subview.findViewById(R.id.latency_header);
    ImageView button3_iv = (ImageView) findViewById(R.id.btn_latency_toggle);

    button3.setOnClickListener(this);
    button3_iv.setOnClickListener(this);

    TableLayout button4;
    button4 = (TableLayout) subview.findViewById(R.id.packetloss_header);
    ImageView button4_iv = (ImageView) findViewById(R.id.btn_packetloss_toggle);

    button4.setOnClickListener(this);
    button4_iv.setOnClickListener(this);

    TableLayout button5;
    button5 = (TableLayout) subview.findViewById(R.id.jitter_header);
    ImageView button5_iv = (ImageView) findViewById(R.id.btn_jitter_toggle);

    button5.setOnClickListener(this);
    button5_iv.setOnClickListener(this);

}

From source file:com.esri.android.mapsapp.MapFragment.java

/**
 * Displays the search view layout//  ww w . j  ava  2s .co m
 * 
 */
private void showSearchBoxLayout() {

    // Inflating the layout from the xml file
    mSearchBox = mInflater.inflate(R.layout.searchview, null);
    // Inflate navigation drawer button on SearchView
    navButton = (ImageButton) mSearchBox.findViewById(R.id.btn_nav_menu);
    // Get the navigation drawer from Activity
    mDrawerLayout = (DrawerLayout) getActivity().findViewById(R.id.maps_app_activity_drawer_layout);
    mDrawerList = (ListView) getActivity().findViewById(R.id.maps_app_activity_left_drawer);

    // Set click listener to open/close drawer
    navButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
                mDrawerLayout.closeDrawer(mDrawerList);
            } else {
                mDrawerLayout.openDrawer(mDrawerList);
            }

        }
    });

    // Setting the layout parameters to the layout
    mSearchBox.setLayoutParams(mlayoutParams);

    // Initializing the searchview and the image view
    mSearchview = (SearchView) mSearchBox.findViewById(R.id.searchView1);

    ImageView iv_route = (ImageView) mSearchBox.findViewById(R.id.imageView1);

    mSearchview.setIconifiedByDefault(false);
    mSearchview.setQueryHint(SEARCH_HINT);

    applySuggestionCursor();

    //      navButton = (Button)mSearchBox.findViewById(R.id.navbutton);

    // Adding the layout to the map conatiner
    mMapContainer.addView(mSearchBox);

    // Setup the listener for the route onclick
    iv_route.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            showRoutingDialogFragment();

        }
    });

    // Setup the listener when the search button is pressed on the keyboard
    mSearchview.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            onSearchButtonClicked(query);
            mSearchview.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (mLocator == null)
                return false;
            getSuggestions(newText);
            return true;
        }
    });

    // Add the compass after getting the height of the layout
    mSearchBox.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            addCompass(mSearchBox.getHeight());
            mSearchBox.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }

    });

    mSearchview.setOnSuggestionListener(new SearchView.OnSuggestionListener() {

        @Override
        public boolean onSuggestionSelect(int position) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int position) {
            // Obtain the content of the selected suggesting place via cursor
            MatrixCursor cursor = (MatrixCursor) mSearchview.getSuggestionsAdapter().getItem(position);
            int indexColumnSuggestion = cursor.getColumnIndex(COLUMN_NAME_ADDRESS);
            final String address = cursor.getString(indexColumnSuggestion);

            suggestionClickFlag = true;
            // Find the Location of the suggestion
            new FindLocationTask(address).execute(address);

            cursor.close();

            return true;
        }
    });

}

From source file:de.baumann.hhsmoodle.data_schedule.Schedule_Fragment.java

private void setScheduleList() {

    final int line = sharedPref.getInt("getLine", 1);
    //display data
    final int layoutstyle = R.layout.list_item_schedule;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.att_notes,
            R.id.textView_create_notes };
    String[] column = new String[] { "schedule_title", "schedule_content", "schedule_attachment",
            "schedule_creation" };
    final Cursor row = db.fetchAllData();
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override//www. j  a va 2s .c om
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title"));
            final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content"));
            final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon"));
            final String schedule_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("schedule_attachment"));
            final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation"));
            final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);

            if (position == line) {
                v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorAccent_trans));
            } else {
                v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.color_trans));
            }

            if (schedule_title.equals(getActivity().getString(R.string.schedule_weekend))
                    || schedule_title.equals(getActivity().getString(R.string.schedule_def_title))) {
                sharedPref.edit().putString("hour_" + schedule_id, "false").apply();
            } else {
                sharedPref.edit().putString("hour_" + schedule_id, "true").apply();
            }

            Subjects_helper.switchIcon(getActivity(), schedule_icon, "schedule_color", iv_icon);

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red),
                            new helper_main.Item(getString(R.string.subjects_color_pink),
                                    R.drawable.circle_pink),
                            new helper_main.Item(getString(R.string.subjects_color_purple),
                                    R.drawable.circle_purple),
                            new helper_main.Item(getString(R.string.subjects_color_blue),
                                    R.drawable.circle_blue),
                            new helper_main.Item(getString(R.string.subjects_color_teal),
                                    R.drawable.circle_teal),
                            new helper_main.Item(getString(R.string.subjects_color_green),
                                    R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.subjects_color_lime),
                                    R.drawable.circle_lime),
                            new helper_main.Item(getString(R.string.subjects_color_yellow),
                                    R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.subjects_color_orange),
                                    R.drawable.circle_orange),
                            new helper_main.Item(getString(R.string.subjects_color_brown),
                                    R.drawable.circle_brown),
                            new helper_main.Item(getString(R.string.subjects_color_grey),
                                    R.drawable.circle_grey), };

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(getActivity())
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "1",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "2",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "3",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 3) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "4",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 4) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "5",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 5) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "6",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 6) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "7",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 7) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "8",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 8) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "9",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 9) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "10",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    } else if (item == 10) {
                                        db.update(Integer.parseInt(_id), schedule_title, schedule_content, "11",
                                                schedule_attachment, schedule_creation, schedule_id);
                                        setScheduleList();
                                    }
                                }
                            }).show();
                }
            });

            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_scheduleBY", "schedule_title");
    sharedPref.edit().putString("filter_scheduleBY", "schedule_title").apply();
    filter.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title"));

            final CharSequence[] options = { getString(R.string.schedule_todo),
                    getString(R.string.schedule_notes) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.schedule_todo))) {
                                sharedPref.edit().putString("filter_todo_subject", schedule_title).apply();
                                new Handler().postDelayed(new Runnable() {
                                    public void run() {
                                        helper_main.switchToActivity(getActivity(), Popup_todo.class, false);
                                    }
                                }, 200);
                            }
                            if (options[item].equals(getString(R.string.schedule_notes))) {
                                sharedPref.edit().putString("filter_note_subject", schedule_title).apply();
                                new Handler().postDelayed(new Runnable() {
                                    public void run() {
                                        helper_main.switchToActivity(getActivity(), Popup_note.class, false);
                                    }
                                }, 200);
                            }
                        }
                    }).show();
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title"));
            final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content"));
            final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon"));
            final String schedule_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("schedule_attachment"));
            final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation"));
            final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_menu),
                    getString(R.string.bookmark_createNote), getString(R.string.count_create),
                    getString(R.string.bookmark_createEvent) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @SuppressWarnings("ConstantConditions")
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                final CharSequence[] options = { getString(R.string.schedule_fromSubjectList),
                                        getString(R.string.todo_from_new) };
                                new AlertDialog.Builder(getActivity()).setPositiveButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        }).setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item]
                                                        .equals(getString(R.string.schedule_fromSubjectList))) {
                                                    sharedPref.edit().putString("edit_yes", "true")
                                                            .putInt("scroll", Integer.parseInt(schedule_id))
                                                            .putString("handleSubjectCreation",
                                                                    schedule_creation)
                                                            .putString("handleSubject_id", schedule_id)
                                                            .putString("handle_id", _id).apply();
                                                    helper_main.switchToActivity(getActivity(),
                                                            Popup_subjects.class, false);
                                                }

                                                if (options[item].equals(getString(R.string.todo_from_new))) {

                                                    LayoutInflater inflater = getActivity().getLayoutInflater();

                                                    final ViewGroup nullParent = null;
                                                    View dialogView = inflater
                                                            .inflate(R.layout.dialog_edit_subject, nullParent);

                                                    final EditText titleInput = (EditText) dialogView
                                                            .findViewById(R.id.subject_title_);
                                                    titleInput.setSelection(titleInput.getText().length());
                                                    titleInput.setText(schedule_title);
                                                    final EditText teacherInput = (EditText) dialogView
                                                            .findViewById(R.id.subject_teacher);
                                                    teacherInput.setText(schedule_content);
                                                    final EditText roomInput = (EditText) dialogView
                                                            .findViewById(R.id.subject_room);
                                                    roomInput.setText(schedule_attachment);

                                                    helper_main.showKeyboard(getActivity(), titleInput);

                                                    final ImageButton be = (ImageButton) dialogView
                                                            .findViewById(R.id.imageButtonPri);
                                                    assert be != null;

                                                    Subjects_helper.switchIcon(getActivity(), schedule_icon,
                                                            "schedule_color", be);

                                                    be.setOnClickListener(new View.OnClickListener() {

                                                        @Override
                                                        public void onClick(View arg0) {

                                                            final helper_main.Item[] items = {
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_red),
                                                                            R.drawable.circle_red),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_pink),
                                                                            R.drawable.circle_pink),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_purple),
                                                                            R.drawable.circle_purple),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_blue),
                                                                            R.drawable.circle_blue),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_teal),
                                                                            R.drawable.circle_teal),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_green),
                                                                            R.drawable.circle_green),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_lime),
                                                                            R.drawable.circle_lime),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_yellow),
                                                                            R.drawable.circle_yellow),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_orange),
                                                                            R.drawable.circle_orange),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_brown),
                                                                            R.drawable.circle_brown),
                                                                    new helper_main.Item(getString(
                                                                            R.string.subjects_color_grey),
                                                                            R.drawable.circle_grey), };

                                                            ListAdapter adapter = new ArrayAdapter<helper_main.Item>(
                                                                    getActivity(),
                                                                    android.R.layout.select_dialog_item,
                                                                    android.R.id.text1, items) {
                                                                @NonNull
                                                                public View getView(int position,
                                                                        View convertView,
                                                                        @NonNull ViewGroup parent) {
                                                                    //Use super class to create the View
                                                                    View v = super.getView(position,
                                                                            convertView, parent);
                                                                    TextView tv = (TextView) v
                                                                            .findViewById(android.R.id.text1);
                                                                    tv.setTextSize(18);
                                                                    tv.setCompoundDrawablesWithIntrinsicBounds(
                                                                            items[position].icon, 0, 0, 0);
                                                                    //Add margin between image and text (support various screen densities)
                                                                    int dp5 = (int) (24
                                                                            * getActivity().getResources()
                                                                                    .getDisplayMetrics().density
                                                                            + 0.5f);
                                                                    tv.setCompoundDrawablePadding(dp5);

                                                                    return v;
                                                                }
                                                            };

                                                            new android.app.AlertDialog.Builder(getActivity())
                                                                    .setPositiveButton(R.string.toast_cancel,
                                                                            new DialogInterface.OnClickListener() {

                                                                                public void onClick(
                                                                                        DialogInterface dialog,
                                                                                        int whichButton) {
                                                                                    dialog.cancel();
                                                                                }
                                                                            })
                                                                    .setAdapter(adapter,
                                                                            new DialogInterface.OnClickListener() {
                                                                                public void onClick(
                                                                                        DialogInterface dialog,
                                                                                        int item) {
                                                                                    if (item == 0) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_red);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "1")
                                                                                                .apply();
                                                                                    } else if (item == 1) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_pink);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "2")
                                                                                                .apply();
                                                                                    } else if (item == 2) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_purple);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "3")
                                                                                                .apply();
                                                                                    } else if (item == 3) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_blue);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "4")
                                                                                                .apply();
                                                                                    } else if (item == 4) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_teal);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "5")
                                                                                                .apply();
                                                                                    } else if (item == 5) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_green);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "6")
                                                                                                .apply();
                                                                                    } else if (item == 6) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_lime);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "7")
                                                                                                .apply();
                                                                                    } else if (item == 7) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_yellow);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "8")
                                                                                                .apply();
                                                                                    } else if (item == 8) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_orange);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "9")
                                                                                                .apply();
                                                                                    } else if (item == 9) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_brown);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "10")
                                                                                                .apply();
                                                                                    } else if (item == 10) {
                                                                                        be.setImageResource(
                                                                                                R.drawable.circle_grey);
                                                                                        sharedPref.edit()
                                                                                                .putString(
                                                                                                        "schedule_color",
                                                                                                        "11")
                                                                                                .apply();
                                                                                    }
                                                                                }
                                                                            })
                                                                    .show();
                                                        }
                                                    });

                                                    android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                                                            getActivity());
                                                    builder.setTitle(R.string.subjects_edit);
                                                    builder.setView(dialogView);
                                                    builder.setPositiveButton(R.string.toast_yes,
                                                            new DialogInterface.OnClickListener() {

                                                                public void onClick(DialogInterface dialog,
                                                                        int whichButton) {

                                                                    String inputTitle = titleInput.getText()
                                                                            .toString().trim();
                                                                    String inputTeacher = teacherInput.getText()
                                                                            .toString().trim();
                                                                    String inputRoom = roomInput.getText()
                                                                            .toString().trim();

                                                                    db.update(Integer.parseInt(_id), inputTitle,
                                                                            inputTeacher,
                                                                            sharedPref.getString(
                                                                                    "schedule_color", ""),
                                                                            inputRoom, schedule_creation,
                                                                            schedule_id);
                                                                    dialog.dismiss();
                                                                    setScheduleList();
                                                                    lv.setSelection(
                                                                            Integer.parseInt(schedule_id) - 1);
                                                                    Snackbar.make(lv, R.string.bookmark_added,
                                                                            Snackbar.LENGTH_SHORT).show();
                                                                }
                                                            });
                                                    builder.setNegativeButton(R.string.toast_cancel,
                                                            new DialogInterface.OnClickListener() {

                                                                public void onClick(DialogInterface dialog,
                                                                        int whichButton) {
                                                                    dialog.cancel();
                                                                }
                                                            });

                                                    final android.support.v7.app.AlertDialog dialog2 = builder
                                                            .create();
                                                    dialog2.show();
                                                }

                                            }
                                        }).show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.update(Integer.parseInt(_id),
                                                        getString(R.string.schedule_def_teacher),
                                                        getString(R.string.schedule_def_teacher), "11",
                                                        getString(R.string.schedule_def_teacher),
                                                        schedule_creation, schedule_id);
                                                setScheduleList();
                                                lv.setSelection(Integer.parseInt(schedule_id) - 1);
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {
                                Todo_helper.newTodo(getActivity(), schedule_title, schedule_content,
                                        getActivity().getString(R.string.note_content));
                            }

                            if (options[item].equals(getString(R.string.count_create))) {
                                Count_helper.newCount(getActivity(), schedule_title, schedule_content,
                                        getActivity().getString(R.string.note_content), false);
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), schedule_title,
                                        schedule_content);
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                Notes_helper.newNote(getActivity(), schedule_title, schedule_content, "", "",
                                        "", "");
                            }

                        }
                    }).show();
            return true;
        }
    });

    scrollToNow();
}

From source file:com.tafayor.selfcamerashot.ui.AboutFragment.java

private void initView(View view) {

    TextView appTitleView = (TextView) view.findViewById(R.id.app_title);
    Button upgradeBtn = (Button) view.findViewById(R.id.btn_upgrade);
    Button rateBtn = (Button) view.findViewById(R.id.btn_rate);
    Button sendEmailBtn = (Button) view.findViewById(R.id.btn_sendEmail);
    Button legalNoticesBtn = (Button) view.findViewById(R.id.btn_legalNotices);
    TextView versionView = (TextView) view.findViewById(R.id.tv_version);
    Button contributionsBtn = (Button) view.findViewById(R.id.btn_contributions);
    Button otherAppsBtn = (Button) view.findViewById(R.id.btn_otherApps);
    ImageView facebookBtn = (ImageView) view.findViewById(R.id.social_facebook);
    ImageView gplusBtn = (ImageView) view.findViewById(R.id.social_gplus);
    ImageView twitterBtn = (ImageView) view.findViewById(R.id.social_twitter);

    versionView.setText("v" + AppHelper.getVersionName(mContext));

    if (App.isPro()) {
        upgradeBtn.setVisibility(View.GONE);
        appTitleView.setText(getResources().getString(R.string.app_name_pro));
    } else {/*from   w  w w  .  j a v a  2 s  . co  m*/
        upgradeBtn.setVisibility(View.VISIBLE);
        appTitleView.setText(getResources().getString(R.string.app_name));
    }

    upgradeBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((FragmentWrapperActivity) getActivity()).getUpgrader().upgrade();
        }
    });

    rateBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MarketHelper.showProductPage(mContext);
        }
    });

    sendEmailBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FeedbackHelper.showSendEmailView(mContext, App.VENDOR_EMAIL);
        }
    });

    legalNoticesBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showLegalNotices();
        }
    });

    contributionsBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showContributions();
        }
    });

    otherAppsBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MarketHelper.showVendorPage(mContext);
        }
    });

    facebookBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IntentHelper.openURL(mContext, "www.facebook.com");
        }
    });

    gplusBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IntentHelper.openURL(mContext, "https://goo.gl/IJpuEv");
        }
    });

    twitterBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IntentHelper.openURL(mContext, "twitter.com/joselikoxulo");
        }
    });
}

From source file:com.zertinteractive.wallpaper.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.e(LOG_TAG, "onCreate()");
    setContentView(R.layout.activity_main);
    context = this;
    checkPermission();/* w ww. j  av a2  s .  co m*/
    DetailActivity.setContext(this);
    initDownloadComponents();
    downloadTestImage();
    initSearchGridView();

    progressBar = (ProgressBar) findViewById(R.id.progressBarImageSearch);
    progressBar.setVisibility(View.GONE);

    searchQueryButton = (ImageView) findViewById(R.id.search_query_ok);
    searchQueryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            in.hideSoftInputFromWindow(searchKey.getApplicationWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            searchActionMethod();
        }
    });

    searchKey = (EditText) findViewById(R.id.search_key);
    searchKey.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            //                if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
            //                    InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            //                    in.hideSoftInputFromWindow(searchKey.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            //                    Log.e("SEARCH", searchKey.getText().toString());
            //                }
            searchActionMethod();
            return false;
        }
    });

    searchQueryClear = (ImageView) findViewById(R.id.search_query_clear);
    searchQueryClear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchKey.setText("");
        }
    });

    // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in
    // values/strings.xml.
    mAdView = (AdView) findViewById(R.id.adView);
    mAdView.setVisibility(View.GONE);

    //        mAdView.setScaleX(1.3f);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();

    // Start loading the ad in sthe background.
    mAdView.loadAd(adRequest);
    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            mAdView.setVisibility(View.VISIBLE);
        }
    });

    //        AdView mAdView = (AdView) findViewById(R.id.adView);
    //        AdRequest adRequest = new AdRequest.Builder().build();
    //        mAdView.loadAd(adRequest);

    initWallpaperLists();
    initRecyclerView(GRIDVIEW_COLUMN);
    initSearchView();
    initFab();
    initToolbar();
    setupDrawerLayout();
    setCategorySutter(false);
    categorySutterChange(1200);
    //        setNotification();

    setupWindowAnimations();

    reminderCount = 0;

    timerTasks = new TimerTasks(context);

    timerTasks.startTimerTask();

    currentWallpaperCategory = WallpaperCategory.ALL;
    DetailActivity.checkDir();

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        setRecyclerAdapter(recyclerView, 0);
        currentWallpaperCategory = WallpaperCategory.ALL;
    }

    LinearLayout categoryHappyWallpaper = (LinearLayout) findViewById(R.id.category_happy);
    LinearLayout categorySadWallpaper = (LinearLayout) findViewById(R.id.category_sad);
    LinearLayout categorySurpriseWallpaper = (LinearLayout) findViewById(R.id.category_surprise);
    LinearLayout categoryAngryWallpaper = (LinearLayout) findViewById(R.id.category_angry);
    LinearLayout categoryFunnyWallpaper = (LinearLayout) findViewById(R.id.category_funny);
    LinearLayout categoryAmazedWallpaper = (LinearLayout) findViewById(R.id.category_amazed);
    categoryHappyWallpaper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setRecyclerAdapter(recyclerView, 1);
            currentWallpaperCategory = WallpaperCategory.HAPPY;
        }
    });
    categorySadWallpaper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setRecyclerAdapter(recyclerView, 2);
            currentWallpaperCategory = WallpaperCategory.SAD;
        }
    });
    categorySurpriseWallpaper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setRecyclerAdapter(recyclerView, 3);
            currentWallpaperCategory = WallpaperCategory.SURPRISE;
        }
    });
    categoryAngryWallpaper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setRecyclerAdapter(recyclerView, 4);
            currentWallpaperCategory = WallpaperCategory.ANGRY;
        }
    });
    categoryFunnyWallpaper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setRecyclerAdapter(recyclerView, 5);
            currentWallpaperCategory = WallpaperCategory.FUNNY;
        }
    });
    categoryAmazedWallpaper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setRecyclerAdapter(recyclerView, 6);
            currentWallpaperCategory = WallpaperCategory.AMAZED;
        }
    });

    ImageView category_daily = (ImageView) findViewById(R.id.category_daily);
    ImageView category_featured = (ImageView) findViewById(R.id.category_featured);
    ImageView category_favourite = (ImageView) findViewById(R.id.category_favourite);
    category_daily.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setRecyclerAdapter(recyclerView, 7);
            currentWallpaperCategory = WallpaperCategory.DAILY;
        }
    });
    category_featured.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setRecyclerAdapter(recyclerView, 8);
            currentWallpaperCategory = WallpaperCategory.FEATURED;
        }
    });
    category_favourite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setRecyclerAdapter(recyclerView, 9);
            currentWallpaperCategory = WallpaperCategory.FAVOURITE;
        }
    });

    LinearLayout categoryWallpaper = (LinearLayout) findViewById(R.id.categoryButtonArrow);
    LinearLayout categoryAllWallpaper = (LinearLayout) findViewById(R.id.categoryWallpaper);
    LinearLayout kidsyWallpaperAction = (LinearLayout) findViewById(R.id.kidsyWallpaperAction);
    LinearLayout keepCalmWallpaperAction = (LinearLayout) findViewById(R.id.keepCalmWallpaperAction);
    LinearLayout romanticWallpaperAction = (LinearLayout) findViewById(R.id.romanticWallpaperAction);
    LinearLayout materialWallpaperAction = (LinearLayout) findViewById(R.id.materialWallpaperAction);
    categoryAllWallpaper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setRecyclerAdapter(recyclerView, 0);
            currentWallpaperCategory = WallpaperCategory.ALL;
        }
    });
    categoryWallpaper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            categorySutterChange(600);
            //                YoYo.with(Techniques.RotateAntiClockWise)
            //                        .duration(300)
            //                        .interpolate(new AccelerateDecelerateInterpolator())
            //                        .withListener(new Animator.AnimatorListener() {
            //                            @Override
            //                            public void onAnimationStart(Animator animation) {
            //
            //                            }
            //
            //                            @Override
            //                            public void onAnimationEnd(Animator animation) {
            //
            //                            }
            //
            //                            @Override
            //                            public void onAnimationCancel(Animator animation) {
            //                                Toast.makeText(MainActivity.this, "canceled", Toast.LENGTH_SHORT).show();
            //                            }
            //
            //                            @Override
            //                            public void onAnimationRepeat(Animator animation) {
            //
            //                            }
            //                        })
            //                        .playOn(findViewById(R.id.categoryButtonArrow));
        }
    });
    kidsyWallpaperAction.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openUri(PLAY_STORE_URL);
        }
    });
    keepCalmWallpaperAction.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openUri(PLAY_STORE_URL);
        }
    });
    romanticWallpaperAction.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openUri(PLAY_STORE_URL);
        }
    });
    materialWallpaperAction.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openUri(PLAY_STORE_URL);
        }
    });

    //        Button button = (Button) findViewById(R.id.testButton);
    //        button.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-LightItalic.ttf");
    //                SnackbarManager.show(
    //                        SnackBar.with(MainActivity.this)
    //                                .text("Something has been done")
    //                                .actionLabel("Undo")
    //                                .margin(15, 15)
    //                                .backgroundDrawable(R.drawable.custom_shape)
    //                                .actionLabelTypeface(tf)
    //                                .actionListener(new ActionClickListener() {
    //                                    @Override
    //                                    public void onActionClicked(SnackBar snackBar) {
    //                                        Toast.makeText(MainActivity.this,
    //                                                "Action undone",
    //                                                Toast.LENGTH_SHORT).show();
    //                                    }
    //                                }));
    //            }
    //        });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window w = getWindow();
        w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    } else {
        // do something for lower version
    }

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (dy > 0 && isSearchOn && !isSearchAnimationRunning) {
                isSearchOn = false;
                isSearchAnimationRunning = true;
                YoYo.with(Techniques.ZoomOutPosition).duration(500)
                        .interpolate(new AccelerateDecelerateInterpolator())
                        .withListener(new Animator.AnimatorListener() {
                            @Override
                            public void onAnimationStart(Animator animation) {

                            }

                            @Override
                            public void onAnimationEnd(Animator animation) {
                                fabSearchWallpaper.setVisibility(View.GONE);
                                isSearchAnimationRunning = false;
                            }

                            @Override
                            public void onAnimationCancel(Animator animation) {
                                Toast.makeText(MainActivity.this, "canceled", Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public void onAnimationRepeat(Animator animation) {

                            }
                        }).playOn(findViewById(R.id.fab_search_wallpaper));
            } else if (dy < 0 && !isSearchOn && !isSearchAnimationRunning) {
                isSearchOn = true;
                isSearchAnimationRunning = true;
                fabSearchWallpaper.setVisibility(View.VISIBLE);
                YoYo.with(Techniques.ZoomInPosition).duration(500)
                        .interpolate(new AccelerateDecelerateInterpolator())
                        .withListener(new Animator.AnimatorListener() {
                            @Override
                            public void onAnimationStart(Animator animation) {

                            }

                            @Override
                            public void onAnimationEnd(Animator animation) {
                                isSearchAnimationRunning = false;
                            }

                            @Override
                            public void onAnimationCancel(Animator animation) {
                                Toast.makeText(MainActivity.this, "canceled", Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public void onAnimationRepeat(Animator animation) {

                            }
                        }).playOn(findViewById(R.id.fab_search_wallpaper));
            }
        }
    });

}

From source file:org.alfresco.mobile.android.application.fragments.node.details.NodeDetailsFragment.java

protected void displayToolsBar() {
    // BUTTONS/*w  ww  .  jav a 2s. com*/
    ImageView b = (ImageView) viewById(R.id.action_openin);
    if (b == null) {
        return;
    }
    if ((node instanceof Document && ((Document) node).getContentStreamLength() > 0 && !isRestrictable)
            || (node instanceof NodeSyncPlaceHolder && !isRestrictable)) {
        // Tablet : Header thumbnail must be clickable
        if (viewById(R.id.icon) != null) {
            viewById(R.id.icon).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    openin();
                }
            });
        }

        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                openin();
            }
        });
    } else {
        b.setVisibility(View.GONE);
    }
    hideActionIfNecessary(b, ConfigurableActionHelper.ACTION_NODE_OPEN);

    b = (ImageView) viewById(R.id.action_like);
    if (node instanceof NodeSyncPlaceHolder) {
        b.setVisibility(View.GONE);
        viewById(R.id.like_progress).setVisibility(View.GONE);
    }
    if (getSession() != null && getSession().getRepositoryInfo() != null
            && getSession().getRepositoryInfo().getCapabilities() != null
            && getSession().getRepositoryInfo().getCapabilities().doesSupportLikingNodes()) {
        isLiked(b);
        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                like(v);
            }
        });
    } else {
        b.setVisibility(View.GONE);
        if (viewById(R.id.like_progress) != null) {
            viewById(R.id.like_progress).setVisibility(View.GONE);
        }
    }
    hideActionIfNecessary(b, ConfigurableActionHelper.ACTION_NODE_LIKE);

    // BUTTONS
    b = (ImageView) viewById(R.id.action_favorite);
    if (node instanceof NodeSyncPlaceHolder) {
        b.setVisibility(View.GONE);
        viewById(R.id.favorite_progress).setVisibility(View.GONE);
    } else if (!isRestrictable) {
        isFavorite(b);
        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                favorite(v);
            }
        });
    } else {
        b.setVisibility(View.GONE);
        viewById(R.id.favorite_progress).setVisibility(View.GONE);
    }
    hideActionIfNecessary(b, ConfigurableActionHelper.ACTION_NODE_FAVORITE);

    // SYNC
    b = (ImageView) viewById(R.id.action_sync);

    if (node instanceof NodeSyncPlaceHolder) {
        b.setVisibility(View.VISIBLE);
        b.setImageResource(R.drawable.ic_synced_dark);
    } else if (SyncContentManager.getInstance(getActivity()).hasActivateSync(getAccount())) {
        isSynced = (node.isFolder())
                ? SyncContentManager.getInstance(getActivity()).isRootSynced(getAccount(), node)
                : SyncContentManager.getInstance(getActivity()).isSynced(getAccount(), node);

        if (isSynced && !isRootSynced(b)) {
            b.setVisibility(View.GONE);
        } else if (node instanceof NodeSyncPlaceHolder) {
            b.setVisibility(View.VISIBLE);
            b.setImageResource(R.drawable.ic_synced_dark);
        } else if (!isRestrictable) {
            b.setImageResource(isSynced ? R.drawable.ic_synced_dark : R.drawable.ic_sync_light);
            b.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    isSynced = (node.isFolder())
                            ? SyncContentManager.getInstance(getActivity()).isRootSynced(getAccount(), node)
                            : SyncContentManager.getInstance(getActivity()).isSynced(getAccount(), node);

                    sync(v);
                }
            });
        } else {
            b.setVisibility(View.GONE);
        }
    } else {
        b.setVisibility(View.GONE);
    }
    hideActionIfNecessary(b, ConfigurableActionHelper.ACTION_NODE_SYNC);

    b = (ImageView) viewById(R.id.action_share);
    if (node.isDocument() && !isRestrictable) {
        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                share();
            }
        });
    } else {
        b.setVisibility(View.GONE);
    }
    hideActionIfNecessary(b, ConfigurableActionHelper.ACTION_NODE_SHARE);

    b = (ImageView) viewById(R.id.action_open_in_alfresco_editor);

    if (node.isDocument()) {
        String mimetype = node.getPropertyValue(PropertyIds.CONTENT_STREAM_MIME_TYPE);
        if (!TextUtils.isEmpty(mimetype) && mimetype.startsWith(MimeType.TYPE_TEXT)) {
            b.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    openin(true);
                }
            });
        } else {
            b.setVisibility(View.GONE);
        }
    } else {
        b.setVisibility(View.GONE);
    }
    hideActionIfNecessary(b, ConfigurableActionHelper.ACTION_NODE_EDIT_WITH_ALFRESCO);
}