Example usage for android.app AlertDialog setCancelable

List of usage examples for android.app AlertDialog setCancelable

Introduction

In this page you can find the example usage for android.app AlertDialog setCancelable.

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:com.star.printer.StarPrinter.java

/**
 * This function shows how to get the status of a printer
 * /*  w  w w.  j a v  a2s  .co  m*/
 * @param context
 *            Activity for displaying messages to the user
 * @param portName
 *            Port name to use for communication. This should be
 *            (TCP:<IPAddress> or BT:<DeviceName> for bluetooth)
 * @param portSettings
 *            Should be mini, the port settings mini is used for portable
 *            printers
 */
// portSettings = "mini";
// String portName = BT:<DeviceName>;
// context = this
public static void CheckStatus(Context context, String portName, String portSettings) {
    StarIOPort port = null;
    try {
        /*
         * using StarIOPort3.1.jar (support USB Port) Android OS Version:
         * upper 2.2
         */
        port = StarIOPort.getPort(portName, portSettings, 10000, context);
        /*
         * using StarIOPort.jar Android OS Version: under 2.1 port =
         * StarIOPort.getPort(portName, portSettings, 10000);
         */

        // A sleep is used to get time for the socket to completely open
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }

        StarPrinterStatus status = port.retreiveStatus();

        if (status.offline == false) {
            Builder dialog = new AlertDialog.Builder(context);
            dialog.setNegativeButton("Ok", null);
            AlertDialog alert = dialog.create();
            alert.setTitle("Printer");
            alert.setMessage("Printer is Online");
            alert.setCancelable(false);
            alert.show();
        } else {
            String message = "Printer is offline";
            if (status.receiptPaperEmpty == true) {
                message += "\nPaper is Empty";
            }
            if (status.coverOpen == true) {
                message += "\nCover is Open";
            }
            Builder dialog = new AlertDialog.Builder(context);
            dialog.setNegativeButton("Ok", null);
            AlertDialog alert = dialog.create();
            alert.setTitle("Printer");
            alert.setMessage(message);
            alert.setCancelable(false);
            alert.show();
        }
    } catch (StarIOPortException e) {
        Builder dialog = new AlertDialog.Builder(context);
        dialog.setNegativeButton("Ok", null);
        AlertDialog alert = dialog.create();
        alert.setTitle("Failure");
        alert.setMessage("Failed to connect to printer");
        alert.setCancelable(false);
        alert.show();
    } finally {
        if (port != null) {
            try {
                StarIOPort.releasePort(port);
            } catch (StarIOPortException e) {
            }
        }
    }
}

From source file:com.star.printer.StarPrinter.java

