Example usage for android.content DialogInterface.OnClickListener DialogInterface.OnClickListener

List of usage examples for android.content DialogInterface.OnClickListener DialogInterface.OnClickListener

Introduction

In this page you can find the example usage for android.content DialogInterface.OnClickListener DialogInterface.OnClickListener.

Prototype

DialogInterface.OnClickListener

Source Link

Usage

From source file:com.juick.android.MainActivity.java

public void updateNavigation() {
    navigationItems = new ArrayList<NavigationItem>();

    List<MicroBlog> blogs = new ArrayList<MicroBlog>(microBlogs.values());
    Collections.<MicroBlog>sort(blogs, new Comparator<MicroBlog>() {
        @Override//  w  w w  .  j  av  a 2 s .  c  o  m
        public int compare(MicroBlog microBlog, MicroBlog microBlog2) {
            return microBlog.getPiority() - microBlog2.getPiority();
        }
    });
    for (MicroBlog blog : blogs) {
        blog.addNavigationSources(navigationItems, this);
    }
    navigationItems.add(new NavigationItem(NAVITEM_UNREAD, R.string.navigationUnread,
            R.drawable.navicon_juickadvanced, "msrcUnread") {
        @Override
        public void action() {
            final NavigationItem thisNi = this;
            final ProgressDialog pd = new ProgressDialog(MainActivity.this);
            pd.setIndeterminate(true);
            pd.setTitle(R.string.navigationUnread);
            pd.setCancelable(true);
            pd.show();
            UnreadSegmentsView.loadPeriods(MainActivity.this,
                    new Utils.Function<Void, ArrayList<DatabaseService.Period>>() {
                        @Override
                        public Void apply(ArrayList<DatabaseService.Period> periods) {
                            if (pd.isShowing()) {
                                pd.cancel();
                                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                                final AlertDialog alerDialog;
                                if (periods.size() == 0) {
                                    alerDialog = builder.setTitle(getString(R.string.UnreadSegments))
                                            .setMessage(getString(R.string.YouHaveNotEnabledForUnreadSegments))
                                            .setCancelable(true)
                                            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialogInterface, int i) {
                                                    dialogInterface.dismiss();
                                                    restoreLastNavigationPosition();
                                                }
                                            }).create();
                                } else {
                                    UnreadSegmentsView unreadSegmentsView = new UnreadSegmentsView(
                                            MainActivity.this, periods);
                                    final int myIndex = navigationItems.indexOf(thisNi);
                                    alerDialog = builder.setTitle(getString(R.string.ChooseUnreadSegment))
                                            .setView(unreadSegmentsView).setCancelable(true)
                                            .setNegativeButton(android.R.string.cancel,
                                                    new DialogInterface.OnClickListener() {
                                                        @Override
                                                        public void onClick(DialogInterface dialogInterface,
                                                                int i) {
                                                            dialogInterface.dismiss();
                                                            restoreLastNavigationPosition();
                                                        }
                                                    })
                                            .create();
                                    unreadSegmentsView.setListener(new UnreadSegmentsView.PeriodListener() {
                                        @Override
                                        public void onPeriodClicked(DatabaseService.Period period) {
                                            alerDialog.dismiss();
                                            int beforeMid = period.beforeMid;
                                            Bundle args = new Bundle();
                                            args.putSerializable("messagesSource",
                                                    new UnreadSegmentMessagesSource(
                                                            getString(R.string.navigationUnread),
                                                            MainActivity.this, period));
                                            if (getSelectedNavigationIndex() != myIndex) {
                                                setSelectedNavigationItem(myIndex);
                                            }
                                            runDefaultFragmentWithBundle(args, thisNi);
                                        }
                                    });
                                }
                                alerDialog.show();
                                restyleChildrenOrWidget(alerDialog.getWindow().getDecorView());
                            }
                            return null;
                        }
                    });
            return;
        }
    });
    navigationItems.add(new NavigationItem(NAVITEM_SAVED, R.string.navigationSaved,
            R.drawable.navicon_juickadvanced, "msrcSaved") {
        @Override
        public void action() {
            final Bundle args = new Bundle();
            args.putSerializable("messagesSource", new SavedMessagesSource(MainActivity.this));
            runDefaultFragmentWithBundle(args, this);
        }
    });
    navigationItems.add(new NavigationItem(NAVITEM_RECENT_READ, R.string.navigationRecentlyOpened,
            R.drawable.navicon_juickadvanced, "msrcRecentOpen") {
        @Override
        public void action() {
            final Bundle args = new Bundle();
            args.putSerializable("messagesSource", new RecentlyOpenedMessagesSource(MainActivity.this));
            runDefaultFragmentWithBundle(args, this);
        }
    });
    navigationItems.add(new NavigationItem(NAVITEM_RECENT_WRITE, R.string.navigationRecentlyCommented,
            R.drawable.navicon_juickadvanced, "msrcRecentComment") {
        @Override
        public void action() {
            final Bundle args = new Bundle();
            args.putSerializable("messagesSource", new RecentlyCommentedMessagesSource(MainActivity.this));
            runDefaultFragmentWithBundle(args, this);
        }
    });
    navigationItems.add(new NavigationItem(NAVITEM_ALL_COMBINED, R.string.navigationAllCombined,
            R.drawable.navicon_juickadvanced, "msrcAllCombined") {
        @Override
        public void action() {
            final Bundle args = new Bundle();
            args.putSerializable("messagesSource",
                    new CombinedAllMessagesSource(MainActivity.this, "combined_all"));
            runDefaultFragmentWithBundle(args, this);
        }

        @Override
        public ArrayList<String> getMenuItems() {
            String s = getString(R.string.SelectSources);
            ArrayList<String> strings = new ArrayList<String>();
            strings.add(s);
            return strings;
        }

        @Override
        public void handleMenuAction(int which, String value) {
            switch (which) {
            case 0:
                selectSourcesForAllCombined();
                break;
            }
        }
    });
    navigationItems.add(new NavigationItem(NAVITEM_SUBS_COMBINED, R.string.navigationSubsCombined,
            R.drawable.navicon_juickadvanced, "msrcSubsCombined") {
        @Override
        public void action() {
            final NavigationItem thiz = this;
            new Thread("MessageSource Initializer") {
                @Override
                public void run() {
                    final Bundle args = new Bundle();
                    args.putSerializable("messagesSource",
                            new CombinedSubscriptionMessagesSource(MainActivity.this));
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            runDefaultFragmentWithBundle(args, thiz);
                        }

                    });
                }
            }.start();
            final Bundle args = new Bundle();
            runDefaultFragmentWithBundle(args, this);
        }

        @Override
        public ArrayList<String> getMenuItems() {
            String s = getString(R.string.SelectSources);
            ArrayList<String> strings = new ArrayList<String>();
            strings.add(s);
            return strings;
        }

        @Override
        public void handleMenuAction(int which, String value) {
            switch (which) {
            case 0:
                selectSourcesForAllSubs();
                break;
            }
        }
    });
    int index = 10000;
    final SharedPreferences sp_order = getSharedPreferences("messages_source_ordering", MODE_PRIVATE);
    for (NavigationItem navigationItem : navigationItems) {
        navigationItem.itemOrder = sp_order.getInt("order_" + navigationItem.id, -1);
        if (navigationItem.itemOrder == -1) {
            navigationItem.itemOrder = index;
            sp_order.edit().putInt("order_" + navigationItem.id, navigationItem.itemOrder).commit();
        }
        index++;
    }
    Collections.sort(navigationItems, new Comparator<NavigationItem>() {
        @Override
        public int compare(NavigationItem lhs, NavigationItem rhs) {
            return lhs.itemOrder - rhs.itemOrder; // increasing
        }
    });
    allNavigationItems = new ArrayList<NavigationItem>(navigationItems);
    final Iterator<NavigationItem> iterator = navigationItems.iterator();
    while (iterator.hasNext()) {
        NavigationItem next = iterator.next();
        if (next.sharedPrefsKey != null) {
            if (!sp.getBoolean(next.sharedPrefsKey, defaultValues(next.sharedPrefsKey))) {
                iterator.remove();
            }
        }
    }
    sp_order.edit().commit(); // save

    final boolean compressedMenu = sp.getBoolean("compressedMenu", false);
    float menuFontScale = 1;
    try {
        menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0"));
    } catch (Exception e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }
    final float finalMenuFontScale = menuFontScale;
    navigationList = (DragSortListView) findViewById(R.id.navigation_list);

    // adapter for old-style navigation
    final BaseAdapter navigationAdapter = new BaseAdapter() {
        @Override
        public int getCount() {
            return navigationItems.size();
        }

        @Override
        public Object getItem(int position) {
            return navigationItems.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (position == -1) {
                // NOOK is funny
                return convertView;
            }
            final int screenHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight();
            final int layoutId = R.layout.simple_list_item_1_mine;
            final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView
                    : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null);
            TextView tv = (TextView) retval.findViewById(android.R.id.text1);
            if (parent instanceof Spinner) {
                tv.setTextSize(18 * finalMenuFontScale);
                tv.setEllipsize(TextUtils.TruncateAt.MARQUEE);
            } else {
                tv.setTextSize(22 * finalMenuFontScale);
            }
            tv.setText(getString(navigationItems.get(position).labelId));
            if (compressedMenu) {
                int minHeight = (int) ((screenHeight * 0.7) / getCount());
                tv.setMinHeight(minHeight);
                tv.setMinimumHeight(minHeight);
            }
            retval.setPressedListener(new PressableLinearLayout.PressedListener() {
                @Override
                public void onPressStateChanged(boolean selected) {
                    MainActivity.restyleChildrenOrWidget(retval, false);
                }

                @Override
                public void onSelectStateChanged(boolean selected) {
                    MainActivity.restyleChildrenOrWidget(retval, false);
                }
            });
            MainActivity.restyleChildrenOrWidget(retval, false);
            return retval;
        }
    };
    // adapter for new-style navigation
    final BaseAdapter navigationListAdapter = new BaseAdapter() {
        @Override
        public int getCount() {
            return getItems().size();
        }

        private ArrayList<NavigationItem> getItems() {
            if (navigationList.isDragEnabled()) {
                return allNavigationItems;
            } else {
                return navigationItems;
            }
        }

        @Override
        public Object getItem(int position) {
            return getItems().get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        float textSize = -1;

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (position == -1) {
                // NOOK is funny
                return convertView;
            }
            if (textSize < 0) {
                View inflate = getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null);
                TextView text = (TextView) inflate.findViewById(android.R.id.text1);
                textSize = text.getTextSize();
            }
            final int layoutId = R.layout.navigation_list_item;
            final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView
                    : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null);
            TextView tv = (TextView) retval.findViewById(android.R.id.text1);
            final ArrayList<NavigationItem> items = getItems();
            final NavigationItem theItem = items.get(position);
            tv.setText(getString(theItem.labelId));
            ImageButton menuButton = (ImageButton) retval.findViewById(R.id.menu_button);
            menuButton.setFocusable(false);
            ArrayList<String> menuItems = theItem.getMenuItems();
            menuButton.setVisibility(menuItems != null && menuItems.size() > 0 ? View.VISIBLE : View.GONE);
            menuButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    doNavigationItemMenu(theItem);
                }
            });
            ImageView iv = (ImageView) retval.findViewById(android.R.id.icon);
            iv.setImageResource(theItem.imageId);
            retval.findViewById(R.id.draggable)
                    .setVisibility(items != allNavigationItems ? View.GONE : View.VISIBLE);
            retval.findViewById(R.id.checkbox).setVisibility(
                    items != allNavigationItems || theItem.sharedPrefsKey == null ? View.GONE : View.VISIBLE);
            CheckBox cb = (CheckBox) retval.findViewById(R.id.checkbox);
            cb.setOnCheckedChangeListener(null);
            if (theItem.sharedPrefsKey != null) {
                cb.setChecked(sp.getBoolean(theItem.sharedPrefsKey, defaultValues(theItem.sharedPrefsKey)));
            }
            cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    sp.edit().putBoolean(theItem.sharedPrefsKey, isChecked).commit();
                }
            });
            int spacing = sp.getInt("navigation_spacing", 0);
            tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize + spacing);

            retval.setPadding(0, spacing, 0, spacing);
            return retval;
        }
    };
    ActionBar bar = getSupportActionBar();
    updateActionBarMode();
    navigationList.setDragEnabled(false);
    ((DragSortController) navigationList.getFloatViewManager()).setDragHandleId(R.id.draggable);
    navigationList.setAdapter(navigationListAdapter);
    navigationList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            setSelectedNavigationItem(position);
            closeNavigationMenu(true, false);
        }
    });
    navigationList.setDropListener(new DragSortListView.DropListener() {
        @Override
        public void drop(int from, int to) {
            final NavigationItem item = allNavigationItems.remove(from);
            allNavigationItems.add(to, item);

            int index = 0;
            for (NavigationItem allNavigationItem : allNavigationItems) {
                if (allNavigationItem.itemOrder != index) {
                    allNavigationItem.itemOrder = index;
                    sp_order.edit().putInt("order_" + allNavigationItem.id, allNavigationItem.itemOrder)
                            .commit();
                }
                index++;
            }
            sp_order.edit().commit(); // save
            navigationListAdapter.notifyDataSetChanged();
            //To change body of implemented methods use File | Settings | File Templates.
        }
    });
    bar.setListNavigationCallbacks(navigationAdapter, this);
    final View navigationMenuButton = (View) findViewById(R.id.navigation_menu_button);
    navigationMenuButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(MainActivity.this)
                    .setItems(navigationList.isDragEnabled() ? R.array.navigation_menu_end
                            : R.array.navigation_menu_start, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    int spacing = sp.getInt("navigation_spacing", 0);
                                    switch (which) {
                                    case 0:
                                        if (navigationList.isDragEnabled()) {
                                            navigationList.setDragEnabled(false);
                                            updateNavigation();
                                        } else {
                                            navigationList.setDragEnabled(true);
                                        }
                                        break;
                                    case 1:
                                        final Map<String, ?> all = sp_order.getAll();
                                        for (String s : all.keySet()) {
                                            sp_order.edit().remove(s).commit();
                                        }
                                        sp_order.edit().commit();
                                        updateNavigation();
                                        break;
                                    case 2: // wider
                                        sp.edit().putInt("navigation_spacing", spacing + 1).commit();
                                        ((BaseAdapter) navigationList.getAdapter()).notifyDataSetInvalidated();
                                        break;
                                    case 3: // narrower
                                        if (spacing > 0) {
                                            sp.edit().putInt("navigation_spacing", spacing - 1).commit();
                                            ((BaseAdapter) navigationList.getAdapter())
                                                    .notifyDataSetInvalidated();
                                        }
                                        break;
                                    case 4: // logout from..
                                        logoutFromSomeServices();
                                        break;

                                    }
                                    navigationListAdapter.notifyDataSetChanged();
                                }
                            })
                    .setCancelable(true).create().show();
        }
    });

    final SharedPreferences spn = getSharedPreferences("saved_last_navigation_type", MODE_PRIVATE);
    int restoredLastNavItem = spn.getInt("last_navigation", 0);
    if (restoredLastNavItem != 0) {
        NavigationItem allSources = null;
        for (int i = 0; i < navigationItems.size(); i++) {
            NavigationItem navigationItem = navigationItems.get(i);
            if (navigationItem.labelId == restoredLastNavItem) {
                lastNavigationItem = navigationItem;
            }
            if (navigationItem.labelId == R.string.navigationAll) {
                allSources = navigationItem;
            }
        }
        if (lastNavigationItem == null) {
            lastNavigationItem = allSources; // could be null if not configured
        }
        if (lastNavigationItem == null && navigationItems.size() > 0) {
            lastNavigationItem = navigationItems.get(0); // last default
        }
        if (lastNavigationItem != null) {
            restoreLastNavigationPosition();
            lastNavigationItem.action();
        }
    }

}

