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:info.guardianproject.otr.app.im.app.ChatView.java

private synchronized void initEmoji() {
    if (emojiManager == null) {
        emojiManager = EmojiManager.getInstance(mContext);

        try {//w  ww  . j  a  v a  2 s  .com

            emojiManager.addJsonPlugins();

        } catch (JsonSyntaxException jse) {
            Log.e(ImApp.LOG_TAG, "could not parse json", jse);
        } catch (IOException fe) {
            Log.e(ImApp.LOG_TAG, "could not load emoji definition", fe);
        } catch (Exception fe) {
            Log.e(ImApp.LOG_TAG, "could not load emoji definition", fe);
        }

    }

    mEmojiPager = (ViewPager) this.findViewById(R.id.emojiPager);
    ImageView btnEmoji = (ImageView) findViewById(R.id.btnEmoji);

    Collection<EmojiGroup> emojiGroups = emojiManager.getEmojiGroups();

    if (emojiGroups.size() > 0) {
        btnEmoji.setVisibility(View.VISIBLE);

        EmojiPagerAdapter emojiPagerAdapter = new EmojiPagerAdapter(mNewChatActivity, mComposeMessage,
                new ArrayList<EmojiGroup>(emojiGroups));

        mEmojiPager.setAdapter(emojiPagerAdapter);

        btnEmoji.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                //     mActionBox.setVisibility(View.GONE);

                if (mEmojiPager.getVisibility() == View.GONE)
                    mEmojiPager.setVisibility(View.VISIBLE);
                else
                    mEmojiPager.setVisibility(View.GONE);
            }

        });
    } else {
        btnEmoji.setVisibility(View.GONE);

        btnEmoji.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                //what? prompt to install?
            }

        });
    }

}

From source file:com.igniva.filemanager.activities.MainActivity.java