private static boolean sendCommand(Context context, String portName, String portSettings,
        ArrayList<byte[]> byteList) {
    boolean result = true;
    StarIOPort port = null;/* w w  w  . j  a  v  a 2s.co m*/
    try {
        /*
         * using StarIOPort3.1.jar (support USB Port) Android OS Version:
         * upper 2.2
         */
        port = StarIOPort.getPort(portName, portSettings, 20000, context);
        /*
         * using StarIOPort.jar Android OS Version: under 2.1 port =
         * StarIOPort.getPort(portName, portSettings, 10000);
         */
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }

        /*
         * Portable Printer Firmware Version 2.4 later, SM-S220i(Firmware
         * Version 2.0 later) Using Begin / End Checked Block method for
         * preventing "data detective". When sending large amounts of raster
         * data, use Begin / End Checked Block method and adjust the value
         * in the timeout in the "StarIOPort.getPort" in order to prevent
         * "timeout" of the "endCheckedBlock method" while a printing. If
         * receipt print is success but timeout error occurs(Show message
         * which is
         * "There was no response of the printer within the timeout period."
         * ), need to change value of timeout more longer in
         * "StarIOPort.getPort" method. (e.g.) 10000 -> 30000When use
         * "Begin / End Checked Block Sample Code", do comment out
         * "query commands Sample code".
         */

        /* Start of Begin / End Checked Block Sample code */
        StarPrinterStatus status = port.beginCheckedBlock();

        if (true == status.offline) {
            throw new StarIOPortException("A printer is offline");
        }

        byte[] commandToSendToPrinter = convertFromListByteArrayTobyteArray(byteList);
        port.writePort(commandToSendToPrinter, 0, commandToSendToPrinter.length);

        port.setEndCheckedBlockTimeoutMillis(30000);// Change the timeout
        // time of
        // endCheckedBlock
        // method.
        status = port.endCheckedBlock();

        if (true == status.coverOpen) {
            throw new StarIOPortException("Printer cover is open");
        } else if (true == status.receiptPaperEmpty) {
            throw new StarIOPortException("Receipt paper is empty");
        } else if (true == status.offline) {
            throw new StarIOPortException("Printer is offline");
        }
        /* End of Begin / End Checked Block Sample code */

        /*
         * Portable Printer Firmware Version 2.3 earlier Using query
         * commands for preventing "data detective". When sending large
         * amounts of raster data, send query commands after writePort data
         * for confirming the end of printing and adjust the value in the
         * timeout in the "checkPrinterSendToComplete" method in order to
         * prevent "timeout" of the "sending query commands" while a
         * printing. If receipt print is success but timeout error
         * occurs(Show message which is
         * "There was no response of the printer within the timeout period."
         * ), need to change value of timeout more longer in
         * "checkPrinterSendToComplete" method. (e.g.) 10000 -> 30000When
         * use "query commands Sample code", do comment out
         * "Begin / End Checked Block Sample Code".
         */

        /* Start of query commands Sample code */
        // byte[] commandToSendToPrinter =
        // convertFromListByteArrayTobyteArray(byteList);
        // port.writePort(commandToSendToPrinter, 0,
        // commandToSendToPrinter.length);
        //
        // checkPrinterSendToComplete(port);
        /* End of query commands Sample code */
    } catch (StarIOPortException e) {
        result = false;
        Builder dialog = new AlertDialog.Builder(context);
        dialog.setNegativeButton("Ok", null);
        AlertDialog alert = dialog.create();
        alert.setTitle("Failure");
        alert.setMessage(e.getMessage());
        alert.setCancelable(false);
        alert.show();
    } finally {
        if (port != null) {
            try {
                StarIOPort.releasePort(port);
            } catch (StarIOPortException e) {
            }
        }
    }

    return result;
}

From source file:org.jonblack.bluetrack.activities.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    // Load default preference values.
    // The defaults are only loaded if they haven't been done before. It will
    // not overwrite changes.
    // @see PreferenceManager.setDefaultValues
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Get the local bluetooth adapter and check if bluetooth is supported.
    BluetoothAdapter localBtAdapter = BluetoothAdapter.getDefaultAdapter();
    if (localBtAdapter == null) {
        Log.w(TAG, "Bluetooth isn't supported on device.");

        AlertDialog ad = new AlertDialog.Builder(this).create();
        ad.setCancelable(false);
        Resources r = getResources();
        String msg = r.getString(R.string.error_bluetooth_not_supported, r.getString(R.string.app_name));
        ad.setMessage(msg);//from  www.  j  a  v a2s.c o m
        ad.setButton(AlertDialog.BUTTON_POSITIVE, r.getString(R.string.button_exit),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                        dialog.dismiss();
                    }
                });
        ad.show();

        return;
    }

    Resources r = getResources();

    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ActionBar.Tab tab1 = actionBar.newTab().setText(r.getText(R.string.ab_tab_live_tracking));
    tab1.setTag("tracking");
    tab1.setTabListener(new TabListener<LiveTrackingFragment>(this, "tracking", LiveTrackingFragment.class));
    actionBar.addTab(tab1);

    ActionBar.Tab tab2 = actionBar.newTab().setText(r.getText(R.string.ab_tab_sessions));
    tab2.setTag("session");
    tab2.setTabListener(new TabListener<SessionFragment>(this, "session", SessionFragment.class));
    actionBar.addTab(tab2);

    ActionBar.Tab tab3 = actionBar.newTab().setText(r.getText(R.string.ab_tab_devices));
    tab3.setTag("devices");
    tab3.setTabListener(new TabListener<DevicesFragment>(this, "devices", DevicesFragment.class));
    actionBar.addTab(tab3);
}