From source file:com.fututel.ui.dialpad.DialerFragment.java

public void placeVMCall() {
    Long accountToUse = SipProfile.INVALID_ID;
    SipProfile acc = null;/*w  w w  .  j av  a  2 s. c  o  m*/
    acc = accountChooserButton.getSelectedAccount();
    if (acc != null) {
        accountToUse = acc.id;
    }

    if (accountToUse >= 0) {
        SipProfile vmAcc = SipProfile.getProfileFromDbId(getActivity(), acc.id,
                new String[] { SipProfile.FIELD_VOICE_MAIL_NBR });
        if (!TextUtils.isEmpty(vmAcc.vm_nbr)) {
            // Account already have a VM number
            try {
                service.makeCall(vmAcc.vm_nbr, (int) acc.id);
            } catch (RemoteException e) {
                Log.e(THIS_FILE, "Service can't be called to make the call");
            }
        } else {
            // Account has no VM number, propose to create one
            final long editedAccId = acc.id;
            LayoutInflater factory = LayoutInflater.from(getActivity());
            final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(acc.display_name)
                    .setView(textEntryView)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                            if (missingVoicemailDialog != null) {
                                TextView tf = (TextView) missingVoicemailDialog.findViewById(R.id.vmfield);
                                if (tf != null) {
                                    String vmNumber = tf.getText().toString();
                                    if (!TextUtils.isEmpty(vmNumber)) {
                                        ContentValues cv = new ContentValues();
                                        cv.put(SipProfile.FIELD_VOICE_MAIL_NBR, vmNumber);

                                        int updated = getActivity().getContentResolver()
                                                .update(ContentUris.withAppendedId(
                                                        SipProfile.ACCOUNT_ID_URI_BASE, editedAccId), cv, null,
                                                        null);
                                        Log.d(THIS_FILE, "Updated accounts " + updated);
                                    }
                                }
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    } else if (accountToUse == CallHandlerPlugin.getAccountIdForCallHandler(getActivity(),
            (new ComponentName(getActivity(), com.fututel.plugins.telephony.CallHandler.class)
                    .flattenToString()))) {
        // Case gsm voice mail
        TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
        String vmNumber = tm.getVoiceMailNumber();

        if (!TextUtils.isEmpty(vmNumber)) {
            if (service != null) {
                try {
                    service.ignoreNextOutgoingCallFor(vmNumber);
                } catch (RemoteException e) {
                    Log.e(THIS_FILE, "Not possible to ignore next");
                }
            }
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel", vmNumber, null));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {

            missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.gsm)
                    .setMessage(R.string.no_voice_mail_configured)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            if (missingVoicemailDialog != null) {
                                missingVoicemailDialog.hide();
                            }
                        }
                    }).create();

            // When the dialog is up, completely hide the in-call UI
            // underneath (which is in a partially-constructed state).
            missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

            missingVoicemailDialog.show();
        }
    }
    // TODO : manage others ?... for now, no way to do so cause no vm stored
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventsListActivity.java