void initialiseViews() {
    appBarLayout = (AppBarLayout) findViewById(R.id.lin);

    if (!ImageLoader.getInstance().isInited()) {

        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));
    }//w w w . j  a  va 2s. c  o m
    displayImageOptions = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.amaze_header)
            .showImageForEmptyUri(R.drawable.amaze_header).showImageOnFail(R.drawable.amaze_header)
            .cacheInMemory(true).cacheOnDisk(true).considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565)
            .build();

    mScreenLayout = (CoordinatorLayout) findViewById(R.id.main_frame);
    buttonBarFrame = (FrameLayout) findViewById(R.id.buttonbarframe);

    //buttonBarFrame.setBackgroundColor(Color.parseColor(currentTab==1 ? skinTwo : skin));
    drawerHeaderLayout = getLayoutInflater().inflate(R.layout.drawerheader, null);
    drawerHeaderParent = (RelativeLayout) drawerHeaderLayout.findViewById(R.id.drawer_header_parent);
    drawerHeaderView = (View) drawerHeaderLayout.findViewById(R.id.drawer_header);
    mFabBackground = findViewById(R.id.fab_bg);
    drawerHeaderView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Intent intent;
            if (Build.VERSION.SDK_INT < 19) {
                intent = new Intent();
                intent.setAction(Intent.ACTION_GET_CONTENT);
            } else {
                intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

            }
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("image/*");
            startActivityForResult(intent, image_selector_request_code);
            return false;
        }
    });
    drawerProfilePic = (RoundedImageView) drawerHeaderLayout.findViewById(R.id.profile_pic);
    mGoogleName = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_name);
    mGoogleId = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_email);
    toolbar = (Toolbar) findViewById(R.id.action_bar);
    /* For SearchView, see onCreateOptionsMenu(Menu menu)*/
    TOOLBAR_START_INSET = toolbar.getContentInsetStart();
    setSupportActionBar(toolbar);
    frameLayout = (FrameLayout) findViewById(R.id.content_frame);
    indicator_layout = findViewById(R.id.indicator_layout);
    mDrawerLinear = (ScrimInsetsRelativeLayout) findViewById(R.id.left_drawer);
    if (theme1 == 1)
        mDrawerLinear.setBackgroundColor(Color.parseColor("#303030"));
    else
        mDrawerLinear.setBackgroundColor(Color.WHITE);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    //mDrawerLayout.setStatusBarBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    mDrawerList = (ListView) findViewById(R.id.menu_drawer);
    drawerHeaderView.setBackgroundResource(R.drawable.amaze_header);
    //drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    if (findViewById(R.id.tab_frame) != null) {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mDrawerLinear);
        mDrawerLayout.openDrawer(mDrawerLinear);
        mDrawerLayout.setScrimColor(Color.TRANSPARENT);
        isDrawerLocked = true;
    } else if (findViewById(R.id.tab_frame) == null) {

        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerLinear);
        mDrawerLayout.closeDrawer(mDrawerLinear);
        isDrawerLocked = false;
    }
    mDrawerList.addHeaderView(drawerHeaderLayout);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    View v = findViewById(R.id.fab_bg);
    /*if (theme1 != 1)
    v.setBackgroundColor(Color.parseColor("#a6ffffff"));*/
    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            floatingActionButton.close(true);
            utils.revealShow(view, false);
            if (isSearchViewEnabled)
                hideSearchView();
        }
    });

    pathbar = (LinearLayout) findViewById(R.id.pathbar);
    buttons = (LinearLayout) findViewById(R.id.buttons);
    scroll = (HorizontalScrollView) findViewById(R.id.scroll);
    scroll1 = (HorizontalScrollView) findViewById(R.id.scroll1);
    scroll.setSmoothScrollingEnabled(true);
    scroll1.setSmoothScrollingEnabled(true);
    ImageView divider = (ImageView) findViewById(R.id.divider1);
    if (theme1 == 0)
        divider.setImageResource(R.color.divider);
    else
        divider.setImageResource(R.color.divider_dark);

    setDrawerHeaderBackground();
    View settingsbutton = findViewById(R.id.settingsbutton);
    if (theme1 == 1) {
        settingsbutton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) settingsbutton.findViewById(R.id.settingicon))
                .setImageResource(R.drawable.ic_settings_white_48dp);
        ((TextView) settingsbutton.findViewById(R.id.settingtext))
                .setTextColor(getResources().getColor(android.R.color.white));
    }
    settingsbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent in = new Intent(MainActivity.this, Preferences.class);
            finish();
            final int enter_anim = android.R.anim.fade_in;
            final int exit_anim = android.R.anim.fade_out;
            Activity s = MainActivity.this;
            s.overridePendingTransition(exit_anim, enter_anim);
            s.finish();
            s.overridePendingTransition(enter_anim, exit_anim);
            s.startActivity(in);
        }

    });
    View appbutton = findViewById(R.id.appbutton);
    if (theme1 == 1) {
        appbutton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) appbutton.findViewById(R.id.appicon)).setImageResource(R.drawable.ic_doc_apk_white);
        ((TextView) appbutton.findViewById(R.id.apptext))
                .setTextColor(getResources().getColor(android.R.color.white));
    }
    appbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            android.support.v4.app.FragmentTransaction transaction2 = getSupportFragmentManager()
                    .beginTransaction();
            transaction2.replace(R.id.content_frame, new AppsList());
            findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2))
                    .start();
            pending_fragmentTransaction = transaction2;
            if (!isDrawerLocked)
                mDrawerLayout.closeDrawer(mDrawerLinear);
            else
                onDrawerClosed();
            select = -2;
            adapter.toggleChecked(false);
        }
    });

    View ftpButton = findViewById(R.id.ftpbutton);
    if (theme1 == 1) {
        ftpButton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) ftpButton.findViewById(R.id.ftpicon)).setImageResource(R.drawable.ic_ftp_dark);
        ((TextView) ftpButton.findViewById(R.id.ftptext))
                .setTextColor(getResources().getColor(android.R.color.white));
    }
    ftpButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            android.support.v4.app.FragmentTransaction transaction2 = getSupportFragmentManager()
                    .beginTransaction();
            transaction2.replace(R.id.content_frame, new FTPServerFragment());
            findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2))
                    .start();
            pending_fragmentTransaction = transaction2;
            if (!isDrawerLocked)
                mDrawerLayout.closeDrawer(mDrawerLinear);
            else
                onDrawerClosed();
            select = -2;
            adapter.toggleChecked(false);
        }
    });
    //getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor((currentTab==1 ? skinTwo : skin))));

    // status bar0
    sdk = Build.VERSION.SDK_INT;

    if (sdk == 20 || sdk == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        //tintManager.setStatusBarTintColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.drawer_layout)
                .getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        if (!isDrawerLocked)
            p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (Build.VERSION.SDK_INT >= 21) {

        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        //window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (isDrawerLocked) {
            window.setStatusBarColor((skinStatusBar));
        } else
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (colourednavigation)
            window.setNavigationBarColor(skinStatusBar);
    }

    searchViewLayout = (RelativeLayout) findViewById(R.id.search_view);
    searchViewEditText = (AppCompatEditText) findViewById(R.id.search_edit_text);
    ImageView clear = (ImageView) findViewById(R.id.search_close_btn);
    clear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchViewEditText.setText("");
        }
    });
    findViewById(R.id.img_view_back).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideSearchView();
        }
    });
    searchViewEditText.setOnKeyListener(new TextView.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN)) {
                // Perform action on key press
                mainActivityHelper.search(searchViewEditText.getText().toString());
                hideSearchView();
                return true;
            }
            return false;
        }
    });

    //    searchViewEditText.setTextColor(getResources().getColor(android.R.color.black));
    //     searchViewEditText.setHintTextColor(Color.parseColor(BaseActivity.accentSkin));
}

From source file:com.pixby.texo.EditTools.ColorTool.java