From source file:com.github.mobile.ui.DialogFragmentHelper.java

/**
 * Create default dialog//  w w w  . ja v  a  2s  .  c o  m
 *
 * @return dialog
 */
protected AlertDialog createDialog() {
    final AlertDialog dialog = LightAlertDialog.create(getActivity());
    dialog.setTitle(getTitle());
    dialog.setMessage(getMessage());
    dialog.setCancelable(true);
    dialog.setOnCancelListener(this);
    return dialog;
}

From source file:semanticweb.hws14.movapp.activities.Criteria.java

private void useLocationData(Location location) {
    //Receive the location Data
    AlertDialog ad = new AlertDialog.Builder(that).create();
    ad.setCancelable(false); // This blocks the 'BACK' button
    Geocoder geocoder = new Geocoder(that, Locale.ENGLISH);
    try {// w  w w .ja va 2s . com
        List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);

        if (addresses != null) {
            Address returnedAddress = addresses.get(0);
            final String strReturnedAdress = returnedAddress.getLocality();
            ad.setMessage("You are in: " + strReturnedAdress + "\nUse this location for the search?");

            ad.setButton(DialogInterface.BUTTON_POSITIVE, "YES", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    if (tabPosition == 0) {
                        MovieCriteria currentFragmet = (MovieCriteria) getFragmentByPosition(tabPosition);
                        currentFragmet.setGPSLocation(strReturnedAdress);
                    } else if (tabPosition == 1) {
                        ActorCriteria currentFragmet = (ActorCriteria) getFragmentByPosition(tabPosition);
                        currentFragmet.setGPSLocation(strReturnedAdress);
                    }

                    dialog.dismiss();
                }
            });

            ad.setButton(DialogInterface.BUTTON_NEGATIVE, "NO", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
        } else {
            ad.setMessage("No Address returned!");
            ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
        }
    } catch (IOException e) {
        e.printStackTrace();
        ad.setMessage("Can not get Address!");
        ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    }

    ad.show();
    setProgressBarIndeterminateVisibility(false);
    locMgr.removeUpdates(locListner);
}

From source file:ch.fixme.status.Widget_config.java

@Override
protected Dialog onCreateDialog(int id) {
    AlertDialog dialog = null;
    switch (id) {
    case DIALOG_LOADING:
        dialog = new ProgressDialog(this);
        dialog.setCancelable(false);
        dialog.setMessage(getString(R.string.msg_loading));
        dialog.setCancelable(true);//from w  ww. j av  a2  s .  co  m
        ((ProgressDialog) dialog).setIndeterminate(true);
        break;
    }
    return dialog;
}

From source file:com.zen.bodybuildingdiet.IntroScreen.java