@Override
public void onItemSelected(final ZenossEvent event, final int position) {
    try {//from  w w w .  ja v a 2 s  .c o  m
        if (mTwoPane) {
            // In two-pane mode, show the detail view in this activity by
            // adding or replacing the detail fragment using a
            // fragment transaction.
            Bundle arguments = new Bundle();
            arguments.putString("EventID", event.getEVID());
            arguments.putString("EventTitle", event.getDevice());
            arguments.putInt("EventCount", event.getCount());
            arguments.putBoolean(ViewZenossDeviceFragment.ARG_2PANE, true);
            arguments.putInt("position", position);
            ViewZenossEventFragment fragment = new ViewZenossEventFragment();
            fragment.setArguments(arguments);
            getSupportFragmentManager().beginTransaction().replace(R.id.event_detail_container, fragment)
                    .commit();
        } else {
            AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
            alertbox.setTitle("Event Management");
            alertbox.setMessage("What would you like to do?");

            alertbox.setPositiveButton("Acknowledge", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    //AcknowledgeSingleEvent(position);
                    ViewZenossEventsListFragment listFrag = (ViewZenossEventsListFragment) getSupportFragmentManager()
                            .findFragmentById(R.id.events_list);
                    //Log.e("Activity","ack with position " + Integer.toString(position));
                    listFrag.acknowledgeSingleEvent(position);
                }
            });

            alertbox.setNeutralButton("View Details", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    Intent ViewEventIntent = new Intent(ViewZenossEventsListActivity.this,
                            ViewZenossEventActivity.class);
                    ViewEventIntent.putExtra("EventID", event.getEVID());
                    ViewEventIntent.putExtra("position", position);
                    ViewEventIntent.putExtra("EventTitle", event.getDevice());
                    ViewEventIntent.putExtra("EventCount", event.getCount());
                    ArrayList<String> EventNames = new ArrayList<String>();
                    ArrayList<String> EVIDs = new ArrayList<String>();

                    ViewZenossEventsListFragment listFrag = (ViewZenossEventsListFragment) getSupportFragmentManager()
                            .findFragmentById(R.id.events_list);
                    List<ZenossEvent> listOfZenossEvents = listFrag.getListOfEvents();

                    for (ZenossEvent evt : listOfZenossEvents) {
                        EventNames.add(evt.getDevice());
                        EVIDs.add(evt.getEVID());
                    }

                    ViewEventIntent.putStringArrayListExtra("eventnames", EventNames);
                    ViewEventIntent.putStringArrayListExtra("evids", EVIDs);
                    ViewZenossEventsListActivity.this.startActivity(ViewEventIntent);
                }
            });

            alertbox.setNegativeButton("Nothing", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                }
            });
            alertbox.show();
        }
    } catch (Exception e) {
        //Damn I'm lazy
        BugSenseHandler.sendExceptionMessage("ViewZenossEventsListActivity", "onItemSelected", e);
    }
}