@Override
public void onViewCreated(View v, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    mHueSeekBar = (HueSeekBar) v.findViewById(R.id.colorpicker);
    mAlphaSeekBar = (AlphaSeekBar) v.findViewById((R.id.alphapicker));
    mSwatchWhite = v.findViewById(R.id.swatch_white);
    mSwatchGrey = v.findViewById(R.id.swatch_grey);
    mSwatchBlack = v.findViewById(R.id.swatch_black);
    mSwatchShade1 = v.findViewById(R.id.swatch_shade1);
    mSwatchShade2 = v.findViewById(R.id.swatch_shade2);
    mSwatchTint1 = v.findViewById(R.id.swatch_tint1);
    mSwatchTint2 = v.findViewById(R.id.swatch_tint2);

    ImageView okButton = (ImageButton) v.findViewById(R.id.save_button);
    ImageButton cancelButton = (ImageButton) v.findViewById(R.id.cancel_button);

    View.OnClickListener swatchClickHandler = new View.OnClickListener() {
        @Override//from   w  w w .j  av  a2s. c  om
        public void onClick(View v) {
            int color = mSampleColors.get(v.getId());
            setColors(color);
            // if this is one of the preset color buttons set up swatches for this color
            if (isPresetColor(color)) {
                setSwatchColors(color);
            }
        }
    };

    View.OnFocusChangeListener focusChangeListener = new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            drawBackground(v);
        }
    };

    mSwatchWhite.setOnFocusChangeListener(focusChangeListener);
    mSwatchGrey.setOnFocusChangeListener(focusChangeListener);
    mSwatchBlack.setOnFocusChangeListener(focusChangeListener);
    mSwatchShade1.setOnFocusChangeListener(focusChangeListener);
    mSwatchShade2.setOnFocusChangeListener(focusChangeListener);
    mSwatchTint1.setOnFocusChangeListener(focusChangeListener);
    mSwatchTint2.setOnFocusChangeListener(focusChangeListener);

    setSwatchColors(getInitialColor());

    mSwatchWhite.setOnClickListener(swatchClickHandler);
    mSwatchGrey.setOnClickListener(swatchClickHandler);
    mSwatchBlack.setOnClickListener(swatchClickHandler);
    mSwatchShade1.setOnClickListener(swatchClickHandler);
    mSwatchShade2.setOnClickListener(swatchClickHandler);
    mSwatchTint1.setOnClickListener(swatchClickHandler);
    mSwatchTint2.setOnClickListener(swatchClickHandler);

    SeekBar.OnSeekBarChangeListener seekBarListener = new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                if (seekBar instanceof HueSeekBar) {
                    int color = hueToColor(progress);
                    setColors(color);
                    setSwatchColors(color);
                }
                if (seekBar instanceof AlphaSeekBar) {
                    setWatermarkAlpha(progress);
                }
            }
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }
    };

    mHueSeekBar.setOnSeekBarChangeListener(seekBarListener);
    mAlphaSeekBar.setOnSeekBarChangeListener(seekBarListener);

    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getListener().onSave(getTag());
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // restore initial state - user cancelled
            setWatermarkColor(getInitialColor());
            setWatermarkAlpha(getInitialAlpha());
            getListener().onCancel(getTag());
        }
    });
}

From source file:com.mdlive.sav.MDLiveProviderDetails.java

/**
 *  Successful Response Handler for getting the Affillitations and the provider image.
 *  This method will give the successful response of the Provider's affilitations.
 *  This response is for the Affilations Purpose.The image can be placed one below the other
 *
 *//*from w w  w . jav a2s  . c o m*/
private void getProviderImageArrayResponse(JsonObject providerdetObj) {
    JsonArray ProviderImageArray = providerdetObj.get("provider_groups").getAsJsonArray();
    if (ProviderImageArray.size() != 0) {
        providerImageCollectionHolder.removeAllViews();
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                100);
        params.setMargins(5, 10, 5, 10);
        for (int i = 0; i < ProviderImageArray.size(); i++) {
            try {
                if (!ProviderImageArray.get(i).getAsJsonObject().get("logo").isJsonNull()) {
                    final ImageView imageView = new ImageView(MDLiveProviderDetails.this);
                    //imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                    imageView.setLayoutParams(params);
                    ImageRequest request = new ImageRequest(
                            ProviderImageArray.get(i).getAsJsonObject().get("logo").getAsString(),
                            new Response.Listener<Bitmap>() {
                                @Override
                                public void onResponse(Bitmap bitmap) {
                                    imageView.setImageBitmap(bitmap);
                                }
                            }, 0, 0, null, new Response.ErrorListener() {
                                public void onErrorResponse(VolleyError error) {
                                }
                            });
                    ApplicationController.getInstance().getRequestQueue(this).add(request);
                    imageView.setTag(ProviderImageArray.get(i).getAsJsonObject().get("url").getAsString());
                    imageView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(MDLiveProviderDetails.this,
                                    MDLiveProviderGroupDetailsAffiliations.class);
                            intent.putExtra("affurl",
                                    (imageView.getTag() != null) ? imageView.getTag().toString() : "");
                            startActivity(intent);
                            MdliveUtils.startActivityAnimation(MDLiveProviderDetails.this);
                        }
                    });
                    providerImageCollectionHolder.addView(imageView);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else {
        if (!isCignaCoachUser)
            findViewById(R.id.providerGroupAffiliation).setVisibility(View.GONE);
    }
}