public void showWaiver(String result) {

    AlertDialog.Builder builder = new AlertDialog.Builder(IntroScreen.this);
    builder.setPositiveButton("I Agree", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();/*from w  w w.  ja  v a2 s . c  o  m*/
        }
    });
    builder.setMessage("End User License Agreement" + "\n" + "\n"
            + "IF YOU DOWNLOAD THE SOFTWARE SUBJECT TO THESE TERMS BY CLICKING THE I AGREE BUTTON, AND/OR USE THE Zen Software, LLC SOFTWARE OR/AND INCLUDED DOCUMENTATION (together the \"Software\"), YOU AGREE TO BE BOUND BY THE TERMS AND CONDITIONS OF THIS AGREEMENT (the \"Agreement\"), AND THIS WILL BE A LEGALLY BINDING AGREEMENT BETWEEN YOU AND ZEN SOFTWARE, LLC (\"Zen Software, LLC\").  PLEASE READ THIS DOCUMENT CAREFULLY BEFORE ACCEPTING THESE TERMS AND USING THIS SOFTWARE.    IF YOU DO NOT AGREE WITH THE TERMS AND CONDITIONS OF THIS AGREEMENT, YOU SHOULD REJECT THEM BY NOT DOWNLOADING THE SOFTWARE.  References in this Agreement to \"you\" or \"your\" refer to both you and any person or entity on whose behalf you act, if any."
            + "\n" + "\n"
            + "1.  Grant Of License.  Subject to the terms and conditions of this Agreement, Zen Software, LLC hereby grants to you a personal, non-transferable and non-exclusive license to install and use the Software on your device for the purposes of your own diet and exercise needs."
            + "\n" + "\n"
            + "2.  Software Use Restrictions.  You shall not sublicense, distribute, hypothecate, lease, loan or otherwise convey the Software or any portion thereof to anyone, and under no circumstance may you use or allow the use of the Software in any manner other than as expressly set forth above.  You shall not modify the Software, incorporate the Software in whole or in part in any other product or create derivative works based on all or part of the Software.  You shall not remove any copyright, trademark, proprietary rights, disclaimer or warning notice included on or embedded in any part of the Software.  You shall not use the Software in connection with a service bureau, time sharing or fee-for service arrangement with third parties.  Except to the extent permitted by applicable local law, you shall not reverse assemble, decompile or disassemble or otherwise reverse engineer any portion of the Software.  If you dispose of any media embodying Software, you will ensure that you have completely erased or otherwise destroyed any Software stored on such media.  THE SOFTWARE IS NOT INTENDED FOR USE IN ANY SITUATION IN WHICH THE FAILURE OF THE SOFTWARE COULD LEAD TO DEATH OR BODILY INJURY OF ANY TYPE."
            + "\n" + "\n"
            + "3.  Copying Restrictions.  You may copy the Software onto your device, and you may make one (1) copy of the Software for backup or archival purposes.  You agree that (i) your use and possession of such copies shall be solely under the terms and conditions of this Agreement, and (ii) you shall place the same proprietary and copyright notices and legends on all such copies as included by Zen Software, LLC on any media embodying an authorized copy of the Software originally provided by Zen Software, LLC.  Except as described in this paragraph, you are not permitted to copy the Software."
            + "\n" + "\n"
            + "4.  Disclosure Restrictions.  You acknowledge that the Software, including the source code for the Software and any information derived therefrom, constitutes a valuable trade secret of Zen Software, LLC.  You shall not disclose such materials to anyone."
            + "\n" + "\n"
            + "5.  Ownership of Software.  You agree and acknowledge that (i) the Software is licensed to you, not sold, and Zen Software, LLC transfers no ownership interest in the Software, in the intellectual property in any Software or in any Software copy, to you under this Agreement or otherwise, (ii) that Zen Software, LLC and its licensors reserve all rights not expressly granted to you hereunder, (iii) Zen Software, LLC or its licensors own the Software (including, but not by way of limitation, any images, algorithms, photographs, animations, video, audio, music and text incorporated in the Software), and (iv) the Software is protected by United States Copyright Law and international treaties relating to protection of copyright.  The Software includes, and this Agreement will cover, any updates, upgrades or bug fixes for the Software provided to you."
            + "\n" + "\n"
            + "6.  Transfer Restrictions.  You may transfer the Software and all licenses and rights in the Software granted to you under this Agreement to a third party provided that: (i) such transferee agrees to accept the terms and conditions of this Agreement, and (ii) you also transfer all Software, including all copies thereof, to such transferee.  Except as provided in this Section, you may not transfer or assign this Agreement or any of your rights or obligations under this Agreement, in whole or in part."
            + "\n" + "\n"
            + "7.  Export Restrictions.  You may not export or re-export any Software except in full compliance with all United States laws and regulations, executive orders and the like, including in particular the Export Administration Regulations of the U.S.  Department of Commerce.  Without limitation of the foregoing, no Software may be exported or re-exported into (or to a national or resident of) any country to which the U.S. embargoes goods, or to anyone on the U.S.  Treasury Departments list of Specially Designated Nationals and Blocked Persons or the U.S.  Commerce Departments Denied Persons List."
            + "\n" + "\n"
            + "8.  Enforcement Of Terms; Termination.  If you fail to fulfill any of your obligations under this Agreement, this Agreement, this Agreement will automatically terminate, and Zen Software, LLC and/or its licensors may pursue all available legal remedies available to them.  You agree that Zen Software, LLCs licensors referenced in the Software are third-party beneficiaries of this Agreement, and may enforce this Agreement as it relates to their intellectual property.  Sections 2-9 and 11-18 shall survive any termination or expiration of this Agreement."
            + "\n" + "\n"
            + "9.  U.  S.  Government Users.  Pursuant to the policy stated at48 CFR 227.7202-1, U.S.  Government users acknowledge that (i) the Software is commercial computer software, (ii) this Agreement embodies the licenses customarily used by Zen Software, LLC for licenses in Software granted to the public, and (iii) the licenses set forth herein shall apply to all possession, use and duplication of the Software by the Government, except to the extent which such licenses are inconsistent with Federal procurement law.  Contractor/manufacturer is Zen Software, LLC, Inc."
            + "\n" + "\n"
            + "10.  Assumption of Risk.  You acknowledge that your diet and exercise activities involve risks, which may involve risk of bodily injury or death, and that you assume those risks.  You should consult a licensed physician prior to beginning or modifying any diet or exercise program that you undertake, and you acknowledge that Zen Software, LLC has advised you of the necessity for obtaining such consultations.  In addition, the Software should not be used by pregnant women or individuals underage 18.  The Software is a source of information, but it does not provide medical advice.  In no event shall Zen Software, LLC be liable for any death or bodily injury that you suffer, or that you cause to any third party, in connection with your use of the Software or any diet, exercise or other activity you undertake in connection with your use of the Software."
            + "\n" + "\n"
            + "11.  Disclaimer of Warranty.  ZEN SOFTWARE, LLC PROVIDES THE SOFTWARE TO YOU \"AS IS\", WITH ALL FAULTS, AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, STATUTORY, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION ANV WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  ZEN SOFTWARE, LLC MAKES NO REPRESENTATION OR WARRANTY THAT THE SOFTWARE IS ACCURATE, COMPLETE OR UP-TO-DATE.  NO ORAL ORWRITTEN INFORMATION OR ADVICE GIVEN BY ANY ZEN SOFTWARE, LLC EMPLOVEE, REPRESENTATIVE OR DISTRIBUTOR SHALL CREATE A WARRANTY FOR THE SOFTWARE, AND YOU MAY NOT RELY ON ANY SUCH INFORMATION OR ADVICE.  ZEN SOFTWARE, LLCS LICENSORS EXPLICITLY DISCLAIM ANY AND ALL WARRANTIES WITH RESPECT TO THE SOFTWARE."
            + "\n" + "\n"
            + "12.  Limitation Of Liability.  IN NO EVENT SHALL ZEN SOFTWARE, LLC OR ITS LICENSORS BE LIABLE TO YOU FOR ANY SPECIAL, CONSEOUENTIAL, PUNITIVE, EXEMPLARY, INCIDENTAL OR INDIRECT DAMAGES OFANY KIND (INCLUDING WITHOUT LIMITATION THE COST OF COVER, DAMAGES ARISING FROM LOSS OF DATA, USE, PROFITS OR GOODWILL), WHETHER OR NOT ZEN SOFTWARE, LLC HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITV ARISING OUT OF THIS AGREEMENT.  THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE OFANV LIMITED REMEDY.  ZEN SOFTWARE, LLCS MAXIMUM AGGREGATE LIABILITY ARISING OUT OF THIS AGREEMENT AND/OR YOURR USE OR POSSESSION OFTHE SOFTWARE, INCLUDING WITHOUT LIMITATION ANY CLAIMS IN TORT (INCLUDING NEGLIGENCE), CONTRACT, BREACH OF WARRANTY, STRICT LIABILITY OR OTHERWISE, AND FOR ANY AND ALL CLAIMS COMBINED, WILL NOT EXCEED THE LESSER OF(A) $10; OR(B) THE FEE YOU PAID FOR YOUR LICENSE TO THE SOFTWARE."
            + "\n" + "\n"
            + "13.  Governing Law.  This Agreement shall be governed by and interpreted in accordance with the laws of the Commonwealth of Minnesota, excluding its choice of law rules.  The United Nations Convention on Contracts for the International Sale of Goods shall not apply."
            + "\n" + "\n"
            + "14.  Disputes.  A party shall not seek relief from a court with respect to any dispute arising in connection with this Agreement (except for any application for urgent equitable relief) unless such dispute has first been referred to voluntary mediation, and, if such mediation is not successful, has been submitted to arbitration conducted by a panel of three arbitrators sitting in Minneapolis, Minnesota.  Each party shall choose one arbitrator and those two shall choose the third.  The arbitration shall be conducted in accordance with the Commercial Arbitration Rules of the American Arbitration Association and the decision of the arbitrators shall be binding and enforceable in any court of competent jurisdiction.  The arbitrators shall have no power to award punitive damages nor any damages inconsistent with this Agreement or measured other than by the actual losses suffered by the parties."
            + "\n" + "\n"
            + "15.  Complete Agreement; Waiver; Severability.  This Agreement supersedes all proposals, oral or written, all negotiations, conversations, discussions and all past course of dealing between you and  Zen Software, LLC relating to the Software or the terms of its license to you, and may only be modified in writing signed by you and Zen Software, LLC.  In the event any term of this Agreement is held by a court of competent jurisdiction not to be enforceable, the remaining terms shall survive and be enforced to the maximum extent permissible by law.  No waiver of any right or obligation contained herein shall be given except in writing signed by the party against whom the waiver is sought to be enforced.  If any of the provisions of this Agreement are held to be invalid under any applicable statute or rule of law, they shall be severed from this Agreement and the remaining provisions of this Agreement shall be interpreted so as best to reasonably effect the intent of the parties.  The parties further agree to replace any such invalid or unenforceable provisions with valid and enforceable provisions designed to achieve, to the extent possible, the business purposes and intent of such invalid or unenforceable provisions."
            + "\n" + "\n"
            + "16.  Consent to Electronic Contracting.  You agree that execution of this Agreement may occur by your manifesting your acceptance of it when you downloaded the Software, and that no signature on a paper copy of this Agreement is required in order to form a binding contract."
            + "\n" + "\n"
            + "17.  Privacy Disclosure.  Zen Software, LLC may use analytics technology to track anonymous traffic data about the use of the Software.  This data does not include any personally identifiable information of you, the user.  Some of the analytics technology described in this paragraph is provided to Zen Software, LLC by Google, Inc. (\"Google\").  Under the Google Analytics Terms of Service, Google and its subsidiaries have the right to retain and use the anonymous traffic data collected by the Google Analytics service from users of the Software.  Google's use of such data is subject to the Google Privacy Policy located at http://www.google.com/privacy.html.");

    AlertDialog alert = builder.create();
    alert.setCancelable(false);
    alert.show();
}