From source file:com.andreadec.musicplayer.MainActivity.java

public void setBaseFolder(final File folder) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.setAsBaseFolder);
    builder.setMessage(R.string.setBaseFolderConfirm);
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            saveBaseFolder(folder);//ww w  . j a  v  a 2s.co m
        }
    });
    builder.setNegativeButton(R.string.no, null);
    builder.show();
}

From source file:com.andreadec.musicplayer.MainActivity.java

private void saveBaseFolder(final File folder) {
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(Constants.PREFERENCE_BASEFOLDER, folder.getAbsolutePath());
    editor.commit();/*from   w w w  . j a  va2 s.c o m*/

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.setAsBaseFolder);
    builder.setMessage(R.string.indexBaseFolderConfirm);
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent indexIntent = new Intent(MainActivity.this, IndexFolderService.class);
            indexIntent.putExtra("folder", folder.getAbsolutePath());
            startService(indexIntent);
        }
    });
    builder.setNegativeButton(R.string.no, null);
    builder.show();
}

From source file:pro.dbro.bart.TheActivity.java

public void displayRouteResponse(routeResponse routeResponse) {
    // Log.d("displayRouteResponse","Is this real?: "+routeResponse.toString());
    // Previously, if the device's locale wasn't in Pacific Standard Time
    // Responses with all expired routes could present, causing a looping refresh cycle
    // This is now remedied by coercing response dates into PST
    boolean expiredResponse = false;
    if (routeResponse.routes.size() == 0) {
        Log.d("displayRouteResponse", "no routes to display");
        expiredResponse = true;//from   ww  w .j a v a2  s . c  o  m
    }

    if (timer != null)
        timer.cancel(); // cancel previous timer
    timerViews = new ArrayList(); // release old ETA text views
    maxTimer = 0;
    try {
        tableLayout.removeAllViews();
        //Log.v("DATE",new Date().toString());
        long now = new Date().getTime();

        if (!expiredResponse) {
            fareTv.setVisibility(0);
            fareTv.setText("$" + routeResponse.routes.get(0).fare);
            for (int x = 0; x < routeResponse.routes.size(); x++) {
                route thisRoute = routeResponse.routes.get(x);

                TableRow tr = (TableRow) View.inflate(c, R.layout.tablerow, null);
                tr.setPadding(0, 20, 0, 0);
                LinearLayout legLayout = (LinearLayout) View.inflate(c, R.layout.routelinearlayout, null);

                for (int y = 0; y < thisRoute.legs.size(); y++) {
                    TextView trainTv = (TextView) View.inflate(c, R.layout.tabletext, null);
                    trainTv.setPadding(0, 0, 0, 0);
                    trainTv.setTextSize(20);
                    trainTv.setGravity(3); // set left gravity
                    // If route has multiple legs, generate "Transfer At [station name]" and "To [train name] " rows for each leg after the first
                    if (y > 0) {
                        trainTv.setText("transfer at " + BART.REVERSE_STATION_MAP
                                .get(((leg) thisRoute.legs.get(y - 1)).disembarkStation.toLowerCase()));
                        trainTv.setPadding(0, 0, 0, 0);
                        legLayout.addView(trainTv);
                        trainTv.setTextSize(14);
                        trainTv = (TextView) View.inflate(c, R.layout.tabletext, null);
                        trainTv.setPadding(0, 0, 0, 0);
                        trainTv.setTextSize(20);
                        trainTv.setGravity(3); // set left gravity
                        trainTv.setText("to " + BART.REVERSE_STATION_MAP
                                .get(((leg) thisRoute.legs.get(y)).trainHeadStation.toLowerCase()));
                    } else {
                        // For first route leg, display "Take [train name]" row
                        trainTv.setText("take "
                                + BART.REVERSE_STATION_MAP.get(((leg) thisRoute.legs.get(y)).trainHeadStation));
                    }

                    legLayout.addView(trainTv);

                }

                if (thisRoute.legs.size() == 1) {
                    legLayout.setPadding(0, 10, 0, 0); // Address detination train and ETA not aligning 
                }

                tr.addView(legLayout);

                // Prepare ETA TextView
                TextView arrivalTimeTv = (TextView) View.inflate(c, R.layout.tabletext, null);
                arrivalTimeTv.setPadding(10, 0, 0, 0);

                //Log.v("DEPART_DATE",thisRoute.departureDate.toString());

                // Don't report a train that may JUST be leaving with a negative ETA
                long eta;
                if (thisRoute.departureDate.getTime() - now <= 0) {
                    eta = 0;
                } else {
                    eta = thisRoute.departureDate.getTime() - now;
                }

                if (eta > maxTimer) {
                    maxTimer = eta;
                }
                // Set timeTv Tag to departure date for interpretation by ViewCountDownTimer
                arrivalTimeTv.setTag(thisRoute.departureDate.getTime());

                // Print arrival as time, not eta if greater than BART.ETA_THRESHOLD_MS
                if (thisRoute.departureDate.getTime() - now > BART.ETA_IN_MINUTES_THRESHOLD_MS) {
                    SimpleDateFormat sdf = new SimpleDateFormat("h:mm a");
                    arrivalTimeTv.setText(sdf.format(thisRoute.departureDate));
                    arrivalTimeTv.setTextSize(20);
                }
                // Display ETA as minutes until arrival
                else {
                    arrivalTimeTv.setTextSize(36);
                    // Display eta less than 1m as "<1"
                    if (eta < 60 * 1000)
                        arrivalTimeTv.setText("<1"); // TODO - remove this? Does countdown tick on start
                    else
                        arrivalTimeTv.setText(String.valueOf(eta / (1000 * 60))); // TODO - remove this? Does countdown tick on start
                    // Add the timerView to the list of views to be passed to the ViewCountDownTimer
                    timerViews.add(arrivalTimeTv);
                }

                //new ViewCountDownTimer(arrivalTimeTv, eta, 60*1000).start();
                tr.addView(arrivalTimeTv);
                // Set the Row View (containing train names and times) Tag to the route it represents
                tr.setTag(thisRoute);
                tableLayout.addView(tr);
                tr.setOnLongClickListener(new OnLongClickListener() {

                    @Override
                    public boolean onLongClick(View arg0) {
                        Log.d("RouteViewTag", ((route) arg0.getTag()).toString());
                        usherRoute = (route) arg0.getTag();
                        TextView guidanceTv = (TextView) View.inflate(c, R.layout.tabletext, null);
                        guidanceTv.setText(Html.fromHtml(getString(R.string.service_prompt)));
                        guidanceTv.setTextSize(18);
                        guidanceTv.setPadding(0, 0, 0, 0);
                        new AlertDialog.Builder(c).setTitle("Route Guidance").setIcon(R.drawable.ic_launcher)
                                .setView(guidanceTv).setPositiveButton(R.string.service_start_button,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int which) {
                                                Intent i = new Intent(c, UsherService.class);
                                                //i.putExtra("departure", ((leg)usherRoute.legs.get(0)).boardStation);
                                                //Log.v("SERVICE","Starting");
                                                if (usherServiceIsRunning()) {
                                                    stopService(i);
                                                }
                                                startService(i);
                                            }

                                        })
                                .setNeutralButton("Cancel", null).show();
                        return true; // consumed the long click
                    }

                });
                tr.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        int index = tableLayout.indexOfChild(arg0); // index of clicked view. Expanded view will always be +1
                        route thisRoute = (route) arg0.getTag();
                        if (!thisRoute.isExpanded) { // if route not expanded
                            thisRoute.isExpanded = true;
                            LinearLayout routeDetail = (LinearLayout) View.inflate(c, R.layout.routedetail,
                                    null);
                            TextView arrivalTv = (TextView) View.inflate(c, R.layout.tabletext, null);
                            SimpleDateFormat curFormater = new SimpleDateFormat("h:mm a");
                            //arrivalTv.setTextColor(0xFFC9C7C8);
                            arrivalTv.setText("arrives " + curFormater.format(thisRoute.arrivalDate));
                            arrivalTv.setTextSize(20);
                            routeDetail.addView(arrivalTv);
                            ImageView bikeIv = (ImageView) View.inflate(c, R.layout.bikeimage, null);

                            if (!thisRoute.bikes) {
                                bikeIv.setImageResource(R.drawable.no_bicycle);
                            }
                            routeDetail.addView(bikeIv);
                            tableLayout.addView(routeDetail, index + 1);
                        } else {
                            thisRoute.isExpanded = false;
                            tableLayout.removeViewAt(index + 1);
                        }

                    }
                });
            } // end route iteration
        } // end expiredResponse check
          // expiredResponse == True
          // If a late-night routeResponse includes the next morning's routes, they will be
          // presented with HH:MM ETAs, instead of minutes
          // Else if a late-night routeResponse includes routes from earlier in the evening
          // We will display "This route has stopped for tonight"
        else {
            String message = "This route has stopped for tonight";
            TextView specialScheduleTextView = (TextView) View.inflate(c, R.layout.tabletext, null);
            specialScheduleTextView.setText(message);
            specialScheduleTextView.setPadding(0, 0, 0, 0);
            tableLayout.addView(specialScheduleTextView);
        }
        if (routeResponse.specialSchedule != null) {
            ImageView specialSchedule = (ImageView) View.inflate(c, R.layout.specialschedulelayout, null);
            specialSchedule.setTag(routeResponse.specialSchedule);
            specialSchedule.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    TextView specialScheduleTv = (TextView) View.inflate(c, R.layout.tabletext, null);
                    specialScheduleTv.setPadding(0, 0, 0, 0);
                    specialScheduleTv.setText(Html.fromHtml(arg0.getTag().toString()));
                    specialScheduleTv.setTextSize(16);
                    specialScheduleTv.setMovementMethod(LinkMovementMethod.getInstance());
                    new AlertDialog.Builder(c).setTitle("Route Alerts").setIcon(R.drawable.warning)
                            .setView(specialScheduleTv).setPositiveButton("Okay!", null).show();

                }

            });
            tableLayout.addView(specialSchedule);
        }
        // Don't set timer if response is expired
        if (!expiredResponse) {
            timer = new ViewCountDownTimer(timerViews, "route", maxTimer, 30 * 1000);
            timer.start();
        }
    } catch (Throwable t) {
        Log.d("displayRouteResponseError", t.getStackTrace().toString());
    }
}