From source file:com.example.aitor2.myapplication.DrawerArrowSample.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.home_view);/*w  w  w.  j  a v a 2 s. com*/
    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    final ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator);
    final Resources resources = getResources();
    drawer_adapter adapter = new drawer_adapter(this, icons, titles);
    ListView lv = (ListView) findViewById(R.id.drawer_listview);
    lv.setAdapter(adapter);
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            drawer.closeDrawer(START);
            if (position == 0) {
                Intent intent = new Intent(DrawerArrowSample.this, DrawerArrowSample.class);
                startActivity(intent);
                finish();
            } else if (position == 1) {
                Intent intent = new Intent(DrawerArrowSample.this, misReservas.class);
                startActivity(intent);
                finish();
            }
        }
    });
    findViewById(R.id.pink_icon).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(DrawerArrowSample.this, "Clicked pink Floating Action Button", Toast.LENGTH_SHORT)
                    .show();
        }
    });
    actionB = (FloatingActionButton) findViewById(R.id.pink_icon);
    actionB.setStrokeVisible(true);

    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
    swipeRefreshLayout.setOnRefreshListener(onRefreshListener);
    swipeRefreshLayout.setColorSchemeColors(Color.BLACK, Color.GREEN, Color.BLACK, Color.GREEN);

    drawerArrowDrawable = new DrawerArrowDrawable(resources);
    drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray));

    imageView.setImageDrawable(drawerArrowDrawable);

    drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {

            offset = slideOffset;

            // Sometimes slideOffset ends up so close to but not quite 1 or 0.
            if (slideOffset >= .995) {
                flipped = true;
                drawerArrowDrawable.setFlip(flipped);
            } else if (slideOffset <= .005) {
                flipped = false;
                drawerArrowDrawable.setFlip(flipped);
            }

            drawerArrowDrawable.setParameter(offset);
        }
    });

    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (drawer.isDrawerVisible(START)) {
                drawer.closeDrawer(START);
            } else {
                drawer.openDrawer(START);
            }
        }
    });

    final TextView styleButton = (TextView) findViewById(R.id.indicator_style);
    styleButton.setOnClickListener(new View.OnClickListener() {

        boolean rounded = false;

        @Override
        public void onClick(View v) {

            styleButton.setText(rounded //
                    ? resources.getString(R.string.rounded) //
                    : resources.getString(R.string.squared));

            rounded = !rounded;

            drawerArrowDrawable = new DrawerArrowDrawable(resources, rounded);
            drawerArrowDrawable.setParameter(offset);
            drawerArrowDrawable.setFlip(flipped);
            drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray));

            imageView.setImageDrawable(drawerArrowDrawable);
        }
    });

    /////////////////////create expandable listview
    new expandable().execute();
    ////////////////////calendario

    // Pop up Date picker on pressing the editText

}

From source file:com.ymt.demo1.plates.hub.FireHubMainFragment.java

protected void initView(View view) {
    //??//w w  w .j  a v  a2s .  c o  m
    ExpandableListView expandableListView = (ExpandableListView) view.findViewById(R.id.hub_list_view);
    //?
    ProgressBar progressBar = new ProgressBar(getActivity());
    progressBar.setIndeterminate(true);
    expandableListView.setEmptyView(progressBar);

    hubPlateAdapter = new HubPlateAdapter(getActivity());
    expandableListView.setAdapter(hubPlateAdapter);

    //item
    expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            //???
            Intent intent = new Intent(getActivity(), SubjectsActivity.class);
            intent.putExtra("plate", childList.get(groupPosition).get(childPosition));
            intent.putExtra("group_name", parentList.get(groupPosition).getName());
            startActivity(intent);
            getActivity().overridePendingTransition(android.R.anim.slide_in_left,
                    android.R.anim.slide_out_right);
            return true;
        }
    });

    ImageView doPostView = (ImageView) view.findViewById(R.id.hub_act_post);
    //        ImageView topPostView = (ImageView) view.findViewById(R.id.hub_act_top);
    ImageView newPostView = (ImageView) view.findViewById(R.id.hub_act_new);
    ImageView hotPostView = (ImageView) view.findViewById(R.id.hub_act_hot);
    ImageView myPostView = (ImageView) view.findViewById(R.id.hub_act_my);

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.hub_act_post: //?
                Intent intent1 = new Intent(getActivity(), DoPostActivity.class);
                ArrayList<HubPlate> parents = new ArrayList<>();
                for (HubPlate plate : parentList) {
                    parents.add(plate);
                }
                ArrayList<HubPlate> childs = new ArrayList<>();
                for (List<HubPlate> pList : childList) {
                    for (HubPlate plate : pList) {
                        childs.add(plate);
                    }
                }
                intent1.putParcelableArrayListExtra("parent", parents);
                intent1.putParcelableArrayListExtra("child", childs);
                getActivity().startActivity(intent1);
                getActivity().overridePendingTransition(android.R.anim.slide_in_left,
                        android.R.anim.slide_out_right);
                break;
            //                    case R.id.hub_act_top:                                          //??
            //
            //                        break;
            case R.id.hub_act_new: //?
                Intent intentN = new Intent(getActivity(), HotNewPostActivity.class);
                intentN.putExtra("type", HotNewPostActivity.TYPE_NEW);
                startActivity(intentN);
                getActivity().overridePendingTransition(android.R.anim.slide_in_left,
                        android.R.anim.slide_out_right);
                break;
            case R.id.hub_act_hot: //?
                Intent intentH = new Intent(getActivity(), HotNewPostActivity.class);
                intentH.putExtra("type", HotNewPostActivity.TYPE_HOT);
                startActivity(intentH);
                getActivity().overridePendingTransition(android.R.anim.slide_in_left,
                        android.R.anim.slide_out_right);
                break;
            case R.id.hub_act_my: //?
                startActivity(new Intent(getActivity(), MyHubTabActivity.class));
                getActivity().overridePendingTransition(android.R.anim.slide_in_left,
                        android.R.anim.slide_out_right);
                break;
            }
        }
    };
    doPostView.setOnClickListener(onClickListener);
    //        topPostView.setOnClickListener(onClickListener);
    newPostView.setOnClickListener(onClickListener);
    hotPostView.setOnClickListener(onClickListener);
    myPostView.setOnClickListener(onClickListener);

}