From source file:bikebadger.RideActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.d("Bike Badger", "RideActivity::onCreate");
    super.onCreate(savedInstanceState);

    Context context = getApplicationContext();
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    AppManager.AppStartEnum startMode = AppManager.CheckAppStart(getApplicationContext(), preferences);
    //startMode = AppManager.AppStartEnum.EXPIRED_FREE;
    //startMode = AppManager.AppStartEnum.DISABLED;
    switch (startMode) {
    case DISABLED:
        AlertDialog finishAlert = new AlertDialog.Builder(this).create();
        finishAlert.setCancelable(false);
        finishAlert.setTitle("Trial Expired");
        finishAlert.setMessage("Your trial has expired. Please consider purchasing the full version.");
        finishAlert.setButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //RideManager rm = RideManager.get(RideActivity.this);
                //if(rm != null)
                //  rm.Shutdown();
                RideActivity.this.finish();
                //dialog.dismiss();
            }// w w w .j  a  va  2s .c o m
        });
        finishAlert.show();
        break;
    case EXPIRED_FREE: // expired trail. Let them purchase or do nothing.
        AppManager.PurchaseDialog(this);
        break;
    case NORMAL_FREE:
        // Still counting down the expiry. Do nothing
        break;
    case NORMAL_PAID:
        // TODO Until I figure out what this overly complicated thing does, don't use it
        // If it is merely to prevent folks from side-loading a copy they somehow get a hold of, they
        // deserve a free version
        //  checkLicense();
        // all is well. Do nothing
        break;
    case FIRST_TIME_FREE:
        // the version number ends in .free
        AppManager.CopyAssetFileOrDir("empty.gpx", context);
        AppManager.CopyAssetFileOrDir("EnchiladaBuffet_Austin.gpx", context);
        AppManager.CopyAssetFileOrDir("BikeBadger.pdf", context);

        // conditional shows the version notes (only if the version has changed)
        VersionNotes myNotes = new VersionNotes(this);
        myNotes.showVersionNotes();
        break;
    case FIRST_TIME_PAID:
        AppManager.CopyAssetFileOrDir("empty.gpx", context);
        AppManager.CopyAssetFileOrDir("EnchiladaBuffet_Austin.gpx", context);
        AppManager.CopyAssetFileOrDir("BikeBadger.pdf", context);

        // TODO Until I figure out what this overly complicated thing does, don't use it
        // If it is merely to prevent folks from side-loading a copy they somehow get a hold of, they
        // deserve a free version
        // checkLicense();

        // conditional shows the version notes (only if the version has changed)
        VersionNotes myNotes2 = new VersionNotes(this);
        myNotes2.showVersionNotes();

        break;
    case FIRST_TIME_VERSION:
        AppManager.CopyAssetFileOrDir("BikeBadger.pdf", context);
        // conditional shows the version notes (only if the version has changed)
        VersionNotes myNotes1 = new VersionNotes(this);
        myNotes1.showVersionNotes();
        break;
    }

    if (AppManager.IsPackageInstalled("net.dinglisch.android.taskerm", context)) {
        Log.d(Constants.APP.TAG, "Tasker Installed");
    }

    if (AppManager.IsPackageInstalled("com.strava", context)) {
        Log.d(Constants.APP.TAG, "Strava Installed");
    } else {
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=com.google.android.apps.maps"));
        startActivity(intent);
    }

    if (AppManager.IsPackageInstalled("com.maxmpz.audioplayer", context)) {
        Log.d(Constants.APP.TAG, "PowerAMP Installed");
    }

}