From source file:com.aibasis.parent.ui.MainActivity.java

/**
 * ??dialog/*from  ww  w .  ja  v a2 s . co m*/
 */
private void showConflictDialog() {
    isConflictDialogShow = true;
    DemoHXSDKHelper.getInstance().logout(false, null);
    String st = getResources().getString(R.string.Logoff_notification);
    if (!MainActivity.this.isFinishing()) {
        // clear up global variables
        try {
            if (conflictBuilder == null)
                conflictBuilder = new android.app.AlertDialog.Builder(MainActivity.this);
            conflictBuilder.setTitle(st);
            conflictBuilder.setMessage(R.string.connect_conflict);
            conflictBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    conflictBuilder = null;
                    finish();
                    startActivity(new Intent(MainActivity.this, LoginActivity.class));
                }
            });
            conflictBuilder.setCancelable(false);
            conflictBuilder.create().show();
            isConflict = true;
        } catch (Exception e) {
            EMLog.e(TAG, "---------color conflictBuilder error" + e.getMessage());
        }

    }

}

From source file:com.aibasis.parent.ui.MainActivity.java

/**
 * ??dialog//from w w  w. j av a  2  s  .c om
 */
private void showAccountRemovedDialog() {
    isAccountRemovedDialogShow = true;
    DemoHXSDKHelper.getInstance().logout(true, null);
    String st5 = getResources().getString(R.string.Remove_the_notification);
    if (!MainActivity.this.isFinishing()) {
        // clear up global variables
        try {
            if (accountRemovedBuilder == null)
                accountRemovedBuilder = new android.app.AlertDialog.Builder(MainActivity.this);
            accountRemovedBuilder.setTitle(st5);
            accountRemovedBuilder.setMessage(R.string.em_user_remove);
            accountRemovedBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    accountRemovedBuilder = null;
                    finish();
                    startActivity(new Intent(MainActivity.this, LoginActivity.class));
                }
            });
            accountRemovedBuilder.setCancelable(false);
            accountRemovedBuilder.create().show();
            isCurrentAccountRemoved = true;
        } catch (Exception e) {
            EMLog.e(TAG, "---------color userRemovedBuilder error" + e.getMessage());
        }

    }

}