From source file:de.baumann.hhsmoodle.data_todo.Todo_Fragment.java

public void setTodoList() {

    if (isFABOpen) {
        closeFABMenu();//from   w ww.j av a  2 s.c  o m
    }

    NotificationManager nMgr = (NotificationManager) getActivity()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancelAll();

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "todo_title", "todo_content", "todo_creation" };
    final Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        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 todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);
            helper_main.switchIcon(getActivity(), todo_icon, "todo_icon", iv_icon);

            switch (todo_attachment) {
            case "true":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle_red);

                int n = Integer.valueOf(_id);

                android.content.Intent iMain = new android.content.Intent();
                iMain.setAction("shortcutToDo");
                iMain.setClassName(getActivity(), "de.baumann.hhsmoodle.activities.Activity_splash");
                PendingIntent piMain = PendingIntent.getActivity(getActivity(), n, iMain, 0);

                NotificationCompat.Builder builderSummary = new NotificationCompat.Builder(getActivity())
                        .setSmallIcon(R.drawable.school)
                        .setColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary))
                        .setGroup("HHS_Moodle").setGroupSummary(true).setContentIntent(piMain);

                Notification notification = new NotificationCompat.Builder(getActivity())
                        .setColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary))
                        .setSmallIcon(R.drawable.school).setContentTitle(todo_title)
                        .setContentText(todo_content).setContentIntent(piMain).setAutoCancel(true)
                        .setGroup("HHS_Moodle")
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(todo_content))
                        .setPriority(Notification.PRIORITY_DEFAULT).setVibrate(new long[0]).build();

                NotificationManager notificationManager = (NotificationManager) getActivity()
                        .getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(n, notification);
                notificationManager.notify(0, builderSummary.build());
                break;
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    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), todo_title, todo_content, "3",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "2",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "1",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    switch (todo_attachment) {
                    case "true":
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "",
                                todo_creation);
                        setTodoList();
                        break;
                    default:
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "true",
                                todo_creation);
                        setTodoList();
                        break;
                    }
                }
            });
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_todoBY", "note_title");
    sharedPref.edit().putString("filter_todoBY", "note_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) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            sharedPref.edit().putString("toDo_title", todo_title).apply();
            sharedPref.edit().putString("toDo_text", todo_content).apply();
            sharedPref.edit().putString("toDo_seqno", _id).apply();
            sharedPref.edit().putString("toDo_icon", todo_icon).apply();
            sharedPref.edit().putString("toDo_create", todo_creation).apply();
            sharedPref.edit().putString("toDo_attachment", todo_attachment).apply();

            helper_main.switchToActivity(getActivity(), Activity_todo.class, false);
        }
    });

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

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_share),
                    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() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null);

                                final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                                edit_title.setHint(R.string.bookmark_edit_title);
                                edit_title.setText(todo_title);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.bookmark_edit_title);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTag = edit_title.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTag, todo_content,
                                                        todo_icon, todo_attachment, todo_creation);
                                                setTodoList();
                                                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 AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.todo_share))) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, todo_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, todo_content);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

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

                            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.delete(Integer.parseInt(_id));
                                                setTodoList();
                                            }
                                        });
                                snackbar.show();
                            }

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

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

                        }
                    }).show();

            return true;
        }
    });
}

From source file:de.baumann.hhsmoodle.popup.Popup_todo.java