From source file:in.fabinpaul.sixthsense.SixthSenseActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case REQUEST_CAMERA_PERMISSION: {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);

        } else {/*from  w w w  . j  av a2 s.  com*/

            AlertDialog ad = new AlertDialog.Builder(this).create();
            ad.setCancelable(false); // This blocks the 'BACK' button
            ad.setMessage(
                    "It seems that you device does not support camera (or it is locked). Application will be closed.");
            ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    finish();
                }
            });
            ad.show();
        }
        return;
    }

    // other 'case' lines to check for other
    // permissions this app might request
    }
}

From source file:com.dena.app.usage.watcher.fragment.WatchFragment.java

public void onItemClick(AdapterView adapterview, View view, int i, long l) {
    final WatchItem item = (WatchItem) adapterview.getItemAtPosition(i);
    final Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage(item.getPackageName());
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(item.getAppName());
    List<String> list = new ArrayList<>();
    list.add(getString(R.string.set_usage_limit));
    list.add(getString(R.string.reset_usage_limit));
    list.add(getString(R.string.hide_this_app));
    if (null != intent) {
        list.add(getString(R.string.launch_this_app));
    }//  w  ww .  j a v  a 2  s.c o m
    builder.setItems(list.toArray(new String[0]), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialoginterface, int j) {
            switch (j) {
            case 0:
                showSetTimerDialog(item);
                break;
            case 1:
                mDB.setTimerInfo(item.getPackageName(), 0);
                mDB.setTimerWarning(item.getPackageName(), 0);
                mDB.setTimerFinish(item.getPackageName(), 0);
                onRefresh();
                break;
            case 2:
                (new UnwatchManager(getActivity())).addUnwatch(item.getPackageName());
                onRefresh();
                break;
            case 3:
                if (null != intent) {
                    startActivity(intent);
                }
                break;
            }
        }
    });
    AlertDialog alertdialog = builder.create();
    alertdialog.setCancelable(true);
    alertdialog.setCanceledOnTouchOutside(true);
    alertdialog.show();
}