From source file:com.andreadec.musicplayer.MainActivity.java

private void bassBoostSettings() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.bassBoost);
    View view = getLayoutInflater().inflate(R.layout.layout_bassboost, null);
    builder.setView(view);//from   w  ww  . j a v  a 2 s .  co m

    builder.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            updateExtendedMenu();
        }
    });
    builder.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            updateExtendedMenu();
        }
    });

    CheckBox checkBoxBassBoostEnable = (CheckBox) view.findViewById(R.id.checkBoxBassBoostEnabled);
    checkBoxBassBoostEnable.setChecked(musicService.getBassBoostEnabled());
    checkBoxBassBoostEnable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            musicService.toggleBassBoost();
            updateExtendedMenu();
        }
    });

    SeekBar seekbar = (SeekBar) view.findViewById(R.id.seekBarBassBoostStrength);
    seekbar.setMax(1000);
    seekbar.setProgress(musicService.getBassBoostStrength());
    seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                musicService.setBassBoostStrength(seekBar.getProgress());
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {
        }
    });

    builder.show();
}

From source file:fr.paug.droidcon.ui.BaseActivity.java

private void complainMustHaveGoogleAccount() {
    LOGD(TAG, "Complaining about missing Google account.");
    new AlertDialog.Builder(this).setTitle(R.string.google_account_required_title)
            .setMessage(R.string.google_account_required_message)
            .setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
                @Override/*from  w w w.  j a v a2 s  . co m*/
                public void onClick(DialogInterface dialog, int which) {
                    promptAddAccount();
                }
            }).setNegativeButton(R.string.not_now, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            }).show();
}