private void setTodoList() {

    PreferenceManager.setDefaultValues(Popup_todo.this, R.xml.user_settings, false);
    final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Popup_todo.this);

    NotificationManager nMgr = (NotificationManager) Popup_todo.this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancelAll();//from   w ww .j  av  a  2  s  .c  o m

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "todo_title", "todo_content", "todo_creation" };

    final String search = sharedPref.getString("filter_todo_subject", "");
    final Cursor row = db.fetchDataByFilter(search, "todo_title");
    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(Popup_todo.this, layoutstyle, row, column,
            xml_id, 0) {
        @Override
        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 todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

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

            switch (todo_icon) {
            case "3":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            }

            switch (todo_attachment) {
            case "true":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle_red);

                int n = Integer.valueOf(_id);

                android.content.Intent iMain = new android.content.Intent();
                iMain.setAction("shortcutToDo");
                iMain.setClassName(Popup_todo.this, "de.baumann.hhsmoodle.activities.Activity_splash");
                PendingIntent piMain = PendingIntent.getActivity(Popup_todo.this, n, iMain, 0);

                NotificationCompat.Builder builderSummary = new NotificationCompat.Builder(Popup_todo.this)
                        .setSmallIcon(R.drawable.school)
                        .setColor(ContextCompat.getColor(Popup_todo.this, R.color.colorPrimary))
                        .setGroup("HHS_Moodle").setGroupSummary(true).setContentIntent(piMain);

                Notification notification = new NotificationCompat.Builder(Popup_todo.this)
                        .setColor(ContextCompat.getColor(Popup_todo.this, R.color.colorPrimary))
                        .setSmallIcon(R.drawable.school).setContentTitle(todo_title)
                        .setContentText(todo_content).setContentIntent(piMain).setAutoCancel(true)
                        .setGroup("HHS_Moodle")
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(todo_content))
                        .setPriority(Notification.PRIORITY_DEFAULT).setVibrate(new long[0]).build();

                NotificationManager notificationManager = (NotificationManager) Popup_todo.this
                        .getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(n, notification);
                notificationManager.notify(0, builderSummary.build());
                break;
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final Item[] items = {
                            new Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<Item>(Popup_todo.this,
                            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(Popup_todo.this)
                            .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), todo_title, todo_content, "3",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "2",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "1",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    switch (todo_attachment) {
                    case "true":
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "",
                                todo_creation);
                        setTodoList();
                        break;
                    default:
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "true",
                                todo_creation);
                        setTodoList();
                        break;
                    }
                }
            });
            return v;
        }
    };

    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 _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            sharedPref.edit().putString("toDo_title", todo_title).apply();
            sharedPref.edit().putString("toDo_text", todo_content).apply();
            sharedPref.edit().putString("toDo_seqno", _id).apply();
            sharedPref.edit().putString("toDo_icon", todo_icon).apply();
            sharedPref.edit().putString("toDo_create", todo_creation).apply();
            sharedPref.edit().putString("toDo_attachment", todo_attachment).apply();

            helper_main.switchToActivity(Popup_todo.this, Activity_todo.class, false);
        }
    });

    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 todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            final CharSequence[] options = { getString(R.string.bookmark_edit_title),
                    getString(R.string.todo_share), getString(R.string.bookmark_createNote),
                    getString(R.string.bookmark_createEvent), getString(R.string.bookmark_remove_bookmark) };
            new AlertDialog.Builder(Popup_todo.this)
                    .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.bookmark_edit_title))) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(Popup_todo.this);
                                View dialogView = View.inflate(Popup_todo.this, R.layout.dialog_edit_title,
                                        null);

                                final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                                edit_title.setHint(R.string.bookmark_edit_title);
                                edit_title.setText(todo_title);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.bookmark_edit_title);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTag = edit_title.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTag, todo_content,
                                                        todo_icon, todo_attachment, todo_creation);
                                                setTodoList();
                                                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 AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(Popup_todo.this, edit_title);
                            }

                            if (options[item].equals(getString(R.string.todo_share))) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, todo_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, todo_content);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                Intent calIntent = new Intent(Intent.ACTION_INSERT);
                                calIntent.setType("vnd.android.cursor.item/event");
                                calIntent.putExtra(CalendarContract.Events.TITLE, todo_title);
                                calIntent.putExtra(CalendarContract.Events.DESCRIPTION, todo_content);
                                startActivity(calIntent);
                            }

                            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.delete(Integer.parseInt(_id));
                                                setTodoList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                sharedPref.edit().putString("handleTextTitle", todo_title)
                                        .putString("handleTextText", todo_content).apply();
                                helper_main.switchToActivity(Popup_todo.this, Activity_EditNote.class, false);
                            }

                        }
                    }).show();

            return true;
        }
    });

    if (lv.getAdapter().getCount() == 0) {
        new android.app.AlertDialog.Builder(this)
                .setMessage(helper_main.textSpannable(getString(R.string.toast_noEntry)))
                .setPositiveButton(this.getString(R.string.toast_yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                    }
                }).show();
        new Handler().postDelayed(new Runnable() {
            public void run() {
                finish();
            }
        }, 2000);
    }
}

From source file:net.idlesoft.android.apps.github.activities.Commit.java

protected void buildUi() {
    // Get the commit data for that commit ID so that we can get the
    // tree ID and filename.
    try {/*  w  w  w . j  av  a 2s . c o m*/
        final ImageView authorImage = (ImageView) findViewById(R.id.commit_view_author_gravatar);
        final ImageView committerImage = (ImageView) findViewById(R.id.commit_view_committer_gravatar);

        // If the committer is the author then just show them as the
        // author, otherwise show
        // both people
        ((TextView) findViewById(R.id.commit_view_author_name)).setText(mAuthorName);
        if (mAuthorGravatar != null) {
            authorImage.setImageBitmap(mAuthorGravatar);
        } else {
            authorImage.setImageBitmap(Commit.loadGravatarByLoginName(Commit.this, mAuthor));
        }

        // Set the commit message
        ((TextView) findViewById(R.id.commit_view_message)).setText(mJson.getString("message"));

        final SimpleDateFormat dateFormat = new SimpleDateFormat(Hubroid.GITHUB_TIME_FORMAT);
        Date commit_time;
        Date current_time;
        String authorDate = "";

        try {
            commit_time = dateFormat.parse(mJson.getString("authored_date"));
            current_time = dateFormat.parse(dateFormat.format(new Date()));
            ((TextView) findViewById(R.id.commit_view_author_time))
                    .setText(Commit.getHumanDate(current_time, commit_time));

            commit_time = dateFormat.parse(mJson.getString("committed_date"));
            authorDate = Commit.getHumanDate(current_time, commit_time);

        } catch (final ParseException e) {
            e.printStackTrace();
        }

        if (!mAuthor.equals(mCommitter)) {
            // They are not the same person, make the author visible and
            // fill in the details
            ((LinearLayout) findViewById(R.id.commit_view_author_layout)).setVisibility(View.VISIBLE);
            ((TextView) findViewById(R.id.commit_view_committer_name)).setText(mCommitterName);
            ((TextView) findViewById(R.id.commit_view_committer_time)).setText(authorDate);
            if (mCommitterGravatar != null) {
                committerImage.setImageBitmap(mCommitterGravatar);
            } else {
                committerImage.setImageBitmap(Commit.loadGravatarByLoginName(Commit.this, mCommitter));
            }
        }

        final OnClickListener onGravatarClick = new OnClickListener() {
            public void onClick(final View v) {
                final Intent i = new Intent(Commit.this, Profile.class);
                if (v.getId() == authorImage.getId()) {
                    i.putExtra("username", mAuthor);
                } else if (v.getId() == committerImage.getId()) {
                    i.putExtra("username", mCommitter);
                } else {
                    return;
                }
                startActivity(i);
            }
        };

        if ((mAuthor != null) && !mAuthor.equals("")) {
            authorImage.setOnClickListener(onGravatarClick);
        }
        if ((mCommitter != null) && !mCommitter.equals("")) {
            committerImage.setOnClickListener(onGravatarClick);
        }

        int filesAdded, filesRemoved, filesChanged;

        try {
            filesAdded = mJson.getJSONArray("added").length();
        } catch (final JSONException e) {
            filesAdded = 0;
        }
        try {
            filesRemoved = mJson.getJSONArray("removed").length();
        } catch (final JSONException e) {
            filesRemoved = 0;
        }
        try {
            filesChanged = mJson.getJSONArray("modified").length();
        } catch (final JSONException e) {
            filesChanged = 0;
        }

        final Button filesAddedButton = (Button) findViewById(R.id.btn_commit_addedFiles);
        final Button filesRemovedButton = (Button) findViewById(R.id.btn_commit_removedFiles);
        final Button filesChangedButton = (Button) findViewById(R.id.btn_commit_changedFiles);

        Log.d("debug", filesAdded + " " + filesRemoved + " " + filesChanged);
        if (filesAdded > 0) {
            filesAddedButton.setText(filesAdded + " files added");
        } else {
            filesAddedButton.setVisibility(View.GONE);
        }
        if (filesRemoved > 0) {
            filesRemovedButton.setText(filesRemoved + " files removed");
        } else {
            filesRemovedButton.setVisibility(View.GONE);
        }
        if (filesChanged > 0) {
            filesChangedButton.setText(filesChanged + " files changed");
        } else {
            filesChangedButton.setVisibility(View.GONE);
        }

        filesAddedButton.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                final Intent i = new Intent(Commit.this, DiffFilesList.class);
                i.putExtra("type", "added");
                i.putExtra("json", mJson.toString());
                i.putExtra("repo_owner", mRepositoryOwner);
                i.putExtra("repo_name", mRepositoryName);
                startActivity(i);
            }
        });
        filesRemovedButton.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                final Intent i = new Intent(Commit.this, DiffFilesList.class);
                i.putExtra("type", "removed");
                i.putExtra("json", mJson.toString());
                i.putExtra("repo_owner", mRepositoryOwner);
                i.putExtra("repo_name", mRepositoryName);
                startActivity(i);
            }
        });
        filesChangedButton.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
                final Intent i = new Intent(Commit.this, DiffFilesList.class);
                i.putExtra("type", "modified");
                i.putExtra("json", mJson.toString());
                i.putExtra("repo_owner", mRepositoryOwner);
                i.putExtra("repo_name", mRepositoryName);
                startActivity(i);
            }
        });
    } catch (final JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

void initialiseViews() {
    appBarLayout = (AppBarLayout) findViewById(R.id.lin);

    mScreenLayout = (CoordinatorLayout) findViewById(R.id.main_frame);
    buttonBarFrame = (FrameLayout) findViewById(R.id.buttonbarframe);

    //buttonBarFrame.setBackgroundColor(Color.parseColor(currentTab==1 ? skinTwo : skin));
    drawerHeaderLayout = getLayoutInflater().inflate(R.layout.drawerheader, null);
    drawerHeaderParent = (RelativeLayout) drawerHeaderLayout.findViewById(R.id.drawer_header_parent);
    drawerHeaderView = drawerHeaderLayout.findViewById(R.id.drawer_header);
    drawerHeaderView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override//w w  w. j av  a2 s. c o  m
        public boolean onLongClick(View v) {
            Intent intent;
            if (SDK_INT < 19) {
                intent = new Intent();
                intent.setAction(Intent.ACTION_GET_CONTENT);
            } else {
                intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

            }
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("image/*");
            startActivityForResult(intent, image_selector_request_code);
            return false;
        }
    });
    drawerProfilePic = (RoundedImageView) drawerHeaderLayout.findViewById(R.id.profile_pic);
    mGoogleName = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_name);
    mGoogleId = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_email);
    toolbar = (Toolbar) findViewById(R.id.action_bar);
    /* For SearchView, see onCreateOptionsMenu(Menu menu)*/
    TOOLBAR_START_INSET = toolbar.getContentInsetStart();
    setSupportActionBar(toolbar);
    frameLayout = (FrameLayout) findViewById(R.id.content_frame);
    indicator_layout = findViewById(R.id.indicator_layout);
    mDrawerLinear = (ScrimInsetsRelativeLayout) findViewById(R.id.left_drawer);
    if (getAppTheme().equals(AppTheme.DARK))
        mDrawerLinear.setBackgroundColor(Utils.getColor(this, R.color.holo_dark_background));
    else
        mDrawerLinear.setBackgroundColor(Color.WHITE);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    //mDrawerLayout.setStatusBarBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    mDrawerList = (ListView) findViewById(R.id.menu_drawer);
    drawerHeaderView.setBackgroundResource(R.drawable.amaze_header);
    //drawerHeaderParent.setBackgroundColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
    if (findViewById(R.id.tab_frame) != null) {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mDrawerLinear);
        mDrawerLayout.openDrawer(mDrawerLinear);
        mDrawerLayout.setScrimColor(Color.TRANSPARENT);
        isDrawerLocked = true;
    } else if (findViewById(R.id.tab_frame) == null) {

        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerLinear);
        mDrawerLayout.closeDrawer(mDrawerLinear);
        isDrawerLocked = false;
    }
    mDrawerList.addHeaderView(drawerHeaderLayout);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    fabBgView = findViewById(R.id.fab_bg);
    if (getAppTheme().equals(AppTheme.DARK)) {
        fabBgView.setBackgroundResource(R.drawable.fab_shadow_dark);
    }

    fabBgView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            floatingActionButton.close(true);
            if (isSearchViewEnabled)
                hideSearchView();
        }
    });

    pathbar = (LinearLayout) findViewById(R.id.pathbar);
    buttons = (LinearLayout) findViewById(R.id.buttons);
    scroll = (HorizontalScrollView) findViewById(R.id.scroll);
    scroll1 = (HorizontalScrollView) findViewById(R.id.scroll1);
    scroll.setSmoothScrollingEnabled(true);
    scroll1.setSmoothScrollingEnabled(true);
    ImageView divider = (ImageView) findViewById(R.id.divider1);
    if (getAppTheme().equals(AppTheme.LIGHT))
        divider.setImageResource(R.color.divider);
    else
        divider.setImageResource(R.color.divider_dark);

    setDrawerHeaderBackground();
    View settingsButton = findViewById(R.id.settingsbutton);
    if (getAppTheme().equals(AppTheme.DARK)) {
        settingsButton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) settingsButton.findViewById(R.id.settingicon))
                .setImageResource(R.drawable.ic_settings_white_48dp);
        ((TextView) settingsButton.findViewById(R.id.settingtext))
                .setTextColor(Utils.getColor(this, android.R.color.white));
    }
    settingsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent in = new Intent(MainActivity.this, PreferencesActivity.class);
            startActivity(in);
            finish();
        }

    });
    View appButton = findViewById(R.id.appbutton);
    if (getAppTheme().equals(AppTheme.DARK)) {
        appButton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) appButton.findViewById(R.id.appicon)).setImageResource(R.drawable.ic_doc_apk_white);
        ((TextView) appButton.findViewById(R.id.apptext))
                .setTextColor(Utils.getColor(this, android.R.color.white));
    }
    appButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            android.support.v4.app.FragmentTransaction transaction2 = getSupportFragmentManager()
                    .beginTransaction();
            transaction2.replace(R.id.content_frame, new AppsList());
            findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2))
                    .start();
            pending_fragmentTransaction = transaction2;
            if (!isDrawerLocked)
                mDrawerLayout.closeDrawer(mDrawerLinear);
            else
                onDrawerClosed();
            selectedStorage = SELECT_MINUS_2;
            adapter.toggleChecked(false);
        }
    });

    View ftpButton = findViewById(R.id.ftpbutton);
    if (getAppTheme().equals(AppTheme.DARK)) {
        ftpButton.setBackgroundResource(R.drawable.safr_ripple_black);
        ((ImageView) ftpButton.findViewById(R.id.ftpicon)).setImageResource(R.drawable.ic_ftp_dark);
        ((TextView) ftpButton.findViewById(R.id.ftptext))
                .setTextColor(Utils.getColor(this, android.R.color.white));
    }
    ftpButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            android.support.v4.app.FragmentTransaction transaction2 = getSupportFragmentManager()
                    .beginTransaction();
            transaction2.replace(R.id.content_frame, new FTPServerFragment());
            findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2))
                    .start();
            pending_fragmentTransaction = transaction2;
            if (!isDrawerLocked)
                mDrawerLayout.closeDrawer(mDrawerLinear);
            else
                onDrawerClosed();
            selectedStorage = SELECT_MINUS_2;
            adapter.toggleChecked(false);
        }
    });
    //getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor((currentTab==1 ? skinTwo : skin))));

    // status bar0
    if (SDK_INT == 20 || SDK_INT == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        //tintManager.setStatusBarTintColor(Color.parseColor((currentTab==1 ? skinTwo : skin)));
        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.drawer_layout)
                .getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        if (!isDrawerLocked)
            p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        //window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (isDrawerLocked) {
            window.setStatusBarColor((skinStatusBar));
        } else
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (colourednavigation)
            window.setNavigationBarColor(skinStatusBar);
    }

    searchViewLayout = (RelativeLayout) findViewById(R.id.search_view);
    searchViewEditText = (AppCompatEditText) findViewById(R.id.search_edit_text);
    ImageView clear = (ImageView) findViewById(R.id.search_close_btn);
    clear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchViewEditText.setText("");
        }
    });
    findViewById(R.id.img_view_back).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideSearchView();
        }
    });
    searchViewEditText.setOnKeyListener(new TextView.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN)) {
                // Perform action on key press
                mainActivityHelper.search(searchViewEditText.getText().toString());
                hideSearchView();
                return true;
            }
            return false;
        }
    });

    //    searchViewEditText.setTextColor(Utils.getColor(this, android.R.color.black));
    //     searchViewEditText.setHintTextColor(Color.parseColor(BaseActivity.accentSkin));
}